Completed
Branch FET-Wait-List (287eab)
by
unknown
46:31 queued 35:41
created
core/helpers/EEH_DTT_Helper.helper.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     /**
328 328
      * Get Timezone Transitions
329 329
      * @param \DateTimeZone $date_time_zone
330
-     * @param null          $time
330
+     * @param integer|null          $time
331 331
      * @param bool          $first_only
332 332
      * @return array|mixed
333 333
      */
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
     /**
344 344
      * Get Timezone Offset for given timezone object.
345 345
      * @param \DateTimeZone $date_time_zone
346
-     * @param null          $time
346
+     * @param integer|null          $time
347 347
      * @return mixed
348 348
      * @throws \DomainException
349 349
      */
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
      * this method will add that "1" into your date regardless of the format.
1076 1076
      *
1077 1077
      * @param string $month
1078
-     * @return string
1078
+     * @return integer
1079 1079
      */
1080 1080
     public static function first_of_month_timestamp($month = '')
1081 1081
     {
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
     /**
1228 1228
      * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1229 1229
      *
1230
-     * @param int|WP_User $user_id
1230
+     * @param integer $user_id
1231 1231
      * @return string
1232 1232
      */
1233 1233
     public static function get_user_locale($user_id = 0)
Please login to merge, or discard this patch.
Indentation   +1177 added lines, -1177 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -26,364 +26,364 @@  discard block
 block discarded – undo
26 26
 {
27 27
 
28 28
 
29
-    /**
30
-     * return the timezone set for the WP install
31
-     *
32
-     * @return string valid timezone string for PHP DateTimeZone() class
33
-     */
34
-    public static function get_timezone()
35
-    {
36
-        return EEH_DTT_Helper::get_valid_timezone_string();
37
-    }
38
-
39
-
40
-    /**
41
-     * get_valid_timezone_string
42
-     *    ensures that a valid timezone string is returned
43
-     *
44
-     * @access protected
45
-     * @param string $timezone_string
46
-     * @return string
47
-     * @throws \EE_Error
48
-     */
49
-    public static function get_valid_timezone_string($timezone_string = '')
50
-    {
51
-        // if passed a value, then use that, else get WP option
52
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
-        // value from above exists, use that, else get timezone string from gmt_offset
54
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
-        EEH_DTT_Helper::validate_timezone($timezone_string);
56
-        return $timezone_string;
57
-    }
58
-
59
-
60
-    /**
61
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
-     *
63
-     * @static
64
-     * @access public
65
-     * @param  string $timezone_string Timezone string to check
66
-     * @param bool    $throw_error
67
-     * @return bool
68
-     * @throws \EE_Error
69
-     */
70
-    public static function validate_timezone($timezone_string, $throw_error = true)
71
-    {
72
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
-        try {
74
-            new DateTimeZone($timezone_string);
75
-        } catch (Exception $e) {
76
-            // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
78
-                return false;
79
-            }
80
-            throw new EE_Error(
81
-                sprintf(
82
-                    __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
-                        'event_espresso'),
84
-                    $timezone_string,
85
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
86
-                    '</a>'
87
-                )
88
-            );
89
-        }
90
-        return true;
91
-    }
92
-
93
-
94
-    /**
95
-     * _create_timezone_object_from_timezone_name
96
-     *
97
-     * @access protected
98
-     * @param string $gmt_offset
99
-     * @return string
100
-     */
101
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
-    {
103
-        $timezone_string = 'UTC';
104
-        //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
105
-        //set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
106
-        //that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
107
-        if ($gmt_offset === '') {
108
-            //autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
109
-            if (get_option('timezone_string')) {
110
-                return get_option('timezone_string');
111
-            }
112
-        }
113
-        $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset');
114
-        $gmt_offset = (float) $gmt_offset;
115
-
116
-        //if $gmt_offset is 0, then just return UTC
117
-        if ($gmt_offset === (float) 0) {
118
-            return $timezone_string;
119
-        }
120
-
121
-
122
-        if ($gmt_offset !== '') {
123
-            // convert GMT offset to seconds
124
-            $gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
125
-            // although we don't know the TZ abbreviation, we know the UTC offset
126
-            $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
127
-            //only use this timezone_string IF it's current offset matches the given offset
128
-            try {
129
-                $offset = self::get_timezone_offset(new DateTimeZone($timezone_string));
130
-                if ($offset !== $gmt_offset) {
131
-                    $timezone_string = false;
132
-                }
133
-            } catch (Exception $e) {
134
-                $timezone_string = false;
135
-            }
136
-        }
137
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
138
-        $timezone_string = $timezone_string !== false
139
-            ? $timezone_string
140
-            : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
141
-        return $timezone_string;
142
-    }
143
-
144
-    /**
145
-     * Gets the site's GMT offset based on either the timezone string
146
-     * (in which case teh gmt offset will vary depending on the location's
147
-     * observance of daylight savings time) or the gmt_offset wp option
148
-     *
149
-     * @return int seconds offset
150
-     */
151
-    public static function get_site_timezone_gmt_offset()
152
-    {
153
-        $timezone_string = get_option('timezone_string');
154
-        if ($timezone_string) {
155
-            try {
156
-                $timezone = new DateTimeZone($timezone_string);
157
-                return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
158
-            } catch (Exception $e) {
159
-            }
160
-        }
161
-        $offset = get_option('gmt_offset');
162
-        return (int)($offset * HOUR_IN_SECONDS);
163
-    }
164
-
165
-
166
-    /**
167
-     * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its
168
-     * timezone tables.
169
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
170
-     *
171
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
172
-     *
173
-     * @access public
174
-     * @param int $gmt_offset
175
-     * @return int
176
-     */
177
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
178
-    {
179
-        //make sure $gmt_offset is int
180
-        $gmt_offset = (int)$gmt_offset;
181
-        switch ($gmt_offset) {
182
-            //-12
183
-            case -43200:
184
-                $gmt_offset = -39600;
185
-                break;
186
-            //-11.5
187
-            case -41400:
188
-                $gmt_offset = -39600;
189
-                break;
190
-            //-10.5
191
-            case -37800:
192
-                $gmt_offset = -39600;
193
-                break;
194
-            //-8.5
195
-            case -30600:
196
-                $gmt_offset = -28800;
197
-                break;
198
-            //-7.5
199
-            case -27000:
200
-                $gmt_offset = -25200;
201
-                break;
202
-            //-6.5
203
-            case -23400:
204
-                $gmt_offset = -21600;
205
-                break;
206
-            //-5.5
207
-            case -19800:
208
-                $gmt_offset = -18000;
209
-                break;
210
-            //-4.5
211
-            case -16200:
212
-                $gmt_offset = -14400;
213
-                break;
214
-            //-3.5
215
-            case -12600:
216
-                $gmt_offset = -10800;
217
-                break;
218
-            //-2.5
219
-            case -9000:
220
-                $gmt_offset = -7200;
221
-                break;
222
-            //-1.5
223
-            case -5400:
224
-                $gmt_offset = -3600;
225
-                break;
226
-            //-0.5
227
-            case -1800:
228
-                $gmt_offset = 0;
229
-                break;
230
-            //.5
231
-            case 1800:
232
-                $gmt_offset = 3600;
233
-                break;
234
-            //1.5
235
-            case 5400:
236
-                $gmt_offset = 7200;
237
-                break;
238
-            //2.5
239
-            case 9000:
240
-                $gmt_offset = 10800;
241
-                break;
242
-            //3.5
243
-            case 12600:
244
-                $gmt_offset = 14400;
245
-                break;
246
-
247
-            //7.5
248
-            case 27000:
249
-                $gmt_offset = 28800;
250
-                break;
251
-            //8.5
252
-            case 30600:
253
-                $gmt_offset = 31500;
254
-                break;
255
-            //10.5
256
-            case 37800:
257
-                $gmt_offset = 39600;
258
-                break;
259
-            //11.5
260
-            case 41400:
261
-                $gmt_offset = 43200;
262
-                break;
263
-            //12.75
264
-            case 45900:
265
-                $gmt_offset = 46800;
266
-                break;
267
-            //13.75
268
-            case 49500:
269
-                $gmt_offset = 50400;
270
-                break;
271
-        }
272
-        return $gmt_offset;
273
-    }
274
-
275
-
276
-    /**
277
-     * get_timezone_string_from_abbreviations_list
278
-     *
279
-     * @access public
280
-     * @param int  $gmt_offset
281
-     * @param bool $coerce   If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
282
-     * @return string
283
-     * @throws \EE_Error
284
-     */
285
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
286
-    {
287
-        $abbreviations = timezone_abbreviations_list();
288
-        foreach ($abbreviations as $abbreviation) {
289
-            foreach ($abbreviation as $city) {
290
-                if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
291
-                    try {
292
-                        $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id']));
293
-                        if ($offset !== $gmt_offset) {
294
-                            continue;
295
-                        } else {
296
-                            return $city['timezone_id'];
297
-                        }
298
-                    } catch (Exception $e) {
299
-                        continue;
300
-                    }
301
-                }
302
-            }
303
-        }
304
-        //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
305
-        if ($coerce == true) {
306
-            $timezone_string = self::get_timezone_string_from_abbreviations_list(
307
-                self::adjust_invalid_gmt_offsets($gmt_offset),
308
-                false
309
-            );
310
-            if ($timezone_string) {
311
-                return $timezone_string;
312
-            }
313
-        }
314
-        throw new EE_Error(
315
-            sprintf(
316
-                __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
317
-                    'event_espresso'),
318
-                $gmt_offset,
319
-                '<a href="http://www.php.net/manual/en/timezones.php">',
320
-                '</a>'
321
-            )
322
-        );
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * Get Timezone Transitions
329
-     * @param \DateTimeZone $date_time_zone
330
-     * @param null          $time
331
-     * @param bool          $first_only
332
-     * @return array|mixed
333
-     */
334
-    public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
335
-    {
336
-        $time = is_int($time) || $time === null ? $time : strtotime($time);
337
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
338
-        $transitions = $date_time_zone->getTransitions($time);
339
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
340
-    }
341
-
342
-
343
-    /**
344
-     * Get Timezone Offset for given timezone object.
345
-     * @param \DateTimeZone $date_time_zone
346
-     * @param null          $time
347
-     * @return mixed
348
-     * @throws \DomainException
349
-     */
350
-    public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
351
-    {
352
-        $transitions = self::get_timezone_transitions($date_time_zone, $time);
353
-        if (! isset($transitions['offset'])) {
354
-            throw new DomainException();
355
-        }
356
-        return $transitions['offset'];
357
-    }
358
-
359
-
360
-    /**
361
-     * @access public
362
-     * @param string $timezone_string
363
-     */
364
-    public static function timezone_select_input($timezone_string = '')
365
-    {
366
-        // get WP date time format
367
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
368
-        // if passed a value, then use that, else get WP option
369
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
370
-        // check if the timezone is valid but don't throw any errors if it isn't
371
-        $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
372
-        $gmt_offset      = get_option('gmt_offset');
373
-
374
-        $check_zone_info = true;
375
-        if (empty($timezone_string)) {
376
-            // Create a UTC+- zone if no timezone string exists
377
-            $check_zone_info = false;
378
-            if ($gmt_offset > 0) {
379
-                $timezone_string = 'UTC+' . $gmt_offset;
380
-            } elseif ($gmt_offset < 0) {
381
-                $timezone_string = 'UTC' . $gmt_offset;
382
-            } else {
383
-                $timezone_string = 'UTC';
384
-            }
385
-        }
386
-        ?>
29
+	/**
30
+	 * return the timezone set for the WP install
31
+	 *
32
+	 * @return string valid timezone string for PHP DateTimeZone() class
33
+	 */
34
+	public static function get_timezone()
35
+	{
36
+		return EEH_DTT_Helper::get_valid_timezone_string();
37
+	}
38
+
39
+
40
+	/**
41
+	 * get_valid_timezone_string
42
+	 *    ensures that a valid timezone string is returned
43
+	 *
44
+	 * @access protected
45
+	 * @param string $timezone_string
46
+	 * @return string
47
+	 * @throws \EE_Error
48
+	 */
49
+	public static function get_valid_timezone_string($timezone_string = '')
50
+	{
51
+		// if passed a value, then use that, else get WP option
52
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
+		// value from above exists, use that, else get timezone string from gmt_offset
54
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
+		EEH_DTT_Helper::validate_timezone($timezone_string);
56
+		return $timezone_string;
57
+	}
58
+
59
+
60
+	/**
61
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
+	 *
63
+	 * @static
64
+	 * @access public
65
+	 * @param  string $timezone_string Timezone string to check
66
+	 * @param bool    $throw_error
67
+	 * @return bool
68
+	 * @throws \EE_Error
69
+	 */
70
+	public static function validate_timezone($timezone_string, $throw_error = true)
71
+	{
72
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
+		try {
74
+			new DateTimeZone($timezone_string);
75
+		} catch (Exception $e) {
76
+			// sometimes we take exception to exceptions
77
+			if (! $throw_error) {
78
+				return false;
79
+			}
80
+			throw new EE_Error(
81
+				sprintf(
82
+					__('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
+						'event_espresso'),
84
+					$timezone_string,
85
+					'<a href="http://www.php.net/manual/en/timezones.php">',
86
+					'</a>'
87
+				)
88
+			);
89
+		}
90
+		return true;
91
+	}
92
+
93
+
94
+	/**
95
+	 * _create_timezone_object_from_timezone_name
96
+	 *
97
+	 * @access protected
98
+	 * @param string $gmt_offset
99
+	 * @return string
100
+	 */
101
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
+	{
103
+		$timezone_string = 'UTC';
104
+		//if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
105
+		//set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
106
+		//that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
107
+		if ($gmt_offset === '') {
108
+			//autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
109
+			if (get_option('timezone_string')) {
110
+				return get_option('timezone_string');
111
+			}
112
+		}
113
+		$gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset');
114
+		$gmt_offset = (float) $gmt_offset;
115
+
116
+		//if $gmt_offset is 0, then just return UTC
117
+		if ($gmt_offset === (float) 0) {
118
+			return $timezone_string;
119
+		}
120
+
121
+
122
+		if ($gmt_offset !== '') {
123
+			// convert GMT offset to seconds
124
+			$gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
125
+			// although we don't know the TZ abbreviation, we know the UTC offset
126
+			$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
127
+			//only use this timezone_string IF it's current offset matches the given offset
128
+			try {
129
+				$offset = self::get_timezone_offset(new DateTimeZone($timezone_string));
130
+				if ($offset !== $gmt_offset) {
131
+					$timezone_string = false;
132
+				}
133
+			} catch (Exception $e) {
134
+				$timezone_string = false;
135
+			}
136
+		}
137
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
138
+		$timezone_string = $timezone_string !== false
139
+			? $timezone_string
140
+			: EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
141
+		return $timezone_string;
142
+	}
143
+
144
+	/**
145
+	 * Gets the site's GMT offset based on either the timezone string
146
+	 * (in which case teh gmt offset will vary depending on the location's
147
+	 * observance of daylight savings time) or the gmt_offset wp option
148
+	 *
149
+	 * @return int seconds offset
150
+	 */
151
+	public static function get_site_timezone_gmt_offset()
152
+	{
153
+		$timezone_string = get_option('timezone_string');
154
+		if ($timezone_string) {
155
+			try {
156
+				$timezone = new DateTimeZone($timezone_string);
157
+				return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
158
+			} catch (Exception $e) {
159
+			}
160
+		}
161
+		$offset = get_option('gmt_offset');
162
+		return (int)($offset * HOUR_IN_SECONDS);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its
168
+	 * timezone tables.
169
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
170
+	 *
171
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
172
+	 *
173
+	 * @access public
174
+	 * @param int $gmt_offset
175
+	 * @return int
176
+	 */
177
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
178
+	{
179
+		//make sure $gmt_offset is int
180
+		$gmt_offset = (int)$gmt_offset;
181
+		switch ($gmt_offset) {
182
+			//-12
183
+			case -43200:
184
+				$gmt_offset = -39600;
185
+				break;
186
+			//-11.5
187
+			case -41400:
188
+				$gmt_offset = -39600;
189
+				break;
190
+			//-10.5
191
+			case -37800:
192
+				$gmt_offset = -39600;
193
+				break;
194
+			//-8.5
195
+			case -30600:
196
+				$gmt_offset = -28800;
197
+				break;
198
+			//-7.5
199
+			case -27000:
200
+				$gmt_offset = -25200;
201
+				break;
202
+			//-6.5
203
+			case -23400:
204
+				$gmt_offset = -21600;
205
+				break;
206
+			//-5.5
207
+			case -19800:
208
+				$gmt_offset = -18000;
209
+				break;
210
+			//-4.5
211
+			case -16200:
212
+				$gmt_offset = -14400;
213
+				break;
214
+			//-3.5
215
+			case -12600:
216
+				$gmt_offset = -10800;
217
+				break;
218
+			//-2.5
219
+			case -9000:
220
+				$gmt_offset = -7200;
221
+				break;
222
+			//-1.5
223
+			case -5400:
224
+				$gmt_offset = -3600;
225
+				break;
226
+			//-0.5
227
+			case -1800:
228
+				$gmt_offset = 0;
229
+				break;
230
+			//.5
231
+			case 1800:
232
+				$gmt_offset = 3600;
233
+				break;
234
+			//1.5
235
+			case 5400:
236
+				$gmt_offset = 7200;
237
+				break;
238
+			//2.5
239
+			case 9000:
240
+				$gmt_offset = 10800;
241
+				break;
242
+			//3.5
243
+			case 12600:
244
+				$gmt_offset = 14400;
245
+				break;
246
+
247
+			//7.5
248
+			case 27000:
249
+				$gmt_offset = 28800;
250
+				break;
251
+			//8.5
252
+			case 30600:
253
+				$gmt_offset = 31500;
254
+				break;
255
+			//10.5
256
+			case 37800:
257
+				$gmt_offset = 39600;
258
+				break;
259
+			//11.5
260
+			case 41400:
261
+				$gmt_offset = 43200;
262
+				break;
263
+			//12.75
264
+			case 45900:
265
+				$gmt_offset = 46800;
266
+				break;
267
+			//13.75
268
+			case 49500:
269
+				$gmt_offset = 50400;
270
+				break;
271
+		}
272
+		return $gmt_offset;
273
+	}
274
+
275
+
276
+	/**
277
+	 * get_timezone_string_from_abbreviations_list
278
+	 *
279
+	 * @access public
280
+	 * @param int  $gmt_offset
281
+	 * @param bool $coerce   If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
282
+	 * @return string
283
+	 * @throws \EE_Error
284
+	 */
285
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
286
+	{
287
+		$abbreviations = timezone_abbreviations_list();
288
+		foreach ($abbreviations as $abbreviation) {
289
+			foreach ($abbreviation as $city) {
290
+				if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
291
+					try {
292
+						$offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id']));
293
+						if ($offset !== $gmt_offset) {
294
+							continue;
295
+						} else {
296
+							return $city['timezone_id'];
297
+						}
298
+					} catch (Exception $e) {
299
+						continue;
300
+					}
301
+				}
302
+			}
303
+		}
304
+		//if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
305
+		if ($coerce == true) {
306
+			$timezone_string = self::get_timezone_string_from_abbreviations_list(
307
+				self::adjust_invalid_gmt_offsets($gmt_offset),
308
+				false
309
+			);
310
+			if ($timezone_string) {
311
+				return $timezone_string;
312
+			}
313
+		}
314
+		throw new EE_Error(
315
+			sprintf(
316
+				__('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
317
+					'event_espresso'),
318
+				$gmt_offset,
319
+				'<a href="http://www.php.net/manual/en/timezones.php">',
320
+				'</a>'
321
+			)
322
+		);
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * Get Timezone Transitions
329
+	 * @param \DateTimeZone $date_time_zone
330
+	 * @param null          $time
331
+	 * @param bool          $first_only
332
+	 * @return array|mixed
333
+	 */
334
+	public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
335
+	{
336
+		$time = is_int($time) || $time === null ? $time : strtotime($time);
337
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
338
+		$transitions = $date_time_zone->getTransitions($time);
339
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
340
+	}
341
+
342
+
343
+	/**
344
+	 * Get Timezone Offset for given timezone object.
345
+	 * @param \DateTimeZone $date_time_zone
346
+	 * @param null          $time
347
+	 * @return mixed
348
+	 * @throws \DomainException
349
+	 */
350
+	public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
351
+	{
352
+		$transitions = self::get_timezone_transitions($date_time_zone, $time);
353
+		if (! isset($transitions['offset'])) {
354
+			throw new DomainException();
355
+		}
356
+		return $transitions['offset'];
357
+	}
358
+
359
+
360
+	/**
361
+	 * @access public
362
+	 * @param string $timezone_string
363
+	 */
364
+	public static function timezone_select_input($timezone_string = '')
365
+	{
366
+		// get WP date time format
367
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
368
+		// if passed a value, then use that, else get WP option
369
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
370
+		// check if the timezone is valid but don't throw any errors if it isn't
371
+		$timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
372
+		$gmt_offset      = get_option('gmt_offset');
373
+
374
+		$check_zone_info = true;
375
+		if (empty($timezone_string)) {
376
+			// Create a UTC+- zone if no timezone string exists
377
+			$check_zone_info = false;
378
+			if ($gmt_offset > 0) {
379
+				$timezone_string = 'UTC+' . $gmt_offset;
380
+			} elseif ($gmt_offset < 0) {
381
+				$timezone_string = 'UTC' . $gmt_offset;
382
+			} else {
383
+				$timezone_string = 'UTC';
384
+			}
385
+		}
386
+		?>
387 387
 
388 388
         <p>
389 389
             <label for="timezone_string"><?php _e('timezone'); ?></label>
@@ -396,13 +396,13 @@  discard block
 block discarded – undo
396 396
 
397 397
         <p>
398 398
         <span><?php
399
-            printf(
400
-                __('%1$sUTC%2$s time is %3$s'),
401
-                '<abbr title="Coordinated Universal Time">',
402
-                '</abbr>',
403
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
404
-            );
405
-            ?></span>
399
+			printf(
400
+				__('%1$sUTC%2$s time is %3$s'),
401
+				'<abbr title="Coordinated Universal Time">',
402
+				'</abbr>',
403
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
404
+			);
405
+			?></span>
406 406
         <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
407 407
         <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
408 408
     <?php endif; ?>
@@ -411,693 +411,693 @@  discard block
 block discarded – undo
411 411
         <br/>
412 412
         <span>
413 413
 					<?php
414
-                    // Set TZ so localtime works.
415
-                    date_default_timezone_set($timezone_string);
416
-                    $now = localtime(time(), true);
417
-                    if ($now['tm_isdst']) {
418
-                        _e('This timezone is currently in daylight saving time.');
419
-                    } else {
420
-                        _e('This timezone is currently in standard time.');
421
-                    }
422
-                    ?>
414
+					// Set TZ so localtime works.
415
+					date_default_timezone_set($timezone_string);
416
+					$now = localtime(time(), true);
417
+					if ($now['tm_isdst']) {
418
+						_e('This timezone is currently in daylight saving time.');
419
+					} else {
420
+						_e('This timezone is currently in standard time.');
421
+					}
422
+					?>
423 423
             <br/>
424 424
             <?php
425
-            if (function_exists('timezone_transitions_get')) {
426
-                $found                   = false;
427
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
428
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
429
-                $right_now               = time();
430
-                $tr['isdst']             = false;
431
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
432
-                    if ($tr['ts'] > $right_now) {
433
-                        $found = true;
434
-                        break;
435
-                    }
436
-                }
437
-
438
-                if ($found) {
439
-                    $message = $tr['isdst'] ?
440
-                        __(' Daylight saving time begins on: %s.') :
441
-                        __(' Standard time begins  on: %s.');
442
-                    // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
443
-                    printf($message,
444
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
445
-                } else {
446
-                    _e('This timezone does not observe daylight saving time.');
447
-                }
448
-            }
449
-            // Set back to UTC.
450
-            date_default_timezone_set('UTC');
451
-            ?>
425
+			if (function_exists('timezone_transitions_get')) {
426
+				$found                   = false;
427
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
428
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
429
+				$right_now               = time();
430
+				$tr['isdst']             = false;
431
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
432
+					if ($tr['ts'] > $right_now) {
433
+						$found = true;
434
+						break;
435
+					}
436
+				}
437
+
438
+				if ($found) {
439
+					$message = $tr['isdst'] ?
440
+						__(' Daylight saving time begins on: %s.') :
441
+						__(' Standard time begins  on: %s.');
442
+					// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
443
+					printf($message,
444
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
445
+				} else {
446
+					_e('This timezone does not observe daylight saving time.');
447
+				}
448
+			}
449
+			// Set back to UTC.
450
+			date_default_timezone_set('UTC');
451
+			?>
452 452
 				</span></p>
453 453
         <?php
454
-    endif;
455
-    }
456
-
457
-
458
-    /**
459
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
460
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
461
-     * the site is used.
462
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
463
-     * computed timestamp (i.e. date_i18n() )
464
-     *
465
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
466
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
467
-     *                                                site will be used.
468
-     * @return int      $unix_timestamp with the offset applied for the given timezone.
469
-     */
470
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
471
-    {
472
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
473
-        $timezone_string = self::get_valid_timezone_string($timezone_string);
474
-        $TimeZone        = new DateTimeZone($timezone_string);
475
-
476
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
477
-        $offset   = timezone_offset_get($TimeZone, $DateTime);
478
-        return (int)$DateTime->format('U') + (int)$offset;
479
-    }
480
-
481
-
482
-    /**
483
-     *    _set_date_time_field
484
-     *    modifies EE_Base_Class EE_Datetime_Field objects
485
-     *
486
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
487
-     * @param    DateTime    $DateTime            PHP DateTime object
488
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
489
-     * @return    EE_Base_Class
490
-     */
491
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
492
-    {
493
-        // grab current datetime format
494
-        $current_format = $obj->get_format();
495
-        // set new full timestamp format
496
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
497
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
498
-        // set the new date value using a full timestamp format so that no data is lost
499
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
500
-        // reset datetime formats
501
-        $obj->set_date_format($current_format[0]);
502
-        $obj->set_time_format($current_format[1]);
503
-        return $obj;
504
-    }
505
-
506
-
507
-    /**
508
-     *    date_time_add
509
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
510
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
511
-     *
512
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
513
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
514
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
515
-     *                                            minutes, seconds) defaults to years
516
-     * @param  integer       $value               what you want to increment the time by
517
-     * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
518
-     *                                 (chaining)
519
-     */
520
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
521
-    {
522
-        //get the raw UTC date.
523
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
524
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
525
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
526
-    }
527
-
528
-
529
-    /**
530
-     *    date_time_subtract
531
-     *    same as date_time_add except subtracting value instead of adding.
532
-     *
533
-     * @param \EE_Base_Class $obj
534
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
535
-     * @param string         $period
536
-     * @param int            $value
537
-     * @return \EE_Base_Class
538
-     */
539
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
540
-    {
541
-        //get the raw UTC date
542
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
543
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
544
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
545
-    }
546
-
547
-
548
-    /**
549
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
550
-     *
551
-     * @param  DateTime $DateTime DateTime object
552
-     * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
553
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
554
-     * @param  integer  $value    What you want to increment the date by
555
-     * @param  string   $operand  What operand you wish to use for the calculation
556
-     * @return \DateTime return whatever type came in.
557
-     * @throws \EE_Error
558
-     */
559
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
560
-    {
561
-        if (! $DateTime instanceof DateTime) {
562
-            throw new EE_Error(
563
-                sprintf(
564
-                    __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
565
-                    print_r($DateTime, true)
566
-                )
567
-            );
568
-        }
569
-        switch ($period) {
570
-            case 'years' :
571
-                $value = 'P' . $value . 'Y';
572
-                break;
573
-            case 'months' :
574
-                $value = 'P' . $value . 'M';
575
-                break;
576
-            case 'weeks' :
577
-                $value = 'P' . $value . 'W';
578
-                break;
579
-            case 'days' :
580
-                $value = 'P' . $value . 'D';
581
-                break;
582
-            case 'hours' :
583
-                $value = 'PT' . $value . 'H';
584
-                break;
585
-            case 'minutes' :
586
-                $value = 'PT' . $value . 'M';
587
-                break;
588
-            case 'seconds' :
589
-                $value = 'PT' . $value . 'S';
590
-                break;
591
-        }
592
-        switch ($operand) {
593
-            case '+':
594
-                $DateTime->add(new DateInterval($value));
595
-                break;
596
-            case '-':
597
-                $DateTime->sub(new DateInterval($value));
598
-                break;
599
-        }
600
-        return $DateTime;
601
-    }
602
-
603
-
604
-    /**
605
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
606
-     *
607
-     * @param  int     $timestamp Unix timestamp
608
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
609
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
610
-     * @param  integer $value     What you want to increment the date by
611
-     * @param  string  $operand   What operand you wish to use for the calculation
612
-     * @return \DateTime return whatever type came in.
613
-     * @throws \EE_Error
614
-     */
615
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
616
-    {
617
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
618
-            throw new EE_Error(
619
-                sprintf(
620
-                    __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
621
-                    print_r($timestamp, true)
622
-                )
623
-            );
624
-        }
625
-        switch ($period) {
626
-            case 'years' :
627
-                $value = YEAR_IN_SECONDS * $value;
628
-                break;
629
-            case 'months' :
630
-                $value = YEAR_IN_SECONDS / 12 * $value;
631
-                break;
632
-            case 'weeks' :
633
-                $value = WEEK_IN_SECONDS * $value;
634
-                break;
635
-            case 'days' :
636
-                $value = DAY_IN_SECONDS * $value;
637
-                break;
638
-            case 'hours' :
639
-                $value = HOUR_IN_SECONDS * $value;
640
-                break;
641
-            case 'minutes' :
642
-                $value = MINUTE_IN_SECONDS * $value;
643
-                break;
644
-        }
645
-        switch ($operand) {
646
-            case '+':
647
-                $timestamp += $value;
648
-                break;
649
-            case '-':
650
-                $timestamp -= $value;
651
-                break;
652
-        }
653
-        return $timestamp;
654
-    }
655
-
656
-
657
-    /**
658
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
659
-     * parameters and returns the new timestamp or DateTime.
660
-     *
661
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
662
-     * @param  string         $period                a value to indicate what interval is being used in the
663
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
664
-     *                                               'minutes', 'seconds'. Defaults to years.
665
-     * @param  integer        $value                 What you want to increment the date by
666
-     * @param  string         $operand               What operand you wish to use for the calculation
667
-     * @return mixed string|DateTime          return whatever type came in.
668
-     */
669
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
670
-    {
671
-        if ($DateTime_or_timestamp instanceof DateTime) {
672
-            return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
673
-        } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
674
-            return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
675
-        } else {
676
-            //error
677
-            return $DateTime_or_timestamp;
678
-        }
679
-    }
680
-
681
-
682
-    /**
683
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
684
-     * and spit out the js and moment.js equivalent formats.
685
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
686
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
687
-     * time picker.
688
-     *
689
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
690
-     * @param null $date_format_string
691
-     * @param null $time_format_string
692
-     * @return array
693
-     *                array(
694
-     *                'js' => array (
695
-     *                'date' => //date format
696
-     *                'time' => //time format
697
-     *                ),
698
-     *                'moment' => //date and time format.
699
-     *                )
700
-     */
701
-    public static function convert_php_to_js_and_moment_date_formats(
702
-        $date_format_string = null,
703
-        $time_format_string = null
704
-    ) {
705
-        if ($date_format_string === null) {
706
-            $date_format_string = get_option('date_format');
707
-        }
708
-
709
-        if ($time_format_string === null) {
710
-            $time_format_string = get_option('time_format');
711
-        }
712
-
713
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
714
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
715
-
716
-        return array(
717
-            'js'     => array(
718
-                'date' => $date_format['js'],
719
-                'time' => $time_format['js'],
720
-            ),
721
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * This converts incoming format string into js and moment variations.
728
-     *
729
-     * @param string $format_string incoming php format string
730
-     * @return array js and moment formats.
731
-     */
732
-    protected static function _php_to_js_moment_converter($format_string)
733
-    {
734
-        /**
735
-         * This is a map of symbols for formats.
736
-         * The index is the php symbol, the equivalent values are in the array.
737
-         *
738
-         * @var array
739
-         */
740
-        $symbols_map      = array(
741
-            // Day
742
-            //01
743
-            'd' => array(
744
-                'js'     => 'dd',
745
-                'moment' => 'DD',
746
-            ),
747
-            //Mon
748
-            'D' => array(
749
-                'js'     => 'D',
750
-                'moment' => 'ddd',
751
-            ),
752
-            //1,2,...31
753
-            'j' => array(
754
-                'js'     => 'd',
755
-                'moment' => 'D',
756
-            ),
757
-            //Monday
758
-            'l' => array(
759
-                'js'     => 'DD',
760
-                'moment' => 'dddd',
761
-            ),
762
-            //ISO numeric representation of the day of the week (1-6)
763
-            'N' => array(
764
-                'js'     => '',
765
-                'moment' => 'E',
766
-            ),
767
-            //st,nd.rd
768
-            'S' => array(
769
-                'js'     => '',
770
-                'moment' => 'o',
771
-            ),
772
-            //numeric representation of day of week (0-6)
773
-            'w' => array(
774
-                'js'     => '',
775
-                'moment' => 'd',
776
-            ),
777
-            //day of year starting from 0 (0-365)
778
-            'z' => array(
779
-                'js'     => 'o',
780
-                'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
781
-            ),
782
-            // Week
783
-            //ISO-8601 week number of year (weeks starting on monday)
784
-            'W' => array(
785
-                'js'     => '',
786
-                'moment' => 'w',
787
-            ),
788
-            // Month
789
-            // January...December
790
-            'F' => array(
791
-                'js'     => 'MM',
792
-                'moment' => 'MMMM',
793
-            ),
794
-            //01...12
795
-            'm' => array(
796
-                'js'     => 'mm',
797
-                'moment' => 'MM',
798
-            ),
799
-            //Jan...Dec
800
-            'M' => array(
801
-                'js'     => 'M',
802
-                'moment' => 'MMM',
803
-            ),
804
-            //1-12
805
-            'n' => array(
806
-                'js'     => 'm',
807
-                'moment' => 'M',
808
-            ),
809
-            //number of days in given month
810
-            't' => array(
811
-                'js'     => '',
812
-                'moment' => '',
813
-            ),
814
-            // Year
815
-            //whether leap year or not 1/0
816
-            'L' => array(
817
-                'js'     => '',
818
-                'moment' => '',
819
-            ),
820
-            //ISO-8601 year number
821
-            'o' => array(
822
-                'js'     => '',
823
-                'moment' => 'GGGG',
824
-            ),
825
-            //1999...2003
826
-            'Y' => array(
827
-                'js'     => 'yy',
828
-                'moment' => 'YYYY',
829
-            ),
830
-            //99...03
831
-            'y' => array(
832
-                'js'     => 'y',
833
-                'moment' => 'YY',
834
-            ),
835
-            // Time
836
-            // am/pm
837
-            'a' => array(
838
-                'js'     => 'tt',
839
-                'moment' => 'a',
840
-            ),
841
-            // AM/PM
842
-            'A' => array(
843
-                'js'     => 'TT',
844
-                'moment' => 'A',
845
-            ),
846
-            // Swatch Internet Time?!?
847
-            'B' => array(
848
-                'js'     => '',
849
-                'moment' => '',
850
-            ),
851
-            //1...12
852
-            'g' => array(
853
-                'js'     => 'h',
854
-                'moment' => 'h',
855
-            ),
856
-            //0...23
857
-            'G' => array(
858
-                'js'     => 'H',
859
-                'moment' => 'H',
860
-            ),
861
-            //01...12
862
-            'h' => array(
863
-                'js'     => 'hh',
864
-                'moment' => 'hh',
865
-            ),
866
-            //00...23
867
-            'H' => array(
868
-                'js'     => 'HH',
869
-                'moment' => 'HH',
870
-            ),
871
-            //00..59
872
-            'i' => array(
873
-                'js'     => 'mm',
874
-                'moment' => 'mm',
875
-            ),
876
-            //seconds... 00...59
877
-            's' => array(
878
-                'js'     => 'ss',
879
-                'moment' => 'ss',
880
-            ),
881
-            //microseconds
882
-            'u' => array(
883
-                'js'     => '',
884
-                'moment' => '',
885
-            ),
886
-        );
887
-        $jquery_ui_format = "";
888
-        $moment_format    = "";
889
-        $escaping         = false;
890
-        for ($i = 0; $i < strlen($format_string); $i++) {
891
-            $char = $format_string[$i];
892
-            if ($char === '\\') { // PHP date format escaping character
893
-                $i++;
894
-                if ($escaping) {
895
-                    $jquery_ui_format .= $format_string[$i];
896
-                    $moment_format .= $format_string[$i];
897
-                } else {
898
-                    $jquery_ui_format .= '\'' . $format_string[$i];
899
-                    $moment_format .= $format_string[$i];
900
-                }
901
-                $escaping = true;
902
-            } else {
903
-                if ($escaping) {
904
-                    $jquery_ui_format .= "'";
905
-                    $moment_format .= "'";
906
-                    $escaping = false;
907
-                }
908
-                if (isset($symbols_map[$char])) {
909
-                    $jquery_ui_format .= $symbols_map[$char]['js'];
910
-                    $moment_format .= $symbols_map[$char]['moment'];
911
-                } else {
912
-                    $jquery_ui_format .= $char;
913
-                    $moment_format .= $char;
914
-                }
915
-            }
916
-        }
917
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
918
-    }
919
-
920
-
921
-    /**
922
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
923
-     *
924
-     * @param string $format_string   Incoming format string for php date().
925
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
926
-     *                                errors is returned.  So for client code calling, check for is_array() to
927
-     *                                indicate failed validations.
928
-     */
929
-    public static function validate_format_string($format_string)
930
-    {
931
-        $error_msg = array();
932
-        //time format checks
933
-        switch (true) {
934
-            case   strpos($format_string, 'h') !== false  :
935
-            case   strpos($format_string, 'g') !== false :
936
-                /**
937
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
938
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
939
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
940
-                 */
941
-                if (strpos(strtoupper($format_string), 'A') === false) {
942
-                    $error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
943
-                        'event_espresso');
944
-                }
945
-                break;
946
-
947
-        }
948
-
949
-        return empty($error_msg) ? true : $error_msg;
950
-    }
951
-
952
-
953
-    /**
954
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
955
-     *     very next day then this method will return true.
956
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
957
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
958
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
959
-     *
960
-     * @param mixed $date_1
961
-     * @param mixed $date_2
962
-     * @return bool
963
-     */
964
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
965
-    {
966
-
967
-        if (
968
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
969
-            ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
970
-        ) {
971
-            return false;
972
-        }
973
-        return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
974
-    }
975
-
976
-
977
-    /**
978
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
979
-     * Functions.
980
-     *
981
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
982
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
983
-     * @return string
984
-     */
985
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
986
-    {
987
-        try {
988
-            /** need to account for timezone offset on the selects */
989
-            $DateTimeZone = new DateTimeZone($timezone_string);
990
-        } catch (Exception $e) {
991
-            $DateTimeZone = null;
992
-        }
993
-
994
-        /**
995
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
996
-         * Hence we do the calc for DateTimeZone::getOffset.
997
-         */
998
-        $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
999
-        $query_interval = $offset < 0
1000
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
1001
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
1002
-        return $query_interval;
1003
-    }
1004
-
1005
-    /**
1006
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
1007
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
1008
-     * and 'gmt_offset' WordPress options directly; or use the filter
1009
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
1010
-     * (although note that we remove any HTML that may be added)
1011
-     *
1012
-     * @return string
1013
-     */
1014
-    public static function get_timezone_string_for_display()
1015
-    {
1016
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
1017
-        if (! empty($pretty_timezone)) {
1018
-            return esc_html($pretty_timezone);
1019
-        }
1020
-        $timezone_string = get_option('timezone_string');
1021
-        if ($timezone_string) {
1022
-            static $mo_loaded = false;
1023
-            // Load translations for continents and cities just like wp_timezone_choice does
1024
-            if (! $mo_loaded) {
1025
-                $locale = get_locale();
1026
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
1027
-                load_textdomain('continents-cities', $mofile);
1028
-                $mo_loaded = true;
1029
-            }
1030
-            //well that was easy.
1031
-            $parts = explode('/', $timezone_string);
1032
-            //remove the continent
1033
-            unset($parts[0]);
1034
-            $t_parts = array();
1035
-            foreach ($parts as $part) {
1036
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
1037
-            }
1038
-            return implode(' - ', $t_parts);
1039
-        }
1040
-        //they haven't set the timezone string, so let's return a string like "UTC+1"
1041
-        $gmt_offset = get_option('gmt_offset');
1042
-        if (intval($gmt_offset) >= 0) {
1043
-            $prefix = '+';
1044
-        } else {
1045
-            $prefix = '';
1046
-        }
1047
-        $parts = explode('.', (string)$gmt_offset);
1048
-        if (count($parts) === 1) {
1049
-            $parts[1] = '00';
1050
-        } else {
1051
-            //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
1052
-            //to minutes, eg 30 or 15, respectively
1053
-            $hour_fraction = (float)('0.' . $parts[1]);
1054
-            $parts[1]      = (string)$hour_fraction * 60;
1055
-        }
1056
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
1057
-    }
1058
-
1059
-
1060
-
1061
-    /**
1062
-     * So PHP does this awesome thing where if you are trying to get a timestamp
1063
-     * for a month using a string like "February" or "February 2017",
1064
-     * and you don't specify a day as part of your string,
1065
-     * then PHP will use whatever the current day of the month is.
1066
-     * IF the current day of the month happens to be the 30th or 31st,
1067
-     * then PHP gets really confused by a date like February 30,
1068
-     * so instead of saying
1069
-     *      "Hey February only has 28 days (this year)...
1070
-     *      ...you must have meant the last day of the month!"
1071
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
1072
-     * because someone requesting February 30th obviously meant March 1st!
1073
-     * The way around this is to always set the day to the first,
1074
-     * so that the month will stay on the month you wanted.
1075
-     * this method will add that "1" into your date regardless of the format.
1076
-     *
1077
-     * @param string $month
1078
-     * @return string
1079
-     */
1080
-    public static function first_of_month_timestamp($month = '')
1081
-    {
1082
-        $month = (string)$month;
1083
-        $year = '';
1084
-        // check if the incoming string has a year in it or not
1085
-       if (preg_match('/\b\d{4}\b/', $month, $matches)) {
1086
-           $year = $matches[0];
1087
-           // ten remove that from the month string as well as any spaces
1088
-           $month = trim(str_replace($year, '', $month));
1089
-           // add a space before the year
1090
-           $year = " {$year}";
1091
-        }
1092
-        // return timestamp for something like "February 1 2017"
1093
-        return strtotime("{$month} 1{$year}");
1094
-    }
454
+	endif;
455
+	}
456
+
457
+
458
+	/**
459
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
460
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
461
+	 * the site is used.
462
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
463
+	 * computed timestamp (i.e. date_i18n() )
464
+	 *
465
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
466
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
467
+	 *                                                site will be used.
468
+	 * @return int      $unix_timestamp with the offset applied for the given timezone.
469
+	 */
470
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
471
+	{
472
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
473
+		$timezone_string = self::get_valid_timezone_string($timezone_string);
474
+		$TimeZone        = new DateTimeZone($timezone_string);
475
+
476
+		$DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
477
+		$offset   = timezone_offset_get($TimeZone, $DateTime);
478
+		return (int)$DateTime->format('U') + (int)$offset;
479
+	}
480
+
481
+
482
+	/**
483
+	 *    _set_date_time_field
484
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
485
+	 *
486
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
487
+	 * @param    DateTime    $DateTime            PHP DateTime object
488
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
489
+	 * @return    EE_Base_Class
490
+	 */
491
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
492
+	{
493
+		// grab current datetime format
494
+		$current_format = $obj->get_format();
495
+		// set new full timestamp format
496
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
497
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
498
+		// set the new date value using a full timestamp format so that no data is lost
499
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
500
+		// reset datetime formats
501
+		$obj->set_date_format($current_format[0]);
502
+		$obj->set_time_format($current_format[1]);
503
+		return $obj;
504
+	}
505
+
1095 506
 
