Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
136:24 queued 121:17
created
core/helpers/EEH_DTT_Helper.helper.php 2 patches
Indentation   +916 added lines, -916 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,233 +26,233 @@  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
-        $gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
-        if ($gmt_offset !== '') {
106
-            // convert GMT offset to seconds
107
-            $gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
-            // account for WP offsets that aren't valid UTC
109
-            $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
-            // although we don't know the TZ abbreviation, we know the UTC offset
111
-            $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
-        }
113
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
-        $timezone_string = $timezone_string !== false
115
-            ? $timezone_string
116
-            : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
-        return $timezone_string;
118
-    }
119
-
120
-    /**
121
-     * Gets the site's GMT offset based on either the timezone string
122
-     * (in which case teh gmt offset will vary depending on the location's
123
-     * observance of daylight savings time) or the gmt_offset wp option
124
-     *
125
-     * @return int seconds offset
126
-     */
127
-    public static function get_site_timezone_gmt_offset()
128
-    {
129
-        $timezone_string = get_option('timezone_string');
130
-        if ($timezone_string) {
131
-            try {
132
-                $timezone = new DateTimeZone($timezone_string);
133
-                return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
-            } catch (Exception $e) {
135
-            }
136
-        }
137
-        $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
139
-    }
140
-
141
-
142
-    /**
143
-     * _create_timezone_object_from_timezone_name
144
-     *
145
-     * @access public
146
-     * @param int $gmt_offset
147
-     * @return int
148
-     */
149
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
-    {
151
-        //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
153
-        switch ($gmt_offset) {
154
-
155
-            //			case -30600 :
156
-            //				$gmt_offset = -28800;
157
-            //				break;
158
-
159
-            case -27000 :
160
-                $gmt_offset = -25200;
161
-                break;
162
-
163
-            case -23400 :
164
-                $gmt_offset = -21600;
165
-                break;
166
-
167
-            case -19800 :
168
-                $gmt_offset = -18000;
169
-                break;
170
-
171
-            case -9000 :
172
-                $gmt_offset = -7200;
173
-                break;
174
-
175
-            case -5400 :
176
-                $gmt_offset = -3600;
177
-                break;
178
-
179
-            case -1800 :
180
-                $gmt_offset = 0;
181
-                break;
182
-
183
-            case 1800 :
184
-                $gmt_offset = 3600;
185
-                break;
186
-
187
-            case 49500 :
188
-                $gmt_offset = 50400;
189
-                break;
190
-
191
-        }
192
-        return $gmt_offset;
193
-    }
194
-
195
-
196
-    /**
197
-     * get_timezone_string_from_abbreviations_list
198
-     *
199
-     * @access public
200
-     * @param int $gmt_offset
201
-     * @return string
202
-     * @throws \EE_Error
203
-     */
204
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
-    {
206
-        $abbreviations = timezone_abbreviations_list();
207
-        foreach ($abbreviations as $abbreviation) {
208
-            foreach ($abbreviation as $city) {
209
-                if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
-                    // check if the timezone is valid but don't throw any errors if it isn't
211
-                    if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
-                        return $city['timezone_id'];
213
-                    }
214
-                }
215
-            }
216
-        }
217
-        throw new EE_Error(
218
-            sprintf(
219
-                __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
-                    'event_espresso'),
221
-                $gmt_offset,
222
-                '<a href="http://www.php.net/manual/en/timezones.php">',
223
-                '</a>'
224
-            )
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * @access public
231
-     * @param string $timezone_string
232
-     */
233
-    public static function timezone_select_input($timezone_string = '')
234
-    {
235
-        // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
-        // if passed a value, then use that, else get WP option
238
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
-        // check if the timezone is valid but don't throw any errors if it isn't
240
-        $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
-        $gmt_offset      = get_option('gmt_offset');
242
-
243
-        $check_zone_info = true;
244
-        if (empty($timezone_string)) {
245
-            // Create a UTC+- zone if no timezone string exists
246
-            $check_zone_info = false;
247
-            if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
249
-            } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
251
-            } else {
252
-                $timezone_string = 'UTC';
253
-            }
254
-        }
255
-        ?>
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
+		$gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
+		if ($gmt_offset !== '') {
106
+			// convert GMT offset to seconds
107
+			$gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
+			// account for WP offsets that aren't valid UTC
109
+			$gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
+			// although we don't know the TZ abbreviation, we know the UTC offset
111
+			$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
+		}
113
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
+		$timezone_string = $timezone_string !== false
115
+			? $timezone_string
116
+			: EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
+		return $timezone_string;
118
+	}
119
+
120
+	/**
121
+	 * Gets the site's GMT offset based on either the timezone string
122
+	 * (in which case teh gmt offset will vary depending on the location's
123
+	 * observance of daylight savings time) or the gmt_offset wp option
124
+	 *
125
+	 * @return int seconds offset
126
+	 */
127
+	public static function get_site_timezone_gmt_offset()
128
+	{
129
+		$timezone_string = get_option('timezone_string');
130
+		if ($timezone_string) {
131
+			try {
132
+				$timezone = new DateTimeZone($timezone_string);
133
+				return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
+			} catch (Exception $e) {
135
+			}
136
+		}
137
+		$offset = get_option('gmt_offset');
138
+		return (int)($offset * HOUR_IN_SECONDS);
139
+	}
140
+
141
+
142
+	/**
143
+	 * _create_timezone_object_from_timezone_name
144
+	 *
145
+	 * @access public
146
+	 * @param int $gmt_offset
147
+	 * @return int
148
+	 */
149
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
+	{
151
+		//make sure $gmt_offset is int
152
+		$gmt_offset = (int)$gmt_offset;
153
+		switch ($gmt_offset) {
154
+
155
+			//			case -30600 :
156
+			//				$gmt_offset = -28800;
157
+			//				break;
158
+
159
+			case -27000 :
160
+				$gmt_offset = -25200;
161
+				break;
162
+
163
+			case -23400 :
164
+				$gmt_offset = -21600;
165
+				break;
166
+
167
+			case -19800 :
168
+				$gmt_offset = -18000;
169
+				break;
170
+
171
+			case -9000 :
172
+				$gmt_offset = -7200;
173
+				break;
174
+
175
+			case -5400 :
176
+				$gmt_offset = -3600;
177
+				break;
178
+
179
+			case -1800 :
180
+				$gmt_offset = 0;
181
+				break;
182
+
183
+			case 1800 :
184
+				$gmt_offset = 3600;
185
+				break;
186
+
187
+			case 49500 :
188
+				$gmt_offset = 50400;
189
+				break;
190
+
191
+		}
192
+		return $gmt_offset;
193
+	}
194
+
195
+
196
+	/**
197
+	 * get_timezone_string_from_abbreviations_list
198
+	 *
199
+	 * @access public
200
+	 * @param int $gmt_offset
201
+	 * @return string
202
+	 * @throws \EE_Error
203
+	 */
204
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
+	{
206
+		$abbreviations = timezone_abbreviations_list();
207
+		foreach ($abbreviations as $abbreviation) {
208
+			foreach ($abbreviation as $city) {
209
+				if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
+					// check if the timezone is valid but don't throw any errors if it isn't
211
+					if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
+						return $city['timezone_id'];
213
+					}
214
+				}
215
+			}
216
+		}
217
+		throw new EE_Error(
218
+			sprintf(
219
+				__('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
+					'event_espresso'),
221
+				$gmt_offset,
222
+				'<a href="http://www.php.net/manual/en/timezones.php">',
223
+				'</a>'
224
+			)
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * @access public
231
+	 * @param string $timezone_string
232
+	 */
233
+	public static function timezone_select_input($timezone_string = '')
234
+	{
235
+		// get WP date time format
236
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
+		// if passed a value, then use that, else get WP option
238
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
+		// check if the timezone is valid but don't throw any errors if it isn't
240
+		$timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
+		$gmt_offset      = get_option('gmt_offset');
242
+
243
+		$check_zone_info = true;
244
+		if (empty($timezone_string)) {
245
+			// Create a UTC+- zone if no timezone string exists
246
+			$check_zone_info = false;
247
+			if ($gmt_offset > 0) {
248
+				$timezone_string = 'UTC+' . $gmt_offset;
249
+			} elseif ($gmt_offset < 0) {
250
+				$timezone_string = 'UTC' . $gmt_offset;
251
+			} else {
252
+				$timezone_string = 'UTC';
253
+			}
254
+		}
255
+		?>
256 256
 
257 257
         <p>
258 258
             <label for="timezone_string"><?php _e('timezone'); ?></label>
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 
266 266
         <p>
267 267
         <span><?php
268
-            printf(
269
-                __('%1$sUTC%2$s time is %3$s'),
270
-                '<abbr title="Coordinated Universal Time">',
271
-                '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
-            );
274
-            ?></span>
268
+			printf(
269
+				__('%1$sUTC%2$s time is %3$s'),
270
+				'<abbr title="Coordinated Universal Time">',
271
+				'</abbr>',
272
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
+			);
274
+			?></span>
275 275
         <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276 276
         <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
277 277
     <?php endif; ?>
@@ -280,693 +280,693 @@  discard block
 block discarded – undo
280 280
         <br/>
281 281
         <span>
282 282
 					<?php
283
-                    // Set TZ so localtime works.
284
-                    date_default_timezone_set($timezone_string);
285
-                    $now = localtime(time(), true);
286
-                    if ($now['tm_isdst']) {
287
-                        _e('This timezone is currently in daylight saving time.');
288
-                    } else {
289
-                        _e('This timezone is currently in standard time.');
290
-                    }
291
-                    ?>
283
+					// Set TZ so localtime works.
284
+					date_default_timezone_set($timezone_string);
285
+					$now = localtime(time(), true);
286
+					if ($now['tm_isdst']) {
287
+						_e('This timezone is currently in daylight saving time.');
288
+					} else {
289
+						_e('This timezone is currently in standard time.');
290
+					}
291
+					?>
292 292
             <br/>
293 293
             <?php
294
-            if (function_exists('timezone_transitions_get')) {
295
-                $found                   = false;
296
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
297
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
-                $right_now               = time();
299
-                $tr['isdst']             = false;
300
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
-                    if ($tr['ts'] > $right_now) {
302
-                        $found = true;
303
-                        break;
304
-                    }
305
-                }
306
-
307
-                if ($found) {
308
-                    $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
311
-                    // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
-                    printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
-                } else {
315
-                    _e('This timezone does not observe daylight saving time.');
316
-                }
317
-            }
318
-            // Set back to UTC.
319
-            date_default_timezone_set('UTC');
320
-            ?>
294
+			if (function_exists('timezone_transitions_get')) {
295
+				$found                   = false;
296
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
297
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
+				$right_now               = time();
299
+				$tr['isdst']             = false;
300
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
+					if ($tr['ts'] > $right_now) {
302
+						$found = true;
303
+						break;
304
+					}
305
+				}
306
+
307
+				if ($found) {
308
+					$message = $tr['isdst'] ?
309
+						__(' Daylight saving time begins on: %s.') :
310
+						__(' Standard time begins  on: %s.');
311
+					// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
+					printf($message,
313
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
+				} else {
315
+					_e('This timezone does not observe daylight saving time.');
316
+				}
317
+			}
318
+			// Set back to UTC.
319
+			date_default_timezone_set('UTC');
320
+			?>
321 321
 				</span></p>
322 322
         <?php
323
-    endif;
324
-    }
325
-
326
-
327
-    /**
328
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
-     * the site is used.
331
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
-     * computed timestamp (i.e. date_i18n() )
333
-     *
334
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
335
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
-     *                                                site will be used.
337
-     * @return int      $unix_timestamp with the offset applied for the given timezone.
338
-     */
339
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
-    {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
-        $timezone_string = self::get_valid_timezone_string($timezone_string);
343
-        $TimeZone        = new DateTimeZone($timezone_string);
344
-
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
-        $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
348
-    }
349
-
350
-
351
-    /**
352
-     *    _set_date_time_field
353
-     *    modifies EE_Base_Class EE_Datetime_Field objects
354
-     *
355
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
356
-     * @param    DateTime    $DateTime            PHP DateTime object
357
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
-     * @return    EE_Base_Class
359
-     */
360
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
-    {
362
-        // grab current datetime format
363
-        $current_format = $obj->get_format();
364
-        // set new full timestamp format
365
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
-        // set the new date value using a full timestamp format so that no data is lost
368
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
-        // reset datetime formats
370
-        $obj->set_date_format($current_format[0]);
371
-        $obj->set_time_format($current_format[1]);
372
-        return $obj;
373
-    }
374
-
375
-
376
-    /**
377
-     *    date_time_add
378
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
-     *
381
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
382
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
-     *                                            minutes, seconds) defaults to years
385
-     * @param  integer       $value               what you want to increment the time by
386
-     * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
-     *                                 (chaining)
388
-     */
389
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
-    {
391
-        //get the raw UTC date.
392
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
393
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
-    }
396
-
397
-
398
-    /**
399
-     *    date_time_subtract
400
-     *    same as date_time_add except subtracting value instead of adding.
401
-     *
402
-     * @param \EE_Base_Class $obj
403
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
-     * @param string         $period
405
-     * @param int            $value
406
-     * @return \EE_Base_Class
407
-     */
408
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
-    {
410
-        //get the raw UTC date
411
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
412
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
-    }
415
-
416
-
417
-    /**
418
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
-     *
420
-     * @param  DateTime $DateTime DateTime object
421
-     * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
-     * @param  integer  $value    What you want to increment the date by
424
-     * @param  string   $operand  What operand you wish to use for the calculation
425
-     * @return \DateTime return whatever type came in.
426
-     * @throws \EE_Error
427
-     */
428
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
-    {
430
-        if (! $DateTime instanceof DateTime) {
431
-            throw new EE_Error(
432
-                sprintf(
433
-                    __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
-                    print_r($DateTime, true)
435
-                )
436
-            );
437
-        }
438
-        switch ($period) {
439
-            case 'years' :
440
-                $value = 'P' . $value . 'Y';
441
-                break;
442
-            case 'months' :
443
-                $value = 'P' . $value . 'M';
444
-                break;
445
-            case 'weeks' :
446
-                $value = 'P' . $value . 'W';
447
-                break;
448
-            case 'days' :
449
-                $value = 'P' . $value . 'D';
450
-                break;
451
-            case 'hours' :
452
-                $value = 'PT' . $value . 'H';
453
-                break;
454
-            case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
456
-                break;
457
-            case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
459
-                break;
460
-        }
461
-        switch ($operand) {
462
-            case '+':
463
-                $DateTime->add(new DateInterval($value));
464
-                break;
465
-            case '-':
466
-                $DateTime->sub(new DateInterval($value));
467
-                break;
468
-        }
469
-        return $DateTime;
470
-    }
471
-
472
-
473
-    /**
474
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
-     *
476
-     * @param  int     $timestamp Unix timestamp
477
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
-     * @param  integer $value     What you want to increment the date by
480
-     * @param  string  $operand   What operand you wish to use for the calculation
481
-     * @return \DateTime return whatever type came in.
482
-     * @throws \EE_Error
483
-     */
484
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
-    {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
-            throw new EE_Error(
488
-                sprintf(
489
-                    __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
-                    print_r($timestamp, true)
491
-                )
492
-            );
493
-        }
494
-        switch ($period) {
495
-            case 'years' :
496
-                $value = YEAR_IN_SECONDS * $value;
497
-                break;
498
-            case 'months' :
499
-                $value = YEAR_IN_SECONDS / 12 * $value;
500
-                break;
501
-            case 'weeks' :
502
-                $value = WEEK_IN_SECONDS * $value;
503
-                break;
504
-            case 'days' :
505
-                $value = DAY_IN_SECONDS * $value;
506
-                break;
507
-            case 'hours' :
508
-                $value = HOUR_IN_SECONDS * $value;
509
-                break;
510
-            case 'minutes' :
511
-                $value = MINUTE_IN_SECONDS * $value;
512
-                break;
513
-        }
514
-        switch ($operand) {
515
-            case '+':
516
-                $timestamp += $value;
517
-                break;
518
-            case '-':
519
-                $timestamp -= $value;
520
-                break;
521
-        }
522
-        return $timestamp;
523
-    }
524
-
525
-
526
-    /**
527
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
-     * parameters and returns the new timestamp or DateTime.
529
-     *
530
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
-     * @param  string         $period                a value to indicate what interval is being used in the
532
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
-     *                                               'minutes', 'seconds'. Defaults to years.
534
-     * @param  integer        $value                 What you want to increment the date by
535
-     * @param  string         $operand               What operand you wish to use for the calculation
536
-     * @return mixed string|DateTime          return whatever type came in.
537
-     */
538
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
-    {
540
-        if ($DateTime_or_timestamp instanceof DateTime) {
541
-            return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
-        } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
-            return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
-        } else {
545
-            //error
546
-            return $DateTime_or_timestamp;
547
-        }
548
-    }
549
-
550
-
551
-    /**
552
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
553
-     * and spit out the js and moment.js equivalent formats.
554
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
-     * time picker.
557
-     *
558
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
-     * @param null $date_format_string
560
-     * @param null $time_format_string
561
-     * @return array
562
-     *                array(
563
-     *                'js' => array (
564
-     *                'date' => //date format
565
-     *                'time' => //time format
566
-     *                ),
567
-     *                'moment' => //date and time format.
568
-     *                )
569
-     */
570
-    public static function convert_php_to_js_and_moment_date_formats(
571
-        $date_format_string = null,
572
-        $time_format_string = null
573
-    ) {
574
-        if ($date_format_string === null) {
575
-            $date_format_string = get_option('date_format');
576
-        }
577
-
578
-        if ($time_format_string === null) {
579
-            $time_format_string = get_option('time_format');
580
-        }
581
-
582
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
583
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
584
-
585
-        return array(
586
-            'js'     => array(
587
-                'date' => $date_format['js'],
588
-                'time' => $time_format['js'],
589
-            ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
-        );
592
-    }
593
-
594
-
595
-    /**
596
-     * This converts incoming format string into js and moment variations.
597
-     *
598
-     * @param string $format_string incoming php format string
599
-     * @return array js and moment formats.
600
-     */
601
-    protected static function _php_to_js_moment_converter($format_string)
602
-    {
603
-        /**
604
-         * This is a map of symbols for formats.
605
-         * The index is the php symbol, the equivalent values are in the array.
606
-         *
607
-         * @var array
608
-         */
609
-        $symbols_map      = array(
610
-            // Day
611
-            //01
612
-            'd' => array(
613
-                'js'     => 'dd',
614
-                'moment' => 'DD',
615
-            ),
616
-            //Mon
617
-            'D' => array(
618
-                'js'     => 'D',
619
-                'moment' => 'ddd',
620
-            ),
621
-            //1,2,...31
622
-            'j' => array(
623
-                'js'     => 'd',
624
-                'moment' => 'D',
625
-            ),
626
-            //Monday
627
-            'l' => array(
628
-                'js'     => 'DD',
629
-                'moment' => 'dddd',
630
-            ),
631
-            //ISO numeric representation of the day of the week (1-6)
632
-            'N' => array(
633
-                'js'     => '',
634
-                'moment' => 'E',
635
-            ),
636
-            //st,nd.rd
637
-            'S' => array(
638
-                'js'     => '',
639
-                'moment' => 'o',
640
-            ),
641
-            //numeric representation of day of week (0-6)
642
-            'w' => array(
643
-                'js'     => '',
644
-                'moment' => 'd',
645
-            ),
646
-            //day of year starting from 0 (0-365)
647
-            'z' => array(
648
-                'js'     => 'o',
649
-                'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
-            ),
651
-            // Week
652
-            //ISO-8601 week number of year (weeks starting on monday)
653
-            'W' => array(
654
-                'js'     => '',
655
-                'moment' => 'w',
656
-            ),
657
-            // Month
658
-            // January...December
659
-            'F' => array(
660
-                'js'     => 'MM',
661
-                'moment' => 'MMMM',
662
-            ),
663
-            //01...12
664
-            'm' => array(
665
-                'js'     => 'mm',
666
-                'moment' => 'MM',
667
-            ),
668
-            //Jan...Dec
669
-            'M' => array(
670
-                'js'     => 'M',
671
-                'moment' => 'MMM',
672
-            ),
673
-            //1-12
674
-            'n' => array(
675
-                'js'     => 'm',
676
-                'moment' => 'M',
677
-            ),
678
-            //number of days in given month
679
-            't' => array(
680
-                'js'     => '',
681
-                'moment' => '',
682
-            ),
683
-            // Year
684
-            //whether leap year or not 1/0
685
-            'L' => array(
686
-                'js'     => '',
687
-                'moment' => '',
688
-            ),
689
-            //ISO-8601 year number
690
-            'o' => array(
691
-                'js'     => '',
692
-                'moment' => 'GGGG',
693
-            ),
694
-            //1999...2003
695
-            'Y' => array(
696
-                'js'     => 'yy',
697
-                'moment' => 'YYYY',
698
-            ),
699
-            //99...03
700
-            'y' => array(
701
-                'js'     => 'y',
702
-                'moment' => 'YY',
703
-            ),
704
-            // Time
705
-            // am/pm
706
-            'a' => array(
707
-                'js'     => 'tt',
708
-                'moment' => 'a',
709
-            ),
710
-            // AM/PM
711
-            'A' => array(
712
-                'js'     => 'TT',
713
-                'moment' => 'A',
714
-            ),
715
-            // Swatch Internet Time?!?
716
-            'B' => array(
717
-                'js'     => '',
718
-                'moment' => '',
719
-            ),
720
-            //1...12
721
-            'g' => array(
722
-                'js'     => 'h',
723
-                'moment' => 'h',
724
-            ),
725
-            //0...23
726
-            'G' => array(
727
-                'js'     => 'H',
728
-                'moment' => 'H',
729
-            ),
730
-            //01...12
731
-            'h' => array(
732
-                'js'     => 'hh',
733
-                'moment' => 'hh',
734
-            ),
735
-            //00...23
736
-            'H' => array(
737
-                'js'     => 'HH',
738
-                'moment' => 'HH',
739
-            ),
740
-            //00..59
741
-            'i' => array(
742
-                'js'     => 'mm',
743
-                'moment' => 'mm',
744
-            ),
745
-            //seconds... 00...59
746
-            's' => array(
747
-                'js'     => 'ss',
748
-                'moment' => 'ss',
749
-            ),
750
-            //microseconds
751
-            'u' => array(
752
-                'js'     => '',
753
-                'moment' => '',
754
-            ),
755
-        );
756
-        $jquery_ui_format = "";
757
-        $moment_format    = "";
758
-        $escaping         = false;
759
-        for ($i = 0; $i < strlen($format_string); $i++) {
760
-            $char = $format_string[$i];
761
-            if ($char === '\\') { // PHP date format escaping character
762
-                $i++;
763
-                if ($escaping) {
764
-                    $jquery_ui_format .= $format_string[$i];
765
-                    $moment_format .= $format_string[$i];
766
-                } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
768
-                    $moment_format .= $format_string[$i];
769
-                }
770
-                $escaping = true;
771
-            } else {
772
-                if ($escaping) {
773
-                    $jquery_ui_format .= "'";
774
-                    $moment_format .= "'";
775
-                    $escaping = false;
776
-                }
777
-                if (isset($symbols_map[$char])) {
778
-                    $jquery_ui_format .= $symbols_map[$char]['js'];
779
-                    $moment_format .= $symbols_map[$char]['moment'];
780
-                } else {
781
-                    $jquery_ui_format .= $char;
782
-                    $moment_format .= $char;
783
-                }
784
-            }
785
-        }
786
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
-    }
788
-
789
-
790
-    /**
791
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
-     *
793
-     * @param string $format_string   Incoming format string for php date().
794
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
-     *                                errors is returned.  So for client code calling, check for is_array() to
796
-     *                                indicate failed validations.
797
-     */
798
-    public static function validate_format_string($format_string)
799
-    {
800
-        $error_msg = array();
801
-        //time format checks
802
-        switch (true) {
803
-            case   strpos($format_string, 'h') !== false  :
804
-            case   strpos($format_string, 'g') !== false :
805
-                /**
806
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
-                 */
810
-                if (strpos(strtoupper($format_string), 'A') === false) {
811
-                    $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".',
812
-                        'event_espresso');
813
-                }
814
-                break;
815
-
816
-        }
817
-
818
-        return empty($error_msg) ? true : $error_msg;
819
-    }
820
-
821
-
822
-    /**
823
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
-     *     very next day then this method will return true.
825
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
-     *
829
-     * @param mixed $date_1
830
-     * @param mixed $date_2
831
-     * @return bool
832
-     */
833
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
-    {
835
-
836
-        if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
-            ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
-        ) {
840
-            return false;
841
-        }
842
-        return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
-    }
844
-
845
-
846
-    /**
847
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
-     * Functions.
849
-     *
850
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
-     * @return string
853
-     */
854
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
-    {
856
-        try {
857
-            /** need to account for timezone offset on the selects */
858
-            $DateTimeZone = new DateTimeZone($timezone_string);
859
-        } catch (Exception $e) {
860
-            $DateTimeZone = null;
861
-        }
862
-
863
-        /**
864
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
-         * Hence we do the calc for DateTimeZone::getOffset.
866
-         */
867
-        $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
-        $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
-        return $query_interval;
872
-    }
873
-
874
-    /**
875
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
-     * and 'gmt_offset' WordPress options directly; or use the filter
878
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
-     * (although note that we remove any HTML that may be added)
880
-     *
881
-     * @return string
882
-     */
883
-    public static function get_timezone_string_for_display()
884
-    {
885
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
887
-            return esc_html($pretty_timezone);
888
-        }
889
-        $timezone_string = get_option('timezone_string');
890
-        if ($timezone_string) {
891
-            static $mo_loaded = false;
892
-            // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
894
-                $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
-                load_textdomain('continents-cities', $mofile);
897
-                $mo_loaded = true;
898
-            }
899
-            //well that was easy.
900
-            $parts = explode('/', $timezone_string);
901
-            //remove the continent
902
-            unset($parts[0]);
903
-            $t_parts = array();
904
-            foreach ($parts as $part) {
905
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
-            }
907
-            return implode(' - ', $t_parts);
908
-        }
909
-        //they haven't set the timezone string, so let's return a string like "UTC+1"
910
-        $gmt_offset = get_option('gmt_offset');
911
-        if (intval($gmt_offset) >= 0) {
912
-            $prefix = '+';
913
-        } else {
914
-            $prefix = '';
915
-        }
916
-        $parts = explode('.', (string)$gmt_offset);
917
-        if (count($parts) === 1) {
918
-            $parts[1] = '00';
919
-        } else {
920
-            //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
-            //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
924
-        }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
-    }
927
-
928
-
929
-
930
-    /**
931
-     * So PHP does this awesome thing where if you are trying to get a timestamp
932
-     * for a month using a string like "February" or "February 2017",
933
-     * and you don't specify a day as part of your string,
934
-     * then PHP will use whatever the current day of the month is.
935
-     * IF the current day of the month happens to be the 30th or 31st,
936
-     * then PHP gets really confused by a date like February 30,
937
-     * so instead of saying
938
-     *      "Hey February only has 28 days (this year)...
939
-     *      ...you must have meant the last day of the month!"
940
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
-     * because someone requesting February 30th obviously meant March 1st!
942
-     * The way around this is to always set the day to the first,
943
-     * so that the month will stay on the month you wanted.
944
-     * this method will add that "1" into your date regardless of the format.
945
-     *
946
-     * @param string $month
947
-     * @return string
948
-     */
949
-    public static function first_of_month_timestamp($month = '')
950
-    {
951
-        $month = (string)$month;
952
-        $year = '';
953
-        // check if the incoming string has a year in it or not
954
-       if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
-           $year = $matches[0];
956
-           // ten remove that from the month string as well as any spaces
957
-           $month = trim(str_replace($year, '', $month));
958
-           // add a space before the year
959
-           $year = " {$year}";
960
-        }
961
-        // return timestamp for something like "February 1 2017"
962
-        return strtotime("{$month} 1{$year}");
963
-    }
323
+	endif;
324
+	}
325
+
326
+
327
+	/**
328
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
+	 * the site is used.
331
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
+	 * computed timestamp (i.e. date_i18n() )
333
+	 *
334
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
335
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
+	 *                                                site will be used.
337
+	 * @return int      $unix_timestamp with the offset applied for the given timezone.
338
+	 */
339
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
+	{
341
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
+		$timezone_string = self::get_valid_timezone_string($timezone_string);
343
+		$TimeZone        = new DateTimeZone($timezone_string);
344
+
345
+		$DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
+		$offset   = timezone_offset_get($TimeZone, $DateTime);
347
+		return (int)$DateTime->format('U') + (int)$offset;
348
+	}
349
+
350
+
351
+	/**
352
+	 *    _set_date_time_field
353
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
354
+	 *
355
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
356
+	 * @param    DateTime    $DateTime            PHP DateTime object
357
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
+	 * @return    EE_Base_Class
359
+	 */
360
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
+	{
362
+		// grab current datetime format
363
+		$current_format = $obj->get_format();
364
+		// set new full timestamp format
365
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
+		// set the new date value using a full timestamp format so that no data is lost
368
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
+		// reset datetime formats
370
+		$obj->set_date_format($current_format[0]);
371
+		$obj->set_time_format($current_format[1]);
372
+		return $obj;
373
+	}
374
+
375
+
376
+	/**
377
+	 *    date_time_add
378
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
+	 *
381
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
382
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
+	 *                                            minutes, seconds) defaults to years
385
+	 * @param  integer       $value               what you want to increment the time by
386
+	 * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
+	 *                                 (chaining)
388
+	 */
389
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
+	{
391
+		//get the raw UTC date.
392
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
393
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
+	}
396
+
397
+
398
+	/**
399
+	 *    date_time_subtract
400
+	 *    same as date_time_add except subtracting value instead of adding.
401
+	 *
402
+	 * @param \EE_Base_Class $obj
403
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
+	 * @param string         $period
405
+	 * @param int            $value
406
+	 * @return \EE_Base_Class
407
+	 */
408
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
+	{
410
+		//get the raw UTC date
411
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
412
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
+	 *
420
+	 * @param  DateTime $DateTime DateTime object
421
+	 * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
+	 * @param  integer  $value    What you want to increment the date by
424
+	 * @param  string   $operand  What operand you wish to use for the calculation
425
+	 * @return \DateTime return whatever type came in.
426
+	 * @throws \EE_Error
427
+	 */
428
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
+	{
430
+		if (! $DateTime instanceof DateTime) {
431
+			throw new EE_Error(
432
+				sprintf(
433
+					__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
+					print_r($DateTime, true)
435
+				)
436
+			);
437
+		}
438
+		switch ($period) {
439
+			case 'years' :
440
+				$value = 'P' . $value . 'Y';
441
+				break;
442
+			case 'months' :
443
+				$value = 'P' . $value . 'M';
444
+				break;
445
+			case 'weeks' :
446
+				$value = 'P' . $value . 'W';
447
+				break;
448
+			case 'days' :
449
+				$value = 'P' . $value . 'D';
450
+				break;
451
+			case 'hours' :
452
+				$value = 'PT' . $value . 'H';
453
+				break;
454
+			case 'minutes' :
455
+				$value = 'PT' . $value . 'M';
456
+				break;
457
+			case 'seconds' :
458
+				$value = 'PT' . $value . 'S';
459
+				break;
460
+		}
461
+		switch ($operand) {
462
+			case '+':
463
+				$DateTime->add(new DateInterval($value));
464
+				break;
465
+			case '-':
466
+				$DateTime->sub(new DateInterval($value));
467
+				break;
468
+		}
469
+		return $DateTime;
470
+	}
471
+
472
+
473
+	/**
474
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
+	 *
476
+	 * @param  int     $timestamp Unix timestamp
477
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
+	 * @param  integer $value     What you want to increment the date by
480
+	 * @param  string  $operand   What operand you wish to use for the calculation
481
+	 * @return \DateTime return whatever type came in.
482
+	 * @throws \EE_Error
483
+	 */
484
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
+	{
486
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
+			throw new EE_Error(
488
+				sprintf(
489
+					__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
+					print_r($timestamp, true)
491
+				)
492
+			);
493
+		}
494
+		switch ($period) {
495
+			case 'years' :
496
+				$value = YEAR_IN_SECONDS * $value;
497
+				break;
498
+			case 'months' :
499
+				$value = YEAR_IN_SECONDS / 12 * $value;
500
+				break;
501
+			case 'weeks' :
502
+				$value = WEEK_IN_SECONDS * $value;
503
+				break;
504
+			case 'days' :
505
+				$value = DAY_IN_SECONDS * $value;
506
+				break;
507
+			case 'hours' :
508
+				$value = HOUR_IN_SECONDS * $value;
509
+				break;
510
+			case 'minutes' :
511
+				$value = MINUTE_IN_SECONDS * $value;
512
+				break;
513
+		}
514
+		switch ($operand) {
515
+			case '+':
516
+				$timestamp += $value;
517
+				break;
518
+			case '-':
519
+				$timestamp -= $value;
520
+				break;
521
+		}
522
+		return $timestamp;
523
+	}
524
+
525
+
526
+	/**
527
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
+	 * parameters and returns the new timestamp or DateTime.
529
+	 *
530
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
+	 * @param  string         $period                a value to indicate what interval is being used in the
532
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
+	 *                                               'minutes', 'seconds'. Defaults to years.
534
+	 * @param  integer        $value                 What you want to increment the date by
535
+	 * @param  string         $operand               What operand you wish to use for the calculation
536
+	 * @return mixed string|DateTime          return whatever type came in.
537
+	 */
538
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
+	{
540
+		if ($DateTime_or_timestamp instanceof DateTime) {
541
+			return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
+		} else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
+			return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
+		} else {
545
+			//error
546
+			return $DateTime_or_timestamp;
547
+		}
548
+	}
549
+
550
+
551
+	/**
552
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
553
+	 * and spit out the js and moment.js equivalent formats.
554
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
+	 * time picker.
557
+	 *
558
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
+	 * @param null $date_format_string
560
+	 * @param null $time_format_string
561
+	 * @return array
562
+	 *                array(
563
+	 *                'js' => array (
564
+	 *                'date' => //date format
565
+	 *                'time' => //time format
566
+	 *                ),
567
+	 *                'moment' => //date and time format.
568
+	 *                )
569
+	 */
570
+	public static function convert_php_to_js_and_moment_date_formats(
571
+		$date_format_string = null,
572
+		$time_format_string = null
573
+	) {
574
+		if ($date_format_string === null) {
575
+			$date_format_string = get_option('date_format');
576
+		}
577
+
578
+		if ($time_format_string === null) {
579
+			$time_format_string = get_option('time_format');
580
+		}
581
+
582
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
583
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
584
+
585
+		return array(
586
+			'js'     => array(
587
+				'date' => $date_format['js'],
588
+				'time' => $time_format['js'],
589
+			),
590
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
+		);
592
+	}
593
+
594
+
595
+	/**
596
+	 * This converts incoming format string into js and moment variations.
597
+	 *
598
+	 * @param string $format_string incoming php format string
599
+	 * @return array js and moment formats.
600
+	 */
601
+	protected static function _php_to_js_moment_converter($format_string)
602
+	{
603
+		/**
604
+		 * This is a map of symbols for formats.
605
+		 * The index is the php symbol, the equivalent values are in the array.
606
+		 *
607
+		 * @var array
608
+		 */
609
+		$symbols_map      = array(
610
+			// Day
611
+			//01
612
+			'd' => array(
613
+				'js'     => 'dd',
614
+				'moment' => 'DD',
615
+			),
616
+			//Mon
617
+			'D' => array(
618
+				'js'     => 'D',
619
+				'moment' => 'ddd',
620
+			),
621
+			//1,2,...31
622
+			'j' => array(
623
+				'js'     => 'd',
624
+				'moment' => 'D',
625
+			),
626
+			//Monday
627
+			'l' => array(
628
+				'js'     => 'DD',
629
+				'moment' => 'dddd',
630
+			),
631
+			//ISO numeric representation of the day of the week (1-6)
632
+			'N' => array(
633
+				'js'     => '',
634
+				'moment' => 'E',
635
+			),
636
+			//st,nd.rd
637
+			'S' => array(
638
+				'js'     => '',
639
+				'moment' => 'o',
640
+			),
641
+			//numeric representation of day of week (0-6)
642
+			'w' => array(
643
+				'js'     => '',
644
+				'moment' => 'd',
645
+			),
646
+			//day of year starting from 0 (0-365)
647
+			'z' => array(
648
+				'js'     => 'o',
649
+				'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
+			),
651
+			// Week
652
+			//ISO-8601 week number of year (weeks starting on monday)
653
+			'W' => array(
654
+				'js'     => '',
655
+				'moment' => 'w',
656
+			),
657
+			// Month
658
+			// January...December
659
+			'F' => array(
660
+				'js'     => 'MM',
661
+				'moment' => 'MMMM',
662
+			),
663
+			//01...12
664
+			'm' => array(
665
+				'js'     => 'mm',
666
+				'moment' => 'MM',
667
+			),
668
+			//Jan...Dec
669
+			'M' => array(
670
+				'js'     => 'M',
671
+				'moment' => 'MMM',
672
+			),
673
+			//1-12
674
+			'n' => array(
675
+				'js'     => 'm',
676
+				'moment' => 'M',
677
+			),
678
+			//number of days in given month
679
+			't' => array(
680
+				'js'     => '',
681
+				'moment' => '',
682
+			),
683
+			// Year
684
+			//whether leap year or not 1/0
685
+			'L' => array(
686
+				'js'     => '',
687
+				'moment' => '',
688
+			),
689
+			//ISO-8601 year number
690
+			'o' => array(
691
+				'js'     => '',
692
+				'moment' => 'GGGG',
693
+			),
694
+			//1999...2003
695
+			'Y' => array(
696
+				'js'     => 'yy',
697
+				'moment' => 'YYYY',
698
+			),
699
+			//99...03
700
+			'y' => array(
701
+				'js'     => 'y',
702
+				'moment' => 'YY',
703
+			),
704
+			// Time
705
+			// am/pm
706
+			'a' => array(
707
+				'js'     => 'tt',
708
+				'moment' => 'a',
709
+			),
710
+			// AM/PM
711
+			'A' => array(
712
+				'js'     => 'TT',
713
+				'moment' => 'A',
714
+			),
715
+			// Swatch Internet Time?!?
716
+			'B' => array(
717
+				'js'     => '',
718
+				'moment' => '',
719
+			),
720
+			//1...12
721
+			'g' => array(
722
+				'js'     => 'h',
723
+				'moment' => 'h',
724
+			),
725
+			//0...23
726
+			'G' => array(
727
+				'js'     => 'H',
728
+				'moment' => 'H',
729
+			),
730
+			//01...12
731
+			'h' => array(
732
+				'js'     => 'hh',
733
+				'moment' => 'hh',
734
+			),
735
+			//00...23
736
+			'H' => array(
737
+				'js'     => 'HH',
738
+				'moment' => 'HH',
739
+			),
740
+			//00..59
741
+			'i' => array(
742
+				'js'     => 'mm',
743
+				'moment' => 'mm',
744
+			),
745
+			//seconds... 00...59
746
+			's' => array(
747
+				'js'     => 'ss',
748
+				'moment' => 'ss',
749
+			),
750
+			//microseconds
751
+			'u' => array(
752
+				'js'     => '',
753
+				'moment' => '',
754
+			),
755
+		);
756
+		$jquery_ui_format = "";
757
+		$moment_format    = "";
758
+		$escaping         = false;
759
+		for ($i = 0; $i < strlen($format_string); $i++) {
760
+			$char = $format_string[$i];
761
+			if ($char === '\\') { // PHP date format escaping character
762
+				$i++;
763
+				if ($escaping) {
764
+					$jquery_ui_format .= $format_string[$i];
765
+					$moment_format .= $format_string[$i];
766
+				} else {
767
+					$jquery_ui_format .= '\'' . $format_string[$i];
768
+					$moment_format .= $format_string[$i];
769
+				}
770
+				$escaping = true;
771
+			} else {
772
+				if ($escaping) {
773
+					$jquery_ui_format .= "'";
774
+					$moment_format .= "'";
775
+					$escaping = false;
776
+				}
777
+				if (isset($symbols_map[$char])) {
778
+					$jquery_ui_format .= $symbols_map[$char]['js'];
779
+					$moment_format .= $symbols_map[$char]['moment'];
780
+				} else {
781
+					$jquery_ui_format .= $char;
782
+					$moment_format .= $char;
783
+				}
784
+			}
785
+		}
786
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
+	}
788
+
789
+
790
+	/**
791
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
+	 *
793
+	 * @param string $format_string   Incoming format string for php date().
794
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
+	 *                                errors is returned.  So for client code calling, check for is_array() to
796
+	 *                                indicate failed validations.
797
+	 */
798
+	public static function validate_format_string($format_string)
799
+	{
800
+		$error_msg = array();
801
+		//time format checks
802
+		switch (true) {
803
+			case   strpos($format_string, 'h') !== false  :
804
+			case   strpos($format_string, 'g') !== false :
805
+				/**
806
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
+				 */
810
+				if (strpos(strtoupper($format_string), 'A') === false) {
811
+					$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".',
812
+						'event_espresso');
813
+				}
814
+				break;
815
+
816
+		}
817
+
818
+		return empty($error_msg) ? true : $error_msg;
819
+	}
820
+
821
+
822
+	/**
823
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
+	 *     very next day then this method will return true.
825
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
+	 *
829
+	 * @param mixed $date_1
830
+	 * @param mixed $date_2
831
+	 * @return bool
832
+	 */
833
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
+	{
835
+
836
+		if (
837
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
+			($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
+		) {
840
+			return false;
841
+		}
842
+		return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
+	}
844
+
845
+
846
+	/**
847
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
+	 * Functions.
849
+	 *
850
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
+	 * @return string
853
+	 */
854
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
+	{
856
+		try {
857
+			/** need to account for timezone offset on the selects */
858
+			$DateTimeZone = new DateTimeZone($timezone_string);
859
+		} catch (Exception $e) {
860
+			$DateTimeZone = null;
861
+		}
862
+
863
+		/**
864
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
+		 * Hence we do the calc for DateTimeZone::getOffset.
866
+		 */
867
+		$offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
+		$query_interval = $offset < 0
869
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
+		return $query_interval;
872
+	}
873
+
874
+	/**
875
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
+	 * and 'gmt_offset' WordPress options directly; or use the filter
878
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
+	 * (although note that we remove any HTML that may be added)
880
+	 *
881
+	 * @return string
882
+	 */
883
+	public static function get_timezone_string_for_display()
884
+	{
885
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
+		if (! empty($pretty_timezone)) {
887
+			return esc_html($pretty_timezone);
888
+		}
889
+		$timezone_string = get_option('timezone_string');
890
+		if ($timezone_string) {
891
+			static $mo_loaded = false;
892
+			// Load translations for continents and cities just like wp_timezone_choice does
893
+			if (! $mo_loaded) {
894
+				$locale = get_locale();
895
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
+				load_textdomain('continents-cities', $mofile);
897
+				$mo_loaded = true;
898
+			}
899
+			//well that was easy.
900
+			$parts = explode('/', $timezone_string);
901
+			//remove the continent
902
+			unset($parts[0]);
903
+			$t_parts = array();
904
+			foreach ($parts as $part) {
905
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
+			}
907
+			return implode(' - ', $t_parts);
908
+		}
909
+		//they haven't set the timezone string, so let's return a string like "UTC+1"
910
+		$gmt_offset = get_option('gmt_offset');
911
+		if (intval($gmt_offset) >= 0) {
912
+			$prefix = '+';
913
+		} else {
914
+			$prefix = '';
915
+		}
916
+		$parts = explode('.', (string)$gmt_offset);
917
+		if (count($parts) === 1) {
918
+			$parts[1] = '00';
919
+		} else {
920
+			//convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
+			//to minutes, eg 30 or 15, respectively
922
+			$hour_fraction = (float)('0.' . $parts[1]);
923
+			$parts[1]      = (string)$hour_fraction * 60;
924
+		}
925
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
+	}
927
+
928
+
929
+
930
+	/**
931
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
932
+	 * for a month using a string like "February" or "February 2017",
933
+	 * and you don't specify a day as part of your string,
934
+	 * then PHP will use whatever the current day of the month is.
935
+	 * IF the current day of the month happens to be the 30th or 31st,
936
+	 * then PHP gets really confused by a date like February 30,
937
+	 * so instead of saying
938
+	 *      "Hey February only has 28 days (this year)...
939
+	 *      ...you must have meant the last day of the month!"
940
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
+	 * because someone requesting February 30th obviously meant March 1st!
942
+	 * The way around this is to always set the day to the first,
943
+	 * so that the month will stay on the month you wanted.
944
+	 * this method will add that "1" into your date regardless of the format.
945
+	 *
946
+	 * @param string $month
947
+	 * @return string
948
+	 */
949
+	public static function first_of_month_timestamp($month = '')
950
+	{
951
+		$month = (string)$month;
952
+		$year = '';
953
+		// check if the incoming string has a year in it or not
954
+	   if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
+		   $year = $matches[0];
956
+		   // ten remove that from the month string as well as any spaces
957
+		   $month = trim(str_replace($year, '', $month));
958
+		   // add a space before the year
959
+		   $year = " {$year}";
960
+		}
961
+		// return timestamp for something like "February 1 2017"
962
+		return strtotime("{$month} 1{$year}");
963
+	}
964 964
 
