@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * this method will add that "1" into your date regardless of the format. |
945 | 945 | * |
946 | 946 | * @param string $month |
947 | - * @return string |
|
947 | + * @return integer |
|
948 | 948 | */ |
949 | 949 | public static function first_of_month_timestamp($month = '') |
950 | 950 | { |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | /** |
1106 | 1106 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
1107 | 1107 | * |
1108 | - * @param int|WP_User $user_id |
|
1108 | + * @param integer $user_id |
|
1109 | 1109 | * @return string |
1110 | 1110 | */ |
1111 | 1111 | public static function get_user_locale($user_id = 0) |
@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | + |
|
964 | 525 | |
965 | 526 | /** |
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() |
|
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 | + |
|
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() |
|
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 |
@@ -976,135 +976,135 @@ discard block |
||
976 | 976 | } |
977 | 977 | |
978 | 978 | |
979 | - /** |
|
980 | - * ** |
|
981 | - * Gives a nicely-formatted list of timezone strings. |
|
982 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
983 | - * |
|
984 | - * @since 4.9.40.rc.008 |
|
985 | - * @staticvar bool $mo_loaded |
|
986 | - * @staticvar string $locale_loaded |
|
987 | - * @param string $selected_zone Selected timezone. |
|
988 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
989 | - * @return string |
|
990 | - */ |
|
991 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
992 | - { |
|
993 | - static $mo_loaded = false, $locale_loaded = null; |
|
994 | - |
|
995 | - $continents = array( |
|
996 | - 'Africa', |
|
997 | - 'America', |
|
998 | - 'Antarctica', |
|
999 | - 'Arctic', |
|
1000 | - 'Asia', |
|
1001 | - 'Atlantic', |
|
1002 | - 'Australia', |
|
1003 | - 'Europe', |
|
1004 | - 'Indian', |
|
1005 | - 'Pacific', |
|
1006 | - ); |
|
1007 | - |
|
1008 | - // Load translations for continents and cities. |
|
1009 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
1010 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
1011 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
1012 | - unload_textdomain('continents-cities'); |
|
1013 | - load_textdomain('continents-cities', $mofile); |
|
1014 | - $mo_loaded = true; |
|
1015 | - } |
|
1016 | - |
|
1017 | - $zonen = array(); |
|
1018 | - foreach (timezone_identifiers_list() as $zone) { |
|
1019 | - $zone = explode('/', $zone); |
|
1020 | - if (! in_array($zone[0], $continents)) { |
|
1021 | - continue; |
|
1022 | - } |
|
1023 | - |
|
1024 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
1025 | - $exists = array( |
|
1026 | - 0 => (isset($zone[0]) && $zone[0]), |
|
1027 | - 1 => (isset($zone[1]) && $zone[1]), |
|
1028 | - 2 => (isset($zone[2]) && $zone[2]), |
|
1029 | - ); |
|
1030 | - $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
1031 | - $exists[4] = ($exists[1] && $exists[3]); |
|
1032 | - $exists[5] = ($exists[2] && $exists[3]); |
|
1033 | - |
|
1034 | - $zonen[] = array( |
|
1035 | - 'continent' => ($exists[0] ? $zone[0] : ''), |
|
1036 | - 'city' => ($exists[1] ? $zone[1] : ''), |
|
1037 | - 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
1038 | - 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
1039 | - 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
1040 | - 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
1041 | - ); |
|
1042 | - } |
|
1043 | - usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
1044 | - |
|
1045 | - $structure = array(); |
|
1046 | - |
|
1047 | - if (empty($selected_zone)) { |
|
1048 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
1049 | - } |
|
1050 | - |
|
1051 | - foreach ($zonen as $key => $zone) { |
|
1052 | - // Build value in an array to join later |
|
1053 | - $value = array($zone['continent']); |
|
1054 | - |
|
1055 | - if (empty($zone['city'])) { |
|
1056 | - // It's at the continent level (generally won't happen) |
|
1057 | - $display = $zone['t_continent']; |
|
1058 | - } else { |
|
1059 | - // It's inside a continent group |
|
1060 | - |
|
1061 | - // Continent optgroup |
|
1062 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
1063 | - $label = $zone['t_continent']; |
|
1064 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
1065 | - } |
|
1066 | - |
|
1067 | - // Add the city to the value |
|
1068 | - $value[] = $zone['city']; |
|
1069 | - |
|
1070 | - $display = $zone['t_city']; |
|
1071 | - if (! empty($zone['subcity'])) { |
|
1072 | - // Add the subcity to the value |
|
1073 | - $value[] = $zone['subcity']; |
|
1074 | - $display .= ' - ' . $zone['t_subcity']; |
|
1075 | - } |
|
1076 | - } |
|
1077 | - |
|
1078 | - // Build the value |
|
1079 | - $value = join('/', $value); |
|
1080 | - $selected = ''; |
|
1081 | - if ($value === $selected_zone) { |
|
1082 | - $selected = 'selected="selected" '; |
|
1083 | - } |
|
1084 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
1085 | - |
|
1086 | - // Close continent optgroup |
|
1087 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
1088 | - $structure[] = '</optgroup>'; |
|
1089 | - } |
|
1090 | - } |
|
1091 | - |
|
1092 | - return join("\n", $structure); |
|
1093 | - } |
|
1094 | - |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1098 | - * |
|
1099 | - * @param int|WP_User $user_id |
|
1100 | - * @return string |
|
1101 | - */ |
|
1102 | - public static function get_user_locale($user_id = 0) |
|
1103 | - { |
|
1104 | - if (function_exists('get_user_locale')) { |
|
1105 | - return get_user_locale($user_id); |
|
1106 | - } |
|
1107 | - return get_locale(); |
|
1108 | - } |
|
979 | + /** |
|
980 | + * ** |
|
981 | + * Gives a nicely-formatted list of timezone strings. |
|
982 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
983 | + * |
|
984 | + * @since 4.9.40.rc.008 |
|
985 | + * @staticvar bool $mo_loaded |
|
986 | + * @staticvar string $locale_loaded |
|
987 | + * @param string $selected_zone Selected timezone. |
|
988 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
989 | + * @return string |
|
990 | + */ |
|
991 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
992 | + { |
|
993 | + static $mo_loaded = false, $locale_loaded = null; |
|
994 | + |
|
995 | + $continents = array( |
|
996 | + 'Africa', |
|
997 | + 'America', |
|
998 | + 'Antarctica', |
|
999 | + 'Arctic', |
|
1000 | + 'Asia', |
|
1001 | + 'Atlantic', |
|
1002 | + 'Australia', |
|
1003 | + 'Europe', |
|
1004 | + 'Indian', |
|
1005 | + 'Pacific', |
|
1006 | + ); |
|
1007 | + |
|
1008 | + // Load translations for continents and cities. |
|
1009 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
1010 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
1011 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
1012 | + unload_textdomain('continents-cities'); |
|
1013 | + load_textdomain('continents-cities', $mofile); |
|
1014 | + $mo_loaded = true; |
|
1015 | + } |
|
1016 | + |
|
1017 | + $zonen = array(); |
|
1018 | + foreach (timezone_identifiers_list() as $zone) { |
|
1019 | + $zone = explode('/', $zone); |
|
1020 | + if (! in_array($zone[0], $continents)) { |
|
1021 | + continue; |
|
1022 | + } |
|
1023 | + |
|
1024 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
1025 | + $exists = array( |
|
1026 | + 0 => (isset($zone[0]) && $zone[0]), |
|
1027 | + 1 => (isset($zone[1]) && $zone[1]), |
|
1028 | + 2 => (isset($zone[2]) && $zone[2]), |
|
1029 | + ); |
|
1030 | + $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
1031 | + $exists[4] = ($exists[1] && $exists[3]); |
|
1032 | + $exists[5] = ($exists[2] && $exists[3]); |
|
1033 | + |
|
1034 | + $zonen[] = array( |
|
1035 | + 'continent' => ($exists[0] ? $zone[0] : ''), |
|
1036 | + 'city' => ($exists[1] ? $zone[1] : ''), |
|
1037 | + 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
1038 | + 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
1039 | + 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
1040 | + 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
1041 | + ); |
|
1042 | + } |
|
1043 | + usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
1044 | + |
|
1045 | + $structure = array(); |
|
1046 | + |
|
1047 | + if (empty($selected_zone)) { |
|
1048 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
1049 | + } |
|
1050 | + |
|
1051 | + foreach ($zonen as $key => $zone) { |
|
1052 | + // Build value in an array to join later |
|
1053 | + $value = array($zone['continent']); |
|
1054 | + |
|
1055 | + if (empty($zone['city'])) { |
|
1056 | + // It's at the continent level (generally won't happen) |
|
1057 | + $display = $zone['t_continent']; |
|
1058 | + } else { |
|
1059 | + // It's inside a continent group |
|
1060 | + |
|
1061 | + // Continent optgroup |
|
1062 | + if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
1063 | + $label = $zone['t_continent']; |
|
1064 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
1065 | + } |
|
1066 | + |
|
1067 | + // Add the city to the value |
|
1068 | + $value[] = $zone['city']; |
|
1069 | + |
|
1070 | + $display = $zone['t_city']; |
|
1071 | + if (! empty($zone['subcity'])) { |
|
1072 | + // Add the subcity to the value |
|
1073 | + $value[] = $zone['subcity']; |
|
1074 | + $display .= ' - ' . $zone['t_subcity']; |
|
1075 | + } |
|
1076 | + } |
|
1077 | + |
|
1078 | + // Build the value |
|
1079 | + $value = join('/', $value); |
|
1080 | + $selected = ''; |
|
1081 | + if ($value === $selected_zone) { |
|
1082 | + $selected = 'selected="selected" '; |
|
1083 | + } |
|
1084 | + $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
1085 | + |
|
1086 | + // Close continent optgroup |
|
1087 | + if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
1088 | + $structure[] = '</optgroup>'; |
|
1089 | + } |
|
1090 | + } |
|
1091 | + |
|
1092 | + return join("\n", $structure); |
|
1093 | + } |
|
1094 | + |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1098 | + * |
|
1099 | + * @param int|WP_User $user_id |
|
1100 | + * @return string |
|
1101 | + */ |
|
1102 | + public static function get_user_locale($user_id = 0) |
|
1103 | + { |
|
1104 | + if (function_exists('get_user_locale')) { |
|
1105 | + return get_user_locale($user_id); |
|
1106 | + } |
|
1107 | + return get_locale(); |
|
1108 | + } |
|
1109 | 1109 | |
1110 | 1110 | }// end class EEH_DTT_Helper |
@@ -1,5 +1,5 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | |
@@ -1006,9 +1005,9 @@ discard block |
||
1006 | 1005 | ); |
1007 | 1006 | |
1008 | 1007 | // Load translations for continents and cities. |
1009 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
1008 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
1010 | 1009 | $locale_loaded = $locale ? $locale : get_locale(); |
1011 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
1010 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
1012 | 1011 | unload_textdomain('continents-cities'); |
1013 | 1012 | load_textdomain('continents-cities', $mofile); |
1014 | 1013 | $mo_loaded = true; |
@@ -1017,12 +1016,12 @@ discard block |
||
1017 | 1016 | $zonen = array(); |
1018 | 1017 | foreach (timezone_identifiers_list() as $zone) { |
1019 | 1018 | $zone = explode('/', $zone); |
1020 | - if (! in_array($zone[0], $continents)) { |
|
1019 | + if ( ! in_array($zone[0], $continents)) { |
|
1021 | 1020 | continue; |
1022 | 1021 | } |
1023 | 1022 | |
1024 | 1023 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
1025 | - $exists = array( |
|
1024 | + $exists = array( |
|
1026 | 1025 | 0 => (isset($zone[0]) && $zone[0]), |
1027 | 1026 | 1 => (isset($zone[1]) && $zone[1]), |
1028 | 1027 | 2 => (isset($zone[2]) && $zone[2]), |
@@ -1045,7 +1044,7 @@ discard block |
||
1045 | 1044 | $structure = array(); |
1046 | 1045 | |
1047 | 1046 | if (empty($selected_zone)) { |
1048 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
1047 | + $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>'; |
|
1049 | 1048 | } |
1050 | 1049 | |
1051 | 1050 | foreach ($zonen as $key => $zone) { |
@@ -1059,19 +1058,19 @@ discard block |
||
1059 | 1058 | // It's inside a continent group |
1060 | 1059 | |
1061 | 1060 | // Continent optgroup |
1062 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
1061 | + if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
1063 | 1062 | $label = $zone['t_continent']; |
1064 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
1063 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
1065 | 1064 | } |
1066 | 1065 | |
1067 | 1066 | // Add the city to the value |
1068 | 1067 | $value[] = $zone['city']; |
1069 | 1068 | |
1070 | 1069 | $display = $zone['t_city']; |
1071 | - if (! empty($zone['subcity'])) { |
|
1070 | + if ( ! empty($zone['subcity'])) { |
|
1072 | 1071 | // Add the subcity to the value |
1073 | 1072 | $value[] = $zone['subcity']; |
1074 | - $display .= ' - ' . $zone['t_subcity']; |
|
1073 | + $display .= ' - '.$zone['t_subcity']; |
|
1075 | 1074 | } |
1076 | 1075 | } |
1077 | 1076 | |
@@ -1081,10 +1080,10 @@ discard block |
||
1081 | 1080 | if ($value === $selected_zone) { |
1082 | 1081 | $selected = 'selected="selected" '; |
1083 | 1082 | } |
1084 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
1083 | + $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>"; |
|
1085 | 1084 | |
1086 | 1085 | // Close continent optgroup |
1087 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
1086 | + if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
1088 | 1087 | $structure[] = '</optgroup>'; |
1089 | 1088 | } |
1090 | 1089 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.3.2 |
8 | 8 | */ |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -22,735 +22,735 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * constructor. |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - $this->_caf_hooks(); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
36 | - * |
|
37 | - * @since 4.3.2 |
|
38 | - * |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - private function _caf_hooks() |
|
42 | - { |
|
43 | - add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
44 | - add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'), |
|
45 | - 5, 2); |
|
46 | - add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5, |
|
47 | - 2); |
|
48 | - add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5, |
|
49 | - 2); |
|
50 | - add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5, |
|
51 | - 2); |
|
52 | - add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
53 | - add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5, |
|
54 | - 2); |
|
55 | - add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
56 | - array($this, 'new_default_templates'), 5, 7); |
|
57 | - add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5, |
|
58 | - 2); |
|
59 | - |
|
60 | - //shortcode parsers |
|
61 | - add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
62 | - add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
63 | - add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
64 | - array($this, 'additional_recipient_details_shortcodes'), 5, 2); |
|
65 | - add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
66 | - array($this, 'additional_recipient_details_parser'), 5, 5); |
|
67 | - add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
68 | - array($this, 'additional_primary_registration_details_shortcodes'), 5, 2); |
|
69 | - add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
70 | - array($this, 'additional_primary_registration_details_parser'), 5, 5); |
|
71 | - |
|
72 | - /** |
|
73 | - * @since 4.2.0 |
|
74 | - */ |
|
75 | - add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
76 | - add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
77 | - |
|
78 | - /** |
|
79 | - * @since 4.3.0 |
|
80 | - */ |
|
81 | - //eat our own dog food! |
|
82 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
83 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
84 | - do_action('EE_Brewing_Regular___messages_caf'); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
90 | - * messages system. |
|
91 | - * |
|
92 | - * @param array $dir_ref original array of paths |
|
93 | - * |
|
94 | - * @return array appended paths |
|
95 | - */ |
|
96 | - public function messages_autoload_paths($dir_ref) |
|
97 | - { |
|
98 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
99 | - |
|
100 | - return $dir_ref; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
105 | - { |
|
106 | - $validator_config['attendee_list'] = array( |
|
107 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
108 | - 'required' => array('[ATTENDEE_LIST]') |
|
109 | - ); |
|
110 | - $validator_config['question_list'] = array( |
|
111 | - 'shortcodes' => array('question'), |
|
112 | - 'required' => array('[QUESTION_LIST]') |
|
113 | - ); |
|
114 | - |
|
115 | - return $validator_config; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
120 | - { |
|
121 | - $validator_config['attendee_list'] = array( |
|
122 | - 'shortcodes' => array('attendee', 'question_list'), |
|
123 | - 'required' => array('[ATTENDEE_LIST]') |
|
124 | - ); |
|
125 | - $validator_config['question_list'] = array( |
|
126 | - 'shortcodes' => array('question'), |
|
127 | - 'required' => array('[QUESTION_LIST]') |
|
128 | - ); |
|
129 | - |
|
130 | - return $validator_config; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
135 | - { |
|
136 | - $validator_config['attendee_list'] = array( |
|
137 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
138 | - 'required' => array('[ATTENDEE_LIST]') |
|
139 | - ); |
|
140 | - $validator_config['question_list'] = array( |
|
141 | - 'shortcodes' => array('question'), |
|
142 | - 'required' => array('[QUESTION_LIST]') |
|
143 | - ); |
|
144 | - |
|
145 | - return $validator_config; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
150 | - { |
|
151 | - $template_fields['extra']['content']['question_list'] = array( |
|
152 | - 'input' => 'textarea', |
|
153 | - 'label' => '[QUESTION_LIST]', |
|
154 | - 'type' => 'string', |
|
155 | - 'required' => true, |
|
156 | - 'validation' => true, |
|
157 | - 'format' => '%s', |
|
158 | - 'css_class' => 'large-text', |
|
159 | - 'rows' => '5', |
|
160 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
161 | - ); |
|
162 | - |
|
163 | - return $template_fields; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
168 | - { |
|
169 | - $template_fields['extra']['content']['question_list'] = array( |
|
170 | - 'input' => 'textarea', |
|
171 | - 'label' => '[QUESTION_LIST]', |
|
172 | - 'type' => 'string', |
|
173 | - 'required' => true, |
|
174 | - 'validation' => true, |
|
175 | - 'format' => '%s', |
|
176 | - 'css_class' => 'large-text', |
|
177 | - 'rows' => '5', |
|
178 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
179 | - ); |
|
180 | - |
|
181 | - return $template_fields; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
186 | - { |
|
187 | - $template_fields['extra']['content']['question_list'] = array( |
|
188 | - 'input' => 'textarea', |
|
189 | - 'label' => '[QUESTION_LIST]', |
|
190 | - 'type' => 'string', |
|
191 | - 'required' => true, |
|
192 | - 'validation' => true, |
|
193 | - 'format' => '%s', |
|
194 | - 'css_class' => 'large-text', |
|
195 | - 'rows' => '5', |
|
196 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
197 | - ); |
|
198 | - |
|
199 | - return $template_fields; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - public function new_default_templates( |
|
204 | - $contents, |
|
205 | - $actual_path, |
|
206 | - EE_messenger $messenger, |
|
207 | - EE_message_type $message_type, |
|
208 | - $field, |
|
209 | - $context, |
|
210 | - EE_Messages_Template_Pack $template_pack |
|
211 | - ) { |
|
212 | - |
|
213 | - //we're only modifying templates for the default template pack |
|
214 | - if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
215 | - return $contents; |
|
216 | - } |
|
217 | - |
|
218 | - //the template file name we're replacing contents for. |
|
219 | - $template_file_prefix = $field . '_' . $context; |
|
220 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
221 | - |
|
222 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
223 | - |
|
224 | - if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
25 | + /** |
|
26 | + * constructor. |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + $this->_caf_hooks(); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
36 | + * |
|
37 | + * @since 4.3.2 |
|
38 | + * |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + private function _caf_hooks() |
|
42 | + { |
|
43 | + add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
44 | + add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'), |
|
45 | + 5, 2); |
|
46 | + add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5, |
|
47 | + 2); |
|
48 | + add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5, |
|
49 | + 2); |
|
50 | + add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5, |
|
51 | + 2); |
|
52 | + add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
53 | + add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5, |
|
54 | + 2); |
|
55 | + add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
56 | + array($this, 'new_default_templates'), 5, 7); |
|
57 | + add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5, |
|
58 | + 2); |
|
59 | + |
|
60 | + //shortcode parsers |
|
61 | + add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
62 | + add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
63 | + add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
64 | + array($this, 'additional_recipient_details_shortcodes'), 5, 2); |
|
65 | + add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
66 | + array($this, 'additional_recipient_details_parser'), 5, 5); |
|
67 | + add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
68 | + array($this, 'additional_primary_registration_details_shortcodes'), 5, 2); |
|
69 | + add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
70 | + array($this, 'additional_primary_registration_details_parser'), 5, 5); |
|
71 | + |
|
72 | + /** |
|
73 | + * @since 4.2.0 |
|
74 | + */ |
|
75 | + add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
76 | + add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
77 | + |
|
78 | + /** |
|
79 | + * @since 4.3.0 |
|
80 | + */ |
|
81 | + //eat our own dog food! |
|
82 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
83 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
84 | + do_action('EE_Brewing_Regular___messages_caf'); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
90 | + * messages system. |
|
91 | + * |
|
92 | + * @param array $dir_ref original array of paths |
|
93 | + * |
|
94 | + * @return array appended paths |
|
95 | + */ |
|
96 | + public function messages_autoload_paths($dir_ref) |
|
97 | + { |
|
98 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
99 | + |
|
100 | + return $dir_ref; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
105 | + { |
|
106 | + $validator_config['attendee_list'] = array( |
|
107 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
108 | + 'required' => array('[ATTENDEE_LIST]') |
|
109 | + ); |
|
110 | + $validator_config['question_list'] = array( |
|
111 | + 'shortcodes' => array('question'), |
|
112 | + 'required' => array('[QUESTION_LIST]') |
|
113 | + ); |
|
114 | + |
|
115 | + return $validator_config; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
120 | + { |
|
121 | + $validator_config['attendee_list'] = array( |
|
122 | + 'shortcodes' => array('attendee', 'question_list'), |
|
123 | + 'required' => array('[ATTENDEE_LIST]') |
|
124 | + ); |
|
125 | + $validator_config['question_list'] = array( |
|
126 | + 'shortcodes' => array('question'), |
|
127 | + 'required' => array('[QUESTION_LIST]') |
|
128 | + ); |
|
129 | + |
|
130 | + return $validator_config; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
135 | + { |
|
136 | + $validator_config['attendee_list'] = array( |
|
137 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
138 | + 'required' => array('[ATTENDEE_LIST]') |
|
139 | + ); |
|
140 | + $validator_config['question_list'] = array( |
|
141 | + 'shortcodes' => array('question'), |
|
142 | + 'required' => array('[QUESTION_LIST]') |
|
143 | + ); |
|
144 | + |
|
145 | + return $validator_config; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
150 | + { |
|
151 | + $template_fields['extra']['content']['question_list'] = array( |
|
152 | + 'input' => 'textarea', |
|
153 | + 'label' => '[QUESTION_LIST]', |
|
154 | + 'type' => 'string', |
|
155 | + 'required' => true, |
|
156 | + 'validation' => true, |
|
157 | + 'format' => '%s', |
|
158 | + 'css_class' => 'large-text', |
|
159 | + 'rows' => '5', |
|
160 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
161 | + ); |
|
162 | + |
|
163 | + return $template_fields; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
168 | + { |
|
169 | + $template_fields['extra']['content']['question_list'] = array( |
|
170 | + 'input' => 'textarea', |
|
171 | + 'label' => '[QUESTION_LIST]', |
|
172 | + 'type' => 'string', |
|
173 | + 'required' => true, |
|
174 | + 'validation' => true, |
|
175 | + 'format' => '%s', |
|
176 | + 'css_class' => 'large-text', |
|
177 | + 'rows' => '5', |
|
178 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
179 | + ); |
|
180 | + |
|
181 | + return $template_fields; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
186 | + { |
|
187 | + $template_fields['extra']['content']['question_list'] = array( |
|
188 | + 'input' => 'textarea', |
|
189 | + 'label' => '[QUESTION_LIST]', |
|
190 | + 'type' => 'string', |
|
191 | + 'required' => true, |
|
192 | + 'validation' => true, |
|
193 | + 'format' => '%s', |
|
194 | + 'css_class' => 'large-text', |
|
195 | + 'rows' => '5', |
|
196 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
197 | + ); |
|
198 | + |
|
199 | + return $template_fields; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + public function new_default_templates( |
|
204 | + $contents, |
|
205 | + $actual_path, |
|
206 | + EE_messenger $messenger, |
|
207 | + EE_message_type $message_type, |
|
208 | + $field, |
|
209 | + $context, |
|
210 | + EE_Messages_Template_Pack $template_pack |
|
211 | + ) { |
|
212 | + |
|
213 | + //we're only modifying templates for the default template pack |
|
214 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
215 | + return $contents; |
|
216 | + } |
|
217 | + |
|
218 | + //the template file name we're replacing contents for. |
|
219 | + $template_file_prefix = $field . '_' . $context; |
|
220 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
221 | + |
|
222 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
223 | + |
|
224 | + if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
225 | 225 | |
226 | - switch ($template_file_prefix) { |
|
226 | + switch ($template_file_prefix) { |
|
227 | 227 | |
228 | - case 'question_list_admin' : |
|
229 | - case 'question_list_attendee' : |
|
230 | - case 'question_list_primary_attendee' : |
|
231 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
232 | - $contents = EEH_Template::display_template($path, array(), true); |
|
233 | - break; |
|
228 | + case 'question_list_admin' : |
|
229 | + case 'question_list_attendee' : |
|
230 | + case 'question_list_primary_attendee' : |
|
231 | + $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
232 | + $contents = EEH_Template::display_template($path, array(), true); |
|
233 | + break; |
|
234 | 234 | |
235 | - case 'attendee_list_primary_attendee' : |
|
236 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
237 | - $contents = EEH_Template::display_template($path, array(), true); |
|
238 | - break; |
|
235 | + case 'attendee_list_primary_attendee' : |
|
236 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
237 | + $contents = EEH_Template::display_template($path, array(), true); |
|
238 | + break; |
|
239 | 239 | |
240 | - case 'attendee_list_admin' : |
|
241 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
242 | - $contents = EEH_Template::display_template($path, |
|
243 | - array(), true); |
|
244 | - break; |
|
240 | + case 'attendee_list_admin' : |
|
241 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
242 | + $contents = EEH_Template::display_template($path, |
|
243 | + array(), true); |
|
244 | + break; |
|
245 | 245 | |
246 | - case 'attendee_list_attendee' : |
|
247 | - $contents = ''; |
|
248 | - break; |
|
246 | + case 'attendee_list_attendee' : |
|
247 | + $contents = ''; |
|
248 | + break; |
|
249 | 249 | |
250 | - case 'event_list_attendee' : |
|
251 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
252 | - $contents = EEH_Template::display_template($path, array(), true); |
|
253 | - break; |
|
254 | - } |
|
255 | - } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
256 | - switch ($template_file_prefix) { |
|
250 | + case 'event_list_attendee' : |
|
251 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
252 | + $contents = EEH_Template::display_template($path, array(), true); |
|
253 | + break; |
|
254 | + } |
|
255 | + } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
256 | + switch ($template_file_prefix) { |
|
257 | 257 | |
258 | - case 'content_attendee' : |
|
259 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
260 | - $contents = EEH_Template::display_template($path, array(), true); |
|
261 | - break; |
|
258 | + case 'content_attendee' : |
|
259 | + $path = $base_path . $msg_prefix . 'content.template.php'; |
|
260 | + $contents = EEH_Template::display_template($path, array(), true); |
|
261 | + break; |
|
262 | 262 | |
263 | - case 'newsletter_content_attendee' : |
|
264 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
265 | - $contents = EEH_Template::display_template($path, array(), true); |
|
266 | - break; |
|
263 | + case 'newsletter_content_attendee' : |
|
264 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
265 | + $contents = EEH_Template::display_template($path, array(), true); |
|
266 | + break; |
|
267 | 267 | |
268 | - case 'newsletter_subject_attendee' : |
|
269 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
270 | - $contents = EEH_Template::display_template($path, array(), true); |
|
271 | - break; |
|
272 | - } |
|
273 | - } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
274 | - switch ($template_file_prefix) { |
|
275 | - case 'attendee_list_purchaser' : |
|
276 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
277 | - $contents = EEH_Template::display_template($path, array(), true); |
|
278 | - break; |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - return $contents; |
|
283 | - |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
288 | - { |
|
289 | - //make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
290 | - $include_with = array( |
|
291 | - 'registration', |
|
292 | - 'cancelled_registration', |
|
293 | - 'declined_registration', |
|
294 | - 'not_approved_registration', |
|
295 | - 'payment_declined', |
|
296 | - 'payment_failed', |
|
297 | - 'payment_cancelled', |
|
298 | - 'payment', |
|
299 | - 'payment_reminder', |
|
300 | - 'pending_approval', |
|
301 | - 'registration_summary', |
|
302 | - 'invoice', |
|
303 | - 'receipt' |
|
304 | - ); |
|
305 | - if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
306 | - $contexts = array_keys($msg->get_contexts()); |
|
307 | - foreach ($contexts as $context) { |
|
308 | - $valid_shortcodes[$context][] = 'question_list'; |
|
309 | - $valid_shortcodes[$context][] = 'question'; |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - return $valid_shortcodes; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
318 | - { |
|
319 | - $shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
320 | - 'event_espresso'); |
|
321 | - |
|
322 | - return $shortcodes; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
327 | - { |
|
328 | - |
|
329 | - if (strpos($shortcode, |
|
330 | - '[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations) |
|
331 | - ) { |
|
332 | - return $parsed; |
|
333 | - } |
|
334 | - |
|
335 | - //let's get the question from the code. |
|
336 | - $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
337 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
338 | - |
|
339 | - $registration = $data instanceof EE_Registration ? $data : null; |
|
340 | - $registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
341 | - |
|
342 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
343 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
344 | - |
|
345 | - if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
346 | - return $parsed; |
|
347 | - } |
|
348 | - |
|
349 | - //now let's figure out which question has this text. |
|
350 | - foreach ($aee->questions as $ansid => $question) { |
|
351 | - if ( |
|
352 | - $question instanceof EE_Question |
|
353 | - && trim($question->display_text()) == trim($shortcode) |
|
354 | - && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
355 | - ) { |
|
356 | - return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value', |
|
357 | - 'no_wpautop'); |
|
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - //nothing! |
|
362 | - return $parsed; |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
368 | - * |
|
369 | - * @since 4.2 |
|
370 | - * |
|
371 | - * @param array $shortcodes array of shortcodes and |
|
372 | - * descriptions |
|
373 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
374 | - * |
|
375 | - * @return array array of shortcodes and |
|
376 | - * descriptions |
|
377 | - */ |
|
378 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
379 | - { |
|
380 | - $shortcodes['[DTT_NAME]'] = __('This will be parsed to the Title given for a Datetime', |
|
381 | - 'event_espresso'); |
|
382 | - $shortcodes['[DTT_DESCRIPTION]'] = __('This will be parsed to the description for a Datetime', |
|
383 | - 'event_espresso'); |
|
384 | - $shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
385 | - 'event_espresso'); |
|
386 | - |
|
387 | - return $shortcodes; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Callback for additional shortcodes parser filter used for adding parser for new |
|
393 | - * Datetime shortcodes |
|
394 | - * |
|
395 | - * @since 4.2 |
|
396 | - * |
|
397 | - * @param string $parsed The finished parsed string for the given shortcode. |
|
398 | - * @param string $shortcode The shortcode being parsed. |
|
399 | - * @param object $data The incoming data object for the Shortcode Parser. |
|
400 | - * @param object $extra_data The incoming extra date object for the Shortcode |
|
401 | - * Parser. |
|
402 | - * @param EE_Datetime_Shortcodes $shortcode_parser |
|
403 | - * |
|
404 | - * @return string The new parsed string. |
|
405 | - */ |
|
406 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
407 | - { |
|
408 | - |
|
409 | - if ( ! $data instanceof EE_Datetime) { |
|
410 | - return ''; //get out because we can only parse with the datetime object. |
|
411 | - } |
|
412 | - |
|
413 | - switch ($shortcode) { |
|
414 | - case '[DTT_NAME]' : |
|
415 | - return $data->name(); |
|
416 | - break; |
|
417 | - case '[DTT_DESCRIPTION]' : |
|
418 | - return $data->description(); |
|
419 | - break; |
|
420 | - case '[DTT_NAME_OR_DATES]' : |
|
421 | - return $data->get_dtt_display_name(true); |
|
422 | - break; |
|
423 | - default : |
|
424 | - return $parsed; |
|
425 | - break; |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
431 | - { |
|
432 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
433 | - 'event_espresso'); |
|
434 | - |
|
435 | - return $shortcodes; |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
441 | - * |
|
442 | - * @param string $parsed The original parsed content for the shortcode |
|
443 | - * @param string $shortcode The shortcode being parsed |
|
444 | - * @param array $data The shortcode parser data array |
|
445 | - * @param array $extra_data The shortcode parser extra data array |
|
446 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
447 | - * |
|
448 | - * @return string |
|
449 | - */ |
|
450 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
451 | - { |
|
452 | - |
|
453 | - if (array($data) && ! isset($data['data'])) { |
|
454 | - return $parsed; |
|
455 | - } |
|
456 | - |
|
457 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
458 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
459 | - |
|
460 | - if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
461 | - return $parsed; |
|
462 | - } |
|
463 | - |
|
464 | - switch ($shortcode) { |
|
465 | - case '[RECIPIENT_QUESTION_LIST]' : |
|
466 | - $att = $recipient->att_obj; |
|
467 | - $registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array(); |
|
468 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
469 | - $answers = array(); |
|
268 | + case 'newsletter_subject_attendee' : |
|
269 | + $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
270 | + $contents = EEH_Template::display_template($path, array(), true); |
|
271 | + break; |
|
272 | + } |
|
273 | + } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
274 | + switch ($template_file_prefix) { |
|
275 | + case 'attendee_list_purchaser' : |
|
276 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
277 | + $contents = EEH_Template::display_template($path, array(), true); |
|
278 | + break; |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + return $contents; |
|
283 | + |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
288 | + { |
|
289 | + //make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
290 | + $include_with = array( |
|
291 | + 'registration', |
|
292 | + 'cancelled_registration', |
|
293 | + 'declined_registration', |
|
294 | + 'not_approved_registration', |
|
295 | + 'payment_declined', |
|
296 | + 'payment_failed', |
|
297 | + 'payment_cancelled', |
|
298 | + 'payment', |
|
299 | + 'payment_reminder', |
|
300 | + 'pending_approval', |
|
301 | + 'registration_summary', |
|
302 | + 'invoice', |
|
303 | + 'receipt' |
|
304 | + ); |
|
305 | + if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
306 | + $contexts = array_keys($msg->get_contexts()); |
|
307 | + foreach ($contexts as $context) { |
|
308 | + $valid_shortcodes[$context][] = 'question_list'; |
|
309 | + $valid_shortcodes[$context][] = 'question'; |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + return $valid_shortcodes; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
318 | + { |
|
319 | + $shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
320 | + 'event_espresso'); |
|
321 | + |
|
322 | + return $shortcodes; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
327 | + { |
|
328 | + |
|
329 | + if (strpos($shortcode, |
|
330 | + '[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations) |
|
331 | + ) { |
|
332 | + return $parsed; |
|
333 | + } |
|
334 | + |
|
335 | + //let's get the question from the code. |
|
336 | + $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
337 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
338 | + |
|
339 | + $registration = $data instanceof EE_Registration ? $data : null; |
|
340 | + $registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
341 | + |
|
342 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
343 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
344 | + |
|
345 | + if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
346 | + return $parsed; |
|
347 | + } |
|
348 | + |
|
349 | + //now let's figure out which question has this text. |
|
350 | + foreach ($aee->questions as $ansid => $question) { |
|
351 | + if ( |
|
352 | + $question instanceof EE_Question |
|
353 | + && trim($question->display_text()) == trim($shortcode) |
|
354 | + && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
355 | + ) { |
|
356 | + return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value', |
|
357 | + 'no_wpautop'); |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + //nothing! |
|
362 | + return $parsed; |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
368 | + * |
|
369 | + * @since 4.2 |
|
370 | + * |
|
371 | + * @param array $shortcodes array of shortcodes and |
|
372 | + * descriptions |
|
373 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
374 | + * |
|
375 | + * @return array array of shortcodes and |
|
376 | + * descriptions |
|
377 | + */ |
|
378 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
379 | + { |
|
380 | + $shortcodes['[DTT_NAME]'] = __('This will be parsed to the Title given for a Datetime', |
|
381 | + 'event_espresso'); |
|
382 | + $shortcodes['[DTT_DESCRIPTION]'] = __('This will be parsed to the description for a Datetime', |
|
383 | + 'event_espresso'); |
|
384 | + $shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
385 | + 'event_espresso'); |
|
386 | + |
|
387 | + return $shortcodes; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Callback for additional shortcodes parser filter used for adding parser for new |
|
393 | + * Datetime shortcodes |
|
394 | + * |
|
395 | + * @since 4.2 |
|
396 | + * |
|
397 | + * @param string $parsed The finished parsed string for the given shortcode. |
|
398 | + * @param string $shortcode The shortcode being parsed. |
|
399 | + * @param object $data The incoming data object for the Shortcode Parser. |
|
400 | + * @param object $extra_data The incoming extra date object for the Shortcode |
|
401 | + * Parser. |
|
402 | + * @param EE_Datetime_Shortcodes $shortcode_parser |
|
403 | + * |
|
404 | + * @return string The new parsed string. |
|
405 | + */ |
|
406 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
407 | + { |
|
408 | + |
|
409 | + if ( ! $data instanceof EE_Datetime) { |
|
410 | + return ''; //get out because we can only parse with the datetime object. |
|
411 | + } |
|
412 | + |
|
413 | + switch ($shortcode) { |
|
414 | + case '[DTT_NAME]' : |
|
415 | + return $data->name(); |
|
416 | + break; |
|
417 | + case '[DTT_DESCRIPTION]' : |
|
418 | + return $data->description(); |
|
419 | + break; |
|
420 | + case '[DTT_NAME_OR_DATES]' : |
|
421 | + return $data->get_dtt_display_name(true); |
|
422 | + break; |
|
423 | + default : |
|
424 | + return $parsed; |
|
425 | + break; |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
431 | + { |
|
432 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
433 | + 'event_espresso'); |
|
434 | + |
|
435 | + return $shortcodes; |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
441 | + * |
|
442 | + * @param string $parsed The original parsed content for the shortcode |
|
443 | + * @param string $shortcode The shortcode being parsed |
|
444 | + * @param array $data The shortcode parser data array |
|
445 | + * @param array $extra_data The shortcode parser extra data array |
|
446 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
447 | + * |
|
448 | + * @return string |
|
449 | + */ |
|
450 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
451 | + { |
|
452 | + |
|
453 | + if (array($data) && ! isset($data['data'])) { |
|
454 | + return $parsed; |
|
455 | + } |
|
456 | + |
|
457 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
458 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
459 | + |
|
460 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
461 | + return $parsed; |
|
462 | + } |
|
463 | + |
|
464 | + switch ($shortcode) { |
|
465 | + case '[RECIPIENT_QUESTION_LIST]' : |
|
466 | + $att = $recipient->att_obj; |
|
467 | + $registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array(); |
|
468 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
469 | + $answers = array(); |
|
470 | 470 | |
471 | - $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
472 | - $valid_shortcodes = array('question'); |
|
471 | + $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
472 | + $valid_shortcodes = array('question'); |
|
473 | 473 | |
474 | - //if the context is main_content then get all answers for all registrations on this attendee |
|
475 | - if ($data['data'] instanceof EE_Messages_Addressee) { |
|
474 | + //if the context is main_content then get all answers for all registrations on this attendee |
|
475 | + if ($data['data'] instanceof EE_Messages_Addressee) { |
|
476 | 476 | |
477 | - foreach ($registrations_on_attendee as $reg) { |
|
478 | - if ($reg instanceof EE_Registration) { |
|
479 | - $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
480 | - foreach ($anss as $ans) { |
|
481 | - if ($ans instanceof EE_Answer) { |
|
482 | - $answers[$ans->ID()] = $ans; |
|
483 | - } |
|
484 | - } |
|
485 | - } |
|
486 | - } |
|
487 | - } |
|
477 | + foreach ($registrations_on_attendee as $reg) { |
|
478 | + if ($reg instanceof EE_Registration) { |
|
479 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
480 | + foreach ($anss as $ans) { |
|
481 | + if ($ans instanceof EE_Answer) { |
|
482 | + $answers[$ans->ID()] = $ans; |
|
483 | + } |
|
484 | + } |
|
485 | + } |
|
486 | + } |
|
487 | + } |
|
488 | 488 | |
489 | - //if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
490 | - if ($data['data'] instanceof EE_Event) { |
|
491 | - $event = $data['data']; |
|
492 | - foreach ($registrations_on_attendee as $reg) { |
|
493 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
494 | - $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
495 | - foreach ($anss as $ans) { |
|
496 | - if ($ans instanceof EE_Answer) { |
|
497 | - $answers[$ans->ID()] = $ans; |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
501 | - } |
|
502 | - } |
|
489 | + //if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
490 | + if ($data['data'] instanceof EE_Event) { |
|
491 | + $event = $data['data']; |
|
492 | + foreach ($registrations_on_attendee as $reg) { |
|
493 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
494 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
495 | + foreach ($anss as $ans) { |
|
496 | + if ($ans instanceof EE_Answer) { |
|
497 | + $answers[$ans->ID()] = $ans; |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | + } |
|
502 | + } |
|
503 | 503 | |
504 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
504 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
505 | 505 | |
506 | - //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
507 | - //object on it. |
|
508 | - if ( ! isset( $extra_data['data'] ) ) { |
|
509 | - $extra_data['data'] = $recipient; |
|
510 | - } |
|
506 | + //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
507 | + //object on it. |
|
508 | + if ( ! isset( $extra_data['data'] ) ) { |
|
509 | + $extra_data['data'] = $recipient; |
|
510 | + } |
|
511 | 511 | |
512 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
513 | - $shortcode_parser, |
|
514 | - $questions, |
|
515 | - $answers, |
|
516 | - $template, |
|
517 | - $valid_shortcodes, |
|
518 | - $extra_data |
|
519 | - ); |
|
520 | - break; |
|
512 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
513 | + $shortcode_parser, |
|
514 | + $questions, |
|
515 | + $answers, |
|
516 | + $template, |
|
517 | + $valid_shortcodes, |
|
518 | + $extra_data |
|
519 | + ); |
|
520 | + break; |
|
521 | 521 | |
522 | - default : |
|
523 | - return $parsed; |
|
524 | - break; |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
530 | - { |
|
531 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
532 | - 'event_espresso'); |
|
533 | - |
|
534 | - return $shortcodes; |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
540 | - * |
|
541 | - * @param string $parsed The original parsed content for the shortcode |
|
542 | - * @param string $shortcode The shortcode being parsed |
|
543 | - * @param array $data The shortcode parser data array |
|
544 | - * @param array $extra_data The shortcode parser extra data array |
|
545 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
546 | - * |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - public function additional_primary_registration_details_parser( |
|
550 | - $parsed, |
|
551 | - $shortcode, |
|
552 | - $data, |
|
553 | - $extra_data, |
|
554 | - $shortcode_parser |
|
555 | - ) { |
|
556 | - if (array($data) && ! isset($data['data'])) { |
|
557 | - return $parsed; |
|
558 | - } |
|
559 | - |
|
560 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
561 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
562 | - |
|
563 | - if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
564 | - return $parsed; |
|
565 | - } |
|
566 | - |
|
567 | - switch ($shortcode) { |
|
568 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]' : |
|
569 | - if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
570 | - return ''; |
|
571 | - } |
|
572 | - $registration = $recipient->primary_reg_obj; |
|
573 | - $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
574 | - ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
575 | - : array(); |
|
576 | - if (empty($answers)) { |
|
577 | - return ''; |
|
578 | - } |
|
579 | - $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
580 | - $valid_shortcodes = array('question'); |
|
581 | - $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
582 | - $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
583 | - //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
584 | - //object on it. |
|
585 | - if ( ! isset( $extra_data['data'] ) ){ |
|
586 | - $extra_data['data'] = $recipient; |
|
587 | - } |
|
588 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
589 | - $shortcode_parser, |
|
590 | - $questions, |
|
591 | - $answers, |
|
592 | - $template, |
|
593 | - $valid_shortcodes, |
|
594 | - $extra_data |
|
595 | - ); |
|
596 | - break; |
|
522 | + default : |
|
523 | + return $parsed; |
|
524 | + break; |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
530 | + { |
|
531 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
532 | + 'event_espresso'); |
|
533 | + |
|
534 | + return $shortcodes; |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
540 | + * |
|
541 | + * @param string $parsed The original parsed content for the shortcode |
|
542 | + * @param string $shortcode The shortcode being parsed |
|
543 | + * @param array $data The shortcode parser data array |
|
544 | + * @param array $extra_data The shortcode parser extra data array |
|
545 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
546 | + * |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + public function additional_primary_registration_details_parser( |
|
550 | + $parsed, |
|
551 | + $shortcode, |
|
552 | + $data, |
|
553 | + $extra_data, |
|
554 | + $shortcode_parser |
|
555 | + ) { |
|
556 | + if (array($data) && ! isset($data['data'])) { |
|
557 | + return $parsed; |
|
558 | + } |
|
559 | + |
|
560 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
561 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
562 | + |
|
563 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
564 | + return $parsed; |
|
565 | + } |
|
566 | + |
|
567 | + switch ($shortcode) { |
|
568 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]' : |
|
569 | + if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
570 | + return ''; |
|
571 | + } |
|
572 | + $registration = $recipient->primary_reg_obj; |
|
573 | + $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
574 | + ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
575 | + : array(); |
|
576 | + if (empty($answers)) { |
|
577 | + return ''; |
|
578 | + } |
|
579 | + $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
580 | + $valid_shortcodes = array('question'); |
|
581 | + $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
582 | + $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
583 | + //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
584 | + //object on it. |
|
585 | + if ( ! isset( $extra_data['data'] ) ){ |
|
586 | + $extra_data['data'] = $recipient; |
|
587 | + } |
|
588 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
589 | + $shortcode_parser, |
|
590 | + $questions, |
|
591 | + $answers, |
|
592 | + $template, |
|
593 | + $valid_shortcodes, |
|
594 | + $extra_data |
|
595 | + ); |
|
596 | + break; |
|
597 | 597 | |
598 | - default : |
|
599 | - return $parsed; |
|
600 | - break; |
|
601 | - } |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * Takes care of registering the message types that are only available in caffeinated EE. |
|
607 | - * |
|
608 | - * @since 4.3.2 |
|
609 | - * |
|
610 | - * @return void |
|
611 | - */ |
|
612 | - public function register_caf_message_types() |
|
613 | - { |
|
614 | - //register newsletter message type |
|
615 | - $setup_args = array( |
|
616 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
617 | - 'autoloadpaths' => array( |
|
618 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
619 | - ), |
|
620 | - 'messengers_to_activate_with' => array('email'), |
|
621 | - 'messengers_to_validate_with' => array('email'), |
|
622 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
623 | - ); |
|
624 | - EE_Register_Message_Type::register('newsletter', $setup_args); |
|
625 | - |
|
626 | - //register payment reminder message type |
|
627 | - $setup_args = array( |
|
628 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
629 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
630 | - 'messengers_to_activate_with' => array('email'), |
|
631 | - 'messengers_to_validate_with' => array('email'), |
|
632 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
633 | - ); |
|
634 | - EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
635 | - |
|
636 | - //register payment declined message type |
|
637 | - $setup_args = array( |
|
638 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
639 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
640 | - 'messengers_to_activate_with' => array('email'), |
|
641 | - 'messengers_to_validate_with' => array('email'), |
|
642 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
643 | - ); |
|
644 | - EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
645 | - |
|
646 | - //register registration declined message type |
|
647 | - $setup_args = array( |
|
648 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
649 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
650 | - 'messengers_to_activate_with' => array('email'), |
|
651 | - 'messengers_to_validate_with' => array('email'), |
|
652 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
653 | - ); |
|
654 | - EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
655 | - |
|
656 | - //register registration cancelled message type |
|
657 | - $setup_args = array( |
|
658 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
659 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
660 | - 'messengers_to_activate_with' => array('email'), |
|
661 | - 'messengers_to_validate_with' => array('email'), |
|
662 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
663 | - ); |
|
664 | - EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
665 | - |
|
666 | - |
|
667 | - //register payment failed message type |
|
668 | - $setup_args = array( |
|
669 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
670 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
671 | - 'messengers_to_activate_with' => array('email'), |
|
672 | - 'messengers_to_validate_with' => array('email'), |
|
673 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
674 | - ); |
|
675 | - EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
676 | - |
|
677 | - //register payment declined message type |
|
678 | - $setup_args = array( |
|
679 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
680 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
681 | - 'messengers_to_activate_with' => array('email'), |
|
682 | - 'messengers_to_validate_with' => array('email'), |
|
683 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
684 | - ); |
|
685 | - EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - /** |
|
690 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
691 | - * |
|
692 | - * @since 4.3.2 |
|
693 | - * |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function register_caf_shortcodes() |
|
697 | - { |
|
698 | - $setup_args = array( |
|
699 | - 'autoloadpaths' => array( |
|
700 | - EE_CAF_LIBRARIES . 'shortcodes/' |
|
701 | - ), |
|
702 | - 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
703 | - 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
704 | - 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]') |
|
705 | - ); |
|
706 | - EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * Parses a question list shortcode using given data and template |
|
712 | - * |
|
713 | - * @param \EE_Shortcodes $shortcode_parser |
|
714 | - * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
715 | - * @param EE_Answer[] $answers An array of answer objects |
|
716 | - * @param string $template Template content to be parsed. |
|
717 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
718 | - * @param array $extra_data Extra data that might be used when parsing the template. |
|
719 | - */ |
|
720 | - protected function _parse_question_list_for_primary_or_recipient_registration( |
|
721 | - $shortcode_parser, |
|
722 | - $questions, |
|
723 | - $answers, |
|
724 | - $template, |
|
725 | - $valid_shortcodes, |
|
726 | - $extra_data |
|
727 | - ) { |
|
728 | - $question_list = ''; |
|
729 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
730 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
731 | - foreach ($answers as $answer) { |
|
732 | - if ($answer instanceof EE_Answer) { |
|
733 | - //first see if the question is in our $questions array. If not then try to get from answer object. |
|
734 | - $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
735 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
736 | - if ( |
|
737 | - ! $question instanceof EE_Question |
|
738 | - || ( |
|
739 | - $question instanceof EE_Question |
|
740 | - && $question->admin_only() |
|
741 | - ) |
|
742 | - ) { |
|
743 | - continue; |
|
744 | - } |
|
745 | - $question_list .= $shortcode_helper->parse_question_list_template( |
|
746 | - $template, |
|
747 | - $answer, |
|
748 | - $valid_shortcodes, |
|
749 | - $extra_data |
|
750 | - ); |
|
751 | - } |
|
752 | - } |
|
753 | - |
|
754 | - return $question_list; |
|
755 | - } |
|
598 | + default : |
|
599 | + return $parsed; |
|
600 | + break; |
|
601 | + } |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * Takes care of registering the message types that are only available in caffeinated EE. |
|
607 | + * |
|
608 | + * @since 4.3.2 |
|
609 | + * |
|
610 | + * @return void |
|
611 | + */ |
|
612 | + public function register_caf_message_types() |
|
613 | + { |
|
614 | + //register newsletter message type |
|
615 | + $setup_args = array( |
|
616 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
617 | + 'autoloadpaths' => array( |
|
618 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
619 | + ), |
|
620 | + 'messengers_to_activate_with' => array('email'), |
|
621 | + 'messengers_to_validate_with' => array('email'), |
|
622 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
623 | + ); |
|
624 | + EE_Register_Message_Type::register('newsletter', $setup_args); |
|
625 | + |
|
626 | + //register payment reminder message type |
|
627 | + $setup_args = array( |
|
628 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
629 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
630 | + 'messengers_to_activate_with' => array('email'), |
|
631 | + 'messengers_to_validate_with' => array('email'), |
|
632 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
633 | + ); |
|
634 | + EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
635 | + |
|
636 | + //register payment declined message type |
|
637 | + $setup_args = array( |
|
638 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
639 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
640 | + 'messengers_to_activate_with' => array('email'), |
|
641 | + 'messengers_to_validate_with' => array('email'), |
|
642 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
643 | + ); |
|
644 | + EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
645 | + |
|
646 | + //register registration declined message type |
|
647 | + $setup_args = array( |
|
648 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
649 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
650 | + 'messengers_to_activate_with' => array('email'), |
|
651 | + 'messengers_to_validate_with' => array('email'), |
|
652 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
653 | + ); |
|
654 | + EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
655 | + |
|
656 | + //register registration cancelled message type |
|
657 | + $setup_args = array( |
|
658 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
659 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
660 | + 'messengers_to_activate_with' => array('email'), |
|
661 | + 'messengers_to_validate_with' => array('email'), |
|
662 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
663 | + ); |
|
664 | + EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
665 | + |
|
666 | + |
|
667 | + //register payment failed message type |
|
668 | + $setup_args = array( |
|
669 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
670 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
671 | + 'messengers_to_activate_with' => array('email'), |
|
672 | + 'messengers_to_validate_with' => array('email'), |
|
673 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
674 | + ); |
|
675 | + EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
676 | + |
|
677 | + //register payment declined message type |
|
678 | + $setup_args = array( |
|
679 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
680 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
681 | + 'messengers_to_activate_with' => array('email'), |
|
682 | + 'messengers_to_validate_with' => array('email'), |
|
683 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
684 | + ); |
|
685 | + EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + /** |
|
690 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
691 | + * |
|
692 | + * @since 4.3.2 |
|
693 | + * |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function register_caf_shortcodes() |
|
697 | + { |
|
698 | + $setup_args = array( |
|
699 | + 'autoloadpaths' => array( |
|
700 | + EE_CAF_LIBRARIES . 'shortcodes/' |
|
701 | + ), |
|
702 | + 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
703 | + 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
704 | + 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]') |
|
705 | + ); |
|
706 | + EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * Parses a question list shortcode using given data and template |
|
712 | + * |
|
713 | + * @param \EE_Shortcodes $shortcode_parser |
|
714 | + * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
715 | + * @param EE_Answer[] $answers An array of answer objects |
|
716 | + * @param string $template Template content to be parsed. |
|
717 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
718 | + * @param array $extra_data Extra data that might be used when parsing the template. |
|
719 | + */ |
|
720 | + protected function _parse_question_list_for_primary_or_recipient_registration( |
|
721 | + $shortcode_parser, |
|
722 | + $questions, |
|
723 | + $answers, |
|
724 | + $template, |
|
725 | + $valid_shortcodes, |
|
726 | + $extra_data |
|
727 | + ) { |
|
728 | + $question_list = ''; |
|
729 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
730 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
731 | + foreach ($answers as $answer) { |
|
732 | + if ($answer instanceof EE_Answer) { |
|
733 | + //first see if the question is in our $questions array. If not then try to get from answer object. |
|
734 | + $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
735 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
736 | + if ( |
|
737 | + ! $question instanceof EE_Question |
|
738 | + || ( |
|
739 | + $question instanceof EE_Question |
|
740 | + && $question->admin_only() |
|
741 | + ) |
|
742 | + ) { |
|
743 | + continue; |
|
744 | + } |
|
745 | + $question_list .= $shortcode_helper->parse_question_list_template( |
|
746 | + $template, |
|
747 | + $answer, |
|
748 | + $valid_shortcodes, |
|
749 | + $extra_data |
|
750 | + ); |
|
751 | + } |
|
752 | + } |
|
753 | + |
|
754 | + return $question_list; |
|
755 | + } |
|
756 | 756 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function messages_autoload_paths($dir_ref) |
97 | 97 | { |
98 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
98 | + $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/'; |
|
99 | 99 | |
100 | 100 | return $dir_ref; |
101 | 101 | } |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | //the template file name we're replacing contents for. |
219 | - $template_file_prefix = $field . '_' . $context; |
|
220 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
219 | + $template_file_prefix = $field.'_'.$context; |
|
220 | + $msg_prefix = $messenger->name.'_'.$message_type->name.'_'; |
|
221 | 221 | |
222 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
222 | + $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/'; |
|
223 | 223 | |
224 | 224 | if ($messenger->name == 'email' && $message_type->name == 'registration') { |
225 | 225 | |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | case 'question_list_admin' : |
229 | 229 | case 'question_list_attendee' : |
230 | 230 | case 'question_list_primary_attendee' : |
231 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
231 | + $path = $base_path.$msg_prefix.'question_list.template.php'; |
|
232 | 232 | $contents = EEH_Template::display_template($path, array(), true); |
233 | 233 | break; |
234 | 234 | |
235 | 235 | case 'attendee_list_primary_attendee' : |
236 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
236 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
237 | 237 | $contents = EEH_Template::display_template($path, array(), true); |
238 | 238 | break; |
239 | 239 | |
240 | 240 | case 'attendee_list_admin' : |
241 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
241 | + $path = $base_path.$msg_prefix.'attendee_list_admin.template.php'; |
|
242 | 242 | $contents = EEH_Template::display_template($path, |
243 | 243 | array(), true); |
244 | 244 | break; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | break; |
249 | 249 | |
250 | 250 | case 'event_list_attendee' : |
251 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
251 | + $path = $base_path.$msg_prefix.'event_list_attendee.template.php'; |
|
252 | 252 | $contents = EEH_Template::display_template($path, array(), true); |
253 | 253 | break; |
254 | 254 | } |
@@ -256,24 +256,24 @@ discard block |
||
256 | 256 | switch ($template_file_prefix) { |
257 | 257 | |
258 | 258 | case 'content_attendee' : |
259 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
259 | + $path = $base_path.$msg_prefix.'content.template.php'; |
|
260 | 260 | $contents = EEH_Template::display_template($path, array(), true); |
261 | 261 | break; |
262 | 262 | |
263 | 263 | case 'newsletter_content_attendee' : |
264 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
264 | + $path = $base_path.$msg_prefix.'newsletter_content.template.php'; |
|
265 | 265 | $contents = EEH_Template::display_template($path, array(), true); |
266 | 266 | break; |
267 | 267 | |
268 | 268 | case 'newsletter_subject_attendee' : |
269 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
269 | + $path = $base_path.$msg_prefix.'subject.template.php'; |
|
270 | 270 | $contents = EEH_Template::display_template($path, array(), true); |
271 | 271 | break; |
272 | 272 | } |
273 | 273 | } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
274 | 274 | switch ($template_file_prefix) { |
275 | 275 | case 'attendee_list_purchaser' : |
276 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
276 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
277 | 277 | $contents = EEH_Template::display_template($path, array(), true); |
278 | 278 | break; |
279 | 279 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | |
506 | 506 | //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
507 | 507 | //object on it. |
508 | - if ( ! isset( $extra_data['data'] ) ) { |
|
508 | + if ( ! isset($extra_data['data'])) { |
|
509 | 509 | $extra_data['data'] = $recipient; |
510 | 510 | } |
511 | 511 | |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
570 | 570 | return ''; |
571 | 571 | } |
572 | - $registration = $recipient->primary_reg_obj; |
|
572 | + $registration = $recipient->primary_reg_obj; |
|
573 | 573 | $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
574 | 574 | ? $recipient->registrations[$registration->ID()]['ans_objs'] |
575 | 575 | : array(); |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | $questions = isset($recipient->questions) ? $recipient->questions : array(); |
583 | 583 | //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
584 | 584 | //object on it. |
585 | - if ( ! isset( $extra_data['data'] ) ){ |
|
585 | + if ( ! isset($extra_data['data'])) { |
|
586 | 586 | $extra_data['data'] = $recipient; |
587 | 587 | } |
588 | 588 | return $this->_parse_question_list_for_primary_or_recipient_registration( |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | $setup_args = array( |
616 | 616 | 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
617 | 617 | 'autoloadpaths' => array( |
618 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
618 | + EE_CAF_LIBRARIES.'messages/message_type/newsletter/' |
|
619 | 619 | ), |
620 | 620 | 'messengers_to_activate_with' => array('email'), |
621 | 621 | 'messengers_to_validate_with' => array('email'), |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | //register payment reminder message type |
627 | 627 | $setup_args = array( |
628 | 628 | 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
629 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
629 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'), |
|
630 | 630 | 'messengers_to_activate_with' => array('email'), |
631 | 631 | 'messengers_to_validate_with' => array('email'), |
632 | 632 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | //register payment declined message type |
637 | 637 | $setup_args = array( |
638 | 638 | 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
639 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
639 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'), |
|
640 | 640 | 'messengers_to_activate_with' => array('email'), |
641 | 641 | 'messengers_to_validate_with' => array('email'), |
642 | 642 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | //register registration declined message type |
647 | 647 | $setup_args = array( |
648 | 648 | 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
649 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
649 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'), |
|
650 | 650 | 'messengers_to_activate_with' => array('email'), |
651 | 651 | 'messengers_to_validate_with' => array('email'), |
652 | 652 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | //register registration cancelled message type |
657 | 657 | $setup_args = array( |
658 | 658 | 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
659 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
659 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'), |
|
660 | 660 | 'messengers_to_activate_with' => array('email'), |
661 | 661 | 'messengers_to_validate_with' => array('email'), |
662 | 662 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | //register payment failed message type |
668 | 668 | $setup_args = array( |
669 | 669 | 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
670 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
670 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'), |
|
671 | 671 | 'messengers_to_activate_with' => array('email'), |
672 | 672 | 'messengers_to_validate_with' => array('email'), |
673 | 673 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | //register payment declined message type |
678 | 678 | $setup_args = array( |
679 | 679 | 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
680 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
680 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'), |
|
681 | 681 | 'messengers_to_activate_with' => array('email'), |
682 | 682 | 'messengers_to_validate_with' => array('email'), |
683 | 683 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | { |
698 | 698 | $setup_args = array( |
699 | 699 | 'autoloadpaths' => array( |
700 | - EE_CAF_LIBRARIES . 'shortcodes/' |
|
700 | + EE_CAF_LIBRARIES.'shortcodes/' |
|
701 | 701 | ), |
702 | 702 | 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
703 | 703 | 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
@@ -32,211 +32,211 @@ |
||
32 | 32 | class ShortcodesManager |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
37 | - */ |
|
38 | - private $legacy_shortcodes_manager; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var ShortcodeInterface[] $shortcodes |
|
42 | - */ |
|
43 | - private $shortcodes; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * ShortcodesManager constructor |
|
49 | - * |
|
50 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
51 | - */ |
|
52 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
53 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
54 | - // assemble a list of installed and active shortcodes |
|
55 | - add_action( |
|
56 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
57 | - array($this, 'registerShortcodes'), |
|
58 | - 999 |
|
59 | - ); |
|
60 | - // call add_shortcode() for all installed shortcodes |
|
61 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
62 | - // check content for shortcodes the old way |
|
63 | - add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
64 | - // check content for shortcodes the NEW more efficient way |
|
65 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return CollectionInterface|ShortcodeInterface[] |
|
72 | - * @throws InvalidIdentifierException |
|
73 | - * @throws InvalidInterfaceException |
|
74 | - * @throws InvalidFilePathException |
|
75 | - * @throws InvalidEntityException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidClassException |
|
78 | - */ |
|
79 | - public function getShortcodes() |
|
80 | - { |
|
81 | - if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
82 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
83 | - } |
|
84 | - return $this->shortcodes; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return CollectionInterface|ShortcodeInterface[] |
|
91 | - * @throws InvalidIdentifierException |
|
92 | - * @throws InvalidInterfaceException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - * @throws InvalidEntityException |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws InvalidClassException |
|
97 | - */ |
|
98 | - protected function loadShortcodesCollection() |
|
99 | - { |
|
100 | - $loader = new CollectionLoader( |
|
101 | - new CollectionDetails( |
|
102 | - // collection name |
|
103 | - 'shortcodes', |
|
104 | - // collection interface |
|
105 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
106 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
107 | - array('EventEspresso\core\domain\entities\shortcodes'), |
|
108 | - // filepaths to classes to add |
|
109 | - array(), |
|
110 | - // file mask to use if parsing folder for files to add |
|
111 | - '', |
|
112 | - // what to use as identifier for collection entities |
|
113 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
114 | - CollectionDetails::ID_CLASS_NAME |
|
115 | - ) |
|
116 | - ); |
|
117 | - return $loader->getCollection(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - * @throws DomainException |
|
125 | - * @throws InvalidInterfaceException |
|
126 | - * @throws InvalidIdentifierException |
|
127 | - * @throws InvalidFilePathException |
|
128 | - * @throws InvalidEntityException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws InvalidClassException |
|
131 | - */ |
|
132 | - public function registerShortcodes() |
|
133 | - { |
|
134 | - try { |
|
135 | - $this->shortcodes = apply_filters( |
|
136 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
137 | - $this->getShortcodes() |
|
138 | - ); |
|
139 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
140 | - throw new InvalidEntityException( |
|
141 | - $this->shortcodes, |
|
142 | - 'CollectionInterface', |
|
143 | - sprintf( |
|
144 | - esc_html__( |
|
145 | - 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
149 | - ) |
|
150 | - ); |
|
151 | - } |
|
152 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
153 | - } catch (Exception $exception) { |
|
154 | - new ExceptionStackTraceDisplay($exception); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return void |
|
162 | - */ |
|
163 | - public function addShortcodes() |
|
164 | - { |
|
165 | - try { |
|
166 | - // cycle thru shortcode folders |
|
167 | - foreach ($this->shortcodes as $shortcode) { |
|
168 | - /** @var ShortcodeInterface $shortcode */ |
|
169 | - if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
170 | - add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
171 | - add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
172 | - } |
|
173 | - // add_shortcode() if it has not already been added |
|
174 | - if ( ! shortcode_exists($shortcode->getTag())) { |
|
175 | - add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
176 | - } |
|
177 | - } |
|
178 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
179 | - } catch (Exception $exception) { |
|
180 | - new ExceptionStackTraceDisplay($exception); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * callback for the "template_redirect" hook point |
|
188 | - * checks posts for EE shortcodes, and initializes them, |
|
189 | - * then toggles filter switch that loads core default assets |
|
190 | - * |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function templateRedirect() |
|
194 | - { |
|
195 | - global $wp_query; |
|
196 | - if (empty($wp_query->posts)) { |
|
197 | - return; |
|
198 | - } |
|
199 | - $load_assets = false; |
|
200 | - // array of posts displayed in current request |
|
201 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
202 | - foreach ($posts as $post) { |
|
203 | - // now check post content and excerpt for EE shortcodes |
|
204 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | - ? true |
|
206 | - : $load_assets; |
|
207 | - } |
|
208 | - if ($load_assets) { |
|
209 | - $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
210 | - add_filter('FHEE_load_css', '__return_true'); |
|
211 | - add_filter('FHEE_load_js', '__return_true'); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * checks supplied content against list of shortcodes, |
|
219 | - * then initializes any found shortcodes, and returns true. |
|
220 | - * returns false if no shortcodes found. |
|
221 | - * |
|
222 | - * @param string $content |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function parseContentForShortcodes($content) |
|
226 | - { |
|
227 | - $has_shortcode = false; |
|
228 | - if(empty($this->shortcodes)){ |
|
229 | - return $has_shortcode; |
|
230 | - } |
|
231 | - foreach ($this->shortcodes as $shortcode) { |
|
232 | - /** @var ShortcodeInterface $shortcode */ |
|
233 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
234 | - $shortcode->initializeShortcode(); |
|
235 | - $has_shortcode = true; |
|
236 | - } |
|
237 | - } |
|
238 | - return $has_shortcode; |
|
239 | - } |
|
35 | + /** |
|
36 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
37 | + */ |
|
38 | + private $legacy_shortcodes_manager; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var ShortcodeInterface[] $shortcodes |
|
42 | + */ |
|
43 | + private $shortcodes; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * ShortcodesManager constructor |
|
49 | + * |
|
50 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
51 | + */ |
|
52 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
53 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
54 | + // assemble a list of installed and active shortcodes |
|
55 | + add_action( |
|
56 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
57 | + array($this, 'registerShortcodes'), |
|
58 | + 999 |
|
59 | + ); |
|
60 | + // call add_shortcode() for all installed shortcodes |
|
61 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
62 | + // check content for shortcodes the old way |
|
63 | + add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
64 | + // check content for shortcodes the NEW more efficient way |
|
65 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return CollectionInterface|ShortcodeInterface[] |
|
72 | + * @throws InvalidIdentifierException |
|
73 | + * @throws InvalidInterfaceException |
|
74 | + * @throws InvalidFilePathException |
|
75 | + * @throws InvalidEntityException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidClassException |
|
78 | + */ |
|
79 | + public function getShortcodes() |
|
80 | + { |
|
81 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
82 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
83 | + } |
|
84 | + return $this->shortcodes; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return CollectionInterface|ShortcodeInterface[] |
|
91 | + * @throws InvalidIdentifierException |
|
92 | + * @throws InvalidInterfaceException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + * @throws InvalidEntityException |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws InvalidClassException |
|
97 | + */ |
|
98 | + protected function loadShortcodesCollection() |
|
99 | + { |
|
100 | + $loader = new CollectionLoader( |
|
101 | + new CollectionDetails( |
|
102 | + // collection name |
|
103 | + 'shortcodes', |
|
104 | + // collection interface |
|
105 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
106 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
107 | + array('EventEspresso\core\domain\entities\shortcodes'), |
|
108 | + // filepaths to classes to add |
|
109 | + array(), |
|
110 | + // file mask to use if parsing folder for files to add |
|
111 | + '', |
|
112 | + // what to use as identifier for collection entities |
|
113 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
114 | + CollectionDetails::ID_CLASS_NAME |
|
115 | + ) |
|
116 | + ); |
|
117 | + return $loader->getCollection(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + * @throws DomainException |
|
125 | + * @throws InvalidInterfaceException |
|
126 | + * @throws InvalidIdentifierException |
|
127 | + * @throws InvalidFilePathException |
|
128 | + * @throws InvalidEntityException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws InvalidClassException |
|
131 | + */ |
|
132 | + public function registerShortcodes() |
|
133 | + { |
|
134 | + try { |
|
135 | + $this->shortcodes = apply_filters( |
|
136 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
137 | + $this->getShortcodes() |
|
138 | + ); |
|
139 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
140 | + throw new InvalidEntityException( |
|
141 | + $this->shortcodes, |
|
142 | + 'CollectionInterface', |
|
143 | + sprintf( |
|
144 | + esc_html__( |
|
145 | + 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
149 | + ) |
|
150 | + ); |
|
151 | + } |
|
152 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
153 | + } catch (Exception $exception) { |
|
154 | + new ExceptionStackTraceDisplay($exception); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return void |
|
162 | + */ |
|
163 | + public function addShortcodes() |
|
164 | + { |
|
165 | + try { |
|
166 | + // cycle thru shortcode folders |
|
167 | + foreach ($this->shortcodes as $shortcode) { |
|
168 | + /** @var ShortcodeInterface $shortcode */ |
|
169 | + if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
170 | + add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
171 | + add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
172 | + } |
|
173 | + // add_shortcode() if it has not already been added |
|
174 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
175 | + add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
176 | + } |
|
177 | + } |
|
178 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
179 | + } catch (Exception $exception) { |
|
180 | + new ExceptionStackTraceDisplay($exception); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * callback for the "template_redirect" hook point |
|
188 | + * checks posts for EE shortcodes, and initializes them, |
|
189 | + * then toggles filter switch that loads core default assets |
|
190 | + * |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function templateRedirect() |
|
194 | + { |
|
195 | + global $wp_query; |
|
196 | + if (empty($wp_query->posts)) { |
|
197 | + return; |
|
198 | + } |
|
199 | + $load_assets = false; |
|
200 | + // array of posts displayed in current request |
|
201 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
202 | + foreach ($posts as $post) { |
|
203 | + // now check post content and excerpt for EE shortcodes |
|
204 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | + ? true |
|
206 | + : $load_assets; |
|
207 | + } |
|
208 | + if ($load_assets) { |
|
209 | + $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
210 | + add_filter('FHEE_load_css', '__return_true'); |
|
211 | + add_filter('FHEE_load_js', '__return_true'); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * checks supplied content against list of shortcodes, |
|
219 | + * then initializes any found shortcodes, and returns true. |
|
220 | + * returns false if no shortcodes found. |
|
221 | + * |
|
222 | + * @param string $content |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function parseContentForShortcodes($content) |
|
226 | + { |
|
227 | + $has_shortcode = false; |
|
228 | + if(empty($this->shortcodes)){ |
|
229 | + return $has_shortcode; |
|
230 | + } |
|
231 | + foreach ($this->shortcodes as $shortcode) { |
|
232 | + /** @var ShortcodeInterface $shortcode */ |
|
233 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
234 | + $shortcode->initializeShortcode(); |
|
235 | + $has_shortcode = true; |
|
236 | + } |
|
237 | + } |
|
238 | + return $has_shortcode; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | // End of file ShortcodesManager.php |
@@ -3,7 +3,7 @@ discard block |
||
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,378 +26,378 @@ discard block |
||
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 | - // primarily used to process any content shortcodes |
|
83 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
84 | - // header |
|
85 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
86 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
87 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
88 | - // display errors |
|
89 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
90 | - // the content |
|
91 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
92 | - //exclude our private cpt comments |
|
93 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
94 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
95 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
96 | - // action hook EE |
|
97 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
98 | - // for checking that browser cookies are enabled |
|
99 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return EE_Request_Handler |
|
107 | - */ |
|
108 | - public function Request_Handler() |
|
109 | - { |
|
110 | - return $this->Request_Handler; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return EE_Module_Request_Router |
|
116 | - */ |
|
117 | - public function Module_Request_Router() |
|
118 | - { |
|
119 | - return $this->Module_Request_Router; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return LegacyShortcodesManager |
|
126 | - */ |
|
127 | - public function getLegacyShortcodesManager() |
|
128 | - { |
|
129 | - return EE_Config::getLegacyShortcodesManager(); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * filter_wp_comments |
|
142 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
143 | - * widgets/queries done on frontend |
|
144 | - * |
|
145 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
146 | - * @return array array of comment clauses with modifications. |
|
147 | - */ |
|
148 | - public function filter_wp_comments($clauses) |
|
149 | - { |
|
150 | - global $wpdb; |
|
151 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
152 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
153 | - foreach ($cpts as $cpt => $details) { |
|
154 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
155 | - } |
|
156 | - } |
|
157 | - return $clauses; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * employ_CPT_Strategy |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function employ_CPT_Strategy() |
|
168 | - { |
|
169 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
170 | - $this->Registry->load_core('CPT_Strategy'); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
177 | - * |
|
178 | - * @param string $url incoming url |
|
179 | - * @return string final assembled url |
|
180 | - */ |
|
181 | - public function maybe_force_admin_ajax_ssl($url) |
|
182 | - { |
|
183 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
184 | - $url = str_replace('http://', 'https://', $url); |
|
185 | - } |
|
186 | - return $url; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
199 | - * default priority init phases have run |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public function wp_loaded() |
|
205 | - { |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
213 | - /** |
|
214 | - * _get_request |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @param WP $WP |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - public function get_request(WP $WP) |
|
221 | - { |
|
222 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
223 | - $this->Request_Handler->parse_request($WP); |
|
224 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
231 | - * |
|
232 | - * @access public |
|
233 | - * @param WP_Query $WP_Query |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - public function pre_get_posts($WP_Query) |
|
237 | - { |
|
238 | - // only load Module_Request_Router if this is the main query |
|
239 | - if ( |
|
240 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
241 | - && $WP_Query->is_main_query() |
|
242 | - ) { |
|
243 | - // cycle thru module routes |
|
244 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
245 | - // determine module and method for route |
|
246 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
247 | - if ($module instanceof EED_Module) { |
|
248 | - // get registered view for route |
|
249 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
250 | - // grab module name |
|
251 | - $module_name = $module->module_name(); |
|
252 | - // map the module to the module objects |
|
253 | - $this->Registry->modules->{$module_name} = $module; |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /*********************************************** WP HOOK ***********************************************/ |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * wp - basically last chance to do stuff before headers sent |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function wp() |
|
273 | - { |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * callback for the "template_redirect" hook point |
|
284 | - * checks sidebars for EE widgets |
|
285 | - * loads resources and assets accordingly |
|
286 | - * |
|
287 | - * @return void |
|
288 | - */ |
|
289 | - public function templateRedirect() |
|
290 | - { |
|
291 | - global $wp_query; |
|
292 | - if (empty($wp_query->posts)){ |
|
293 | - return; |
|
294 | - } |
|
295 | - // if we already know this is an espresso page, then load assets |
|
296 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
297 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
298 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
299 | - if ( $load_assets){ |
|
300 | - wp_enqueue_style('espresso_default'); |
|
301 | - wp_enqueue_style('espresso_custom_css'); |
|
302 | - wp_enqueue_script('espresso_core'); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * builds list of active widgets then scans active sidebars looking for them |
|
310 | - * returns true is an EE widget is found in an active sidebar |
|
311 | - * Please Note: this does NOT mean that the sidebar or widget |
|
312 | - * is actually in use in a given template, as that is unfortunately not known |
|
313 | - * until a sidebar and it's widgets are actually loaded |
|
314 | - * |
|
315 | - * @return boolean |
|
316 | - */ |
|
317 | - private function espresso_widgets_in_active_sidebars() |
|
318 | - { |
|
319 | - $espresso_widgets = array(); |
|
320 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
321 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
322 | - if (is_active_widget(false, false, $id_base)) { |
|
323 | - $espresso_widgets[] = $id_base; |
|
324 | - } |
|
325 | - } |
|
326 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
327 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
328 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
329 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
330 | - foreach ($espresso_widgets as $espresso_widget) { |
|
331 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
332 | - return true; |
|
333 | - } |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - return false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * header_meta_tag |
|
346 | - * |
|
347 | - * @access public |
|
348 | - * @return void |
|
349 | - */ |
|
350 | - public function header_meta_tag() |
|
351 | - { |
|
352 | - print( |
|
353 | - apply_filters( |
|
354 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
355 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
356 | - ); |
|
357 | - |
|
358 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
359 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
360 | - //also exclude all critical pages from indexing |
|
361 | - if ( |
|
362 | - ( |
|
363 | - is_tax('espresso_event_type') |
|
364 | - && get_option( 'blog_public' ) !== '0' |
|
365 | - ) |
|
366 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
367 | - ) { |
|
368 | - print( |
|
369 | - apply_filters( |
|
370 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
371 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
372 | - ) |
|
373 | - ); |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * wp_print_scripts |
|
381 | - * |
|
382 | - * @return void |
|
383 | - */ |
|
384 | - public function wp_print_scripts() |
|
385 | - { |
|
386 | - global $post; |
|
387 | - if ( |
|
388 | - isset($post->EE_Event) |
|
389 | - && $post->EE_Event instanceof EE_Event |
|
390 | - && get_post_type() === 'espresso_events' |
|
391 | - && is_singular() |
|
392 | - ) { |
|
393 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /*********************************************** 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 | + // primarily used to process any content shortcodes |
|
83 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
84 | + // header |
|
85 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
86 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
87 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
88 | + // display errors |
|
89 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
90 | + // the content |
|
91 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
92 | + //exclude our private cpt comments |
|
93 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
94 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
95 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
96 | + // action hook EE |
|
97 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
98 | + // for checking that browser cookies are enabled |
|
99 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
100 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return EE_Request_Handler |
|
107 | + */ |
|
108 | + public function Request_Handler() |
|
109 | + { |
|
110 | + return $this->Request_Handler; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return EE_Module_Request_Router |
|
116 | + */ |
|
117 | + public function Module_Request_Router() |
|
118 | + { |
|
119 | + return $this->Module_Request_Router; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return LegacyShortcodesManager |
|
126 | + */ |
|
127 | + public function getLegacyShortcodesManager() |
|
128 | + { |
|
129 | + return EE_Config::getLegacyShortcodesManager(); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * filter_wp_comments |
|
142 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
143 | + * widgets/queries done on frontend |
|
144 | + * |
|
145 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
146 | + * @return array array of comment clauses with modifications. |
|
147 | + */ |
|
148 | + public function filter_wp_comments($clauses) |
|
149 | + { |
|
150 | + global $wpdb; |
|
151 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
152 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
153 | + foreach ($cpts as $cpt => $details) { |
|
154 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
155 | + } |
|
156 | + } |
|
157 | + return $clauses; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * employ_CPT_Strategy |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function employ_CPT_Strategy() |
|
168 | + { |
|
169 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
170 | + $this->Registry->load_core('CPT_Strategy'); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
177 | + * |
|
178 | + * @param string $url incoming url |
|
179 | + * @return string final assembled url |
|
180 | + */ |
|
181 | + public function maybe_force_admin_ajax_ssl($url) |
|
182 | + { |
|
183 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
184 | + $url = str_replace('http://', 'https://', $url); |
|
185 | + } |
|
186 | + return $url; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
199 | + * default priority init phases have run |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public function wp_loaded() |
|
205 | + { |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
213 | + /** |
|
214 | + * _get_request |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @param WP $WP |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + public function get_request(WP $WP) |
|
221 | + { |
|
222 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
223 | + $this->Request_Handler->parse_request($WP); |
|
224 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
231 | + * |
|
232 | + * @access public |
|
233 | + * @param WP_Query $WP_Query |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + public function pre_get_posts($WP_Query) |
|
237 | + { |
|
238 | + // only load Module_Request_Router if this is the main query |
|
239 | + if ( |
|
240 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
241 | + && $WP_Query->is_main_query() |
|
242 | + ) { |
|
243 | + // cycle thru module routes |
|
244 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
245 | + // determine module and method for route |
|
246 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
247 | + if ($module instanceof EED_Module) { |
|
248 | + // get registered view for route |
|
249 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
250 | + // grab module name |
|
251 | + $module_name = $module->module_name(); |
|
252 | + // map the module to the module objects |
|
253 | + $this->Registry->modules->{$module_name} = $module; |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /*********************************************** WP HOOK ***********************************************/ |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * wp - basically last chance to do stuff before headers sent |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function wp() |
|
273 | + { |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * callback for the "template_redirect" hook point |
|
284 | + * checks sidebars for EE widgets |
|
285 | + * loads resources and assets accordingly |
|
286 | + * |
|
287 | + * @return void |
|
288 | + */ |
|
289 | + public function templateRedirect() |
|
290 | + { |
|
291 | + global $wp_query; |
|
292 | + if (empty($wp_query->posts)){ |
|
293 | + return; |
|
294 | + } |
|
295 | + // if we already know this is an espresso page, then load assets |
|
296 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
297 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
298 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
299 | + if ( $load_assets){ |
|
300 | + wp_enqueue_style('espresso_default'); |
|
301 | + wp_enqueue_style('espresso_custom_css'); |
|
302 | + wp_enqueue_script('espresso_core'); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * builds list of active widgets then scans active sidebars looking for them |
|
310 | + * returns true is an EE widget is found in an active sidebar |
|
311 | + * Please Note: this does NOT mean that the sidebar or widget |
|
312 | + * is actually in use in a given template, as that is unfortunately not known |
|
313 | + * until a sidebar and it's widgets are actually loaded |
|
314 | + * |
|
315 | + * @return boolean |
|
316 | + */ |
|
317 | + private function espresso_widgets_in_active_sidebars() |
|
318 | + { |
|
319 | + $espresso_widgets = array(); |
|
320 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
321 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
322 | + if (is_active_widget(false, false, $id_base)) { |
|
323 | + $espresso_widgets[] = $id_base; |
|
324 | + } |
|
325 | + } |
|
326 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
327 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
328 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
329 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
330 | + foreach ($espresso_widgets as $espresso_widget) { |
|
331 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
332 | + return true; |
|
333 | + } |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + return false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * header_meta_tag |
|
346 | + * |
|
347 | + * @access public |
|
348 | + * @return void |
|
349 | + */ |
|
350 | + public function header_meta_tag() |
|
351 | + { |
|
352 | + print( |
|
353 | + apply_filters( |
|
354 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
355 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
356 | + ); |
|
357 | + |
|
358 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
359 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
360 | + //also exclude all critical pages from indexing |
|
361 | + if ( |
|
362 | + ( |
|
363 | + is_tax('espresso_event_type') |
|
364 | + && get_option( 'blog_public' ) !== '0' |
|
365 | + ) |
|
366 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
367 | + ) { |
|
368 | + print( |
|
369 | + apply_filters( |
|
370 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
371 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
372 | + ) |
|
373 | + ); |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * wp_print_scripts |
|
381 | + * |
|
382 | + * @return void |
|
383 | + */ |
|
384 | + public function wp_print_scripts() |
|
385 | + { |
|
386 | + global $post; |
|
387 | + if ( |
|
388 | + isset($post->EE_Event) |
|
389 | + && $post->EE_Event instanceof EE_Event |
|
390 | + && get_post_type() === 'espresso_events' |
|
391 | + && is_singular() |
|
392 | + ) { |
|
393 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
401 | 401 | |
402 | 402 | |
403 | 403 | |
@@ -408,99 +408,99 @@ discard block |
||
408 | 408 | // * @param $the_content |
409 | 409 | // * @return string |
410 | 410 | // */ |
411 | - // public function the_content( $the_content ) { |
|
412 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
413 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
414 | - // } |
|
415 | - // return $the_content; |
|
416 | - // } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * display_errors |
|
425 | - * |
|
426 | - * @access public |
|
427 | - * @return void |
|
428 | - */ |
|
429 | - public function display_errors() |
|
430 | - { |
|
431 | - static $shown_already = false; |
|
432 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
433 | - if ( |
|
434 | - ! $shown_already |
|
435 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
436 | - && is_main_query() |
|
437 | - && ! is_feed() |
|
438 | - && in_the_loop() |
|
439 | - && $this->Request_Handler->is_espresso_page() |
|
440 | - ) { |
|
441 | - echo EE_Error::get_notices(); |
|
442 | - $shown_already = true; |
|
443 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
444 | - } |
|
445 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /*********************************************** UTILITIES ***********************************************/ |
|
453 | - /** |
|
454 | - * template_include |
|
455 | - * |
|
456 | - * @access public |
|
457 | - * @param string $template_include_path |
|
458 | - * @return string |
|
459 | - */ |
|
460 | - public function template_include($template_include_path = null) |
|
461 | - { |
|
462 | - if ($this->Request_Handler->is_espresso_page()) { |
|
463 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
464 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
465 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
466 | - $this->_template = basename($this->_template_path); |
|
467 | - return $this->_template_path; |
|
468 | - } |
|
469 | - return $template_include_path; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * get_selected_template |
|
475 | - * |
|
476 | - * @access public |
|
477 | - * @param bool $with_path |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_selected_template($with_path = false) |
|
481 | - { |
|
482 | - return $with_path ? $this->_template_path : $this->_template; |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @deprecated 4.9.26 |
|
489 | - * @param string $shortcode_class |
|
490 | - * @param \WP $wp |
|
491 | - */ |
|
492 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
493 | - { |
|
494 | - \EE_Error::doing_it_wrong( |
|
495 | - __METHOD__, |
|
496 | - __( |
|
497 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
498 | - 'event_espresso' |
|
499 | - ), |
|
500 | - '4.9.26' |
|
501 | - ); |
|
502 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
503 | - } |
|
411 | + // public function the_content( $the_content ) { |
|
412 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
413 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
414 | + // } |
|
415 | + // return $the_content; |
|
416 | + // } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * display_errors |
|
425 | + * |
|
426 | + * @access public |
|
427 | + * @return void |
|
428 | + */ |
|
429 | + public function display_errors() |
|
430 | + { |
|
431 | + static $shown_already = false; |
|
432 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
433 | + if ( |
|
434 | + ! $shown_already |
|
435 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
436 | + && is_main_query() |
|
437 | + && ! is_feed() |
|
438 | + && in_the_loop() |
|
439 | + && $this->Request_Handler->is_espresso_page() |
|
440 | + ) { |
|
441 | + echo EE_Error::get_notices(); |
|
442 | + $shown_already = true; |
|
443 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
444 | + } |
|
445 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /*********************************************** UTILITIES ***********************************************/ |
|
453 | + /** |
|
454 | + * template_include |
|
455 | + * |
|
456 | + * @access public |
|
457 | + * @param string $template_include_path |
|
458 | + * @return string |
|
459 | + */ |
|
460 | + public function template_include($template_include_path = null) |
|
461 | + { |
|
462 | + if ($this->Request_Handler->is_espresso_page()) { |
|
463 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
464 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
465 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
466 | + $this->_template = basename($this->_template_path); |
|
467 | + return $this->_template_path; |
|
468 | + } |
|
469 | + return $template_include_path; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * get_selected_template |
|
475 | + * |
|
476 | + * @access public |
|
477 | + * @param bool $with_path |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_selected_template($with_path = false) |
|
481 | + { |
|
482 | + return $with_path ? $this->_template_path : $this->_template; |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @deprecated 4.9.26 |
|
489 | + * @param string $shortcode_class |
|
490 | + * @param \WP $wp |
|
491 | + */ |
|
492 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
493 | + { |
|
494 | + \EE_Error::doing_it_wrong( |
|
495 | + __METHOD__, |
|
496 | + __( |
|
497 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
498 | + 'event_espresso' |
|
499 | + ), |
|
500 | + '4.9.26' |
|
501 | + ); |
|
502 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
503 | + } |
|
504 | 504 | |
505 | 505 | } |
506 | 506 | // End of file EE_Front_Controller.core.php |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
98 | 98 | // for checking that browser cookies are enabled |
99 | 99 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
100 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
100 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | public function templateRedirect() |
290 | 290 | { |
291 | 291 | global $wp_query; |
292 | - if (empty($wp_query->posts)){ |
|
292 | + if (empty($wp_query->posts)) { |
|
293 | 293 | return; |
294 | 294 | } |
295 | 295 | // if we already know this is an espresso page, then load assets |
296 | 296 | $load_assets = $this->Request_Handler->is_espresso_page(); |
297 | 297 | // if we are already loading assets then just move along, otherwise check for widgets |
298 | 298 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
299 | - if ( $load_assets){ |
|
299 | + if ($load_assets) { |
|
300 | 300 | wp_enqueue_style('espresso_default'); |
301 | 301 | wp_enqueue_style('espresso_custom_css'); |
302 | 302 | wp_enqueue_script('espresso_core'); |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | print( |
353 | 353 | apply_filters( |
354 | 354 | 'FHEE__EE_Front_Controller__header_meta_tag', |
355 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
355 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
356 | 356 | ); |
357 | 357 | |
358 | 358 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | if ( |
362 | 362 | ( |
363 | 363 | is_tax('espresso_event_type') |
364 | - && get_option( 'blog_public' ) !== '0' |
|
364 | + && get_option('blog_public') !== '0' |
|
365 | 365 | ) |
366 | 366 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
367 | 367 | ) { |
368 | 368 | print( |
369 | 369 | apply_filters( |
370 | 370 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
371 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
371 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
372 | 372 | ) |
373 | 373 | ); |
374 | 374 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | ) { |
441 | 441 | echo EE_Error::get_notices(); |
442 | 442 | $shown_already = true; |
443 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
443 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
444 | 444 | } |
445 | 445 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
446 | 446 | } |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | * Sets deleted |
1073 | 1073 | * |
1074 | 1074 | * @param boolean $deleted |
1075 | - * @return boolean |
|
1075 | + * @return boolean|null |
|
1076 | 1076 | */ |
1077 | 1077 | public function set_deleted($deleted) |
1078 | 1078 | { |
@@ -1125,6 +1125,7 @@ discard block |
||
1125 | 1125 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
1126 | 1126 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
1127 | 1127 | * consider registration status as well as datetime access. |
1128 | + * @param integer $DTT_OR_ID |
|
1128 | 1129 | * @return bool |
1129 | 1130 | */ |
1130 | 1131 | public function can_checkin($DTT_OR_ID, $check_approved = true) |
@@ -1278,7 +1279,7 @@ discard block |
||
1278 | 1279 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
1279 | 1280 | * "Latest" is defined by the `DTT_EVT_start` column. |
1280 | 1281 | * |
1281 | - * @return EE_Datetime|null |
|
1282 | + * @return null|EE_Base_Class |
|
1282 | 1283 | * @throws \EE_Error |
1283 | 1284 | */ |
1284 | 1285 | public function get_latest_related_datetime() |
@@ -1557,7 +1558,7 @@ discard block |
||
1557 | 1558 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
1558 | 1559 | * Note: if there are no payments on the registration there will be no payment method returned. |
1559 | 1560 | * |
1560 | - * @return EE_Payment_Method|null |
|
1561 | + * @return null|EE_Base_Class |
|
1561 | 1562 | */ |
1562 | 1563 | public function payment_method() |
1563 | 1564 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | { |
107 | 107 | switch ($field_name) { |
108 | 108 | case 'REG_code' : |
109 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
109 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
110 | 110 | $this->set_reg_code($field_value, $use_default); |
111 | 111 | } |
112 | 112 | break; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | public function event() |
282 | 282 | { |
283 | 283 | $event = $this->get_first_related('Event'); |
284 | - if (! $event instanceof \EE_Event) { |
|
284 | + if ( ! $event instanceof \EE_Event) { |
|
285 | 285 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
286 | 286 | } |
287 | 287 | return $event; |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | */ |
674 | 674 | public function reg_url_link() |
675 | 675 | { |
676 | - return (string)$this->get('REG_url_link'); |
|
676 | + return (string) $this->get('REG_url_link'); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | |
@@ -934,7 +934,7 @@ discard block |
||
934 | 934 | $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
935 | 935 | break; |
936 | 936 | } |
937 | - return $icon . $status[$this->status_ID()]; |
|
937 | + return $icon.$status[$this->status_ID()]; |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | return false; |
1137 | 1137 | } |
1138 | 1138 | //is there a datetime ticket that matches this dtt_ID? |
1139 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1139 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1140 | 1140 | array( |
1141 | 1141 | 'TKT_ID' => $this->get('TKT_ID'), |
1142 | 1142 | 'DTT_ID' => $DTT_ID, |
@@ -1164,7 +1164,7 @@ discard block |
||
1164 | 1164 | { |
1165 | 1165 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
1166 | 1166 | |
1167 | - if (! $DTT_ID) { |
|
1167 | + if ( ! $DTT_ID) { |
|
1168 | 1168 | return false; |
1169 | 1169 | } |
1170 | 1170 | |
@@ -1172,7 +1172,7 @@ discard block |
||
1172 | 1172 | |
1173 | 1173 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
1174 | 1174 | // or not. |
1175 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1175 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
1176 | 1176 | return true; |
1177 | 1177 | } |
1178 | 1178 | |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | $datetime = $this->get_latest_related_datetime(); |
1222 | 1222 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
1223 | 1223 | // verify the registration can checkin for the given DTT_ID |
1224 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1224 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
1225 | 1225 | EE_Error::add_error( |
1226 | 1226 | sprintf( |
1227 | 1227 | __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
@@ -1393,7 +1393,7 @@ discard block |
||
1393 | 1393 | public function transaction() |
1394 | 1394 | { |
1395 | 1395 | $transaction = $this->get_first_related('Transaction'); |
1396 | - if (! $transaction instanceof \EE_Transaction) { |
|
1396 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
1397 | 1397 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
1398 | 1398 | } |
1399 | 1399 | return $transaction; |
@@ -1440,11 +1440,11 @@ discard block |
||
1440 | 1440 | EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
1441 | 1441 | return; |
1442 | 1442 | } |
1443 | - if (! $this->reg_code()) { |
|
1443 | + if ( ! $this->reg_code()) { |
|
1444 | 1444 | parent::set('REG_code', $REG_code, $use_default); |
1445 | 1445 | } else { |
1446 | 1446 | EE_Error::doing_it_wrong( |
1447 | - __CLASS__ . '::' . __FUNCTION__, |
|
1447 | + __CLASS__.'::'.__FUNCTION__, |
|
1448 | 1448 | __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
1449 | 1449 | '4.6.0' |
1450 | 1450 | ); |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | break; |
1591 | 1591 | } |
1592 | 1592 | } |
1593 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1593 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1594 | 1594 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
1595 | 1595 | } |
1596 | 1596 | return $line_item; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -15,1690 +15,1690 @@ discard block |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Used to reference when a registration has never been checked in. |
|
20 | - * |
|
21 | - * @type int |
|
22 | - */ |
|
23 | - const checkin_status_never = 2; |
|
24 | - |
|
25 | - /** |
|
26 | - * Used to reference when a registration has been checked in. |
|
27 | - * |
|
28 | - * @type int |
|
29 | - */ |
|
30 | - const checkin_status_in = 1; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Used to reference when a registration has been checked out. |
|
35 | - * |
|
36 | - * @type int |
|
37 | - */ |
|
38 | - const checkin_status_out = 0; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * extra meta key for tracking reg status os trashed registrations |
|
43 | - * |
|
44 | - * @type string |
|
45 | - */ |
|
46 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * extra meta key for tracking if registration has reserved ticket |
|
51 | - * |
|
52 | - * @type string |
|
53 | - */ |
|
54 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $props_n_values incoming values |
|
59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
60 | - * used.) |
|
61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
62 | - * date_format and the second value is the time format |
|
63 | - * @return EE_Registration |
|
64 | - */ |
|
65 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
66 | - { |
|
67 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
68 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param array $props_n_values incoming values from the database |
|
74 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
75 | - * the website will be used. |
|
76 | - * @return EE_Registration |
|
77 | - */ |
|
78 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
79 | - { |
|
80 | - return new self($props_n_values, true, $timezone); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Set Event ID |
|
86 | - * |
|
87 | - * @param int $EVT_ID Event ID |
|
88 | - */ |
|
89 | - public function set_event($EVT_ID = 0) |
|
90 | - { |
|
91 | - $this->set('EVT_ID', $EVT_ID); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
97 | - * be routed to internal methods |
|
98 | - * |
|
99 | - * @param string $field_name |
|
100 | - * @param mixed $field_value |
|
101 | - * @param bool $use_default |
|
102 | - * @throws \EE_Error |
|
103 | - * @throws \RuntimeException |
|
104 | - */ |
|
105 | - public function set($field_name, $field_value, $use_default = false) |
|
106 | - { |
|
107 | - switch ($field_name) { |
|
108 | - case 'REG_code' : |
|
109 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
110 | - $this->set_reg_code($field_value, $use_default); |
|
111 | - } |
|
112 | - break; |
|
113 | - case 'STS_ID' : |
|
114 | - $this->set_status($field_value, $use_default); |
|
115 | - break; |
|
116 | - default : |
|
117 | - parent::set($field_name, $field_value, $use_default); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Set Status ID |
|
124 | - * updates the registration status and ALSO... |
|
125 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
126 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
127 | - * |
|
128 | - * @param string $new_STS_ID |
|
129 | - * @param boolean $use_default |
|
130 | - * @return bool |
|
131 | - * @throws \RuntimeException |
|
132 | - * @throws \EE_Error |
|
133 | - */ |
|
134 | - public function set_status($new_STS_ID = null, $use_default = false) |
|
135 | - { |
|
136 | - // get current REG_Status |
|
137 | - $old_STS_ID = $this->status_ID(); |
|
138 | - // if status has changed |
|
139 | - if ( |
|
140 | - $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
141 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
142 | - && ! empty($new_STS_ID) // as well as the new status |
|
143 | - && $this->ID() // ensure registration is in the db |
|
144 | - ) { |
|
145 | - // TO approved |
|
146 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
147 | - // reserve a space by incrementing ticket and datetime sold values |
|
148 | - $this->_reserve_registration_space(); |
|
149 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); |
|
150 | - // OR FROM approved |
|
151 | - } else if ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
152 | - // release a space by decrementing ticket and datetime sold values |
|
153 | - $this->_release_registration_space(); |
|
154 | - do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); |
|
155 | - } |
|
156 | - // update status |
|
157 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
158 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
|
159 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
160 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
161 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
162 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
163 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID); |
|
164 | - return true; |
|
165 | - } |
|
166 | - //even though the old value matches the new value, it's still good to |
|
167 | - //allow the parent set method to have a say |
|
168 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
169 | - return true; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * update REGs and TXN when cancelled or declined registrations involved |
|
175 | - * |
|
176 | - * @param string $new_STS_ID |
|
177 | - * @param string $old_STS_ID |
|
178 | - * @throws \EE_Error |
|
179 | - */ |
|
180 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) |
|
181 | - { |
|
182 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
183 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
184 | - // true if registration has been cancelled or declined |
|
185 | - if ( |
|
186 | - in_array($new_STS_ID, $closed_reg_statuses, true) |
|
187 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
188 | - ) { |
|
189 | - /** @type EE_Registration_Processor $registration_processor */ |
|
190 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
191 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
192 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
193 | - // cancelled or declined registration |
|
194 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
195 | - $this, |
|
196 | - $closed_reg_statuses |
|
197 | - ); |
|
198 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
199 | - $this, |
|
200 | - $closed_reg_statuses, |
|
201 | - false |
|
202 | - ); |
|
203 | - do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); |
|
204 | - return; |
|
205 | - } |
|
206 | - // true if reinstating cancelled or declined registration |
|
207 | - if ( |
|
208 | - in_array($old_STS_ID, $closed_reg_statuses, true) |
|
209 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
210 | - ) { |
|
211 | - /** @type EE_Registration_Processor $registration_processor */ |
|
212 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
213 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
214 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
215 | - // reinstating cancelled or declined registration |
|
216 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
217 | - $this, |
|
218 | - $closed_reg_statuses |
|
219 | - ); |
|
220 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
221 | - $this, |
|
222 | - $closed_reg_statuses, |
|
223 | - false |
|
224 | - ); |
|
225 | - do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * get Status ID |
|
232 | - */ |
|
233 | - public function status_ID() |
|
234 | - { |
|
235 | - return $this->get('STS_ID'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
241 | - * |
|
242 | - * @return void |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - private function _reserve_registration_space() |
|
246 | - { |
|
247 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
248 | - // so stop tracking that this reg has a ticket reserved |
|
249 | - $this->release_reserved_ticket(); |
|
250 | - $ticket = $this->ticket(); |
|
251 | - $ticket->increase_sold(); |
|
252 | - $ticket->save(); |
|
253 | - // possibly set event status to sold out |
|
254 | - $this->event()->perform_sold_out_status_check(); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Gets the ticket this registration is for |
|
260 | - * |
|
261 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
262 | - * @return EE_Ticket|EE_Base_Class |
|
263 | - * @throws \EE_Error |
|
264 | - */ |
|
265 | - public function ticket($include_archived = true) |
|
266 | - { |
|
267 | - $query_params = array(); |
|
268 | - if ($include_archived) { |
|
269 | - $query_params['default_where_conditions'] = 'none'; |
|
270 | - } |
|
271 | - return $this->get_first_related('Ticket', $query_params); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Gets the event this registration is for |
|
277 | - * |
|
278 | - * @return EE_Event |
|
279 | - */ |
|
280 | - public function event() |
|
281 | - { |
|
282 | - $event = $this->get_first_related('Event'); |
|
283 | - if (! $event instanceof \EE_Event) { |
|
284 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
285 | - } |
|
286 | - return $event; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
292 | - * with the author of the event this registration is for. |
|
293 | - * |
|
294 | - * @since 4.5.0 |
|
295 | - * @return int |
|
296 | - */ |
|
297 | - public function wp_user() |
|
298 | - { |
|
299 | - $event = $this->event(); |
|
300 | - if ($event instanceof EE_Event) { |
|
301 | - return $event->wp_user(); |
|
302 | - } |
|
303 | - return 0; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
309 | - * |
|
310 | - * @return void |
|
311 | - * @throws \EE_Error |
|
312 | - */ |
|
313 | - private function _release_registration_space() |
|
314 | - { |
|
315 | - $ticket = $this->ticket(); |
|
316 | - $ticket->decrease_sold(); |
|
317 | - $ticket->save(); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * tracks this registration's ticket reservation in extra meta |
|
323 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
324 | - * |
|
325 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
326 | - * @return void |
|
327 | - * @throws \EE_Error |
|
328 | - */ |
|
329 | - public function reserve_ticket($update_ticket = false) |
|
330 | - { |
|
331 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
332 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
333 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
334 | - if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
335 | - $ticket = $this->ticket(); |
|
336 | - $ticket->increase_reserved(); |
|
337 | - $ticket->save(); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * stops tracking this registration's ticket reservation in extra meta |
|
345 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
346 | - * |
|
347 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
348 | - * @return void |
|
349 | - * @throws \EE_Error |
|
350 | - */ |
|
351 | - public function release_reserved_ticket($update_ticket = false) |
|
352 | - { |
|
353 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
354 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
355 | - // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
356 | - if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
357 | - $ticket = $this->ticket(); |
|
358 | - $ticket->decrease_reserved(); |
|
359 | - $ticket->save(); |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Set Attendee ID |
|
367 | - * |
|
368 | - * @param int $ATT_ID Attendee ID |
|
369 | - */ |
|
370 | - public function set_attendee_id($ATT_ID = 0) |
|
371 | - { |
|
372 | - $this->set('ATT_ID', $ATT_ID); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Set Transaction ID |
|
378 | - * |
|
379 | - * @param int $TXN_ID Transaction ID |
|
380 | - */ |
|
381 | - public function set_transaction_id($TXN_ID = 0) |
|
382 | - { |
|
383 | - $this->set('TXN_ID', $TXN_ID); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * Set Session |
|
389 | - * |
|
390 | - * @param string $REG_session PHP Session ID |
|
391 | - */ |
|
392 | - public function set_session($REG_session = '') |
|
393 | - { |
|
394 | - $this->set('REG_session', $REG_session); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * Set Registration URL Link |
|
400 | - * |
|
401 | - * @param string $REG_url_link Registration URL Link |
|
402 | - */ |
|
403 | - public function set_reg_url_link($REG_url_link = '') |
|
404 | - { |
|
405 | - $this->set('REG_url_link', $REG_url_link); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * Set Attendee Counter |
|
411 | - * |
|
412 | - * @param int $REG_count Primary Attendee |
|
413 | - */ |
|
414 | - public function set_count($REG_count = 1) |
|
415 | - { |
|
416 | - $this->set('REG_count', $REG_count); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Set Group Size |
|
422 | - * |
|
423 | - * @param boolean $REG_group_size Group Registration |
|
424 | - */ |
|
425 | - public function set_group_size($REG_group_size = false) |
|
426 | - { |
|
427 | - $this->set('REG_group_size', $REG_group_size); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
433 | - * EEM_Registration::status_id_not_approved |
|
434 | - * |
|
435 | - * @return boolean |
|
436 | - */ |
|
437 | - public function is_not_approved() |
|
438 | - { |
|
439 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
445 | - * EEM_Registration::status_id_pending_payment |
|
446 | - * |
|
447 | - * @return boolean |
|
448 | - */ |
|
449 | - public function is_pending_payment() |
|
450 | - { |
|
451 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
457 | - * |
|
458 | - * @return boolean |
|
459 | - */ |
|
460 | - public function is_approved() |
|
461 | - { |
|
462 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
468 | - * |
|
469 | - * @return boolean |
|
470 | - */ |
|
471 | - public function is_cancelled() |
|
472 | - { |
|
473 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
479 | - * |
|
480 | - * @return boolean |
|
481 | - */ |
|
482 | - public function is_declined() |
|
483 | - { |
|
484 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
490 | - * EEM_Registration::status_id_incomplete |
|
491 | - * |
|
492 | - * @return boolean |
|
493 | - */ |
|
494 | - public function is_incomplete() |
|
495 | - { |
|
496 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * Set Registration Date |
|
502 | - * |
|
503 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
504 | - * Date |
|
505 | - */ |
|
506 | - public function set_reg_date($REG_date = false) |
|
507 | - { |
|
508 | - $this->set('REG_date', $REG_date); |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Set final price owing for this registration after all ticket/price modifications |
|
514 | - * |
|
515 | - * @access public |
|
516 | - * @param float $REG_final_price |
|
517 | - */ |
|
518 | - public function set_final_price($REG_final_price = 0.00) |
|
519 | - { |
|
520 | - $this->set('REG_final_price', $REG_final_price); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * Set amount paid towards this registration's final price |
|
526 | - * |
|
527 | - * @access public |
|
528 | - * @param float $REG_paid |
|
529 | - */ |
|
530 | - public function set_paid($REG_paid = 0.00) |
|
531 | - { |
|
532 | - $this->set('REG_paid', $REG_paid); |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * Attendee Is Going |
|
538 | - * |
|
539 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
540 | - */ |
|
541 | - public function set_att_is_going($REG_att_is_going = false) |
|
542 | - { |
|
543 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * Gets the related attendee |
|
549 | - * |
|
550 | - * @return EE_Attendee |
|
551 | - */ |
|
552 | - public function attendee() |
|
553 | - { |
|
554 | - return $this->get_first_related('Attendee'); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * get Event ID |
|
560 | - */ |
|
561 | - public function event_ID() |
|
562 | - { |
|
563 | - return $this->get('EVT_ID'); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * get Event ID |
|
569 | - */ |
|
570 | - public function event_name() |
|
571 | - { |
|
572 | - $event = $this->event_obj(); |
|
573 | - if ($event) { |
|
574 | - return $event->name(); |
|
575 | - } else { |
|
576 | - return null; |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Fetches the event this registration is for |
|
583 | - * |
|
584 | - * @return EE_Event |
|
585 | - */ |
|
586 | - public function event_obj() |
|
587 | - { |
|
588 | - return $this->get_first_related('Event'); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * get Attendee ID |
|
594 | - */ |
|
595 | - public function attendee_ID() |
|
596 | - { |
|
597 | - return $this->get('ATT_ID'); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * get PHP Session ID |
|
603 | - */ |
|
604 | - public function session_ID() |
|
605 | - { |
|
606 | - return $this->get('REG_session'); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
612 | - * |
|
613 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
614 | - * @return string |
|
615 | - */ |
|
616 | - public function receipt_url($messenger = 'html') |
|
617 | - { |
|
618 | - |
|
619 | - /** |
|
620 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template already in use on old system. If there is then we just return the standard url for it. |
|
621 | - * |
|
622 | - * @since 4.5.0 |
|
623 | - */ |
|
624 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
625 | - $has_custom = EEH_Template::locate_template($template_relative_path, array(), true, true, true); |
|
626 | - |
|
627 | - if ($has_custom) { |
|
628 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
629 | - } |
|
630 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
636 | - * |
|
637 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - public function invoice_url($messenger = 'html') |
|
641 | - { |
|
642 | - /** |
|
643 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template already in use on old system. If there is then we just return the standard url for it. |
|
644 | - * |
|
645 | - * @since 4.5.0 |
|
646 | - */ |
|
647 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
648 | - $has_custom = EEH_Template::locate_template($template_relative_path, array(), true, true, true); |
|
649 | - |
|
650 | - if ($has_custom) { |
|
651 | - if ($messenger == 'html') { |
|
652 | - return $this->invoice_url('launch'); |
|
653 | - } |
|
654 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
655 | - |
|
656 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
657 | - if ($messenger == 'html') { |
|
658 | - $query_args['html'] = true; |
|
659 | - } |
|
660 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
661 | - } |
|
662 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * get Registration URL Link |
|
668 | - * |
|
669 | - * @access public |
|
670 | - * @return string |
|
671 | - * @throws \EE_Error |
|
672 | - */ |
|
673 | - public function reg_url_link() |
|
674 | - { |
|
675 | - return (string)$this->get('REG_url_link'); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Echoes out invoice_url() |
|
681 | - * |
|
682 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - public function e_invoice_url($type = 'launch') |
|
686 | - { |
|
687 | - echo $this->invoice_url($type); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * Echoes out payment_overview_url |
|
693 | - */ |
|
694 | - public function e_payment_overview_url() |
|
695 | - { |
|
696 | - echo $this->payment_overview_url(); |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
702 | - * a query parameter |
|
703 | - * |
|
704 | - * @return string |
|
705 | - */ |
|
706 | - public function payment_overview_url() |
|
707 | - { |
|
708 | - return add_query_arg(array( |
|
709 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
710 | - 'step' => 'payment_options', |
|
711 | - 'revisit' => true, |
|
712 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
718 | - * a query parameter |
|
719 | - * |
|
720 | - * @return string |
|
721 | - */ |
|
722 | - public function edit_attendee_information_url() |
|
723 | - { |
|
724 | - return add_query_arg(array( |
|
725 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
726 | - 'step' => 'attendee_information', |
|
727 | - 'revisit' => true, |
|
728 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
734 | - * |
|
735 | - * @return string |
|
736 | - */ |
|
737 | - public function get_admin_edit_url() |
|
738 | - { |
|
739 | - return EEH_URL::add_query_args_and_nonce(array( |
|
740 | - 'page' => 'espresso_registrations', |
|
741 | - 'action' => 'view_registration', |
|
742 | - '_REG_ID' => $this->ID(), |
|
743 | - ), admin_url('admin.php')); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * is_primary_registrant? |
|
749 | - */ |
|
750 | - public function is_primary_registrant() |
|
751 | - { |
|
752 | - return $this->get('REG_count') == 1 ? true : false; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * This returns the primary registration object for this registration group (which may be this object). |
|
758 | - * |
|
759 | - * @return EE_Registration |
|
760 | - */ |
|
761 | - public function get_primary_registration() |
|
762 | - { |
|
763 | - if ($this->is_primary_registrant()) { |
|
764 | - return $this; |
|
765 | - } |
|
766 | - |
|
767 | - //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
768 | - $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
769 | - array( |
|
770 | - 'TXN_ID' => $this->transaction_ID(), |
|
771 | - 'REG_count' => 1, |
|
772 | - ), |
|
773 | - )); |
|
774 | - return $primary_registrant; |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * get Attendee Number |
|
780 | - * |
|
781 | - * @access public |
|
782 | - */ |
|
783 | - public function count() |
|
784 | - { |
|
785 | - return $this->get('REG_count'); |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * get Group Size |
|
791 | - */ |
|
792 | - public function group_size() |
|
793 | - { |
|
794 | - return $this->get('REG_group_size'); |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - /** |
|
799 | - * get Registration Date |
|
800 | - */ |
|
801 | - public function date() |
|
802 | - { |
|
803 | - return $this->get('REG_date'); |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * gets a pretty date |
|
809 | - * |
|
810 | - * @param string $date_format |
|
811 | - * @param string $time_format |
|
812 | - * @return string |
|
813 | - */ |
|
814 | - public function pretty_date($date_format = null, $time_format = null) |
|
815 | - { |
|
816 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * final_price |
|
822 | - * the registration's share of the transaction total, so that the |
|
823 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
824 | - * |
|
825 | - * @return float |
|
826 | - */ |
|
827 | - public function final_price() |
|
828 | - { |
|
829 | - return $this->get('REG_final_price'); |
|
830 | - } |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * pretty_final_price |
|
835 | - * final price as formatted string, with correct decimal places and currency symbol |
|
836 | - * |
|
837 | - * @return string |
|
838 | - */ |
|
839 | - public function pretty_final_price() |
|
840 | - { |
|
841 | - return $this->get_pretty('REG_final_price'); |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * get paid (yeah) |
|
847 | - * |
|
848 | - * @return float |
|
849 | - */ |
|
850 | - public function paid() |
|
851 | - { |
|
852 | - return $this->get('REG_paid'); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * pretty_paid |
|
858 | - * |
|
859 | - * @return float |
|
860 | - */ |
|
861 | - public function pretty_paid() |
|
862 | - { |
|
863 | - return $this->get_pretty('REG_paid'); |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * owes_monies_and_can_pay |
|
869 | - * whether or not this registration has monies owing and it's' status allows payment |
|
870 | - * |
|
871 | - * @param array $requires_payment |
|
872 | - * @return bool |
|
873 | - */ |
|
874 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
875 | - { |
|
876 | - // these reg statuses require payment (if event is not free) |
|
877 | - $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
878 | - if ( |
|
879 | - in_array($this->status_ID(), $requires_payment) && |
|
880 | - $this->final_price() != 0 && |
|
881 | - $this->final_price() != $this->paid() |
|
882 | - ) { |
|
883 | - return true; |
|
884 | - } else { |
|
885 | - return false; |
|
886 | - } |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * Prints out the return value of $this->pretty_status() |
|
892 | - * |
|
893 | - * @param bool $show_icons |
|
894 | - * @return void |
|
895 | - */ |
|
896 | - public function e_pretty_status($show_icons = false) |
|
897 | - { |
|
898 | - echo $this->pretty_status($show_icons); |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * Returns a nice version of the status for displaying to customers |
|
904 | - * |
|
905 | - * @param bool $show_icons |
|
906 | - * @return string |
|
907 | - */ |
|
908 | - public function pretty_status($show_icons = false) |
|
909 | - { |
|
910 | - $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), |
|
911 | - false, 'sentence'); |
|
912 | - $icon = ''; |
|
913 | - switch ($this->status_ID()) { |
|
914 | - case EEM_Registration::status_id_approved: |
|
915 | - $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : ''; |
|
916 | - break; |
|
917 | - case EEM_Registration::status_id_pending_payment: |
|
918 | - $icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : ''; |
|
919 | - break; |
|
920 | - case EEM_Registration::status_id_not_approved: |
|
921 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : ''; |
|
922 | - break; |
|
923 | - case EEM_Registration::status_id_cancelled: |
|
924 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : ''; |
|
925 | - break; |
|
926 | - case EEM_Registration::status_id_incomplete: |
|
927 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : ''; |
|
928 | - break; |
|
929 | - case EEM_Registration::status_id_declined: |
|
930 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
931 | - break; |
|
932 | - case EEM_Registration::status_id_wait_list: |
|
933 | - $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
|
934 | - break; |
|
935 | - } |
|
936 | - return $icon . $status[$this->status_ID()]; |
|
937 | - } |
|
938 | - |
|
939 | - |
|
940 | - /** |
|
941 | - * get Attendee Is Going |
|
942 | - */ |
|
943 | - public function att_is_going() |
|
944 | - { |
|
945 | - return $this->get('REG_att_is_going'); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * Gets related answers |
|
951 | - * |
|
952 | - * @param array $query_params like EEM_Base::get_all |
|
953 | - * @return EE_Answer[] |
|
954 | - */ |
|
955 | - public function answers($query_params = null) |
|
956 | - { |
|
957 | - return $this->get_many_related('Answer', $query_params); |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * Gets the registration's answer value to the specified question |
|
963 | - * (either the question's ID or a question object) |
|
964 | - * |
|
965 | - * @param EE_Question|int $question |
|
966 | - * @param bool $pretty_value |
|
967 | - * @return array|string if pretty_value= true, the result will always be a string |
|
968 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
969 | - * will convert it into some kind of string) |
|
970 | - */ |
|
971 | - public function answer_value_to_question($question, $pretty_value = true) |
|
972 | - { |
|
973 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
974 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
975 | - } |
|
976 | - |
|
977 | - |
|
978 | - /** |
|
979 | - * question_groups |
|
980 | - * returns an array of EE_Question_Group objects for this registration |
|
981 | - * |
|
982 | - * @return EE_Question_Group[] |
|
983 | - */ |
|
984 | - public function question_groups() |
|
985 | - { |
|
986 | - $question_groups = array(); |
|
987 | - if ($this->event() instanceof EE_Event) { |
|
988 | - $question_groups = $this->event()->question_groups( |
|
989 | - array( |
|
990 | - array( |
|
991 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
992 | - ), |
|
993 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
994 | - ) |
|
995 | - ); |
|
996 | - } |
|
997 | - return $question_groups; |
|
998 | - } |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * count_question_groups |
|
1003 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
1004 | - * |
|
1005 | - * @return int |
|
1006 | - */ |
|
1007 | - public function count_question_groups() |
|
1008 | - { |
|
1009 | - $qg_count = 0; |
|
1010 | - if ($this->event() instanceof EE_Event) { |
|
1011 | - $qg_count = $this->event()->count_related( |
|
1012 | - 'Question_Group', |
|
1013 | - array( |
|
1014 | - array( |
|
1015 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1016 | - ), |
|
1017 | - ) |
|
1018 | - ); |
|
1019 | - } |
|
1020 | - return $qg_count; |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * Returns the registration date in the 'standard' string format |
|
1026 | - * (function may be improved in the future to allow for different formats and timezones) |
|
1027 | - * |
|
1028 | - * @return string |
|
1029 | - */ |
|
1030 | - public function reg_date() |
|
1031 | - { |
|
1032 | - return $this->get_datetime('REG_date'); |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1038 | - * the ticket this registration purchased, or the datetime they have registered |
|
1039 | - * to attend) |
|
1040 | - * |
|
1041 | - * @return EE_Datetime_Ticket |
|
1042 | - */ |
|
1043 | - public function datetime_ticket() |
|
1044 | - { |
|
1045 | - return $this->get_first_related('Datetime_Ticket'); |
|
1046 | - } |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Sets the registration's datetime_ticket. |
|
1051 | - * |
|
1052 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
1053 | - * @return EE_Datetime_Ticket |
|
1054 | - */ |
|
1055 | - public function set_datetime_ticket($datetime_ticket) |
|
1056 | - { |
|
1057 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Gets deleted |
|
1062 | - * |
|
1063 | - * @return boolean |
|
1064 | - */ |
|
1065 | - public function deleted() |
|
1066 | - { |
|
1067 | - return $this->get('REG_deleted'); |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Sets deleted |
|
1072 | - * |
|
1073 | - * @param boolean $deleted |
|
1074 | - * @return boolean |
|
1075 | - */ |
|
1076 | - public function set_deleted($deleted) |
|
1077 | - { |
|
1078 | - if ($deleted) { |
|
1079 | - $this->delete(); |
|
1080 | - } else { |
|
1081 | - $this->restore(); |
|
1082 | - } |
|
1083 | - } |
|
1084 | - |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * Get the status object of this object |
|
1088 | - * |
|
1089 | - * @return EE_Status |
|
1090 | - */ |
|
1091 | - public function status_obj() |
|
1092 | - { |
|
1093 | - return $this->get_first_related('Status'); |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Returns the number of times this registration has checked into any of the datetimes |
|
1099 | - * its available for |
|
1100 | - * |
|
1101 | - * @return int |
|
1102 | - */ |
|
1103 | - public function count_checkins() |
|
1104 | - { |
|
1105 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
1106 | - } |
|
1107 | - |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1111 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1112 | - * |
|
1113 | - * @return int |
|
1114 | - */ |
|
1115 | - public function count_checkins_not_checkedout() |
|
1116 | - { |
|
1117 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1123 | - * |
|
1124 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1125 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1126 | - * consider registration status as well as datetime access. |
|
1127 | - * @return bool |
|
1128 | - */ |
|
1129 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1130 | - { |
|
1131 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1132 | - |
|
1133 | - //first check registration status |
|
1134 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1135 | - return false; |
|
1136 | - } |
|
1137 | - //is there a datetime ticket that matches this dtt_ID? |
|
1138 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1139 | - array( |
|
1140 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
1141 | - 'DTT_ID' => $DTT_ID, |
|
1142 | - ), |
|
1143 | - ))) |
|
1144 | - ) { |
|
1145 | - return false; |
|
1146 | - } |
|
1147 | - |
|
1148 | - //final check is against TKT_uses |
|
1149 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1150 | - } |
|
1151 | - |
|
1152 | - |
|
1153 | - /** |
|
1154 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1155 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1156 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1157 | - * then return false. Otherwise return true. |
|
1158 | - * |
|
1159 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1160 | - * @return bool true means can checkin. false means cannot checkin. |
|
1161 | - */ |
|
1162 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1163 | - { |
|
1164 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1165 | - |
|
1166 | - if (! $DTT_ID) { |
|
1167 | - return false; |
|
1168 | - } |
|
1169 | - |
|
1170 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1171 | - |
|
1172 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
|
1173 | - // or not. |
|
1174 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1175 | - return true; |
|
1176 | - } |
|
1177 | - |
|
1178 | - //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1179 | - //go ahead and toggle. |
|
1180 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1181 | - return true; |
|
1182 | - } |
|
1183 | - |
|
1184 | - //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1185 | - //disallows further check-ins. |
|
1186 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
1187 | - array( |
|
1188 | - 'REG_ID' => $this->ID(), |
|
1189 | - 'CHK_in' => true, |
|
1190 | - ), |
|
1191 | - ), 'DTT_ID', true); |
|
1192 | - // checkins have already reached their max number of uses |
|
1193 | - // so registrant can NOT checkin |
|
1194 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
1195 | - EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1196 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1197 | - return false; |
|
1198 | - } |
|
1199 | - return true; |
|
1200 | - } |
|
1201 | - |
|
1202 | - |
|
1203 | - /** |
|
1204 | - * toggle Check-in status for this registration |
|
1205 | - * Check-ins are toggled in the following order: |
|
1206 | - * never checked in -> checked in |
|
1207 | - * checked in -> checked out |
|
1208 | - * checked out -> checked in |
|
1209 | - * |
|
1210 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1211 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1212 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1213 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1214 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1215 | - * @throws EE_Error |
|
1216 | - */ |
|
1217 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1218 | - { |
|
1219 | - if (empty($DTT_ID)) { |
|
1220 | - $datetime = $this->get_latest_related_datetime(); |
|
1221 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1222 | - // verify the registration can checkin for the given DTT_ID |
|
1223 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1224 | - EE_Error::add_error( |
|
1225 | - sprintf( |
|
1226 | - __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1227 | - 'event_espresso'), |
|
1228 | - $this->ID(), |
|
1229 | - $DTT_ID |
|
1230 | - ), |
|
1231 | - __FILE__, __FUNCTION__, __LINE__ |
|
1232 | - ); |
|
1233 | - return false; |
|
1234 | - } |
|
1235 | - $status_paths = array( |
|
1236 | - EE_Registration::checkin_status_never => EE_Registration::checkin_status_in, |
|
1237 | - EE_Registration::checkin_status_in => EE_Registration::checkin_status_out, |
|
1238 | - EE_Registration::checkin_status_out => EE_Registration::checkin_status_in, |
|
1239 | - ); |
|
1240 | - //start by getting the current status so we know what status we'll be changing to. |
|
1241 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1242 | - $status_to = $status_paths[$cur_status]; |
|
1243 | - // database only records true for checked IN or false for checked OUT |
|
1244 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1245 | - $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; |
|
1246 | - // add relation - note Check-ins are always creating new rows |
|
1247 | - // because we are keeping track of Check-ins over time. |
|
1248 | - // Eventually we'll probably want to show a list table |
|
1249 | - // for the individual Check-ins so that they can be managed. |
|
1250 | - $checkin = EE_Checkin::new_instance(array( |
|
1251 | - 'REG_ID' => $this->ID(), |
|
1252 | - 'DTT_ID' => $DTT_ID, |
|
1253 | - 'CHK_in' => $new_status, |
|
1254 | - )); |
|
1255 | - // if the record could not be saved then return false |
|
1256 | - if ($checkin->save() === 0) { |
|
1257 | - if (WP_DEBUG) { |
|
1258 | - global $wpdb; |
|
1259 | - $error = sprintf( |
|
1260 | - __('Registration check in update failed because of the following database error: %1$s%2$s', |
|
1261 | - 'event_espresso'), |
|
1262 | - '<br />', |
|
1263 | - $wpdb->last_error |
|
1264 | - ); |
|
1265 | - } else { |
|
1266 | - $error = __('Registration check in update failed because of an unknown database error', |
|
1267 | - 'event_espresso'); |
|
1268 | - } |
|
1269 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1270 | - return false; |
|
1271 | - } |
|
1272 | - return $status_to; |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1278 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1279 | - * |
|
1280 | - * @return EE_Datetime|null |
|
1281 | - * @throws \EE_Error |
|
1282 | - */ |
|
1283 | - public function get_latest_related_datetime() |
|
1284 | - { |
|
1285 | - return EEM_Datetime::instance()->get_one( |
|
1286 | - array( |
|
1287 | - array( |
|
1288 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1289 | - ), |
|
1290 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1291 | - ) |
|
1292 | - ); |
|
1293 | - } |
|
1294 | - |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1298 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1299 | - * |
|
1300 | - * @throws \EE_Error |
|
1301 | - */ |
|
1302 | - public function get_earliest_related_datetime() |
|
1303 | - { |
|
1304 | - return EEM_Datetime::instance()->get_one( |
|
1305 | - array( |
|
1306 | - array( |
|
1307 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1308 | - ), |
|
1309 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1310 | - ) |
|
1311 | - ); |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1317 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1318 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1319 | - * |
|
1320 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1321 | - * (if empty we'll get the primary datetime for |
|
1322 | - * this registration (via event) and use it's ID); |
|
1323 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1324 | - * @return int Integer representing Check-in status. |
|
1325 | - * @throws \EE_Error |
|
1326 | - */ |
|
1327 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1328 | - { |
|
1329 | - $checkin_query_params = array( |
|
1330 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1331 | - ); |
|
1332 | - |
|
1333 | - if ($DTT_ID > 0) { |
|
1334 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1335 | - } |
|
1336 | - |
|
1337 | - //get checkin object (if exists) |
|
1338 | - $checkin = $checkin instanceof EE_Checkin |
|
1339 | - ? $checkin |
|
1340 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
1341 | - if ($checkin instanceof EE_Checkin) { |
|
1342 | - if ($checkin->get('CHK_in')) { |
|
1343 | - return EE_Registration::checkin_status_in; //checked in |
|
1344 | - } |
|
1345 | - return EE_Registration::checkin_status_out; //had checked in but is now checked out. |
|
1346 | - } |
|
1347 | - return EE_Registration::checkin_status_never; //never been checked in |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * This method returns a localized message for the toggled Check-in message. |
|
1353 | - * |
|
1354 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1355 | - * then it is assumed Check-in for primary datetime was toggled. |
|
1356 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1357 | - * message can be customized with the attendee name. |
|
1358 | - * @return string internationalized message |
|
1359 | - */ |
|
1360 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
1361 | - { |
|
1362 | - //let's get the attendee first so we can include the name of the attendee |
|
1363 | - $attendee = $this->get_first_related('Attendee'); |
|
1364 | - if ($attendee instanceof EE_Attendee) { |
|
1365 | - if ($error) { |
|
1366 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1367 | - } |
|
1368 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1369 | - //what is the status message going to be? |
|
1370 | - switch ($cur_status) { |
|
1371 | - case EE_Registration::checkin_status_never : |
|
1372 | - return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
1373 | - $attendee->full_name()); |
|
1374 | - break; |
|
1375 | - case EE_Registration::checkin_status_in : |
|
1376 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1377 | - break; |
|
1378 | - case EE_Registration::checkin_status_out : |
|
1379 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1380 | - break; |
|
1381 | - } |
|
1382 | - } |
|
1383 | - return __("The check-in status could not be determined.", "event_espresso"); |
|
1384 | - } |
|
1385 | - |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Returns the related EE_Transaction to this registration |
|
1389 | - * |
|
1390 | - * @return EE_Transaction |
|
1391 | - */ |
|
1392 | - public function transaction() |
|
1393 | - { |
|
1394 | - $transaction = $this->get_first_related('Transaction'); |
|
1395 | - if (! $transaction instanceof \EE_Transaction) { |
|
1396 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1397 | - } |
|
1398 | - return $transaction; |
|
1399 | - } |
|
1400 | - |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * get Registration Code |
|
1404 | - */ |
|
1405 | - public function reg_code() |
|
1406 | - { |
|
1407 | - return $this->get('REG_code'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - |
|
1411 | - /** |
|
1412 | - * get Transaction ID |
|
1413 | - */ |
|
1414 | - public function transaction_ID() |
|
1415 | - { |
|
1416 | - return $this->get('TXN_ID'); |
|
1417 | - } |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * @return int |
|
1422 | - */ |
|
1423 | - public function ticket_ID() |
|
1424 | - { |
|
1425 | - return $this->get('TKT_ID'); |
|
1426 | - } |
|
1427 | - |
|
1428 | - |
|
1429 | - /** |
|
1430 | - * Set Registration Code |
|
1431 | - * |
|
1432 | - * @access public |
|
1433 | - * @param string $REG_code Registration Code |
|
1434 | - * @param boolean $use_default |
|
1435 | - */ |
|
1436 | - public function set_reg_code($REG_code, $use_default = false) |
|
1437 | - { |
|
1438 | - if (empty($REG_code)) { |
|
1439 | - EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1440 | - return; |
|
1441 | - } |
|
1442 | - if (! $this->reg_code()) { |
|
1443 | - parent::set('REG_code', $REG_code, $use_default); |
|
1444 | - } else { |
|
1445 | - EE_Error::doing_it_wrong( |
|
1446 | - __CLASS__ . '::' . __FUNCTION__, |
|
1447 | - __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1448 | - '4.6.0' |
|
1449 | - ); |
|
1450 | - } |
|
1451 | - } |
|
1452 | - |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1456 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1457 | - * $registration->transaction()->registrations(); |
|
1458 | - * |
|
1459 | - * @since 4.5.0 |
|
1460 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1461 | - */ |
|
1462 | - public function get_all_other_registrations_in_group() |
|
1463 | - { |
|
1464 | - if ($this->group_size() < 2) { |
|
1465 | - return array(); |
|
1466 | - } |
|
1467 | - |
|
1468 | - $query[0] = array( |
|
1469 | - 'TXN_ID' => $this->transaction_ID(), |
|
1470 | - 'REG_ID' => array('!=', $this->ID()), |
|
1471 | - 'TKT_ID' => $this->ticket_ID(), |
|
1472 | - ); |
|
1473 | - |
|
1474 | - $registrations = $this->get_model()->get_all($query); |
|
1475 | - return $registrations; |
|
1476 | - } |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Return the link to the admin details for the object. |
|
1480 | - * |
|
1481 | - * @return string |
|
1482 | - */ |
|
1483 | - public function get_admin_details_link() |
|
1484 | - { |
|
1485 | - EE_Registry::instance()->load_helper('URL'); |
|
1486 | - return EEH_URL::add_query_args_and_nonce( |
|
1487 | - array( |
|
1488 | - 'page' => 'espresso_registrations', |
|
1489 | - 'action' => 'view_registration', |
|
1490 | - '_REG_ID' => $this->ID(), |
|
1491 | - ), |
|
1492 | - admin_url('admin.php') |
|
1493 | - ); |
|
1494 | - } |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1498 | - * |
|
1499 | - * @return string |
|
1500 | - */ |
|
1501 | - public function get_admin_edit_link() |
|
1502 | - { |
|
1503 | - return $this->get_admin_details_link(); |
|
1504 | - } |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * Returns the link to a settings page for the object. |
|
1508 | - * |
|
1509 | - * @return string |
|
1510 | - */ |
|
1511 | - public function get_admin_settings_link() |
|
1512 | - { |
|
1513 | - return $this->get_admin_details_link(); |
|
1514 | - } |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1518 | - * |
|
1519 | - * @return string |
|
1520 | - */ |
|
1521 | - public function get_admin_overview_link() |
|
1522 | - { |
|
1523 | - EE_Registry::instance()->load_helper('URL'); |
|
1524 | - return EEH_URL::add_query_args_and_nonce( |
|
1525 | - array( |
|
1526 | - 'page' => 'espresso_registrations', |
|
1527 | - ), |
|
1528 | - admin_url('admin.php') |
|
1529 | - ); |
|
1530 | - } |
|
1531 | - |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * @param array $query_params |
|
1535 | - * @return \EE_Registration[] |
|
1536 | - * @throws \EE_Error |
|
1537 | - */ |
|
1538 | - public function payments($query_params = array()) |
|
1539 | - { |
|
1540 | - return $this->get_many_related('Payment', $query_params); |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - /** |
|
1545 | - * @param array $query_params |
|
1546 | - * @return \EE_Registration_Payment[] |
|
1547 | - * @throws \EE_Error |
|
1548 | - */ |
|
1549 | - public function registration_payments($query_params = array()) |
|
1550 | - { |
|
1551 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
1552 | - } |
|
1553 | - |
|
1554 | - |
|
1555 | - /** |
|
1556 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1557 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
1558 | - * |
|
1559 | - * @return EE_Payment_Method|null |
|
1560 | - */ |
|
1561 | - public function payment_method() |
|
1562 | - { |
|
1563 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1564 | - } |
|
1565 | - |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * @return \EE_Line_Item |
|
1569 | - * @throws EntityNotFoundException |
|
1570 | - * @throws \EE_Error |
|
1571 | - */ |
|
1572 | - public function ticket_line_item() |
|
1573 | - { |
|
1574 | - $ticket = $this->ticket(); |
|
1575 | - $transaction = $this->transaction(); |
|
1576 | - $line_item = null; |
|
1577 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1578 | - $transaction->total_line_item(), |
|
1579 | - 'Ticket', |
|
1580 | - array($ticket->ID()) |
|
1581 | - ); |
|
1582 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
1583 | - if ( |
|
1584 | - $ticket_line_item instanceof \EE_Line_Item |
|
1585 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1586 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1587 | - ) { |
|
1588 | - $line_item = $ticket_line_item; |
|
1589 | - break; |
|
1590 | - } |
|
1591 | - } |
|
1592 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1593 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1594 | - } |
|
1595 | - return $line_item; |
|
1596 | - } |
|
1597 | - |
|
1598 | - |
|
1599 | - /** |
|
1600 | - * Soft Deletes this model object. |
|
1601 | - * |
|
1602 | - * @return boolean | int |
|
1603 | - * @throws \RuntimeException |
|
1604 | - * @throws \EE_Error |
|
1605 | - */ |
|
1606 | - public function delete() |
|
1607 | - { |
|
1608 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1609 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
1610 | - } |
|
1611 | - return parent::delete(); |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1617 | - * |
|
1618 | - * @throws \EE_Error |
|
1619 | - * @throws \RuntimeException |
|
1620 | - */ |
|
1621 | - public function restore() |
|
1622 | - { |
|
1623 | - $previous_status = $this->get_extra_meta( |
|
1624 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1625 | - true, |
|
1626 | - EEM_Registration::status_id_cancelled |
|
1627 | - ); |
|
1628 | - if ($previous_status) { |
|
1629 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1630 | - $this->set_status($previous_status); |
|
1631 | - } |
|
1632 | - return parent::restore(); |
|
1633 | - } |
|
1634 | - |
|
1635 | - |
|
1636 | - |
|
1637 | - /*************************** DEPRECATED ***************************/ |
|
1638 | - |
|
1639 | - |
|
1640 | - /** |
|
1641 | - * @deprecated |
|
1642 | - * @since 4.7.0 |
|
1643 | - * @access public |
|
1644 | - */ |
|
1645 | - public function price_paid() |
|
1646 | - { |
|
1647 | - EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
1648 | - __('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
1649 | - '4.7.0'); |
|
1650 | - return $this->final_price(); |
|
1651 | - } |
|
1652 | - |
|
1653 | - |
|
1654 | - /** |
|
1655 | - * @deprecated |
|
1656 | - * @since 4.7.0 |
|
1657 | - * @access public |
|
1658 | - * @param float $REG_final_price |
|
1659 | - */ |
|
1660 | - public function set_price_paid($REG_final_price = 0.00) |
|
1661 | - { |
|
1662 | - EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
1663 | - __('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
1664 | - '4.7.0'); |
|
1665 | - $this->set_final_price($REG_final_price); |
|
1666 | - } |
|
1667 | - |
|
1668 | - |
|
1669 | - /** |
|
1670 | - * @deprecated |
|
1671 | - * @since 4.7.0 |
|
1672 | - * @return string |
|
1673 | - */ |
|
1674 | - public function pretty_price_paid() |
|
1675 | - { |
|
1676 | - EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
1677 | - __('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
1678 | - 'event_espresso'), '4.7.0'); |
|
1679 | - return $this->pretty_final_price(); |
|
1680 | - } |
|
1681 | - |
|
1682 | - |
|
1683 | - /** |
|
1684 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
1685 | - * |
|
1686 | - * @deprecated 4.9.17 |
|
1687 | - * @return EE_Datetime |
|
1688 | - */ |
|
1689 | - public function get_related_primary_datetime() |
|
1690 | - { |
|
1691 | - EE_Error::doing_it_wrong( |
|
1692 | - __METHOD__, |
|
1693 | - esc_html__( |
|
1694 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1695 | - 'event_espresso' |
|
1696 | - ), |
|
1697 | - '4.9.17', |
|
1698 | - '5.0.0' |
|
1699 | - ); |
|
1700 | - return $this->event()->primary_datetime(); |
|
1701 | - } |
|
18 | + /** |
|
19 | + * Used to reference when a registration has never been checked in. |
|
20 | + * |
|
21 | + * @type int |
|
22 | + */ |
|
23 | + const checkin_status_never = 2; |
|
24 | + |
|
25 | + /** |
|
26 | + * Used to reference when a registration has been checked in. |
|
27 | + * |
|
28 | + * @type int |
|
29 | + */ |
|
30 | + const checkin_status_in = 1; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Used to reference when a registration has been checked out. |
|
35 | + * |
|
36 | + * @type int |
|
37 | + */ |
|
38 | + const checkin_status_out = 0; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * extra meta key for tracking reg status os trashed registrations |
|
43 | + * |
|
44 | + * @type string |
|
45 | + */ |
|
46 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * extra meta key for tracking if registration has reserved ticket |
|
51 | + * |
|
52 | + * @type string |
|
53 | + */ |
|
54 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $props_n_values incoming values |
|
59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
60 | + * used.) |
|
61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
62 | + * date_format and the second value is the time format |
|
63 | + * @return EE_Registration |
|
64 | + */ |
|
65 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
66 | + { |
|
67 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
68 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param array $props_n_values incoming values from the database |
|
74 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
75 | + * the website will be used. |
|
76 | + * @return EE_Registration |
|
77 | + */ |
|
78 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
79 | + { |
|
80 | + return new self($props_n_values, true, $timezone); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Set Event ID |
|
86 | + * |
|
87 | + * @param int $EVT_ID Event ID |
|
88 | + */ |
|
89 | + public function set_event($EVT_ID = 0) |
|
90 | + { |
|
91 | + $this->set('EVT_ID', $EVT_ID); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
97 | + * be routed to internal methods |
|
98 | + * |
|
99 | + * @param string $field_name |
|
100 | + * @param mixed $field_value |
|
101 | + * @param bool $use_default |
|
102 | + * @throws \EE_Error |
|
103 | + * @throws \RuntimeException |
|
104 | + */ |
|
105 | + public function set($field_name, $field_value, $use_default = false) |
|
106 | + { |
|
107 | + switch ($field_name) { |
|
108 | + case 'REG_code' : |
|
109 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
110 | + $this->set_reg_code($field_value, $use_default); |
|
111 | + } |
|
112 | + break; |
|
113 | + case 'STS_ID' : |
|
114 | + $this->set_status($field_value, $use_default); |
|
115 | + break; |
|
116 | + default : |
|
117 | + parent::set($field_name, $field_value, $use_default); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Set Status ID |
|
124 | + * updates the registration status and ALSO... |
|
125 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
126 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
127 | + * |
|
128 | + * @param string $new_STS_ID |
|
129 | + * @param boolean $use_default |
|
130 | + * @return bool |
|
131 | + * @throws \RuntimeException |
|
132 | + * @throws \EE_Error |
|
133 | + */ |
|
134 | + public function set_status($new_STS_ID = null, $use_default = false) |
|
135 | + { |
|
136 | + // get current REG_Status |
|
137 | + $old_STS_ID = $this->status_ID(); |
|
138 | + // if status has changed |
|
139 | + if ( |
|
140 | + $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
141 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
142 | + && ! empty($new_STS_ID) // as well as the new status |
|
143 | + && $this->ID() // ensure registration is in the db |
|
144 | + ) { |
|
145 | + // TO approved |
|
146 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
147 | + // reserve a space by incrementing ticket and datetime sold values |
|
148 | + $this->_reserve_registration_space(); |
|
149 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); |
|
150 | + // OR FROM approved |
|
151 | + } else if ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
152 | + // release a space by decrementing ticket and datetime sold values |
|
153 | + $this->_release_registration_space(); |
|
154 | + do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); |
|
155 | + } |
|
156 | + // update status |
|
157 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
158 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
|
159 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
160 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
161 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
162 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
163 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID); |
|
164 | + return true; |
|
165 | + } |
|
166 | + //even though the old value matches the new value, it's still good to |
|
167 | + //allow the parent set method to have a say |
|
168 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
169 | + return true; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * update REGs and TXN when cancelled or declined registrations involved |
|
175 | + * |
|
176 | + * @param string $new_STS_ID |
|
177 | + * @param string $old_STS_ID |
|
178 | + * @throws \EE_Error |
|
179 | + */ |
|
180 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) |
|
181 | + { |
|
182 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
183 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
184 | + // true if registration has been cancelled or declined |
|
185 | + if ( |
|
186 | + in_array($new_STS_ID, $closed_reg_statuses, true) |
|
187 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
188 | + ) { |
|
189 | + /** @type EE_Registration_Processor $registration_processor */ |
|
190 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
191 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
192 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
193 | + // cancelled or declined registration |
|
194 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
195 | + $this, |
|
196 | + $closed_reg_statuses |
|
197 | + ); |
|
198 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
199 | + $this, |
|
200 | + $closed_reg_statuses, |
|
201 | + false |
|
202 | + ); |
|
203 | + do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); |
|
204 | + return; |
|
205 | + } |
|
206 | + // true if reinstating cancelled or declined registration |
|
207 | + if ( |
|
208 | + in_array($old_STS_ID, $closed_reg_statuses, true) |
|
209 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
210 | + ) { |
|
211 | + /** @type EE_Registration_Processor $registration_processor */ |
|
212 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
213 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
214 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
215 | + // reinstating cancelled or declined registration |
|
216 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
217 | + $this, |
|
218 | + $closed_reg_statuses |
|
219 | + ); |
|
220 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
221 | + $this, |
|
222 | + $closed_reg_statuses, |
|
223 | + false |
|
224 | + ); |
|
225 | + do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * get Status ID |
|
232 | + */ |
|
233 | + public function status_ID() |
|
234 | + { |
|
235 | + return $this->get('STS_ID'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
241 | + * |
|
242 | + * @return void |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + private function _reserve_registration_space() |
|
246 | + { |
|
247 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
248 | + // so stop tracking that this reg has a ticket reserved |
|
249 | + $this->release_reserved_ticket(); |
|
250 | + $ticket = $this->ticket(); |
|
251 | + $ticket->increase_sold(); |
|
252 | + $ticket->save(); |
|
253 | + // possibly set event status to sold out |
|
254 | + $this->event()->perform_sold_out_status_check(); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Gets the ticket this registration is for |
|
260 | + * |
|
261 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
262 | + * @return EE_Ticket|EE_Base_Class |
|
263 | + * @throws \EE_Error |
|
264 | + */ |
|
265 | + public function ticket($include_archived = true) |
|
266 | + { |
|
267 | + $query_params = array(); |
|
268 | + if ($include_archived) { |
|
269 | + $query_params['default_where_conditions'] = 'none'; |
|
270 | + } |
|
271 | + return $this->get_first_related('Ticket', $query_params); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Gets the event this registration is for |
|
277 | + * |
|
278 | + * @return EE_Event |
|
279 | + */ |
|
280 | + public function event() |
|
281 | + { |
|
282 | + $event = $this->get_first_related('Event'); |
|
283 | + if (! $event instanceof \EE_Event) { |
|
284 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
285 | + } |
|
286 | + return $event; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
292 | + * with the author of the event this registration is for. |
|
293 | + * |
|
294 | + * @since 4.5.0 |
|
295 | + * @return int |
|
296 | + */ |
|
297 | + public function wp_user() |
|
298 | + { |
|
299 | + $event = $this->event(); |
|
300 | + if ($event instanceof EE_Event) { |
|
301 | + return $event->wp_user(); |
|
302 | + } |
|
303 | + return 0; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
309 | + * |
|
310 | + * @return void |
|
311 | + * @throws \EE_Error |
|
312 | + */ |
|
313 | + private function _release_registration_space() |
|
314 | + { |
|
315 | + $ticket = $this->ticket(); |
|
316 | + $ticket->decrease_sold(); |
|
317 | + $ticket->save(); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * tracks this registration's ticket reservation in extra meta |
|
323 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
324 | + * |
|
325 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
326 | + * @return void |
|
327 | + * @throws \EE_Error |
|
328 | + */ |
|
329 | + public function reserve_ticket($update_ticket = false) |
|
330 | + { |
|
331 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
332 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
333 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
334 | + if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
335 | + $ticket = $this->ticket(); |
|
336 | + $ticket->increase_reserved(); |
|
337 | + $ticket->save(); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * stops tracking this registration's ticket reservation in extra meta |
|
345 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
346 | + * |
|
347 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
348 | + * @return void |
|
349 | + * @throws \EE_Error |
|
350 | + */ |
|
351 | + public function release_reserved_ticket($update_ticket = false) |
|
352 | + { |
|
353 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
354 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
355 | + // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
356 | + if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
357 | + $ticket = $this->ticket(); |
|
358 | + $ticket->decrease_reserved(); |
|
359 | + $ticket->save(); |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Set Attendee ID |
|
367 | + * |
|
368 | + * @param int $ATT_ID Attendee ID |
|
369 | + */ |
|
370 | + public function set_attendee_id($ATT_ID = 0) |
|
371 | + { |
|
372 | + $this->set('ATT_ID', $ATT_ID); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Set Transaction ID |
|
378 | + * |
|
379 | + * @param int $TXN_ID Transaction ID |
|
380 | + */ |
|
381 | + public function set_transaction_id($TXN_ID = 0) |
|
382 | + { |
|
383 | + $this->set('TXN_ID', $TXN_ID); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * Set Session |
|
389 | + * |
|
390 | + * @param string $REG_session PHP Session ID |
|
391 | + */ |
|
392 | + public function set_session($REG_session = '') |
|
393 | + { |
|
394 | + $this->set('REG_session', $REG_session); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * Set Registration URL Link |
|
400 | + * |
|
401 | + * @param string $REG_url_link Registration URL Link |
|
402 | + */ |
|
403 | + public function set_reg_url_link($REG_url_link = '') |
|
404 | + { |
|
405 | + $this->set('REG_url_link', $REG_url_link); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * Set Attendee Counter |
|
411 | + * |
|
412 | + * @param int $REG_count Primary Attendee |
|
413 | + */ |
|
414 | + public function set_count($REG_count = 1) |
|
415 | + { |
|
416 | + $this->set('REG_count', $REG_count); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Set Group Size |
|
422 | + * |
|
423 | + * @param boolean $REG_group_size Group Registration |
|
424 | + */ |
|
425 | + public function set_group_size($REG_group_size = false) |
|
426 | + { |
|
427 | + $this->set('REG_group_size', $REG_group_size); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
433 | + * EEM_Registration::status_id_not_approved |
|
434 | + * |
|
435 | + * @return boolean |
|
436 | + */ |
|
437 | + public function is_not_approved() |
|
438 | + { |
|
439 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
445 | + * EEM_Registration::status_id_pending_payment |
|
446 | + * |
|
447 | + * @return boolean |
|
448 | + */ |
|
449 | + public function is_pending_payment() |
|
450 | + { |
|
451 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
457 | + * |
|
458 | + * @return boolean |
|
459 | + */ |
|
460 | + public function is_approved() |
|
461 | + { |
|
462 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
468 | + * |
|
469 | + * @return boolean |
|
470 | + */ |
|
471 | + public function is_cancelled() |
|
472 | + { |
|
473 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
479 | + * |
|
480 | + * @return boolean |
|
481 | + */ |
|
482 | + public function is_declined() |
|
483 | + { |
|
484 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
490 | + * EEM_Registration::status_id_incomplete |
|
491 | + * |
|
492 | + * @return boolean |
|
493 | + */ |
|
494 | + public function is_incomplete() |
|
495 | + { |
|
496 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * Set Registration Date |
|
502 | + * |
|
503 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
504 | + * Date |
|
505 | + */ |
|
506 | + public function set_reg_date($REG_date = false) |
|
507 | + { |
|
508 | + $this->set('REG_date', $REG_date); |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Set final price owing for this registration after all ticket/price modifications |
|
514 | + * |
|
515 | + * @access public |
|
516 | + * @param float $REG_final_price |
|
517 | + */ |
|
518 | + public function set_final_price($REG_final_price = 0.00) |
|
519 | + { |
|
520 | + $this->set('REG_final_price', $REG_final_price); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * Set amount paid towards this registration's final price |
|
526 | + * |
|
527 | + * @access public |
|
528 | + * @param float $REG_paid |
|
529 | + */ |
|
530 | + public function set_paid($REG_paid = 0.00) |
|
531 | + { |
|
532 | + $this->set('REG_paid', $REG_paid); |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * Attendee Is Going |
|
538 | + * |
|
539 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
540 | + */ |
|
541 | + public function set_att_is_going($REG_att_is_going = false) |
|
542 | + { |
|
543 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * Gets the related attendee |
|
549 | + * |
|
550 | + * @return EE_Attendee |
|
551 | + */ |
|
552 | + public function attendee() |
|
553 | + { |
|
554 | + return $this->get_first_related('Attendee'); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * get Event ID |
|
560 | + */ |
|
561 | + public function event_ID() |
|
562 | + { |
|
563 | + return $this->get('EVT_ID'); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * get Event ID |
|
569 | + */ |
|
570 | + public function event_name() |
|
571 | + { |
|
572 | + $event = $this->event_obj(); |
|
573 | + if ($event) { |
|
574 | + return $event->name(); |
|
575 | + } else { |
|
576 | + return null; |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Fetches the event this registration is for |
|
583 | + * |
|
584 | + * @return EE_Event |
|
585 | + */ |
|
586 | + public function event_obj() |
|
587 | + { |
|
588 | + return $this->get_first_related('Event'); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * get Attendee ID |
|
594 | + */ |
|
595 | + public function attendee_ID() |
|
596 | + { |
|
597 | + return $this->get('ATT_ID'); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * get PHP Session ID |
|
603 | + */ |
|
604 | + public function session_ID() |
|
605 | + { |
|
606 | + return $this->get('REG_session'); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
612 | + * |
|
613 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
614 | + * @return string |
|
615 | + */ |
|
616 | + public function receipt_url($messenger = 'html') |
|
617 | + { |
|
618 | + |
|
619 | + /** |
|
620 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template already in use on old system. If there is then we just return the standard url for it. |
|
621 | + * |
|
622 | + * @since 4.5.0 |
|
623 | + */ |
|
624 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
625 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), true, true, true); |
|
626 | + |
|
627 | + if ($has_custom) { |
|
628 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
629 | + } |
|
630 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
636 | + * |
|
637 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + public function invoice_url($messenger = 'html') |
|
641 | + { |
|
642 | + /** |
|
643 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template already in use on old system. If there is then we just return the standard url for it. |
|
644 | + * |
|
645 | + * @since 4.5.0 |
|
646 | + */ |
|
647 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
648 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), true, true, true); |
|
649 | + |
|
650 | + if ($has_custom) { |
|
651 | + if ($messenger == 'html') { |
|
652 | + return $this->invoice_url('launch'); |
|
653 | + } |
|
654 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
655 | + |
|
656 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
657 | + if ($messenger == 'html') { |
|
658 | + $query_args['html'] = true; |
|
659 | + } |
|
660 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
661 | + } |
|
662 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * get Registration URL Link |
|
668 | + * |
|
669 | + * @access public |
|
670 | + * @return string |
|
671 | + * @throws \EE_Error |
|
672 | + */ |
|
673 | + public function reg_url_link() |
|
674 | + { |
|
675 | + return (string)$this->get('REG_url_link'); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Echoes out invoice_url() |
|
681 | + * |
|
682 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + public function e_invoice_url($type = 'launch') |
|
686 | + { |
|
687 | + echo $this->invoice_url($type); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * Echoes out payment_overview_url |
|
693 | + */ |
|
694 | + public function e_payment_overview_url() |
|
695 | + { |
|
696 | + echo $this->payment_overview_url(); |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
702 | + * a query parameter |
|
703 | + * |
|
704 | + * @return string |
|
705 | + */ |
|
706 | + public function payment_overview_url() |
|
707 | + { |
|
708 | + return add_query_arg(array( |
|
709 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
710 | + 'step' => 'payment_options', |
|
711 | + 'revisit' => true, |
|
712 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
718 | + * a query parameter |
|
719 | + * |
|
720 | + * @return string |
|
721 | + */ |
|
722 | + public function edit_attendee_information_url() |
|
723 | + { |
|
724 | + return add_query_arg(array( |
|
725 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
726 | + 'step' => 'attendee_information', |
|
727 | + 'revisit' => true, |
|
728 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
734 | + * |
|
735 | + * @return string |
|
736 | + */ |
|
737 | + public function get_admin_edit_url() |
|
738 | + { |
|
739 | + return EEH_URL::add_query_args_and_nonce(array( |
|
740 | + 'page' => 'espresso_registrations', |
|
741 | + 'action' => 'view_registration', |
|
742 | + '_REG_ID' => $this->ID(), |
|
743 | + ), admin_url('admin.php')); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * is_primary_registrant? |
|
749 | + */ |
|
750 | + public function is_primary_registrant() |
|
751 | + { |
|
752 | + return $this->get('REG_count') == 1 ? true : false; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * This returns the primary registration object for this registration group (which may be this object). |
|
758 | + * |
|
759 | + * @return EE_Registration |
|
760 | + */ |
|
761 | + public function get_primary_registration() |
|
762 | + { |
|
763 | + if ($this->is_primary_registrant()) { |
|
764 | + return $this; |
|
765 | + } |
|
766 | + |
|
767 | + //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
768 | + $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
769 | + array( |
|
770 | + 'TXN_ID' => $this->transaction_ID(), |
|
771 | + 'REG_count' => 1, |
|
772 | + ), |
|
773 | + )); |
|
774 | + return $primary_registrant; |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * get Attendee Number |
|
780 | + * |
|
781 | + * @access public |
|
782 | + */ |
|
783 | + public function count() |
|
784 | + { |
|
785 | + return $this->get('REG_count'); |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * get Group Size |
|
791 | + */ |
|
792 | + public function group_size() |
|
793 | + { |
|
794 | + return $this->get('REG_group_size'); |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + /** |
|
799 | + * get Registration Date |
|
800 | + */ |
|
801 | + public function date() |
|
802 | + { |
|
803 | + return $this->get('REG_date'); |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * gets a pretty date |
|
809 | + * |
|
810 | + * @param string $date_format |
|
811 | + * @param string $time_format |
|
812 | + * @return string |
|
813 | + */ |
|
814 | + public function pretty_date($date_format = null, $time_format = null) |
|
815 | + { |
|
816 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * final_price |
|
822 | + * the registration's share of the transaction total, so that the |
|
823 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
824 | + * |
|
825 | + * @return float |
|
826 | + */ |
|
827 | + public function final_price() |
|
828 | + { |
|
829 | + return $this->get('REG_final_price'); |
|
830 | + } |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * pretty_final_price |
|
835 | + * final price as formatted string, with correct decimal places and currency symbol |
|
836 | + * |
|
837 | + * @return string |
|
838 | + */ |
|
839 | + public function pretty_final_price() |
|
840 | + { |
|
841 | + return $this->get_pretty('REG_final_price'); |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * get paid (yeah) |
|
847 | + * |
|
848 | + * @return float |
|
849 | + */ |
|
850 | + public function paid() |
|
851 | + { |
|
852 | + return $this->get('REG_paid'); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * pretty_paid |
|
858 | + * |
|
859 | + * @return float |
|
860 | + */ |
|
861 | + public function pretty_paid() |
|
862 | + { |
|
863 | + return $this->get_pretty('REG_paid'); |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * owes_monies_and_can_pay |
|
869 | + * whether or not this registration has monies owing and it's' status allows payment |
|
870 | + * |
|
871 | + * @param array $requires_payment |
|
872 | + * @return bool |
|
873 | + */ |
|
874 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
875 | + { |
|
876 | + // these reg statuses require payment (if event is not free) |
|
877 | + $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
878 | + if ( |
|
879 | + in_array($this->status_ID(), $requires_payment) && |
|
880 | + $this->final_price() != 0 && |
|
881 | + $this->final_price() != $this->paid() |
|
882 | + ) { |
|
883 | + return true; |
|
884 | + } else { |
|
885 | + return false; |
|
886 | + } |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * Prints out the return value of $this->pretty_status() |
|
892 | + * |
|
893 | + * @param bool $show_icons |
|
894 | + * @return void |
|
895 | + */ |
|
896 | + public function e_pretty_status($show_icons = false) |
|
897 | + { |
|
898 | + echo $this->pretty_status($show_icons); |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * Returns a nice version of the status for displaying to customers |
|
904 | + * |
|
905 | + * @param bool $show_icons |
|
906 | + * @return string |
|
907 | + */ |
|
908 | + public function pretty_status($show_icons = false) |
|
909 | + { |
|
910 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), |
|
911 | + false, 'sentence'); |
|
912 | + $icon = ''; |
|
913 | + switch ($this->status_ID()) { |
|
914 | + case EEM_Registration::status_id_approved: |
|
915 | + $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : ''; |
|
916 | + break; |
|
917 | + case EEM_Registration::status_id_pending_payment: |
|
918 | + $icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : ''; |
|
919 | + break; |
|
920 | + case EEM_Registration::status_id_not_approved: |
|
921 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : ''; |
|
922 | + break; |
|
923 | + case EEM_Registration::status_id_cancelled: |
|
924 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : ''; |
|
925 | + break; |
|
926 | + case EEM_Registration::status_id_incomplete: |
|
927 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : ''; |
|
928 | + break; |
|
929 | + case EEM_Registration::status_id_declined: |
|
930 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
931 | + break; |
|
932 | + case EEM_Registration::status_id_wait_list: |
|
933 | + $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
|
934 | + break; |
|
935 | + } |
|
936 | + return $icon . $status[$this->status_ID()]; |
|
937 | + } |
|
938 | + |
|
939 | + |
|
940 | + /** |
|
941 | + * get Attendee Is Going |
|
942 | + */ |
|
943 | + public function att_is_going() |
|
944 | + { |
|
945 | + return $this->get('REG_att_is_going'); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * Gets related answers |
|
951 | + * |
|
952 | + * @param array $query_params like EEM_Base::get_all |
|
953 | + * @return EE_Answer[] |
|
954 | + */ |
|
955 | + public function answers($query_params = null) |
|
956 | + { |
|
957 | + return $this->get_many_related('Answer', $query_params); |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * Gets the registration's answer value to the specified question |
|
963 | + * (either the question's ID or a question object) |
|
964 | + * |
|
965 | + * @param EE_Question|int $question |
|
966 | + * @param bool $pretty_value |
|
967 | + * @return array|string if pretty_value= true, the result will always be a string |
|
968 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
969 | + * will convert it into some kind of string) |
|
970 | + */ |
|
971 | + public function answer_value_to_question($question, $pretty_value = true) |
|
972 | + { |
|
973 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
974 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
975 | + } |
|
976 | + |
|
977 | + |
|
978 | + /** |
|
979 | + * question_groups |
|
980 | + * returns an array of EE_Question_Group objects for this registration |
|
981 | + * |
|
982 | + * @return EE_Question_Group[] |
|
983 | + */ |
|
984 | + public function question_groups() |
|
985 | + { |
|
986 | + $question_groups = array(); |
|
987 | + if ($this->event() instanceof EE_Event) { |
|
988 | + $question_groups = $this->event()->question_groups( |
|
989 | + array( |
|
990 | + array( |
|
991 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
992 | + ), |
|
993 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
994 | + ) |
|
995 | + ); |
|
996 | + } |
|
997 | + return $question_groups; |
|
998 | + } |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * count_question_groups |
|
1003 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
1004 | + * |
|
1005 | + * @return int |
|
1006 | + */ |
|
1007 | + public function count_question_groups() |
|
1008 | + { |
|
1009 | + $qg_count = 0; |
|
1010 | + if ($this->event() instanceof EE_Event) { |
|
1011 | + $qg_count = $this->event()->count_related( |
|
1012 | + 'Question_Group', |
|
1013 | + array( |
|
1014 | + array( |
|
1015 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1016 | + ), |
|
1017 | + ) |
|
1018 | + ); |
|
1019 | + } |
|
1020 | + return $qg_count; |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * Returns the registration date in the 'standard' string format |
|
1026 | + * (function may be improved in the future to allow for different formats and timezones) |
|
1027 | + * |
|
1028 | + * @return string |
|
1029 | + */ |
|
1030 | + public function reg_date() |
|
1031 | + { |
|
1032 | + return $this->get_datetime('REG_date'); |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1038 | + * the ticket this registration purchased, or the datetime they have registered |
|
1039 | + * to attend) |
|
1040 | + * |
|
1041 | + * @return EE_Datetime_Ticket |
|
1042 | + */ |
|
1043 | + public function datetime_ticket() |
|
1044 | + { |
|
1045 | + return $this->get_first_related('Datetime_Ticket'); |
|
1046 | + } |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Sets the registration's datetime_ticket. |
|
1051 | + * |
|
1052 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
1053 | + * @return EE_Datetime_Ticket |
|
1054 | + */ |
|
1055 | + public function set_datetime_ticket($datetime_ticket) |
|
1056 | + { |
|
1057 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Gets deleted |
|
1062 | + * |
|
1063 | + * @return boolean |
|
1064 | + */ |
|
1065 | + public function deleted() |
|
1066 | + { |
|
1067 | + return $this->get('REG_deleted'); |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Sets deleted |
|
1072 | + * |
|
1073 | + * @param boolean $deleted |
|
1074 | + * @return boolean |
|
1075 | + */ |
|
1076 | + public function set_deleted($deleted) |
|
1077 | + { |
|
1078 | + if ($deleted) { |
|
1079 | + $this->delete(); |
|
1080 | + } else { |
|
1081 | + $this->restore(); |
|
1082 | + } |
|
1083 | + } |
|
1084 | + |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * Get the status object of this object |
|
1088 | + * |
|
1089 | + * @return EE_Status |
|
1090 | + */ |
|
1091 | + public function status_obj() |
|
1092 | + { |
|
1093 | + return $this->get_first_related('Status'); |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Returns the number of times this registration has checked into any of the datetimes |
|
1099 | + * its available for |
|
1100 | + * |
|
1101 | + * @return int |
|
1102 | + */ |
|
1103 | + public function count_checkins() |
|
1104 | + { |
|
1105 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
1106 | + } |
|
1107 | + |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1111 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1112 | + * |
|
1113 | + * @return int |
|
1114 | + */ |
|
1115 | + public function count_checkins_not_checkedout() |
|
1116 | + { |
|
1117 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1123 | + * |
|
1124 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1125 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1126 | + * consider registration status as well as datetime access. |
|
1127 | + * @return bool |
|
1128 | + */ |
|
1129 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1130 | + { |
|
1131 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1132 | + |
|
1133 | + //first check registration status |
|
1134 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1135 | + return false; |
|
1136 | + } |
|
1137 | + //is there a datetime ticket that matches this dtt_ID? |
|
1138 | + if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1139 | + array( |
|
1140 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
1141 | + 'DTT_ID' => $DTT_ID, |
|
1142 | + ), |
|
1143 | + ))) |
|
1144 | + ) { |
|
1145 | + return false; |
|
1146 | + } |
|
1147 | + |
|
1148 | + //final check is against TKT_uses |
|
1149 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1150 | + } |
|
1151 | + |
|
1152 | + |
|
1153 | + /** |
|
1154 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1155 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1156 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1157 | + * then return false. Otherwise return true. |
|
1158 | + * |
|
1159 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1160 | + * @return bool true means can checkin. false means cannot checkin. |
|
1161 | + */ |
|
1162 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1163 | + { |
|
1164 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1165 | + |
|
1166 | + if (! $DTT_ID) { |
|
1167 | + return false; |
|
1168 | + } |
|
1169 | + |
|
1170 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1171 | + |
|
1172 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
|
1173 | + // or not. |
|
1174 | + if (! $max_uses || $max_uses === EE_INF) { |
|
1175 | + return true; |
|
1176 | + } |
|
1177 | + |
|
1178 | + //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1179 | + //go ahead and toggle. |
|
1180 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1181 | + return true; |
|
1182 | + } |
|
1183 | + |
|
1184 | + //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1185 | + //disallows further check-ins. |
|
1186 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
1187 | + array( |
|
1188 | + 'REG_ID' => $this->ID(), |
|
1189 | + 'CHK_in' => true, |
|
1190 | + ), |
|
1191 | + ), 'DTT_ID', true); |
|
1192 | + // checkins have already reached their max number of uses |
|
1193 | + // so registrant can NOT checkin |
|
1194 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1195 | + EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1196 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1197 | + return false; |
|
1198 | + } |
|
1199 | + return true; |
|
1200 | + } |
|
1201 | + |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * toggle Check-in status for this registration |
|
1205 | + * Check-ins are toggled in the following order: |
|
1206 | + * never checked in -> checked in |
|
1207 | + * checked in -> checked out |
|
1208 | + * checked out -> checked in |
|
1209 | + * |
|
1210 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1211 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1212 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1213 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1214 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1215 | + * @throws EE_Error |
|
1216 | + */ |
|
1217 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1218 | + { |
|
1219 | + if (empty($DTT_ID)) { |
|
1220 | + $datetime = $this->get_latest_related_datetime(); |
|
1221 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1222 | + // verify the registration can checkin for the given DTT_ID |
|
1223 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1224 | + EE_Error::add_error( |
|
1225 | + sprintf( |
|
1226 | + __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1227 | + 'event_espresso'), |
|
1228 | + $this->ID(), |
|
1229 | + $DTT_ID |
|
1230 | + ), |
|
1231 | + __FILE__, __FUNCTION__, __LINE__ |
|
1232 | + ); |
|
1233 | + return false; |
|
1234 | + } |
|
1235 | + $status_paths = array( |
|
1236 | + EE_Registration::checkin_status_never => EE_Registration::checkin_status_in, |
|
1237 | + EE_Registration::checkin_status_in => EE_Registration::checkin_status_out, |
|
1238 | + EE_Registration::checkin_status_out => EE_Registration::checkin_status_in, |
|
1239 | + ); |
|
1240 | + //start by getting the current status so we know what status we'll be changing to. |
|
1241 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1242 | + $status_to = $status_paths[$cur_status]; |
|
1243 | + // database only records true for checked IN or false for checked OUT |
|
1244 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1245 | + $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; |
|
1246 | + // add relation - note Check-ins are always creating new rows |
|
1247 | + // because we are keeping track of Check-ins over time. |
|
1248 | + // Eventually we'll probably want to show a list table |
|
1249 | + // for the individual Check-ins so that they can be managed. |
|
1250 | + $checkin = EE_Checkin::new_instance(array( |
|
1251 | + 'REG_ID' => $this->ID(), |
|
1252 | + 'DTT_ID' => $DTT_ID, |
|
1253 | + 'CHK_in' => $new_status, |
|
1254 | + )); |
|
1255 | + // if the record could not be saved then return false |
|
1256 | + if ($checkin->save() === 0) { |
|
1257 | + if (WP_DEBUG) { |
|
1258 | + global $wpdb; |
|
1259 | + $error = sprintf( |
|
1260 | + __('Registration check in update failed because of the following database error: %1$s%2$s', |
|
1261 | + 'event_espresso'), |
|
1262 | + '<br />', |
|
1263 | + $wpdb->last_error |
|
1264 | + ); |
|
1265 | + } else { |
|
1266 | + $error = __('Registration check in update failed because of an unknown database error', |
|
1267 | + 'event_espresso'); |
|
1268 | + } |
|
1269 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1270 | + return false; |
|
1271 | + } |
|
1272 | + return $status_to; |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1278 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1279 | + * |
|
1280 | + * @return EE_Datetime|null |
|
1281 | + * @throws \EE_Error |
|
1282 | + */ |
|
1283 | + public function get_latest_related_datetime() |
|
1284 | + { |
|
1285 | + return EEM_Datetime::instance()->get_one( |
|
1286 | + array( |
|
1287 | + array( |
|
1288 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1289 | + ), |
|
1290 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1291 | + ) |
|
1292 | + ); |
|
1293 | + } |
|
1294 | + |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1298 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1299 | + * |
|
1300 | + * @throws \EE_Error |
|
1301 | + */ |
|
1302 | + public function get_earliest_related_datetime() |
|
1303 | + { |
|
1304 | + return EEM_Datetime::instance()->get_one( |
|
1305 | + array( |
|
1306 | + array( |
|
1307 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1308 | + ), |
|
1309 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1310 | + ) |
|
1311 | + ); |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1317 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1318 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1319 | + * |
|
1320 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1321 | + * (if empty we'll get the primary datetime for |
|
1322 | + * this registration (via event) and use it's ID); |
|
1323 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1324 | + * @return int Integer representing Check-in status. |
|
1325 | + * @throws \EE_Error |
|
1326 | + */ |
|
1327 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1328 | + { |
|
1329 | + $checkin_query_params = array( |
|
1330 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1331 | + ); |
|
1332 | + |
|
1333 | + if ($DTT_ID > 0) { |
|
1334 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1335 | + } |
|
1336 | + |
|
1337 | + //get checkin object (if exists) |
|
1338 | + $checkin = $checkin instanceof EE_Checkin |
|
1339 | + ? $checkin |
|
1340 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1341 | + if ($checkin instanceof EE_Checkin) { |
|
1342 | + if ($checkin->get('CHK_in')) { |
|
1343 | + return EE_Registration::checkin_status_in; //checked in |
|
1344 | + } |
|
1345 | + return EE_Registration::checkin_status_out; //had checked in but is now checked out. |
|
1346 | + } |
|
1347 | + return EE_Registration::checkin_status_never; //never been checked in |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * This method returns a localized message for the toggled Check-in message. |
|
1353 | + * |
|
1354 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1355 | + * then it is assumed Check-in for primary datetime was toggled. |
|
1356 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1357 | + * message can be customized with the attendee name. |
|
1358 | + * @return string internationalized message |
|
1359 | + */ |
|
1360 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
1361 | + { |
|
1362 | + //let's get the attendee first so we can include the name of the attendee |
|
1363 | + $attendee = $this->get_first_related('Attendee'); |
|
1364 | + if ($attendee instanceof EE_Attendee) { |
|
1365 | + if ($error) { |
|
1366 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1367 | + } |
|
1368 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1369 | + //what is the status message going to be? |
|
1370 | + switch ($cur_status) { |
|
1371 | + case EE_Registration::checkin_status_never : |
|
1372 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
1373 | + $attendee->full_name()); |
|
1374 | + break; |
|
1375 | + case EE_Registration::checkin_status_in : |
|
1376 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1377 | + break; |
|
1378 | + case EE_Registration::checkin_status_out : |
|
1379 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1380 | + break; |
|
1381 | + } |
|
1382 | + } |
|
1383 | + return __("The check-in status could not be determined.", "event_espresso"); |
|
1384 | + } |
|
1385 | + |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Returns the related EE_Transaction to this registration |
|
1389 | + * |
|
1390 | + * @return EE_Transaction |
|
1391 | + */ |
|
1392 | + public function transaction() |
|
1393 | + { |
|
1394 | + $transaction = $this->get_first_related('Transaction'); |
|
1395 | + if (! $transaction instanceof \EE_Transaction) { |
|
1396 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1397 | + } |
|
1398 | + return $transaction; |
|
1399 | + } |
|
1400 | + |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * get Registration Code |
|
1404 | + */ |
|
1405 | + public function reg_code() |
|
1406 | + { |
|
1407 | + return $this->get('REG_code'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + |
|
1411 | + /** |
|
1412 | + * get Transaction ID |
|
1413 | + */ |
|
1414 | + public function transaction_ID() |
|
1415 | + { |
|
1416 | + return $this->get('TXN_ID'); |
|
1417 | + } |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * @return int |
|
1422 | + */ |
|
1423 | + public function ticket_ID() |
|
1424 | + { |
|
1425 | + return $this->get('TKT_ID'); |
|
1426 | + } |
|
1427 | + |
|
1428 | + |
|
1429 | + /** |
|
1430 | + * Set Registration Code |
|
1431 | + * |
|
1432 | + * @access public |
|
1433 | + * @param string $REG_code Registration Code |
|
1434 | + * @param boolean $use_default |
|
1435 | + */ |
|
1436 | + public function set_reg_code($REG_code, $use_default = false) |
|
1437 | + { |
|
1438 | + if (empty($REG_code)) { |
|
1439 | + EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1440 | + return; |
|
1441 | + } |
|
1442 | + if (! $this->reg_code()) { |
|
1443 | + parent::set('REG_code', $REG_code, $use_default); |
|
1444 | + } else { |
|
1445 | + EE_Error::doing_it_wrong( |
|
1446 | + __CLASS__ . '::' . __FUNCTION__, |
|
1447 | + __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1448 | + '4.6.0' |
|
1449 | + ); |
|
1450 | + } |
|
1451 | + } |
|
1452 | + |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1456 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1457 | + * $registration->transaction()->registrations(); |
|
1458 | + * |
|
1459 | + * @since 4.5.0 |
|
1460 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1461 | + */ |
|
1462 | + public function get_all_other_registrations_in_group() |
|
1463 | + { |
|
1464 | + if ($this->group_size() < 2) { |
|
1465 | + return array(); |
|
1466 | + } |
|
1467 | + |
|
1468 | + $query[0] = array( |
|
1469 | + 'TXN_ID' => $this->transaction_ID(), |
|
1470 | + 'REG_ID' => array('!=', $this->ID()), |
|
1471 | + 'TKT_ID' => $this->ticket_ID(), |
|
1472 | + ); |
|
1473 | + |
|
1474 | + $registrations = $this->get_model()->get_all($query); |
|
1475 | + return $registrations; |
|
1476 | + } |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Return the link to the admin details for the object. |
|
1480 | + * |
|
1481 | + * @return string |
|
1482 | + */ |
|
1483 | + public function get_admin_details_link() |
|
1484 | + { |
|
1485 | + EE_Registry::instance()->load_helper('URL'); |
|
1486 | + return EEH_URL::add_query_args_and_nonce( |
|
1487 | + array( |
|
1488 | + 'page' => 'espresso_registrations', |
|
1489 | + 'action' => 'view_registration', |
|
1490 | + '_REG_ID' => $this->ID(), |
|
1491 | + ), |
|
1492 | + admin_url('admin.php') |
|
1493 | + ); |
|
1494 | + } |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1498 | + * |
|
1499 | + * @return string |
|
1500 | + */ |
|
1501 | + public function get_admin_edit_link() |
|
1502 | + { |
|
1503 | + return $this->get_admin_details_link(); |
|
1504 | + } |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * Returns the link to a settings page for the object. |
|
1508 | + * |
|
1509 | + * @return string |
|
1510 | + */ |
|
1511 | + public function get_admin_settings_link() |
|
1512 | + { |
|
1513 | + return $this->get_admin_details_link(); |
|
1514 | + } |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1518 | + * |
|
1519 | + * @return string |
|
1520 | + */ |
|
1521 | + public function get_admin_overview_link() |
|
1522 | + { |
|
1523 | + EE_Registry::instance()->load_helper('URL'); |
|
1524 | + return EEH_URL::add_query_args_and_nonce( |
|
1525 | + array( |
|
1526 | + 'page' => 'espresso_registrations', |
|
1527 | + ), |
|
1528 | + admin_url('admin.php') |
|
1529 | + ); |
|
1530 | + } |
|
1531 | + |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * @param array $query_params |
|
1535 | + * @return \EE_Registration[] |
|
1536 | + * @throws \EE_Error |
|
1537 | + */ |
|
1538 | + public function payments($query_params = array()) |
|
1539 | + { |
|
1540 | + return $this->get_many_related('Payment', $query_params); |
|
1541 | + } |
|
1542 | + |
|
1543 | + |
|
1544 | + /** |
|
1545 | + * @param array $query_params |
|
1546 | + * @return \EE_Registration_Payment[] |
|
1547 | + * @throws \EE_Error |
|
1548 | + */ |
|
1549 | + public function registration_payments($query_params = array()) |
|
1550 | + { |
|
1551 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1552 | + } |
|
1553 | + |
|
1554 | + |
|
1555 | + /** |
|
1556 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1557 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
1558 | + * |
|
1559 | + * @return EE_Payment_Method|null |
|
1560 | + */ |
|
1561 | + public function payment_method() |
|
1562 | + { |
|
1563 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1564 | + } |
|
1565 | + |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * @return \EE_Line_Item |
|
1569 | + * @throws EntityNotFoundException |
|
1570 | + * @throws \EE_Error |
|
1571 | + */ |
|
1572 | + public function ticket_line_item() |
|
1573 | + { |
|
1574 | + $ticket = $this->ticket(); |
|
1575 | + $transaction = $this->transaction(); |
|
1576 | + $line_item = null; |
|
1577 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1578 | + $transaction->total_line_item(), |
|
1579 | + 'Ticket', |
|
1580 | + array($ticket->ID()) |
|
1581 | + ); |
|
1582 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
1583 | + if ( |
|
1584 | + $ticket_line_item instanceof \EE_Line_Item |
|
1585 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1586 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1587 | + ) { |
|
1588 | + $line_item = $ticket_line_item; |
|
1589 | + break; |
|
1590 | + } |
|
1591 | + } |
|
1592 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1593 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1594 | + } |
|
1595 | + return $line_item; |
|
1596 | + } |
|
1597 | + |
|
1598 | + |
|
1599 | + /** |
|
1600 | + * Soft Deletes this model object. |
|
1601 | + * |
|
1602 | + * @return boolean | int |
|
1603 | + * @throws \RuntimeException |
|
1604 | + * @throws \EE_Error |
|
1605 | + */ |
|
1606 | + public function delete() |
|
1607 | + { |
|
1608 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1609 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
1610 | + } |
|
1611 | + return parent::delete(); |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1617 | + * |
|
1618 | + * @throws \EE_Error |
|
1619 | + * @throws \RuntimeException |
|
1620 | + */ |
|
1621 | + public function restore() |
|
1622 | + { |
|
1623 | + $previous_status = $this->get_extra_meta( |
|
1624 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1625 | + true, |
|
1626 | + EEM_Registration::status_id_cancelled |
|
1627 | + ); |
|
1628 | + if ($previous_status) { |
|
1629 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1630 | + $this->set_status($previous_status); |
|
1631 | + } |
|
1632 | + return parent::restore(); |
|
1633 | + } |
|
1634 | + |
|
1635 | + |
|
1636 | + |
|
1637 | + /*************************** DEPRECATED ***************************/ |
|
1638 | + |
|
1639 | + |
|
1640 | + /** |
|
1641 | + * @deprecated |
|
1642 | + * @since 4.7.0 |
|
1643 | + * @access public |
|
1644 | + */ |
|
1645 | + public function price_paid() |
|
1646 | + { |
|
1647 | + EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
1648 | + __('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
1649 | + '4.7.0'); |
|
1650 | + return $this->final_price(); |
|
1651 | + } |
|
1652 | + |
|
1653 | + |
|
1654 | + /** |
|
1655 | + * @deprecated |
|
1656 | + * @since 4.7.0 |
|
1657 | + * @access public |
|
1658 | + * @param float $REG_final_price |
|
1659 | + */ |
|
1660 | + public function set_price_paid($REG_final_price = 0.00) |
|
1661 | + { |
|
1662 | + EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
1663 | + __('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
1664 | + '4.7.0'); |
|
1665 | + $this->set_final_price($REG_final_price); |
|
1666 | + } |
|
1667 | + |
|
1668 | + |
|
1669 | + /** |
|
1670 | + * @deprecated |
|
1671 | + * @since 4.7.0 |
|
1672 | + * @return string |
|
1673 | + */ |
|
1674 | + public function pretty_price_paid() |
|
1675 | + { |
|
1676 | + EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
1677 | + __('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
1678 | + 'event_espresso'), '4.7.0'); |
|
1679 | + return $this->pretty_final_price(); |
|
1680 | + } |
|
1681 | + |
|
1682 | + |
|
1683 | + /** |
|
1684 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
1685 | + * |
|
1686 | + * @deprecated 4.9.17 |
|
1687 | + * @return EE_Datetime |
|
1688 | + */ |
|
1689 | + public function get_related_primary_datetime() |
|
1690 | + { |
|
1691 | + EE_Error::doing_it_wrong( |
|
1692 | + __METHOD__, |
|
1693 | + esc_html__( |
|
1694 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1695 | + 'event_espresso' |
|
1696 | + ), |
|
1697 | + '4.9.17', |
|
1698 | + '5.0.0' |
|
1699 | + ); |
|
1700 | + return $this->event()->primary_datetime(); |
|
1701 | + } |
|
1702 | 1702 | |
1703 | 1703 | |
1704 | 1704 | } |
@@ -14,248 +14,248 @@ |
||
14 | 14 | abstract class EE_Form_Section_Layout_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Form form section to lay out |
|
19 | - * |
|
20 | - * @var EE_Form_Section_Proper |
|
21 | - */ |
|
22 | - protected $_form_section; |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * __construct |
|
28 | - */ |
|
29 | - function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * The form section on which this strategy is to perform |
|
37 | - * |
|
38 | - * @param EE_Form_Section_Proper $form |
|
39 | - */ |
|
40 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
41 | - { |
|
42 | - $this->_form_section = $form; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return \EE_Form_Section_Proper |
|
49 | - */ |
|
50 | - public function form_section() |
|
51 | - { |
|
52 | - return $this->_form_section; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
59 | - * this form. |
|
60 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
61 | - * proper subsections. |
|
62 | - * Returns the HTML |
|
63 | - * |
|
64 | - * @return string HTML for displaying |
|
65 | - */ |
|
66 | - public function layout_form() |
|
67 | - { |
|
68 | - $html = ''; |
|
69 | - // layout_form_begin |
|
70 | - $html .= apply_filters( |
|
71 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
72 | - $this->layout_form_begin(), |
|
73 | - $this->_form_section |
|
74 | - ); |
|
75 | - // layout_form_loop |
|
76 | - $html .= apply_filters( |
|
77 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
78 | - $this->layout_form_loop(), |
|
79 | - $this->_form_section |
|
80 | - ); |
|
81 | - // layout_form_end |
|
82 | - $html .= apply_filters( |
|
83 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
84 | - $this->layout_form_end(), |
|
85 | - $this->_form_section |
|
86 | - ); |
|
87 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
88 | - return $html; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function layout_form_loop() |
|
97 | - { |
|
98 | - $html = ''; |
|
99 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
100 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
101 | - $html .= apply_filters( |
|
102 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' . $name . '__in_' . $this->_form_section->name(), |
|
103 | - $this->layout_input($subsection), |
|
104 | - $this->_form_section, |
|
105 | - $subsection |
|
106 | - ); |
|
107 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
108 | - $html .= apply_filters( |
|
109 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' . $name . '__in_' . $this->_form_section->name(), |
|
110 | - $this->layout_subsection($subsection), |
|
111 | - $this->_form_section, |
|
112 | - $subsection |
|
113 | - ); |
|
114 | - } |
|
115 | - } |
|
116 | - return $html; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - abstract public function layout_form_begin(); |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - abstract public function layout_form_end(); |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
141 | - * is putting each input in a row of its own, this should probably be called by a |
|
142 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | - * customize the form's layout, but would like to make use of it for laying out |
|
145 | - * 'easy-to-layout' inputs |
|
146 | - * |
|
147 | - * @param EE_Form_Input_Base $input |
|
148 | - * @return string html |
|
149 | - */ |
|
150 | - abstract public function layout_input($input); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | - * that the proper subsection will layout its container, label, etc on its own. |
|
158 | - * |
|
159 | - * @param EE_Form_Section_Base $subsection |
|
160 | - * @return string html |
|
161 | - */ |
|
162 | - abstract public function layout_subsection($subsection); |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Gets the HTML for the label tag and its contents for the input |
|
168 | - * |
|
169 | - * @param EE_Form_Input_Base $input |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function display_label($input) |
|
173 | - { |
|
174 | - $class = $input->required() ? 'ee-required-label ' . $input->html_label_class() : $input->html_label_class(); |
|
175 | - $label_text = $input->required() |
|
176 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
177 | - : $input->html_label_text(); |
|
178 | - return '<label id="' |
|
179 | - . $input->html_label_id() |
|
180 | - . '" class="' |
|
181 | - . $class |
|
182 | - . '" style="' |
|
183 | - . $input->html_label_style() |
|
184 | - . '" for="' . $input->html_name() |
|
185 | - . '">' |
|
186 | - . $label_text |
|
187 | - . '</label>'; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * returns the HTML for the server-side validation errors for the specified input |
|
194 | - * Note that if JS is enabled, it should remove these and instead |
|
195 | - * populate the form's errors in the jquery validate fashion |
|
196 | - * using the localized data provided to the JS |
|
197 | - * |
|
198 | - * @param EE_Form_Input_Base $input |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function display_errors($input) |
|
202 | - { |
|
203 | - if ($input->get_validation_errors()) { |
|
204 | - return "<label id='" |
|
205 | - . $input->html_id() |
|
206 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
207 | - . $input->get_validation_error_string() |
|
208 | - . "</label>"; |
|
209 | - } else { |
|
210 | - return ''; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Displays the help span for the specified input |
|
218 | - * |
|
219 | - * @param EE_Form_Input_Base $input |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function display_help_text($input) |
|
223 | - { |
|
224 | - if ($input->html_help_text() != '') { |
|
225 | - $tag = is_admin() ? 'p' : 'span'; |
|
226 | - return '<' |
|
227 | - . $tag |
|
228 | - . ' id="' |
|
229 | - . $input->html_id() |
|
230 | - . '-help" class="' |
|
231 | - . $input->html_help_class() |
|
232 | - . '" style="' |
|
233 | - . $input->html_help_style() |
|
234 | - . '">' |
|
235 | - . $input->html_help_text() |
|
236 | - . '</' |
|
237 | - . $tag |
|
238 | - . '>'; |
|
239 | - } |
|
240 | - return ''; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Does an action and hook onto the end of teh form |
|
247 | - * |
|
248 | - * @param string $html |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function add_form_section_hooks_and_filters($html) |
|
252 | - { |
|
253 | - // replace dashes and spaces with underscores |
|
254 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
255 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
256 | - $html = apply_filters('AFEE__Form_Section_Layout__' . $hook_name . '__html', $html, $this->_form_section); |
|
257 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
258 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
259 | - return $html; |
|
260 | - } |
|
17 | + /** |
|
18 | + * Form form section to lay out |
|
19 | + * |
|
20 | + * @var EE_Form_Section_Proper |
|
21 | + */ |
|
22 | + protected $_form_section; |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * __construct |
|
28 | + */ |
|
29 | + function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * The form section on which this strategy is to perform |
|
37 | + * |
|
38 | + * @param EE_Form_Section_Proper $form |
|
39 | + */ |
|
40 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
41 | + { |
|
42 | + $this->_form_section = $form; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return \EE_Form_Section_Proper |
|
49 | + */ |
|
50 | + public function form_section() |
|
51 | + { |
|
52 | + return $this->_form_section; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
59 | + * this form. |
|
60 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
61 | + * proper subsections. |
|
62 | + * Returns the HTML |
|
63 | + * |
|
64 | + * @return string HTML for displaying |
|
65 | + */ |
|
66 | + public function layout_form() |
|
67 | + { |
|
68 | + $html = ''; |
|
69 | + // layout_form_begin |
|
70 | + $html .= apply_filters( |
|
71 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
72 | + $this->layout_form_begin(), |
|
73 | + $this->_form_section |
|
74 | + ); |
|
75 | + // layout_form_loop |
|
76 | + $html .= apply_filters( |
|
77 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
78 | + $this->layout_form_loop(), |
|
79 | + $this->_form_section |
|
80 | + ); |
|
81 | + // layout_form_end |
|
82 | + $html .= apply_filters( |
|
83 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
84 | + $this->layout_form_end(), |
|
85 | + $this->_form_section |
|
86 | + ); |
|
87 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
88 | + return $html; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function layout_form_loop() |
|
97 | + { |
|
98 | + $html = ''; |
|
99 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
100 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
101 | + $html .= apply_filters( |
|
102 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' . $name . '__in_' . $this->_form_section->name(), |
|
103 | + $this->layout_input($subsection), |
|
104 | + $this->_form_section, |
|
105 | + $subsection |
|
106 | + ); |
|
107 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
108 | + $html .= apply_filters( |
|
109 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' . $name . '__in_' . $this->_form_section->name(), |
|
110 | + $this->layout_subsection($subsection), |
|
111 | + $this->_form_section, |
|
112 | + $subsection |
|
113 | + ); |
|
114 | + } |
|
115 | + } |
|
116 | + return $html; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + abstract public function layout_form_begin(); |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + abstract public function layout_form_end(); |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
141 | + * is putting each input in a row of its own, this should probably be called by a |
|
142 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | + * customize the form's layout, but would like to make use of it for laying out |
|
145 | + * 'easy-to-layout' inputs |
|
146 | + * |
|
147 | + * @param EE_Form_Input_Base $input |
|
148 | + * @return string html |
|
149 | + */ |
|
150 | + abstract public function layout_input($input); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | + * that the proper subsection will layout its container, label, etc on its own. |
|
158 | + * |
|
159 | + * @param EE_Form_Section_Base $subsection |
|
160 | + * @return string html |
|
161 | + */ |
|
162 | + abstract public function layout_subsection($subsection); |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Gets the HTML for the label tag and its contents for the input |
|
168 | + * |
|
169 | + * @param EE_Form_Input_Base $input |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function display_label($input) |
|
173 | + { |
|
174 | + $class = $input->required() ? 'ee-required-label ' . $input->html_label_class() : $input->html_label_class(); |
|
175 | + $label_text = $input->required() |
|
176 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
177 | + : $input->html_label_text(); |
|
178 | + return '<label id="' |
|
179 | + . $input->html_label_id() |
|
180 | + . '" class="' |
|
181 | + . $class |
|
182 | + . '" style="' |
|
183 | + . $input->html_label_style() |
|
184 | + . '" for="' . $input->html_name() |
|
185 | + . '">' |
|
186 | + . $label_text |
|
187 | + . '</label>'; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * returns the HTML for the server-side validation errors for the specified input |
|
194 | + * Note that if JS is enabled, it should remove these and instead |
|
195 | + * populate the form's errors in the jquery validate fashion |
|
196 | + * using the localized data provided to the JS |
|
197 | + * |
|
198 | + * @param EE_Form_Input_Base $input |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function display_errors($input) |
|
202 | + { |
|
203 | + if ($input->get_validation_errors()) { |
|
204 | + return "<label id='" |
|
205 | + . $input->html_id() |
|
206 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
207 | + . $input->get_validation_error_string() |
|
208 | + . "</label>"; |
|
209 | + } else { |
|
210 | + return ''; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Displays the help span for the specified input |
|
218 | + * |
|
219 | + * @param EE_Form_Input_Base $input |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function display_help_text($input) |
|
223 | + { |
|
224 | + if ($input->html_help_text() != '') { |
|
225 | + $tag = is_admin() ? 'p' : 'span'; |
|
226 | + return '<' |
|
227 | + . $tag |
|
228 | + . ' id="' |
|
229 | + . $input->html_id() |
|
230 | + . '-help" class="' |
|
231 | + . $input->html_help_class() |
|
232 | + . '" style="' |
|
233 | + . $input->html_help_style() |
|
234 | + . '">' |
|
235 | + . $input->html_help_text() |
|
236 | + . '</' |
|
237 | + . $tag |
|
238 | + . '>'; |
|
239 | + } |
|
240 | + return ''; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Does an action and hook onto the end of teh form |
|
247 | + * |
|
248 | + * @param string $html |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function add_form_section_hooks_and_filters($html) |
|
252 | + { |
|
253 | + // replace dashes and spaces with underscores |
|
254 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
255 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
256 | + $html = apply_filters('AFEE__Form_Section_Layout__' . $hook_name . '__html', $html, $this->_form_section); |
|
257 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
258 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
259 | + return $html; |
|
260 | + } |
|
261 | 261 | } |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | $html = ''; |
69 | 69 | // layout_form_begin |
70 | 70 | $html .= apply_filters( |
71 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
71 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
72 | 72 | $this->layout_form_begin(), |
73 | 73 | $this->_form_section |
74 | 74 | ); |
75 | 75 | // layout_form_loop |
76 | 76 | $html .= apply_filters( |
77 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
77 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
78 | 78 | $this->layout_form_loop(), |
79 | 79 | $this->_form_section |
80 | 80 | ); |
81 | 81 | // layout_form_end |
82 | 82 | $html .= apply_filters( |
83 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
83 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
84 | 84 | $this->layout_form_end(), |
85 | 85 | $this->_form_section |
86 | 86 | ); |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | foreach ($this->_form_section->subsections() as $name => $subsection) { |
100 | 100 | if ($subsection instanceof EE_Form_Input_Base) { |
101 | 101 | $html .= apply_filters( |
102 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' . $name . '__in_' . $this->_form_section->name(), |
|
102 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'.$name.'__in_'.$this->_form_section->name(), |
|
103 | 103 | $this->layout_input($subsection), |
104 | 104 | $this->_form_section, |
105 | 105 | $subsection |
106 | 106 | ); |
107 | 107 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
108 | 108 | $html .= apply_filters( |
109 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' . $name . '__in_' . $this->_form_section->name(), |
|
109 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'.$name.'__in_'.$this->_form_section->name(), |
|
110 | 110 | $this->layout_subsection($subsection), |
111 | 111 | $this->_form_section, |
112 | 112 | $subsection |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function display_label($input) |
173 | 173 | { |
174 | - $class = $input->required() ? 'ee-required-label ' . $input->html_label_class() : $input->html_label_class(); |
|
174 | + $class = $input->required() ? 'ee-required-label '.$input->html_label_class() : $input->html_label_class(); |
|
175 | 175 | $label_text = $input->required() |
176 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
176 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
177 | 177 | : $input->html_label_text(); |
178 | 178 | return '<label id="' |
179 | 179 | . $input->html_label_id() |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | . $class |
182 | 182 | . '" style="' |
183 | 183 | . $input->html_label_style() |
184 | - . '" for="' . $input->html_name() |
|
184 | + . '" for="'.$input->html_name() |
|
185 | 185 | . '">' |
186 | 186 | . $label_text |
187 | 187 | . '</label>'; |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | { |
253 | 253 | // replace dashes and spaces with underscores |
254 | 254 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
255 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
256 | - $html = apply_filters('AFEE__Form_Section_Layout__' . $hook_name . '__html', $html, $this->_form_section); |
|
257 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
258 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
255 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
256 | + $html = apply_filters('AFEE__Form_Section_Layout__'.$hook_name.'__html', $html, $this->_form_section); |
|
257 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
258 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
259 | 259 | return $html; |
260 | 260 | } |
261 | 261 | } |
@@ -9,69 +9,69 @@ |
||
9 | 9 | class EE_Admin_Two_Column_Layout extends EE_Two_Column_Layout |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * Overriding the parent table layout to include <tbody> tags |
|
14 | - * |
|
15 | - * @param array $additional_args |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function layout_form_begin($additional_args = array()) |
|
19 | - { |
|
20 | - $this->_form_section->set_html_class('form-table'); |
|
21 | - return parent::layout_form_begin($additional_args); |
|
22 | - } |
|
12 | + /** |
|
13 | + * Overriding the parent table layout to include <tbody> tags |
|
14 | + * |
|
15 | + * @param array $additional_args |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function layout_form_begin($additional_args = array()) |
|
19 | + { |
|
20 | + $this->_form_section->set_html_class('form-table'); |
|
21 | + return parent::layout_form_begin($additional_args); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Lays out a row for the subsection |
|
28 | - * |
|
29 | - * @param EE_Form_Section_Proper $form_section |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function layout_subsection($form_section) |
|
33 | - { |
|
34 | - if ($form_section instanceof EE_Form_Section_Proper) { |
|
35 | - return EEH_HTML::no_row($form_section->get_html(), 2); |
|
36 | - } elseif ($form_section instanceof EE_Form_Section_HTML) { |
|
37 | - return EEH_HTML::no_row($form_section->get_html(), 2); |
|
38 | - } |
|
39 | - return ''; |
|
40 | - } |
|
26 | + /** |
|
27 | + * Lays out a row for the subsection |
|
28 | + * |
|
29 | + * @param EE_Form_Section_Proper $form_section |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function layout_subsection($form_section) |
|
33 | + { |
|
34 | + if ($form_section instanceof EE_Form_Section_Proper) { |
|
35 | + return EEH_HTML::no_row($form_section->get_html(), 2); |
|
36 | + } elseif ($form_section instanceof EE_Form_Section_HTML) { |
|
37 | + return EEH_HTML::no_row($form_section->get_html(), 2); |
|
38 | + } |
|
39 | + return ''; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Lays out the row for the input, including label and errors |
|
46 | - * |
|
47 | - * @param EE_Form_Input_Base $input |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function layout_input($input) |
|
51 | - { |
|
52 | - if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
53 | - || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
54 | - || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
55 | - ) { |
|
56 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
57 | - } |
|
58 | - if ($input instanceof EE_Text_Area_Input) { |
|
59 | - $input->set_rows(4); |
|
60 | - $input->set_cols(60); |
|
61 | - } |
|
62 | - $input_html = $input->get_html_for_input(); |
|
63 | - // maybe add errors and help text ? |
|
64 | - $input_html .= $input->get_html_for_errors() != '' ? EEH_HTML::nl() . $input->get_html_for_errors() : ''; |
|
65 | - $input_html .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
66 | - //overriding parent to add wp admin specific things. |
|
67 | - $html = ''; |
|
68 | - if ($input instanceof EE_Hidden_Input) { |
|
69 | - $html .= EEH_HTML::no_row($input->get_html_for_input(), 2); |
|
70 | - } else { |
|
71 | - $html .= EEH_HTML::tr( |
|
72 | - EEH_HTML::th($input->get_html_for_label(), '', '', '', 'scope="row"') . EEH_HTML::td($input_html) |
|
73 | - ); |
|
74 | - } |
|
75 | - return $html; |
|
76 | - } |
|
44 | + /** |
|
45 | + * Lays out the row for the input, including label and errors |
|
46 | + * |
|
47 | + * @param EE_Form_Input_Base $input |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function layout_input($input) |
|
51 | + { |
|
52 | + if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
53 | + || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
54 | + || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
55 | + ) { |
|
56 | + $input->set_html_class($input->html_class() . ' large-text'); |
|
57 | + } |
|
58 | + if ($input instanceof EE_Text_Area_Input) { |
|
59 | + $input->set_rows(4); |
|
60 | + $input->set_cols(60); |
|
61 | + } |
|
62 | + $input_html = $input->get_html_for_input(); |
|
63 | + // maybe add errors and help text ? |
|
64 | + $input_html .= $input->get_html_for_errors() != '' ? EEH_HTML::nl() . $input->get_html_for_errors() : ''; |
|
65 | + $input_html .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
66 | + //overriding parent to add wp admin specific things. |
|
67 | + $html = ''; |
|
68 | + if ($input instanceof EE_Hidden_Input) { |
|
69 | + $html .= EEH_HTML::no_row($input->get_html_for_input(), 2); |
|
70 | + } else { |
|
71 | + $html .= EEH_HTML::tr( |
|
72 | + EEH_HTML::th($input->get_html_for_label(), '', '', '', 'scope="row"') . EEH_HTML::td($input_html) |
|
73 | + ); |
|
74 | + } |
|
75 | + return $html; |
|
76 | + } |
|
77 | 77 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
54 | 54 | || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
55 | 55 | ) { |
56 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
56 | + $input->set_html_class($input->html_class().' large-text'); |
|
57 | 57 | } |
58 | 58 | if ($input instanceof EE_Text_Area_Input) { |
59 | 59 | $input->set_rows(4); |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | } |
62 | 62 | $input_html = $input->get_html_for_input(); |
63 | 63 | // maybe add errors and help text ? |
64 | - $input_html .= $input->get_html_for_errors() != '' ? EEH_HTML::nl() . $input->get_html_for_errors() : ''; |
|
65 | - $input_html .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
64 | + $input_html .= $input->get_html_for_errors() != '' ? EEH_HTML::nl().$input->get_html_for_errors() : ''; |
|
65 | + $input_html .= $input->get_html_for_help() != '' ? EEH_HTML::nl().$input->get_html_for_help() : ''; |
|
66 | 66 | //overriding parent to add wp admin specific things. |
67 | 67 | $html = ''; |
68 | 68 | if ($input instanceof EE_Hidden_Input) { |
69 | 69 | $html .= EEH_HTML::no_row($input->get_html_for_input(), 2); |
70 | 70 | } else { |
71 | 71 | $html .= EEH_HTML::tr( |
72 | - EEH_HTML::th($input->get_html_for_label(), '', '', '', 'scope="row"') . EEH_HTML::td($input_html) |
|
72 | + EEH_HTML::th($input->get_html_for_label(), '', '', '', 'scope="row"').EEH_HTML::td($input_html) |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 | return $html; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,109 +16,109 @@ discard block |
||
16 | 16 | class EE_Fieldset_Section_Layout extends EE_Div_Per_Section_Layout |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * legend_class |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_legend_class; |
|
25 | - |
|
26 | - /** |
|
27 | - * legend_text |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_legend_text; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * construct |
|
37 | - * |
|
38 | - * @param array $options |
|
39 | - */ |
|
40 | - public function __construct($options = array()) |
|
41 | - { |
|
42 | - foreach ($options as $key => $value) { |
|
43 | - $key = '_' . $key; |
|
44 | - if (property_exists($this, $key)) { |
|
45 | - $this->{$key} = $value; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * opening div tag for a form |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function layout_form_begin() |
|
58 | - { |
|
59 | - $html = EEH_HTML::nl(1) |
|
60 | - . '<fieldset id="' |
|
61 | - . $this->_form_section->html_id() |
|
62 | - . '" class="' |
|
63 | - . $this->_form_section->html_class() |
|
64 | - . '" style="' |
|
65 | - . $this->_form_section->html_style() |
|
66 | - . '">'; |
|
67 | - $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
68 | - return $html; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * closing div tag for a form |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function layout_form_end() |
|
79 | - { |
|
80 | - return EEH_HTML::nl(-1) . '</fieldset>'; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $legend_class |
|
87 | - */ |
|
88 | - public function set_legend_class($legend_class) |
|
89 | - { |
|
90 | - $this->_legend_class = $legend_class; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function legend_class() |
|
99 | - { |
|
100 | - return $this->_legend_class; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $legend_text |
|
107 | - */ |
|
108 | - public function set_legend_text($legend_text) |
|
109 | - { |
|
110 | - $this->_legend_text = $legend_text; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function legend_text() |
|
119 | - { |
|
120 | - return $this->_legend_text; |
|
121 | - } |
|
19 | + /** |
|
20 | + * legend_class |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_legend_class; |
|
25 | + |
|
26 | + /** |
|
27 | + * legend_text |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_legend_text; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * construct |
|
37 | + * |
|
38 | + * @param array $options |
|
39 | + */ |
|
40 | + public function __construct($options = array()) |
|
41 | + { |
|
42 | + foreach ($options as $key => $value) { |
|
43 | + $key = '_' . $key; |
|
44 | + if (property_exists($this, $key)) { |
|
45 | + $this->{$key} = $value; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * opening div tag for a form |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function layout_form_begin() |
|
58 | + { |
|
59 | + $html = EEH_HTML::nl(1) |
|
60 | + . '<fieldset id="' |
|
61 | + . $this->_form_section->html_id() |
|
62 | + . '" class="' |
|
63 | + . $this->_form_section->html_class() |
|
64 | + . '" style="' |
|
65 | + . $this->_form_section->html_style() |
|
66 | + . '">'; |
|
67 | + $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
68 | + return $html; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * closing div tag for a form |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function layout_form_end() |
|
79 | + { |
|
80 | + return EEH_HTML::nl(-1) . '</fieldset>'; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $legend_class |
|
87 | + */ |
|
88 | + public function set_legend_class($legend_class) |
|
89 | + { |
|
90 | + $this->_legend_class = $legend_class; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function legend_class() |
|
99 | + { |
|
100 | + return $this->_legend_class; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $legend_text |
|
107 | + */ |
|
108 | + public function set_legend_text($legend_text) |
|
109 | + { |
|
110 | + $this->_legend_text = $legend_text; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function legend_text() |
|
119 | + { |
|
120 | + return $this->_legend_text; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | 124 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function __construct($options = array()) |
41 | 41 | { |
42 | 42 | foreach ($options as $key => $value) { |
43 | - $key = '_' . $key; |
|
43 | + $key = '_'.$key; |
|
44 | 44 | if (property_exists($this, $key)) { |
45 | 45 | $this->{$key} = $value; |
46 | 46 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | . '" style="' |
65 | 65 | . $this->_form_section->html_style() |
66 | 66 | . '">'; |
67 | - $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
67 | + $html .= '<legend class="'.$this->legend_class().'">'.$this->legend_text().'</legend>'; |
|
68 | 68 | return $html; |
69 | 69 | } |
70 | 70 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function layout_form_end() |
79 | 79 | { |
80 | - return EEH_HTML::nl(-1) . '</fieldset>'; |
|
80 | + return EEH_HTML::nl(-1).'</fieldset>'; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 |
@@ -15,117 +15,117 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
20 | - * strategy. |
|
21 | - * |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $_use_break_tags = true; |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * EE_No_Layout constructor. |
|
30 | - * |
|
31 | - * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
32 | - * property on the class. |
|
33 | - */ |
|
34 | - public function __construct($options = array()) |
|
35 | - { |
|
36 | - $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
37 | - ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
38 | - : $this->_use_break_tags; |
|
39 | - parent::__construct(); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Add line break at beginning of form |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function layout_form_begin() |
|
50 | - { |
|
51 | - return EEH_HTML::nl(1); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Lays out the row for the input, including label and errors |
|
58 | - * |
|
59 | - * @param EE_Form_Input_Base $input |
|
60 | - * @return string |
|
61 | - * @throws \EE_Error |
|
62 | - */ |
|
63 | - public function layout_input($input) |
|
64 | - { |
|
65 | - $html = ''; |
|
66 | - if ($input instanceof EE_Hidden_Input) { |
|
67 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
68 | - } elseif ($input instanceof EE_Submit_Input) { |
|
69 | - $html .= $this->br(); |
|
70 | - $html .= $input->get_html_for_input(); |
|
71 | - } elseif ($input instanceof EE_Select_Input) { |
|
72 | - $html .= $this->br(); |
|
73 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
74 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
75 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
76 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
77 | - $html .= $this->br(); |
|
78 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
79 | - $html .= $this->br(); |
|
80 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
81 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
82 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
83 | - } else { |
|
84 | - $html .= $this->br(); |
|
85 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
86 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
87 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
88 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
89 | - } |
|
90 | - $html .= EEH_HTML::nl(-1); |
|
91 | - return $html; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Lays out a row for the subsection |
|
98 | - * |
|
99 | - * @param EE_Form_Section_Proper $form_section |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function layout_subsection($form_section) |
|
103 | - { |
|
104 | - // d( $form_section ); |
|
105 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Add line break at end of form. |
|
112 | - * |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function layout_form_end() |
|
116 | - { |
|
117 | - return EEH_HTML::nl(-1); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - protected function br() |
|
128 | - { |
|
129 | - return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
130 | - } |
|
18 | + /** |
|
19 | + * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
20 | + * strategy. |
|
21 | + * |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $_use_break_tags = true; |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * EE_No_Layout constructor. |
|
30 | + * |
|
31 | + * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
32 | + * property on the class. |
|
33 | + */ |
|
34 | + public function __construct($options = array()) |
|
35 | + { |
|
36 | + $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
37 | + ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
38 | + : $this->_use_break_tags; |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Add line break at beginning of form |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function layout_form_begin() |
|
50 | + { |
|
51 | + return EEH_HTML::nl(1); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Lays out the row for the input, including label and errors |
|
58 | + * |
|
59 | + * @param EE_Form_Input_Base $input |
|
60 | + * @return string |
|
61 | + * @throws \EE_Error |
|
62 | + */ |
|
63 | + public function layout_input($input) |
|
64 | + { |
|
65 | + $html = ''; |
|
66 | + if ($input instanceof EE_Hidden_Input) { |
|
67 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
68 | + } elseif ($input instanceof EE_Submit_Input) { |
|
69 | + $html .= $this->br(); |
|
70 | + $html .= $input->get_html_for_input(); |
|
71 | + } elseif ($input instanceof EE_Select_Input) { |
|
72 | + $html .= $this->br(); |
|
73 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
74 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
75 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
76 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
77 | + $html .= $this->br(); |
|
78 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
79 | + $html .= $this->br(); |
|
80 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
81 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
82 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
83 | + } else { |
|
84 | + $html .= $this->br(); |
|
85 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
86 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
87 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
88 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
89 | + } |
|
90 | + $html .= EEH_HTML::nl(-1); |
|
91 | + return $html; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Lays out a row for the subsection |
|
98 | + * |
|
99 | + * @param EE_Form_Section_Proper $form_section |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function layout_subsection($form_section) |
|
103 | + { |
|
104 | + // d( $form_section ); |
|
105 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Add line break at end of form. |
|
112 | + * |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function layout_form_end() |
|
116 | + { |
|
117 | + return EEH_HTML::nl(-1); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + protected function br() |
|
128 | + { |
|
129 | + return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
130 | + } |
|
131 | 131 | } |
@@ -64,28 +64,28 @@ discard block |
||
64 | 64 | { |
65 | 65 | $html = ''; |
66 | 66 | if ($input instanceof EE_Hidden_Input) { |
67 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
67 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
68 | 68 | } elseif ($input instanceof EE_Submit_Input) { |
69 | 69 | $html .= $this->br(); |
70 | 70 | $html .= $input->get_html_for_input(); |
71 | 71 | } elseif ($input instanceof EE_Select_Input) { |
72 | 72 | $html .= $this->br(); |
73 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
74 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
75 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
76 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
73 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
74 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
75 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
76 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
77 | 77 | $html .= $this->br(); |
78 | 78 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
79 | 79 | $html .= $this->br(); |
80 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
81 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
82 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
80 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
81 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
82 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
83 | 83 | } else { |
84 | 84 | $html .= $this->br(); |
85 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
86 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
87 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
88 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
85 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
86 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
87 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
88 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
89 | 89 | } |
90 | 90 | $html .= EEH_HTML::nl(-1); |
91 | 91 | return $html; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | public function layout_subsection($form_section) |
103 | 103 | { |
104 | 104 | // d( $form_section ); |
105 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
105 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 |