1096 507
 	/**
1097
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
1098
-	* for this sites timezone, but the timestamp could be some other time GMT.
1099
-    */
1100
-    public static function tomorrow()
508
+	 *    date_time_add
509
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
510
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
511
+	 *
512
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
513
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
514
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
515
+	 *                                            minutes, seconds) defaults to years
516
+	 * @param  integer       $value               what you want to increment the time by
517
+	 * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
518
+	 *                                 (chaining)
519
+	 */
520
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
521
+	{
522
+		//get the raw UTC date.
523
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
524
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
525
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
526
+	}
527
+
528
+
529
+	/**
530
+	 *    date_time_subtract
531
+	 *    same as date_time_add except subtracting value instead of adding.
532
+	 *
533
+	 * @param \EE_Base_Class $obj
534
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
535
+	 * @param string         $period
536
+	 * @param int            $value
537
+	 * @return \EE_Base_Class
538
+	 */
539
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
540
+	{
541
+		//get the raw UTC date
542
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
543
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
544
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
545
+	}
546
+
547
+
548
+	/**
549
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
550
+	 *
551
+	 * @param  DateTime $DateTime DateTime object
552
+	 * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
553
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
554
+	 * @param  integer  $value    What you want to increment the date by
555
+	 * @param  string   $operand  What operand you wish to use for the calculation
556
+	 * @return \DateTime return whatever type came in.
557
+	 * @throws \EE_Error
558
+	 */
559
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
560
+	{
561
+		if (! $DateTime instanceof DateTime) {
562
+			throw new EE_Error(
563
+				sprintf(
564
+					__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
565
+					print_r($DateTime, true)
566
+				)
567
+			);
568
+		}
569
+		switch ($period) {
570
+			case 'years' :
571
+				$value = 'P' . $value . 'Y';
572
+				break;
573
+			case 'months' :
574
+				$value = 'P' . $value . 'M';
575
+				break;
576
+			case 'weeks' :
577
+				$value = 'P' . $value . 'W';
578
+				break;
579
+			case 'days' :
580
+				$value = 'P' . $value . 'D';
581
+				break;
582
+			case 'hours' :
583
+				$value = 'PT' . $value . 'H';
584
+				break;
585
+			case 'minutes' :
586
+				$value = 'PT' . $value . 'M';
587
+				break;
588
+			case 'seconds' :
589
+				$value = 'PT' . $value . 'S';
590
+				break;
591
+		}
592
+		switch ($operand) {
593
+			case '+':
594
+				$DateTime->add(new DateInterval($value));
595
+				break;
596
+			case '-':
597
+				$DateTime->sub(new DateInterval($value));
598
+				break;
599
+		}
600
+		return $DateTime;
601
+	}
602
+
603
+
604
+	/**
605
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
606
+	 *
607
+	 * @param  int     $timestamp Unix timestamp
608
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
609
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
610
+	 * @param  integer $value     What you want to increment the date by
611
+	 * @param  string  $operand   What operand you wish to use for the calculation
612
+	 * @return \DateTime return whatever type came in.
613
+	 * @throws \EE_Error
614
+	 */
615
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
616
+	{
617
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
618
+			throw new EE_Error(
619
+				sprintf(
620
+					__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
621
+					print_r($timestamp, true)
622
+				)
623
+			);
624
+		}
625
+		switch ($period) {
626
+			case 'years' :
627
+				$value = YEAR_IN_SECONDS * $value;
628
+				break;
629
+			case 'months' :
630
+				$value = YEAR_IN_SECONDS / 12 * $value;
631
+				break;
632
+			case 'weeks' :
633
+				$value = WEEK_IN_SECONDS * $value;
634
+				break;
635
+			case 'days' :
636
+				$value = DAY_IN_SECONDS * $value;
637
+				break;
638
+			case 'hours' :
639
+				$value = HOUR_IN_SECONDS * $value;
640
+				break;
641
+			case 'minutes' :
642
+				$value = MINUTE_IN_SECONDS * $value;
643
+				break;
644
+		}
645
+		switch ($operand) {
646
+			case '+':
647
+				$timestamp += $value;
648
+				break;
649
+			case '-':
650
+				$timestamp -= $value;
651
+				break;
652
+		}
653
+		return $timestamp;
654
+	}
655
+
656
+
657
+	/**
658
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
659
+	 * parameters and returns the new timestamp or DateTime.
660
+	 *
661
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
662
+	 * @param  string         $period                a value to indicate what interval is being used in the
663
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
664
+	 *                                               'minutes', 'seconds'. Defaults to years.
665
+	 * @param  integer        $value                 What you want to increment the date by
666
+	 * @param  string         $operand               What operand you wish to use for the calculation
667
+	 * @return mixed string|DateTime          return whatever type came in.
668
+	 */
669
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
670
+	{
671
+		if ($DateTime_or_timestamp instanceof DateTime) {
672
+			return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
673
+		} else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
674
+			return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
675
+		} else {
676
+			//error
677
+			return $DateTime_or_timestamp;
678
+		}
679
+	}
680
+
681
+
682
+	/**
683
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
684
+	 * and spit out the js and moment.js equivalent formats.
685
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
686
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
687
+	 * time picker.
688
+	 *
689
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
690
+	 * @param null $date_format_string
691
+	 * @param null $time_format_string
692
+	 * @return array
693
+	 *                array(
694
+	 *                'js' => array (
695
+	 *                'date' => //date format
696
+	 *                'time' => //time format
697
+	 *                ),
698
+	 *                'moment' => //date and time format.
699
+	 *                )
700
+	 */
701
+	public static function convert_php_to_js_and_moment_date_formats(
702
+		$date_format_string = null,
703
+		$time_format_string = null
704
+	) {
705
+		if ($date_format_string === null) {
706
+			$date_format_string = get_option('date_format');
707
+		}
708
+
709
+		if ($time_format_string === null) {
710
+			$time_format_string = get_option('time_format');
711
+		}
712
+
713
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
714
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
715
+
716
+		return array(
717
+			'js'     => array(
718
+				'date' => $date_format['js'],
719
+				'time' => $time_format['js'],
720
+			),
721
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * This converts incoming format string into js and moment variations.
728
+	 *
729
+	 * @param string $format_string incoming php format string
730
+	 * @return array js and moment formats.
731
+	 */
732
+	protected static function _php_to_js_moment_converter($format_string)
733
+	{
734
+		/**
735
+		 * This is a map of symbols for formats.
736
+		 * The index is the php symbol, the equivalent values are in the array.
737
+		 *
738
+		 * @var array
739
+		 */
740
+		$symbols_map      = array(
741
+			// Day
742
+			//01
743
+			'd' => array(
744
+				'js'     => 'dd',
745
+				'moment' => 'DD',
746
+			),
747
+			//Mon
748
+			'D' => array(
749
+				'js'     => 'D',
750
+				'moment' => 'ddd',
751
+			),
752
+			//1,2,...31
753
+			'j' => array(
754
+				'js'     => 'd',
755
+				'moment' => 'D',
756
+			),
757
+			//Monday
758
+			'l' => array(
759
+				'js'     => 'DD',
760
+				'moment' => 'dddd',
761
+			),
762
+			//ISO numeric representation of the day of the week (1-6)
763
+			'N' => array(
764
+				'js'     => '',
765
+				'moment' => 'E',
766
+			),
767
+			//st,nd.rd
768
+			'S' => array(
769
+				'js'     => '',
770
+				'moment' => 'o',
771
+			),
772
+			//numeric representation of day of week (0-6)
773
+			'w' => array(
774
+				'js'     => '',
775
+				'moment' => 'd',
776
+			),
777
+			//day of year starting from 0 (0-365)
778
+			'z' => array(
779
+				'js'     => 'o',
780
+				'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
781
+			),
782
+			// Week
783
+			//ISO-8601 week number of year (weeks starting on monday)
784
+			'W' => array(
785
+				'js'     => '',
786
+				'moment' => 'w',
787
+			),
788
+			// Month
789
+			// January...December
790
+			'F' => array(
791
+				'js'     => 'MM',
792
+				'moment' => 'MMMM',
793
+			),
794
+			//01...12
795
+			'm' => array(
796
+				'js'     => 'mm',
797
+				'moment' => 'MM',
798
+			),
799
+			//Jan...Dec
800
+			'M' => array(
801
+				'js'     => 'M',
802
+				'moment' => 'MMM',
803
+			),
804
+			//1-12
805
+			'n' => array(
806
+				'js'     => 'm',
807
+				'moment' => 'M',
808
+			),
809
+			//number of days in given month
810
+			't' => array(
811
+				'js'     => '',
812
+				'moment' => '',
813
+			),
814
+			// Year
815
+			//whether leap year or not 1/0
816
+			'L' => array(
817
+				'js'     => '',
818
+				'moment' => '',
819
+			),
820
+			//ISO-8601 year number
821
+			'o' => array(
822
+				'js'     => '',
823
+				'moment' => 'GGGG',
824
+			),
825
+			//1999...2003
826
+			'Y' => array(
827
+				'js'     => 'yy',
828
+				'moment' => 'YYYY',
829
+			),
830
+			//99...03
831
+			'y' => array(
832
+				'js'     => 'y',
833
+				'moment' => 'YY',
834
+			),
835
+			// Time
836
+			// am/pm
837
+			'a' => array(
838
+				'js'     => 'tt',
839
+				'moment' => 'a',
840
+			),
841
+			// AM/PM
842
+			'A' => array(
843
+				'js'     => 'TT',
844
+				'moment' => 'A',
845
+			),
846
+			// Swatch Internet Time?!?
847
+			'B' => array(
848
+				'js'     => '',
849
+				'moment' => '',
850
+			),
851
+			//1...12
852
+			'g' => array(
853
+				'js'     => 'h',
854
+				'moment' => 'h',
855
+			),
856
+			//0...23
857
+			'G' => array(
858
+				'js'     => 'H',
859
+				'moment' => 'H',
860
+			),
861
+			//01...12
862
+			'h' => array(
863
+				'js'     => 'hh',
864
+				'moment' => 'hh',
865
+			),
866
+			//00...23
867
+			'H' => array(
868
+				'js'     => 'HH',
869
+				'moment' => 'HH',
870
+			),
871
+			//00..59
872
+			'i' => array(
873
+				'js'     => 'mm',
874
+				'moment' => 'mm',
875
+			),
876
+			//seconds... 00...59
877
+			's' => array(
878
+				'js'     => 'ss',
879
+				'moment' => 'ss',
880
+			),
881
+			//microseconds
882
+			'u' => array(
883
+				'js'     => '',
884
+				'moment' => '',
885
+			),
886
+		);
887
+		$jquery_ui_format = "";
888
+		$moment_format    = "";
889
+		$escaping         = false;
890
+		for ($i = 0; $i < strlen($format_string); $i++) {
891
+			$char = $format_string[$i];
892
+			if ($char === '\\') { // PHP date format escaping character
893
+				$i++;
894
+				if ($escaping) {
895
+					$jquery_ui_format .= $format_string[$i];
896
+					$moment_format .= $format_string[$i];
897
+				} else {
898
+					$jquery_ui_format .= '\'' . $format_string[$i];
899
+					$moment_format .= $format_string[$i];
900
+				}
901
+				$escaping = true;
902
+			} else {
903
+				if ($escaping) {
904
+					$jquery_ui_format .= "'";
905
+					$moment_format .= "'";
906
+					$escaping = false;
907
+				}
908
+				if (isset($symbols_map[$char])) {
909
+					$jquery_ui_format .= $symbols_map[$char]['js'];
910
+					$moment_format .= $symbols_map[$char]['moment'];
911
+				} else {
912
+					$jquery_ui_format .= $char;
913
+					$moment_format .= $char;
914
+				}
915
+			}
916
+		}
917
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
918
+	}
919
+
920
+
921
+	/**
922
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
923
+	 *
924
+	 * @param string $format_string   Incoming format string for php date().
925
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
926
+	 *                                errors is returned.  So for client code calling, check for is_array() to
927
+	 *                                indicate failed validations.
928
+	 */
929
+	public static function validate_format_string($format_string)
930
+	{
931
+		$error_msg = array();
932
+		//time format checks
933
+		switch (true) {
934
+			case   strpos($format_string, 'h') !== false  :
935
+			case   strpos($format_string, 'g') !== false :
936
+				/**
937
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
938
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
939
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
940
+				 */
941
+				if (strpos(strtoupper($format_string), 'A') === false) {
942
+					$error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
943
+						'event_espresso');
944
+				}
945
+				break;
946
+
947
+		}
948
+
949
+		return empty($error_msg) ? true : $error_msg;
950
+	}
951
+
952
+
953
+	/**
954
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
955
+	 *     very next day then this method will return true.
956
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
957
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
958
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
959
+	 *
960
+	 * @param mixed $date_1
961
+	 * @param mixed $date_2
962
+	 * @return bool
963
+	 */
964
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
965
+	{
966
+
967
+		if (
968
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
969
+			($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
970
+		) {
971
+			return false;
972
+		}
973
+		return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
974
+	}
975
+
976
+
977
+	/**
978
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
979
+	 * Functions.
980
+	 *
981
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
982
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
983
+	 * @return string
984
+	 */
985
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
986
+	{
987
+		try {
988
+			/** need to account for timezone offset on the selects */
989
+			$DateTimeZone = new DateTimeZone($timezone_string);
990
+		} catch (Exception $e) {
991
+			$DateTimeZone = null;
992
+		}
993
+
994
+		/**
995
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
996
+		 * Hence we do the calc for DateTimeZone::getOffset.
997
+		 */
998
+		$offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
999
+		$query_interval = $offset < 0
1000
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
1001
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
1002
+		return $query_interval;
1003
+	}
1004
+
1005
+	/**
1006
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
1007
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
1008
+	 * and 'gmt_offset' WordPress options directly; or use the filter
1009
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
1010
+	 * (although note that we remove any HTML that may be added)
1011
+	 *
1012
+	 * @return string
1013
+	 */
1014
+	public static function get_timezone_string_for_display()
1015
+	{
1016
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
1017
+		if (! empty($pretty_timezone)) {
1018
+			return esc_html($pretty_timezone);
1019
+		}
1020
+		$timezone_string = get_option('timezone_string');
1021
+		if ($timezone_string) {
1022
+			static $mo_loaded = false;
1023
+			// Load translations for continents and cities just like wp_timezone_choice does
1024
+			if (! $mo_loaded) {
1025
+				$locale = get_locale();
1026
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
1027
+				load_textdomain('continents-cities', $mofile);
1028
+				$mo_loaded = true;
1029
+			}
1030
+			//well that was easy.
1031
+			$parts = explode('/', $timezone_string);
1032
+			//remove the continent
1033
+			unset($parts[0]);
1034
+			$t_parts = array();
1035
+			foreach ($parts as $part) {
1036
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
1037
+			}
1038
+			return implode(' - ', $t_parts);
1039
+		}
1040
+		//they haven't set the timezone string, so let's return a string like "UTC+1"
1041
+		$gmt_offset = get_option('gmt_offset');
1042
+		if (intval($gmt_offset) >= 0) {
1043
+			$prefix = '+';
1044
+		} else {
1045
+			$prefix = '';
1046
+		}
1047
+		$parts = explode('.', (string)$gmt_offset);
1048
+		if (count($parts) === 1) {
1049
+			$parts[1] = '00';
1050
+		} else {
1051
+			//convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
1052
+			//to minutes, eg 30 or 15, respectively
1053
+			$hour_fraction = (float)('0.' . $parts[1]);
1054
+			$parts[1]      = (string)$hour_fraction * 60;
1055
+		}
1056
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
1057
+	}
1058
+
1059
+
1060
+
1061
+	/**
1062
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
1063
+	 * for a month using a string like "February" or "February 2017",
1064
+	 * and you don't specify a day as part of your string,
1065
+	 * then PHP will use whatever the current day of the month is.
1066
+	 * IF the current day of the month happens to be the 30th or 31st,
1067
+	 * then PHP gets really confused by a date like February 30,
1068
+	 * so instead of saying
1069
+	 *      "Hey February only has 28 days (this year)...
1070
+	 *      ...you must have meant the last day of the month!"
1071
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
1072
+	 * because someone requesting February 30th obviously meant March 1st!
1073
+	 * The way around this is to always set the day to the first,
1074
+	 * so that the month will stay on the month you wanted.
1075
+	 * this method will add that "1" into your date regardless of the format.
1076
+	 *
1077
+	 * @param string $month
1078
+	 * @return string
1079
+	 */
1080
+	public static function first_of_month_timestamp($month = '')
1081
+	{
1082
+		$month = (string)$month;
1083
+		$year = '';
1084
+		// check if the incoming string has a year in it or not
1085
+	   if (preg_match('/\b\d{4}\b/', $month, $matches)) {
1086
+		   $year = $matches[0];
1087
+		   // ten remove that from the month string as well as any spaces
1088
+		   $month = trim(str_replace($year, '', $month));
1089
+		   // add a space before the year
1090
+		   $year = " {$year}";
1091
+		}
1092
+		// return timestamp for something like "February 1 2017"
1093
+		return strtotime("{$month} 1{$year}");
1094
+	}
1095
+
1096
+	/**
1097
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
1098
+	 * for this sites timezone, but the timestamp could be some other time GMT.
1099
+	 */
1100
+	public static function tomorrow()
1101 1101
 	{
1102 1102
 		//The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
1103 1103
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
@@ -1107,135 +1107,135 @@  discard block
 block discarded – undo
1107 1107
 	}
1108 1108
 
1109 1109
 
1110
-    /**
1111
-     * **
1112
-     * Gives a nicely-formatted list of timezone strings.
1113
-     * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
1114
-     *
1115
-     * @since     4.9.40.rc.008
1116
-     * @staticvar bool $mo_loaded
1117
-     * @staticvar string $locale_loaded
1118
-     * @param string $selected_zone Selected timezone.
1119
-     * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
1120
-     * @return string
1121
-     */
1122
-    public static function wp_timezone_choice($selected_zone, $locale = null)
1123
-    {
1124
-        static $mo_loaded = false, $locale_loaded = null;
1125
-
1126
-        $continents = array(
1127
-            'Africa',
1128
-            'America',
1129
-            'Antarctica',
1130
-            'Arctic',
1131
-            'Asia',
1132
-            'Atlantic',
1133
-            'Australia',
1134
-            'Europe',
1135
-            'Indian',
1136
-            'Pacific',
1137
-        );
1138
-
1139
-        // Load translations for continents and cities.
1140
-        if (! $mo_loaded || $locale !== $locale_loaded) {
1141
-            $locale_loaded = $locale ? $locale : get_locale();
1142
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1143
-            unload_textdomain('continents-cities');
1144
-            load_textdomain('continents-cities', $mofile);
1145
-            $mo_loaded = true;
1146
-        }
1147
-
1148
-        $zonen = array();
1149
-        foreach (timezone_identifiers_list() as $zone) {
1150
-            $zone = explode('/', $zone);
1151
-            if (! in_array($zone[0], $continents)) {
1152
-                continue;
1153
-            }
1154
-
1155
-            // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1156
-            $exists    = array(
1157
-                0 => (isset($zone[0]) && $zone[0]),
1158
-                1 => (isset($zone[1]) && $zone[1]),
1159
-                2 => (isset($zone[2]) && $zone[2]),
1160
-            );
1161
-            $exists[3] = ($exists[0] && 'Etc' !== $zone[0]);
1162
-            $exists[4] = ($exists[1] && $exists[3]);
1163
-            $exists[5] = ($exists[2] && $exists[3]);
1164
-
1165
-            $zonen[] = array(
1166
-                'continent'   => ($exists[0] ? $zone[0] : ''),
1167
-                'city'        => ($exists[1] ? $zone[1] : ''),
1168
-                'subcity'     => ($exists[2] ? $zone[2] : ''),
1169
-                't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''),
1170
-                't_city'      => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''),
1171
-                't_subcity'   => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''),
1172
-            );
1173
-        }
1174
-        usort($zonen, '_wp_timezone_choice_usort_callback');
1175
-
1176
-        $structure = array();
1177
-
1178
-        if (empty($selected_zone)) {
1179
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1180
-        }
1181
-
1182
-        foreach ($zonen as $key => $zone) {
1183
-            // Build value in an array to join later
1184
-            $value = array($zone['continent']);
1185
-
1186
-            if (empty($zone['city'])) {
1187
-                // It's at the continent level (generally won't happen)
1188
-                $display = $zone['t_continent'];
1189
-            } else {
1190
-                // It's inside a continent group
1191
-
1192
-                // Continent optgroup
1193
-                if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1194
-                    $label       = $zone['t_continent'];
1195
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
1196
-                }
1197
-
1198
-                // Add the city to the value
1199
-                $value[] = $zone['city'];
1200
-
1201
-                $display = $zone['t_city'];
1202
-                if (! empty($zone['subcity'])) {
1203
-                    // Add the subcity to the value
1204
-                    $value[] = $zone['subcity'];
1205
-                    $display .= ' - ' . $zone['t_subcity'];
1206
-                }
1207
-            }
1208
-
1209
-            // Build the value
1210
-            $value    = join('/', $value);
1211
-            $selected = '';
1212
-            if ($value === $selected_zone) {
1213
-                $selected = 'selected="selected" ';
1214
-            }
1215
-            $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1216
-
1217
-            // Close continent optgroup
1218
-            if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1219
-                $structure[] = '</optgroup>';
1220
-            }
1221
-        }
1222
-
1223
-        return join("\n", $structure);
1224
-    }
1225
-
1226
-
1227
-    /**
1228
-     * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1229
-     *
1230
-     * @param int|WP_User $user_id
1231
-     * @return string
1232
-     */
1233
-    public static function get_user_locale($user_id = 0)
1234
-    {
1235
-        if (function_exists('get_user_locale')) {
1236
-            return get_user_locale($user_id);
1237
-        }
1238
-        return get_locale();
1239
-    }
1110
+	/**
1111
+	 * **
1112
+	 * Gives a nicely-formatted list of timezone strings.
1113
+	 * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
1114
+	 *
1115
+	 * @since     4.9.40.rc.008
1116
+	 * @staticvar bool $mo_loaded
1117
+	 * @staticvar string $locale_loaded
1118
+	 * @param string $selected_zone Selected timezone.
1119
+	 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
1120
+	 * @return string
1121
+	 */
1122
+	public static function wp_timezone_choice($selected_zone, $locale = null)
1123
+	{
1124
+		static $mo_loaded = false, $locale_loaded = null;
1125
+
1126
+		$continents = array(
1127
+			'Africa',
1128
+			'America',
1129
+			'Antarctica',
1130
+			'Arctic',
1131
+			'Asia',
1132
+			'Atlantic',
1133
+			'Australia',
1134
+			'Europe',
1135
+			'Indian',
1136
+			'Pacific',
1137
+		);
1138
+
1139
+		// Load translations for continents and cities.
1140
+		if (! $mo_loaded || $locale !== $locale_loaded) {
1141
+			$locale_loaded = $locale ? $locale : get_locale();
1142
+			$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1143
+			unload_textdomain('continents-cities');
1144
+			load_textdomain('continents-cities', $mofile);
1145
+			$mo_loaded = true;
1146
+		}
1147
+
1148
+		$zonen = array();
1149
+		foreach (timezone_identifiers_list() as $zone) {
1150
+			$zone = explode('/', $zone);
1151
+			if (! in_array($zone[0], $continents)) {
1152
+				continue;
1153
+			}
1154
+
1155
+			// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1156
+			$exists    = array(
1157
+				0 => (isset($zone[0]) && $zone[0]),
1158
+				1 => (isset($zone[1]) && $zone[1]),
1159
+				2 => (isset($zone[2]) && $zone[2]),
1160
+			);
1161
+			$exists[3] = ($exists[0] && 'Etc' !== $zone[0]);
1162
+			$exists[4] = ($exists[1] && $exists[3]);
1163
+			$exists[5] = ($exists[2] && $exists[3]);
1164
+
1165
+			$zonen[] = array(
1166
+				'continent'   => ($exists[0] ? $zone[0] : ''),
1167
+				'city'        => ($exists[1] ? $zone[1] : ''),
1168
+				'subcity'     => ($exists[2] ? $zone[2] : ''),
1169
+				't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''),
1170
+				't_city'      => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''),
1171
+				't_subcity'   => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''),
1172
+			);
1173
+		}
1174
+		usort($zonen, '_wp_timezone_choice_usort_callback');
1175
+
1176
+		$structure = array();
1177
+
1178
+		if (empty($selected_zone)) {
1179
+			$structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1180
+		}
1181
+
1182
+		foreach ($zonen as $key => $zone) {
1183
+			// Build value in an array to join later
1184
+			$value = array($zone['continent']);
1185
+
1186
+			if (empty($zone['city'])) {
1187
+				// It's at the continent level (generally won't happen)
1188
+				$display = $zone['t_continent'];
1189
+			} else {
1190
+				// It's inside a continent group
1191
+
1192
+				// Continent optgroup
1193
+				if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1194
+					$label       = $zone['t_continent'];
1195
+					$structure[] = '<optgroup label="' . esc_attr($label) . '">';
1196
+				}
1197
+
1198
+				// Add the city to the value
1199
+				$value[] = $zone['city'];
1200
+
1201
+				$display = $zone['t_city'];
1202
+				if (! empty($zone['subcity'])) {
1203
+					// Add the subcity to the value
1204
+					$value[] = $zone['subcity'];
1205
+					$display .= ' - ' . $zone['t_subcity'];
1206
+				}
1207
+			}
1208
+
1209
+			// Build the value
1210
+			$value    = join('/', $value);
1211
+			$selected = '';
1212
+			if ($value === $selected_zone) {
1213
+				$selected = 'selected="selected" ';
1214
+			}
1215
+			$structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1216
+
1217
+			// Close continent optgroup
1218
+			if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1219
+				$structure[] = '</optgroup>';
1220
+			}
1221
+		}
1222
+
1223
+		return join("\n", $structure);
1224
+	}
1225
+
1226
+
1227
+	/**
1228
+	 * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1229
+	 *
1230
+	 * @param int|WP_User $user_id
1231
+	 * @return string
1232
+	 */
1233
+	public static function get_user_locale($user_id = 0)
1234
+	{
1235
+		if (function_exists('get_user_locale')) {
1236
+			return get_user_locale($user_id);
1237
+		}
1238
+		return get_locale();
1239
+	}
1240 1240
 