965 965
 	/**
966
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
967
-	* for this sites timezone, but the timestamp could be some other time GMT.
968
-    */
969
-    public static function tomorrow()
966
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
967
+	 * for this sites timezone, but the timestamp could be some other time GMT.
968
+	 */
969
+	public static function tomorrow()
970 970
 	{
971 971
 		//The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
972 972
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
Please login to merge, or discard this patch.
Spacing   +39 added lines, -40 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(
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             }
136 136
         }
137 137
         $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
138
+        return (int) ($offset * HOUR_IN_SECONDS);
139 139
     }
140 140
 
141 141
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150 150
     {
151 151
         //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
152
+        $gmt_offset = (int) $gmt_offset;
153 153
         switch ($gmt_offset) {
154 154
 
155 155
             //			case -30600 :
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public static function timezone_select_input($timezone_string = '')
234 234
     {
235 235
         // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
236
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
237 237
         // if passed a value, then use that, else get WP option
238 238
         $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239 239
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
             // Create a UTC+- zone if no timezone string exists
246 246
             $check_zone_info = false;
247 247
             if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
248
+                $timezone_string = 'UTC+'.$gmt_offset;
249 249
             } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
250
+                $timezone_string = 'UTC'.$gmt_offset;
251 251
             } else {
252 252
                 $timezone_string = 'UTC';
253 253
             }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
                 __('%1$sUTC%2$s time is %3$s'),
270 270
                 '<abbr title="Coordinated Universal Time">',
271 271
                 '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
272
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
273 273
             );