1241 1241
 }// end class EEH_DTT_Helper
Please login to merge, or discard this patch.
Spacing   +51 added lines, -52 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             new DateTimeZone($timezone_string);
75 75
         } catch (Exception $e) {
76 76
             // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
77
+            if ( ! $throw_error) {
78 78
                 return false;
79 79
             }
80 80
             throw new EE_Error(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             }
160 160
         }
161 161
         $offset = get_option('gmt_offset');
162
-        return (int)($offset * HOUR_IN_SECONDS);
162
+        return (int) ($offset * HOUR_IN_SECONDS);
163 163
     }
164 164
 
165 165
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
178 178
     {
179 179
         //make sure $gmt_offset is int
180
-        $gmt_offset = (int)$gmt_offset;
180
+        $gmt_offset = (int) $gmt_offset;
181 181
         switch ($gmt_offset) {
182 182
             //-12
183 183
             case -43200:
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
     public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
351 351
     {
352 352
         $transitions = self::get_timezone_transitions($date_time_zone, $time);
353
-        if (! isset($transitions['offset'])) {
353
+        if ( ! isset($transitions['offset'])) {
354 354
             throw new DomainException();
355 355
         }
356 356
         return $transitions['offset'];
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
     public static function timezone_select_input($timezone_string = '')
365 365
     {
366 366
         // get WP date time format
367
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
367
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
368 368
         // if passed a value, then use that, else get WP option
369 369
         $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
370 370
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
             // Create a UTC+- zone if no timezone string exists
377 377
             $check_zone_info = false;
378 378
             if ($gmt_offset > 0) {
379
-                $timezone_string = 'UTC+' . $gmt_offset;
379
+                $timezone_string = 'UTC+'.$gmt_offset;
380 380
             } elseif ($gmt_offset < 0) {
381
-                $timezone_string = 'UTC' . $gmt_offset;
381
+                $timezone_string = 'UTC'.$gmt_offset;
382 382
             } else {
383 383
                 $timezone_string = 'UTC';
384 384
             }
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
                 __('%1$sUTC%2$s time is %3$s'),
401 401
                 '<abbr title="Coordinated Universal Time">',
402 402
                 '</abbr>',
403
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
403
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
404 404
             );
405 405
             ?></span>
406
-        <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
407
-        <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
406
+        <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
407
+        <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
408 408
     <?php endif; ?>
409 409
 
410 410
         <?php if ($check_zone_info && $timezone_string) : ?>
@@ -437,11 +437,10 @@  discard block
 block discarded – undo
437 437
 
438 438
                 if ($found) {
439 439
                     $message = $tr['isdst'] ?
440
-                        __(' Daylight saving time begins on: %s.') :
441
-                        __(' Standard time begins  on: %s.');
440
+                        __(' Daylight saving time begins on: %s.') : __(' Standard time begins  on: %s.');
442 441
                     // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
443 442
                     printf($message,
444
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
443
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >');
445 444
                 } else {
446 445
                     _e('This timezone does not observe daylight saving time.');
447 446
                 }
@@ -469,13 +468,13 @@  discard block
 block discarded – undo
469 468
      */
470 469
     public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
471 470
     {
472
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
471
+        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
473 472
         $timezone_string = self::get_valid_timezone_string($timezone_string);
474 473
         $TimeZone        = new DateTimeZone($timezone_string);
475 474
 
476
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
475
+        $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone);
477 476
         $offset   = timezone_offset_get($TimeZone, $DateTime);
478
-        return (int)$DateTime->format('U') + (int)$offset;
477
+        return (int) $DateTime->format('U') + (int) $offset;
479 478
     }
480 479
 
481 480
 
@@ -558,7 +557,7 @@  discard block
 block discarded – undo
558 557
      */
559 558
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
560 559
     {
561
-        if (! $DateTime instanceof DateTime) {
560
+        if ( ! $DateTime instanceof DateTime) {
562 561
             throw new EE_Error(
563 562
                 sprintf(
564 563
                     __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -568,25 +567,25 @@  discard block
 block discarded – undo
568 567
         }
569 568
         switch ($period) {
570 569
             case 'years' :
571
-                $value = 'P' . $value . 'Y';
570
+                $value = 'P'.$value.'Y';
572 571
                 break;
573 572
             case 'months' :
574
-                $value = 'P' . $value . 'M';
573
+                $value = 'P'.$value.'M';
575 574
                 break;
576 575
             case 'weeks' :
577
-                $value = 'P' . $value . 'W';
576
+                $value = 'P'.$value.'W';
578 577
                 break;
579 578
             case 'days' :
580
-                $value = 'P' . $value . 'D';
579
+                $value = 'P'.$value.'D';
581 580
                 break;
582 581
             case 'hours' :
583
-                $value = 'PT' . $value . 'H';
582
+                $value = 'PT'.$value.'H';
584 583
                 break;
585 584
             case 'minutes' :
586
-                $value = 'PT' . $value . 'M';
585
+                $value = 'PT'.$value.'M';
587 586
                 break;
588 587
             case 'seconds' :
589
-                $value = 'PT' . $value . 'S';
588
+                $value = 'PT'.$value.'S';
590 589
                 break;
591 590
         }
592 591
         switch ($operand) {
@@ -614,7 +613,7 @@  discard block
 block discarded – undo
614 613
      */
615 614
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
616 615
     {
617
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
616
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
618 617
             throw new EE_Error(
619 618
                 sprintf(
620 619
                     __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -718,7 +717,7 @@  discard block
 block discarded – undo
718 717
                 'date' => $date_format['js'],
719 718
                 'time' => $time_format['js'],
720 719
             ),
721
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
720
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
722 721
         );
723 722
     }
724 723
 
@@ -737,7 +736,7 @@  discard block
 block discarded – undo
737 736
          *
738 737
          * @var array
739 738
          */
740
-        $symbols_map      = array(
739
+        $symbols_map = array(
741 740
             // Day
742 741
             //01
743 742
             'd' => array(
@@ -895,7 +894,7 @@  discard block
 block discarded – undo
895 894
                     $jquery_ui_format .= $format_string[$i];
896 895
                     $moment_format .= $format_string[$i];
897 896
                 } else {
898
-                    $jquery_ui_format .= '\'' . $format_string[$i];
897
+                    $jquery_ui_format .= '\''.$format_string[$i];
899 898
                     $moment_format .= $format_string[$i];
900 899
                 }
901 900
                 $escaping = true;
@@ -965,7 +964,7 @@  discard block
 block discarded – undo
965 964
     {
966 965
 
967 966
         if (
968
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
967
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
969 968
             ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
970 969
         ) {
971 970
             return false;
@@ -997,8 +996,8 @@  discard block
 block discarded – undo
997 996
          */
998 997
         $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
999 998
         $query_interval = $offset < 0
1000
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
1001
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
999
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
1000
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
1002 1001
         return $query_interval;
1003 1002
     }
1004 1003
 
@@ -1014,16 +1013,16 @@  discard block
 block discarded – undo
1014 1013
     public static function get_timezone_string_for_display()
1015 1014
     {
1016 1015
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
1017
-        if (! empty($pretty_timezone)) {
1016
+        if ( ! empty($pretty_timezone)) {
1018 1017
             return esc_html($pretty_timezone);
1019 1018
         }
1020 1019
         $timezone_string = get_option('timezone_string');
1021 1020
         if ($timezone_string) {
1022 1021
             static $mo_loaded = false;
1023 1022
             // Load translations for continents and cities just like wp_timezone_choice does
1024
-            if (! $mo_loaded) {
1023
+            if ( ! $mo_loaded) {
1025 1024
                 $locale = get_locale();
1026
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
1025
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
1027 1026
                 load_textdomain('continents-cities', $mofile);
1028 1027
                 $mo_loaded = true;
1029 1028
             }
@@ -1044,16 +1043,16 @@  discard block
 block discarded – undo
1044 1043
         } else {
1045 1044
             $prefix = '';
1046 1045
         }
1047
-        $parts = explode('.', (string)$gmt_offset);
1046
+        $parts = explode('.', (string) $gmt_offset);
1048 1047
         if (count($parts) === 1) {
1049 1048
             $parts[1] = '00';
1050 1049
         } else {
1051 1050
             //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
1052 1051
             //to minutes, eg 30 or 15, respectively
1053
-            $hour_fraction = (float)('0.' . $parts[1]);
1054
-            $parts[1]      = (string)$hour_fraction * 60;
1052
+            $hour_fraction = (float) ('0.'.$parts[1]);
1053
+            $parts[1]      = (string) $hour_fraction * 60;
1055 1054
         }
1056
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
1055
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
1057 1056
     }
1058 1057
 
1059 1058
 
@@ -1079,7 +1078,7 @@  discard block
 block discarded – undo
1079 1078
      */
1080 1079
     public static function first_of_month_timestamp($month = '')
1081 1080
     {
1082
-        $month = (string)$month;
1081
+        $month = (string) $month;
1083 1082
         $year = '';
1084 1083
         // check if the incoming string has a year in it or not
1085 1084
        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
@@ -1103,7 +1102,7 @@  discard block
 block discarded – undo
1103 1102
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
1104 1103
 		//not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
1105 1104
 		//final timestamp is equivalent to midnight in this timezone as represented in GMT.
1106
-		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1);
1105
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
1107 1106
 	}
1108 1107
 
1109 1108
 
@@ -1137,9 +1136,9 @@  discard block
 block discarded – undo
1137 1136
         );
1138 1137
 
1139 1138
         // Load translations for continents and cities.
1140
-        if (! $mo_loaded || $locale !== $locale_loaded) {
1139
+        if ( ! $mo_loaded || $locale !== $locale_loaded) {
1141 1140
             $locale_loaded = $locale ? $locale : get_locale();
1142
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1141
+            $mofile        = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo';
1143 1142
             unload_textdomain('continents-cities');
1144 1143
             load_textdomain('continents-cities', $mofile);
1145 1144
             $mo_loaded = true;
@@ -1148,12 +1147,12 @@  discard block
 block discarded – undo
1148 1147
         $zonen = array();
1149 1148
         foreach (timezone_identifiers_list() as $zone) {
1150 1149
             $zone = explode('/', $zone);
1151
-            if (! in_array($zone[0], $continents)) {
1150
+            if ( ! in_array($zone[0], $continents)) {
1152 1151
                 continue;
1153 1152
             }
1154 1153
 
1155 1154
             // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1156
-            $exists    = array(
1155
+            $exists = array(
1157 1156
                 0 => (isset($zone[0]) && $zone[0]),
1158 1157
                 1 => (isset($zone[1]) && $zone[1]),
1159 1158
                 2 => (isset($zone[2]) && $zone[2]),
@@ -1176,7 +1175,7 @@  discard block
 block discarded – undo
1176 1175
         $structure = array();
1177 1176
 
1178 1177
         if (empty($selected_zone)) {
1179
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1178
+            $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>';
1180 1179
         }
1181 1180
 
1182 1181
         foreach ($zonen as $key => $zone) {
@@ -1190,19 +1189,19 @@  discard block
 block discarded – undo
1190 1189
                 // It's inside a continent group
1191 1190
 
1192 1191
                 // Continent optgroup
1193
-                if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1192
+                if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1194 1193
                     $label       = $zone['t_continent'];
1195
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
1194
+                    $structure[] = '<optgroup label="'.esc_attr($label).'">';
1196 1195
                 }
1197 1196
 
1198 1197
                 // Add the city to the value
1199 1198
                 $value[] = $zone['city'];
1200 1199
 
1201 1200
                 $display = $zone['t_city'];
1202
-                if (! empty($zone['subcity'])) {
1201
+                if ( ! empty($zone['subcity'])) {
1203 1202
                     // Add the subcity to the value
1204 1203
                     $value[] = $zone['subcity'];
1205
-                    $display .= ' - ' . $zone['t_subcity'];
1204
+                    $display .= ' - '.$zone['t_subcity'];
1206 1205
                 }
1207 1206
             }
1208 1207
 
@@ -1212,10 +1211,10 @@  discard block
 block discarded – undo
1212 1211
             if ($value === $selected_zone) {
1213 1212
                 $selected = 'selected="selected" ';
1214 1213
             }
1215
-            $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1214
+            $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>";
1216 1215
 
1217 1216
             // Close continent optgroup
1218
-            if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1217
+            if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1219 1218
                 $structure[] = '</optgroup>';
1220 1219
             }
1221 1220
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Indentation   +854 added lines, -854 removed lines patch added patch discarded remove patch
@@ -15,395 +15,395 @@  discard block
 block discarded – undo
15 15
 final class EE_Admin implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @access private
20
-     * @var EE_Admin $_instance
21
-     */
22
-    private static $_instance;
23
-
24
-
25
-    /**
26
-     *@ singleton method used to instantiate class object
27
-     *@ access public
28
-     *@ return class instance
29
-     *
30
-     * @throws \EE_Error
31
-     */
32
-    public static function instance()
33
-    {
34
-        // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
36
-            self::$_instance = new self();
37
-        }
38
-        return self::$_instance;
39
-    }
40
-
41
-
42
-    /**
43
-     * @return EE_Admin
44
-     * @throws EE_Error
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     * class constructor
55
-     *
56
-     * @throws \EE_Error
57
-     */
58
-    protected function __construct()
59
-    {
60
-        // define global EE_Admin constants
61
-        $this->_define_all_constants();
62
-        // set autoloaders for our admin page classes based on included path information
63
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
-        // admin hooks
65
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
-        // load EE_Request_Handler early
67
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
-        add_action('admin_init', array($this, 'admin_init'), 100);
72
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
-
78
-        //reset Environment config (we only do this on admin page loads);
79
-        EE_Registry::instance()->CFG->environment->recheck_values();
80
-
81
-        do_action('AHEE__EE_Admin__loaded');
82
-    }
83
-
84
-
85
-    /**
86
-     * _define_all_constants
87
-     * define constants that are set globally for all admin pages
88
-     *
89
-     * @access private
90
-     * @return void
91
-     */
92
-    private function _define_all_constants()
93
-    {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     *    filter_plugin_actions - adds links to the Plugins page listing
106
-     *
107
-     * @access    public
108
-     * @param    array  $links
109
-     * @param    string $plugin
110
-     * @return    array
111
-     */
112
-    public function filter_plugin_actions($links, $plugin)
113
-    {
114
-        // set $main_file in stone
115
-        static $main_file;
116
-        // if $main_file is not set yet
117
-        if (! $main_file) {
118
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
-        }
120
-        if ($plugin === $main_file) {
121
-            // compare current plugin to this one
122
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
126
-                                    . '</a>';
127
-                array_unshift($links, $maintenance_link);
128
-            } else {
129
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
-                                     . esc_html__('Settings', 'event_espresso')
131
-                                     . '</a>';
132
-                $events_link       = '<a href="admin.php?page=espresso_events">'
133
-                                     . esc_html__('Events', 'event_espresso')
134
-                                     . '</a>';
135
-                // add before other links
136
-                array_unshift($links, $org_settings_link, $events_link);
137
-            }
138
-        }
139
-        return $links;
140
-    }
141
-
142
-
143
-    /**
144
-     *    _get_request
145
-     *
146
-     * @access public
147
-     * @return void
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public function get_request()
152
-    {
153
-        EE_Registry::instance()->load_core('Request_Handler');
154
-        EE_Registry::instance()->load_core('CPT_Strategy');
155
-    }
156
-
157
-
158
-    /**
159
-     *    hide_admin_pages_except_maintenance_mode
160
-     *
161
-     * @access public
162
-     * @param array $admin_page_folder_names
163
-     * @return array
164
-     */
165
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
-    {
167
-        return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
-        );
172
-    }
173
-
174
-
175
-    /**
176
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
-     * EE_Front_Controller's init phases have run
178
-     *
179
-     * @access public
180
-     * @return void
181
-     * @throws EE_Error
182
-     * @throws ReflectionException
183
-     */
184
-    public function init()
185
-    {
186
-        //only enable most of the EE_Admin IF we're not in full maintenance mode
187
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
-            //ok so we want to enable the entire admin
189
-            add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
-            add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
-            add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
-            //at a glance dashboard widget
193
-            add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
-            //filter for get_edit_post_link used on comments for custom post types
195
-            add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
-        }
197
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
-            try {
200
-                //this loads the controller for the admin pages which will setup routing etc
201
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
202
-            } catch (EE_Error $e) {
203
-                $e->get_error();
204
-            }
205
-        }
206
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
-        //make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
-        //exclude EE critical pages from all nav menus and wp_list_pages
211
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
-    }
213
-
214
-
215
-    /**
216
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
-     * normal property on the post_type object.  It's found ONLY in this particular context.
221
-     *
222
-     * @param  object $post_type WP post type object
223
-     * @return object            WP post type object
224
-     */
225
-    public function remove_pages_from_nav_menu($post_type)
226
-    {
227
-        //if this isn't the "pages" post type let's get out
228
-        if ($post_type->name !== 'page') {
229
-            return $post_type;
230
-        }
231
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
-
233
-        $post_type->_default_query = array(
234
-            'post__not_in' => $critical_pages,
235
-        );
236
-        return $post_type;
237
-    }
238
-
239
-
240
-    /**
241
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
-     * metaboxes get shown as well
243
-     *
244
-     * @access public
245
-     * @return void
246
-     */
247
-    public function enable_hidden_ee_nav_menu_metaboxes()
248
-    {
249
-        global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
-            return;
252
-        }
253
-        $user = wp_get_current_user();
254
-        //has this been done yet?
255
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
-            return;
257
-        }
258
-
259
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
-        $initial_meta_boxes = apply_filters(
261
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
-            array(
263
-                'nav-menu-theme-locations',
264
-                'add-page',
265
-                'add-custom-links',
266
-                'add-category',
267
-                'add-espresso_events',
268
-                'add-espresso_venues',
269
-                'add-espresso_event_categories',
270
-                'add-espresso_venue_categories',
271
-                'add-post-type-post',
272
-                'add-post-type-page',
273
-            )
274
-        );
275
-
276
-        if (is_array($hidden_meta_boxes)) {
277
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
-                if (in_array($meta_box_id, $initial_meta_boxes)) {
279
-                    unset($hidden_meta_boxes[$key]);
280
-                }
281
-            }
282
-        }
283
-
284
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
-    }
287
-
288
-
289
-    /**
290
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
-     *
293
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
-     *         addons etc.
295
-     * @access public
296
-     * @return void
297
-     */
298
-    public function register_custom_nav_menu_boxes()
299
-    {
300
-        add_meta_box(
301
-            'add-extra-nav-menu-pages',
302
-            esc_html__('Event Espresso Pages', 'event_espresso'),
303
-            array($this, 'ee_cpt_archive_pages'),
304
-            'nav-menus',
305
-            'side',
306
-            'core'
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
-     *
314
-     * @since   4.3.0
315
-     * @param string $link the original link generated by wp
316
-     * @param int    $id   post id
317
-     * @return string  the (maybe) modified link
318
-     */
319
-    public function modify_edit_post_link($link, $id)
320
-    {
321
-        if (! $post = get_post($id)) {
322
-            return $link;
323
-        }
324
-        if ($post->post_type === 'espresso_attendees') {
325
-            $query_args = array(
326
-                'action' => 'edit_attendee',
327
-                'post'   => $id,
328
-            );
329
-            return EEH_URL::add_query_args_and_nonce(
330
-                $query_args,
331
-                admin_url('admin.php?page=espresso_registrations')
332
-            );
333
-        }
334
-        return $link;
335
-    }
336
-
337
-
338
-    public function ee_cpt_archive_pages()
339
-    {
340
-        global $nav_menu_selected_id;
341
-
342
-        $db_fields   = false;
343
-        $walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
-        $current_tab = 'event-archives';
345
-
346
-        /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
18
+	/**
19
+	 * @access private
20
+	 * @var EE_Admin $_instance
21
+	 */
22
+	private static $_instance;
23
+
24
+
25
+	/**
26
+	 *@ singleton method used to instantiate class object
27
+	 *@ access public
28
+	 *@ return class instance
29
+	 *
30
+	 * @throws \EE_Error
31
+	 */
32
+	public static function instance()
33
+	{
34
+		// check if class object is instantiated
35
+		if (! self::$_instance instanceof EE_Admin) {
36
+			self::$_instance = new self();
37
+		}
38
+		return self::$_instance;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @return EE_Admin
44
+	 * @throws EE_Error
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 * class constructor
55
+	 *
56
+	 * @throws \EE_Error
57
+	 */
58
+	protected function __construct()
59
+	{
60
+		// define global EE_Admin constants
61
+		$this->_define_all_constants();
62
+		// set autoloaders for our admin page classes based on included path information
63
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
+		// admin hooks
65
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
+		// load EE_Request_Handler early
67
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
+		add_action('admin_init', array($this, 'admin_init'), 100);
72
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
+
78
+		//reset Environment config (we only do this on admin page loads);
79
+		EE_Registry::instance()->CFG->environment->recheck_values();
80
+
81
+		do_action('AHEE__EE_Admin__loaded');
82
+	}
83
+
84
+
85
+	/**
86
+	 * _define_all_constants
87
+	 * define constants that are set globally for all admin pages
88
+	 *
89
+	 * @access private
90
+	 * @return void
91
+	 */
92
+	private function _define_all_constants()
93
+	{
94
+		if (! defined('EE_ADMIN_URL')) {
95
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 *    filter_plugin_actions - adds links to the Plugins page listing
106
+	 *
107
+	 * @access    public
108
+	 * @param    array  $links
109
+	 * @param    string $plugin
110
+	 * @return    array
111
+	 */
112
+	public function filter_plugin_actions($links, $plugin)
113
+	{
114
+		// set $main_file in stone
115
+		static $main_file;
116
+		// if $main_file is not set yet
117
+		if (! $main_file) {
118
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
+		}
120
+		if ($plugin === $main_file) {
121
+			// compare current plugin to this one
122
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
126
+									. '</a>';
127
+				array_unshift($links, $maintenance_link);
128
+			} else {
129
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
+									 . esc_html__('Settings', 'event_espresso')
131
+									 . '</a>';
132
+				$events_link       = '<a href="admin.php?page=espresso_events">'
133
+									 . esc_html__('Events', 'event_espresso')
134
+									 . '</a>';
135
+				// add before other links
136
+				array_unshift($links, $org_settings_link, $events_link);
137
+			}
138
+		}
139
+		return $links;
140
+	}
141
+
142
+
143
+	/**
144
+	 *    _get_request
145
+	 *
146
+	 * @access public
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public function get_request()
152
+	{
153
+		EE_Registry::instance()->load_core('Request_Handler');
154
+		EE_Registry::instance()->load_core('CPT_Strategy');
155
+	}
156
+
157
+
158
+	/**
159
+	 *    hide_admin_pages_except_maintenance_mode
160
+	 *
161
+	 * @access public
162
+	 * @param array $admin_page_folder_names
163
+	 * @return array
164
+	 */
165
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
+	{
167
+		return array(
168
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
+		);
172
+	}
173
+
174
+
175
+	/**
176
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
+	 * EE_Front_Controller's init phases have run
178
+	 *
179
+	 * @access public
180
+	 * @return void
181
+	 * @throws EE_Error
182
+	 * @throws ReflectionException
183
+	 */
184
+	public function init()
185
+	{
186
+		//only enable most of the EE_Admin IF we're not in full maintenance mode
187
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
+			//ok so we want to enable the entire admin
189
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
+			//at a glance dashboard widget
193
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
+			//filter for get_edit_post_link used on comments for custom post types
195
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
+		}
197
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
198
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
+			try {
200
+				//this loads the controller for the admin pages which will setup routing etc
201
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
202
+			} catch (EE_Error $e) {
203
+				$e->get_error();
204
+			}
205
+		}
206
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
+		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
+		//exclude EE critical pages from all nav menus and wp_list_pages
211
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
+	}
213
+
214
+
215
+	/**
216
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
221
+	 *
222
+	 * @param  object $post_type WP post type object
223
+	 * @return object            WP post type object
224
+	 */
225
+	public function remove_pages_from_nav_menu($post_type)
226
+	{
227
+		//if this isn't the "pages" post type let's get out
228
+		if ($post_type->name !== 'page') {
229
+			return $post_type;
230
+		}
231
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
+
233
+		$post_type->_default_query = array(
234
+			'post__not_in' => $critical_pages,
235
+		);
236
+		return $post_type;
237
+	}
238
+
239
+
240
+	/**
241
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
+	 * metaboxes get shown as well
243
+	 *
244
+	 * @access public
245
+	 * @return void
246
+	 */
247
+	public function enable_hidden_ee_nav_menu_metaboxes()
248
+	{
249
+		global $wp_meta_boxes, $pagenow;
250
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
+			return;
252
+		}
253
+		$user = wp_get_current_user();
254
+		//has this been done yet?
255
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
+			return;
257
+		}
258
+
259
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
+		$initial_meta_boxes = apply_filters(
261
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
+			array(
263
+				'nav-menu-theme-locations',
264
+				'add-page',
265
+				'add-custom-links',
266
+				'add-category',
267
+				'add-espresso_events',
268
+				'add-espresso_venues',
269
+				'add-espresso_event_categories',
270
+				'add-espresso_venue_categories',
271
+				'add-post-type-post',
272
+				'add-post-type-page',
273
+			)
274
+		);
275
+
276
+		if (is_array($hidden_meta_boxes)) {
277
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
279
+					unset($hidden_meta_boxes[$key]);
280
+				}
281
+			}
282
+		}
283
+
284
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
+	}
287
+
288
+
289
+	/**
290
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
+	 *
293
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
+	 *         addons etc.
295
+	 * @access public
296
+	 * @return void
297
+	 */
298
+	public function register_custom_nav_menu_boxes()
299
+	{
300
+		add_meta_box(
301
+			'add-extra-nav-menu-pages',
302
+			esc_html__('Event Espresso Pages', 'event_espresso'),
303
+			array($this, 'ee_cpt_archive_pages'),
304
+			'nav-menus',
305
+			'side',
306
+			'core'
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
+	 *
314
+	 * @since   4.3.0
315
+	 * @param string $link the original link generated by wp
316
+	 * @param int    $id   post id
317
+	 * @return string  the (maybe) modified link
318
+	 */
319
+	public function modify_edit_post_link($link, $id)
320
+	{
321
+		if (! $post = get_post($id)) {
322
+			return $link;
323
+		}
324
+		if ($post->post_type === 'espresso_attendees') {
325
+			$query_args = array(
326
+				'action' => 'edit_attendee',
327
+				'post'   => $id,
328
+			);
329
+			return EEH_URL::add_query_args_and_nonce(
330
+				$query_args,
331
+				admin_url('admin.php?page=espresso_registrations')
332
+			);
333
+		}
334
+		return $link;
335
+	}
336
+
337
+
338
+	public function ee_cpt_archive_pages()
339
+	{
340
+		global $nav_menu_selected_id;
341
+
342
+		$db_fields   = false;
343
+		$walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
+		$current_tab = 'event-archives';
345
+
346
+		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
347 347
             $current_tab = 'search';
348 348
         }/**/
349 349
 
350
-        $removed_args = array(
351
-            'action',
352
-            'customlink-tab',
353
-            'edit-menu-item',
354
-            'menu-item',
355
-            'page-tab',
356
-            '_wpnonce',
357
-        );
350
+		$removed_args = array(
351
+			'action',
352
+			'customlink-tab',
353
+			'edit-menu-item',
354
+			'menu-item',
355
+			'page-tab',
356
+			'_wpnonce',
357
+		);
358 358
 
359
-        ?>
359
+		?>
360 360
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
361 361
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
362 362
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
363 363
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
364 364
                        href="<?php if ($nav_menu_selected_id) {
365
-                            echo esc_url(
366
-                                add_query_arg(
367
-                                    'extra-nav-menu-pages-tab',
368
-                                    'event-archives',
369
-                                    remove_query_arg($removed_args)
370
-                                )
371
-                            );
372
-                       } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
365
+							echo esc_url(
366
+								add_query_arg(
367
+									'extra-nav-menu-pages-tab',
368
+									'event-archives',
369
+									remove_query_arg($removed_args)
370
+								)
371
+							);
372
+					   } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
373 373
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
374 374
                     </a>
375 375
                 </li>
376 376
 
377 377
                 <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
378
-                echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
-                ?>">
378
+				echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
+				?>">
380 380
                     <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
381 381
                         <?php
382
-                        $pages          = $this->_get_extra_nav_menu_pages_items();
383
-                        $args['walker'] = $walker;
384
-                        echo walk_nav_menu_tree(
385
-                            array_map(
386
-                                array($this, '_setup_extra_nav_menu_pages_items'),
387
-                                $pages
388
-                            ),
389
-                            0,
390
-                            (object) $args
391
-                        );
392
-                        ?>
382
+						$pages          = $this->_get_extra_nav_menu_pages_items();
383
+						$args['walker'] = $walker;
384
+						echo walk_nav_menu_tree(
385
+							array_map(
386
+								array($this, '_setup_extra_nav_menu_pages_items'),
387
+								$pages
388
+							),
389
+							0,
390
+							(object) $args
391
+						);
392
+						?>
393 393
                     </ul>
394 394
                 </div><!-- /.tabs-panel -->
395 395
 
396 396
                 <p class="button-controls">
397 397
                 <span class="list-controls">
398 398
                     <a href="<?php
399
-                    echo esc_url(add_query_arg(
400
-                        array(
401
-                            'extra-nav-menu-pages-tab' => 'event-archives',
402
-                            'selectall'                => 1,
403
-                        ),
404
-                        remove_query_arg($removed_args)
405
-                    ));
406
-                    ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
399
+					echo esc_url(add_query_arg(
400
+						array(
401
+							'extra-nav-menu-pages-tab' => 'event-archives',
402
+							'selectall'                => 1,
403
+						),
404
+						remove_query_arg($removed_args)
405
+					));
406
+					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
407 407
                 </span>
408 408
                 <span class="add-to-menu">
409 409
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -416,491 +416,491 @@  discard block
 block discarded – undo
416 416
 
417 417
         </div><!-- /.posttypediv -->
418 418
         <?php
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns an array of event archive nav items.
424
-     *
425
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
-     *        method we use for getting the extra nav menu items
427
-     * @return array
428
-     */
429
-    private function _get_extra_nav_menu_pages_items()
430
-    {
431
-        $menuitems[] = array(
432
-            'title'       => esc_html__('Event List', 'event_espresso'),
433
-            'url'         => get_post_type_archive_link('espresso_events'),
434
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
-        );
436
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
-    }
438
-
439
-
440
-    /**
441
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
-     * the properties and converts it to the menu item object.
443
-     *
444
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
-     * @param $menu_item_values
446
-     * @return stdClass
447
-     */
448
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
-    {
450
-        $menu_item = new stdClass();
451
-        $keys      = array(
452
-            'ID'               => 0,
453
-            'db_id'            => 0,
454
-            'menu_item_parent' => 0,
455
-            'object_id'        => -1,
456
-            'post_parent'      => 0,
457
-            'type'             => 'custom',
458
-            'object'           => '',
459
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
-            'title'            => '',
461
-            'url'              => '',
462
-            'target'           => '',
463
-            'attr_title'       => '',
464
-            'description'      => '',
465
-            'classes'          => array(),
466
-            'xfn'              => '',
467
-        );
468
-
469
-        foreach ($keys as $key => $value) {
470
-            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
-        }
472
-        return $menu_item;
473
-    }
474
-
475
-
476
-    /**
477
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
-     * EE_Admin_Page route is called.
479
-     *
480
-     * @return void
481
-     */
482
-    public function route_admin_request()
483
-    {
484
-    }
485
-
486
-
487
-    /**
488
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
-     *
490
-     * @return void
491
-     */
492
-    public function wp_loaded()
493
-    {
494
-    }
495
-
496
-
497
-    /**
498
-     * admin_init
499
-     *
500
-     * @access public
501
-     * @return void
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     */
505
-    public function admin_init()
506
-    {
507
-
508
-        /**
509
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
-         * - check if doing post processing.
512
-         * - check if doing post processing of one of EE CPTs
513
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
514
-         */
515
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
-            EE_Registry::instance()->load_core('Register_CPTs');
517
-            EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
-        }
519
-
520
-
521
-        /**
522
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
-         * Pages" tab in the EE General Settings Admin page.
525
-         * This is for user-proofing.
526
-         */
527
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
-    }
529
-
530
-
531
-    /**
532
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
-     *
534
-     * @param string $output Current output.
535
-     * @return string
536
-     */
537
-    public function modify_dropdown_pages($output)
538
-    {
539
-        //get critical pages
540
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
-
542
-        //split current output by line break for easier parsing.
543
-        $split_output = explode("\n", $output);
544
-
545
-        //loop through to remove any critical pages from the array.
546
-        foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
548
-            foreach ($split_output as $key => $haystack) {
549
-                if (strpos($haystack, $needle) !== false) {
550
-                    unset($split_output[$key]);
551
-                }
552
-            }
553
-        }
554
-
555
-        //replace output with the new contents
556
-        return implode("\n", $split_output);
557
-    }
558
-
559
-
560
-    /**
561
-     * enqueue all admin scripts that need loaded for admin pages
562
-     *
563
-     * @access public
564
-     * @return void
565
-     */
566
-    public function enqueue_admin_scripts()
567
-    {
568
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
-        // calls.
571
-        wp_enqueue_script(
572
-            'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
-            array('jquery'),
575
-            EVENT_ESPRESSO_VERSION,
576
-            true
577
-        );
578
-        // register cookie script for future dependencies
579
-        wp_register_script(
580
-            'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
-            array('jquery'),
583
-            '2.1',
584
-            true
585
-        );
586
-        //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
588
-        if (apply_filters('FHEE_load_joyride', false)) {
589
-            //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
-            wp_register_style(
592
-                'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
-                array('joyride-css'),
595
-                EVENT_ESPRESSO_VERSION
596
-            );
597
-            wp_register_script(
598
-                'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
-                array(),
601
-                '2.1',
602
-                true
603
-            );
604
-            //joyride JS
605
-            wp_register_script(
606
-                'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
-                array('jquery-cookie', 'joyride-modernizr'),
609
-                '2.1',
610
-                true
611
-            );
612
-            // wanna go for a joyride?
613
-            wp_enqueue_style('ee-joyride-css');
614
-            wp_enqueue_script('jquery-joyride');
615
-        }
616
-    }
617
-
618
-
619
-    /**
620
-     *    display_admin_notices
621
-     *
622
-     * @access    public
623
-     * @return    string
624
-     */
625
-    public function display_admin_notices()
626
-    {
627
-        echo EE_Error::get_notices();
628
-    }
629
-
630
-
631
-    /**
632
-     *    get_persistent_admin_notices
633
-     *
634
-     * @access    public
635
-     * @return        void
636
-     */
637
-    public function get_persistent_admin_notices()
638
-    {
639
-        // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
640
-        $args       = array(
641
-            'page'   => EE_Registry::instance()->REQ->is_set('page')
642
-                ? EE_Registry::instance()->REQ->get('page')
643
-                : '',
644
-            'action' => EE_Registry::instance()->REQ->is_set('action')
645
-                ? EE_Registry::instance()->REQ->get('action')
646
-                : '',
647
-        );
648
-        $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php'));
649
-        //add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
650
-        //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
651
-        //with this.  But after enough time (indeterminate at this point) we can just remove this notice.
652
-        //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
653
-        if (! get_option('timezone_string')) {
654
-            EE_Error::add_persistent_admin_notice(
655
-                'datetime_fix_notice',
656
-                sprintf(
657
-                    esc_html__(
658
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
659
-                        'event_espresso'
660
-                    ),
661
-                    '<strong>',
662
-                    '</strong>',
663
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
664
-                    '</a>',
665
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
666
-                        array(
667
-                            'page' => 'espresso_maintenance_settings',
668
-                            'action' => 'datetime_tools'
669
-                        ),
670
-                        admin_url('admin.php')
671
-                    ) . '">'
672
-                )
673
-            );
674
-        }
675
-        echo EE_Error::get_persistent_admin_notices($return_url);
676
-    }
677
-
678
-
679
-    /**
680
-     *    dismiss_persistent_admin_notice
681
-     *
682
-     * @access    public
683
-     * @return        void
684
-     */
685
-    public function dismiss_ee_nag_notice_callback()
686
-    {
687
-        EE_Error::dismiss_persistent_admin_notice();
688
-    }
689
-
690
-
691
-    /**
692
-     * @param array $elements
693
-     * @return array
694
-     * @throws \EE_Error
695
-     */
696
-    public function dashboard_glance_items($elements)
697
-    {
698
-        $elements                        = is_array($elements) ? $elements : array($elements);
699
-        $events                          = EEM_Event::instance()->count();
700
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
701
-            array('page' => 'espresso_events'),
702
-            admin_url('admin.php')
703
-        );
704
-        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
705
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
706
-        $registrations                   = EEM_Registration::instance()->count(
707
-            array(
708
-                array(
709
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
710
-                ),
711
-            )
712
-        );
713
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
714
-            array('page' => 'espresso_registrations'),
715
-            admin_url('admin.php')
716
-        );
717
-        $items['registrations']['text']  = sprintf(
718
-            _n('%s Registration', '%s Registrations', $registrations),
719
-            number_format_i18n($registrations)
720
-        );
721
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
722
-
723
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
724
-
725
-        foreach ($items as $type => $item_properties) {
726
-            $elements[] = sprintf(
727
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
728
-                $item_properties['url'],
729
-                $item_properties['title'],
730
-                $item_properties['text']
731
-            );
732
-        }
733
-        return $elements;
734
-    }
735
-
736
-
737
-    /**
738
-     *    check_for_invalid_datetime_formats
739
-     *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
740
-     *    their selected format can be parsed by PHP
741
-     *
742
-     * @access    public
743
-     * @param    $value
744
-     * @param    $option
745
-     * @throws EE_Error
746
-     * @return    string
747
-     */
748
-    public function check_for_invalid_datetime_formats($value, $option)
749
-    {
750
-        // check for date_format or time_format
751
-        switch ($option) {
752
-            case 'date_format':
753
-                $date_time_format = $value . ' ' . get_option('time_format');
754
-                break;
755
-            case 'time_format':
756
-                $date_time_format = get_option('date_format') . ' ' . $value;
757
-                break;
758
-            default:
759
-                $date_time_format = false;
760
-        }
761
-        // do we have a date_time format to check ?
762
-        if ($date_time_format) {
763
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
764
-
765
-            if (is_array($error_msg)) {
766
-                $msg = '<p>'
767
-                       . sprintf(
768
-                           esc_html__(
769
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
770
-                               'event_espresso'
771
-                           ),
772
-                           date($date_time_format),
773
-                           $date_time_format
774
-                       )
775
-                       . '</p><p><ul>';
776
-
777
-
778
-                foreach ($error_msg as $error) {
779
-                    $msg .= '<li>' . $error . '</li>';
780
-                }
781
-
782
-                $msg .= '</ul></p><p>'
783
-                        . sprintf(
784
-                            esc_html__(
785
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
786
-                                'event_espresso'
787
-                            ),
788
-                            '<span style="color:#D54E21;">',
789
-                            '</span>'
790
-                        )
791
-                        . '</p>';
792
-
793
-                // trigger WP settings error
794
-                add_settings_error(
795
-                    'date_format',
796
-                    'date_format',
797
-                    $msg
798
-                );
799
-
800
-                // set format to something valid
801
-                switch ($option) {
802
-                    case 'date_format':
803
-                        $value = 'F j, Y';
804
-                        break;
805
-                    case 'time_format':
806
-                        $value = 'g:i a';
807
-                        break;
808
-                }
809
-            }
810
-        }
811
-        return $value;
812
-    }
813
-
814
-
815
-    /**
816
-     *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
817
-     *
818
-     * @access    public
819
-     * @param $content
820
-     * @return    string
821
-     */
822
-    public function its_eSpresso($content)
823
-    {
824
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
825
-    }
826
-
827
-
828
-    /**
829
-     *    espresso_admin_footer
830
-     *
831
-     * @access    public
832
-     * @return    string
833
-     */
834
-    public function espresso_admin_footer()
835
-    {
836
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
837
-    }
838
-
839
-
840
-    /**
841
-     * static method for registering ee admin page.
842
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
843
-     *
844
-     * @since      4.3.0
845
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
846
-     * @see        EE_Register_Admin_Page::register()
847
-     * @param       $page_basename
848
-     * @param       $page_path
849
-     * @param array $config
850
-     * @return void
851
-     * @throws EE_Error
852
-     */
853
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
854
-    {
855
-        EE_Error::doing_it_wrong(
856
-            __METHOD__,
857
-            sprintf(
858
-                esc_html__(
859
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
860
-                    'event_espresso'
861
-                ),
862
-                $page_basename
863
-            ),
864
-            '4.3'
865
-        );
866
-        if (class_exists('EE_Register_Admin_Page')) {
867
-            $config['page_path'] = $page_path;
868
-        }
869
-        EE_Register_Admin_Page::register($page_basename, $config);
870
-    }
871
-
872
-
873
-    /**
874
-     * @deprecated 4.8.41
875
-     * @access     public
876
-     * @param  int      $post_ID
877
-     * @param  \WP_Post $post
878
-     * @return void
879
-     */
880
-    public static function parse_post_content_on_save($post_ID, $post)
881
-    {
882
-        EE_Error::doing_it_wrong(
883
-            __METHOD__,
884
-            esc_html__('Usage is deprecated', 'event_espresso'),
885
-            '4.8.41'
886
-        );
887
-    }
888
-
889
-
890
-    /**
891
-     * @deprecated 4.8.41
892
-     * @access     public
893
-     * @param  $option
894
-     * @param  $old_value
895
-     * @param  $value
896
-     * @return void
897
-     */
898
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
899
-    {
900
-        EE_Error::doing_it_wrong(
901
-            __METHOD__,
902
-            esc_html__('Usage is deprecated', 'event_espresso'),
903
-            '4.8.41'
904
-        );
905
-    }
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns an array of event archive nav items.
424
+	 *
425
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
+	 *        method we use for getting the extra nav menu items
427
+	 * @return array
428
+	 */
429
+	private function _get_extra_nav_menu_pages_items()
430
+	{
431
+		$menuitems[] = array(
432
+			'title'       => esc_html__('Event List', 'event_espresso'),
433
+			'url'         => get_post_type_archive_link('espresso_events'),
434
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
+		);
436
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
+	}
438
+
439
+
440
+	/**
441
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
+	 * the properties and converts it to the menu item object.
443
+	 *
444
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
+	 * @param $menu_item_values
446
+	 * @return stdClass
447
+	 */
448
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
+	{
450
+		$menu_item = new stdClass();
451
+		$keys      = array(
452
+			'ID'               => 0,
453
+			'db_id'            => 0,
454
+			'menu_item_parent' => 0,
455
+			'object_id'        => -1,
456
+			'post_parent'      => 0,
457
+			'type'             => 'custom',
458
+			'object'           => '',
459
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
+			'title'            => '',
461
+			'url'              => '',
462
+			'target'           => '',
463
+			'attr_title'       => '',
464
+			'description'      => '',
465
+			'classes'          => array(),
466
+			'xfn'              => '',
467
+		);
468
+
469
+		foreach ($keys as $key => $value) {
470
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
+		}
472
+		return $menu_item;
473
+	}
474
+
475
+
476
+	/**
477
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
+	 * EE_Admin_Page route is called.
479
+	 *
480
+	 * @return void
481
+	 */
482
+	public function route_admin_request()
483
+	{
484
+	}
485
+
486
+
487
+	/**
488
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
+	 *
490
+	 * @return void
491
+	 */
492
+	public function wp_loaded()
493
+	{
494
+	}
495
+
496
+
497
+	/**
498
+	 * admin_init
499
+	 *
500
+	 * @access public
501
+	 * @return void
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 */
505
+	public function admin_init()
506
+	{
507
+
508
+		/**
509
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
+		 * - check if doing post processing.
512
+		 * - check if doing post processing of one of EE CPTs
513
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
514
+		 */
515
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
+			EE_Registry::instance()->load_core('Register_CPTs');
517
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
+		}
519
+
520
+
521
+		/**
522
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
+		 * Pages" tab in the EE General Settings Admin page.
525
+		 * This is for user-proofing.
526
+		 */
527
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
+	 *
534
+	 * @param string $output Current output.
535
+	 * @return string
536
+	 */
537
+	public function modify_dropdown_pages($output)
538
+	{
539
+		//get critical pages
540
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
+
542
+		//split current output by line break for easier parsing.
543
+		$split_output = explode("\n", $output);
544
+
545
+		//loop through to remove any critical pages from the array.
546
+		foreach ($critical_pages as $page_id) {
547
+			$needle = 'value="' . $page_id . '"';
548
+			foreach ($split_output as $key => $haystack) {
549
+				if (strpos($haystack, $needle) !== false) {
550
+					unset($split_output[$key]);
551
+				}
552
+			}
553
+		}
554
+
555
+		//replace output with the new contents
556
+		return implode("\n", $split_output);
557
+	}
558
+
559
+
560
+	/**
561
+	 * enqueue all admin scripts that need loaded for admin pages
562
+	 *
563
+	 * @access public
564
+	 * @return void
565
+	 */
566
+	public function enqueue_admin_scripts()
567
+	{
568
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
+		// calls.
571
+		wp_enqueue_script(
572
+			'ee-inject-wp',
573
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
+			array('jquery'),
575
+			EVENT_ESPRESSO_VERSION,
576
+			true
577
+		);
578
+		// register cookie script for future dependencies
579
+		wp_register_script(
580
+			'jquery-cookie',
581
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
+			array('jquery'),
583
+			'2.1',
584
+			true
585
+		);
586
+		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
588
+		if (apply_filters('FHEE_load_joyride', false)) {
589
+			//joyride style
590
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
+			wp_register_style(
592
+				'ee-joyride-css',
593
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
+				array('joyride-css'),
595
+				EVENT_ESPRESSO_VERSION
596
+			);
597
+			wp_register_script(
598
+				'joyride-modernizr',
599
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
+				array(),
601
+				'2.1',
602
+				true
603
+			);
604
+			//joyride JS
605
+			wp_register_script(
606
+				'jquery-joyride',
607
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
+				array('jquery-cookie', 'joyride-modernizr'),
609
+				'2.1',
610
+				true
611
+			);
612
+			// wanna go for a joyride?
613
+			wp_enqueue_style('ee-joyride-css');
614
+			wp_enqueue_script('jquery-joyride');
615
+		}
616
+	}
617
+
618
+
619
+	/**
620
+	 *    display_admin_notices
621
+	 *
622
+	 * @access    public
623
+	 * @return    string
624
+	 */
625
+	public function display_admin_notices()
626
+	{
627
+		echo EE_Error::get_notices();
628
+	}
629
+
630
+
631
+	/**
632
+	 *    get_persistent_admin_notices
633
+	 *
634
+	 * @access    public
635
+	 * @return        void
636
+	 */
637
+	public function get_persistent_admin_notices()
638
+	{
639
+		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
640
+		$args       = array(
641
+			'page'   => EE_Registry::instance()->REQ->is_set('page')
642
+				? EE_Registry::instance()->REQ->get('page')
643
+				: '',
644
+			'action' => EE_Registry::instance()->REQ->is_set('action')
645
+				? EE_Registry::instance()->REQ->get('action')
646
+				: '',
647
+		);
648
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php'));
649
+		//add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
650
+		//@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
651
+		//with this.  But after enough time (indeterminate at this point) we can just remove this notice.
652
+		//this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
653
+		if (! get_option('timezone_string')) {
654
+			EE_Error::add_persistent_admin_notice(
655
+				'datetime_fix_notice',
656
+				sprintf(
657
+					esc_html__(
658
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
659
+						'event_espresso'
660
+					),
661
+					'<strong>',
662
+					'</strong>',
663
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
664
+					'</a>',
665
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
666
+						array(
667
+							'page' => 'espresso_maintenance_settings',
668
+							'action' => 'datetime_tools'
669
+						),
670
+						admin_url('admin.php')
671
+					) . '">'
672
+				)
673
+			);
674
+		}
675
+		echo EE_Error::get_persistent_admin_notices($return_url);
676
+	}
677
+
678
+
679
+	/**
680
+	 *    dismiss_persistent_admin_notice
681
+	 *
682
+	 * @access    public
683
+	 * @return        void
684
+	 */
685
+	public function dismiss_ee_nag_notice_callback()
686
+	{
687
+		EE_Error::dismiss_persistent_admin_notice();
688
+	}
689
+
690
+
691
+	/**
692
+	 * @param array $elements
693
+	 * @return array
694
+	 * @throws \EE_Error
695
+	 */
696
+	public function dashboard_glance_items($elements)
697
+	{
698
+		$elements                        = is_array($elements) ? $elements : array($elements);
699
+		$events                          = EEM_Event::instance()->count();
700
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
701
+			array('page' => 'espresso_events'),
702
+			admin_url('admin.php')
703
+		);
704
+		$items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
705
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
706
+		$registrations                   = EEM_Registration::instance()->count(
707
+			array(
708
+				array(
709
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
710
+				),
711
+			)
712
+		);
713
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
714
+			array('page' => 'espresso_registrations'),
715
+			admin_url('admin.php')
716
+		);
717
+		$items['registrations']['text']  = sprintf(
718
+			_n('%s Registration', '%s Registrations', $registrations),
719
+			number_format_i18n($registrations)
720
+		);
721
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
722
+
723
+		$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
724
+
725
+		foreach ($items as $type => $item_properties) {
726
+			$elements[] = sprintf(
727
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
728
+				$item_properties['url'],
729
+				$item_properties['title'],
730
+				$item_properties['text']
731
+			);
732
+		}
733
+		return $elements;
734
+	}
735
+
736
+
737
+	/**
738
+	 *    check_for_invalid_datetime_formats
739
+	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
740
+	 *    their selected format can be parsed by PHP
741
+	 *
742
+	 * @access    public
743
+	 * @param    $value
744
+	 * @param    $option
745
+	 * @throws EE_Error
746
+	 * @return    string
747
+	 */
748
+	public function check_for_invalid_datetime_formats($value, $option)
749
+	{
750
+		// check for date_format or time_format
751
+		switch ($option) {
752
+			case 'date_format':
753
+				$date_time_format = $value . ' ' . get_option('time_format');
754
+				break;
755
+			case 'time_format':
756
+				$date_time_format = get_option('date_format') . ' ' . $value;
757
+				break;
758
+			default:
759
+				$date_time_format = false;
760
+		}
761
+		// do we have a date_time format to check ?
762
+		if ($date_time_format) {
763
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
764
+
765
+			if (is_array($error_msg)) {
766
+				$msg = '<p>'
767
+					   . sprintf(
768
+						   esc_html__(
769
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
770
+							   'event_espresso'
771
+						   ),
772
+						   date($date_time_format),
773
+						   $date_time_format
774
+					   )
775
+					   . '</p><p><ul>';
776
+
777
+
778
+				foreach ($error_msg as $error) {
779
+					$msg .= '<li>' . $error . '</li>';
780
+				}
781
+
782
+				$msg .= '</ul></p><p>'
783
+						. sprintf(
784
+							esc_html__(
785
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
786
+								'event_espresso'
787
+							),
788
+							'<span style="color:#D54E21;">',
789
+							'</span>'
790
+						)
791
+						. '</p>';
792
+
793
+				// trigger WP settings error
794
+				add_settings_error(
795
+					'date_format',
796
+					'date_format',
797
+					$msg
798
+				);
799
+
800
+				// set format to something valid
801
+				switch ($option) {
802
+					case 'date_format':
803
+						$value = 'F j, Y';
804
+						break;
805
+					case 'time_format':
806
+						$value = 'g:i a';
807
+						break;
808
+				}
809
+			}
810
+		}
811
+		return $value;
812
+	}
813
+
814
+
815
+	/**
816
+	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
817
+	 *
818
+	 * @access    public
819
+	 * @param $content
820
+	 * @return    string
821
+	 */
822
+	public function its_eSpresso($content)
823
+	{
824
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
825
+	}
826
+
827
+
828
+	/**
829
+	 *    espresso_admin_footer
830
+	 *
831
+	 * @access    public
832
+	 * @return    string
833
+	 */
834
+	public function espresso_admin_footer()
835
+	{
836
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
837
+	}
838
+
839
+
840
+	/**
841
+	 * static method for registering ee admin page.
842
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
843
+	 *
844
+	 * @since      4.3.0
845
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
846
+	 * @see        EE_Register_Admin_Page::register()
847
+	 * @param       $page_basename
848
+	 * @param       $page_path
849
+	 * @param array $config
850
+	 * @return void
851
+	 * @throws EE_Error
852
+	 */
853
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
854
+	{
855
+		EE_Error::doing_it_wrong(
856
+			__METHOD__,
857
+			sprintf(
858
+				esc_html__(
859
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
860
+					'event_espresso'
861
+				),
862
+				$page_basename
863
+			),
864
+			'4.3'
865
+		);
866
+		if (class_exists('EE_Register_Admin_Page')) {
867
+			$config['page_path'] = $page_path;
868
+		}
869
+		EE_Register_Admin_Page::register($page_basename, $config);
870
+	}
871
+
872
+
873
+	/**
874
+	 * @deprecated 4.8.41
875
+	 * @access     public
876
+	 * @param  int      $post_ID
877
+	 * @param  \WP_Post $post
878
+	 * @return void
879
+	 */
880
+	public static function parse_post_content_on_save($post_ID, $post)
881
+	{
882
+		EE_Error::doing_it_wrong(
883
+			__METHOD__,
884
+			esc_html__('Usage is deprecated', 'event_espresso'),
885
+			'4.8.41'
886
+		);
887
+	}
888
+
889
+
890
+	/**
891
+	 * @deprecated 4.8.41
892
+	 * @access     public
893
+	 * @param  $option
894
+	 * @param  $old_value
895
+	 * @param  $value
896
+	 * @return void
897
+	 */
898
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
899
+	{
900
+		EE_Error::doing_it_wrong(
901
+			__METHOD__,
902
+			esc_html__('Usage is deprecated', 'event_espresso'),
903
+			'4.8.41'
904
+		);
905
+	}
906 906
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     public static function instance()
33 33
     {
34 34
         // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
35
+        if ( ! self::$_instance instanceof EE_Admin) {
36 36
             self::$_instance = new self();
37 37
         }
38 38
         return self::$_instance;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function _define_all_constants()
93 93
     {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
94
+        if ( ! defined('EE_ADMIN_URL')) {
95
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
96
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
97
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
98
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
99 99
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100 100
         }
101 101
     }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         // set $main_file in stone
115 115
         static $main_file;
116 116
         // if $main_file is not set yet
117
-        if (! $main_file) {
117
+        if ( ! $main_file) {
118 118
             $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119 119
         }
120 120
         if ($plugin === $main_file) {
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166 166
     {
167 167
         return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
168
+            'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
169
+            'about'       => EE_ADMIN_PAGES.'about'.DS,
170
+            'support'     => EE_ADMIN_PAGES.'support'.DS,
171 171
         );
172 172
     }
173 173
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196 196
         }
197 197
         // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
198
+        if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199 199
             try {
200 200
                 //this loads the controller for the admin pages which will setup routing etc
201 201
                 EE_Registry::instance()->load_core('Admin_Page_Loader');
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function enable_hidden_ee_nav_menu_metaboxes()
248 248
     {
249 249
         global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
250
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251 251
             return;
252 252
         }
253 253
         $user = wp_get_current_user();
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      */
319 319
     public function modify_edit_post_link($link, $id)
320 320
     {
321
-        if (! $post = get_post($id)) {
321
+        if ( ! $post = get_post($id)) {
322 322
             return $link;
323 323
         }
324 324
         if ($post->post_type === 'espresso_attendees') {
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 
545 545
         //loop through to remove any critical pages from the array.
546 546
         foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
547
+            $needle = 'value="'.$page_id.'"';
548 548
             foreach ($split_output as $key => $haystack) {
549 549
                 if (strpos($haystack, $needle) !== false) {
550 550
                     unset($split_output[$key]);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         // calls.
571 571
         wp_enqueue_script(
572 572
             'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
573
+            EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js',
574 574
             array('jquery'),
575 575
             EVENT_ESPRESSO_VERSION,
576 576
             true
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
         // register cookie script for future dependencies
579 579
         wp_register_script(
580 580
             'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
581
+            EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js',
582 582
             array('jquery'),
583 583
             '2.1',
584 584
             true
@@ -587,16 +587,16 @@  discard block
 block discarded – undo
587 587
         // via: add_filter('FHEE_load_joyride', '__return_true' );
588 588
         if (apply_filters('FHEE_load_joyride', false)) {
589 589
             //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
590
+            wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
591 591
             wp_register_style(
592 592
                 'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
593
+                EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css',
594 594
                 array('joyride-css'),
595 595
                 EVENT_ESPRESSO_VERSION
596 596
             );
597 597
             wp_register_script(
598 598
                 'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
599
+                EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js',
600 600
                 array(),
601 601
                 '2.1',
602 602
                 true
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
             //joyride JS
605 605
             wp_register_script(
606 606
                 'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
607
+                EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js',
608 608
                 array('jquery-cookie', 'joyride-modernizr'),
609 609
                 '2.1',
610 610
                 true
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
     public function get_persistent_admin_notices()
638 638
     {
639 639
         // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
640
-        $args       = array(
640
+        $args = array(
641 641
             'page'   => EE_Registry::instance()->REQ->is_set('page')
642 642
                 ? EE_Registry::instance()->REQ->get('page')
643 643
                 : '',
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
651 651
         //with this.  But after enough time (indeterminate at this point) we can just remove this notice.
652 652
         //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
653
-        if (! get_option('timezone_string')) {
653
+        if ( ! get_option('timezone_string')) {
654 654
             EE_Error::add_persistent_admin_notice(
655 655
                 'datetime_fix_notice',
656 656
                 sprintf(
@@ -662,13 +662,13 @@  discard block
 block discarded – undo
662 662
                     '</strong>',
663 663
                     '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
664 664
                     '</a>',
665
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
665
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
666 666
                         array(
667 667
                             'page' => 'espresso_maintenance_settings',
668 668
                             'action' => 'datetime_tools'
669 669
                         ),
670 670
                         admin_url('admin.php')
671
-                    ) . '">'
671
+                    ).'">'
672 672
                 )
673 673
             );
674 674
         }
@@ -710,21 +710,21 @@  discard block
 block discarded – undo
710 710
                 ),
711 711
             )
712 712
         );
713
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
713
+        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
714 714
             array('page' => 'espresso_registrations'),
715 715
             admin_url('admin.php')
716 716
         );
717
-        $items['registrations']['text']  = sprintf(
717
+        $items['registrations']['text'] = sprintf(
718 718
             _n('%s Registration', '%s Registrations', $registrations),
719 719
             number_format_i18n($registrations)
720 720
         );
721 721
         $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
722 722
 
723
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
723
+        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
724 724
 
725 725
         foreach ($items as $type => $item_properties) {
726 726
             $elements[] = sprintf(
727
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
727
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
728 728
                 $item_properties['url'],
729 729
                 $item_properties['title'],
730 730
                 $item_properties['text']
@@ -750,10 +750,10 @@  discard block
 block discarded – undo
750 750
         // check for date_format or time_format
751 751
         switch ($option) {
752 752
             case 'date_format':
753
-                $date_time_format = $value . ' ' . get_option('time_format');
753
+                $date_time_format = $value.' '.get_option('time_format');
754 754
                 break;
755 755
             case 'time_format':
756
-                $date_time_format = get_option('date_format') . ' ' . $value;
756
+                $date_time_format = get_option('date_format').' '.$value;
757 757
                 break;
758 758
             default:
759 759
                 $date_time_format = false;
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 
777 777
 
778 778
                 foreach ($error_msg as $error) {
779
-                    $msg .= '<li>' . $error . '</li>';
779
+                    $msg .= '<li>'.$error.'</li>';
780 780
                 }
781 781
 
782 782
                 $msg .= '</ul></p><p>'
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 1 patch
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -15,753 +15,753 @@
 block discarded – undo
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 \EE_Error
246
-     */
247
-    public function set_timezone($timezone_string)
248
-    {
249
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
250
-            // leave the timezone AS-IS if we already have one and
251
-            // the function arg didn't provide one
252
-            return;
253
-        }
254
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
-    }
258
-
259
-
260
-    /**
261
-     * _create_timezone_object_from_timezone_name
262
-     *
263
-     * @access protected
264
-     * @param string $timezone_string
265
-     * @return \DateTimeZone
266
-     * @throws \EE_Error
267
-     */
268
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
-    {
270
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
-    }
272
-
273
-
274
-    /**
275
-     * This just returns whatever is set for the current timezone.
276
-     *
277
-     * @access public
278
-     * @return string timezone string
279
-     */
280
-    public function get_timezone()
281
-    {
282
-        return $this->_timezone_string;
283
-    }
284
-
285
-
286
-    /**
287
-     * set the $_date_format property
288
-     *
289
-     * @access public
290
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
-     * @param bool   $pretty Whether to set pretty format or not.
292
-     * @return void
293
-     */
294
-    public function set_date_format($format, $pretty = false)
295
-    {
296
-        if ($pretty) {
297
-            $this->_pretty_date_format = $format;
298
-        } else {
299
-            $this->_date_format = $format;
300
-        }
301
-    }
302
-
303
-
304
-    /**
305
-     * return the $_date_format property value.
306
-     *
307
-     * @param bool $pretty Whether to get pretty format or not.
308
-     * @return string
309
-     */
310
-    public function get_date_format($pretty = false)
311
-    {
312
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
-    }
314
-
315
-
316
-    /**
317
-     * set the $_time_format property
318
-     *
319
-     * @access public
320
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
-     * @param bool   $pretty Whether to set pretty format or not.
322
-     * @return void
323
-     */
324
-    public function set_time_format($format, $pretty = false)
325
-    {
326
-        if ($pretty) {
327
-            $this->_pretty_time_format = $format;
328
-        } else {
329
-            $this->_time_format = $format;
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     * return the $_time_format property value.
336
-     *
337
-     * @param bool $pretty Whether to get pretty format or not.
338
-     * @return string
339
-     */
340
-    public function get_time_format($pretty = false)
341
-    {
342
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
-    }
344
-
345
-
346
-    /**
347
-     * set the $_pretty_date_format property
348
-     *
349
-     * @access public
350
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
-     * @return void
352
-     */
353
-    public function set_pretty_date_format($format)
354
-    {
355
-        $this->_pretty_date_format = $format;
356
-    }
357
-
358
-
359
-    /**
360
-     * set the $_pretty_time_format property
361
-     *
362
-     * @access public
363
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
-     * @return void
365
-     */
366
-    public function set_pretty_time_format($format)
367
-    {
368
-        $this->_pretty_time_format = $format;
369
-    }
370
-
371
-
372
-    /**
373
-     * Only sets the time portion of the datetime.
374
-     *
375
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
-     * @param DateTime        $current            current DateTime object for the datetime field
377
-     * @return DateTime
378
-     */
379
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
-    {
381
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
-        // Otherwise parse the string.
383
-        if ($time_to_set_string instanceof DateTime) {
384
-            $parsed = array(
385
-                'hour'   => $time_to_set_string->format('H'),
386
-                'minute' => $time_to_set_string->format('i'),
387
-                'second' => $time_to_set_string->format('s'),
388
-            );
389
-        } else {
390
-            //parse incoming string
391
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
-        }
393
-
394
-        //make sure $current is in the correct timezone.
395
-        $current->setTimezone($this->_DateTimeZone);
396
-
397
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
-    }
399
-
400
-
401
-    /**
402
-     * Only sets the date portion of the datetime.
403
-     *
404
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
-     * @param DateTime        $current            current DateTime object for the datetime field
406
-     * @return DateTime
407
-     */
408
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
-    {
410
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
-        // Otherwise parse the string.
412
-        if ($date_to_set_string instanceof DateTime) {
413
-            $parsed = array(
414
-                'year'  => $date_to_set_string->format('Y'),
415
-                'month' => $date_to_set_string->format('m'),
416
-                'day'   => $date_to_set_string->format('d'),
417
-            );
418
-        } else {
419
-            //parse incoming string
420
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
-        }
422
-
423
-        //make sure $current is in the correct timezone
424
-        $current->setTimezone($this->_DateTimeZone);
425
-
426
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
-    }
428
-
429
-
430
-    /**
431
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
-     * datetime gets to this stage it should ALREADY be in UTC time
433
-     *
434
-     * @param  DateTime $DateTime
435
-     * @return string formatted date time for given timezone
436
-     * @throws \EE_Error
437
-     */
438
-    public function prepare_for_get($DateTime)
439
-    {
440
-        return $this->_prepare_for_display($DateTime);
441
-    }
442
-
443
-
444
-    /**
445
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
-     * abbreviation to the date_string.
449
-     *
450
-     * @param mixed $DateTime
451
-     * @param null  $schema
452
-     * @return string
453
-     * @throws \EE_Error
454
-     */
455
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
-    {
457
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
-    }
459
-
460
-
461
-    /**
462
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
-     * timezone).
464
-     *
465
-     * @param DateTime    $DateTime
466
-     * @param bool|string $schema
467
-     * @return string
468
-     * @throws \EE_Error
469
-     */
470
-    protected function _prepare_for_display($DateTime, $schema = false)
471
-    {
472
-        if (! $DateTime instanceof DateTime) {
473
-            if ($this->_nullable) {
474
-                return '';
475
-            } else {
476
-                if (WP_DEBUG) {
477
-                    throw new EE_Error(
478
-                        sprintf(
479
-                            __(
480
-                                '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.',
481
-                                'event_espresso'
482
-                            ),
483
-                            $this->_nicename
484
-                        )
485
-                    );
486
-                } else {
487
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
-                    EE_Error::add_error(
489
-                        sprintf(
490
-                            __(
491
-                                '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.',
492
-                                'event_espresso'
493
-                            ),
494
-                            $this->_nicename
495
-                        )
496
-                    );
497
-                }
498
-            }
499
-        }
500
-        $format_string = $this->_get_date_time_output($schema);
501
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
502
-        $DateTime->setTimezone($this->_DateTimeZone);
503
-        if ($schema) {
504
-            if ($this->_display_timezone()) {
505
-                //must be explicit because schema could equal true.
506
-                if ($schema === 'no_html') {
507
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
508
-                } else {
509
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
-                }
511
-            } else {
512
-                $timezone_string = '';
513
-            }
514
-
515
-            return $DateTime->format($format_string) . $timezone_string;
516
-        } else {
517
-            return $DateTime->format($format_string);
518
-        }
519
-    }
520
-
521
-
522
-    /**
523
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
-     * timezone).
525
-     *
526
-     * @param  mixed $datetime_value u
527
-     * @return string mysql timestamp in UTC
528
-     * @throws \EE_Error
529
-     */
530
-    public function prepare_for_use_in_db($datetime_value)
531
-    {
532
-        //we allow an empty value or DateTime object, but nothing else.
533
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
-            throw new EE_Error(
535
-            	sprintf(
536
-            	    __(
537
-            		    '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 \EE_Error
246
+	 */
247
+	public function set_timezone($timezone_string)
248
+	{
249
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
250
+			// leave the timezone AS-IS if we already have one and
251
+			// the function arg didn't provide one
252
+			return;
253
+		}
254
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
+	}
258
+
259
+
260
+	/**
261
+	 * _create_timezone_object_from_timezone_name
262
+	 *
263
+	 * @access protected
264
+	 * @param string $timezone_string
265
+	 * @return \DateTimeZone
266
+	 * @throws \EE_Error
267
+	 */
268
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
+	{
270
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
+	}
272
+
273
+
274
+	/**
275
+	 * This just returns whatever is set for the current timezone.
276
+	 *
277
+	 * @access public
278
+	 * @return string timezone string
279
+	 */
280
+	public function get_timezone()
281
+	{
282
+		return $this->_timezone_string;
283
+	}
284
+
285
+
286
+	/**
287
+	 * set the $_date_format property
288
+	 *
289
+	 * @access public
290
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
+	 * @param bool   $pretty Whether to set pretty format or not.
292
+	 * @return void
293
+	 */
294
+	public function set_date_format($format, $pretty = false)
295
+	{
296
+		if ($pretty) {
297
+			$this->_pretty_date_format = $format;
298
+		} else {
299
+			$this->_date_format = $format;
300
+		}
301
+	}
302
+
303
+
304
+	/**
305
+	 * return the $_date_format property value.
306
+	 *
307
+	 * @param bool $pretty Whether to get pretty format or not.
308
+	 * @return string
309
+	 */
310
+	public function get_date_format($pretty = false)
311
+	{
312
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
+	}
314
+
315
+
316
+	/**
317
+	 * set the $_time_format property
318
+	 *
319
+	 * @access public
320
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
+	 * @param bool   $pretty Whether to set pretty format or not.
322
+	 * @return void
323
+	 */
324
+	public function set_time_format($format, $pretty = false)
325
+	{
326
+		if ($pretty) {
327
+			$this->_pretty_time_format = $format;
328
+		} else {
329
+			$this->_time_format = $format;
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 * return the $_time_format property value.
336
+	 *
337
+	 * @param bool $pretty Whether to get pretty format or not.
338
+	 * @return string
339
+	 */
340
+	public function get_time_format($pretty = false)
341
+	{
342
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
+	}
344
+
345
+
346
+	/**
347
+	 * set the $_pretty_date_format property
348
+	 *
349
+	 * @access public
350
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
+	 * @return void
352
+	 */
353
+	public function set_pretty_date_format($format)
354
+	{
355
+		$this->_pretty_date_format = $format;
356
+	}
357
+
358
+
359
+	/**
360
+	 * set the $_pretty_time_format property
361
+	 *
362
+	 * @access public
363
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
+	 * @return void
365
+	 */
366
+	public function set_pretty_time_format($format)
367
+	{
368
+		$this->_pretty_time_format = $format;
369
+	}
370
+
371
+
372
+	/**
373
+	 * Only sets the time portion of the datetime.
374
+	 *
375
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
+	 * @param DateTime        $current            current DateTime object for the datetime field
377
+	 * @return DateTime
378
+	 */
379
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
+	{
381
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
+		// Otherwise parse the string.
383
+		if ($time_to_set_string instanceof DateTime) {
384
+			$parsed = array(
385
+				'hour'   => $time_to_set_string->format('H'),
386
+				'minute' => $time_to_set_string->format('i'),
387
+				'second' => $time_to_set_string->format('s'),
388
+			);
389
+		} else {
390
+			//parse incoming string
391
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
+		}
393
+
394
+		//make sure $current is in the correct timezone.
395
+		$current->setTimezone($this->_DateTimeZone);
396
+
397
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Only sets the date portion of the datetime.
403
+	 *
404
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
+	 * @param DateTime        $current            current DateTime object for the datetime field
406
+	 * @return DateTime
407
+	 */
408
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
+	{
410
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
+		// Otherwise parse the string.
412
+		if ($date_to_set_string instanceof DateTime) {
413
+			$parsed = array(
414
+				'year'  => $date_to_set_string->format('Y'),
415
+				'month' => $date_to_set_string->format('m'),
416
+				'day'   => $date_to_set_string->format('d'),
417
+			);
418
+		} else {
419
+			//parse incoming string
420
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
+		}
422
+
423
+		//make sure $current is in the correct timezone
424
+		$current->setTimezone($this->_DateTimeZone);
425
+
426
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
+	}
428
+
429
+
430
+	/**
431
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
+	 * datetime gets to this stage it should ALREADY be in UTC time
433
+	 *
434
+	 * @param  DateTime $DateTime
435
+	 * @return string formatted date time for given timezone
436
+	 * @throws \EE_Error
437
+	 */
438
+	public function prepare_for_get($DateTime)
439
+	{
440
+		return $this->_prepare_for_display($DateTime);
441
+	}
442
+
443
+
444
+	/**
445
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
+	 * abbreviation to the date_string.
449
+	 *
450
+	 * @param mixed $DateTime
451
+	 * @param null  $schema
452
+	 * @return string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
+	{
457
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
+	}
459
+
460
+
461
+	/**
462
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
+	 * timezone).
464
+	 *
465
+	 * @param DateTime    $DateTime
466
+	 * @param bool|string $schema
467
+	 * @return string
468
+	 * @throws \EE_Error
469
+	 */
470
+	protected function _prepare_for_display($DateTime, $schema = false)
471
+	{
472
+		if (! $DateTime instanceof DateTime) {
473
+			if ($this->_nullable) {
474
+				return '';
475
+			} else {
476
+				if (WP_DEBUG) {
477
+					throw new EE_Error(
478
+						sprintf(
479
+							__(
480
+								'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.',
481
+								'event_espresso'
482
+							),
483
+							$this->_nicename
484
+						)
485
+					);
486
+				} else {
487
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
+					EE_Error::add_error(
489
+						sprintf(
490
+							__(
491
+								'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.',
492
+								'event_espresso'
493
+							),
494
+							$this->_nicename
495
+						)
496
+					);
497
+				}
498
+			}
499
+		}
500
+		$format_string = $this->_get_date_time_output($schema);
501
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
502
+		$DateTime->setTimezone($this->_DateTimeZone);
503
+		if ($schema) {
504
+			if ($this->_display_timezone()) {
505
+				//must be explicit because schema could equal true.
506
+				if ($schema === 'no_html') {
507
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
508
+				} else {
509
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
+				}
511
+			} else {
512
+				$timezone_string = '';
513
+			}
514
+
515
+			return $DateTime->format($format_string) . $timezone_string;
516
+		} else {
517
+			return $DateTime->format($format_string);
518
+		}
519
+	}
520
+
521
+
522
+	/**
523
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
+	 * timezone).
525
+	 *
526
+	 * @param  mixed $datetime_value u
527
+	 * @return string mysql timestamp in UTC
528
+	 * @throws \EE_Error
529
+	 */
530
+	public function prepare_for_use_in_db($datetime_value)
531
+	{
532
+		//we allow an empty value or DateTime object, but nothing else.
533
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
+			throw new EE_Error(
535
+				sprintf(
536
+					__(
537
+						'The incoming value being prepared for setting in the database must either be empty or a php 
538 538
             		    DateTime object, instead of: %1$s %2$s',
539
-                        'event_espresso'
540
-	                ),
541
-                    '<br />',
542
-                    print_r($datetime_value, true)
543
-                )
544
-            );
545
-        }
546
-
547
-        if ($datetime_value instanceof DateTime) {
548
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
549
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
-            }
551
-
552
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
-                EE_Datetime_Field::mysql_timestamp_format
554
-            );
555
-        }
556
-
557
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
-    }
560
-
561
-
562
-    /**
563
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
-     * allowed)
565
-     *
566
-     * @param string $datetime_string mysql timestamp in UTC
567
-     * @return  mixed null | DateTime
568
-     * @throws \EE_Error
569
-     */
570
-    public function prepare_for_set_from_db($datetime_string)
571
-    {
572
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
573
-        if (empty($datetime_string) && $this->_nullable) {
574
-            return null;
575
-        }
576
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
-        if (empty($datetime_string)) {
578
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
-        } else {
580
-            $DateTime = DateTime::createFromFormat(
581
-                EE_Datetime_Field::mysql_timestamp_format,
582
-                $datetime_string,
583
-                $this->get_UTC_DateTimeZone()
584
-            );
585
-            if ($DateTime instanceof \DateTime) {
586
-                $DateTime = new DbSafeDateTime(
587
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
-                    $this->get_UTC_DateTimeZone()
589
-                );
590
-            }
591
-        }
592
-
593
-        if (! $DateTime instanceof DbSafeDateTime) {
594
-            // if still no datetime object, then let's just use now
595
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
-        }
597
-        // THEN apply the field's set DateTimeZone
598
-        $DateTime->setTimezone($this->_DateTimeZone);
599
-
600
-        return $DateTime;
601
-    }
602
-
603
-
604
-    /**
605
-     * All this method does is determine if we're going to display the timezone string or not on any output.
606
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
-     * If so, then true.
608
-     *
609
-     * @return bool true for yes false for no
610
-     * @throws \EE_Error
611
-     */
612
-    protected function _display_timezone()
613
-    {
614
-
615
-        // first let's do a comparison of timezone strings.
616
-        // If they match then we can get out without any further calculations
617
-        $blog_string = get_option('timezone_string');
618
-        if ($blog_string === $this->_timezone_string) {
619
-            return false;
620
-        }
621
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
-        // now compare
625
-        return $blog_offset !== $this_offset;
626
-    }
627
-
628
-
629
-    /**
630
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
-     * with.
633
-     *
634
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
-     *                                                    in the format that is set on the date_field (or DateTime
636
-     *                                                    object)!
637
-     * @return DateTime
638
-     */
639
-    protected function _get_date_object($date_string)
640
-    {
641
-        //first if this is an empty date_string and nullable is allowed, just return null.
642
-        if ($this->_nullable && empty($date_string)) {
643
-            return null;
644
-        }
645
-
646
-        // if incoming date
647
-        if ($date_string instanceof DateTime) {
648
-            $date_string->setTimezone($this->_DateTimeZone);
649
-
650
-            return $date_string;
651
-        }
652
-        // if empty date_string and made it here.
653
-        // Return a datetime object for now in the given timezone.
654
-        if (empty($date_string)) {
655
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
-        }
657
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
-            try {
660
-                // This is operating under the assumption that the incoming Unix timestamp
661
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
-                $DateTime->setTimestamp($date_string);
664
-
665
-                return $DateTime;
666
-            } catch (Exception $e) {
667
-                // should be rare, but if things got fooled then let's just continue
668
-            }
669
-        }
670
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
671
-        //create the DateTime object.
672
-        $format = $this->_date_format . ' ' . $this->_time_format;
673
-        try {
674
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
-            if ($DateTime instanceof DateTime) {
676
-                $DateTime = new DbSafeDateTime(
677
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
-                    $this->_DateTimeZone
679
-                );
680
-            }
681
-            if (! $DateTime instanceof DbSafeDateTime) {
682
-                throw new EE_Error(
683
-                    sprintf(
684
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
-                        $date_string,
686
-                        $format
687
-                    )
688
-                );
689
-            }
690
-        } catch (Exception $e) {
691
-            // if we made it here then likely then something went really wrong.
692
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
-        }
695
-
696
-        return $DateTime;
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * get_timezone_transitions
703
-     *
704
-     * @param \DateTimeZone $DateTimeZone
705
-     * @param int           $time
706
-     * @param bool          $first_only
707
-     * @return mixed
708
-     */
709
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
-    {
711
-        return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     * get_timezone_offset
718
-     *
719
-     * @param \DateTimeZone $DateTimeZone
720
-     * @param int           $time
721
-     * @return mixed
722
-     * @throws \DomainException
723
-     */
724
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
725
-    {
726
-        return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
727
-    }
728
-
729
-
730
-    /**
731
-     * This will take an incoming timezone string and return the abbreviation for that timezone
732
-     *
733
-     * @param  string $timezone_string
734
-     * @return string           abbreviation
735
-     * @throws \EE_Error
736
-     */
737
-    public function get_timezone_abbrev($timezone_string)
738
-    {
739
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
-
742
-        return $dateTime->format('T');
743
-    }
744
-
745
-    /**
746
-     * Overrides the parent to allow for having a dynamic "now" value
747
-     *
748
-     * @return mixed
749
-     */
750
-    public function get_default_value()
751
-    {
752
-        if ($this->_default_value === EE_Datetime_Field::now) {
753
-            return time();
754
-        } else {
755
-            return parent::get_default_value();
756
-        }
757
-    }
758
-
759
-
760
-    public function getSchemaDescription()
761
-    {
762
-        return sprintf(
763
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
-            $this->get_nicename()
765
-        );
766
-    }
539
+						'event_espresso'
540
+					),
541
+					'<br />',
542
+					print_r($datetime_value, true)
543
+				)
544
+			);
545
+		}
546
+
547
+		if ($datetime_value instanceof DateTime) {
548
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
549
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
+			}
551
+
552
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
+				EE_Datetime_Field::mysql_timestamp_format
554
+			);
555
+		}
556
+
557
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
+	}
560
+
561
+
562
+	/**
563
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
+	 * allowed)
565
+	 *
566
+	 * @param string $datetime_string mysql timestamp in UTC
567
+	 * @return  mixed null | DateTime
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function prepare_for_set_from_db($datetime_string)
571
+	{
572
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
573
+		if (empty($datetime_string) && $this->_nullable) {
574
+			return null;
575
+		}
576
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
+		if (empty($datetime_string)) {
578
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
+		} else {
580
+			$DateTime = DateTime::createFromFormat(
581
+				EE_Datetime_Field::mysql_timestamp_format,
582
+				$datetime_string,
583
+				$this->get_UTC_DateTimeZone()
584
+			);
585
+			if ($DateTime instanceof \DateTime) {
586
+				$DateTime = new DbSafeDateTime(
587
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
+					$this->get_UTC_DateTimeZone()
589
+				);
590
+			}
591
+		}
592
+
593
+		if (! $DateTime instanceof DbSafeDateTime) {
594
+			// if still no datetime object, then let's just use now
595
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
+		}
597
+		// THEN apply the field's set DateTimeZone
598
+		$DateTime->setTimezone($this->_DateTimeZone);
599
+
600
+		return $DateTime;
601
+	}
602
+
603
+
604
+	/**
605
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
606
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
+	 * If so, then true.
608
+	 *
609
+	 * @return bool true for yes false for no
610
+	 * @throws \EE_Error
611
+	 */
612
+	protected function _display_timezone()
613
+	{
614
+
615
+		// first let's do a comparison of timezone strings.
616
+		// If they match then we can get out without any further calculations
617
+		$blog_string = get_option('timezone_string');
618
+		if ($blog_string === $this->_timezone_string) {
619
+			return false;
620
+		}
621
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
+		// now compare
625
+		return $blog_offset !== $this_offset;
626
+	}
627
+
628
+
629
+	/**
630
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
+	 * with.
633
+	 *
634
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
+	 *                                                    in the format that is set on the date_field (or DateTime
636
+	 *                                                    object)!
637
+	 * @return DateTime
638
+	 */
639
+	protected function _get_date_object($date_string)
640
+	{
641
+		//first if this is an empty date_string and nullable is allowed, just return null.
642
+		if ($this->_nullable && empty($date_string)) {
643
+			return null;
644
+		}
645
+
646
+		// if incoming date
647
+		if ($date_string instanceof DateTime) {
648
+			$date_string->setTimezone($this->_DateTimeZone);
649
+
650
+			return $date_string;
651
+		}
652
+		// if empty date_string and made it here.
653
+		// Return a datetime object for now in the given timezone.
654
+		if (empty($date_string)) {
655
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
+		}
657
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
+			try {
660
+				// This is operating under the assumption that the incoming Unix timestamp
661
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
+				$DateTime->setTimestamp($date_string);
664
+
665
+				return $DateTime;
666
+			} catch (Exception $e) {
667
+				// should be rare, but if things got fooled then let's just continue
668
+			}
669
+		}
670
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
671
+		//create the DateTime object.
672
+		$format = $this->_date_format . ' ' . $this->_time_format;
673
+		try {
674
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
+			if ($DateTime instanceof DateTime) {
676
+				$DateTime = new DbSafeDateTime(
677
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
+					$this->_DateTimeZone
679
+				);
680
+			}
681
+			if (! $DateTime instanceof DbSafeDateTime) {
682
+				throw new EE_Error(
683
+					sprintf(
684
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
+						$date_string,
686
+						$format
687
+					)
688
+				);
689
+			}
690
+		} catch (Exception $e) {
691
+			// if we made it here then likely then something went really wrong.
692
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
+		}
695
+
696
+		return $DateTime;
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * get_timezone_transitions
703
+	 *
704
+	 * @param \DateTimeZone $DateTimeZone
705
+	 * @param int           $time
706
+	 * @param bool          $first_only
707
+	 * @return mixed
708
+	 */
709
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
+	{
711
+		return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 * get_timezone_offset
718
+	 *
719
+	 * @param \DateTimeZone $DateTimeZone
720
+	 * @param int           $time
721
+	 * @return mixed
722
+	 * @throws \DomainException
723
+	 */
724
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
725
+	{
726
+		return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
727
+	}
728
+
729
+
730
+	/**
731
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
732
+	 *
733
+	 * @param  string $timezone_string
734
+	 * @return string           abbreviation
735
+	 * @throws \EE_Error
736
+	 */
737
+	public function get_timezone_abbrev($timezone_string)
738
+	{
739
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
+
742
+		return $dateTime->format('T');
743
+	}
744
+
745
+	/**
746
+	 * Overrides the parent to allow for having a dynamic "now" value
747
+	 *
748
+	 * @return mixed
749
+	 */
750
+	public function get_default_value()
751
+	{
752
+		if ($this->_default_value === EE_Datetime_Field::now) {
753
+			return time();
754
+		} else {
755
+			return parent::get_default_value();
756
+		}
757
+	}
758
+
759
+
760
+	public function getSchemaDescription()
761
+	{
762
+		return sprintf(
763
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
+			$this->get_nicename()
765
+		);
766
+	}
767 767
 }
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 1 patch
Indentation   +1972 added lines, -1972 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -27,1980 +27,1980 @@  discard block
 block discarded – undo
27 27
 class Transactions_Admin_Page extends EE_Admin_Page
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Transaction
32
-     */
33
-    private $_transaction;
34
-
35
-    /**
36
-     * @var EE_Session
37
-     */
38
-    private $_session;
39
-
40
-    /**
41
-     * @var array $_txn_status
42
-     */
43
-    private static $_txn_status;
44
-
45
-    /**
46
-     * @var array $_pay_status
47
-     */
48
-    private static $_pay_status;
49
-
50
-    /**
51
-     * @var array $_existing_reg_payment_REG_IDs
52
-     */
53
-    protected $_existing_reg_payment_REG_IDs = null;
54
-
55
-
56
-    /**
57
-     * @Constructor
58
-     * @access public
59
-     *
60
-     * @param bool $routing
61
-     *
62
-     * @return Transactions_Admin_Page
63
-     */
64
-    public function __construct($routing = true)
65
-    {
66
-        parent::__construct($routing);
67
-    }
68
-
69
-
70
-    /**
71
-     *    _init_page_props
72
-     * @return void
73
-     */
74
-    protected function _init_page_props()
75
-    {
76
-        $this->page_slug        = TXN_PG_SLUG;
77
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
78
-        $this->_admin_base_url  = TXN_ADMIN_URL;
79
-        $this->_admin_base_path = TXN_ADMIN;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ajax_hooks
85
-     * @return void
86
-     */
87
-    protected function _ajax_hooks()
88
-    {
89
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
-    }
93
-
94
-
95
-    /**
96
-     *    _define_page_props
97
-     * @return void
98
-     */
99
-    protected function _define_page_props()
100
-    {
101
-        $this->_admin_page_title = $this->page_label;
102
-        $this->_labels           = array(
103
-            'buttons' => array(
104
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
-            )
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     *        grab url requests and route them
114
-     * @access private
115
-     * @return void
116
-     */
117
-    public function _set_page_routes()
118
-    {
119
-
120
-        $this->_set_transaction_status_array();
121
-
122
-        $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
-
124
-        $this->_page_routes = array(
125
-
126
-            'default' => array(
127
-                'func'       => '_transactions_overview_list_table',
128
-                'capability' => 'ee_read_transactions'
129
-            ),
130
-
131
-            'view_transaction' => array(
132
-                'func'       => '_transaction_details',
133
-                'capability' => 'ee_read_transaction',
134
-                'obj_id'     => $txn_id
135
-            ),
136
-
137
-            'send_payment_reminder' => array(
138
-                'func'       => '_send_payment_reminder',
139
-                'noheader'   => true,
140
-                'capability' => 'ee_send_message'
141
-            ),
142
-
143
-            'espresso_apply_payment' => array(
144
-                'func'       => 'apply_payments_or_refunds',
145
-                'noheader'   => true,
146
-                'capability' => 'ee_edit_payments'
147
-            ),
148
-
149
-            'espresso_apply_refund' => array(
150
-                'func'       => 'apply_payments_or_refunds',
151
-                'noheader'   => true,
152
-                'capability' => 'ee_edit_payments'
153
-            ),
154
-
155
-            'espresso_delete_payment' => array(
156
-                'func'       => 'delete_payment',
157
-                'noheader'   => true,
158
-                'capability' => 'ee_delete_payments'
159
-            ),
160
-
161
-        );
162
-
163
-    }
164
-
165
-
166
-    protected function _set_page_config()
167
-    {
168
-        $this->_page_config = array(
169
-            'default'          => array(
170
-                'nav'           => array(
171
-                    'label' => esc_html__('Overview', 'event_espresso'),
172
-                    'order' => 10
173
-                ),
174
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
175
-                'help_tabs'     => array(
176
-                    'transactions_overview_help_tab'                       => array(
177
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
-                        'filename' => 'transactions_overview'
179
-                    ),
180
-                    'transactions_overview_table_column_headings_help_tab' => array(
181
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
-                        'filename' => 'transactions_overview_table_column_headings'
183
-                    ),
184
-                    'transactions_overview_views_filters_help_tab'         => array(
185
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
-                        'filename' => 'transactions_overview_views_filters_search'
187
-                    ),
188
-                ),
189
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
-                /**
191
-                 * commented out because currently we are not displaying tips for transaction list table status but this
192
-                 * may change in a later iteration so want to keep the code for then.
193
-                 */
194
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
195
-                'require_nonce' => false
196
-            ),
197
-            'view_transaction' => array(
198
-                'nav'       => array(
199
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
200
-                    'order'      => 5,
201
-                    'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
-                        $this->_current_page_view_url) : $this->_admin_base_url,
203
-                    'persistent' => false
204
-                ),
205
-                'help_tabs' => array(
206
-                    'transactions_view_transaction_help_tab'                                              => array(
207
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
208
-                        'filename' => 'transactions_view_transaction'
209
-                    ),
210
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
-                        'filename' => 'transactions_view_transaction_transaction_details_table'
213
-                    ),
214
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
-                        'filename' => 'transactions_view_transaction_attendees_registered'
217
-                    ),
218
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
-                    ),
222
-                ),
223
-                'qtips'     => array('Transaction_Details_Tips'),
224
-                'help_tour' => array('Transaction_Details_Help_Tour'),
225
-                'metaboxes' => array('_transaction_details_metaboxes'),
226
-
227
-                'require_nonce' => false
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * The below methods aren't used by this class currently
235
-     */
236
-    protected function _add_screen_options()
237
-    {
238
-    }
239
-
240
-    protected function _add_feature_pointers()
241
-    {
242
-    }
243
-
244
-    public function admin_init()
245
-    {
246
-        // IF a registration was JUST added via the admin...
247
-        if (
248
-        isset(
249
-            $this->_req_data['redirect_from'],
250
-            $this->_req_data['EVT_ID'],
251
-            $this->_req_data['event_name']
252
-        )
253
-        ) {
254
-            // then set a cookie so that we can block any attempts to use
255
-            // the back button as a way to enter another registration.
256
-            setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
-            // and update the global
258
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
-        }
260
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
-            'event_espresso');
262
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
-            'event_espresso');
264
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
-            'event_espresso');
269
-    }
270
-
271
-    public function admin_notices()
272
-    {
273
-    }
274
-
275
-    public function admin_footer_scripts()
276
-    {
277
-    }
278
-
279
-
280
-    /**
281
-     * _set_transaction_status_array
282
-     * sets list of transaction statuses
283
-     *
284
-     * @access private
285
-     * @return void
286
-     */
287
-    private function _set_transaction_status_array()
288
-    {
289
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
-    }
291
-
292
-
293
-    /**
294
-     * get_transaction_status_array
295
-     * return the transaction status array for wp_list_table
296
-     *
297
-     * @access public
298
-     * @return array
299
-     */
300
-    public function get_transaction_status_array()
301
-    {
302
-        return self::$_txn_status;
303
-    }
304
-
305
-
306
-    /**
307
-     *    get list of payment statuses
308
-     *
309
-     * @access private
310
-     * @return void
311
-     */
312
-    private function _get_payment_status_array()
313
-    {
314
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
-        $this->_template_args['payment_status'] = self::$_pay_status;
316
-
317
-    }
318
-
319
-
320
-    /**
321
-     *    _add_screen_options_default
322
-     *
323
-     * @access protected
324
-     * @return void
325
-     */
326
-    protected function _add_screen_options_default()
327
-    {
328
-        $this->_per_page_screen_option();
329
-    }
330
-
331
-
332
-    /**
333
-     * load_scripts_styles
334
-     *
335
-     * @access public
336
-     * @return void
337
-     */
338
-    public function load_scripts_styles()
339
-    {
340
-        //enqueue style
341
-        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
-            EVENT_ESPRESSO_VERSION);
343
-        wp_enqueue_style('espresso_txn');
344
-        //scripts
345
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
-            'ee_admin_js',
347
-            'ee-datepicker',
348
-            'jquery-ui-datepicker',
349
-            'jquery-ui-draggable',
350
-            'ee-dialog',
351
-            'ee-accounting',
352
-            'ee-serialize-full-array'
353
-        ), EVENT_ESPRESSO_VERSION, true);
354
-        wp_enqueue_script('espresso_txn');
355
-
356
-    }
357
-
358
-
359
-    /**
360
-     *    load_scripts_styles_view_transaction
361
-     *
362
-     * @access public
363
-     * @return void
364
-     */
365
-    public function load_scripts_styles_view_transaction()
366
-    {
367
-        //styles
368
-        wp_enqueue_style('espresso-ui-theme');
369
-    }
370
-
371
-
372
-    /**
373
-     *    load_scripts_styles_default
374
-     *
375
-     * @access public
376
-     * @return void
377
-     */
378
-    public function load_scripts_styles_default()
379
-    {
380
-        //styles
381
-        wp_enqueue_style('espresso-ui-theme');
382
-    }
383
-
384
-
385
-    /**
386
-     *    _set_list_table_views_default
387
-     *
388
-     * @access protected
389
-     * @return void
390
-     */
391
-    protected function _set_list_table_views_default()
392
-    {
393
-        $this->_views = array(
394
-            'all'       => array(
395
-                'slug'  => 'all',
396
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
397
-                'count' => 0
398
-            ),
399
-            'abandoned' => array(
400
-                'slug'  => 'abandoned',
401
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
-                'count' => 0
403
-            ),
404
-            'failed'    => array(
405
-                'slug'  => 'failed',
406
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
-                'count' => 0
408
-            )
409
-        );
410
-    }
411
-
412
-
413
-    /**
414
-     * _set_transaction_object
415
-     * This sets the _transaction property for the transaction details screen
416
-     *
417
-     * @access private
418
-     * @return void
419
-     */
420
-    private function _set_transaction_object()
421
-    {
422
-        if (is_object($this->_transaction)) {
423
-            return;
424
-        } //get out we've already set the object
425
-
426
-        $TXN = EEM_Transaction::instance();
427
-
428
-        $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
-
430
-        //get transaction object
431
-        $this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
-        $this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
-        $this->_transaction->verify_abandoned_transaction_status();
434
-
435
-        if (empty($this->_transaction)) {
436
-            $error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
-                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
-        }
440
-    }
441
-
442
-
443
-    /**
444
-     *    _transaction_legend_items
445
-     *
446
-     * @access protected
447
-     * @return array
448
-     */
449
-    protected function _transaction_legend_items()
450
-    {
451
-        EE_Registry::instance()->load_helper('MSG_Template');
452
-        $items = array();
453
-
454
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
-                $items['view_related_messages'] = array(
458
-                    'class' => $related_for_icon['css_class'],
459
-                    'desc'  => $related_for_icon['label'],
460
-                );
461
-            }
462
-        }
463
-
464
-        $items = apply_filters(
465
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
-            array_merge($items,
467
-                array(
468
-                    'view_details'      => array(
469
-                        'class' => 'dashicons dashicons-cart',
470
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
-                    ),
472
-                    'view_invoice'      => array(
473
-                        'class' => 'dashicons dashicons-media-spreadsheet',
474
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
-                    ),
476
-                    'view_receipt'      => array(
477
-                        'class' => 'dashicons dashicons-media-default',
478
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
-                    ),
480
-                    'view_registration' => array(
481
-                        'class' => 'dashicons dashicons-clipboard',
482
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
-                    ),
484
-                    'payment_overview_link' => array(
485
-                        'class' => 'dashicons dashicons-money',
486
-                        'desc' => esc_html__('Make Payment on Frontend', 'event_espresso')
487
-                    )
488
-                )
489
-            )
490
-        );
491
-
492
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
493
-            'espresso_transactions_send_payment_reminder')
494
-        ) {
495
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
496
-                $items['send_payment_reminder'] = array(
497
-                    'class' => 'dashicons dashicons-email-alt',
498
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
499
-                );
500
-            } else {
501
-                $items['blank*'] = array(
502
-                    'class' => '',
503
-                    'desc'  => ''
504
-                );
505
-            }
506
-        } else {
507
-            $items['blank*'] = array(
508
-                'class' => '',
509
-                'desc'  => ''
510
-            );
511
-        }
512
-        $more_items = apply_filters(
513
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
514
-            array(
515
-                'overpaid'   => array(
516
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
517
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
518
-                ),
519
-                'complete'   => array(
520
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
521
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
522
-                ),
523
-                'incomplete' => array(
524
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
525
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
526
-                ),
527
-                'abandoned'  => array(
528
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
529
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
530
-                ),
531
-                'failed'     => array(
532
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
533
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
534
-                )
535
-            )
536
-        );
537
-
538
-        return array_merge($items, $more_items);
539
-    }
540
-
541
-
542
-    /**
543
-     *    _transactions_overview_list_table
544
-     *
545
-     * @access protected
546
-     * @return void
547
-     */
548
-    protected function _transactions_overview_list_table()
549
-    {
550
-        $this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
551
-        $event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
552
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
553
-            'event_espresso'), '<h3>',
554
-            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
555
-                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
556
-                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
557
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
558
-        $this->display_admin_list_table_page_with_no_sidebar();
559
-    }
560
-
561
-
562
-    /**
563
-     *    _transaction_details
564
-     * generates HTML for the View Transaction Details Admin page
565
-     *
566
-     * @access protected
567
-     * @return void
568
-     */
569
-    protected function _transaction_details()
570
-    {
571
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
572
-
573
-        $this->_set_transaction_status_array();
574
-
575
-        $this->_template_args                      = array();
576
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
577
-
578
-        $this->_set_transaction_object();
579
-
580
-        $primary_registration = $this->_transaction->primary_registration();
581
-        $attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
582
-
583
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
584
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
585
-
586
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
587
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
588
-
589
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
590
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
591
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
592
-
593
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
594
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
595
-
596
-        if (
597
-            $attendee instanceof EE_Attendee
598
-            && EE_Registry::instance()->CAP->current_user_can(
599
-                'ee_send_message',
600
-                'espresso_transactions_send_payment_reminder'
601
-            )
602
-        ) {
603
-            $this->_template_args['send_payment_reminder_button'] =
604
-                EEH_MSG_Template::is_mt_active('payment_reminder')
605
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
606
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
607
-                    ? EEH_Template::get_button_or_link(
608
-                    EE_Admin_Page::add_query_args_and_nonce(
609
-                        array(
610
-                            'action'      => 'send_payment_reminder',
611
-                            'TXN_ID'      => $this->_transaction->ID(),
612
-                            'redirect_to' => 'view_transaction'
613
-                        ),
614
-                        TXN_ADMIN_URL
615
-                    ),
616
-                    __(' Send Payment Reminder', 'event_espresso'),
617
-                    'button secondary-button right',
618
-                    'dashicons dashicons-email-alt'
619
-                )
620
-                    : '';
621
-        } else {
622
-            $this->_template_args['send_payment_reminder_button'] = '';
623
-        }
624
-
625
-        $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
626
-        $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
627
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
628
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
629
-        } else {
630
-            $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
631
-        }
632
-        $this->_template_args['amount_due_class'] = '';
633
-
634
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
635
-            // paid in full
636
-            $this->_template_args['amount_due'] = false;
637
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
638
-            // overpaid
639
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
640
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
641
-            // monies owing
642
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
643
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
644
-            // no payments made yet
645
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
646
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
647
-            // free event
648
-            $this->_template_args['amount_due'] = false;
649
-        }
650
-
651
-        $payment_method = $this->_transaction->payment_method();
652
-
653
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
654
-            ? $payment_method->admin_name()
655
-            : esc_html__('Unknown', 'event_espresso');
656
-
657
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
658
-        // link back to overview
659
-        $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
660
-            ? $_SERVER['HTTP_REFERER']
661
-            : TXN_ADMIN_URL;
662
-
663
-
664
-        // next link
665
-        $next_txn                                 = $this->_transaction->next(
666
-            null,
667
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
668
-            'TXN_ID'
669
-        );
670
-        $this->_template_args['next_transaction'] = $next_txn
671
-            ? $this->_next_link(
672
-                EE_Admin_Page::add_query_args_and_nonce(
673
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
674
-                    TXN_ADMIN_URL
675
-                ),
676
-                'dashicons dashicons-arrow-right ee-icon-size-22'
677
-            )
678
-            : '';
679
-        // previous link
680
-        $previous_txn                                 = $this->_transaction->previous(
681
-            null,
682
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
683
-            'TXN_ID'
684
-        );
685
-        $this->_template_args['previous_transaction'] = $previous_txn
686
-            ? $this->_previous_link(
687
-                EE_Admin_Page::add_query_args_and_nonce(
688
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
689
-                    TXN_ADMIN_URL
690
-                ),
691
-                'dashicons dashicons-arrow-left ee-icon-size-22'
692
-            )
693
-            : '';
694
-
695
-        // were we just redirected here after adding a new registration ???
696
-        if (
697
-        isset(
698
-            $this->_req_data['redirect_from'],
699
-            $this->_req_data['EVT_ID'],
700
-            $this->_req_data['event_name']
701
-        )
702
-        ) {
703
-            if (
704
-            EE_Registry::instance()->CAP->current_user_can(
705
-                'ee_edit_registrations',
706
-                'espresso_registrations_new_registration',
707
-                $this->_req_data['EVT_ID']
708
-            )
709
-            ) {
710
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
711
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
712
-                    array(
713
-                        'page'     => 'espresso_registrations',
714
-                        'action'   => 'new_registration',
715
-                        'return'   => 'default',
716
-                        'TXN_ID'   => $this->_transaction->ID(),
717
-                        'event_id' => $this->_req_data['EVT_ID'],
718
-                    ),
719
-                    REG_ADMIN_URL
720
-                );
721
-                $this->_admin_page_title .= '">';
722
-
723
-                $this->_admin_page_title .= sprintf(
724
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
725
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
726
-                );
727
-                $this->_admin_page_title .= '</a>';
728
-            }
729
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
730
-        }
731
-        // grab messages at the last second
732
-        $this->_template_args['notices'] = EE_Error::get_notices();
733
-        // path to template
734
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
735
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
736
-            $this->_template_args, true);
737
-
738
-        // the details template wrapper
739
-        $this->display_admin_page_with_sidebar();
740
-
741
-    }
742
-
743
-
744
-    /**
745
-     *        _transaction_details_metaboxes
746
-     *
747
-     * @access protected
748
-     * @return void
749
-     */
750
-    protected function _transaction_details_metaboxes()
751
-    {
752
-
753
-        $this->_set_transaction_object();
754
-
755
-        add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
756
-            array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
757
-        add_meta_box(
758
-            'edit-txn-attendees-mbox',
759
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
760
-            array($this, 'txn_attendees_meta_box'),
761
-            $this->_wp_page_slug,
762
-            'normal',
763
-            'high',
764
-            array('TXN_ID' => $this->_transaction->ID())
765
-        );
766
-        add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
767
-            array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
768
-        add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
769
-            array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
770
-
771
-    }
772
-
773
-
774
-    /**
775
-     * txn_details_meta_box
776
-     * generates HTML for the Transaction main meta box
777
-     *
778
-     * @access public
779
-     * @return void
780
-     */
781
-    public function txn_details_meta_box()
782
-    {
783
-
784
-        $this->_set_transaction_object();
785
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
786
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
787
-
788
-        //get line table
789
-        EEH_Autoloader::register_line_item_display_autoloaders();
790
-        $Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
791
-            'EE_Admin_Table_Line_Item_Display_Strategy');
792
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
793
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
794
-
795
-        // process taxes
796
-        $taxes                         = $this->_transaction->get_many_related('Line_Item',
797
-            array(array('LIN_type' => EEM_Line_Item::type_tax)));
798
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
799
-
800
-        $this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
801
-            false, false);
802
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
803
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
30
+	/**
31
+	 * @var EE_Transaction
32
+	 */
33
+	private $_transaction;
34
+
35
+	/**
36
+	 * @var EE_Session
37
+	 */
38
+	private $_session;
39
+
40
+	/**
41
+	 * @var array $_txn_status
42
+	 */
43
+	private static $_txn_status;
44
+
45
+	/**
46
+	 * @var array $_pay_status
47
+	 */
48
+	private static $_pay_status;
49
+
50
+	/**
51
+	 * @var array $_existing_reg_payment_REG_IDs
52
+	 */
53
+	protected $_existing_reg_payment_REG_IDs = null;
54
+
55
+
56
+	/**
57
+	 * @Constructor
58
+	 * @access public
59
+	 *
60
+	 * @param bool $routing
61
+	 *
62
+	 * @return Transactions_Admin_Page
63
+	 */
64
+	public function __construct($routing = true)
65
+	{
66
+		parent::__construct($routing);
67
+	}
68
+
69
+
70
+	/**
71
+	 *    _init_page_props
72
+	 * @return void
73
+	 */
74
+	protected function _init_page_props()
75
+	{
76
+		$this->page_slug        = TXN_PG_SLUG;
77
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
78
+		$this->_admin_base_url  = TXN_ADMIN_URL;
79
+		$this->_admin_base_path = TXN_ADMIN;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ajax_hooks
85
+	 * @return void
86
+	 */
87
+	protected function _ajax_hooks()
88
+	{
89
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
+	}
93
+
94
+
95
+	/**
96
+	 *    _define_page_props
97
+	 * @return void
98
+	 */
99
+	protected function _define_page_props()
100
+	{
101
+		$this->_admin_page_title = $this->page_label;
102
+		$this->_labels           = array(
103
+			'buttons' => array(
104
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
+			)
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 *        grab url requests and route them
114
+	 * @access private
115
+	 * @return void
116
+	 */
117
+	public function _set_page_routes()
118
+	{
119
+
120
+		$this->_set_transaction_status_array();
121
+
122
+		$txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
+
124
+		$this->_page_routes = array(
125
+
126
+			'default' => array(
127
+				'func'       => '_transactions_overview_list_table',
128
+				'capability' => 'ee_read_transactions'
129
+			),
130
+
131
+			'view_transaction' => array(
132
+				'func'       => '_transaction_details',
133
+				'capability' => 'ee_read_transaction',
134
+				'obj_id'     => $txn_id
135
+			),
136
+
137
+			'send_payment_reminder' => array(
138
+				'func'       => '_send_payment_reminder',
139
+				'noheader'   => true,
140
+				'capability' => 'ee_send_message'
141
+			),
142
+
143
+			'espresso_apply_payment' => array(
144
+				'func'       => 'apply_payments_or_refunds',
145
+				'noheader'   => true,
146
+				'capability' => 'ee_edit_payments'
147
+			),
148
+
149
+			'espresso_apply_refund' => array(
150
+				'func'       => 'apply_payments_or_refunds',
151
+				'noheader'   => true,
152
+				'capability' => 'ee_edit_payments'
153
+			),
154
+
155
+			'espresso_delete_payment' => array(
156
+				'func'       => 'delete_payment',
157
+				'noheader'   => true,
158
+				'capability' => 'ee_delete_payments'
159
+			),
160
+
161
+		);
162
+
163
+	}
164
+
165
+
166
+	protected function _set_page_config()
167
+	{
168
+		$this->_page_config = array(
169
+			'default'          => array(
170
+				'nav'           => array(
171
+					'label' => esc_html__('Overview', 'event_espresso'),
172
+					'order' => 10
173
+				),
174
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
175
+				'help_tabs'     => array(
176
+					'transactions_overview_help_tab'                       => array(
177
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
+						'filename' => 'transactions_overview'
179
+					),
180
+					'transactions_overview_table_column_headings_help_tab' => array(
181
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
+						'filename' => 'transactions_overview_table_column_headings'
183
+					),
184
+					'transactions_overview_views_filters_help_tab'         => array(
185
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
+						'filename' => 'transactions_overview_views_filters_search'
187
+					),
188
+				),
189
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
+				/**
191
+				 * commented out because currently we are not displaying tips for transaction list table status but this
192
+				 * may change in a later iteration so want to keep the code for then.
193
+				 */
194
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
195
+				'require_nonce' => false
196
+			),
197
+			'view_transaction' => array(
198
+				'nav'       => array(
199
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
200
+					'order'      => 5,
201
+					'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
+						$this->_current_page_view_url) : $this->_admin_base_url,
203
+					'persistent' => false
204
+				),
205
+				'help_tabs' => array(
206
+					'transactions_view_transaction_help_tab'                                              => array(
207
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
208
+						'filename' => 'transactions_view_transaction'
209
+					),
210
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
+						'filename' => 'transactions_view_transaction_transaction_details_table'
213
+					),
214
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
+						'filename' => 'transactions_view_transaction_attendees_registered'
217
+					),
218
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
+					),
222
+				),
223
+				'qtips'     => array('Transaction_Details_Tips'),
224
+				'help_tour' => array('Transaction_Details_Help_Tour'),
225
+				'metaboxes' => array('_transaction_details_metaboxes'),
226
+
227
+				'require_nonce' => false
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * The below methods aren't used by this class currently
235
+	 */
236
+	protected function _add_screen_options()
237
+	{
238
+	}
239
+
240
+	protected function _add_feature_pointers()
241
+	{
242
+	}
243
+
244
+	public function admin_init()
245
+	{
246
+		// IF a registration was JUST added via the admin...
247
+		if (
248
+		isset(
249
+			$this->_req_data['redirect_from'],
250
+			$this->_req_data['EVT_ID'],
251
+			$this->_req_data['event_name']
252
+		)
253
+		) {
254
+			// then set a cookie so that we can block any attempts to use
255
+			// the back button as a way to enter another registration.
256
+			setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
+			// and update the global
258
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
+		}
260
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
+			'event_espresso');
262
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
+			'event_espresso');
264
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
+			'event_espresso');
269
+	}
270
+
271
+	public function admin_notices()
272
+	{
273
+	}
274
+
275
+	public function admin_footer_scripts()
276
+	{
277
+	}
278
+
279
+
280
+	/**
281
+	 * _set_transaction_status_array
282
+	 * sets list of transaction statuses
283
+	 *
284
+	 * @access private
285
+	 * @return void
286
+	 */
287
+	private function _set_transaction_status_array()
288
+	{
289
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
+	}
291
+
292
+
293
+	/**
294
+	 * get_transaction_status_array
295
+	 * return the transaction status array for wp_list_table
296
+	 *
297
+	 * @access public
298
+	 * @return array
299
+	 */
300
+	public function get_transaction_status_array()
301
+	{
302
+		return self::$_txn_status;
303
+	}
304
+
305
+
306
+	/**
307
+	 *    get list of payment statuses
308
+	 *
309
+	 * @access private
310
+	 * @return void
311
+	 */
312
+	private function _get_payment_status_array()
313
+	{
314
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
+		$this->_template_args['payment_status'] = self::$_pay_status;
316
+
317
+	}
318
+
319
+
320
+	/**
321
+	 *    _add_screen_options_default
322
+	 *
323
+	 * @access protected
324
+	 * @return void
325
+	 */
326
+	protected function _add_screen_options_default()
327
+	{
328
+		$this->_per_page_screen_option();
329
+	}
330
+
331
+
332
+	/**
333
+	 * load_scripts_styles
334
+	 *
335
+	 * @access public
336
+	 * @return void
337
+	 */
338
+	public function load_scripts_styles()
339
+	{
340
+		//enqueue style
341
+		wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
+			EVENT_ESPRESSO_VERSION);
343
+		wp_enqueue_style('espresso_txn');
344
+		//scripts
345
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
+			'ee_admin_js',
347
+			'ee-datepicker',
348
+			'jquery-ui-datepicker',
349
+			'jquery-ui-draggable',
350
+			'ee-dialog',
351
+			'ee-accounting',
352
+			'ee-serialize-full-array'
353
+		), EVENT_ESPRESSO_VERSION, true);
354
+		wp_enqueue_script('espresso_txn');
355
+
356
+	}
357
+
358
+
359
+	/**
360
+	 *    load_scripts_styles_view_transaction
361
+	 *
362
+	 * @access public
363
+	 * @return void
364
+	 */
365
+	public function load_scripts_styles_view_transaction()
366
+	{
367
+		//styles
368
+		wp_enqueue_style('espresso-ui-theme');
369
+	}
370
+
371
+
372
+	/**
373
+	 *    load_scripts_styles_default
374
+	 *
375
+	 * @access public
376
+	 * @return void
377
+	 */
378
+	public function load_scripts_styles_default()
379
+	{
380
+		//styles
381
+		wp_enqueue_style('espresso-ui-theme');
382
+	}
383
+
384
+
385
+	/**
386
+	 *    _set_list_table_views_default
387
+	 *
388
+	 * @access protected
389
+	 * @return void
390
+	 */
391
+	protected function _set_list_table_views_default()
392
+	{
393
+		$this->_views = array(
394
+			'all'       => array(
395
+				'slug'  => 'all',
396
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
397
+				'count' => 0
398
+			),
399
+			'abandoned' => array(
400
+				'slug'  => 'abandoned',
401
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
+				'count' => 0
403
+			),
404
+			'failed'    => array(
405
+				'slug'  => 'failed',
406
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
+				'count' => 0
408
+			)
409
+		);
410
+	}
411
+
412
+
413
+	/**
414
+	 * _set_transaction_object
415
+	 * This sets the _transaction property for the transaction details screen
416
+	 *
417
+	 * @access private
418
+	 * @return void
419
+	 */
420
+	private function _set_transaction_object()
421
+	{
422
+		if (is_object($this->_transaction)) {
423
+			return;
424
+		} //get out we've already set the object
425
+
426
+		$TXN = EEM_Transaction::instance();
427
+
428
+		$TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
+
430
+		//get transaction object
431
+		$this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
+		$this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
+		$this->_transaction->verify_abandoned_transaction_status();
434
+
435
+		if (empty($this->_transaction)) {
436
+			$error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
+					'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
+		}
440
+	}
441
+
442
+
443
+	/**
444
+	 *    _transaction_legend_items
445
+	 *
446
+	 * @access protected
447
+	 * @return array
448
+	 */
449
+	protected function _transaction_legend_items()
450
+	{
451
+		EE_Registry::instance()->load_helper('MSG_Template');
452
+		$items = array();
453
+
454
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
+				$items['view_related_messages'] = array(
458
+					'class' => $related_for_icon['css_class'],
459
+					'desc'  => $related_for_icon['label'],
460
+				);
461
+			}
462
+		}
463
+
464
+		$items = apply_filters(
465
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
+			array_merge($items,
467
+				array(
468
+					'view_details'      => array(
469
+						'class' => 'dashicons dashicons-cart',
470
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
+					),
472
+					'view_invoice'      => array(
473
+						'class' => 'dashicons dashicons-media-spreadsheet',
474
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
+					),
476
+					'view_receipt'      => array(
477
+						'class' => 'dashicons dashicons-media-default',
478
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
+					),
480
+					'view_registration' => array(
481
+						'class' => 'dashicons dashicons-clipboard',
482
+						'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
+					),
484
+					'payment_overview_link' => array(
485
+						'class' => 'dashicons dashicons-money',
486
+						'desc' => esc_html__('Make Payment on Frontend', 'event_espresso')
487
+					)
488
+				)
489
+			)
490
+		);
491
+
492
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
493
+			'espresso_transactions_send_payment_reminder')
494
+		) {
495
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
496
+				$items['send_payment_reminder'] = array(
497
+					'class' => 'dashicons dashicons-email-alt',
498
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
499
+				);
500
+			} else {
501
+				$items['blank*'] = array(
502
+					'class' => '',
503
+					'desc'  => ''
504
+				);
505
+			}
506
+		} else {
507
+			$items['blank*'] = array(
508
+				'class' => '',
509
+				'desc'  => ''
510
+			);
511
+		}
512
+		$more_items = apply_filters(
513
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
514
+			array(
515
+				'overpaid'   => array(
516
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
517
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
518
+				),
519
+				'complete'   => array(
520
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
521
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
522
+				),
523
+				'incomplete' => array(
524
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
525
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
526
+				),
527
+				'abandoned'  => array(
528
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
529
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
530
+				),
531
+				'failed'     => array(
532
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
533
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
534
+				)
535
+			)
536
+		);
537
+
538
+		return array_merge($items, $more_items);
539
+	}
540
+
541
+
542
+	/**
543
+	 *    _transactions_overview_list_table
544
+	 *
545
+	 * @access protected
546
+	 * @return void
547
+	 */
548
+	protected function _transactions_overview_list_table()
549
+	{
550
+		$this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
551
+		$event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
552
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
553
+			'event_espresso'), '<h3>',
554
+			'<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
555
+				EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
556
+				'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
557
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
558
+		$this->display_admin_list_table_page_with_no_sidebar();
559
+	}
560
+
561
+
562
+	/**
563
+	 *    _transaction_details
564
+	 * generates HTML for the View Transaction Details Admin page
565
+	 *
566
+	 * @access protected
567
+	 * @return void
568
+	 */
569
+	protected function _transaction_details()
570
+	{
571
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
572
+
573
+		$this->_set_transaction_status_array();
574
+
575
+		$this->_template_args                      = array();
576
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
577
+
578
+		$this->_set_transaction_object();
579
+
580
+		$primary_registration = $this->_transaction->primary_registration();
581
+		$attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
582
+
583
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
584
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
585
+
586
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
587
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
588
+
589
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
590
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
591
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
592
+
593
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
594
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
595
+
596
+		if (
597
+			$attendee instanceof EE_Attendee
598
+			&& EE_Registry::instance()->CAP->current_user_can(
599
+				'ee_send_message',
600
+				'espresso_transactions_send_payment_reminder'
601
+			)
602
+		) {
603
+			$this->_template_args['send_payment_reminder_button'] =
604
+				EEH_MSG_Template::is_mt_active('payment_reminder')
605
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
606
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
607
+					? EEH_Template::get_button_or_link(
608
+					EE_Admin_Page::add_query_args_and_nonce(
609
+						array(
610
+							'action'      => 'send_payment_reminder',
611
+							'TXN_ID'      => $this->_transaction->ID(),
612
+							'redirect_to' => 'view_transaction'
613
+						),
614
+						TXN_ADMIN_URL
615
+					),
616
+					__(' Send Payment Reminder', 'event_espresso'),
617
+					'button secondary-button right',
618
+					'dashicons dashicons-email-alt'
619
+				)
620
+					: '';
621
+		} else {
622
+			$this->_template_args['send_payment_reminder_button'] = '';
623
+		}
624
+
625
+		$amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
626
+		$this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
627
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
628
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
629
+		} else {
630
+			$this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
631
+		}
632
+		$this->_template_args['amount_due_class'] = '';
633
+
634
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
635
+			// paid in full
636
+			$this->_template_args['amount_due'] = false;
637
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
638
+			// overpaid
639
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
640
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
641
+			// monies owing
642
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
643
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
644
+			// no payments made yet
645
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
646
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
647
+			// free event
648
+			$this->_template_args['amount_due'] = false;
649
+		}
650
+
651
+		$payment_method = $this->_transaction->payment_method();
652
+
653
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
654
+			? $payment_method->admin_name()
655
+			: esc_html__('Unknown', 'event_espresso');
656
+
657
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
658
+		// link back to overview
659
+		$this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
660
+			? $_SERVER['HTTP_REFERER']
661
+			: TXN_ADMIN_URL;
662
+
663
+
664
+		// next link
665
+		$next_txn                                 = $this->_transaction->next(
666
+			null,
667
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
668
+			'TXN_ID'
669
+		);
670
+		$this->_template_args['next_transaction'] = $next_txn
671
+			? $this->_next_link(
672
+				EE_Admin_Page::add_query_args_and_nonce(
673
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
674
+					TXN_ADMIN_URL
675
+				),
676
+				'dashicons dashicons-arrow-right ee-icon-size-22'
677
+			)
678
+			: '';
679
+		// previous link
680
+		$previous_txn                                 = $this->_transaction->previous(
681
+			null,
682
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
683
+			'TXN_ID'
684
+		);
685
+		$this->_template_args['previous_transaction'] = $previous_txn
686
+			? $this->_previous_link(
687
+				EE_Admin_Page::add_query_args_and_nonce(
688
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
689
+					TXN_ADMIN_URL
690
+				),
691
+				'dashicons dashicons-arrow-left ee-icon-size-22'
692
+			)
693
+			: '';
694
+
695
+		// were we just redirected here after adding a new registration ???
696
+		if (
697
+		isset(
698
+			$this->_req_data['redirect_from'],
699
+			$this->_req_data['EVT_ID'],
700
+			$this->_req_data['event_name']
701
+		)
702
+		) {
703
+			if (
704
+			EE_Registry::instance()->CAP->current_user_can(
705
+				'ee_edit_registrations',
706
+				'espresso_registrations_new_registration',
707
+				$this->_req_data['EVT_ID']
708
+			)
709
+			) {
710
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
711
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
712
+					array(
713
+						'page'     => 'espresso_registrations',
714
+						'action'   => 'new_registration',
715
+						'return'   => 'default',
716
+						'TXN_ID'   => $this->_transaction->ID(),
717
+						'event_id' => $this->_req_data['EVT_ID'],
718
+					),
719
+					REG_ADMIN_URL
720
+				);
721
+				$this->_admin_page_title .= '">';
722
+
723
+				$this->_admin_page_title .= sprintf(
724
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
725
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
726
+				);
727
+				$this->_admin_page_title .= '</a>';
728
+			}
729
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
730
+		}
731
+		// grab messages at the last second
732
+		$this->_template_args['notices'] = EE_Error::get_notices();
733
+		// path to template
734
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
735
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
736
+			$this->_template_args, true);
737
+
738
+		// the details template wrapper
739
+		$this->display_admin_page_with_sidebar();
740
+
741
+	}
742
+
743
+
744
+	/**
745
+	 *        _transaction_details_metaboxes
746
+	 *
747
+	 * @access protected
748
+	 * @return void
749
+	 */
750
+	protected function _transaction_details_metaboxes()
751
+	{
752
+
753
+		$this->_set_transaction_object();
754
+
755
+		add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
756
+			array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
757
+		add_meta_box(
758
+			'edit-txn-attendees-mbox',
759
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
760
+			array($this, 'txn_attendees_meta_box'),
761
+			$this->_wp_page_slug,
762
+			'normal',
763
+			'high',
764
+			array('TXN_ID' => $this->_transaction->ID())
765
+		);
766
+		add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
767
+			array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
768
+		add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
769
+			array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
770
+
771
+	}
772
+
773
+
774
+	/**
775
+	 * txn_details_meta_box
776
+	 * generates HTML for the Transaction main meta box
777
+	 *
778
+	 * @access public
779
+	 * @return void
780
+	 */
781
+	public function txn_details_meta_box()
782
+	{
783
+
784
+		$this->_set_transaction_object();
785
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
786
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
787
+
788
+		//get line table
789
+		EEH_Autoloader::register_line_item_display_autoloaders();
790
+		$Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
791
+			'EE_Admin_Table_Line_Item_Display_Strategy');
792
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
793
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
794
+
795
+		// process taxes
796
+		$taxes                         = $this->_transaction->get_many_related('Line_Item',
797
+			array(array('LIN_type' => EEM_Line_Item::type_tax)));
798
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
799
+
800
+		$this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
801
+			false, false);
802
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
803
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
804 804
 
805 805
 //		$txn_status_class = 'status-' . $this->_transaction->get('STS_ID');
806 806
 
807
-        // process payment details
808
-        $payments = $this->_transaction->get_many_related('Payment');
809
-        if ( ! empty($payments)) {
810
-            $this->_template_args['payments']              = $payments;
811
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
812
-        } else {
813
-            $this->_template_args['payments']              = false;
814
-            $this->_template_args['existing_reg_payments'] = array();
815
-        }
816
-
817
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
818
-        $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
819
-            TXN_ADMIN_URL);
820
-
821
-        if (isset($txn_details['invoice_number'])) {
822
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
823
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
824
-                'event_espresso');
825
-        }
826
-
827
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
828
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
829
-            'event_espresso');
830
-
831
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
832
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
833
-            'event_espresso');
834
-
835
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
836
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
837
-            'event_espresso');
838
-
839
-        $reg_steps = '<ul>';
840
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
841
-            if ($reg_step_status === true) {
842
-                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
843
-                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
844
-            } else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
845
-                $reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
846
-                        esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
847
-                        ucwords(str_replace('_', ' ', $reg_step)),
848
-                        date(get_option('date_format') . ' ' . get_option('time_format'),
849
-                            ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
850
-                    ) . '</li>';
851
-            } else {
852
-                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
853
-                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
854
-            }
855
-        }
856
-        $reg_steps .= '</ul>';
857
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
858
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
859
-            'event_espresso');
860
-
861
-
862
-        $this->_get_registrations_to_apply_payment_to();
863
-        $this->_get_payment_methods($payments);
864
-        $this->_get_payment_status_array();
865
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
866
-
867
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
868
-            'action'  => 'edit_transaction',
869
-            'process' => 'transaction'
870
-        ), TXN_ADMIN_URL);
871
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
872
-            'page'   => 'espresso_transactions',
873
-            'action' => 'espresso_apply_payment'
874
-        ), WP_AJAX_URL);
875
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
876
-            'page'   => 'espresso_transactions',
877
-            'action' => 'espresso_delete_payment'
878
-        ), WP_AJAX_URL);
879
-
880
-        // 'espresso_delete_payment_nonce'
881
-
882
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
883
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
884
-
885
-    }
886
-
887
-
888
-    /**
889
-     * _get_registration_payment_IDs
890
-     *
891
-     *    generates an array of Payment IDs and their corresponding Registration IDs
892
-     *
893
-     * @access protected
894
-     *
895
-     * @param EE_Payment[] $payments
896
-     *
897
-     * @return array
898
-     */
899
-    protected function _get_registration_payment_IDs($payments = array())
900
-    {
901
-        $existing_reg_payments = array();
902
-        // get all reg payments for these payments
903
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
904
-            array(
905
-                'PAY_ID' => array(
906
-                    'IN',
907
-                    array_keys($payments)
908
-                )
909
-            )
910
-        ));
911
-        if ( ! empty($reg_payments)) {
912
-            foreach ($payments as $payment) {
913
-                if ( ! $payment instanceof EE_Payment) {
914
-                    continue;
915
-                } else if ( ! isset($existing_reg_payments[$payment->ID()])) {
916
-                    $existing_reg_payments[$payment->ID()] = array();
917
-                }
918
-                foreach ($reg_payments as $reg_payment) {
919
-                    if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
920
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
921
-                    }
922
-                }
923
-            }
924
-        }
925
-
926
-        return $existing_reg_payments;
927
-    }
928
-
929
-
930
-    /**
931
-     * _get_registrations_to_apply_payment_to
932
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
933
-     * which allows the admin to only apply the payment to the specific registrations
934
-     *
935
-     * @access protected
936
-     * @return void
937
-     * @throws \EE_Error
938
-     */
939
-    protected function _get_registrations_to_apply_payment_to()
940
-    {
941
-        // we want any registration with an active status (ie: not deleted or cancelled)
942
-        $query_params                      = array(
943
-            array(
944
-                'STS_ID' => array(
945
-                    'IN',
946
-                    array(
947
-                        EEM_Registration::status_id_approved,
948
-                        EEM_Registration::status_id_pending_payment,
949
-                        EEM_Registration::status_id_not_approved,
950
-                    )
951
-                )
952
-            )
953
-        );
954
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
955
-                '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
956
-            );
957
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
958
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
959
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
960
-            EEH_HTML::tr(
961
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
962
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
963
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
964
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
965
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
966
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
967
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
968
-            )
969
-        );
970
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
971
-        // get registrations for TXN
972
-        $registrations = $this->_transaction->registrations($query_params);
973
-        foreach ($registrations as $registration) {
974
-            if ($registration instanceof EE_Registration) {
975
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
976
-                    ? $registration->attendee()->full_name()
977
-                    : esc_html__('Unknown Attendee', 'event_espresso');
978
-                $owing         = $registration->final_price() - $registration->paid();
979
-                $taxable       = $registration->ticket()->taxable()
980
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
981
-                    : '';
982
-                $checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
983
-                    ? ' checked="checked"'
984
-                    : '';
985
-                $disabled      = $registration->final_price() > 0 ? '' : ' disabled';
986
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
987
-                    EEH_HTML::td($registration->ID()) .
988
-                    EEH_HTML::td($attendee_name) .
989
-                    EEH_HTML::td(
990
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
991
-                    ) .
992
-                    EEH_HTML::td($registration->event_name()) .
993
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
994
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
995
-                    EEH_HTML::td(
996
-                        '<input type="checkbox" value="' . $registration->ID()
997
-                        . '" name="txn_admin_payment[registrations]"'
998
-                        . $checked . $disabled . '>',
999
-                        '', 'jst-cntr'
1000
-                    ),
1001
-                    'apply-payment-registration-row-' . $registration->ID()
1002
-                );
1003
-            }
1004
-        }
1005
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1006
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1007
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1008
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1009
-            esc_html__(
1010
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1011
-                'event_espresso'
1012
-            ),
1013
-            '', 'clear description'
1014
-        );
1015
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1016
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * _get_reg_status_selection
1022
-     *
1023
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1024
-     *         instead of events.
1025
-     * @access protected
1026
-     * @return void
1027
-     */
1028
-    protected function _get_reg_status_selection()
1029
-    {
1030
-        //first get all possible statuses
1031
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1032
-        //let's add a "don't change" option.
1033
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1034
-        $status_array                                        = array_merge($status_array, $statuses);
1035
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1036
-            $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1037
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1038
-            $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1039
-
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    _get_payment_methods
1045
-     * Gets all the payment methods available generally, or the ones that are already
1046
-     * selected on these payments (in case their payment methods are no longer active).
1047
-     * Has the side-effect of updating the template args' payment_methods item
1048
-     * @access private
1049
-     *
1050
-     * @param EE_Payment[] to show on this page
1051
-     *
1052
-     * @return void
1053
-     */
1054
-    private function _get_payment_methods($payments = array())
1055
-    {
1056
-        $payment_methods_of_payments = array();
1057
-        foreach ($payments as $payment) {
1058
-            if ($payment instanceof EE_Payment) {
1059
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1060
-            }
1061
-        }
1062
-        if ($payment_methods_of_payments) {
1063
-            $query_args = array(
1064
-                array(
1065
-                    'OR*payment_method_for_payment' => array(
1066
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1067
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1068
-                    )
1069
-                )
1070
-            );
1071
-        } else {
1072
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1073
-        }
1074
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * txn_attendees_meta_box
1080
-     *    generates HTML for the Attendees Transaction main meta box
1081
-     *
1082
-     * @access public
1083
-     *
1084
-     * @param WP_Post $post
1085
-     * @param array   $metabox
1086
-     *
1087
-     * @return void
1088
-     */
1089
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1090
-    {
1091
-
1092
-        extract($metabox['args']);
1093
-        $this->_template_args['post']            = $post;
1094
-        $this->_template_args['event_attendees'] = array();
1095
-        // process items in cart
1096
-        $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1097
-        if ( ! empty($line_items)) {
1098
-            foreach ($line_items as $item) {
1099
-                if ($item instanceof EE_Line_Item) {
1100
-                    switch ($item->OBJ_type()) {
1101
-
1102
-                        case 'Event' :
1103
-                            break;
1104
-
1105
-                        case 'Ticket' :
1106
-                            $ticket = $item->ticket();
1107
-                            //right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1108
-                            if ( ! $ticket instanceof EE_Ticket) {
1109
-                                continue;
1110
-                            }
1111
-                            try {
1112
-                                $event_name = $ticket->get_event_name();
1113
-                            } catch (Exception $e) {
1114
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1115
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1116
-                            }
1117
-                            $event_name .= ' - ' . $item->get('LIN_name');
1118
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1119
-                            // now get all of the registrations for this transaction that use this ticket
1120
-                            $registrations = $ticket->get_many_related('Registration',
1121
-                                array(array('TXN_ID' => $this->_transaction->ID())));
1122
-                            foreach ($registrations as $registration) {
1123
-                                if ( ! $registration instanceof EE_Registration) {
1124
-                                    continue;
1125
-                                }
1126
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1127
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1128
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1129
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1130
-                                // attendee info
1131
-                                $attendee = $registration->get_first_related('Attendee');
1132
-                                if ($attendee instanceof EE_Attendee) {
1133
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1134
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1135
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1136
-                                            'event_espresso') . '">' . $attendee->email() . '</a>';
1137
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1138
-                                        'inline', false, false);
1139
-                                } else {
1140
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1141
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1142
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1143
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1144
-                                }
1145
-                            }
1146
-                            break;
1147
-
1148
-                    }
1149
-                }
1150
-            }
1151
-
1152
-            $this->_template_args['transaction_form_url'] = add_query_arg(array(
1153
-                'action'  => 'edit_transaction',
1154
-                'process' => 'attendees'
1155
-            ), TXN_ADMIN_URL);
1156
-            echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1157
-                $this->_template_args, true);
1158
-
1159
-        } else {
1160
-            echo sprintf(
1161
-                esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1162
-                    'event_espresso'),
1163
-                '<p class="important-notice">',
1164
-                '</p>'
1165
-            );
1166
-        }
1167
-    }
1168
-
1169
-
1170
-    /**
1171
-     * txn_registrant_side_meta_box
1172
-     * generates HTML for the Edit Transaction side meta box
1173
-     *
1174
-     * @access public
1175
-     * @throws \EE_Error
1176
-     * @return void
1177
-     */
1178
-    public function txn_registrant_side_meta_box()
1179
-    {
1180
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1181
-        if ( ! $primary_att instanceof EE_Attendee) {
1182
-            $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1183
-                'event_espresso');
1184
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1185
-        }
1186
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1187
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1188
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1189
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1190
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1191
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1192
-            'action' => 'edit_attendee',
1193
-            'post'   => $primary_att->ID()
1194
-        ), REG_ADMIN_URL);
1195
-        // get formatted address for registrant
1196
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1197
-        echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1198
-            $this->_template_args, true);
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * txn_billing_info_side_meta_box
1204
-     *    generates HTML for the Edit Transaction side meta box
1205
-     *
1206
-     * @access public
1207
-     * @return void
1208
-     */
1209
-    public function txn_billing_info_side_meta_box()
1210
-    {
1211
-
1212
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1213
-        $this->_template_args['billing_form_url'] = add_query_arg(
1214
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1215
-            TXN_ADMIN_URL
1216
-        );
1217
-
1218
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1219
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * apply_payments_or_refunds
1225
-     *    registers a payment or refund made towards a transaction
1226
-     *
1227
-     * @access public
1228
-     * @return void
1229
-     */
1230
-    public function apply_payments_or_refunds()
1231
-    {
1232
-        $json_response_data = array('return_data' => false);
1233
-        $valid_data         = $this->_validate_payment_request_data();
1234
-        if ( ! empty($valid_data)) {
1235
-            $PAY_ID = $valid_data['PAY_ID'];
1236
-            //save  the new payment
1237
-            $payment = $this->_create_payment_from_request_data($valid_data);
1238
-            // get the TXN for this payment
1239
-            $transaction = $payment->transaction();
1240
-            // verify transaction
1241
-            if ($transaction instanceof EE_Transaction) {
1242
-                // calculate_total_payments_and_update_status
1243
-                $this->_process_transaction_payments($transaction);
1244
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1245
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1246
-                // apply payment to registrations (if applicable)
1247
-                if ( ! empty($REG_IDs)) {
1248
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1249
-                    $this->_maybe_send_notifications();
1250
-                    // now process status changes for the same registrations
1251
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1252
-                }
1253
-                $this->_maybe_send_notifications($payment);
1254
-                //prepare to render page
1255
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1256
-                do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1257
-                    $payment);
1258
-            } else {
1259
-                EE_Error::add_error(
1260
-                    esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1261
-                    __FILE__, __FUNCTION__, __LINE__
1262
-                );
1263
-            }
1264
-        } else {
1265
-            EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1266
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1267
-        }
1268
-
1269
-        $notices              = EE_Error::get_notices(false, false, false);
1270
-        $this->_template_args = array(
1271
-            'data'    => $json_response_data,
1272
-            'error'   => $notices['errors'],
1273
-            'success' => $notices['success']
1274
-        );
1275
-        $this->_return_json();
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * _validate_payment_request_data
1281
-     *
1282
-     * @return array
1283
-     */
1284
-    protected function _validate_payment_request_data()
1285
-    {
1286
-        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1287
-            return false;
1288
-        }
1289
-        $payment_form = $this->_generate_payment_form_section();
1290
-        try {
1291
-            if ($payment_form->was_submitted()) {
1292
-                $payment_form->receive_form_submission();
1293
-                if ( ! $payment_form->is_valid()) {
1294
-                    $submission_error_messages = array();
1295
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1296
-                        if ($validation_error instanceof EE_Validation_Error) {
1297
-                            $submission_error_messages[] = sprintf(
1298
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1299
-                                $validation_error->get_form_section()->html_label_text(),
1300
-                                $validation_error->getMessage()
1301
-                            );
1302
-                        }
1303
-                    }
1304
-                    EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1305
-
1306
-                    return array();
1307
-                }
1308
-            }
1309
-        } catch (EE_Error $e) {
1310
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1311
-
1312
-            return array();
1313
-        }
1314
-
1315
-        return $payment_form->valid_data();
1316
-    }
1317
-
1318
-
1319
-    /**
1320
-     * _generate_payment_form_section
1321
-     *
1322
-     * @return EE_Form_Section_Proper
1323
-     */
1324
-    protected function _generate_payment_form_section()
1325
-    {
1326
-        return new EE_Form_Section_Proper(
1327
-            array(
1328
-                'name'        => 'txn_admin_payment',
1329
-                'subsections' => array(
1330
-                    'PAY_ID'          => new EE_Text_Input(
1331
-                        array(
1332
-                            'default'               => 0,
1333
-                            'required'              => false,
1334
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1335
-                            'validation_strategies' => array(new EE_Int_Normalization())
1336
-                        )
1337
-                    ),
1338
-                    'TXN_ID'          => new EE_Text_Input(
1339
-                        array(
1340
-                            'default'               => 0,
1341
-                            'required'              => true,
1342
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1343
-                            'validation_strategies' => array(new EE_Int_Normalization())
1344
-                        )
1345
-                    ),
1346
-                    'type'            => new EE_Text_Input(
1347
-                        array(
1348
-                            'default'               => 1,
1349
-                            'required'              => true,
1350
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1351
-                            'validation_strategies' => array(new EE_Int_Normalization())
1352
-                        )
1353
-                    ),
1354
-                    'amount'          => new EE_Text_Input(
1355
-                        array(
1356
-                            'default'               => 0,
1357
-                            'required'              => true,
1358
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1359
-                            'validation_strategies' => array(new EE_Float_Normalization())
1360
-                        )
1361
-                    ),
1362
-                    'status'          => new EE_Text_Input(
1363
-                        array(
1364
-                            'default'         => EEM_Payment::status_id_approved,
1365
-                            'required'        => true,
1366
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1367
-                        )
1368
-                    ),
1369
-                    'PMD_ID'          => new EE_Text_Input(
1370
-                        array(
1371
-                            'default'               => 2,
1372
-                            'required'              => true,
1373
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1374
-                            'validation_strategies' => array(new EE_Int_Normalization())
1375
-                        )
1376
-                    ),
1377
-                    'date'            => new EE_Text_Input(
1378
-                        array(
1379
-                            'default'         => time(),
1380
-                            'required'        => true,
1381
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1382
-                        )
1383
-                    ),
1384
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1385
-                        array(
1386
-                            'default'               => '',
1387
-                            'required'              => false,
1388
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1389
-                            'validation_strategies' => array(
1390
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1391
-                                    100),
1392
-                            )
1393
-                        )
1394
-                    ),
1395
-                    'po_number'       => new EE_Text_Input(
1396
-                        array(
1397
-                            'default'               => '',
1398
-                            'required'              => false,
1399
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1400
-                            'validation_strategies' => array(
1401
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1402
-                                    100),
1403
-                            )
1404
-                        )
1405
-                    ),
1406
-                    'accounting'      => new EE_Text_Input(
1407
-                        array(
1408
-                            'default'               => '',
1409
-                            'required'              => false,
1410
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1411
-                            'validation_strategies' => array(
1412
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1413
-                                    100),
1414
-                            )
1415
-                        )
1416
-                    ),
1417
-                )
1418
-            )
1419
-        );
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * _create_payment_from_request_data
1425
-     *
1426
-     * @param array $valid_data
1427
-     *
1428
-     * @return EE_Payment
1429
-     */
1430
-    protected function _create_payment_from_request_data($valid_data)
1431
-    {
1432
-        $PAY_ID = $valid_data['PAY_ID'];
1433
-        // get payment amount
1434
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1435
-        // payments have a type value of 1 and refunds have a type value of -1
1436
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1437
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1438
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1439
-        $date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1440
-            current_time('timestamp'));
1441
-        $payment = EE_Payment::new_instance(
1442
-            array(
1443
-                'TXN_ID'              => $valid_data['TXN_ID'],
1444
-                'STS_ID'              => $valid_data['status'],
1445
-                'PAY_timestamp'       => $date,
1446
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1447
-                'PMD_ID'              => $valid_data['PMD_ID'],
1448
-                'PAY_amount'          => $amount,
1449
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1450
-                'PAY_po_number'       => $valid_data['po_number'],
1451
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1452
-                'PAY_details'         => $valid_data,
1453
-                'PAY_ID'              => $PAY_ID
1454
-            ),
1455
-            '',
1456
-            array('Y-m-d', 'g:i a')
1457
-        );
1458
-
1459
-        if ( ! $payment->save()) {
1460
-            EE_Error::add_error(
1461
-                sprintf(
1462
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1463
-                    $payment->ID()
1464
-                ),
1465
-                __FILE__, __FUNCTION__, __LINE__
1466
-            );
1467
-        }
1468
-
1469
-        return $payment;
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * _process_transaction_payments
1475
-     *
1476
-     * @param \EE_Transaction $transaction
1477
-     *
1478
-     * @return array
1479
-     */
1480
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1481
-    {
1482
-        /** @type EE_Transaction_Payments $transaction_payments */
1483
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1484
-        //update the transaction with this payment
1485
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1486
-            EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1487
-                __FILE__, __FUNCTION__, __LINE__);
1488
-        } else {
1489
-            EE_Error::add_error(
1490
-                esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1491
-                    'event_espresso')
1492
-                , __FILE__, __FUNCTION__, __LINE__
1493
-            );
1494
-        }
1495
-    }
1496
-
1497
-
1498
-    /**
1499
-     * _get_REG_IDs_to_apply_payment_to
1500
-     *
1501
-     * returns a list of registration IDs that the payment will apply to
1502
-     *
1503
-     * @param \EE_Payment $payment
1504
-     *
1505
-     * @return array
1506
-     */
1507
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1508
-    {
1509
-        $REG_IDs = array();
1510
-        // grab array of IDs for specific registrations to apply changes to
1511
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1512
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1513
-        }
1514
-        //nothing specified ? then get all reg IDs
1515
-        if (empty($REG_IDs)) {
1516
-            $registrations = $payment->transaction()->registrations();
1517
-            $REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1518
-        }
1519
-
1520
-        // ensure that REG_IDs are integers and NOT strings
1521
-        return array_map('intval', $REG_IDs);
1522
-    }
1523
-
1524
-
1525
-    /**
1526
-     * @return array
1527
-     */
1528
-    public function existing_reg_payment_REG_IDs()
1529
-    {
1530
-        return $this->_existing_reg_payment_REG_IDs;
1531
-    }
1532
-
1533
-
1534
-    /**
1535
-     * @param array $existing_reg_payment_REG_IDs
1536
-     */
1537
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1538
-    {
1539
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1540
-    }
1541
-
1542
-
1543
-    /**
1544
-     * _get_existing_reg_payment_REG_IDs
1545
-     *
1546
-     * returns a list of registration IDs that the payment is currently related to
1547
-     * as recorded in the database
1548
-     *
1549
-     * @param \EE_Payment $payment
1550
-     *
1551
-     * @return array
1552
-     */
1553
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1554
-    {
1555
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1556
-            // let's get any existing reg payment records for this payment
1557
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1558
-            // but we only want the REG IDs, so grab the array keys
1559
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1560
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1561
-        }
1562
-
1563
-        return $this->existing_reg_payment_REG_IDs();
1564
-    }
1565
-
1566
-
1567
-    /**
1568
-     * _remove_existing_registration_payments
1569
-     *
1570
-     * this calculates the difference between existing relations
1571
-     * to the supplied payment and the new list registration IDs,
1572
-     * removes any related registrations that no longer apply,
1573
-     * and then updates the registration paid fields
1574
-     *
1575
-     * @param \EE_Payment $payment
1576
-     * @param int         $PAY_ID
1577
-     *
1578
-     * @return bool;
1579
-     */
1580
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1581
-    {
1582
-        // newly created payments will have nothing recorded for $PAY_ID
1583
-        if ($PAY_ID == 0) {
1584
-            return false;
1585
-        }
1586
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1587
-        if (empty($existing_reg_payment_REG_IDs)) {
1588
-            return false;
1589
-        }
1590
-        /** @type EE_Transaction_Payments $transaction_payments */
1591
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1592
-
1593
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1594
-            $payment,
1595
-            array(
1596
-                array(
1597
-                    'PAY_ID' => $payment->ID(),
1598
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1599
-                )
1600
-            )
1601
-        );
1602
-    }
1603
-
1604
-
1605
-    /**
1606
-     * _update_registration_payments
1607
-     *
1608
-     * this applies the payments to the selected registrations
1609
-     * but only if they have not already been paid for
1610
-     *
1611
-     * @param  EE_Transaction $transaction
1612
-     * @param \EE_Payment     $payment
1613
-     * @param array           $REG_IDs
1614
-     *
1615
-     * @return bool
1616
-     */
1617
-    protected function _update_registration_payments(
1618
-        EE_Transaction $transaction,
1619
-        EE_Payment $payment,
1620
-        $REG_IDs = array()
1621
-    ) {
1622
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1623
-        // so let's do that using our set of REG_IDs from the form
1624
-        $registration_query_where_params = array(
1625
-            'REG_ID' => array('IN', $REG_IDs)
1626
-        );
1627
-        // but add in some conditions regarding payment,
1628
-        // so that we don't apply payments to registrations that are free or have already been paid for
1629
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1630
-        if ( ! $payment->is_a_refund()) {
1631
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
1632
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1633
-        }
1634
-        //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1635
-        $registrations = $transaction->registrations(array($registration_query_where_params));
1636
-        if ( ! empty($registrations)) {
1637
-            /** @type EE_Payment_Processor $payment_processor */
1638
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1639
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
1640
-        }
1641
-    }
1642
-
1643
-
1644
-    /**
1645
-     * _process_registration_status_change
1646
-     *
1647
-     * This processes requested registration status changes for all the registrations
1648
-     * on a given transaction and (optionally) sends out notifications for the changes.
1649
-     *
1650
-     * @param  EE_Transaction $transaction
1651
-     * @param array           $REG_IDs
1652
-     *
1653
-     * @return bool
1654
-     */
1655
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1656
-    {
1657
-        // first if there is no change in status then we get out.
1658
-        if (
1659
-            ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1660
-            || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1661
-        ) {
1662
-            //no error message, no change requested, just nothing to do man.
1663
-            return false;
1664
-        }
1665
-        /** @type EE_Transaction_Processor $transaction_processor */
1666
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1667
-
1668
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1669
-        return $transaction_processor->manually_update_registration_statuses(
1670
-            $transaction,
1671
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1672
-            array(array('REG_ID' => array('IN', $REG_IDs)))
1673
-        );
1674
-    }
1675
-
1676
-
1677
-    /**
1678
-     * _build_payment_json_response
1679
-     *
1680
-     * @access public
1681
-     *
1682
-     * @param \EE_Payment $payment
1683
-     * @param array       $REG_IDs
1684
-     * @param bool | null $delete_txn_reg_status_change
1685
-     *
1686
-     * @return array
1687
-     */
1688
-    protected function _build_payment_json_response(
1689
-        EE_Payment $payment,
1690
-        $REG_IDs = array(),
1691
-        $delete_txn_reg_status_change = null
1692
-    ) {
1693
-        // was the payment deleted ?
1694
-        if (is_bool($delete_txn_reg_status_change)) {
1695
-            return array(
1696
-                'PAY_ID'                       => $payment->ID(),
1697
-                'amount'                       => $payment->amount(),
1698
-                'total_paid'                   => $payment->transaction()->paid(),
1699
-                'txn_status'                   => $payment->transaction()->status_ID(),
1700
-                'pay_status'                   => $payment->STS_ID(),
1701
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1702
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1703
-            );
1704
-        } else {
1705
-            $this->_get_payment_status_array();
1706
-
1707
-            return array(
1708
-                'amount'           => $payment->amount(),
1709
-                'total_paid'       => $payment->transaction()->paid(),
1710
-                'txn_status'       => $payment->transaction()->status_ID(),
1711
-                'pay_status'       => $payment->STS_ID(),
1712
-                'PAY_ID'           => $payment->ID(),
1713
-                'STS_ID'           => $payment->STS_ID(),
1714
-                'status'           => self::$_pay_status[$payment->STS_ID()],
1715
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1716
-                'method'           => strtoupper($payment->source()),
1717
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1718
-                'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1719
-                    'event_espresso'),
1720
-                'gateway_response' => $payment->gateway_response(),
1721
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1722
-                'po_number'        => $payment->po_number(),
1723
-                'extra_accntng'    => $payment->extra_accntng(),
1724
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1725
-            );
1726
-        }
1727
-    }
1728
-
1729
-
1730
-    /**
1731
-     * delete_payment
1732
-     *    delete a payment or refund made towards a transaction
1733
-     *
1734
-     * @access public
1735
-     * @return void
1736
-     */
1737
-    public function delete_payment()
1738
-    {
1739
-        $json_response_data = array('return_data' => false);
1740
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1741
-        if ($PAY_ID) {
1742
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1743
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1744
-            if ($payment instanceof EE_Payment) {
1745
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1746
-                /** @type EE_Transaction_Payments $transaction_payments */
1747
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1748
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1749
-                    $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1750
-                        $delete_txn_reg_status_change);
1751
-                    if ($delete_txn_reg_status_change) {
1752
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1753
-                        //MAKE sure we also add the delete_txn_req_status_change to the
1754
-                        //$_REQUEST global because that's how messages will be looking for it.
1755
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1756
-                        $this->_maybe_send_notifications();
1757
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1758
-                    }
1759
-                }
1760
-            } else {
1761
-                EE_Error::add_error(
1762
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1763
-                    __FILE__, __FUNCTION__, __LINE__
1764
-                );
1765
-            }
1766
-        } else {
1767
-            EE_Error::add_error(
1768
-                esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1769
-                    'event_espresso'),
1770
-                __FILE__, __FUNCTION__, __LINE__
1771
-            );
1772
-        }
1773
-        $notices              = EE_Error::get_notices(false, false, false);
1774
-        $this->_template_args = array(
1775
-            'data'      => $json_response_data,
1776
-            'success'   => $notices['success'],
1777
-            'error'     => $notices['errors'],
1778
-            'attention' => $notices['attention']
1779
-        );
1780
-        $this->_return_json();
1781
-    }
1782
-
1783
-
1784
-    /**
1785
-     * _registration_payment_data_array
1786
-     * adds info for 'owing' and 'paid' for each registration to the json response
1787
-     *
1788
-     * @access protected
1789
-     *
1790
-     * @param array $REG_IDs
1791
-     *
1792
-     * @return array
1793
-     */
1794
-    protected function _registration_payment_data_array($REG_IDs)
1795
-    {
1796
-        $registration_payment_data = array();
1797
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1798
-        if ( ! empty($REG_IDs)) {
1799
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1800
-            foreach ($registrations as $registration) {
1801
-                if ($registration instanceof EE_Registration) {
1802
-                    $registration_payment_data[$registration->ID()] = array(
1803
-                        'paid'  => $registration->pretty_paid(),
1804
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1805
-                    );
1806
-                }
1807
-            }
1808
-        }
1809
-
1810
-        return $registration_payment_data;
1811
-    }
1812
-
1813
-
1814
-    /**
1815
-     * _maybe_send_notifications
1816
-     *
1817
-     * determines whether or not the admin has indicated that notifications should be sent.
1818
-     * If so, will toggle a filter switch for delivering registration notices.
1819
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
1820
-     *
1821
-     * @access protected
1822
-     *
1823
-     * @param \EE_Payment | null $payment
1824
-     */
1825
-    protected function _maybe_send_notifications($payment = null)
1826
-    {
1827
-        switch ($payment instanceof EE_Payment) {
1828
-            // payment notifications
1829
-            case true :
1830
-                if (
1831
-                    isset(
1832
-                        $this->_req_data['txn_payments'],
1833
-                        $this->_req_data['txn_payments']['send_notifications']
1834
-                    ) &&
1835
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1836
-                ) {
1837
-                    $this->_process_payment_notification($payment);
1838
-                }
1839
-                break;
1840
-            // registration notifications
1841
-            case false :
1842
-                if (
1843
-                    isset(
1844
-                        $this->_req_data['txn_reg_status_change'],
1845
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
1846
-                    ) &&
1847
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1848
-                ) {
1849
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1850
-                }
1851
-                break;
1852
-        }
1853
-    }
1854
-
1855
-
1856
-    /**
1857
-     * _send_payment_reminder
1858
-     *    generates HTML for the View Transaction Details Admin page
1859
-     *
1860
-     * @access protected
1861
-     * @return void
1862
-     */
1863
-    protected function _send_payment_reminder()
1864
-    {
1865
-        $TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1866
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1867
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
1868
-            'action' => $this->_req_data['redirect_to'],
1869
-            'TXN_ID' => $this->_req_data['TXN_ID']
1870
-        ) : array();
1871
-        do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1872
-            $transaction);
1873
-        $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1874
-            esc_html__('sent', 'event_espresso'), $query_args, true);
1875
-    }
1876
-
1877
-
1878
-    /**
1879
-     *  get_transactions
1880
-     *    get transactions for given parameters (used by list table)
1881
-     *
1882
-     * @param  int     $perpage how many transactions displayed per page
1883
-     * @param  boolean $count   return the count or objects
1884
-     * @param string   $view
1885
-     *
1886
-     * @return mixed int = count || array of transaction objects
1887
-     */
1888
-    public function get_transactions($perpage, $count = false, $view = '')
1889
-    {
1890
-
1891
-        $TXN = EEM_Transaction::instance();
1892
-
1893
-        $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1894
-            strtotime('-10 year'));
1895
-        $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1896
-
1897
-        //make sure our timestamps start and end right at the boundaries for each day
1898
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1899
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1900
-
1901
-
1902
-        //convert to timestamps
1903
-        $start_date = strtotime($start_date);
1904
-        $end_date   = strtotime($end_date);
1905
-
1906
-        //makes sure start date is the lowest value and vice versa
1907
-        $start_date = min($start_date, $end_date);
1908
-        $end_date   = max($start_date, $end_date);
1909
-
1910
-        //convert to correct format for query
1911
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1912
-            date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1913
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1914
-            date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1915
-
1916
-
1917
-        //set orderby
1918
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1919
-
1920
-        switch ($this->_req_data['orderby']) {
1921
-            case 'TXN_ID':
1922
-                $orderby = 'TXN_ID';
1923
-                break;
1924
-            case 'ATT_fname':
1925
-                $orderby = 'Registration.Attendee.ATT_fname';
1926
-                break;
1927
-            case 'event_name':
1928
-                $orderby = 'Registration.Event.EVT_name';
1929
-                break;
1930
-            default: //'TXN_timestamp'
1931
-                $orderby = 'TXN_timestamp';
1932
-        }
1933
-
1934
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1935
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1936
-        $per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1937
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1938
-
1939
-        $offset = ($current_page - 1) * $per_page;
1940
-        $limit  = array($offset, $per_page);
1941
-
1942
-        $_where = array(
1943
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1944
-            'Registration.REG_count' => 1
1945
-        );
1946
-
1947
-        if (isset($this->_req_data['EVT_ID'])) {
1948
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1949
-        }
1950
-
1951
-        if (isset($this->_req_data['s'])) {
1952
-            $search_string = '%' . $this->_req_data['s'] . '%';
1953
-            $_where['OR']  = array(
1954
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1955
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1956
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1957
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1958
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1959
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1960
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1961
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1962
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1963
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1964
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1965
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
1966
-                'Registration.REG_code'               => array('LIKE', $search_string),
1967
-                'Registration.REG_count'              => array('LIKE', $search_string),
1968
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
1969
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1970
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1971
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
1972
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1973
-                'TXN_session_data'                    => array('LIKE', $search_string),
1974
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1975
-            );
1976
-        }
1977
-
1978
-        //failed transactions
1979
-        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1980
-        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1981
-
1982
-        if ($failed) {
1983
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
1984
-        } else if ($abandoned) {
1985
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1986
-        } else {
1987
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1988
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1989
-        }
1990
-
1991
-        $query_params = array(
1992
-            $_where,
1993
-            'order_by' => array($orderby => $sort),
1994
-            'limit' => $limit,
1995
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only
1996
-        );
1997
-
1998
-        $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1999
-
2000
-
2001
-        return $transactions;
2002
-
2003
-    }
807
+		// process payment details
808
+		$payments = $this->_transaction->get_many_related('Payment');
809
+		if ( ! empty($payments)) {
810
+			$this->_template_args['payments']              = $payments;
811
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
812
+		} else {
813
+			$this->_template_args['payments']              = false;
814
+			$this->_template_args['existing_reg_payments'] = array();
815
+		}
816
+
817
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
818
+		$this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
819
+			TXN_ADMIN_URL);
820
+
821
+		if (isset($txn_details['invoice_number'])) {
822
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
823
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
824
+				'event_espresso');
825
+		}
826
+
827
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
828
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
829
+			'event_espresso');
830
+
831
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
832
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
833
+			'event_espresso');
834
+
835
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
836
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
837
+			'event_espresso');
838
+
839
+		$reg_steps = '<ul>';
840
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
841
+			if ($reg_step_status === true) {
842
+				$reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
843
+						ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
844
+			} else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
845
+				$reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
846
+						esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
847
+						ucwords(str_replace('_', ' ', $reg_step)),
848
+						date(get_option('date_format') . ' ' . get_option('time_format'),
849
+							($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
850
+					) . '</li>';
851
+			} else {
852
+				$reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
853
+						'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
854
+			}
855
+		}
856
+		$reg_steps .= '</ul>';
857
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
858
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
859
+			'event_espresso');
860
+
861
+
862
+		$this->_get_registrations_to_apply_payment_to();
863
+		$this->_get_payment_methods($payments);
864
+		$this->_get_payment_status_array();
865
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
866
+
867
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
868
+			'action'  => 'edit_transaction',
869
+			'process' => 'transaction'
870
+		), TXN_ADMIN_URL);
871
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
872
+			'page'   => 'espresso_transactions',
873
+			'action' => 'espresso_apply_payment'
874
+		), WP_AJAX_URL);
875
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
876
+			'page'   => 'espresso_transactions',
877
+			'action' => 'espresso_delete_payment'
878
+		), WP_AJAX_URL);
879
+
880
+		// 'espresso_delete_payment_nonce'
881
+
882
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
883
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
884
+
885
+	}
886
+
887
+
888
+	/**
889
+	 * _get_registration_payment_IDs
890
+	 *
891
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
892
+	 *
893
+	 * @access protected
894
+	 *
895
+	 * @param EE_Payment[] $payments
896
+	 *
897
+	 * @return array
898
+	 */
899
+	protected function _get_registration_payment_IDs($payments = array())
900
+	{
901
+		$existing_reg_payments = array();
902
+		// get all reg payments for these payments
903
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
904
+			array(
905
+				'PAY_ID' => array(
906
+					'IN',
907
+					array_keys($payments)
908
+				)
909
+			)
910
+		));
911
+		if ( ! empty($reg_payments)) {
912
+			foreach ($payments as $payment) {
913
+				if ( ! $payment instanceof EE_Payment) {
914
+					continue;
915
+				} else if ( ! isset($existing_reg_payments[$payment->ID()])) {
916
+					$existing_reg_payments[$payment->ID()] = array();
917
+				}
918
+				foreach ($reg_payments as $reg_payment) {
919
+					if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
920
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
921
+					}
922
+				}
923
+			}
924
+		}
925
+
926
+		return $existing_reg_payments;
927
+	}
928
+
929
+
930
+	/**
931
+	 * _get_registrations_to_apply_payment_to
932
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
933
+	 * which allows the admin to only apply the payment to the specific registrations
934
+	 *
935
+	 * @access protected
936
+	 * @return void
937
+	 * @throws \EE_Error
938
+	 */
939
+	protected function _get_registrations_to_apply_payment_to()
940
+	{
941
+		// we want any registration with an active status (ie: not deleted or cancelled)
942
+		$query_params                      = array(
943
+			array(
944
+				'STS_ID' => array(
945
+					'IN',
946
+					array(
947
+						EEM_Registration::status_id_approved,
948
+						EEM_Registration::status_id_pending_payment,
949
+						EEM_Registration::status_id_not_approved,
950
+					)
951
+				)
952
+			)
953
+		);
954
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
955
+				'', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
956
+			);
957
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
958
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
959
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
960
+			EEH_HTML::tr(
961
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
962
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
963
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
964
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
965
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
966
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
967
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
968
+			)
969
+		);
970
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
971
+		// get registrations for TXN
972
+		$registrations = $this->_transaction->registrations($query_params);
973
+		foreach ($registrations as $registration) {
974
+			if ($registration instanceof EE_Registration) {
975
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
976
+					? $registration->attendee()->full_name()
977
+					: esc_html__('Unknown Attendee', 'event_espresso');
978
+				$owing         = $registration->final_price() - $registration->paid();
979
+				$taxable       = $registration->ticket()->taxable()
980
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
981
+					: '';
982
+				$checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
983
+					? ' checked="checked"'
984
+					: '';
985
+				$disabled      = $registration->final_price() > 0 ? '' : ' disabled';
986
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
987
+					EEH_HTML::td($registration->ID()) .
988
+					EEH_HTML::td($attendee_name) .
989
+					EEH_HTML::td(
990
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
991
+					) .
992
+					EEH_HTML::td($registration->event_name()) .
993
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
994
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
995
+					EEH_HTML::td(
996
+						'<input type="checkbox" value="' . $registration->ID()
997
+						. '" name="txn_admin_payment[registrations]"'
998
+						. $checked . $disabled . '>',
999
+						'', 'jst-cntr'
1000
+					),
1001
+					'apply-payment-registration-row-' . $registration->ID()
1002
+				);
1003
+			}
1004
+		}
1005
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1006
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1007
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1008
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1009
+			esc_html__(
1010
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1011
+				'event_espresso'
1012
+			),
1013
+			'', 'clear description'
1014
+		);
1015
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1016
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * _get_reg_status_selection
1022
+	 *
1023
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1024
+	 *         instead of events.
1025
+	 * @access protected
1026
+	 * @return void
1027
+	 */
1028
+	protected function _get_reg_status_selection()
1029
+	{
1030
+		//first get all possible statuses
1031
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1032
+		//let's add a "don't change" option.
1033
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1034
+		$status_array                                        = array_merge($status_array, $statuses);
1035
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1036
+			$status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1037
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1038
+			$status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1039
+
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    _get_payment_methods
1045
+	 * Gets all the payment methods available generally, or the ones that are already
1046
+	 * selected on these payments (in case their payment methods are no longer active).
1047
+	 * Has the side-effect of updating the template args' payment_methods item
1048
+	 * @access private
1049
+	 *
1050
+	 * @param EE_Payment[] to show on this page
1051
+	 *
1052
+	 * @return void
1053
+	 */
1054
+	private function _get_payment_methods($payments = array())
1055
+	{
1056
+		$payment_methods_of_payments = array();
1057
+		foreach ($payments as $payment) {
1058
+			if ($payment instanceof EE_Payment) {
1059
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1060
+			}
1061
+		}
1062
+		if ($payment_methods_of_payments) {
1063
+			$query_args = array(
1064
+				array(
1065
+					'OR*payment_method_for_payment' => array(
1066
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1067
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1068
+					)
1069
+				)
1070
+			);
1071
+		} else {
1072
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1073
+		}
1074
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * txn_attendees_meta_box
1080
+	 *    generates HTML for the Attendees Transaction main meta box
1081
+	 *
1082
+	 * @access public
1083
+	 *
1084
+	 * @param WP_Post $post
1085
+	 * @param array   $metabox
1086
+	 *
1087
+	 * @return void
1088
+	 */
1089
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1090
+	{
1091
+
1092
+		extract($metabox['args']);
1093
+		$this->_template_args['post']            = $post;
1094
+		$this->_template_args['event_attendees'] = array();
1095
+		// process items in cart
1096
+		$line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1097
+		if ( ! empty($line_items)) {
1098
+			foreach ($line_items as $item) {
1099
+				if ($item instanceof EE_Line_Item) {
1100
+					switch ($item->OBJ_type()) {
1101
+
1102
+						case 'Event' :
1103
+							break;
1104
+
1105
+						case 'Ticket' :
1106
+							$ticket = $item->ticket();
1107
+							//right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1108
+							if ( ! $ticket instanceof EE_Ticket) {
1109
+								continue;
1110
+							}
1111
+							try {
1112
+								$event_name = $ticket->get_event_name();
1113
+							} catch (Exception $e) {
1114
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1115
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1116
+							}
1117
+							$event_name .= ' - ' . $item->get('LIN_name');
1118
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1119
+							// now get all of the registrations for this transaction that use this ticket
1120
+							$registrations = $ticket->get_many_related('Registration',
1121
+								array(array('TXN_ID' => $this->_transaction->ID())));
1122
+							foreach ($registrations as $registration) {
1123
+								if ( ! $registration instanceof EE_Registration) {
1124
+									continue;
1125
+								}
1126
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1127
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1128
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1129
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1130
+								// attendee info
1131
+								$attendee = $registration->get_first_related('Attendee');
1132
+								if ($attendee instanceof EE_Attendee) {
1133
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1134
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1135
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1136
+											'event_espresso') . '">' . $attendee->email() . '</a>';
1137
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1138
+										'inline', false, false);
1139
+								} else {
1140
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1141
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1142
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1143
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1144
+								}
1145
+							}
1146
+							break;
1147
+
1148
+					}
1149
+				}
1150
+			}
1151
+
1152
+			$this->_template_args['transaction_form_url'] = add_query_arg(array(
1153
+				'action'  => 'edit_transaction',
1154
+				'process' => 'attendees'
1155
+			), TXN_ADMIN_URL);
1156
+			echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1157
+				$this->_template_args, true);
1158
+
1159
+		} else {
1160
+			echo sprintf(
1161
+				esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1162
+					'event_espresso'),
1163
+				'<p class="important-notice">',
1164
+				'</p>'
1165
+			);
1166
+		}
1167
+	}
1168
+
1169
+
1170
+	/**
1171
+	 * txn_registrant_side_meta_box
1172
+	 * generates HTML for the Edit Transaction side meta box
1173
+	 *
1174
+	 * @access public
1175
+	 * @throws \EE_Error
1176
+	 * @return void
1177
+	 */
1178
+	public function txn_registrant_side_meta_box()
1179
+	{
1180
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1181
+		if ( ! $primary_att instanceof EE_Attendee) {
1182
+			$this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1183
+				'event_espresso');
1184
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1185
+		}
1186
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1187
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1188
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1189
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1190
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1191
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1192
+			'action' => 'edit_attendee',
1193
+			'post'   => $primary_att->ID()
1194
+		), REG_ADMIN_URL);
1195
+		// get formatted address for registrant
1196
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1197
+		echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1198
+			$this->_template_args, true);
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * txn_billing_info_side_meta_box
1204
+	 *    generates HTML for the Edit Transaction side meta box
1205
+	 *
1206
+	 * @access public
1207
+	 * @return void
1208
+	 */
1209
+	public function txn_billing_info_side_meta_box()
1210
+	{
1211
+
1212
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1213
+		$this->_template_args['billing_form_url'] = add_query_arg(
1214
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1215
+			TXN_ADMIN_URL
1216
+		);
1217
+
1218
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1219
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * apply_payments_or_refunds
1225
+	 *    registers a payment or refund made towards a transaction
1226
+	 *
1227
+	 * @access public
1228
+	 * @return void
1229
+	 */
1230
+	public function apply_payments_or_refunds()
1231
+	{
1232
+		$json_response_data = array('return_data' => false);
1233
+		$valid_data         = $this->_validate_payment_request_data();
1234
+		if ( ! empty($valid_data)) {
1235
+			$PAY_ID = $valid_data['PAY_ID'];
1236
+			//save  the new payment
1237
+			$payment = $this->_create_payment_from_request_data($valid_data);
1238
+			// get the TXN for this payment
1239
+			$transaction = $payment->transaction();
1240
+			// verify transaction
1241
+			if ($transaction instanceof EE_Transaction) {
1242
+				// calculate_total_payments_and_update_status
1243
+				$this->_process_transaction_payments($transaction);
1244
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1245
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1246
+				// apply payment to registrations (if applicable)
1247
+				if ( ! empty($REG_IDs)) {
1248
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1249
+					$this->_maybe_send_notifications();
1250
+					// now process status changes for the same registrations
1251
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1252
+				}
1253
+				$this->_maybe_send_notifications($payment);
1254
+				//prepare to render page
1255
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1256
+				do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1257
+					$payment);
1258
+			} else {
1259
+				EE_Error::add_error(
1260
+					esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1261
+					__FILE__, __FUNCTION__, __LINE__
1262
+				);
1263
+			}
1264
+		} else {
1265
+			EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1266
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1267
+		}
1268
+
1269
+		$notices              = EE_Error::get_notices(false, false, false);
1270
+		$this->_template_args = array(
1271
+			'data'    => $json_response_data,
1272
+			'error'   => $notices['errors'],
1273
+			'success' => $notices['success']
1274
+		);
1275
+		$this->_return_json();
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * _validate_payment_request_data
1281
+	 *
1282
+	 * @return array
1283
+	 */
1284
+	protected function _validate_payment_request_data()
1285
+	{
1286
+		if ( ! isset($this->_req_data['txn_admin_payment'])) {
1287
+			return false;
1288
+		}
1289
+		$payment_form = $this->_generate_payment_form_section();
1290
+		try {
1291
+			if ($payment_form->was_submitted()) {
1292
+				$payment_form->receive_form_submission();
1293
+				if ( ! $payment_form->is_valid()) {
1294
+					$submission_error_messages = array();
1295
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1296
+						if ($validation_error instanceof EE_Validation_Error) {
1297
+							$submission_error_messages[] = sprintf(
1298
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1299
+								$validation_error->get_form_section()->html_label_text(),
1300
+								$validation_error->getMessage()
1301
+							);
1302
+						}
1303
+					}
1304
+					EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1305
+
1306
+					return array();
1307
+				}
1308
+			}
1309
+		} catch (EE_Error $e) {
1310
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1311
+
1312
+			return array();
1313
+		}
1314
+
1315
+		return $payment_form->valid_data();
1316
+	}
1317
+
1318
+
1319
+	/**
1320
+	 * _generate_payment_form_section
1321
+	 *
1322
+	 * @return EE_Form_Section_Proper
1323
+	 */
1324
+	protected function _generate_payment_form_section()
1325
+	{
1326
+		return new EE_Form_Section_Proper(
1327
+			array(
1328
+				'name'        => 'txn_admin_payment',
1329
+				'subsections' => array(
1330
+					'PAY_ID'          => new EE_Text_Input(
1331
+						array(
1332
+							'default'               => 0,
1333
+							'required'              => false,
1334
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1335
+							'validation_strategies' => array(new EE_Int_Normalization())
1336
+						)
1337
+					),
1338
+					'TXN_ID'          => new EE_Text_Input(
1339
+						array(
1340
+							'default'               => 0,
1341
+							'required'              => true,
1342
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1343
+							'validation_strategies' => array(new EE_Int_Normalization())
1344
+						)
1345
+					),
1346
+					'type'            => new EE_Text_Input(
1347
+						array(
1348
+							'default'               => 1,
1349
+							'required'              => true,
1350
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1351
+							'validation_strategies' => array(new EE_Int_Normalization())
1352
+						)
1353
+					),
1354
+					'amount'          => new EE_Text_Input(
1355
+						array(
1356
+							'default'               => 0,
1357
+							'required'              => true,
1358
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1359
+							'validation_strategies' => array(new EE_Float_Normalization())
1360
+						)
1361
+					),
1362
+					'status'          => new EE_Text_Input(
1363
+						array(
1364
+							'default'         => EEM_Payment::status_id_approved,
1365
+							'required'        => true,
1366
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1367
+						)
1368
+					),
1369
+					'PMD_ID'          => new EE_Text_Input(
1370
+						array(
1371
+							'default'               => 2,
1372
+							'required'              => true,
1373
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1374
+							'validation_strategies' => array(new EE_Int_Normalization())
1375
+						)
1376
+					),
1377
+					'date'            => new EE_Text_Input(
1378
+						array(
1379
+							'default'         => time(),
1380
+							'required'        => true,
1381
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1382
+						)
1383
+					),
1384
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1385
+						array(
1386
+							'default'               => '',
1387
+							'required'              => false,
1388
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1389
+							'validation_strategies' => array(
1390
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1391
+									100),
1392
+							)
1393
+						)
1394
+					),
1395
+					'po_number'       => new EE_Text_Input(
1396
+						array(
1397
+							'default'               => '',
1398
+							'required'              => false,
1399
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1400
+							'validation_strategies' => array(
1401
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1402
+									100),
1403
+							)
1404
+						)
1405
+					),
1406
+					'accounting'      => new EE_Text_Input(
1407
+						array(
1408
+							'default'               => '',
1409
+							'required'              => false,
1410
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1411
+							'validation_strategies' => array(
1412
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1413
+									100),
1414
+							)
1415
+						)
1416
+					),
1417
+				)
1418
+			)
1419
+		);
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * _create_payment_from_request_data
1425
+	 *
1426
+	 * @param array $valid_data
1427
+	 *
1428
+	 * @return EE_Payment
1429
+	 */
1430
+	protected function _create_payment_from_request_data($valid_data)
1431
+	{
1432
+		$PAY_ID = $valid_data['PAY_ID'];
1433
+		// get payment amount
1434
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1435
+		// payments have a type value of 1 and refunds have a type value of -1
1436
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1437
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1438
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1439
+		$date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1440
+			current_time('timestamp'));
1441
+		$payment = EE_Payment::new_instance(
1442
+			array(
1443
+				'TXN_ID'              => $valid_data['TXN_ID'],
1444
+				'STS_ID'              => $valid_data['status'],
1445
+				'PAY_timestamp'       => $date,
1446
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1447
+				'PMD_ID'              => $valid_data['PMD_ID'],
1448
+				'PAY_amount'          => $amount,
1449
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1450
+				'PAY_po_number'       => $valid_data['po_number'],
1451
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1452
+				'PAY_details'         => $valid_data,
1453
+				'PAY_ID'              => $PAY_ID
1454
+			),
1455
+			'',
1456
+			array('Y-m-d', 'g:i a')
1457
+		);
1458
+
1459
+		if ( ! $payment->save()) {
1460
+			EE_Error::add_error(
1461
+				sprintf(
1462
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1463
+					$payment->ID()
1464
+				),
1465
+				__FILE__, __FUNCTION__, __LINE__
1466
+			);
1467
+		}
1468
+
1469
+		return $payment;
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * _process_transaction_payments
1475
+	 *
1476
+	 * @param \EE_Transaction $transaction
1477
+	 *
1478
+	 * @return array
1479
+	 */
1480
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1481
+	{
1482
+		/** @type EE_Transaction_Payments $transaction_payments */
1483
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1484
+		//update the transaction with this payment
1485
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1486
+			EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1487
+				__FILE__, __FUNCTION__, __LINE__);
1488
+		} else {
1489
+			EE_Error::add_error(
1490
+				esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1491
+					'event_espresso')
1492
+				, __FILE__, __FUNCTION__, __LINE__
1493
+			);
1494
+		}
1495
+	}
1496
+
1497
+
1498
+	/**
1499
+	 * _get_REG_IDs_to_apply_payment_to
1500
+	 *
1501
+	 * returns a list of registration IDs that the payment will apply to
1502
+	 *
1503
+	 * @param \EE_Payment $payment
1504
+	 *
1505
+	 * @return array
1506
+	 */
1507
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1508
+	{
1509
+		$REG_IDs = array();
1510
+		// grab array of IDs for specific registrations to apply changes to
1511
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1512
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1513
+		}
1514
+		//nothing specified ? then get all reg IDs
1515
+		if (empty($REG_IDs)) {
1516
+			$registrations = $payment->transaction()->registrations();
1517
+			$REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1518
+		}
1519
+
1520
+		// ensure that REG_IDs are integers and NOT strings
1521
+		return array_map('intval', $REG_IDs);
1522
+	}
1523
+
1524
+
1525
+	/**
1526
+	 * @return array
1527
+	 */
1528
+	public function existing_reg_payment_REG_IDs()
1529
+	{
1530
+		return $this->_existing_reg_payment_REG_IDs;
1531
+	}
1532
+
1533
+
1534
+	/**
1535
+	 * @param array $existing_reg_payment_REG_IDs
1536
+	 */
1537
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1538
+	{
1539
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1540
+	}
1541
+
1542
+
1543
+	/**
1544
+	 * _get_existing_reg_payment_REG_IDs
1545
+	 *
1546
+	 * returns a list of registration IDs that the payment is currently related to
1547
+	 * as recorded in the database
1548
+	 *
1549
+	 * @param \EE_Payment $payment
1550
+	 *
1551
+	 * @return array
1552
+	 */
1553
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1554
+	{
1555
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1556
+			// let's get any existing reg payment records for this payment
1557
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1558
+			// but we only want the REG IDs, so grab the array keys
1559
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1560
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1561
+		}
1562
+
1563
+		return $this->existing_reg_payment_REG_IDs();
1564
+	}
1565
+
1566
+
1567
+	/**
1568
+	 * _remove_existing_registration_payments
1569
+	 *
1570
+	 * this calculates the difference between existing relations
1571
+	 * to the supplied payment and the new list registration IDs,
1572
+	 * removes any related registrations that no longer apply,
1573
+	 * and then updates the registration paid fields
1574
+	 *
1575
+	 * @param \EE_Payment $payment
1576
+	 * @param int         $PAY_ID
1577
+	 *
1578
+	 * @return bool;
1579
+	 */
1580
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1581
+	{
1582
+		// newly created payments will have nothing recorded for $PAY_ID
1583
+		if ($PAY_ID == 0) {
1584
+			return false;
1585
+		}
1586
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1587
+		if (empty($existing_reg_payment_REG_IDs)) {
1588
+			return false;
1589
+		}
1590
+		/** @type EE_Transaction_Payments $transaction_payments */
1591
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1592
+
1593
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1594
+			$payment,
1595
+			array(
1596
+				array(
1597
+					'PAY_ID' => $payment->ID(),
1598
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1599
+				)
1600
+			)
1601
+		);
1602
+	}
1603
+
1604
+
1605
+	/**
1606
+	 * _update_registration_payments
1607
+	 *
1608
+	 * this applies the payments to the selected registrations
1609
+	 * but only if they have not already been paid for
1610
+	 *
1611
+	 * @param  EE_Transaction $transaction
1612
+	 * @param \EE_Payment     $payment
1613
+	 * @param array           $REG_IDs
1614
+	 *
1615
+	 * @return bool
1616
+	 */
1617
+	protected function _update_registration_payments(
1618
+		EE_Transaction $transaction,
1619
+		EE_Payment $payment,
1620
+		$REG_IDs = array()
1621
+	) {
1622
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1623
+		// so let's do that using our set of REG_IDs from the form
1624
+		$registration_query_where_params = array(
1625
+			'REG_ID' => array('IN', $REG_IDs)
1626
+		);
1627
+		// but add in some conditions regarding payment,
1628
+		// so that we don't apply payments to registrations that are free or have already been paid for
1629
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1630
+		if ( ! $payment->is_a_refund()) {
1631
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
1632
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1633
+		}
1634
+		//EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1635
+		$registrations = $transaction->registrations(array($registration_query_where_params));
1636
+		if ( ! empty($registrations)) {
1637
+			/** @type EE_Payment_Processor $payment_processor */
1638
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1639
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
1640
+		}
1641
+	}
1642
+
1643
+
1644
+	/**
1645
+	 * _process_registration_status_change
1646
+	 *
1647
+	 * This processes requested registration status changes for all the registrations
1648
+	 * on a given transaction and (optionally) sends out notifications for the changes.
1649
+	 *
1650
+	 * @param  EE_Transaction $transaction
1651
+	 * @param array           $REG_IDs
1652
+	 *
1653
+	 * @return bool
1654
+	 */
1655
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1656
+	{
1657
+		// first if there is no change in status then we get out.
1658
+		if (
1659
+			! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1660
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1661
+		) {
1662
+			//no error message, no change requested, just nothing to do man.
1663
+			return false;
1664
+		}
1665
+		/** @type EE_Transaction_Processor $transaction_processor */
1666
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1667
+
1668
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1669
+		return $transaction_processor->manually_update_registration_statuses(
1670
+			$transaction,
1671
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1672
+			array(array('REG_ID' => array('IN', $REG_IDs)))
1673
+		);
1674
+	}
1675
+
1676
+
1677
+	/**
1678
+	 * _build_payment_json_response
1679
+	 *
1680
+	 * @access public
1681
+	 *
1682
+	 * @param \EE_Payment $payment
1683
+	 * @param array       $REG_IDs
1684
+	 * @param bool | null $delete_txn_reg_status_change
1685
+	 *
1686
+	 * @return array
1687
+	 */
1688
+	protected function _build_payment_json_response(
1689
+		EE_Payment $payment,
1690
+		$REG_IDs = array(),
1691
+		$delete_txn_reg_status_change = null
1692
+	) {
1693
+		// was the payment deleted ?
1694
+		if (is_bool($delete_txn_reg_status_change)) {
1695
+			return array(
1696
+				'PAY_ID'                       => $payment->ID(),
1697
+				'amount'                       => $payment->amount(),
1698
+				'total_paid'                   => $payment->transaction()->paid(),
1699
+				'txn_status'                   => $payment->transaction()->status_ID(),
1700
+				'pay_status'                   => $payment->STS_ID(),
1701
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1702
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1703
+			);
1704
+		} else {
1705
+			$this->_get_payment_status_array();
1706
+
1707
+			return array(
1708
+				'amount'           => $payment->amount(),
1709
+				'total_paid'       => $payment->transaction()->paid(),
1710
+				'txn_status'       => $payment->transaction()->status_ID(),
1711
+				'pay_status'       => $payment->STS_ID(),
1712
+				'PAY_ID'           => $payment->ID(),
1713
+				'STS_ID'           => $payment->STS_ID(),
1714
+				'status'           => self::$_pay_status[$payment->STS_ID()],
1715
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1716
+				'method'           => strtoupper($payment->source()),
1717
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1718
+				'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1719
+					'event_espresso'),
1720
+				'gateway_response' => $payment->gateway_response(),
1721
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1722
+				'po_number'        => $payment->po_number(),
1723
+				'extra_accntng'    => $payment->extra_accntng(),
1724
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1725
+			);
1726
+		}
1727
+	}
1728
+
1729
+
1730
+	/**
1731
+	 * delete_payment
1732
+	 *    delete a payment or refund made towards a transaction
1733
+	 *
1734
+	 * @access public
1735
+	 * @return void
1736
+	 */
1737
+	public function delete_payment()
1738
+	{
1739
+		$json_response_data = array('return_data' => false);
1740
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1741
+		if ($PAY_ID) {
1742
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1743
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1744
+			if ($payment instanceof EE_Payment) {
1745
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1746
+				/** @type EE_Transaction_Payments $transaction_payments */
1747
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1748
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1749
+					$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1750
+						$delete_txn_reg_status_change);
1751
+					if ($delete_txn_reg_status_change) {
1752
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1753
+						//MAKE sure we also add the delete_txn_req_status_change to the
1754
+						//$_REQUEST global because that's how messages will be looking for it.
1755
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1756
+						$this->_maybe_send_notifications();
1757
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1758
+					}
1759
+				}
1760
+			} else {
1761
+				EE_Error::add_error(
1762
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1763
+					__FILE__, __FUNCTION__, __LINE__
1764
+				);
1765
+			}
1766
+		} else {
1767
+			EE_Error::add_error(
1768
+				esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1769
+					'event_espresso'),
1770
+				__FILE__, __FUNCTION__, __LINE__
1771
+			);
1772
+		}
1773
+		$notices              = EE_Error::get_notices(false, false, false);
1774
+		$this->_template_args = array(
1775
+			'data'      => $json_response_data,
1776
+			'success'   => $notices['success'],
1777
+			'error'     => $notices['errors'],
1778
+			'attention' => $notices['attention']
1779
+		);
1780
+		$this->_return_json();
1781
+	}
1782
+
1783
+
1784
+	/**
1785
+	 * _registration_payment_data_array
1786
+	 * adds info for 'owing' and 'paid' for each registration to the json response
1787
+	 *
1788
+	 * @access protected
1789
+	 *
1790
+	 * @param array $REG_IDs
1791
+	 *
1792
+	 * @return array
1793
+	 */
1794
+	protected function _registration_payment_data_array($REG_IDs)
1795
+	{
1796
+		$registration_payment_data = array();
1797
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1798
+		if ( ! empty($REG_IDs)) {
1799
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1800
+			foreach ($registrations as $registration) {
1801
+				if ($registration instanceof EE_Registration) {
1802
+					$registration_payment_data[$registration->ID()] = array(
1803
+						'paid'  => $registration->pretty_paid(),
1804
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1805
+					);
1806
+				}
1807
+			}
1808
+		}
1809
+
1810
+		return $registration_payment_data;
1811
+	}
1812
+
1813
+
1814
+	/**
1815
+	 * _maybe_send_notifications
1816
+	 *
1817
+	 * determines whether or not the admin has indicated that notifications should be sent.
1818
+	 * If so, will toggle a filter switch for delivering registration notices.
1819
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
1820
+	 *
1821
+	 * @access protected
1822
+	 *
1823
+	 * @param \EE_Payment | null $payment
1824
+	 */
1825
+	protected function _maybe_send_notifications($payment = null)
1826
+	{
1827
+		switch ($payment instanceof EE_Payment) {
1828
+			// payment notifications
1829
+			case true :
1830
+				if (
1831
+					isset(
1832
+						$this->_req_data['txn_payments'],
1833
+						$this->_req_data['txn_payments']['send_notifications']
1834
+					) &&
1835
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1836
+				) {
1837
+					$this->_process_payment_notification($payment);
1838
+				}
1839
+				break;
1840
+			// registration notifications
1841
+			case false :
1842
+				if (
1843
+					isset(
1844
+						$this->_req_data['txn_reg_status_change'],
1845
+						$this->_req_data['txn_reg_status_change']['send_notifications']
1846
+					) &&
1847
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1848
+				) {
1849
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1850
+				}
1851
+				break;
1852
+		}
1853
+	}
1854
+
1855
+
1856
+	/**
1857
+	 * _send_payment_reminder
1858
+	 *    generates HTML for the View Transaction Details Admin page
1859
+	 *
1860
+	 * @access protected
1861
+	 * @return void
1862
+	 */
1863
+	protected function _send_payment_reminder()
1864
+	{
1865
+		$TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1866
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1867
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
1868
+			'action' => $this->_req_data['redirect_to'],
1869
+			'TXN_ID' => $this->_req_data['TXN_ID']
1870
+		) : array();
1871
+		do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1872
+			$transaction);
1873
+		$this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1874
+			esc_html__('sent', 'event_espresso'), $query_args, true);
1875
+	}
1876
+
1877
+
1878
+	/**
1879
+	 *  get_transactions
1880
+	 *    get transactions for given parameters (used by list table)
1881
+	 *
1882
+	 * @param  int     $perpage how many transactions displayed per page
1883
+	 * @param  boolean $count   return the count or objects
1884
+	 * @param string   $view
1885
+	 *
1886
+	 * @return mixed int = count || array of transaction objects
1887
+	 */
1888
+	public function get_transactions($perpage, $count = false, $view = '')
1889
+	{
1890
+
1891
+		$TXN = EEM_Transaction::instance();
1892
+
1893
+		$start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1894
+			strtotime('-10 year'));
1895
+		$end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1896
+
1897
+		//make sure our timestamps start and end right at the boundaries for each day
1898
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1899
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1900
+
1901
+
1902
+		//convert to timestamps
1903
+		$start_date = strtotime($start_date);
1904
+		$end_date   = strtotime($end_date);
1905
+
1906
+		//makes sure start date is the lowest value and vice versa
1907
+		$start_date = min($start_date, $end_date);
1908
+		$end_date   = max($start_date, $end_date);
1909
+
1910
+		//convert to correct format for query
1911
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1912
+			date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1913
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1914
+			date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1915
+
1916
+
1917
+		//set orderby
1918
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1919
+
1920
+		switch ($this->_req_data['orderby']) {
1921
+			case 'TXN_ID':
1922
+				$orderby = 'TXN_ID';
1923
+				break;
1924
+			case 'ATT_fname':
1925
+				$orderby = 'Registration.Attendee.ATT_fname';
1926
+				break;
1927
+			case 'event_name':
1928
+				$orderby = 'Registration.Event.EVT_name';
1929
+				break;
1930
+			default: //'TXN_timestamp'
1931
+				$orderby = 'TXN_timestamp';
1932
+		}
1933
+
1934
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1935
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1936
+		$per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1937
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1938
+
1939
+		$offset = ($current_page - 1) * $per_page;
1940
+		$limit  = array($offset, $per_page);
1941
+
1942
+		$_where = array(
1943
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1944
+			'Registration.REG_count' => 1
1945
+		);
1946
+
1947
+		if (isset($this->_req_data['EVT_ID'])) {
1948
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1949
+		}
1950
+
1951
+		if (isset($this->_req_data['s'])) {
1952
+			$search_string = '%' . $this->_req_data['s'] . '%';
1953
+			$_where['OR']  = array(
1954
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1955
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1956
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1957
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1958
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1959
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1960
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1961
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1962
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1963
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1964
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1965
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
1966
+				'Registration.REG_code'               => array('LIKE', $search_string),
1967
+				'Registration.REG_count'              => array('LIKE', $search_string),
1968
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
1969
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1970
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1971
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
1972
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1973
+				'TXN_session_data'                    => array('LIKE', $search_string),
1974
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1975
+			);
1976
+		}
1977
+
1978
+		//failed transactions
1979
+		$failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1980
+		$abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1981
+
1982
+		if ($failed) {
1983
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
1984
+		} else if ($abandoned) {
1985
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1986
+		} else {
1987
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1988
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1989
+		}
1990
+
1991
+		$query_params = array(
1992
+			$_where,
1993
+			'order_by' => array($orderby => $sort),
1994
+			'limit' => $limit,
1995
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only
1996
+		);
1997
+
1998
+		$transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1999
+
2000
+
2001
+		return $transactions;
2002
+
2003
+	}
2004 2004
 