274 274
             ?></span>
275
-        <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
-        <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
275
+        <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
+        <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
277 277
     <?php endif; ?>
278 278
 
279 279
         <?php if ($check_zone_info && $timezone_string) : ?>
@@ -306,11 +306,10 @@  discard block
 block discarded – undo
306 306
 
307 307
                 if ($found) {
308 308
                     $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
309
+                        __(' Daylight saving time begins on: %s.') : __(' Standard time begins  on: %s.');
311 310
                     // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312 311
                     printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
312
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >');
314 313
                 } else {
315 314
                     _e('This timezone does not observe daylight saving time.');
316 315
                 }
@@ -338,13 +337,13 @@  discard block
 block discarded – undo
338 337
      */
339 338
     public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340 339
     {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
340
+        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
342 341
         $timezone_string = self::get_valid_timezone_string($timezone_string);
343 342
         $TimeZone        = new DateTimeZone($timezone_string);
344 343
 
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
344
+        $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone);
346 345
         $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
346
+        return (int) $DateTime->format('U') + (int) $offset;
348 347
     }
349 348
 
350 349
 
@@ -427,7 +426,7 @@  discard block
 block discarded – undo
427 426
      */
428 427
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429 428
     {
430
-        if (! $DateTime instanceof DateTime) {
429
+        if ( ! $DateTime instanceof DateTime) {
431 430
             throw new EE_Error(
432 431
                 sprintf(
433 432
                     __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -437,25 +436,25 @@  discard block
 block discarded – undo
437 436
         }
438 437
         switch ($period) {
439 438
             case 'years' :
440
-                $value = 'P' . $value . 'Y';
439
+                $value = 'P'.$value.'Y';
441 440
                 break;
442 441
             case 'months' :
443
-                $value = 'P' . $value . 'M';
442
+                $value = 'P'.$value.'M';
444 443
                 break;
445 444
             case 'weeks' :
446
-                $value = 'P' . $value . 'W';
445
+                $value = 'P'.$value.'W';
447 446
                 break;
448 447
             case 'days' :
449
-                $value = 'P' . $value . 'D';
448
+                $value = 'P'.$value.'D';
450 449
                 break;
451 450
             case 'hours' :
452
-                $value = 'PT' . $value . 'H';
451
+                $value = 'PT'.$value.'H';
453 452
                 break;
454 453
             case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
454
+                $value = 'PT'.$value.'M';
456 455
                 break;
457 456
             case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
457
+                $value = 'PT'.$value.'S';
459 458
                 break;
460 459
         }
461 460
         switch ($operand) {
@@ -483,7 +482,7 @@  discard block
 block discarded – undo
483 482
      */
484 483
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485 484
     {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
485
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487 486
             throw new EE_Error(
488 487
                 sprintf(
489 488
                     __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -587,7 +586,7 @@  discard block
 block discarded – undo
587 586
                 'date' => $date_format['js'],
588 587
                 'time' => $time_format['js'],
589 588
             ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
589
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
591 590
         );
592 591
     }
593 592
 
@@ -606,7 +605,7 @@  discard block
 block discarded – undo
606 605
          *
607 606
          * @var array
608 607
          */
609
-        $symbols_map      = array(
608
+        $symbols_map = array(
610 609
             // Day
611 610
             //01
612 611
             'd' => array(
@@ -764,7 +763,7 @@  discard block
 block discarded – undo
764 763
                     $jquery_ui_format .= $format_string[$i];
765 764
                     $moment_format .= $format_string[$i];
766 765
                 } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
766
+                    $jquery_ui_format .= '\''.$format_string[$i];
768 767
                     $moment_format .= $format_string[$i];
769 768
                 }
770 769
                 $escaping = true;
@@ -834,7 +833,7 @@  discard block
 block discarded – undo
834 833
     {
835 834
 
836 835
         if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
836
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838 837
             ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839 838
         ) {
840 839
             return false;
@@ -866,8 +865,8 @@  discard block
 block discarded – undo
866 865
          */
867 866
         $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868 867
         $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
868
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
869
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
871 870
         return $query_interval;
872 871
     }
873 872
 
@@ -883,16 +882,16 @@  discard block
 block discarded – undo
883 882
     public static function get_timezone_string_for_display()
884 883
     {
885 884
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
885
+        if ( ! empty($pretty_timezone)) {
887 886
             return esc_html($pretty_timezone);
888 887
         }
889 888
         $timezone_string = get_option('timezone_string');
890 889
         if ($timezone_string) {
891 890
             static $mo_loaded = false;
892 891
             // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
892
+            if ( ! $mo_loaded) {
894 893
                 $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
894
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
896 895
                 load_textdomain('continents-cities', $mofile);
897 896
                 $mo_loaded = true;
898 897
             }
@@ -913,16 +912,16 @@  discard block
 block discarded – undo
913 912
         } else {
914 913
             $prefix = '';
915 914
         }
916
-        $parts = explode('.', (string)$gmt_offset);
915
+        $parts = explode('.', (string) $gmt_offset);
917 916
         if (count($parts) === 1) {
918 917
             $parts[1] = '00';
919 918
         } else {
920 919
             //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921 920
             //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
921
+            $hour_fraction = (float) ('0.'.$parts[1]);
922
+            $parts[1]      = (string) $hour_fraction * 60;
924 923
         }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
924
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
926 925
     }
927 926
 
928 927
 
@@ -948,7 +947,7 @@  discard block
 block discarded – undo
948 947
      */
949 948
     public static function first_of_month_timestamp($month = '')
950 949
     {
951
-        $month = (string)$month;
950
+        $month = (string) $month;
952 951
         $year = '';
953 952
         // check if the incoming string has a year in it or not
954 953
        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
@@ -972,7 +971,7 @@  discard block
 block discarded – undo
972 971
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
973 972
 		//not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
974 973
 		//final timestamp is equivalent to midnight in this timezone as represented in GMT.
975
-		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1);
974
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
976 975
 	}
977 976
 
978 977
 }// end class EEH_DTT_Helper
Please login to merge, or discard this patch.
core/EES_Shortcode.shortcode.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -20,17 +20,17 @@  discard block
 block discarded – undo
20 20
 
21 21
 
22 22
 
23
-    /**
24
-     * class constructor - should ONLY be instantiated by EE_Front_Controller
25
-     */
26
-    final public function __construct()
27
-    {
28
-        $shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this));
29
-        // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier
30
-        add_shortcode($shortcode, array($this, 'process_shortcode'));
31
-        // make sure system knows this is an EE page
32
-        EE_Registry::instance()->REQ->set_espresso_page(true);
33
-    }
23
+	/**
24
+	 * class constructor - should ONLY be instantiated by EE_Front_Controller
25
+	 */
26
+	final public function __construct()
27
+	{
28
+		$shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this));
29
+		// assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier
30
+		add_shortcode($shortcode, array($this, 'process_shortcode'));
31
+		// make sure system knows this is an EE page
32
+		EE_Registry::instance()->REQ->set_espresso_page(true);
33
+	}
34 34
 
35 35
 
36 36
 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 		}
78 78
 		$shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class ));
79 79
 		$shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} )
80
-            ? EE_Registry::instance()->shortcodes->{$shortcode}
81
-            : null;
80
+			? EE_Registry::instance()->shortcodes->{$shortcode}
81
+			: null;
82 82
 		return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
83
-            ? $shortcode_obj
84
-            : new $shortcode_class();
83
+			? $shortcode_obj
84
+			: new $shortcode_class();
85 85
 	}
86 86
 
87 87
 
@@ -135,59 +135,59 @@  discard block
 block discarded – undo
135 135
 
136 136
 
137 137
 
138
-    /**
139
-     * Performs basic sanitization on shortcode attributes
140
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
141
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
142
-     * This can be overridden by supplying an array for the $custom_sanitization param,
143
-     * where keys match keys in your attributes array,
144
-     * and values represent the sanitization function you wish to be applied to that attribute.
145
-     * So for example, if you had an integer attribute named "event_id"
146
-     * that you wanted to be sanitized using absint(),
147
-     * then you would pass the following for your $custom_sanitization array:
148
-     *      array('event_id' => 'absint')
149
-     * all other attributes would be sanitized using the defaults in the switch statement below
150
-     *
151
-     * @param array $attributes
152
-     * @param array $custom_sanitization
153
-     * @return array
154
-     */
155
-    public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
156
-    {
157
-        foreach ($attributes as $key => $value) {
158
-            // is a custom sanitization callback specified ?
159
-            if ( isset($custom_sanitization[$key])) {
160
-                $callback = $custom_sanitization[$key];
161
-                if ($callback === 'skip_sanitization') {
162
-                    $attributes[$key] = $value;
163
-                    continue;
164
-                } else if (function_exists($callback)){
165
-                    $attributes[$key] = $callback($value);
166
-                    continue;
167
-                }
168
-            }
169
-            switch (true) {
170
-                case $value === null :
171
-                case is_int($value) :
172
-                case is_float($value) :
173
-                    // typical booleans
174
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
175
-                    $attributes[$key] = $value;
176
-                    break;
177
-                case is_string($value) :
178
-                    $attributes[$key] = sanitize_text_field($value);
179
-                    break;
180
-                case is_array($value) :
181
-                    $attributes[$key] = \EES_Shortcode::sanitize_attributes($value);
182
-                    break;
183
-                default :
184
-                    // only remaining data types are Object and Resource
185
-                    // which are not allowed as shortcode attributes
186
-                    $attributes[$key] = null;
187
-                    break;
188
-            }
189
-        }
190
-        return $attributes;
138
+	/**
139
+	 * Performs basic sanitization on shortcode attributes
140
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
141
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
142
+	 * This can be overridden by supplying an array for the $custom_sanitization param,
143
+	 * where keys match keys in your attributes array,
144
+	 * and values represent the sanitization function you wish to be applied to that attribute.
145
+	 * So for example, if you had an integer attribute named "event_id"
146
+	 * that you wanted to be sanitized using absint(),
147
+	 * then you would pass the following for your $custom_sanitization array:
148
+	 *      array('event_id' => 'absint')
149
+	 * all other attributes would be sanitized using the defaults in the switch statement below
150
+	 *
151
+	 * @param array $attributes
152
+	 * @param array $custom_sanitization
153
+	 * @return array
154
+	 */
155
+	public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
156
+	{
157
+		foreach ($attributes as $key => $value) {
158
+			// is a custom sanitization callback specified ?
159
+			if ( isset($custom_sanitization[$key])) {
160
+				$callback = $custom_sanitization[$key];
161
+				if ($callback === 'skip_sanitization') {
162
+					$attributes[$key] = $value;
163
+					continue;
164
+				} else if (function_exists($callback)){
165
+					$attributes[$key] = $callback($value);
166
+					continue;
167
+				}
168
+			}
169
+			switch (true) {
170
+				case $value === null :
171
+				case is_int($value) :
172
+				case is_float($value) :
173
+					// typical booleans
174
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
175
+					$attributes[$key] = $value;
176
+					break;
177
+				case is_string($value) :
178
+					$attributes[$key] = sanitize_text_field($value);
179
+					break;
180
+				case is_array($value) :
181
+					$attributes[$key] = \EES_Shortcode::sanitize_attributes($value);
182
+					break;
183
+				default :
184
+					// only remaining data types are Object and Resource
185
+					// which are not allowed as shortcode attributes
186
+					$attributes[$key] = null;
187
+					break;
188
+			}
189
+		}
190
+		return $attributes;
191 191
 	}
192 192
 
193 193
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @param WP $WP
48 48
 	 * @return    void
49 49
 	 */
50
-	public abstract function run( WP $WP );
50
+	public abstract function run(WP $WP);
51 51
 
52 52
 
53 53
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *  @param		array 	$attributes
60 60
 	 *  @return 	mixed
61 61
 	 */
62
-	public abstract function process_shortcode( $attributes = array() );
62
+	public abstract function process_shortcode($attributes = array());
63 63
 
64 64
 
65 65
 
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 	 * @param 	string $shortcode_class
71 71
 	 * @return 	\EES_Shortcode
72 72
 	 */
73
-	final public static function instance( $shortcode_class = null ) {
74
-		$shortcode_class = ! empty( $shortcode_class ) ? $shortcode_class : get_called_class();
75
-		if ( $shortcode_class === 'EES_Shortcode' || empty( $shortcode_class )) {
73
+	final public static function instance($shortcode_class = null) {
74
+		$shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class();
75
+		if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) {
76 76
 			return null;
77 77
 		}
78
-		$shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class ));
79
-		$shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} )
78
+		$shortcode = str_replace('EES_', '', strtoupper($shortcode_class));
79
+		$shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode} )
80 80
             ? EE_Registry::instance()->shortcodes->{$shortcode}
81 81
             : null;
82 82
 		return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
@@ -95,23 +95,23 @@  discard block
 block discarded – undo
95 95
 	 * @param 	$attributes
96 96
 	 * @return 	mixed
97 97
 	 */