2005 2005
 
2006 2006
 }
Please login to merge, or discard this patch.
acceptance_tests/Page/EventsAdmin.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,231 +14,231 @@
 block discarded – undo
14 14
 class EventsAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Selector for the Add new Event button in the admin.
19
-     * @var string
20
-     */
21
-    const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
-
23
-
24
-    /**
25
-     * Selector for the Event Title field in the event editor
26
-     * @var string
27
-     */
28
-    const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
-
30
-    /**
31
-     * Selector for the publish submit button in the event editor.
32
-     * @var string
33
-     */
34
-    const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
-
36
-
37
-    /**
38
-     * Selector for the save button in the event editor
39
-     */
40
-    const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post";
41
-
42
-
43
-    /**
44
-     * @var string
45
-     */
46
-    const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
17
+	/**
18
+	 * Selector for the Add new Event button in the admin.
19
+	 * @var string
20
+	 */
21
+	const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
+
23
+
24
+	/**
25
+	 * Selector for the Event Title field in the event editor
26
+	 * @var string
27
+	 */
28
+	const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']";
29
+
30
+	/**
31
+	 * Selector for the publish submit button in the event editor.
32
+	 * @var string
33
+	 */
34
+	const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish";
35
+
36
+
37
+	/**
38
+	 * Selector for the save button in the event editor
39
+	 */
40
+	const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post";
41
+
42
+
43
+	/**
44
+	 * @var string
45
+	 */
46
+	const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
47 47
 