98
-	final public static function fallback_shortcode_processor( $attributes ) {
99
-		if ( EE_Maintenance_Mode::disable_frontend_for_maintenance() ) {
98
+	final public static function fallback_shortcode_processor($attributes) {
99
+		if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) {
100 100
 			return null;
101 101
 		}
102 102
 		// what shortcode was actually parsed ?
103 103
 		$shortcode_class = get_called_class();
104 104
 		// notify rest of system that fallback processor was triggered
105
-		add_filter( 'FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true' );
105
+		add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true');
106 106
 		// get instance of actual shortcode
107
-		$shortcode_obj = self::instance( $shortcode_class );
107
+		$shortcode_obj = self::instance($shortcode_class);
108 108
 		// verify class
109
-		if ( $shortcode_obj instanceof EES_Shortcode ) {
109
+		if ($shortcode_obj instanceof EES_Shortcode) {
110 110
 			global $wp;
111
-			$shortcode_obj->run( $wp );
111
+			$shortcode_obj->run($wp);
112 112
 			// set attributes and run the shortcode
113
-			$shortcode_obj->_attributes = (array)$attributes;
114
-			return $shortcode_obj->process_shortcode( $shortcode_obj->_attributes );
113
+			$shortcode_obj->_attributes = (array) $attributes;
114
+			return $shortcode_obj->process_shortcode($shortcode_obj->_attributes);
115 115
 		} else {
116 116
 			return null;
117 117
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 * @param 	$attributes
128 128
 	 * @return 	string
129 129
 	 */
130
-	final public static function invalid_shortcode_processor( $attributes ) {
130
+	final public static function invalid_shortcode_processor($attributes) {
131 131
 		return '';
132 132
 	}
133 133
 
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
     {
157 157
         foreach ($attributes as $key => $value) {
158 158
             // is a custom sanitization callback specified ?
159
-            if ( isset($custom_sanitization[$key])) {
159
+            if (isset($custom_sanitization[$key])) {
160 160
                 $callback = $custom_sanitization[$key];
161 161
                 if ($callback === 'skip_sanitization') {
162 162
                     $attributes[$key] = $value;
163 163
                     continue;
164
-                } else if (function_exists($callback)){
164
+                } else if (function_exists($callback)) {
165 165
                     $attributes[$key] = $callback($value);
166 166
                     continue;
167 167
                 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Spacing   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public static function instance() {
42 42
 		// check if class object is instantiated
43
-		if (  ! self::$_instance instanceof EE_Admin ) {
43
+		if ( ! self::$_instance instanceof EE_Admin) {
44 44
 			self::$_instance = new self();
45 45
 		}
46 46
 		return self::$_instance;
@@ -57,25 +57,25 @@  discard block
 block discarded – undo
57 57
 		// define global EE_Admin constants
58 58
 		$this->_define_all_constants();
59 59
 		// set autoloaders for our admin page classes based on included path information
60
-		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN );
60
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
61 61
 		// admin hooks
62
-		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
62
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
63 63
 		// load EE_Request_Handler early
64
-		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' ));
65
-		add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' ));
66
-		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
67
-		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
68
-		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
69
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
70
-		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
71
-		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
72
-		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
73
-		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
64
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
65
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
66
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
67
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
68
+		add_action('admin_init', array($this, 'admin_init'), 100);
69
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
70
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
71
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
72
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
73
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
74 74
 
75 75
 		//reset Environment config (we only do this on admin page loads);
76 76
 		EE_Registry::instance()->CFG->environment->recheck_values();
77 77
 
78
-		do_action( 'AHEE__EE_Admin__loaded' );
78
+		do_action('AHEE__EE_Admin__loaded');
79 79
 	}
80 80
 
81 81
 
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 * @return void
91 91
 	 */
92 92
 	private function _define_all_constants() {
93
-		define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
94
-		define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
95
-		define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
96
-		define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
97
-		define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ));
93
+		define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
94
+		define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
95
+		define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
96
+		define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
97
+		define('WP_AJAX_URL', admin_url('admin-ajax.php'));
98 98
 	}
99 99
 
100 100
 
@@ -107,23 +107,23 @@  discard block
 block discarded – undo
107 107
 	 * @param 	string 	$plugin
108 108
 	 * @return 	array
109 109
 	 */
110
-	public function filter_plugin_actions( $links, $plugin ) {
110
+	public function filter_plugin_actions($links, $plugin) {
111 111
 		// set $main_file in stone
112 112
 		static $main_file;
113 113
 		// if $main_file is not set yet
114
-		if ( ! $main_file ) {
115
-			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
114
+		if ( ! $main_file) {
115
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
116 116
 		}
117
-		 if ( $plugin === $main_file ) {
117
+		 if ($plugin === $main_file) {
118 118
 		 	// compare current plugin to this one
119
-			if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) {
120
-				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>';
121
-				array_unshift( $links, $maintenance_link );
119
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
120
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>';
121
+				array_unshift($links, $maintenance_link);
122 122
 			} else {
123
-				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
124
-				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
123
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>';
124
+				$events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>';
125 125
 				// add before other links
126
-				array_unshift( $links, $org_settings_link, $events_link );
126
+				array_unshift($links, $org_settings_link, $events_link);
127 127
 			}
128 128
 		}
129 129
 		return $links;
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	 *	@return void
139 139
 	 */
140 140
 	public function get_request() {
141
-		EE_Registry::instance()->load_core( 'Request_Handler' );
142
-		EE_Registry::instance()->load_core( 'CPT_Strategy' );
141
+		EE_Registry::instance()->load_core('Request_Handler');
142
+		EE_Registry::instance()->load_core('CPT_Strategy');
143 143
 	}
144 144
 
145 145
 
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 	 * @param array $admin_page_folder_names
152 152
 	 * @return array
153 153
 	 */
154
-	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
154
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) {
155 155
 		return array(
156
-			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
157
-			'about' => EE_ADMIN_PAGES . 'about' . DS,
158
-			'support' => EE_ADMIN_PAGES . 'support' . DS
156
+			'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
157
+			'about' => EE_ADMIN_PAGES.'about'.DS,
158
+			'support' => EE_ADMIN_PAGES.'support'.DS
159 159
 		);
160 160
 	}
161 161
 
@@ -169,31 +169,31 @@  discard block
 block discarded – undo
169 169
 	*/
170 170
 	public function init() {
171 171
 		//only enable most of the EE_Admin IF we're not in full maintenance mode
172
-		if ( EE_Maintenance_Mode::instance()->models_can_query() ){
172
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
173 173
 			//ok so we want to enable the entire admin
174
-			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
175
-			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
176
-			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
174
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
175
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
176
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
177 177
 			//at a glance dashboard widget
178
-			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 );
178
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
179 179
 			//filter for get_edit_post_link used on comments for custom post types
180
-			add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 );
180
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
181 181
 		}
182 182
 		// run the admin page factory but ONLY if we are doing an ee admin ajax request
183
-		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
183
+		if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
184 184
 			try {
185 185
 				//this loads the controller for the admin pages which will setup routing etc
186
-				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
187
-			} catch ( EE_Error $e ) {
186
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
187
+			} catch (EE_Error $e) {
188 188
 				$e->get_error();
189 189
 			}
190 190
 		}
191
-		add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
191
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
192 192
 		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
193
-		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
194
-		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
193
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
194
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
195 195
 		//exclude EE critical pages from all nav menus and wp_list_pages
196
-		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
196
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
197 197
 	}
198 198
 
199 199
 
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 	 * @param  object $post_type WP post type object
207 207
 	 * @return object            WP post type object
208 208
 	 */
209
-	public function remove_pages_from_nav_menu( $post_type ) {
209
+	public function remove_pages_from_nav_menu($post_type) {
210 210
 		//if this isn't the "pages" post type let's get out
211
-		if ( $post_type->name !== 'page' ) {
211
+		if ($post_type->name !== 'page') {
212 212
 			return $post_type;
213 213
 		}
214 214
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
@@ -228,28 +228,28 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function enable_hidden_ee_nav_menu_metaboxes() {
230 230
 		global $wp_meta_boxes, $pagenow;
231
-		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
231
+		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
232 232
 			return;
233 233
 		}
234 234
 		$user = wp_get_current_user();
235 235
 		//has this been done yet?
236
-		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
236
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
237 237
 			return;
238 238
 		}
239 239
 
240
-		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
241
-		$initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) );
240
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
241
+		$initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page'));
242 242
 
243
-		if ( is_array( $hidden_meta_boxes ) ) {
244
-			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
245
-				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
246
-					unset( $hidden_meta_boxes[ $key ] );
243
+		if (is_array($hidden_meta_boxes)) {
244
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
245
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
246
+					unset($hidden_meta_boxes[$key]);
247 247
 				}
248 248
 			}
249 249
 		}
250 250
 
251
-		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
252
-		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
251
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
252
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
253 253
 	}
254 254
 
255 255
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @return void
269 269
 	 */
270 270
 	public function register_custom_nav_menu_boxes() {
271
-		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
271
+		add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core');
272 272
 	}
273 273
 
274 274
 
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @return string  the (maybe) modified link
286 286
 	 */
287
-	public function modify_edit_post_link( $link, $id ) {
288
-		if ( ! $post = get_post( $id ) ){
287
+	public function modify_edit_post_link($link, $id) {
288
+		if ( ! $post = get_post($id)) {
289 289
 			return $link;
290 290
 		}
291
-		if ( $post->post_type === 'espresso_attendees' ) {
291
+		if ($post->post_type === 'espresso_attendees') {
292 292
 			$query_args = array(
293 293
 				'action' => 'edit_attendee',
294 294
 				'post' => $id
295 295
 			);
296
-			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
296
+			return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations'));
297 297
 		}
298 298
 		return $link;
299 299
 	}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		global $nav_menu_selected_id;
306 306
 
307 307
 		$db_fields = false;
308
-		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
308
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
309 309
 		$current_tab = 'event-archives';
310 310
 
311 311
 		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
 		?>
325 325
 		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
326 326
 			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
327
-				<li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>>
328
-					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
329
-						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
327
+				<li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
328
+					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
329
+						<?php _e('Event Archive Pages', 'event_espresso'); ?>
330 330
 					</a>
331 331
 				</li>
332 332
 			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
  			<?php */ ?>
345 345
 
346 346
 			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
347
-			echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
347
+			echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
348 348
 			?>">
349 349
 				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
350 350
 					<?php
351 351
 					$pages = $this->_get_extra_nav_menu_pages_items();
352 352
 					$args['walker'] = $walker;
353
-					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
353
+					echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args);
354 354
 					?>
355 355
 				</ul>
356 356
 			</div><!-- /.tabs-panel -->
@@ -358,18 +358,18 @@  discard block
 block discarded – undo
358 358
 			<p class="button-controls">
359 359
 				<span class="list-controls">
360 360
 					<a href="<?php
361
-						echo esc_url( add_query_arg(
361
+						echo esc_url(add_query_arg(
362 362
 							array(
363 363
 								'extra-nav-menu-pages-tab' => 'event-archives',
364 364
 								'selectall' => 1,
365 365
 							),
366
-							remove_query_arg( $removed_args )
366
+							remove_query_arg($removed_args)
367 367
 						));
368 368
 					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
369 369
 				</span>
370 370
 
371 371
 				<span class="add-to-menu">
372
-					<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" />
372
+					<input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" />
373 373
 					<span class="spinner"></span>
374 374
 				</span>
375 375
 			</p>
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 	private function _get_extra_nav_menu_pages_items() {
391 391
 		$menuitems[] = array(
392 392
 			'title' => __('Event List', 'event_espresso'),
393
-			'url' => get_post_type_archive_link( 'espresso_events' ),
393
+			'url' => get_post_type_archive_link('espresso_events'),
394 394
 			'description' => __('Archive page for all events.', 'event_espresso')
395 395
 		);
396
-		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
396
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
397 397
 	}
398 398
 
399 399
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 * @param $menu_item_values
406 406
 	 * @return stdClass
407 407
 	 */
408
-	private function _setup_extra_nav_menu_pages_items( $menu_item_values ) {
408
+	private function _setup_extra_nav_menu_pages_items($menu_item_values) {
409 409
 		$menu_item = new stdClass();
410 410
 		$keys = array(
411 411
 			'ID' => 0,
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 			'xfn' => ''
426 426
 		);
427 427
 
428
-		foreach ( $keys as $key => $value) {
429
-			$menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value;
428
+		foreach ($keys as $key => $value) {
429
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
430 430
 		}
431 431
 		return $menu_item;
432 432
 	}
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 		 * - check if doing post processing of one of EE CPTs
466 466
 		 * - instantiate the corresponding EE CPT model for the post_type being processed.
467 467
 		 */
468
-		if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) {
469
-			EE_Registry::instance()->load_core( 'Register_CPTs' );
470
-			EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
468
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
469
+			EE_Registry::instance()->load_core('Register_CPTs');
470
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
471 471
 		}
472 472
 
473 473
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
          * tab in the EE General Settings Admin page.
478 478
          * This is for user-proofing.
479 479
 		 */
480
-        add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
480
+        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
481 481
 
482 482
 	}
483 483
 
@@ -488,25 +488,25 @@  discard block
 block discarded – undo
488 488
 	 * @param string $output  Current output.
489 489
 	 * @return string
490 490
 	 */
491
-	public function modify_dropdown_pages( $output ) {
491
+	public function modify_dropdown_pages($output) {
492 492
 		//get critical pages
493 493
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
494 494
 
495 495
 		//split current output by line break for easier parsing.
496
-		$split_output = explode( "\n", $output );
496
+		$split_output = explode("\n", $output);
497 497
 
498 498
 		//loop through to remove any critical pages from the array.
499
-		foreach ( $critical_pages as $page_id ) {
500
-			$needle = 'value="' . $page_id . '"';
501
-			foreach( $split_output as $key => $haystack ) {
502
-				if( strpos( $haystack, $needle ) !== false ) {
503
-					unset( $split_output[$key] );
499
+		foreach ($critical_pages as $page_id) {
500
+			$needle = 'value="'.$page_id.'"';
501
+			foreach ($split_output as $key => $haystack) {
502
+				if (strpos($haystack, $needle) !== false) {
503
+					unset($split_output[$key]);
504 504
 				}
505 505
 			}
506 506
 		}
507 507
 
508 508
 		//replace output with the new contents
509
-		return implode( "\n", $split_output );
509
+		return implode("\n", $split_output);
510 510
 	}
511 511
 
512 512
 
@@ -520,36 +520,36 @@  discard block
 block discarded – undo
520 520
 	public function enqueue_admin_scripts() {
521 521
 		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
522 522
 		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
523
-		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
523
+		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
524 524
 		// register cookie script for future dependencies
525
-		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
525
+		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE);
526 526
 		// jquery_validate loading is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
527
-		if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
527
+		if (apply_filters('FHEE_load_jquery_validate', FALSE)) {
528 528
 			// register jQuery Validate
529
-			wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE);
529
+			wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE);
530 530
 		}
531 531
 		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' );
532
-		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
532
+		if (apply_filters('FHEE_load_joyride', FALSE)) {
533 533
 			//joyride style
534
-			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
535
-			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
536
-			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
534
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
535
+			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION);
536
+			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE);
537 537
 			//joyride JS
538
-			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
538
+			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE);
539 539
 			// wanna go for a joyride?
540 540
 			wp_enqueue_style('ee-joyride-css');
541 541
 			wp_enqueue_script('jquery-joyride');
542 542
 		}
543 543
 		//qtip is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtips', '__return_true' );
544
-		if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) {
544
+		if (apply_filters('FHEE_load_qtip', FALSE)) {
545 545
 			EEH_Qtip_Loader::instance()->register_and_enqueue();
546 546
 		}
547 547
 		//accounting.js library
548 548
 		// @link http://josscrowcroft.github.io/accounting.js/
549
-		if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) {
550
-			wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE );
551
-			wp_register_script( 'ee-accounting-core', EE_THIRD_PARTY_URL . 'accounting/accounting.js', array('underscore'), '0.3.2', TRUE );
552
-			wp_enqueue_script( 'ee-accounting' );
549
+		if (apply_filters('FHEE_load_accounting_js', FALSE)) {
550
+			wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE);
551
+			wp_register_script('ee-accounting-core', EE_THIRD_PARTY_URL.'accounting/accounting.js', array('underscore'), '0.3.2', TRUE);
552
+			wp_enqueue_script('ee-accounting');
553 553
 			// array of settings to get converted to JSON array via wp_localize_script
554 554
 			$currency_config = array(
555 555
 				'currency' => array(
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
 	public function get_persistent_admin_notices() {
597 597
 		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
598 598
 		$args = array(
599
-			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
600
-			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
599
+			'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '',
600
+			'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '',
601 601
 		);
602
-		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
603
-		echo EE_Error::get_persistent_admin_notices( $return_url );
602
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
603
+		echo EE_Error::get_persistent_admin_notices($return_url);
604 604
 	}
605 605
 
606 606
 
@@ -625,24 +625,24 @@  discard block
 block discarded – undo
625 625
 	public function dashboard_glance_items($elements) {
626 626
         $elements = is_array($elements) ? $elements : array($elements);
627 627
 		$events = EEM_Event::instance()->count();
628
-		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') );
629
-		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
628
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php'));
629
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
630 630
 		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
631 631
 		$registrations = EEM_Registration::instance()->count(
632 632
 			array(
633 633
 				array(
634
-					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
634
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)
635 635
 				)
636 636
 			)
637 637
 		);
638
-		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
639
-		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
638
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php'));
639
+		$items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations));
640 640
 		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
641 641
 
642
-		$items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
642
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
643 643
 
644
-		foreach ( $items as $type => $item_properties ) {
645
-			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
644
+		foreach ($items as $type => $item_properties) {
645
+			$elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']);
646 646
 		}
647 647
 		return $elements;
648 648
 	}
@@ -659,31 +659,31 @@  discard block
 block discarded – undo
659 659
 	 * @throws EE_Error
660 660
 	 * @return    string
661 661
 	 */
662
-	public function check_for_invalid_datetime_formats( $value, $option ) {
662
+	public function check_for_invalid_datetime_formats($value, $option) {
663 663
 		// check for date_format or time_format
664
-		switch ( $option ) {
664
+		switch ($option) {
665 665
 			case 'date_format' :
666
-				$date_time_format = $value . ' ' . get_option('time_format');
666
+				$date_time_format = $value.' '.get_option('time_format');
667 667
 				break;
668 668
 			case 'time_format' :
669
-				$date_time_format = get_option('date_format') . ' ' . $value;
669
+				$date_time_format = get_option('date_format').' '.$value;
670 670
 				break;
671 671
 			default :
672 672
 				$date_time_format = FALSE;
673 673
 		}
674 674
 		// do we have a date_time format to check ?
675
-		if ( $date_time_format ) {
676
-			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
675
+		if ($date_time_format) {
676
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
677 677
 
678
-			if ( is_array( $error_msg ) ) {
679
-				$msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format  ) . '</p><p><ul>';
678
+			if (is_array($error_msg)) {
679
+				$msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>';
680 680
 
681 681
 
682
-				foreach ( $error_msg as $error ) {
683
-					$msg .= '<li>' . $error . '</li>';
682
+				foreach ($error_msg as $error) {
683
+					$msg .= '<li>'.$error.'</li>';
684 684
 				}
685 685
 
686
-				$msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>';
686
+				$msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>';
687 687
 
688 688
 				// trigger WP settings error
689 689
 				add_settings_error(
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 				);
694 694
 
695 695
 				// set format to something valid
696
-				switch ( $option ) {
696
+				switch ($option) {
697 697
 					case 'date_format' :
698 698
 						$value = 'F j, Y';
699 699
 						break;
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 	 * @param $content
716 716
 	 * @return    string
717 717
 	 */
718
-	public function its_eSpresso( $content ) {
719
-		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
718
+	public function its_eSpresso($content) {
719
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
720 720
 	}
721 721
 
722 722
 
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 	 *  @return 	string
729 729
 	 */
730 730
 	public function espresso_admin_footer() {
731
-		return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' ));
731
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
732 732
 	}
733 733
 
734 734
 
@@ -747,12 +747,12 @@  discard block
 block discarded – undo
747 747
 	 * @param array $config
748 748
 	 * @return void
749 749
 	 */
750
-	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
751
-		EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' );
752
-		if ( class_exists( 'EE_Register_Admin_Page' ) ) {
750
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array()) {
751
+		EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3');
752
+		if (class_exists('EE_Register_Admin_Page')) {
753 753
 			$config['page_path'] = $page_path;
754 754
 		}
755
-		EE_Register_Admin_Page::register( $page_basename, $config );
755
+		EE_Register_Admin_Page::register($page_basename, $config);
756 756
 
757 757
 	}
758 758
 
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 	 * @param  \WP_Post $post
766 766
 	 * @return void
767 767
 	 */
768
-	public static function parse_post_content_on_save( $post_ID, $post ) {
768
+	public static function parse_post_content_on_save($post_ID, $post) {
769 769
 		EE_Error::doing_it_wrong(
770 770
 			__METHOD__,
771 771
 			__('Usage is deprecated', 'event_espresso'),
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 	 * @param  $value
784 784
 	 * @return void
785 785
 	 */
786
-	public function reset_page_for_posts_on_change( $option, $old_value, $value ) {
786
+	public function reset_page_for_posts_on_change($option, $old_value, $value) {
787 787
 		EE_Error::doing_it_wrong(
788 788
 			__METHOD__,
789 789
 			__('Usage is deprecated', 'event_espresso'),
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEvents.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@
 block discarded – undo
108 108
     private function getAttributes(array $attributes)
109 109
     {
110 110
         return array_merge(
111
-            (array)apply_filters(
111
+            (array) apply_filters(
112 112
                 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
113 113
                 array(
114 114
                     'title'         => '',
Please login to merge, or discard this patch.
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -34,133 +34,133 @@
 block discarded – undo
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * the actual shortcode tag that gets registered with WordPress
39
-     *
40
-     * @return string
41
-     */
42
-    public function getTag()
43
-    {
44
-        return 'ESPRESSO_EVENTS';
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * the time in seconds to cache the results of the processShortcode() method
51
-     * 0 means the processShortcode() results will NOT be cached at all
52
-     *
53
-     * @return int
54
-     */
55
-    public function cacheExpiration()
56
-    {
57
-        return MINUTE_IN_SECONDS * 15;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * a place for adding any initialization code that needs to run prior to wp_header().
64
-     * this may be required for shortcodes that utilize a corresponding module,
65
-     * and need to enqueue assets for that module
66
-     *
67
-     * @return void
68
-     */
69
-    public function initializeShortcode()
70
-    {
71
-        EED_Events_Archive::instance()->event_list();
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * callback that runs when the shortcode is encountered in post content.
78
-     * IMPORTANT !!!
79
-     * remember that shortcode content should be RETURNED and NOT echoed out
80
-     *
81
-     * @param array $attributes
82
-     * @return string
83
-     */
84
-    public function processShortcode($attributes = array())
85
-    {
86
-        // grab attributes and merge with defaults
87
-        $attributes = $this->getAttributes($attributes);
88
-        // make sure we use the_excerpt()
89
-        add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
90
-        // apply query filters
91
-        add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
92
-        // run the query
93
-        global $wp_query;
94
-        // yes we have to overwrite the main wp query, but it's ok...
95
-        // we're going to reset it again below, so everything will be Hunky Dory (amazing album)
96
-        $wp_query = new EventListQuery($attributes);
97
-        // check what template is loaded and load filters accordingly
98
-        EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
99
-        // load our template
100
-        $event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), true, true);
101
-        // now reset the query and postdata
102
-        wp_reset_query();
103
-        wp_reset_postdata();
104
-        EED_Events_Archive::remove_all_events_archive_filters();
105
-        // remove query filters
106
-        remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
107
-        // pull our content from the output buffer and return it
108
-        return $event_list;
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     * merge incoming attributes with filtered defaults
115
-     *
116
-     * @param array $attributes
117
-     * @return array
118
-     */
119
-    private function getAttributes(array $attributes)
120
-    {
121
-        return array_merge(
122
-            (array)apply_filters(
123
-                'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
124
-                array(
125
-                    'title'         => '',
126
-                    'limit'         => 10,
127
-                    'css_class'     => '',
128
-                    'show_expired'  => false,
129
-                    'month'         => '',
130
-                    'category_slug' => '',
131
-                    'order_by'      => 'start_date',
132
-                    'sort'          => 'ASC',
133
-                    'show_title'    => true,
134
-                )
135
-            ),
136
-            $attributes
137
-        );
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * array for defining custom attribute sanitization callbacks,
144
-     * where keys match keys in your attributes array,
145
-     * and values represent the sanitization function you wish to be applied to that attribute.
146
-     * So for example, if you had an integer attribute named "event_id"
147
-     * that you wanted to be sanitized using absint(),
148
-     * then you would pass the following for your $custom_sanitization array:
149
-     *      array('event_id' => 'absint')
150
-     *
151
-     * @return array
152
-     */
153
-    protected function customAttributeSanitizationMap()
154
-    {
155
-        // the following get sanitized/whitelisted in EEH_Event_Query
156
-        return array(
157
-            'category_slug' => 'skip_sanitization',
158
-            'show_expired'  => 'skip_sanitization',
159
-            'order_by'      => 'skip_sanitization',
160
-            'month'         => 'skip_sanitization',
161
-            'sort'          => 'skip_sanitization',
162
-        );
163
-    }
37
+	/**
38
+	 * the actual shortcode tag that gets registered with WordPress
39
+	 *
40
+	 * @return string
41
+	 */
42
+	public function getTag()
43
+	{
44
+		return 'ESPRESSO_EVENTS';
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * the time in seconds to cache the results of the processShortcode() method
51
+	 * 0 means the processShortcode() results will NOT be cached at all
52
+	 *
53
+	 * @return int
54
+	 */
55
+	public function cacheExpiration()
56
+	{
57
+		return MINUTE_IN_SECONDS * 15;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * a place for adding any initialization code that needs to run prior to wp_header().
64
+	 * this may be required for shortcodes that utilize a corresponding module,
65
+	 * and need to enqueue assets for that module
66
+	 *
67
+	 * @return void
68
+	 */
69
+	public function initializeShortcode()
70
+	{
71
+		EED_Events_Archive::instance()->event_list();
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * callback that runs when the shortcode is encountered in post content.
78
+	 * IMPORTANT !!!
79
+	 * remember that shortcode content should be RETURNED and NOT echoed out
80
+	 *
81
+	 * @param array $attributes
82
+	 * @return string
83
+	 */
84
+	public function processShortcode($attributes = array())
85
+	{
86
+		// grab attributes and merge with defaults
87
+		$attributes = $this->getAttributes($attributes);
88
+		// make sure we use the_excerpt()
89
+		add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
90
+		// apply query filters
91
+		add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
92
+		// run the query
93
+		global $wp_query;
94
+		// yes we have to overwrite the main wp query, but it's ok...
95
+		// we're going to reset it again below, so everything will be Hunky Dory (amazing album)
96
+		$wp_query = new EventListQuery($attributes);
97
+		// check what template is loaded and load filters accordingly
98
+		EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
99
+		// load our template
100
+		$event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), true, true);
101
+		// now reset the query and postdata
102
+		wp_reset_query();
103
+		wp_reset_postdata();
104
+		EED_Events_Archive::remove_all_events_archive_filters();
105
+		// remove query filters
106
+		remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
107
+		// pull our content from the output buffer and return it
108
+		return $event_list;
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 * merge incoming attributes with filtered defaults
115
+	 *
116
+	 * @param array $attributes
117
+	 * @return array
118
+	 */
119
+	private function getAttributes(array $attributes)
120
+	{
121
+		return array_merge(
122
+			(array)apply_filters(
123
+				'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
124
+				array(
125
+					'title'         => '',
126
+					'limit'         => 10,
127
+					'css_class'     => '',
128
+					'show_expired'  => false,
129
+					'month'         => '',
130
+					'category_slug' => '',
131
+					'order_by'      => 'start_date',
132
+					'sort'          => 'ASC',
133
+					'show_title'    => true,
134
+				)
135
+			),
136
+			$attributes
137
+		);
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * array for defining custom attribute sanitization callbacks,
144
+	 * where keys match keys in your attributes array,
145
+	 * and values represent the sanitization function you wish to be applied to that attribute.
146
+	 * So for example, if you had an integer attribute named "event_id"
147
+	 * that you wanted to be sanitized using absint(),
148
+	 * then you would pass the following for your $custom_sanitization array:
149
+	 *      array('event_id' => 'absint')
150
+	 *
151
+	 * @return array
152
+	 */
153
+	protected function customAttributeSanitizationMap()
154
+	{
155
+		// the following get sanitized/whitelisted in EEH_Event_Query
156
+		return array(
157
+			'category_slug' => 'skip_sanitization',
158
+			'show_expired'  => 'skip_sanitization',
159
+			'order_by'      => 'skip_sanitization',
160
+			'month'         => 'skip_sanitization',
161
+			'sort'          => 'skip_sanitization',
162
+		);
163
+	}
164 164
 
165 165
 
166 166
 
Please login to merge, or discard this patch.
core/EE_Front_Controller.core.php 2 patches
Indentation   +594 added lines, -594 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\widgets\EspressoWidget;
4 4
 
5 5
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 /**
@@ -26,506 +26,506 @@  discard block
 block discarded – undo
26 26
 final class EE_Front_Controller
27 27
 {
28 28
 
29
-    /**
30
-     * @var string $_template_path
31
-     */
32
-    private $_template_path;
33
-
34
-    /**
35
-     * @var string $_template
36
-     */
37
-    private $_template;
38
-
39
-    /**
40
-     * @type EE_Registry $Registry
41
-     */
42
-    protected $Registry;
43
-
44
-    /**
45
-     * @type EE_Request_Handler $Request_Handler
46
-     */
47
-    protected $Request_Handler;
48
-
49
-    /**
50
-     * @type EE_Module_Request_Router $Module_Request_Router
51
-     */
52
-    protected $Module_Request_Router;
53
-
54
-
55
-    /**
56
-     *    class constructor
57
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
58
-     *
59
-     * @access    public
60
-     * @param \EE_Registry              $Registry
61
-     * @param \EE_Request_Handler       $Request_Handler
62
-     * @param \EE_Module_Request_Router $Module_Request_Router
63
-     */
64
-    public function __construct(
65
-        EE_Registry $Registry,
66
-        EE_Request_Handler $Request_Handler,
67
-        EE_Module_Request_Router $Module_Request_Router
68
-    ) {
69
-        $this->Registry              = $Registry;
70
-        $this->Request_Handler       = $Request_Handler;
71
-        $this->Module_Request_Router = $Module_Request_Router;
72
-        // determine how to integrate WP_Query with the EE models
73
-        add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
74
-        // load other resources and begin to actually run shortcodes and modules
75
-        add_action('wp_loaded', array($this, 'wp_loaded'), 5);
76
-        // analyse the incoming WP request
77
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
78
-        // process request with module factory
79
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
80
-        // before headers sent
81
-        add_action('wp', array($this, 'wp'), 5);
82
-        // after headers sent but before any markup is output,
83
-        // primarily used to process any content shortcodes
84
-        add_action('get_header', array($this, 'get_header'));
85
-        // load css and js
86
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
87
-        // header
88
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
89
-        add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
90
-        add_filter('template_include', array($this, 'template_include'), 1);
91
-        // display errors
92
-        add_action('loop_start', array($this, 'display_errors'), 2);
93
-        // the content
94
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
95
-        //exclude our private cpt comments
96
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
97
-        //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
98
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
99
-        // action hook EE
100
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
101
-        // for checking that browser cookies are enabled
102
-        if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
103
-            setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/');
104
-        }
105
-    }
106
-
107
-
108
-    /**
109
-     * @return EE_Request_Handler
110
-     */
111
-    public function Request_Handler()
112
-    {
113
-        return $this->Request_Handler;
114
-    }
115
-
116
-
117
-    /**
118
-     * @return EE_Module_Request_Router
119
-     */
120
-    public function Module_Request_Router()
121
-    {
122
-        return $this->Module_Request_Router;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * @return LegacyShortcodesManager
129
-     */
130
-    public function getLegacyShortcodesManager()
131
-    {
132
-        return EE_Config::getLegacyShortcodesManager();
133
-    }
134
-
135
-
136
-
137
-
138
-
139
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
140
-
141
-
142
-
143
-    /**
144
-     * filter_wp_comments
145
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
146
-     * widgets/queries done on frontend
147
-     *
148
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
149
-     * @return array array of comment clauses with modifications.
150
-     */
151
-    public function filter_wp_comments($clauses)
152
-    {
153
-        global $wpdb;
154
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
155
-            $cpts = EE_Register_CPTs::get_private_CPTs();
156
-            foreach ($cpts as $cpt => $details) {
157
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
158
-            }
159
-        }
160
-        return $clauses;
161
-    }
162
-
163
-
164
-    /**
165
-     *    employ_CPT_Strategy
166
-     *
167
-     * @access    public
168
-     * @return    void
169
-     */
170
-    public function employ_CPT_Strategy()
171
-    {
172
-        if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
173
-            $this->Registry->load_core('CPT_Strategy');
174
-        }
175
-    }
176
-
177
-
178
-    /**
179
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
180
-     *
181
-     * @param  string $url incoming url
182
-     * @return string         final assembled url
183
-     */
184
-    public function maybe_force_admin_ajax_ssl($url)
185
-    {
186
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
187
-            $url = str_replace('http://', 'https://', $url);
188
-        }
189
-        return $url;
190
-    }
191
-
192
-
193
-
194
-
195
-
196
-
197
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
198
-
199
-
200
-    /**
201
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
202
-     *    default priority init phases have run
203
-     *
204
-     * @access    public
205
-     * @return    void
206
-     */
207
-    public function wp_loaded()
208
-    {
209
-    }
210
-
211
-
212
-
213
-
214
-
215
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
216
-    /**
217
-     *    _get_request
218
-     *
219
-     * @access public
220
-     * @param WP $WP
221
-     * @return void
222
-     */
223
-    public function get_request(WP $WP)
224
-    {
225
-        do_action('AHEE__EE_Front_Controller__get_request__start');
226
-        $this->Request_Handler->parse_request($WP);
227
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
234
-     *
235
-     * @access    public
236
-     * @param   WP_Query $WP_Query
237
-     * @return    void
238
-     */
239
-    public function pre_get_posts($WP_Query)
240
-    {
241
-        // only load Module_Request_Router if this is the main query
242
-        if (
243
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
244
-            && $WP_Query->is_main_query()
245
-        ) {
246
-            // cycle thru module routes
247
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
248
-                // determine module and method for route
249
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
250
-                if ($module instanceof EED_Module) {
251
-                    // get registered view for route
252
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
253
-                    // grab module name
254
-                    $module_name = $module->module_name();
255
-                    // map the module to the module objects
256
-                    $this->Registry->modules->{$module_name} = $module;
257
-                }
258
-            }
259
-        }
260
-    }
261
-
262
-
263
-
264
-
265
-
266
-    /***********************************************        WP HOOK         ***********************************************/
267
-
268
-
269
-    /**
270
-     *    wp - basically last chance to do stuff before headers sent
271
-     *
272
-     * @access    public
273
-     * @return    void
274
-     */
275
-    public function wp()
276
-    {
277
-    }
278
-
279
-
280
-
281
-    /***********************     GET_HEADER, WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK     ***********************/
282
-
283
-
284
-
285
-    /**
286
-     * callback for the WP "get_header" hook point
287
-     * checks sidebars for EE widgets
288
-     * loads resources and assets accordingly
289
-     *
290
-     * @return void
291
-     */
292
-    public function get_header()
293
-    {
294
-        global $wp_query;
295
-        if (empty($wp_query->posts)){
296
-            return;
297
-        }
298
-        // if we already know this is an espresso page, then load assets
299
-        $load_assets = $this->Request_Handler->is_espresso_page();
300
-        // if we are already loading assets then just move along, otherwise check for widgets
301
-        $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
302
-        if ( $load_assets){
303
-            add_filter('FHEE_load_css', '__return_true');
304
-            add_filter('FHEE_load_js', '__return_true');
305
-        }
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * builds list of active widgets then scans active sidebars looking for them
312
-     * returns true is an EE widget is found in an active sidebar
313
-     * Please Note: this does NOT mean that the sidebar or widget
314
-     * is actually in use in a given template, as that is unfortunately not known
315
-     * until a sidebar and it's widgets are actually loaded
316
-     *
317
-     * @return boolean
318
-     */
319
-    private function espresso_widgets_in_active_sidebars()
320
-    {
321
-        $espresso_widgets = array();
322
-        foreach ($this->Registry->widgets as $widget_class => $widget) {
323
-            $id_base = EspressoWidget::getIdBase($widget_class);
324
-            if (is_active_widget(false, false, $id_base)) {
325
-                $espresso_widgets[] = $id_base;
326
-            }
327
-        }
328
-        $all_sidebar_widgets = wp_get_sidebars_widgets();
329
-        foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) {
330
-            if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
331
-                foreach ($sidebar_widgets as $sidebar_widget) {
332
-                    foreach ($espresso_widgets as $espresso_widget) {
333
-                        if (strpos($sidebar_widget, $espresso_widget) !== false) {
334
-                            return true;
335
-                        }
336
-                    }
337
-                }
338
-            }
339
-        }
340
-        return false;
341
-    }
342
-
343
-
344
-
345
-
346
-    /**
347
-     *    wp_enqueue_scripts
348
-     *
349
-     * @access    public
350
-     * @return    void
351
-     */
352
-    public function wp_enqueue_scripts()
353
-    {
354
-        // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
355
-        if (apply_filters('FHEE_load_css', false)) {
356
-
357
-            $this->Registry->CFG->template_settings->enable_default_style = true;
358
-            //Load the ThemeRoller styles if enabled
359
-            if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
360
-
361
-                //Load custom style sheet if available
362
-                if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
363
-                    wp_register_style('espresso_custom_css',
364
-                        EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
365
-                        EVENT_ESPRESSO_VERSION);
366
-                    wp_enqueue_style('espresso_custom_css');
367
-                }
368
-
369
-                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
370
-                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
371
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
372
-                } else {
373
-                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
-                        array('dashicons'), EVENT_ESPRESSO_VERSION);
375
-                }
376
-                wp_enqueue_style('espresso_default');
377
-
378
-                if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
379
-                    wp_register_style('espresso_style',
380
-                        get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
381
-                        array('dashicons', 'espresso_default'));
382
-                } else {
383
-                    wp_register_style('espresso_style',
384
-                        EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
385
-                        array('dashicons', 'espresso_default'));
386
-                }
387
-
388
-            }
389
-
390
-        }
391
-
392
-        // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
393
-        if (apply_filters('FHEE_load_js', false)) {
394
-
395
-            wp_enqueue_script('jquery');
396
-            //let's make sure that all required scripts have been setup
397
-            if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
398
-                $msg = sprintf(
399
-                    __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
400
-                        'event_espresso'),
401
-                    '<em><br />',
402
-                    '</em>'
403
-                );
404
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
405
-            }
406
-            // load core js
407
-            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
408
-                EVENT_ESPRESSO_VERSION, true);
409
-            wp_enqueue_script('espresso_core');
410
-            wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
411
-
412
-        }
413
-
414
-        //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
415
-        if (apply_filters('FHEE_load_qtip', false)) {
416
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
417
-        }
418
-
419
-
420
-        //accounting.js library
421
-        // @link http://josscrowcroft.github.io/accounting.js/
422
-        if (apply_filters('FHEE_load_accounting_js', false)) {
423
-            $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
424
-            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
425
-                array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
426
-            wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
427
-            wp_enqueue_script('ee-accounting');
428
-
429
-            $currency_config = array(
430
-                'currency' => array(
431
-                    'symbol'    => $this->Registry->CFG->currency->sign,
432
-                    'format'    => array(
433
-                        'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
434
-                        'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
435
-                        'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
436
-                    ),
437
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
438
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
439
-                    'precision' => $this->Registry->CFG->currency->dec_plc,
440
-                ),
441
-                'number'   => array(
442
-                    'precision' => 0,
443
-                    'thousand'  => $this->Registry->CFG->currency->thsnds,
444
-                    'decimal'   => $this->Registry->CFG->currency->dec_mrk,
445
-                ),
446
-            );
447
-            wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
448
-        }
449
-
450
-        if ( ! function_exists('wp_head')) {
451
-            $msg = sprintf(
452
-                __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
453
-                    'event_espresso'),
454
-                '<em><br />',
455
-                '</em>'
456
-            );
457
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
458
-        }
459
-        if ( ! function_exists('wp_footer')) {
460
-            $msg = sprintf(
461
-                __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
462
-                    'event_espresso'),
463
-                '<em><br />',
464
-                '</em>'
465
-            );
466
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
-        }
468
-
469
-    }
470
-
471
-
472
-    /**
473
-     *    header_meta_tag
474
-     *
475
-     * @access    public
476
-     * @return    void
477
-     */
478
-    public function header_meta_tag()
479
-    {
480
-        print(
481
-            apply_filters(
482
-                'FHEE__EE_Front_Controller__header_meta_tag',
483
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
484
-        );
485
-
486
-        //let's exclude all event type taxonomy term archive pages from search engine indexing
487
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
488
-        //also exclude all critical pages from indexing
489
-        if (
490
-            (
491
-                is_tax('espresso_event_type')
492
-                && get_option( 'blog_public' ) !== '0'
493
-            )
494
-            || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
495
-        ) {
496
-            print(
497
-                apply_filters(
498
-                    'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
499
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
500
-                )
501
-            );
502
-        }
503
-    }
504
-
505
-
506
-
507
-    /**
508
-     * wp_print_scripts
509
-     *
510
-     * @return void
511
-     */
512
-    public function wp_print_scripts()
513
-    {
514
-        global $post;
515
-        if (
516
-            get_post_type() === 'espresso_events' 
517
-            && is_singular() 
518
-            && isset($post->EE_Event)
519
-            && $post->EE_Event instanceof EE_Event
520
-        ) {
521
-            \EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
522
-        }
523
-    }
524
-
525
-
526
-
527
-
528
-    /***********************************************        THE_CONTENT FILTER HOOK         **********************************************
29
+	/**
30
+	 * @var string $_template_path
31
+	 */
32
+	private $_template_path;
33
+
34
+	/**
35
+	 * @var string $_template
36
+	 */
37
+	private $_template;
38
+
39
+	/**
40
+	 * @type EE_Registry $Registry
41
+	 */
42
+	protected $Registry;
43
+
44
+	/**
45
+	 * @type EE_Request_Handler $Request_Handler
46
+	 */
47
+	protected $Request_Handler;
48
+
49
+	/**
50
+	 * @type EE_Module_Request_Router $Module_Request_Router
51
+	 */
52
+	protected $Module_Request_Router;
53
+
54
+
55
+	/**
56
+	 *    class constructor
57
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
58
+	 *
59
+	 * @access    public
60
+	 * @param \EE_Registry              $Registry
61
+	 * @param \EE_Request_Handler       $Request_Handler
62
+	 * @param \EE_Module_Request_Router $Module_Request_Router
63
+	 */
64
+	public function __construct(
65
+		EE_Registry $Registry,
66
+		EE_Request_Handler $Request_Handler,
67
+		EE_Module_Request_Router $Module_Request_Router
68
+	) {
69
+		$this->Registry              = $Registry;
70
+		$this->Request_Handler       = $Request_Handler;
71
+		$this->Module_Request_Router = $Module_Request_Router;
72
+		// determine how to integrate WP_Query with the EE models
73
+		add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
74
+		// load other resources and begin to actually run shortcodes and modules
75
+		add_action('wp_loaded', array($this, 'wp_loaded'), 5);
76
+		// analyse the incoming WP request
77
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
78
+		// process request with module factory
79
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
80
+		// before headers sent
81
+		add_action('wp', array($this, 'wp'), 5);
82
+		// after headers sent but before any markup is output,
83
+		// primarily used to process any content shortcodes
84
+		add_action('get_header', array($this, 'get_header'));
85
+		// load css and js
86
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1);
87
+		// header
88
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
89
+		add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
90
+		add_filter('template_include', array($this, 'template_include'), 1);
91
+		// display errors
92
+		add_action('loop_start', array($this, 'display_errors'), 2);
93
+		// the content
94
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
95
+		//exclude our private cpt comments
96
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
97
+		//make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
98
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
99
+		// action hook EE
100
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
101
+		// for checking that browser cookies are enabled
102
+		if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
103
+			setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/');
104
+		}
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return EE_Request_Handler
110
+	 */
111
+	public function Request_Handler()
112
+	{
113
+		return $this->Request_Handler;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return EE_Module_Request_Router
119
+	 */
120
+	public function Module_Request_Router()
121
+	{
122
+		return $this->Module_Request_Router;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * @return LegacyShortcodesManager
129
+	 */
130
+	public function getLegacyShortcodesManager()
131
+	{
132
+		return EE_Config::getLegacyShortcodesManager();
133
+	}
134
+
135
+
136
+
137
+
138
+
139
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
140
+
141
+
142
+
143
+	/**
144
+	 * filter_wp_comments
145
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
146
+	 * widgets/queries done on frontend
147
+	 *
148
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
149
+	 * @return array array of comment clauses with modifications.
150
+	 */
151
+	public function filter_wp_comments($clauses)
152
+	{
153
+		global $wpdb;
154
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
155
+			$cpts = EE_Register_CPTs::get_private_CPTs();
156
+			foreach ($cpts as $cpt => $details) {
157
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
158
+			}
159
+		}
160
+		return $clauses;
161
+	}
162
+
163
+
164
+	/**
165
+	 *    employ_CPT_Strategy
166
+	 *
167
+	 * @access    public
168
+	 * @return    void
169
+	 */
170
+	public function employ_CPT_Strategy()
171
+	{
172
+		if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
173
+			$this->Registry->load_core('CPT_Strategy');
174
+		}
175
+	}
176
+
177
+
178
+	/**
179
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
180
+	 *
181
+	 * @param  string $url incoming url
182
+	 * @return string         final assembled url
183
+	 */
184
+	public function maybe_force_admin_ajax_ssl($url)
185
+	{
186
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
187
+			$url = str_replace('http://', 'https://', $url);
188
+		}
189
+		return $url;
190
+	}
191
+
192
+
193
+
194
+
195
+
196
+
197
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
198
+
199
+
200
+	/**
201
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
202
+	 *    default priority init phases have run
203
+	 *
204
+	 * @access    public
205
+	 * @return    void
206
+	 */
207
+	public function wp_loaded()
208
+	{
209
+	}
210
+
211
+
212
+
213
+
214
+
215
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
216
+	/**
217
+	 *    _get_request
218
+	 *
219
+	 * @access public
220
+	 * @param WP $WP
221
+	 * @return void
222
+	 */
223
+	public function get_request(WP $WP)
224
+	{
225
+		do_action('AHEE__EE_Front_Controller__get_request__start');
226
+		$this->Request_Handler->parse_request($WP);
227
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
234
+	 *
235
+	 * @access    public
236
+	 * @param   WP_Query $WP_Query
237
+	 * @return    void
238
+	 */
239
+	public function pre_get_posts($WP_Query)
240
+	{
241
+		// only load Module_Request_Router if this is the main query
242
+		if (
243
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
244
+			&& $WP_Query->is_main_query()
245
+		) {
246
+			// cycle thru module routes
247
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
248
+				// determine module and method for route
249
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
250
+				if ($module instanceof EED_Module) {
251
+					// get registered view for route
252
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
253
+					// grab module name
254
+					$module_name = $module->module_name();
255
+					// map the module to the module objects
256
+					$this->Registry->modules->{$module_name} = $module;
257
+				}
258
+			}
259
+		}
260
+	}
261
+
262
+
263
+
264
+
265
+
266
+	/***********************************************        WP HOOK         ***********************************************/
267
+
268
+
269
+	/**
270
+	 *    wp - basically last chance to do stuff before headers sent
271
+	 *
272
+	 * @access    public
273
+	 * @return    void
274
+	 */
275
+	public function wp()
276
+	{
277
+	}
278
+
279
+
280
+
281
+	/***********************     GET_HEADER, WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK     ***********************/
282
+
283
+
284
+
285
+	/**
286
+	 * callback for the WP "get_header" hook point
287
+	 * checks sidebars for EE widgets
288
+	 * loads resources and assets accordingly
289
+	 *
290
+	 * @return void
291
+	 */
292
+	public function get_header()
293
+	{
294
+		global $wp_query;
295
+		if (empty($wp_query->posts)){
296
+			return;
297
+		}
298
+		// if we already know this is an espresso page, then load assets
299
+		$load_assets = $this->Request_Handler->is_espresso_page();
300
+		// if we are already loading assets then just move along, otherwise check for widgets
301
+		$load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
302
+		if ( $load_assets){
303
+			add_filter('FHEE_load_css', '__return_true');
304
+			add_filter('FHEE_load_js', '__return_true');
305
+		}
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * builds list of active widgets then scans active sidebars looking for them
312
+	 * returns true is an EE widget is found in an active sidebar
313
+	 * Please Note: this does NOT mean that the sidebar or widget
314
+	 * is actually in use in a given template, as that is unfortunately not known
315
+	 * until a sidebar and it's widgets are actually loaded
316
+	 *
317
+	 * @return boolean
318
+	 */
319
+	private function espresso_widgets_in_active_sidebars()
320
+	{
321
+		$espresso_widgets = array();
322
+		foreach ($this->Registry->widgets as $widget_class => $widget) {
323
+			$id_base = EspressoWidget::getIdBase($widget_class);
324
+			if (is_active_widget(false, false, $id_base)) {
325
+				$espresso_widgets[] = $id_base;
326
+			}
327
+		}
328
+		$all_sidebar_widgets = wp_get_sidebars_widgets();
329
+		foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) {
330
+			if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
331
+				foreach ($sidebar_widgets as $sidebar_widget) {
332
+					foreach ($espresso_widgets as $espresso_widget) {
333
+						if (strpos($sidebar_widget, $espresso_widget) !== false) {
334
+							return true;
335
+						}
336
+					}
337
+				}
338
+			}
339
+		}
340
+		return false;
341
+	}
342
+
343
+
344
+
345
+
346
+	/**
347
+	 *    wp_enqueue_scripts
348
+	 *
349
+	 * @access    public
350
+	 * @return    void
351
+	 */
352
+	public function wp_enqueue_scripts()
353
+	{
354
+		// css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_css', '__return_false' );
355
+		if (apply_filters('FHEE_load_css', false)) {
356
+
357
+			$this->Registry->CFG->template_settings->enable_default_style = true;
358
+			//Load the ThemeRoller styles if enabled
359
+			if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) {
360
+
361
+				//Load custom style sheet if available
362
+				if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
363
+					wp_register_style('espresso_custom_css',
364
+						EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
365
+						EVENT_ESPRESSO_VERSION);
366
+					wp_enqueue_style('espresso_custom_css');
367
+				}
368
+
369
+				if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
370
+					wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
371
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
372
+				} else {
373
+					wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
+						array('dashicons'), EVENT_ESPRESSO_VERSION);
375
+				}
376
+				wp_enqueue_style('espresso_default');
377
+
378
+				if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
379
+					wp_register_style('espresso_style',
380
+						get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
381
+						array('dashicons', 'espresso_default'));
382
+				} else {
383
+					wp_register_style('espresso_style',
384
+						EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
385
+						array('dashicons', 'espresso_default'));
386
+				}
387
+
388
+			}
389
+
390
+		}
391
+
392
+		// js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF  via:  add_filter( 'FHEE_load_js', '__return_false' );
393
+		if (apply_filters('FHEE_load_js', false)) {
394
+
395
+			wp_enqueue_script('jquery');
396
+			//let's make sure that all required scripts have been setup
397
+			if (function_exists('wp_script_is') && ! wp_script_is('jquery')) {
398
+				$msg = sprintf(
399
+					__('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.',
400
+						'event_espresso'),
401
+					'<em><br />',
402
+					'</em>'
403
+				);
404
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
405
+			}
406
+			// load core js
407
+			wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
408
+				EVENT_ESPRESSO_VERSION, true);
409
+			wp_enqueue_script('espresso_core');
410
+			wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
411
+
412
+		}
413
+
414
+		//qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
415
+		if (apply_filters('FHEE_load_qtip', false)) {
416
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
417
+		}
418
+
419
+
420
+		//accounting.js library
421
+		// @link http://josscrowcroft.github.io/accounting.js/
422
+		if (apply_filters('FHEE_load_accounting_js', false)) {
423
+			$acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
424
+			wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
425
+				array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
426
+			wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
427
+			wp_enqueue_script('ee-accounting');
428
+
429
+			$currency_config = array(
430
+				'currency' => array(
431
+					'symbol'    => $this->Registry->CFG->currency->sign,
432
+					'format'    => array(
433
+						'pos'  => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
434
+						'neg'  => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
435
+						'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s',
436
+					),
437
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
438
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
439
+					'precision' => $this->Registry->CFG->currency->dec_plc,
440
+				),
441
+				'number'   => array(
442
+					'precision' => 0,
443
+					'thousand'  => $this->Registry->CFG->currency->thsnds,
444
+					'decimal'   => $this->Registry->CFG->currency->dec_mrk,
445
+				),
446
+			);
447
+			wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
448
+		}
449
+
450
+		if ( ! function_exists('wp_head')) {
451
+			$msg = sprintf(
452
+				__('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
453
+					'event_espresso'),
454
+				'<em><br />',
455
+				'</em>'
456
+			);
457
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
458
+		}
459
+		if ( ! function_exists('wp_footer')) {
460
+			$msg = sprintf(
461
+				__('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.',
462
+					'event_espresso'),
463
+				'<em><br />',
464
+				'</em>'
465
+			);
466
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
+		}
468
+
469
+	}
470
+
471
+
472
+	/**
473
+	 *    header_meta_tag
474
+	 *
475
+	 * @access    public
476
+	 * @return    void
477
+	 */
478
+	public function header_meta_tag()
479
+	{
480
+		print(
481
+			apply_filters(
482
+				'FHEE__EE_Front_Controller__header_meta_tag',
483
+				'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
484
+		);
485
+
486
+		//let's exclude all event type taxonomy term archive pages from search engine indexing
487
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
488
+		//also exclude all critical pages from indexing
489
+		if (
490
+			(
491
+				is_tax('espresso_event_type')
492
+				&& get_option( 'blog_public' ) !== '0'
493
+			)
494
+			|| is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
495
+		) {
496
+			print(
497
+				apply_filters(
498
+					'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
499
+					'<meta name="robots" content="noindex,follow" />' . "\n"
500
+				)
501
+			);
502
+		}
503
+	}
504
+
505
+
506
+
507
+	/**
508
+	 * wp_print_scripts
509
+	 *
510
+	 * @return void
511
+	 */
512
+	public function wp_print_scripts()
513
+	{
514
+		global $post;
515
+		if (
516
+			get_post_type() === 'espresso_events' 
517
+			&& is_singular() 
518
+			&& isset($post->EE_Event)
519
+			&& $post->EE_Event instanceof EE_Event
520
+		) {
521
+			\EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
522
+		}
523
+	}
524
+
525
+
526
+
527
+
528
+	/***********************************************        THE_CONTENT FILTER HOOK         **********************************************
529 529
 
530 530
 
531 531
 
@@ -536,99 +536,99 @@  discard block
 block discarded – undo
536 536
     //  * @param   $the_content
537 537
     //  * @return    string
538 538
     //  */
539
-    // public function the_content( $the_content ) {
540
-    // 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
541
-    // 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
542
-    // 	}
543
-    // 	return $the_content;
544
-    // }
545
-
546
-
547
-
548
-    /***********************************************        WP_FOOTER         ***********************************************/
549
-
550
-
551
-    /**
552
-     * display_errors
553
-     *
554
-     * @access public
555
-     * @return void
556
-     */
557
-    public function display_errors()
558
-    {
559
-        static $shown_already = false;
560
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
561
-        if (
562
-            ! $shown_already
563
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
564
-            && is_main_query()
565
-            && ! is_feed()
566
-            && in_the_loop()
567
-            && $this->Request_Handler->is_espresso_page()
568
-        ) {
569
-            echo EE_Error::get_notices();
570
-            $shown_already = true;
571
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
572
-        }
573
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
574
-    }
575
-
576
-
577
-
578
-
579
-
580
-    /***********************************************        UTILITIES         ***********************************************/
581
-    /**
582
-     *    template_include
583
-     *
584
-     * @access    public
585
-     * @param   string $template_include_path
586
-     * @return    string
587
-     */
588
-    public function template_include($template_include_path = null)
589
-    {
590
-        if ($this->Request_Handler->is_espresso_page()) {
591
-            $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
592
-            $template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
593
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
594
-            $this->_template      = basename($this->_template_path);
595
-            return $this->_template_path;
596
-        }
597
-        return $template_include_path;
598
-    }
599
-
600
-
601
-    /**
602
-     *    get_selected_template
603
-     *
604
-     * @access    public
605
-     * @param bool $with_path
606
-     * @return    string
607
-     */
608
-    public function get_selected_template($with_path = false)
609
-    {
610
-        return $with_path ? $this->_template_path : $this->_template;
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * @deprecated 4.9.26
617
-     * @param string $shortcode_class
618
-     * @param \WP    $wp
619
-     */
620
-    public function initialize_shortcode($shortcode_class = '', WP $wp = null)
621
-    {
622
-        \EE_Error::doing_it_wrong(
623
-            __METHOD__,
624
-            __(
625
-                'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
626
-                'event_espresso'
627
-            ),
628
-            '4.9.26'
629
-        );
630
-        $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
631
-    }
539
+	// public function the_content( $the_content ) {
540
+	// 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
541
+	// 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
542
+	// 	}
543
+	// 	return $the_content;
544
+	// }
545
+
546
+
547
+
548
+	/***********************************************        WP_FOOTER         ***********************************************/
549
+
550
+
551
+	/**
552
+	 * display_errors
553
+	 *
554
+	 * @access public
555
+	 * @return void
556
+	 */
557
+	public function display_errors()
558
+	{
559
+		static $shown_already = false;
560
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
561
+		if (
562
+			! $shown_already
563
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
564
+			&& is_main_query()
565
+			&& ! is_feed()
566
+			&& in_the_loop()
567
+			&& $this->Request_Handler->is_espresso_page()
568
+		) {
569
+			echo EE_Error::get_notices();
570
+			$shown_already = true;
571
+			EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
572
+		}
573
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
574
+	}
575
+
576
+
577
+
578
+
579
+
580
+	/***********************************************        UTILITIES         ***********************************************/
581
+	/**
582
+	 *    template_include
583
+	 *
584
+	 * @access    public
585
+	 * @param   string $template_include_path
586
+	 * @return    string
587
+	 */
588
+	public function template_include($template_include_path = null)
589
+	{
590
+		if ($this->Request_Handler->is_espresso_page()) {
591
+			$this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
592
+			$template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
593
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
594
+			$this->_template      = basename($this->_template_path);
595
+			return $this->_template_path;
596
+		}
597
+		return $template_include_path;
598
+	}
599
+
600
+
601
+	/**
602
+	 *    get_selected_template
603
+	 *
604
+	 * @access    public
605
+	 * @param bool $with_path
606
+	 * @return    string
607
+	 */
608
+	public function get_selected_template($with_path = false)
609
+	{
610
+		return $with_path ? $this->_template_path : $this->_template;
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * @deprecated 4.9.26
617
+	 * @param string $shortcode_class
618
+	 * @param \WP    $wp
619
+	 */
620
+	public function initialize_shortcode($shortcode_class = '', WP $wp = null)
621
+	{
622
+		\EE_Error::doing_it_wrong(
623
+			__METHOD__,
624
+			__(
625
+				'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
626
+				'event_espresso'
627
+			),
628
+			'4.9.26'
629
+		);
630
+		$this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
631
+	}
632 632
 
633 633
 }
634 634
 // End of file EE_Front_Controller.core.php
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         do_action('AHEE__EE_Front_Controller__construct__done', $this);
101 101
         // for checking that browser cookies are enabled
102 102
         if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) {
103
-            setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/');
103
+            setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/');
104 104
         }
105 105
     }
106 106
 
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
     public function get_header()
293 293
     {
294 294
         global $wp_query;
295
-        if (empty($wp_query->posts)){
295
+        if (empty($wp_query->posts)) {
296 296
             return;
297 297
         }
298 298
         // if we already know this is an espresso page, then load assets
299 299
         $load_assets = $this->Request_Handler->is_espresso_page();
300 300
         // if we are already loading assets then just move along, otherwise check for widgets
301 301
         $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
302
-        if ( $load_assets){
302
+        if ($load_assets) {
303 303
             add_filter('FHEE_load_css', '__return_true');
304 304
             add_filter('FHEE_load_js', '__return_true');
305 305
         }
@@ -361,27 +361,27 @@  discard block
 block discarded – undo
361 361
                 //Load custom style sheet if available
362 362
                 if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) {
363 363
                     wp_register_style('espresso_custom_css',
364
-                        EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet,
364
+                        EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->Registry->CFG->template_settings->custom_style_sheet,
365 365
                         EVENT_ESPRESSO_VERSION);
366 366
                     wp_enqueue_style('espresso_custom_css');
367 367
                 }
368 368
 
369
-                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) {
370
-                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css',
369
+                if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')) {
370
+                    wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css',
371 371
                         array('dashicons'), EVENT_ESPRESSO_VERSION);
372 372
                 } else {
373
-                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
373
+                    wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
374 374
                         array('dashicons'), EVENT_ESPRESSO_VERSION);
375 375
                 }
376 376
                 wp_enqueue_style('espresso_default');
377 377
 
378
-                if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) {
378
+                if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'style.css')) {
379 379
                     wp_register_style('espresso_style',
380
-                        get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css',
380
+                        get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'style.css',
381 381
                         array('dashicons', 'espresso_default'));
382 382
                 } else {
383 383
                     wp_register_style('espresso_style',
384
-                        EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css',
384
+                        EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'style.css',
385 385
                         array('dashicons', 'espresso_default'));
386 386
                 }
387 387
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
                 EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
405 405
             }
406 406
             // load core js
407
-            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'),
407
+            wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'),
408 408
                 EVENT_ESPRESSO_VERSION, true);
409 409
             wp_enqueue_script('espresso_core');
410 410
             wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
         //accounting.js library
421 421
         // @link http://josscrowcroft.github.io/accounting.js/
422 422
         if (apply_filters('FHEE_load_accounting_js', false)) {
423
-            $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js';
424
-            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
423
+            $acct_js = EE_THIRD_PARTY_URL.'accounting/accounting.js';
424
+            wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
425 425
                 array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true);
426 426
             wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true);
427 427
             wp_enqueue_script('ee-accounting');
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
         print(
481 481
             apply_filters(
482 482
                 'FHEE__EE_Front_Controller__header_meta_tag',
483
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
483
+                '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n")
484 484
         );
485 485
 
486 486
         //let's exclude all event type taxonomy term archive pages from search engine indexing
@@ -489,14 +489,14 @@  discard block
 block discarded – undo
489 489
         if (
490 490
             (
491 491
                 is_tax('espresso_event_type')
492
-                && get_option( 'blog_public' ) !== '0'
492
+                && get_option('blog_public') !== '0'
493 493
             )
494 494
             || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
495 495
         ) {
496 496
             print(
497 497
                 apply_filters(
498 498
                     'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
499
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
499
+                    '<meta name="robots" content="noindex,follow" />'."\n"
500 500
                 )
501 501
             );
502 502
         }
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         ) {
569 569
             echo EE_Error::get_notices();
570 570
             $shown_already = true;
571
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
571
+            EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php');
572 572
         }
573 573
         do_action('AHEE__EE_Front_Controller__display_errors__end');
574 574
     }
Please login to merge, or discard this patch.
core/services/database/TableAnalysis.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class TableAnalysis extends \EE_Base {
18 18
 
19
-    /**
20
-     * The maximum number of characters that can be indexed on a column using utf8mb4 collation,
21
-     * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
22
-     */
23
-    const INDEX_COLUMN_SIZE = 191;
19
+	/**
20
+	 * The maximum number of characters that can be indexed on a column using utf8mb4 collation,
21
+	 * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
22
+	 */
23
+	const INDEX_COLUMN_SIZE = 191;
24 24
 	/**
25 25
 	 * Returns the table name which will definitely have the wpdb prefix on the front,
26 26
 	 * except if it currently has the wpdb->base_prefix on the front, in which case
@@ -111,29 +111,29 @@  discard block
 block discarded – undo
111 111
 
112 112
 
113 113
 
114
-    /**
115
-     * @param $table_name
116
-     * @param $index_name
117
-     * @return array of columns used on that index, Each entry is an object with the following properties {
118
-     *  @type string Table
119
-     *  @type string Non_unique "0" or "1"
120
-     *  @type string Key_name
121
-     *  @type string Seq_in_index
122
-     *  @type string Column_name
123
-     *  @type string Collation
124
-     *  @type string Cardinality
125
-     *  @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing
126
-     *  @type string|null Packed
127
-     *  @type string Null
128
-     *  @type string Index_type
129
-     *  @type string Comment
130
-     *  @type string Index_comment
131
-     * }
132
-     */
114
+	/**
115
+	 * @param $table_name
116
+	 * @param $index_name
117
+	 * @return array of columns used on that index, Each entry is an object with the following properties {
118
+	 *  @type string Table
119
+	 *  @type string Non_unique "0" or "1"
120
+	 *  @type string Key_name
121
+	 *  @type string Seq_in_index
122
+	 *  @type string Column_name
123
+	 *  @type string Collation
124
+	 *  @type string Cardinality
125
+	 *  @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing
126
+	 *  @type string|null Packed
127
+	 *  @type string Null
128
+	 *  @type string Index_type
129
+	 *  @type string Comment
130
+	 *  @type string Index_comment
131
+	 * }
132
+	 */
133 133
 	public function showIndexes($table_name, $index_name){
134
-	    global $wpdb;
135
-        $table_name = $this->ensureTableNameHasPrefix($table_name);
136
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
137
-        return $wpdb->get_results($index_exists_query);
138
-    }
134
+		global $wpdb;
135
+		$table_name = $this->ensureTableNameHasPrefix($table_name);
136
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
137
+		return $wpdb->get_results($index_exists_query);
138
+	}
139 139
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketDetails.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -17,198 +17,198 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @var \EE_Ticket $ticket
22
-     */
23
-    protected $ticket;
24
-
25
-    /**
26
-     * @var \EE_Ticket_Selector_Config $template_settings
27
-     */
28
-    protected $template_settings;
29
-
30
-    /**
31
-     * @var string $date_format
32
-     */
33
-    protected $date_format;
34
-
35
-    /**
36
-     * @var string $time_format
37
-     */
38
-    protected $time_format;
39
-
40
-    /**
41
-     * @var boolean $event_is_expired
42
-     */
43
-    protected $event_is_expired;
44
-
45
-
46
-
47
-    /**
48
-     * TicketDetails constructor.
49
-     *
50
-     * @param \EE_Ticket                 $ticket
51
-     * @param \EE_Ticket_Selector_Config $template_settings
52
-     * @param array                      $template_args
53
-     */
54
-    public function __construct(
55
-        \EE_Ticket $ticket,
56
-        \EE_Ticket_Selector_Config $template_settings,
57
-        array $template_args
58
-    )
59
-    {
60
-        $this->ticket            = $ticket;
61
-        $this->template_settings = $template_settings;
62
-        $this->date_format       = $template_args['date_format'];
63
-        $this->time_format       = $template_args['time_format'];
64
-        $this->event_is_expired  = $template_args['event_is_expired'];
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return \EE_Ticket
71
-     */
72
-    public function getTicket()
73
-    {
74
-        return $this->ticket;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function showTicketDetails()
83
-    {
84
-        return $this->template_settings->show_ticket_details;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * @return \EE_Ticket_Selector_Config
91
-     */
92
-    public function getTemplateSettings()
93
-    {
94
-        return $this->template_settings;
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * @return string
101
-     */
102
-    public function getDateFormat()
103
-    {
104
-        return $this->date_format;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function getTimeFormat()
113
-    {
114
-        return $this->time_format;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function getShowHideLinks()
123
-    {
124
-        if ( ! $this->showTicketDetails()) {
125
-            return '';
126
-        }
127
-        return \EEH_HTML::link(
128
-            '',
129
-            sprintf(__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
130
-            esc_attr(
131
-                apply_filters(
132
-                    'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
133
-                    __('click to show additional ticket details', 'event_espresso')
134
-                )
135
-            ),
136
-            "display-{$this->cssId()}",
137
-            'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
138
-            '',
139
-            'rel="' . $this->cssId() . '"'
140
-        ) . \EEH_HTML::link(
141
-            '',
142
-            sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
143
-            esc_attr(
144
-                apply_filters(
145
-                    'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
146
-                    __('click to hide additional ticket details', 'event_espresso')
147
-                )
148
-            ),
149
-            "hide-{$this->cssId()}",
150
-            'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
151
-            'display:none;',
152
-            'rel="' . $this->cssId() . '"'
153
-        );
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * @return string
160
-     */
161
-    public function cssId()
162
-    {
163
-        return apply_filters(
164
-            'FHEE__ticket_selector_chart_template__ticket_details_css_id',
165
-            "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
166
-        );
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param float $ticket_price
173
-     * @param int   $remaining
174
-     * @param int   $cols
175
-     * @return string
176
-     */
177
-    public function display(
178
-        $ticket_price = 0.00,
179
-        $remaining,
180
-        $cols = 2
181
-    ) {
182
-        $template_args = array();
183
-        $template_args['ticket'] = $this->ticket;
184
-        $template_args['ticket_price'] = $ticket_price;
185
-        $template_args['remaining'] = $remaining;
186
-        $template_args['cols'] = $cols;
187
-        $template_args['show_ticket_details'] = $this->template_settings->show_ticket_details;
188
-        $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
189
-        $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
190
-        $template_args['ticket_details_css_id'] = $this->cssId();
191
-        $template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters(
192
-            'FHEE__ticket_selector_chart_template__display_ticket_price_details',
193
-            true
194
-        );
195
-        $template_args['price_breakdown_heading'] = apply_filters(
196
-            'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
197
-            esc_html__('Price', 'event_espresso')
198
-        );
199
-        $template_args['date_format'] = $this->date_format;
200
-        $template_args['time_format'] = $this->time_format;
201
-        $template_args['event_is_expired'] = $this->event_is_expired;
202
-
203
-        return \EEH_Template::locate_template(
204
-            apply_filters(
205
-                'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
206
-                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
207
-                $this->ticket
208
-            ),
209
-            $template_args
210
-        );
211
-    }
20
+	/**
21
+	 * @var \EE_Ticket $ticket
22
+	 */
23
+	protected $ticket;
24
+
25
+	/**
26
+	 * @var \EE_Ticket_Selector_Config $template_settings
27
+	 */
28
+	protected $template_settings;
29
+
30
+	/**
31
+	 * @var string $date_format
32
+	 */
33
+	protected $date_format;
34
+
35
+	/**
36
+	 * @var string $time_format
37
+	 */
38
+	protected $time_format;
39
+
40
+	/**
41
+	 * @var boolean $event_is_expired
42
+	 */
43
+	protected $event_is_expired;
44
+
45
+
46
+
47
+	/**
48
+	 * TicketDetails constructor.
49
+	 *
50
+	 * @param \EE_Ticket                 $ticket
51
+	 * @param \EE_Ticket_Selector_Config $template_settings
52
+	 * @param array                      $template_args
53
+	 */
54
+	public function __construct(
55
+		\EE_Ticket $ticket,
56
+		\EE_Ticket_Selector_Config $template_settings,
57
+		array $template_args
58
+	)
59
+	{
60
+		$this->ticket            = $ticket;
61
+		$this->template_settings = $template_settings;
62
+		$this->date_format       = $template_args['date_format'];
63
+		$this->time_format       = $template_args['time_format'];
64
+		$this->event_is_expired  = $template_args['event_is_expired'];
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return \EE_Ticket
71
+	 */
72
+	public function getTicket()
73
+	{
74
+		return $this->ticket;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function showTicketDetails()
83
+	{
84
+		return $this->template_settings->show_ticket_details;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * @return \EE_Ticket_Selector_Config
91
+	 */
92
+	public function getTemplateSettings()
93
+	{
94
+		return $this->template_settings;
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * @return string
101
+	 */
102
+	public function getDateFormat()
103
+	{
104
+		return $this->date_format;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function getTimeFormat()
113
+	{
114
+		return $this->time_format;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function getShowHideLinks()
123
+	{
124
+		if ( ! $this->showTicketDetails()) {
125
+			return '';
126
+		}
127
+		return \EEH_HTML::link(
128
+			'',
129
+			sprintf(__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
130
+			esc_attr(
131
+				apply_filters(
132
+					'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
133
+					__('click to show additional ticket details', 'event_espresso')
134
+				)
135
+			),
136
+			"display-{$this->cssId()}",
137
+			'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
138
+			'',
139
+			'rel="' . $this->cssId() . '"'
140
+		) . \EEH_HTML::link(
141
+			'',
142
+			sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
143
+			esc_attr(
144
+				apply_filters(
145
+					'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
146
+					__('click to hide additional ticket details', 'event_espresso')
147
+				)
148
+			),
149
+			"hide-{$this->cssId()}",
150
+			'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
151
+			'display:none;',
152
+			'rel="' . $this->cssId() . '"'
153
+		);
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * @return string
160
+	 */
161
+	public function cssId()
162
+	{
163
+		return apply_filters(
164
+			'FHEE__ticket_selector_chart_template__ticket_details_css_id',
165
+			"tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
166
+		);
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param float $ticket_price
173
+	 * @param int   $remaining
174
+	 * @param int   $cols
175
+	 * @return string
176
+	 */
177
+	public function display(
178
+		$ticket_price = 0.00,
179
+		$remaining,
180
+		$cols = 2
181
+	) {
182
+		$template_args = array();
183
+		$template_args['ticket'] = $this->ticket;
184
+		$template_args['ticket_price'] = $ticket_price;
185
+		$template_args['remaining'] = $remaining;
186
+		$template_args['cols'] = $cols;
187
+		$template_args['show_ticket_details'] = $this->template_settings->show_ticket_details;
188
+		$template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
189
+		$template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
190
+		$template_args['ticket_details_css_id'] = $this->cssId();
191
+		$template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters(
192
+			'FHEE__ticket_selector_chart_template__display_ticket_price_details',
193
+			true
194
+		);
195
+		$template_args['price_breakdown_heading'] = apply_filters(
196
+			'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
197
+			esc_html__('Price', 'event_espresso')
198
+		);
199
+		$template_args['date_format'] = $this->date_format;
200
+		$template_args['time_format'] = $this->time_format;
201
+		$template_args['event_is_expired'] = $this->event_is_expired;
202
+
203
+		return \EEH_Template::locate_template(
204
+			apply_filters(
205
+				'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
206
+				TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
207
+				$this->ticket
208
+			),
209
+			$template_args
210
+		);
211
+	}
212 212
 
213 213
 }
214 214
 // End of file TicketDetails.php
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorStandard.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,126 +17,126 @@
 block discarded – undo
17 17
 class TicketSelectorStandard extends TicketSelector
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $date_format
22
-     */
23
-    protected $date_format;
24
-
25
-    /**
26
-     * @var string $time_format
27
-     */
28
-    protected $time_format;
29
-
30
-    /**
31
-     * @var \EE_Ticket_Selector_Config $ticket_selector_config
32
-     */
33
-    protected $ticket_selector_config;
34
-
35
-    /**
36
-     * @var \EE_Tax_Config $tax_config
37
-     */
38
-    protected $tax_config;
39
-
40
-
41
-
42
-    /**
43
-     * TicketSelectorSimple constructor.
44
-     *
45
-     * @param \EE_Event                  $event
46
-     * @param \EE_Ticket[]               $tickets
47
-     * @param int                        $max_attendees
48
-     * @param array                      $template_args
49
-     * @param string                     $date_format
50
-     * @param string                     $time_format
51
-     * @param \EE_Ticket_Selector_Config $ticket_selector_config
52
-     * @param \EE_Tax_Config             $tax_config
53
-     */
54
-    public function __construct(
55
-        \EE_Event $event,
56
-        array $tickets,
57
-        $max_attendees,
58
-        array $template_args,
59
-        $date_format = 'Y-m-d',
60
-        $time_format = 'g:i a',
61
-        \EE_Ticket_Selector_Config $ticket_selector_config = null,
62
-        \EE_Tax_Config $tax_config = null
63
-    ) {
64
-        $this->date_format = $date_format;
65
-        $this->time_format = $time_format;
66
-        // get EE_Ticket_Selector_Config and TicketDetails
67
-        $this->ticket_selector_config = isset (\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)
68
-            ? \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector
69
-            : new \EE_Ticket_Selector_Config();
70
-        // $template_settings->setDatetimeSelectorThreshold(2);
71
-        // \EEH_Debug_Tools::printr($template_settings->getShowDatetimeSelector(), 'getShowDatetimeSelector', __FILE__, __LINE__);
72
-        // \EEH_Debug_Tools::printr($template_settings->getDatetimeSelectorThreshold(), 'getDatetimeSelectorThreshold', __FILE__, __LINE__);
73
-        $this->tax_config = isset (\EE_Registry::instance()->CFG->tax_settings)
74
-            ? \EE_Registry::instance()->CFG->tax_settings
75
-            : new \EE_Tax_Config();
76
-        parent::__construct($event, $tickets, $max_attendees, $template_args);
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * sets any and all template args that are required for this Ticket Selector
83
-     *
84
-     * @return void
85
-     * @throws \EE_Error
86
-     */
87
-    protected function addTemplateArgs()
88
-    {
89
-        $row = 1;
90
-        $ticket_row_html = '';
91
-        $required_ticket_sold_out = false;
92
-        // flag to indicate that at least one taxable ticket has been encountered
93
-        $taxable_tickets = false;
94
-        $datetime_selector = null;
95
-        $this->template_args['datetime_selector'] = '';
96
-        if (
97
-            $this->ticket_selector_config->getShowDatetimeSelector()
98
-            !== \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
99
-        ) {
100
-            $datetime_selector = new DatetimeSelector(
101
-                $this->event,
102
-                $this->tickets,
103
-                $this->ticket_selector_config,
104
-                $this->date_format,
105
-                $this->time_format
106
-            );
107
-            $this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector();
108
-        }
109
-        $total_tickets = count($this->tickets);
110
-        // loop through tickets
111
-        foreach ($this->tickets as $TKT_ID => $ticket) {
112
-            if ($ticket instanceof \EE_Ticket) {
113
-                $cols = 2;
114
-                $taxable_tickets = $ticket->taxable() ? true : $taxable_tickets;
115
-                $ticket_selector_row = new TicketSelectorRowStandard(
116
-                    new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args),
117
-                    $this->tax_config,
118
-                    $total_tickets,
119
-                    $this->max_attendees,
120
-                    $row,
121
-                    $cols,
122
-                    $required_ticket_sold_out,
123
-                    $this->template_args['event_status'],
124
-                    $datetime_selector instanceof DatetimeSelector
125
-                        ? $datetime_selector->getTicketDatetimeClasses($ticket)
126
-                        : ''
127
-                );
128
-                $ticket_row_html .= $ticket_selector_row->getHtml();
129
-                $required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut();
130
-                $row++;
131
-            }
132
-        }
133
-        $this->template_args['row'] = $row;
134
-        $this->template_args['ticket_row_html'] = $ticket_row_html;
135
-        $this->template_args['taxable_tickets'] = $taxable_tickets;
136
-        $this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes;
137
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php';
138
-        remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector');
139
-    }
20
+	/**
21
+	 * @var string $date_format
22
+	 */
23
+	protected $date_format;
24
+
25
+	/**
26
+	 * @var string $time_format
27
+	 */
28
+	protected $time_format;
29
+
30
+	/**
31
+	 * @var \EE_Ticket_Selector_Config $ticket_selector_config
32
+	 */
33
+	protected $ticket_selector_config;
34
+
35
+	/**
36
+	 * @var \EE_Tax_Config $tax_config
37
+	 */
38
+	protected $tax_config;
39
+
40
+
41
+
42
+	/**
43
+	 * TicketSelectorSimple constructor.
44
+	 *
45
+	 * @param \EE_Event                  $event
46
+	 * @param \EE_Ticket[]               $tickets
47
+	 * @param int                        $max_attendees
48
+	 * @param array                      $template_args
49
+	 * @param string                     $date_format
50
+	 * @param string                     $time_format
51
+	 * @param \EE_Ticket_Selector_Config $ticket_selector_config
52
+	 * @param \EE_Tax_Config             $tax_config
53
+	 */
54
+	public function __construct(
55
+		\EE_Event $event,
56
+		array $tickets,
57
+		$max_attendees,
58
+		array $template_args,
59
+		$date_format = 'Y-m-d',
60
+		$time_format = 'g:i a',
61
+		\EE_Ticket_Selector_Config $ticket_selector_config = null,
62
+		\EE_Tax_Config $tax_config = null
63
+	) {
64
+		$this->date_format = $date_format;
65
+		$this->time_format = $time_format;
66
+		// get EE_Ticket_Selector_Config and TicketDetails
67
+		$this->ticket_selector_config = isset (\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)
68
+			? \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector
69
+			: new \EE_Ticket_Selector_Config();
70
+		// $template_settings->setDatetimeSelectorThreshold(2);
71
+		// \EEH_Debug_Tools::printr($template_settings->getShowDatetimeSelector(), 'getShowDatetimeSelector', __FILE__, __LINE__);
72
+		// \EEH_Debug_Tools::printr($template_settings->getDatetimeSelectorThreshold(), 'getDatetimeSelectorThreshold', __FILE__, __LINE__);
73
+		$this->tax_config = isset (\EE_Registry::instance()->CFG->tax_settings)
74
+			? \EE_Registry::instance()->CFG->tax_settings
75
+			: new \EE_Tax_Config();
76
+		parent::__construct($event, $tickets, $max_attendees, $template_args);
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * sets any and all template args that are required for this Ticket Selector
83
+	 *
84
+	 * @return void
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function addTemplateArgs()
88
+	{
89
+		$row = 1;
90
+		$ticket_row_html = '';
91
+		$required_ticket_sold_out = false;
92
+		// flag to indicate that at least one taxable ticket has been encountered
93
+		$taxable_tickets = false;
94
+		$datetime_selector = null;
95
+		$this->template_args['datetime_selector'] = '';
96
+		if (
97
+			$this->ticket_selector_config->getShowDatetimeSelector()
98
+			!== \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
99
+		) {
100
+			$datetime_selector = new DatetimeSelector(
101
+				$this->event,
102
+				$this->tickets,
103
+				$this->ticket_selector_config,
104
+				$this->date_format,
105
+				$this->time_format
106
+			);
107
+			$this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector();
108
+		}
109
+		$total_tickets = count($this->tickets);
110
+		// loop through tickets
111
+		foreach ($this->tickets as $TKT_ID => $ticket) {
112
+			if ($ticket instanceof \EE_Ticket) {
113
+				$cols = 2;
114
+				$taxable_tickets = $ticket->taxable() ? true : $taxable_tickets;
115
+				$ticket_selector_row = new TicketSelectorRowStandard(
116
+					new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args),
117
+					$this->tax_config,
118
+					$total_tickets,
119
+					$this->max_attendees,
120
+					$row,
121
+					$cols,
122
+					$required_ticket_sold_out,
123
+					$this->template_args['event_status'],
124
+					$datetime_selector instanceof DatetimeSelector
125
+						? $datetime_selector->getTicketDatetimeClasses($ticket)
126
+						: ''
127
+				);
128
+				$ticket_row_html .= $ticket_selector_row->getHtml();
129
+				$required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut();
130
+				$row++;
131
+			}
132
+		}
133
+		$this->template_args['row'] = $row;
134
+		$this->template_args['ticket_row_html'] = $ticket_row_html;
135
+		$this->template_args['taxable_tickets'] = $taxable_tickets;
136
+		$this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes;
137
+		$this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php';
138
+		remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector');
139
+	}
140 140
 
141 141
 
142 142
 
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 3 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         }
180 180
         $ticket_selector_row_html = \EEH_HTML::tr(
181 181
             '', '',
182
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
182
+            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} ".espresso_get_object_css_class($this->ticket)
183 183
         );
184 184
         /**
185 185
          * Allow plugins to hook in and abort the generation and display of the contents of this
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
382 382
             $html .= \EEH_Template::format_currency($ticket_price);
383 383
             $html .= $this->ticket->taxable()
384
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
384
+                ? \EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
385 385
                 : '';
386 386
             $html .= '&nbsp;';
387 387
             $html .= \EEH_HTML::span(
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
         // display submit button since we have tickets available
416 416
         add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
417 417
         $this->hidden_input_qty = false;
418
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
419
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
420
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
418
+        $html = '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"';
419
+        $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"';
420
+        $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"';
421 421
         $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
422 422
         $html .= ' title=""/>';
423 423
         return $html;
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
         // display submit button since we have tickets available
439 439
         add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
440 440
         $this->hidden_input_qty = false;
441
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
442
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
441
+        $html = '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"';
442
+        $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"';
443 443
         $html .= ' class="ticket-selector-tbl-qty-slct">';
444 444
         // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
445 445
         if ($min !== 0 && ! $this->ticket->required()) {
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
         }
448 448
         // offer ticket quantities from the min to the max
449 449
         for ($i = $min; $i <= $max; $i++) {
450
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
450
+            $html .= '<option value="'.$i.'">&nbsp;'.$i.'&nbsp;</option>';
451 451
         }
452 452
         $html .= '</select>';
453 453
         return $html;
@@ -466,10 +466,10 @@  discard block
 block discarded – undo
466 466
         $html = '';
467 467
         // depending on group reg we need to change the format for qty
468 468
         if ($this->hidden_input_qty) {
469
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
469
+            $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>';
470 470
         }
471
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
472
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
471
+        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"';
472
+        $html .= ' value="'.$this->ticket->ID().'"/>';
473 473
         return $html;
474 474
     }
475 475
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@
 block discarded – undo
232 232
      * setTicketMinAndMax
233 233
      *
234 234
      * @param int $remaining
235
-     * @return array
235
+     * @return integer[]
236 236
      * @throws EE_Error
237 237
      */
238 238
     protected function setTicketMinAndMax($remaining)
Please login to merge, or discard this patch.
Indentation   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -19,404 +19,404 @@
 block discarded – undo
19 19
 class TicketSelectorRowStandard extends TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var TicketDetails $ticket_details
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var \EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var \EE_Tax_Config $tax_settings
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean $prices_displayed_including_taxes
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int $row
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int $cols
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean $hidden_input_qty
54
-     */
55
-    protected $hidden_input_qty;
56
-
57
-    /**
58
-     * @var string $ticket_datetime_classes
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails  $ticket_details
68
-     * @param \EE_Tax_Config $tax_settings
69
-     * @param int            $total_tickets
70
-     * @param int            $max_atndz
71
-     * @param int            $row
72
-     * @param int            $cols
73
-     * @param boolean        $required_ticket_sold_out
74
-     * @param string         $event_status
75
-     * @param string         $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        \EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_atndz,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket = $ticket_details->getTicket();
91
-        $this->ticket_details = $ticket_details;
92
-        $this->template_settings = $ticket_details->getTemplateSettings();
93
-        $this->tax_settings = $tax_settings;
94
-        $this->total_tickets = $total_tickets;
95
-        $this->max_atndz = $max_atndz;
96
-        $this->row = $row;
97
-        $this->cols = $cols;
98
-        $this->date_format = $ticket_details->getDateFormat();
99
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
100
-        parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * other ticket rows will need to know if a required ticket is sold out,
107
-     * so that they are not offered for sale
108
-     *
109
-     * @return boolean
110
-     */
111
-    public function getRequiredTicketSoldOut()
112
-    {
113
-        return $this->required_ticket_sold_out;
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $min = 0;
137
-        $max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
-            list($min, $max) = $this->setTicketMinAndMax($remaining);
141
-        } else {
142
-            // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
-            $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
-                ? $this->ticket->start_date()
145
-                : $this->required_ticket_sold_out;
146
-        }
147
-        list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
-        list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
-        /**
150
-         * Allow plugins to hook in and abort the generation and display of this row to do
151
-         * something else if they want.
152
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
153
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
-         * current row.
155
-         *
156
-         * @var string|bool
157
-         */
158
-        $ticket_selector_row_html = apply_filters(
159
-            'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
-            false,
161
-            $this->ticket,
162
-            $max,
163
-            $min,
164
-            $this->required_ticket_sold_out,
165
-            $ticket_price,
166
-            $ticket_bundle,
167
-            $ticket_status,
168
-            $status_class
169
-        );
170
-        if ($ticket_selector_row_html !== false) {
171
-            return $ticket_selector_row_html;
172
-        }
173
-        $ticket_selector_row_html = \EEH_HTML::tr(
174
-            '', '',
175
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
-        );
177
-        /**
178
-         * Allow plugins to hook in and abort the generation and display of the contents of this
179
-         * row to do something else if they want.
180
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
181
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
-         * current row.
183
-         *
184
-         * @var string|bool
185
-         */
186
-        $new_row_cells_content = apply_filters(
187
-            'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
-            false,
189
-            $this->ticket,
190
-            $max,
191
-            $min,
192
-            $this->required_ticket_sold_out,
193
-            $ticket_price,
194
-            $ticket_bundle,
195
-            $ticket_status,
196
-            $status_class
197
-        );
198
-        if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . $this->ticketQtyAndIdHiddenInputs()
202
-                   . \EEH_HTML::trx();
203
-        }
204
-        if ($new_row_cells_content !== false) {
205
-            return $ticket_selector_row_html
206
-                   . $new_row_cells_content
207
-                   . \EEH_HTML::trx();
208
-        }
209
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
-
211
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
212
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
-        if (empty($this->ticket_status_display)) {
216
-            if ($this->max_atndz === 1) {
217
-                // only ONE attendee is allowed to register at a time
218
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
-            } else if ($max > 0) {
220
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
-            }
222
-        }
223
-        $ticket_selector_row_html .= $this->ticket_status_display;
224
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
227
-        $ticket_selector_row_html .= \EEH_HTML::trx();
228
-
229
-
230
-        $this->row++;
231
-        return $ticket_selector_row_html;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * setTicketMinAndMax
238
-     *
239
-     * @param int $remaining
240
-     * @return array
241
-     * @throws EE_Error
242
-     */
243
-    protected function setTicketMinAndMax($remaining)
244
-    {
245
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
-        $max = min($remaining, $this->max_atndz);
247
-        // but... we also want to restrict the number of tickets by the ticket max setting,
248
-        // however, the max still can't be higher than what was just set above
249
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
251
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
-        // and if the ticket is required, then make sure that min qty is at least 1
253
-        $min = $this->ticket->required() ? max($min, 1) : $min;
254
-        return array($min, $max);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * getTicketPriceDetails
261
-     *
262
-     * @return array
263
-     * @throws EE_Error
264
-     */
265
-    protected function getTicketPriceDetails()
266
-    {
267
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
-            ? $this->ticket->get_ticket_total_with_taxes()
269
-            : $this->ticket->get_ticket_subtotal();
270
-        $ticket_bundle = false;
271
-        $ticket_min = $this->ticket->min();
272
-        // for ticket bundles, set min and max qty the same
273
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
-            $ticket_price *= $ticket_min;
275
-            $ticket_bundle = true;
276
-        }
277
-        $ticket_price = apply_filters(
278
-            'FHEE__ticket_selector_chart_template__ticket_price',
279
-            $ticket_price,
280
-            $this->ticket
281
-        );
282
-        return array($ticket_price, $ticket_bundle);
283
-    }
284
-
285
-
286
-
287
-
288
-    /**
289
-     * ticketNameTableCell
290
-     *
291
-     * @return string
292
-     * @throws EE_Error
293
-     */
294
-    protected function ticketNameTableCell()
295
-    {
296
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
-        $html .= $this->ticket_details->getShowHideLinks();
299
-        if ($this->ticket->required()) {
300
-            $html .= \EEH_HTML::p(
301
-                    apply_filters(
302
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
303
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
-                    ),
305
-                    '', 'ticket-required-pg'
306
-            );
307
-        }
308
-        $html .= \EEH_HTML::tdx();
309
-        return $html;
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * ticketPriceTableCell
316
-     *
317
-     * @param float $ticket_price
318
-     * @param bool  $ticket_bundle
319
-     * @return string
320
-     * @throws EE_Error
321
-     */
322
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
-    {
324
-        $html = '';
325
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
-            $html .= \EEH_Template::format_currency($ticket_price);
328
-            $html .= $this->ticket->taxable()
329
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
-                : '';
331
-            $html .= '&nbsp;';
332
-            $html .= \EEH_HTML::span(
333
-                $ticket_bundle
334
-                    ? apply_filters(
335
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
-                        __(' / bundle', 'event_espresso')
337
-                    )
338
-                    : apply_filters(
339
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
340
-                        __('', 'event_espresso')
341
-                    ),
342
-                '', 'smaller-text no-bold'
343
-            );
344
-            $html .= '&nbsp;';
345
-            $html .= \EEH_HTML::tdx();
346
-            $this->cols++;
347
-        }
348
-        return $html;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * onlyOneAttendeeCanRegister
355
-     *
356
-     * @return string
357
-     */
358
-    protected function onlyOneAttendeeCanRegister()
359
-    {
360
-        // display submit button since we have tickets available
361
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
-        $this->hidden_input_qty = false;
363
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
-        $html .= ' title=""/>';
368
-        return $html;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * ticketQuantitySelector
375
-     *
376
-     * @param int $min
377
-     * @param int $max
378
-     * @return string
379
-     * @throws EE_Error
380
-     */
381
-    protected function ticketQuantitySelector($min = 0, $max = 0)
382
-    {
383
-        // display submit button since we have tickets available
384
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
-        $this->hidden_input_qty = false;
386
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
389
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
-        if ($min !== 0 && ! $this->ticket->required()) {
391
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
-        }
393
-        // offer ticket quantities from the min to the max
394
-        for ($i = $min; $i <= $max; $i++) {
395
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
-        }
397
-        $html .= '</select>';
398
-        return $html;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * getHiddenInputs
405
-     *
406
-     * @return string
407
-     * @throws EE_Error
408
-     */
409
-    protected function ticketQtyAndIdHiddenInputs()
410
-    {
411
-        $html = '';
412
-        // depending on group reg we need to change the format for qty
413
-        if ($this->hidden_input_qty) {
414
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
-        }
416
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
418
-        return $html;
419
-    }
22
+	/**
23
+	 * @var TicketDetails $ticket_details
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var \EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var \EE_Tax_Config $tax_settings
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean $prices_displayed_including_taxes
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int $row
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int $cols
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean $hidden_input_qty
54
+	 */
55
+	protected $hidden_input_qty;
56
+
57
+	/**
58
+	 * @var string $ticket_datetime_classes
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails  $ticket_details
68
+	 * @param \EE_Tax_Config $tax_settings
69
+	 * @param int            $total_tickets
70
+	 * @param int            $max_atndz
71
+	 * @param int            $row
72
+	 * @param int            $cols
73
+	 * @param boolean        $required_ticket_sold_out
74
+	 * @param string         $event_status
75
+	 * @param string         $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		\EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_atndz,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket = $ticket_details->getTicket();
91
+		$this->ticket_details = $ticket_details;
92
+		$this->template_settings = $ticket_details->getTemplateSettings();
93
+		$this->tax_settings = $tax_settings;
94
+		$this->total_tickets = $total_tickets;
95
+		$this->max_atndz = $max_atndz;
96
+		$this->row = $row;
97
+		$this->cols = $cols;
98
+		$this->date_format = $ticket_details->getDateFormat();
99
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
100
+		parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * other ticket rows will need to know if a required ticket is sold out,
107
+	 * so that they are not offered for sale
108
+	 *
109
+	 * @return boolean
110
+	 */
111
+	public function getRequiredTicketSoldOut()
112
+	{
113
+		return $this->required_ticket_sold_out;
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$min = 0;
137
+		$max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
+			list($min, $max) = $this->setTicketMinAndMax($remaining);
141
+		} else {
142
+			// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
+			$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
+				? $this->ticket->start_date()
145
+				: $this->required_ticket_sold_out;
146
+		}
147
+		list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
+		list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
+		/**
150
+		 * Allow plugins to hook in and abort the generation and display of this row to do
151
+		 * something else if they want.
152
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
153
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
+		 * current row.
155
+		 *
156
+		 * @var string|bool
157
+		 */
158
+		$ticket_selector_row_html = apply_filters(
159
+			'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
+			false,
161
+			$this->ticket,
162
+			$max,
163
+			$min,
164
+			$this->required_ticket_sold_out,
165
+			$ticket_price,
166
+			$ticket_bundle,
167
+			$ticket_status,
168
+			$status_class
169
+		);
170
+		if ($ticket_selector_row_html !== false) {
171
+			return $ticket_selector_row_html;
172
+		}
173
+		$ticket_selector_row_html = \EEH_HTML::tr(
174
+			'', '',
175
+			"tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
+		);
177
+		/**
178
+		 * Allow plugins to hook in and abort the generation and display of the contents of this
179
+		 * row to do something else if they want.
180
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
181
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
+		 * current row.
183
+		 *
184
+		 * @var string|bool
185
+		 */
186
+		$new_row_cells_content = apply_filters(
187
+			'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
+			false,
189
+			$this->ticket,
190
+			$max,
191
+			$min,
192
+			$this->required_ticket_sold_out,
193
+			$ticket_price,
194
+			$ticket_bundle,
195
+			$ticket_status,
196
+			$status_class
197
+		);
198
+		if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . $this->ticketQtyAndIdHiddenInputs()
202
+				   . \EEH_HTML::trx();
203
+		}
204
+		if ($new_row_cells_content !== false) {
205
+			return $ticket_selector_row_html
206
+				   . $new_row_cells_content
207
+				   . \EEH_HTML::trx();
208
+		}
209
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
+
211
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
212
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
+		if (empty($this->ticket_status_display)) {
216
+			if ($this->max_atndz === 1) {
217
+				// only ONE attendee is allowed to register at a time
218
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
+			} else if ($max > 0) {
220
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
+			}
222
+		}
223
+		$ticket_selector_row_html .= $this->ticket_status_display;
224
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
227
+		$ticket_selector_row_html .= \EEH_HTML::trx();
228
+
229
+
230
+		$this->row++;
231
+		return $ticket_selector_row_html;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * setTicketMinAndMax
238
+	 *
239
+	 * @param int $remaining
240
+	 * @return array
241
+	 * @throws EE_Error
242
+	 */
243
+	protected function setTicketMinAndMax($remaining)
244
+	{
245
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
+		$max = min($remaining, $this->max_atndz);
247
+		// but... we also want to restrict the number of tickets by the ticket max setting,
248
+		// however, the max still can't be higher than what was just set above
249
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
251
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
+		// and if the ticket is required, then make sure that min qty is at least 1
253
+		$min = $this->ticket->required() ? max($min, 1) : $min;
254
+		return array($min, $max);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * getTicketPriceDetails
261
+	 *
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 */
265
+	protected function getTicketPriceDetails()
266
+	{
267
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
+			? $this->ticket->get_ticket_total_with_taxes()
269
+			: $this->ticket->get_ticket_subtotal();
270
+		$ticket_bundle = false;
271
+		$ticket_min = $this->ticket->min();
272
+		// for ticket bundles, set min and max qty the same
273
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
+			$ticket_price *= $ticket_min;
275
+			$ticket_bundle = true;
276
+		}
277
+		$ticket_price = apply_filters(
278
+			'FHEE__ticket_selector_chart_template__ticket_price',
279
+			$ticket_price,
280
+			$this->ticket
281
+		);
282
+		return array($ticket_price, $ticket_bundle);
283
+	}
284
+
285
+
286
+
287
+
288
+	/**
289
+	 * ticketNameTableCell
290
+	 *
291
+	 * @return string
292
+	 * @throws EE_Error
293
+	 */
294
+	protected function ticketNameTableCell()
295
+	{
296
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
+		$html .= $this->ticket_details->getShowHideLinks();
299
+		if ($this->ticket->required()) {
300
+			$html .= \EEH_HTML::p(
301
+					apply_filters(
302
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
303
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
+					),
305
+					'', 'ticket-required-pg'
306
+			);
307
+		}
308
+		$html .= \EEH_HTML::tdx();
309
+		return $html;
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * ticketPriceTableCell
316
+	 *
317
+	 * @param float $ticket_price
318
+	 * @param bool  $ticket_bundle
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 */
322
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
+	{
324
+		$html = '';
325
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
+			$html .= \EEH_Template::format_currency($ticket_price);
328
+			$html .= $this->ticket->taxable()
329
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
+				: '';
331
+			$html .= '&nbsp;';
332
+			$html .= \EEH_HTML::span(
333
+				$ticket_bundle
334
+					? apply_filters(
335
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
+						__(' / bundle', 'event_espresso')
337
+					)
338
+					: apply_filters(
339
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
340
+						__('', 'event_espresso')
341
+					),
342
+				'', 'smaller-text no-bold'
343
+			);
344
+			$html .= '&nbsp;';
345
+			$html .= \EEH_HTML::tdx();
346
+			$this->cols++;
347
+		}
348
+		return $html;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * onlyOneAttendeeCanRegister
355
+	 *
356
+	 * @return string
357
+	 */
358
+	protected function onlyOneAttendeeCanRegister()
359
+	{
360
+		// display submit button since we have tickets available
361
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
+		$this->hidden_input_qty = false;
363
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
+		$html .= ' title=""/>';
368
+		return $html;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * ticketQuantitySelector
375
+	 *
376
+	 * @param int $min
377
+	 * @param int $max
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 */
381
+	protected function ticketQuantitySelector($min = 0, $max = 0)
382
+	{
383
+		// display submit button since we have tickets available
384
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
+		$this->hidden_input_qty = false;
386
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
389
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
+		if ($min !== 0 && ! $this->ticket->required()) {
391
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
+		}
393
+		// offer ticket quantities from the min to the max
394
+		for ($i = $min; $i <= $max; $i++) {
395
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
+		}
397
+		$html .= '</select>';
398
+		return $html;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * getHiddenInputs
405
+	 *
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 */
409
+	protected function ticketQtyAndIdHiddenInputs()
410
+	{
411
+		$html = '';
412
+		// depending on group reg we need to change the format for qty
413
+		if ($this->hidden_input_qty) {
414
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
+		}
416
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
418
+		return $html;
419
+	}
420 420
 
421 421
 }
422 422
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.