48
-    /**
49
-     * Selector for the view link after publishing an event.
50
-     * @var string
51
-     */
52
-    const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a";
48
+	/**
49
+	 * Selector for the view link after publishing an event.
50
+	 * @var string
51
+	 */
52
+	const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a";
53 53
 
54 54
 
55
-    /**
56
-     * Selector for the ID of the event in the event editor
57
-     * @var string
58
-     */
59
-    const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
55
+	/**
56
+	 * Selector for the ID of the event in the event editor
57
+	 * @var string
58
+	 */
59
+	const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
60 60
 
61 61
 
62
-    /**
63
-     * Selector for the search input on the event list table page.
64
-     * @var string
65
-     */
66
-    const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
67
-
68
-
69
-
70
-
71
-    /**
72
-     * @param string $additional_params
73
-     * @return string
74
-     */
75
-    public static function defaultEventsListTableUrl($additional_params = '')
76
-    {
77
-        return self::adminUrl('espresso_events', 'default', $additional_params);
78
-    }
79
-
80
-
81
-    /**
82
-     * The selector for the DTTname field for the given row in the event editor.
83
-     * @param int $row_number
84
-     * @return string
85
-     */
86
-    public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
87
-    {
88
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
89
-    }
90
-
91
-
92
-    /**
93
-     * The selector for the DTT_EVT_start field for the given row in the event editor.d
94
-     * @param int $row_number
95
-     * @return string
96
-     */
97
-    public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
98
-    {
99
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
100
-    }
101
-
102
-
103
-    /**
104
-     * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
105
-     *
106
-     * @param string $field_name
107
-     * @param int    $row_number
108
-     * @return string
109
-     */
110
-    public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
111
-    {
112
-        return "//input[@id='event-datetime-$field_name-$row_number']";
113
-    }
114
-
115
-
116
-    /**
117
-     * The selector for the TKT_name field for the given display row in the event editor.
118
-     * @param int $row_number
119
-     * @return string
120
-     */
121
-    public static function eventEditorTicketNameFieldSelector($row_number = 1)
122
-    {
123
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
124
-    }
125
-
126
-
127
-    public static function eventEditorTicketPriceFieldSelector($row_number = 1)
128
-    {
129
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
130
-    }
131
-
132
-
133
-    public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
134
-    {
135
-        return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
136
-    }
137
-
138
-
139
-    public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
140
-    {
141
-        return "//span[@id='price-total-amount-$row_number']";
142
-    }
143
-
144
-
145
-    public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
146
-    {
147
-        return "//span[@id='price-total-amount-$row_number']";
148
-    }
149
-
150
-
151
-    public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
152
-    {
153
-        return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
154
-    }
155
-
156
-
157
-    /**
158
-     * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
159
-     * given ticket (row) and the given tax id (PRC_ID).
160
-     *
161
-     * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
162
-     *                        setup on a fresh install.
163
-     * @param int $row_number What row representing the ticket you want the locator for.
164
-     * @return string
165
-     */
166
-    public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
167
-    {
168
-        return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
169
-    }
170
-
171
-
172
-    /**
173
-     * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
174
-     * @param     $field_name
175
-     * @param int $row_number
176
-     * @return string
177
-     */
178
-    public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
179
-    {
180
-        return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
181
-    }
182
-
183
-
184
-    /**
185
-     * Returns the selector for the event title edit link in the events list table for the given Event Title.
186
-     * @param string $event_title
187
-     * @return string
188
-     */
189
-    public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
190
-    {
191
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
192
-    }
193
-
194
-
195
-    /**
196
-     * Locator for for the ID column in the event list table for a given event title.
197
-     * @param string $event_title
198
-     * @return string
199
-     */
200
-    public static function eventListTableEventIdSelectorForTitle($event_title)
201
-    {
202
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
203
-               . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
204
-    }
205
-
206
-
207
-    /**
208
-     * Locator for the view link in the row of an event list table for the given event title.
209
-     * @param string $event_title
210
-     * @return string
211
-     */
212
-    public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
213
-    {
214
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
215
-               . "//ancestor::td//span[@class='view']/a";
216
-    }
217
-
218
-
219
-    /**
220
-     * Locator for the messenger tab in the Notifications metabox in the event editor.
221
-     * @param string $messenger_slug  The slug for the messenger (it's reference slug).
222
-     * @return string
223
-     */
224
-    public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
225
-    {
226
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
227
-               . "//a[@rel='ee-tab-$messenger_slug']";
228
-    }
229
-
230
-
231
-    /**
232
-     * Locator for the select input within the notifications metabox.
233
-     * Note, this assumes the tab content for the related messenger is already visible.
234
-     * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
235
-     * @return string
236
-     */
237
-    public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
238
-    {
239
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
240
-               . "//table[@class='messages-custom-template-switcher']"
241
-               . "//tr/td[contains(.,'Registration Approved')]"
242
-               . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
243
-    }
62
+	/**
63
+	 * Selector for the search input on the event list table page.
64
+	 * @var string
65
+	 */
66
+	const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
67
+
68
+
69
+
70
+
71
+	/**
72
+	 * @param string $additional_params
73
+	 * @return string
74
+	 */
75
+	public static function defaultEventsListTableUrl($additional_params = '')
76
+	{
77
+		return self::adminUrl('espresso_events', 'default', $additional_params);
78
+	}
79
+
80
+
81
+	/**
82
+	 * The selector for the DTTname field for the given row in the event editor.
83
+	 * @param int $row_number
84
+	 * @return string
85
+	 */
86
+	public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
87
+	{
88
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
89
+	}
90
+
91
+
92
+	/**
93
+	 * The selector for the DTT_EVT_start field for the given row in the event editor.d
94
+	 * @param int $row_number
95
+	 * @return string
96
+	 */
97
+	public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
98
+	{
99
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
105
+	 *
106
+	 * @param string $field_name
107
+	 * @param int    $row_number
108
+	 * @return string
109
+	 */
110
+	public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
111
+	{
112
+		return "//input[@id='event-datetime-$field_name-$row_number']";
113
+	}
114
+
115
+
116
+	/**
117
+	 * The selector for the TKT_name field for the given display row in the event editor.
118
+	 * @param int $row_number
119
+	 * @return string
120
+	 */
121
+	public static function eventEditorTicketNameFieldSelector($row_number = 1)
122
+	{
123
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
124
+	}
125
+
126
+
127
+	public static function eventEditorTicketPriceFieldSelector($row_number = 1)
128
+	{
129
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
130
+	}
131
+
132
+
133
+	public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
134
+	{
135
+		return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
136
+	}
137
+
138
+
139
+	public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
140
+	{
141
+		return "//span[@id='price-total-amount-$row_number']";
142
+	}
143
+
144
+
145
+	public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
146
+	{
147
+		return "//span[@id='price-total-amount-$row_number']";
148
+	}
149
+
150
+
151
+	public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
152
+	{
153
+		return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
154
+	}
155
+
156
+
157
+	/**
158
+	 * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
159
+	 * given ticket (row) and the given tax id (PRC_ID).
160
+	 *
161
+	 * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
162
+	 *                        setup on a fresh install.
163
+	 * @param int $row_number What row representing the ticket you want the locator for.
164
+	 * @return string
165
+	 */
166
+	public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
167
+	{
168
+		return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
169
+	}
170
+
171
+
172
+	/**
173
+	 * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
174
+	 * @param     $field_name
175
+	 * @param int $row_number
176
+	 * @return string
177
+	 */
178
+	public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
179
+	{
180
+		return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
181
+	}
182
+
183
+
184
+	/**
185
+	 * Returns the selector for the event title edit link in the events list table for the given Event Title.
186
+	 * @param string $event_title
187
+	 * @return string
188
+	 */
189
+	public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
190
+	{
191
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
192
+	}
193
+
194
+
195
+	/**
196
+	 * Locator for for the ID column in the event list table for a given event title.
197
+	 * @param string $event_title
198
+	 * @return string
199
+	 */
200
+	public static function eventListTableEventIdSelectorForTitle($event_title)
201
+	{
202
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
203
+			   . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
204
+	}
205
+
206
+
207
+	/**
208
+	 * Locator for the view link in the row of an event list table for the given event title.
209
+	 * @param string $event_title
210
+	 * @return string
211
+	 */
212
+	public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
213
+	{
214
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
215
+			   . "//ancestor::td//span[@class='view']/a";
216
+	}
217
+
218
+
219
+	/**
220
+	 * Locator for the messenger tab in the Notifications metabox in the event editor.
221
+	 * @param string $messenger_slug  The slug for the messenger (it's reference slug).
222
+	 * @return string
223
+	 */
224
+	public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
225
+	{
226
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
227
+			   . "//a[@rel='ee-tab-$messenger_slug']";
228
+	}
229
+
230
+
231
+	/**
232
+	 * Locator for the select input within the notifications metabox.
233
+	 * Note, this assumes the tab content for the related messenger is already visible.
234
+	 * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
235
+	 * @return string
236
+	 */
237
+	public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
238
+	{
239
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
240
+			   . "//table[@class='messages-custom-template-switcher']"
241
+			   . "//tr/td[contains(.,'Registration Approved')]"
242
+			   . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
243
+	}
244 244
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php 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
-                ); ?>
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
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
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.3.9');
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
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.004');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.004');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.