@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * allowed) |
591 | 591 | * |
592 | 592 | * @param string $datetime_string mysql timestamp in UTC |
593 | - * @return mixed null | DateTime |
|
593 | + * @return null|DbSafeDateTime null | DateTime |
|
594 | 594 | * @throws \EE_Error |
595 | 595 | */ |
596 | 596 | public function prepare_for_set_from_db($datetime_string) |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * |
750 | 750 | * @param \DateTimeZone $DateTimeZone |
751 | 751 | * @param int $time |
752 | - * @return mixed |
|
752 | + * @return integer |
|
753 | 753 | * @throws \DomainException |
754 | 754 | */ |
755 | 755 | public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\domain\entities\DbSafeDateTime; |
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 | /** |
@@ -17,102 +17,102 @@ discard block |
||
17 | 17 | class EE_Datetime_Field extends EE_Model_Field_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
22 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
23 | - * @type string unix_timestamp_regex |
|
24 | - */ |
|
25 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
26 | - |
|
27 | - /** |
|
28 | - * @type string mysql_timestamp_format |
|
29 | - */ |
|
30 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @type string mysql_date_format |
|
34 | - */ |
|
35 | - const mysql_date_format = 'Y-m-d'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @type string mysql_time_format |
|
39 | - */ |
|
40 | - const mysql_time_format = 'H:i:s'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Const for using in the default value. If the field's default is set to this, |
|
44 | - * then we will return the time of calling `get_default_value()`, not |
|
45 | - * just the current time at construction |
|
46 | - */ |
|
47 | - const now = 'now'; |
|
48 | - |
|
49 | - /** |
|
50 | - * The following properties hold the default formats for date and time. |
|
51 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
52 | - * However they can also be overridden later by the set_format() method |
|
53 | - * (and corresponding set_date_format, set_time_format methods); |
|
54 | - */ |
|
55 | - /** |
|
56 | - * @type string $_date_format |
|
57 | - */ |
|
58 | - protected $_date_format = ''; |
|
59 | - |
|
60 | - /** |
|
61 | - * @type string $_time_format |
|
62 | - */ |
|
63 | - protected $_time_format = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * @type string $_pretty_date_format |
|
67 | - */ |
|
68 | - protected $_pretty_date_format = ''; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type string $_pretty_time_format |
|
72 | - */ |
|
73 | - protected $_pretty_time_format = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type DateTimeZone $_DateTimeZone |
|
77 | - */ |
|
78 | - protected $_DateTimeZone; |
|
79 | - |
|
80 | - /** |
|
81 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
82 | - */ |
|
83 | - protected $_UTC_DateTimeZone; |
|
84 | - |
|
85 | - /** |
|
86 | - * @type DateTimeZone $_blog_DateTimeZone |
|
87 | - */ |
|
88 | - protected $_blog_DateTimeZone; |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
93 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
94 | - * and time returned via getters. |
|
95 | - * @var mixed (null|string) |
|
96 | - */ |
|
97 | - protected $_date_time_output; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * timezone string |
|
102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | - * @var string |
|
106 | - */ |
|
107 | - protected $_timezone_string; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
112 | - * offsets for comparison purposes). |
|
113 | - * @var int |
|
114 | - */ |
|
115 | - protected $_blog_offset; |
|
20 | + /** |
|
21 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
22 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
23 | + * @type string unix_timestamp_regex |
|
24 | + */ |
|
25 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
26 | + |
|
27 | + /** |
|
28 | + * @type string mysql_timestamp_format |
|
29 | + */ |
|
30 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @type string mysql_date_format |
|
34 | + */ |
|
35 | + const mysql_date_format = 'Y-m-d'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @type string mysql_time_format |
|
39 | + */ |
|
40 | + const mysql_time_format = 'H:i:s'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Const for using in the default value. If the field's default is set to this, |
|
44 | + * then we will return the time of calling `get_default_value()`, not |
|
45 | + * just the current time at construction |
|
46 | + */ |
|
47 | + const now = 'now'; |
|
48 | + |
|
49 | + /** |
|
50 | + * The following properties hold the default formats for date and time. |
|
51 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
52 | + * However they can also be overridden later by the set_format() method |
|
53 | + * (and corresponding set_date_format, set_time_format methods); |
|
54 | + */ |
|
55 | + /** |
|
56 | + * @type string $_date_format |
|
57 | + */ |
|
58 | + protected $_date_format = ''; |
|
59 | + |
|
60 | + /** |
|
61 | + * @type string $_time_format |
|
62 | + */ |
|
63 | + protected $_time_format = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * @type string $_pretty_date_format |
|
67 | + */ |
|
68 | + protected $_pretty_date_format = ''; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type string $_pretty_time_format |
|
72 | + */ |
|
73 | + protected $_pretty_time_format = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type DateTimeZone $_DateTimeZone |
|
77 | + */ |
|
78 | + protected $_DateTimeZone; |
|
79 | + |
|
80 | + /** |
|
81 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
82 | + */ |
|
83 | + protected $_UTC_DateTimeZone; |
|
84 | + |
|
85 | + /** |
|
86 | + * @type DateTimeZone $_blog_DateTimeZone |
|
87 | + */ |
|
88 | + protected $_blog_DateTimeZone; |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
93 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
94 | + * and time returned via getters. |
|
95 | + * @var mixed (null|string) |
|
96 | + */ |
|
97 | + protected $_date_time_output; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * timezone string |
|
102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | + * @var string |
|
106 | + */ |
|
107 | + protected $_timezone_string; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
112 | + * offsets for comparison purposes). |
|
113 | + * @var int |
|
114 | + */ |
|
115 | + protected $_blog_offset; |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
@@ -128,36 +128,36 @@ discard block |
||
128 | 128 | * @param string $pretty_time_format |
129 | 129 | * @throws \EE_Error |
130 | 130 | */ |
131 | - public function __construct( |
|
132 | - $table_column, |
|
133 | - $nice_name, |
|
134 | - $nullable, |
|
135 | - $default_value, |
|
136 | - $timezone_string = '', |
|
137 | - $date_format = '', |
|
138 | - $time_format = '', |
|
139 | - $pretty_date_format = '', |
|
140 | - $pretty_time_format = '' |
|
141 | - ) { |
|
131 | + public function __construct( |
|
132 | + $table_column, |
|
133 | + $nice_name, |
|
134 | + $nullable, |
|
135 | + $default_value, |
|
136 | + $timezone_string = '', |
|
137 | + $date_format = '', |
|
138 | + $time_format = '', |
|
139 | + $pretty_date_format = '', |
|
140 | + $pretty_time_format = '' |
|
141 | + ) { |
|
142 | 142 | |
143 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
144 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
145 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
146 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
143 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
144 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
145 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
146 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
147 | 147 | |
148 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
149 | - $this->set_timezone($timezone_string); |
|
148 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
149 | + $this->set_timezone($timezone_string); |
|
150 | 150 | |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function get_wpdb_data_type() |
|
158 | - { |
|
159 | - return '%s'; |
|
160 | - } |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function get_wpdb_data_type() |
|
158 | + { |
|
159 | + return '%s'; |
|
160 | + } |
|
161 | 161 | |
162 | 162 | |
163 | 163 | |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | * @return DateTimeZone |
166 | 166 | * @throws \EE_Error |
167 | 167 | */ |
168 | - public function get_UTC_DateTimeZone() |
|
169 | - { |
|
170 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
171 | - ? $this->_UTC_DateTimeZone |
|
172 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
173 | - } |
|
168 | + public function get_UTC_DateTimeZone() |
|
169 | + { |
|
170 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
171 | + ? $this->_UTC_DateTimeZone |
|
172 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | 176 | |
@@ -178,69 +178,69 @@ discard block |
||
178 | 178 | * @return DateTimeZone |
179 | 179 | * @throws \EE_Error |
180 | 180 | */ |
181 | - public function get_blog_DateTimeZone() |
|
182 | - { |
|
183 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
184 | - ? $this->_blog_DateTimeZone |
|
185 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
191 | - * |
|
192 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
193 | - * timestamp |
|
194 | - * |
|
195 | - * @return DateTime |
|
196 | - */ |
|
197 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
198 | - { |
|
199 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
205 | - * |
|
206 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
207 | - * |
|
208 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
209 | - * @return string The final assembled format string. |
|
210 | - */ |
|
211 | - protected function _get_date_time_output($pretty = false) |
|
212 | - { |
|
213 | - |
|
214 | - switch ($this->_date_time_output) { |
|
215 | - case 'time' : |
|
216 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
217 | - break; |
|
218 | - |
|
219 | - case 'date' : |
|
220 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
221 | - break; |
|
222 | - |
|
223 | - default : |
|
224 | - return $pretty |
|
225 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
226 | - : $this->_date_format . ' ' . $this->_time_format; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
233 | - * returned (using the format properties) |
|
234 | - * |
|
235 | - * @param string $what acceptable values are 'time' or 'date'. |
|
236 | - * Any other value will be set but will always result |
|
237 | - * in both 'date' and 'time' being returned. |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function set_date_time_output($what = null) |
|
241 | - { |
|
242 | - $this->_date_time_output = $what; |
|
243 | - } |
|
181 | + public function get_blog_DateTimeZone() |
|
182 | + { |
|
183 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
184 | + ? $this->_blog_DateTimeZone |
|
185 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
191 | + * |
|
192 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
193 | + * timestamp |
|
194 | + * |
|
195 | + * @return DateTime |
|
196 | + */ |
|
197 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
198 | + { |
|
199 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
205 | + * |
|
206 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
207 | + * |
|
208 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
209 | + * @return string The final assembled format string. |
|
210 | + */ |
|
211 | + protected function _get_date_time_output($pretty = false) |
|
212 | + { |
|
213 | + |
|
214 | + switch ($this->_date_time_output) { |
|
215 | + case 'time' : |
|
216 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
217 | + break; |
|
218 | + |
|
219 | + case 'date' : |
|
220 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
221 | + break; |
|
222 | + |
|
223 | + default : |
|
224 | + return $pretty |
|
225 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
226 | + : $this->_date_format . ' ' . $this->_time_format; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
233 | + * returned (using the format properties) |
|
234 | + * |
|
235 | + * @param string $what acceptable values are 'time' or 'date'. |
|
236 | + * Any other value will be set but will always result |
|
237 | + * in both 'date' and 'time' being returned. |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function set_date_time_output($what = null) |
|
241 | + { |
|
242 | + $this->_date_time_output = $what; |
|
243 | + } |
|
244 | 244 | |
245 | 245 | |
246 | 246 | |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | * @return void |
256 | 256 | * @throws \EE_Error |
257 | 257 | */ |
258 | - public function set_timezone($timezone_string) |
|
259 | - { |
|
260 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
261 | - // leave the timezone AS-IS if we already have one and |
|
262 | - // the function arg didn't provide one |
|
263 | - return; |
|
264 | - } |
|
265 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
266 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
267 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
268 | - } |
|
258 | + public function set_timezone($timezone_string) |
|
259 | + { |
|
260 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
261 | + // leave the timezone AS-IS if we already have one and |
|
262 | + // the function arg didn't provide one |
|
263 | + return; |
|
264 | + } |
|
265 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
266 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
267 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | 271 | |
@@ -277,178 +277,178 @@ discard block |
||
277 | 277 | * @return \DateTimeZone |
278 | 278 | * @throws \EE_Error |
279 | 279 | */ |
280 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
281 | - { |
|
282 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * This just returns whatever is set for the current timezone. |
|
288 | - * |
|
289 | - * @access public |
|
290 | - * @return string timezone string |
|
291 | - */ |
|
292 | - public function get_timezone() |
|
293 | - { |
|
294 | - return $this->_timezone_string; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * set the $_date_format property |
|
300 | - * |
|
301 | - * @access public |
|
302 | - * |
|
303 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
304 | - * @param bool $pretty Whether to set pretty format or not. |
|
305 | - * |
|
306 | - * @return void |
|
307 | - */ |
|
308 | - public function set_date_format($format, $pretty = false) |
|
309 | - { |
|
310 | - if ($pretty) { |
|
311 | - $this->_pretty_date_format = $format; |
|
312 | - } else { |
|
313 | - $this->_date_format = $format; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * return the $_date_format property value. |
|
320 | - * |
|
321 | - * @param bool $pretty Whether to get pretty format or not. |
|
322 | - * |
|
323 | - * @return string |
|
324 | - */ |
|
325 | - public function get_date_format($pretty = false) |
|
326 | - { |
|
327 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * set the $_time_format property |
|
333 | - * |
|
334 | - * @access public |
|
335 | - * |
|
336 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
337 | - * @param bool $pretty Whether to set pretty format or not. |
|
338 | - * |
|
339 | - * @return void |
|
340 | - */ |
|
341 | - public function set_time_format($format, $pretty = false) |
|
342 | - { |
|
343 | - if ($pretty) { |
|
344 | - $this->_pretty_time_format = $format; |
|
345 | - } else { |
|
346 | - $this->_time_format = $format; |
|
347 | - } |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * return the $_time_format property value. |
|
353 | - * |
|
354 | - * @param bool $pretty Whether to get pretty format or not. |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function get_time_format($pretty = false) |
|
359 | - { |
|
360 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * set the $_pretty_date_format property |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * |
|
369 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
370 | - * |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public function set_pretty_date_format($format) |
|
374 | - { |
|
375 | - $this->_pretty_date_format = $format; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * set the $_pretty_time_format property |
|
381 | - * |
|
382 | - * @access public |
|
383 | - * |
|
384 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
385 | - * |
|
386 | - * @return void |
|
387 | - */ |
|
388 | - public function set_pretty_time_format($format) |
|
389 | - { |
|
390 | - $this->_pretty_time_format = $format; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Only sets the time portion of the datetime. |
|
396 | - * |
|
397 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
398 | - * @param DateTime $current current DateTime object for the datetime field |
|
399 | - * |
|
400 | - * @return DateTime |
|
401 | - */ |
|
402 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
403 | - { |
|
404 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
405 | - // Otherwise parse the string. |
|
406 | - if ($time_to_set_string instanceof DateTime) { |
|
407 | - $parsed = array( |
|
408 | - 'hour' => $time_to_set_string->format('H'), |
|
409 | - 'minute' => $time_to_set_string->format('i'), |
|
410 | - 'second' => $time_to_set_string->format('s') |
|
411 | - ); |
|
412 | - } else { |
|
413 | - //parse incoming string |
|
414 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
415 | - } |
|
416 | - |
|
417 | - //make sure $current is in the correct timezone. |
|
418 | - $current->setTimezone($this->_DateTimeZone); |
|
419 | - |
|
420 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Only sets the date portion of the datetime. |
|
426 | - * |
|
427 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
428 | - * @param DateTime $current current DateTime object for the datetime field |
|
429 | - * |
|
430 | - * @return DateTime |
|
431 | - */ |
|
432 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
433 | - { |
|
434 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
435 | - // Otherwise parse the string. |
|
436 | - if ($date_to_set_string instanceof DateTime) { |
|
437 | - $parsed = array( |
|
438 | - 'year' => $date_to_set_string->format('Y'), |
|
439 | - 'month' => $date_to_set_string->format('m'), |
|
440 | - 'day' => $date_to_set_string->format('d') |
|
441 | - ); |
|
442 | - } else { |
|
443 | - //parse incoming string |
|
444 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
445 | - } |
|
446 | - |
|
447 | - //make sure $current is in the correct timezone |
|
448 | - $current->setTimezone($this->_DateTimeZone); |
|
449 | - |
|
450 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
451 | - } |
|
280 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
281 | + { |
|
282 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * This just returns whatever is set for the current timezone. |
|
288 | + * |
|
289 | + * @access public |
|
290 | + * @return string timezone string |
|
291 | + */ |
|
292 | + public function get_timezone() |
|
293 | + { |
|
294 | + return $this->_timezone_string; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * set the $_date_format property |
|
300 | + * |
|
301 | + * @access public |
|
302 | + * |
|
303 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
304 | + * @param bool $pretty Whether to set pretty format or not. |
|
305 | + * |
|
306 | + * @return void |
|
307 | + */ |
|
308 | + public function set_date_format($format, $pretty = false) |
|
309 | + { |
|
310 | + if ($pretty) { |
|
311 | + $this->_pretty_date_format = $format; |
|
312 | + } else { |
|
313 | + $this->_date_format = $format; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * return the $_date_format property value. |
|
320 | + * |
|
321 | + * @param bool $pretty Whether to get pretty format or not. |
|
322 | + * |
|
323 | + * @return string |
|
324 | + */ |
|
325 | + public function get_date_format($pretty = false) |
|
326 | + { |
|
327 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * set the $_time_format property |
|
333 | + * |
|
334 | + * @access public |
|
335 | + * |
|
336 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
337 | + * @param bool $pretty Whether to set pretty format or not. |
|
338 | + * |
|
339 | + * @return void |
|
340 | + */ |
|
341 | + public function set_time_format($format, $pretty = false) |
|
342 | + { |
|
343 | + if ($pretty) { |
|
344 | + $this->_pretty_time_format = $format; |
|
345 | + } else { |
|
346 | + $this->_time_format = $format; |
|
347 | + } |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * return the $_time_format property value. |
|
353 | + * |
|
354 | + * @param bool $pretty Whether to get pretty format or not. |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function get_time_format($pretty = false) |
|
359 | + { |
|
360 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * set the $_pretty_date_format property |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * |
|
369 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
370 | + * |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public function set_pretty_date_format($format) |
|
374 | + { |
|
375 | + $this->_pretty_date_format = $format; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * set the $_pretty_time_format property |
|
381 | + * |
|
382 | + * @access public |
|
383 | + * |
|
384 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
385 | + * |
|
386 | + * @return void |
|
387 | + */ |
|
388 | + public function set_pretty_time_format($format) |
|
389 | + { |
|
390 | + $this->_pretty_time_format = $format; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Only sets the time portion of the datetime. |
|
396 | + * |
|
397 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
398 | + * @param DateTime $current current DateTime object for the datetime field |
|
399 | + * |
|
400 | + * @return DateTime |
|
401 | + */ |
|
402 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
403 | + { |
|
404 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
405 | + // Otherwise parse the string. |
|
406 | + if ($time_to_set_string instanceof DateTime) { |
|
407 | + $parsed = array( |
|
408 | + 'hour' => $time_to_set_string->format('H'), |
|
409 | + 'minute' => $time_to_set_string->format('i'), |
|
410 | + 'second' => $time_to_set_string->format('s') |
|
411 | + ); |
|
412 | + } else { |
|
413 | + //parse incoming string |
|
414 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
415 | + } |
|
416 | + |
|
417 | + //make sure $current is in the correct timezone. |
|
418 | + $current->setTimezone($this->_DateTimeZone); |
|
419 | + |
|
420 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Only sets the date portion of the datetime. |
|
426 | + * |
|
427 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
428 | + * @param DateTime $current current DateTime object for the datetime field |
|
429 | + * |
|
430 | + * @return DateTime |
|
431 | + */ |
|
432 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
433 | + { |
|
434 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
435 | + // Otherwise parse the string. |
|
436 | + if ($date_to_set_string instanceof DateTime) { |
|
437 | + $parsed = array( |
|
438 | + 'year' => $date_to_set_string->format('Y'), |
|
439 | + 'month' => $date_to_set_string->format('m'), |
|
440 | + 'day' => $date_to_set_string->format('d') |
|
441 | + ); |
|
442 | + } else { |
|
443 | + //parse incoming string |
|
444 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
445 | + } |
|
446 | + |
|
447 | + //make sure $current is in the correct timezone |
|
448 | + $current->setTimezone($this->_DateTimeZone); |
|
449 | + |
|
450 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
451 | + } |
|
452 | 452 | |
453 | 453 | |
454 | 454 | |
@@ -460,10 +460,10 @@ discard block |
||
460 | 460 | * @return string formatted date time for given timezone |
461 | 461 | * @throws \EE_Error |
462 | 462 | */ |
463 | - public function prepare_for_get($DateTime) |
|
464 | - { |
|
465 | - return $this->_prepare_for_display($DateTime); |
|
466 | - } |
|
463 | + public function prepare_for_get($DateTime) |
|
464 | + { |
|
465 | + return $this->_prepare_for_display($DateTime); |
|
466 | + } |
|
467 | 467 | |
468 | 468 | |
469 | 469 | |
@@ -478,110 +478,110 @@ discard block |
||
478 | 478 | * @return string |
479 | 479 | * @throws \EE_Error |
480 | 480 | */ |
481 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
482 | - { |
|
483 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
489 | - * timezone). |
|
490 | - * |
|
491 | - * @param DateTime $DateTime |
|
492 | - * @param bool|string $schema |
|
493 | - * @return string |
|
494 | - * @throws \EE_Error |
|
495 | - */ |
|
496 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
497 | - { |
|
498 | - if ( ! $DateTime instanceof DateTime) { |
|
499 | - if ($this->_nullable) { |
|
500 | - return ''; |
|
501 | - } else { |
|
502 | - if (WP_DEBUG) { |
|
503 | - throw new EE_Error( |
|
504 | - sprintf( |
|
505 | - __( |
|
506 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
507 | - 'event_espresso' |
|
508 | - ), |
|
509 | - $this->_nicename |
|
510 | - ) |
|
511 | - ); |
|
512 | - } else { |
|
513 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
514 | - EE_Error::add_error( |
|
515 | - sprintf( |
|
516 | - __( |
|
517 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
518 | - 'event_espresso' |
|
519 | - ), |
|
520 | - $this->_nicename |
|
521 | - ) |
|
522 | - ); |
|
523 | - } |
|
524 | - } |
|
525 | - } |
|
526 | - $format_string = $this->_get_date_time_output($schema); |
|
527 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
528 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
529 | - if ($schema) { |
|
530 | - if ($this->_display_timezone()) { |
|
531 | - //must be explicit because schema could equal true. |
|
532 | - if ($schema === 'no_html') { |
|
533 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
534 | - } else { |
|
535 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
536 | - } |
|
537 | - } else { |
|
538 | - $timezone_string = ''; |
|
539 | - } |
|
540 | - |
|
541 | - return $DateTime->format($format_string) . $timezone_string; |
|
542 | - } else { |
|
543 | - return $DateTime->format($format_string); |
|
544 | - } |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
550 | - * timezone). |
|
551 | - * |
|
552 | - * @param mixed $datetime_value u |
|
553 | - * |
|
554 | - * @return string mysql timestamp in UTC |
|
555 | - * @throws \EE_Error |
|
556 | - */ |
|
557 | - public function prepare_for_use_in_db($datetime_value) |
|
558 | - { |
|
559 | - //we allow an empty value or DateTime object, but nothing else. |
|
560 | - if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
561 | - throw new EE_Error( |
|
562 | - __( |
|
563 | - 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
564 | - 'event_espresso' |
|
565 | - ) |
|
566 | - ); |
|
567 | - } |
|
568 | - |
|
569 | - if ($datetime_value instanceof DateTime) { |
|
570 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
571 | - $datetime_value = new DbSafeDateTime( |
|
572 | - $datetime_value->format(EE_Datetime_Field::mysql_timestamp_format), |
|
573 | - new \DateTimeZone($datetime_value->format('e')) |
|
574 | - ); |
|
575 | - } |
|
576 | - |
|
577 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
578 | - EE_Datetime_Field::mysql_timestamp_format |
|
579 | - ); |
|
580 | - } |
|
581 | - |
|
582 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
583 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
584 | - } |
|
481 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
482 | + { |
|
483 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
489 | + * timezone). |
|
490 | + * |
|
491 | + * @param DateTime $DateTime |
|
492 | + * @param bool|string $schema |
|
493 | + * @return string |
|
494 | + * @throws \EE_Error |
|
495 | + */ |
|
496 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
497 | + { |
|
498 | + if ( ! $DateTime instanceof DateTime) { |
|
499 | + if ($this->_nullable) { |
|
500 | + return ''; |
|
501 | + } else { |
|
502 | + if (WP_DEBUG) { |
|
503 | + throw new EE_Error( |
|
504 | + sprintf( |
|
505 | + __( |
|
506 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
507 | + 'event_espresso' |
|
508 | + ), |
|
509 | + $this->_nicename |
|
510 | + ) |
|
511 | + ); |
|
512 | + } else { |
|
513 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
514 | + EE_Error::add_error( |
|
515 | + sprintf( |
|
516 | + __( |
|
517 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
518 | + 'event_espresso' |
|
519 | + ), |
|
520 | + $this->_nicename |
|
521 | + ) |
|
522 | + ); |
|
523 | + } |
|
524 | + } |
|
525 | + } |
|
526 | + $format_string = $this->_get_date_time_output($schema); |
|
527 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
528 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
529 | + if ($schema) { |
|
530 | + if ($this->_display_timezone()) { |
|
531 | + //must be explicit because schema could equal true. |
|
532 | + if ($schema === 'no_html') { |
|
533 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
534 | + } else { |
|
535 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
536 | + } |
|
537 | + } else { |
|
538 | + $timezone_string = ''; |
|
539 | + } |
|
540 | + |
|
541 | + return $DateTime->format($format_string) . $timezone_string; |
|
542 | + } else { |
|
543 | + return $DateTime->format($format_string); |
|
544 | + } |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
550 | + * timezone). |
|
551 | + * |
|
552 | + * @param mixed $datetime_value u |
|
553 | + * |
|
554 | + * @return string mysql timestamp in UTC |
|
555 | + * @throws \EE_Error |
|
556 | + */ |
|
557 | + public function prepare_for_use_in_db($datetime_value) |
|
558 | + { |
|
559 | + //we allow an empty value or DateTime object, but nothing else. |
|
560 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
561 | + throw new EE_Error( |
|
562 | + __( |
|
563 | + 'The incoming value being prepared for setting in the database must either be empty or a php DateTime object', |
|
564 | + 'event_espresso' |
|
565 | + ) |
|
566 | + ); |
|
567 | + } |
|
568 | + |
|
569 | + if ($datetime_value instanceof DateTime) { |
|
570 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
571 | + $datetime_value = new DbSafeDateTime( |
|
572 | + $datetime_value->format(EE_Datetime_Field::mysql_timestamp_format), |
|
573 | + new \DateTimeZone($datetime_value->format('e')) |
|
574 | + ); |
|
575 | + } |
|
576 | + |
|
577 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
578 | + EE_Datetime_Field::mysql_timestamp_format |
|
579 | + ); |
|
580 | + } |
|
581 | + |
|
582 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
583 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
584 | + } |
|
585 | 585 | |
586 | 586 | |
587 | 587 | |
@@ -593,38 +593,38 @@ discard block |
||
593 | 593 | * @return mixed null | DateTime |
594 | 594 | * @throws \EE_Error |
595 | 595 | */ |
596 | - public function prepare_for_set_from_db($datetime_string) |
|
597 | - { |
|
598 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
599 | - if (empty($datetime_string) && $this->_nullable) { |
|
600 | - return null; |
|
601 | - } |
|
602 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
603 | - if (empty($datetime_string)) { |
|
604 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
605 | - } else { |
|
606 | - $DateTime = DateTime::createFromFormat( |
|
607 | - EE_Datetime_Field::mysql_timestamp_format, |
|
608 | - $datetime_string, |
|
609 | - $this->get_UTC_DateTimeZone() |
|
610 | - ); |
|
611 | - if ($DateTime instanceof \DateTime) { |
|
612 | - $DateTime = new DbSafeDateTime( |
|
613 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
614 | - $this->get_UTC_DateTimeZone() |
|
615 | - ); |
|
616 | - } |
|
617 | - } |
|
618 | - |
|
619 | - if ( ! $DateTime instanceof DbSafeDateTime) { |
|
620 | - // if still no datetime object, then let's just use now |
|
621 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
622 | - } |
|
623 | - // THEN apply the field's set DateTimeZone |
|
624 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
625 | - |
|
626 | - return $DateTime; |
|
627 | - } |
|
596 | + public function prepare_for_set_from_db($datetime_string) |
|
597 | + { |
|
598 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
599 | + if (empty($datetime_string) && $this->_nullable) { |
|
600 | + return null; |
|
601 | + } |
|
602 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
603 | + if (empty($datetime_string)) { |
|
604 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
605 | + } else { |
|
606 | + $DateTime = DateTime::createFromFormat( |
|
607 | + EE_Datetime_Field::mysql_timestamp_format, |
|
608 | + $datetime_string, |
|
609 | + $this->get_UTC_DateTimeZone() |
|
610 | + ); |
|
611 | + if ($DateTime instanceof \DateTime) { |
|
612 | + $DateTime = new DbSafeDateTime( |
|
613 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
614 | + $this->get_UTC_DateTimeZone() |
|
615 | + ); |
|
616 | + } |
|
617 | + } |
|
618 | + |
|
619 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
620 | + // if still no datetime object, then let's just use now |
|
621 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
622 | + } |
|
623 | + // THEN apply the field's set DateTimeZone |
|
624 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
625 | + |
|
626 | + return $DateTime; |
|
627 | + } |
|
628 | 628 | |
629 | 629 | |
630 | 630 | |
@@ -636,130 +636,130 @@ discard block |
||
636 | 636 | * @return bool true for yes false for no |
637 | 637 | * @throws \EE_Error |
638 | 638 | */ |
639 | - protected function _display_timezone() |
|
640 | - { |
|
641 | - |
|
642 | - // first let's do a comparison of timezone strings. |
|
643 | - // If they match then we can get out without any further calculations |
|
644 | - $blog_string = get_option('timezone_string'); |
|
645 | - if ($blog_string === $this->_timezone_string) { |
|
646 | - return false; |
|
647 | - } |
|
648 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
649 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
650 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
651 | - // now compare |
|
652 | - return $blog_offset !== $this_offset; |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
658 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
659 | - * with. |
|
660 | - * |
|
661 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
662 | - * in the format that is set on the date_field (or DateTime |
|
663 | - * object)! |
|
664 | - * |
|
665 | - * @return DateTime |
|
666 | - */ |
|
667 | - protected function _get_date_object($date_string) |
|
668 | - { |
|
669 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
670 | - if ($this->_nullable && empty($date_string)) { |
|
671 | - return null; |
|
672 | - } |
|
673 | - |
|
674 | - // if incoming date |
|
675 | - if ($date_string instanceof DateTime) { |
|
676 | - $date_string->setTimezone($this->_DateTimeZone); |
|
677 | - |
|
678 | - return $date_string; |
|
679 | - } |
|
680 | - // if empty date_string and made it here. |
|
681 | - // Return a datetime object for now in the given timezone. |
|
682 | - if (empty($date_string)) { |
|
683 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
684 | - } |
|
685 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
686 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
687 | - try { |
|
688 | - // This is operating under the assumption that the incoming Unix timestamp |
|
689 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
690 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
691 | - $DateTime->setTimestamp($date_string); |
|
692 | - |
|
693 | - return $DateTime; |
|
694 | - } catch (Exception $e) { |
|
695 | - // should be rare, but if things got fooled then let's just continue |
|
696 | - } |
|
697 | - } |
|
698 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
699 | - //create the DateTime object. |
|
700 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
701 | - try { |
|
702 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
703 | - if ($DateTime instanceof DateTime) { |
|
704 | - $DateTime = new DbSafeDateTime( |
|
705 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
706 | - $this->_DateTimeZone |
|
707 | - ); |
|
708 | - } |
|
709 | - if ( ! $DateTime instanceof DbSafeDateTime) { |
|
710 | - throw new EE_Error( |
|
711 | - sprintf( |
|
712 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
713 | - $date_string, |
|
714 | - $format |
|
715 | - ) |
|
716 | - ); |
|
717 | - } |
|
718 | - } catch (Exception $e) { |
|
719 | - // if we made it here then likely then something went really wrong. |
|
720 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
721 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
722 | - } |
|
723 | - |
|
724 | - return $DateTime; |
|
725 | - } |
|
726 | - |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * get_timezone_transitions |
|
731 | - * |
|
732 | - * @param \DateTimeZone $DateTimeZone |
|
733 | - * @param int $time |
|
734 | - * @param bool $first_only |
|
735 | - * @return mixed |
|
736 | - */ |
|
737 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
738 | - { |
|
739 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
740 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
741 | - $transitions = $DateTimeZone->getTransitions($time); |
|
742 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * get_timezone_offset |
|
749 | - * |
|
750 | - * @param \DateTimeZone $DateTimeZone |
|
751 | - * @param int $time |
|
752 | - * @return mixed |
|
753 | - * @throws \DomainException |
|
754 | - */ |
|
755 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
756 | - { |
|
757 | - $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
758 | - if ( ! isset($transitions['offset'])) { |
|
759 | - throw new DomainException(); |
|
760 | - } |
|
761 | - return $transitions['offset']; |
|
762 | - } |
|
639 | + protected function _display_timezone() |
|
640 | + { |
|
641 | + |
|
642 | + // first let's do a comparison of timezone strings. |
|
643 | + // If they match then we can get out without any further calculations |
|
644 | + $blog_string = get_option('timezone_string'); |
|
645 | + if ($blog_string === $this->_timezone_string) { |
|
646 | + return false; |
|
647 | + } |
|
648 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
649 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
650 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
651 | + // now compare |
|
652 | + return $blog_offset !== $this_offset; |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
658 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
659 | + * with. |
|
660 | + * |
|
661 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
662 | + * in the format that is set on the date_field (or DateTime |
|
663 | + * object)! |
|
664 | + * |
|
665 | + * @return DateTime |
|
666 | + */ |
|
667 | + protected function _get_date_object($date_string) |
|
668 | + { |
|
669 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
670 | + if ($this->_nullable && empty($date_string)) { |
|
671 | + return null; |
|
672 | + } |
|
673 | + |
|
674 | + // if incoming date |
|
675 | + if ($date_string instanceof DateTime) { |
|
676 | + $date_string->setTimezone($this->_DateTimeZone); |
|
677 | + |
|
678 | + return $date_string; |
|
679 | + } |
|
680 | + // if empty date_string and made it here. |
|
681 | + // Return a datetime object for now in the given timezone. |
|
682 | + if (empty($date_string)) { |
|
683 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
684 | + } |
|
685 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
686 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
687 | + try { |
|
688 | + // This is operating under the assumption that the incoming Unix timestamp |
|
689 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
690 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
691 | + $DateTime->setTimestamp($date_string); |
|
692 | + |
|
693 | + return $DateTime; |
|
694 | + } catch (Exception $e) { |
|
695 | + // should be rare, but if things got fooled then let's just continue |
|
696 | + } |
|
697 | + } |
|
698 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
699 | + //create the DateTime object. |
|
700 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
701 | + try { |
|
702 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
703 | + if ($DateTime instanceof DateTime) { |
|
704 | + $DateTime = new DbSafeDateTime( |
|
705 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
706 | + $this->_DateTimeZone |
|
707 | + ); |
|
708 | + } |
|
709 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
710 | + throw new EE_Error( |
|
711 | + sprintf( |
|
712 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
713 | + $date_string, |
|
714 | + $format |
|
715 | + ) |
|
716 | + ); |
|
717 | + } |
|
718 | + } catch (Exception $e) { |
|
719 | + // if we made it here then likely then something went really wrong. |
|
720 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
721 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
722 | + } |
|
723 | + |
|
724 | + return $DateTime; |
|
725 | + } |
|
726 | + |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * get_timezone_transitions |
|
731 | + * |
|
732 | + * @param \DateTimeZone $DateTimeZone |
|
733 | + * @param int $time |
|
734 | + * @param bool $first_only |
|
735 | + * @return mixed |
|
736 | + */ |
|
737 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
738 | + { |
|
739 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
740 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
741 | + $transitions = $DateTimeZone->getTransitions($time); |
|
742 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * get_timezone_offset |
|
749 | + * |
|
750 | + * @param \DateTimeZone $DateTimeZone |
|
751 | + * @param int $time |
|
752 | + * @return mixed |
|
753 | + * @throws \DomainException |
|
754 | + */ |
|
755 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
756 | + { |
|
757 | + $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
758 | + if ( ! isset($transitions['offset'])) { |
|
759 | + throw new DomainException(); |
|
760 | + } |
|
761 | + return $transitions['offset']; |
|
762 | + } |
|
763 | 763 | |
764 | 764 | |
765 | 765 | |
@@ -770,27 +770,27 @@ discard block |
||
770 | 770 | * @return string abbreviation |
771 | 771 | * @throws \EE_Error |
772 | 772 | */ |
773 | - public function get_timezone_abbrev($timezone_string) |
|
774 | - { |
|
775 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
776 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
777 | - |
|
778 | - return $dateTime->format('T'); |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Overrides the parent to allow for having a dynamic "now" value |
|
783 | - * |
|
784 | - * @return mixed |
|
785 | - */ |
|
786 | - public function get_default_value() |
|
787 | - { |
|
788 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
789 | - return time(); |
|
790 | - } else { |
|
791 | - return parent::get_default_value(); |
|
792 | - } |
|
793 | - } |
|
773 | + public function get_timezone_abbrev($timezone_string) |
|
774 | + { |
|
775 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
776 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
777 | + |
|
778 | + return $dateTime->format('T'); |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Overrides the parent to allow for having a dynamic "now" value |
|
783 | + * |
|
784 | + * @return mixed |
|
785 | + */ |
|
786 | + public function get_default_value() |
|
787 | + { |
|
788 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
789 | + return time(); |
|
790 | + } else { |
|
791 | + return parent::get_default_value(); |
|
792 | + } |
|
793 | + } |
|
794 | 794 | |
795 | 795 | |
796 | 796 | } |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | } |
118 | 118 | // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
119 | 119 | $timezone_string = $timezone_string !== false |
120 | - ? $timezone_string |
|
121 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
120 | + ? $timezone_string |
|
121 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
122 | 122 | return $timezone_string; |
123 | 123 | } |
124 | 124 | |
@@ -819,7 +819,6 @@ discard block |
||
819 | 819 | |
820 | 820 | |
821 | 821 | /** |
822 | - |
|
823 | 822 | * |
824 | 823 | * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
825 | 824 | * very next day then this method will return true. |
@@ -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 | /** |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @return string |
54 | 54 | * @throws \EE_Error |
55 | 55 | */ |
56 | - public static function get_valid_timezone_string( $timezone_string = '' ) { |
|
56 | + public static function get_valid_timezone_string($timezone_string = '') { |
|
57 | 57 | // if passed a value, then use that, else get WP option |
58 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : get_option( 'timezone_string' ); |
|
58 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
59 | 59 | // value from above exists, use that, else get timezone string from gmt_offset |
60 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
61 | - EEH_DTT_Helper::validate_timezone( $timezone_string ); |
|
60 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
61 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
62 | 62 | return $timezone_string; |
63 | 63 | } |
64 | 64 | |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | * @return bool |
75 | 75 | * @throws \EE_Error |
76 | 76 | */ |
77 | - public static function validate_timezone( $timezone_string, $throw_error = true ) { |
|
77 | + public static function validate_timezone($timezone_string, $throw_error = true) { |
|
78 | 78 | // 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 |
79 | 79 | try { |
80 | - new DateTimeZone( $timezone_string ); |
|
81 | - } catch ( Exception $e ) { |
|
80 | + new DateTimeZone($timezone_string); |
|
81 | + } catch (Exception $e) { |
|
82 | 82 | // sometimes we take exception to exceptions |
83 | - if ( ! $throw_error ) { |
|
83 | + if ( ! $throw_error) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | throw new EE_Error( |
87 | 87 | sprintf( |
88 | - __( 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso' ), |
|
88 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso'), |
|
89 | 89 | $timezone_string, |
90 | 90 | '<a href="http://www.php.net/manual/en/timezones.php">', |
91 | 91 | '</a>' |
@@ -104,21 +104,21 @@ discard block |
||
104 | 104 | * @param string $gmt_offset |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public static function get_timezone_string_from_gmt_offset( $gmt_offset = '' ) { |
|
107 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') { |
|
108 | 108 | $timezone_string = 'UTC'; |
109 | - $gmt_offset = ! empty( $gmt_offset ) ? $gmt_offset : get_option( 'gmt_offset' ); |
|
110 | - if ( $gmt_offset !== '' ) { |
|
109 | + $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
110 | + if ($gmt_offset !== '') { |
|
111 | 111 | // convert GMT offset to seconds |
112 | 112 | $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
113 | 113 | // account for WP offsets that aren't valid UTC |
114 | - $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets( $gmt_offset ); |
|
114 | + $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
115 | 115 | // although we don't know the TZ abbreviation, we know the UTC offset |
116 | - $timezone_string = timezone_name_from_abbr( null, $gmt_offset ); |
|
116 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
117 | 117 | } |
118 | 118 | // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
119 | 119 | $timezone_string = $timezone_string !== false |
120 | 120 | ? $timezone_string |
121 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list( $gmt_offset ); |
|
121 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
122 | 122 | return $timezone_string; |
123 | 123 | } |
124 | 124 | |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | * @return int seconds offset |
130 | 130 | */ |
131 | 131 | public static function get_site_timezone_gmt_offset() { |
132 | - $timezone_string = get_option( 'timezone_string' ); |
|
133 | - if ( $timezone_string ) { |
|
132 | + $timezone_string = get_option('timezone_string'); |
|
133 | + if ($timezone_string) { |
|
134 | 134 | try { |
135 | - $timezone = new DateTimeZone( $timezone_string ); |
|
136 | - return $timezone->getOffset( new DateTime() ); //in WordPress DateTime defaults to UTC |
|
137 | - } catch( Exception $e ){} |
|
135 | + $timezone = new DateTimeZone($timezone_string); |
|
136 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
137 | + } catch (Exception $e) {} |
|
138 | 138 | } |
139 | - $offset = get_option( 'gmt_offset' ); |
|
140 | - return (int) ( $offset * HOUR_IN_SECONDS ); |
|
139 | + $offset = get_option('gmt_offset'); |
|
140 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | * @param int $gmt_offset |
150 | 150 | * @return int |
151 | 151 | */ |
152 | - public static function adjust_invalid_gmt_offsets( $gmt_offset = 0 ) { |
|
152 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) { |
|
153 | 153 | //make sure $gmt_offset is int |
154 | 154 | $gmt_offset = (int) $gmt_offset; |
155 | - switch ( $gmt_offset ) { |
|
155 | + switch ($gmt_offset) { |
|
156 | 156 | |
157 | 157 | // case -30600 : |
158 | 158 | // $gmt_offset = -28800; |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | * @return string |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function get_timezone_string_from_abbreviations_list( $gmt_offset = 0 ) { |
|
207 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) { |
|
208 | 208 | $abbreviations = timezone_abbreviations_list(); |
209 | - foreach ( $abbreviations as $abbreviation ) { |
|
210 | - foreach ( $abbreviation as $city ) { |
|
211 | - if ( $city['offset'] === $gmt_offset && $city['dst'] === FALSE ) { |
|
209 | + foreach ($abbreviations as $abbreviation) { |
|
210 | + foreach ($abbreviation as $city) { |
|
211 | + if ($city['offset'] === $gmt_offset && $city['dst'] === FALSE) { |
|
212 | 212 | // check if the timezone is valid but don't throw any errors if it isn't |
213 | - if ( EEH_DTT_Helper::validate_timezone( $city['timezone_id'], false ) ) { |
|
213 | + if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
214 | 214 | return $city['timezone_id']; |
215 | 215 | } |
216 | 216 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | throw new EE_Error( |
220 | 220 | sprintf( |
221 | - __( 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso' ), |
|
221 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', 'event_espresso'), |
|
222 | 222 | $gmt_offset, |
223 | 223 | '<a href="http://www.php.net/manual/en/timezones.php">', |
224 | 224 | '</a>' |
@@ -232,23 +232,23 @@ discard block |
||
232 | 232 | * @access public |
233 | 233 | * @param string $timezone_string |
234 | 234 | */ |
235 | - public static function timezone_select_input( $timezone_string = '' ) { |
|
235 | + public static function timezone_select_input($timezone_string = '') { |
|
236 | 236 | // get WP date time format |
237 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
237 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
238 | 238 | // if passed a value, then use that, else get WP option |
239 | - $timezone_string = ! empty( $timezone_string ) ? $timezone_string : get_option( 'timezone_string' ); |
|
239 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
240 | 240 | // check if the timezone is valid but don't throw any errors if it isn't |
241 | - $timezone_string = EEH_DTT_Helper::validate_timezone( $timezone_string, false ); |
|
241 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
242 | 242 | $gmt_offset = get_option('gmt_offset'); |
243 | 243 | |
244 | 244 | $check_zone_info = true; |
245 | - if ( empty( $timezone_string )) { |
|
245 | + if (empty($timezone_string)) { |
|
246 | 246 | // Create a UTC+- zone if no timezone string exists |
247 | 247 | $check_zone_info = false; |
248 | - if ( $gmt_offset > 0 ) { |
|
249 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
250 | - } elseif ( $gmt_offset < 0 ) { |
|
251 | - $timezone_string = 'UTC' . $gmt_offset; |
|
248 | + if ($gmt_offset > 0) { |
|
249 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
250 | + } elseif ($gmt_offset < 0) { |
|
251 | + $timezone_string = 'UTC'.$gmt_offset; |
|
252 | 252 | } else { |
253 | 253 | $timezone_string = 'UTC'; |
254 | 254 | } |
@@ -270,11 +270,11 @@ discard block |
||
270 | 270 | __('%1$sUTC%2$s time is %3$s'), |
271 | 271 | '<abbr title="Coordinated Universal Time">', |
272 | 272 | '</abbr>', |
273 | - '<code>' . date_i18n( $datetime_format , false, true ) . '</code>' |
|
273 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
274 | 274 | ); |
275 | 275 | ?></span> |
276 | - <?php if ( ! empty( $timezone_string ) || ! empty( $gmt_offset )) : ?> |
|
277 | - <br /><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n( $datetime_format ) . '</code>' ); ?></span> |
|
276 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
277 | + <br /><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
278 | 278 | <?php endif; ?> |
279 | 279 | |
280 | 280 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -306,10 +306,9 @@ 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 | - printf( $message, '<code >' . date_i18n( $datetime_format, $tr['ts'] + ( $tz_offset - $tr['offset'] ) ). '</code >' ); |
|
311 | + printf($message, '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
313 | 312 | } else { |
314 | 313 | _e('This timezone does not observe daylight saving time.'); |
315 | 314 | } |
@@ -339,14 +338,14 @@ discard block |
||
339 | 338 | * |
340 | 339 | * @return int $unix_timestamp with the offset applied for the given timezone. |
341 | 340 | */ |
342 | - public static function get_timestamp_with_offset( $unix_timestamp = 0, $timezone_string = '' ) { |
|
341 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') { |
|
343 | 342 | $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
344 | - $timezone_string = self::get_valid_timezone_string( $timezone_string ); |
|
345 | - $TimeZone = new DateTimeZone( $timezone_string ); |
|
343 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
344 | + $TimeZone = new DateTimeZone($timezone_string); |
|
346 | 345 | |
347 | - $DateTime = new DateTime( '@' . $unix_timestamp, $TimeZone ); |
|
348 | - $offset = timezone_offset_get( $TimeZone, $DateTime ); |
|
349 | - return (int)$DateTime->format( 'U' ) + (int)$offset; |
|
346 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
347 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
348 | + return (int) $DateTime->format('U') + (int) $offset; |
|
350 | 349 | } |
351 | 350 | |
352 | 351 | |
@@ -361,17 +360,17 @@ discard block |
||
361 | 360 | * @param string $datetime_field_name the datetime fieldname to be manipulated |
362 | 361 | * @return EE_Base_Class |
363 | 362 | */ |
364 | - protected static function _set_date_time_field( EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name ) { |
|
363 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) { |
|
365 | 364 | // grab current datetime format |
366 | 365 | $current_format = $obj->get_format(); |
367 | 366 | // set new full timestamp format |
368 | - $obj->set_date_format( EE_Datetime_Field::mysql_date_format ); |
|
369 | - $obj->set_time_format( EE_Datetime_Field::mysql_time_format ); |
|
367 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
368 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
370 | 369 | // set the new date value using a full timestamp format so that no data is lost |
371 | - $obj->set( $datetime_field_name, $DateTime->format( EE_Datetime_Field::mysql_timestamp_format ) ); |
|
370 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
372 | 371 | // reset datetime formats |
373 | - $obj->set_date_format( $current_format[0] ); |
|
374 | - $obj->set_time_format( $current_format[1] ); |
|
372 | + $obj->set_date_format($current_format[0]); |
|
373 | + $obj->set_time_format($current_format[1]); |
|
375 | 374 | return $obj; |
376 | 375 | } |
377 | 376 | |
@@ -388,11 +387,11 @@ discard block |
||
388 | 387 | * @param integer $value what you want to increment the time by |
389 | 388 | * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it (chaining) |
390 | 389 | */ |
391 | - public static function date_time_add( EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1 ) { |
|
390 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) { |
|
392 | 391 | //get the raw UTC date. |
393 | - $DateTime = $obj->get_DateTime_object( $datetime_field_name ); |
|
394 | - $DateTime = EEH_DTT_Helper::calc_date( $DateTime, $period, $value ); |
|
395 | - return EEH_DTT_Helper::_set_date_time_field( $obj, $DateTime, $datetime_field_name ); |
|
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); |
|
396 | 395 | } |
397 | 396 | |
398 | 397 | |
@@ -407,11 +406,11 @@ discard block |
||
407 | 406 | * @param int $value |
408 | 407 | * @return \EE_Base_Class |
409 | 408 | */ |
410 | - public static function date_time_subtract( EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1 ) { |
|
409 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) { |
|
411 | 410 | //get the raw UTC date |
412 | - $DateTime = $obj->get_DateTime_object( $datetime_field_name ); |
|
413 | - $DateTime = EEH_DTT_Helper::calc_date( $DateTime, $period, $value, '-' ); |
|
414 | - return EEH_DTT_Helper::_set_date_time_field( $obj, $DateTime, $datetime_field_name ); |
|
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); |
|
415 | 414 | } |
416 | 415 | |
417 | 416 | |
@@ -424,44 +423,44 @@ discard block |
||
424 | 423 | * @return \DateTime return whatever type came in. |
425 | 424 | * @throws \EE_Error |
426 | 425 | */ |
427 | - protected static function _modify_datetime_object( DateTime $DateTime, $period = 'years', $value = 1, $operand = '+' ) { |
|
428 | - if ( ! $DateTime instanceof DateTime ) { |
|
426 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') { |
|
427 | + if ( ! $DateTime instanceof DateTime) { |
|
429 | 428 | throw new EE_Error( |
430 | 429 | sprintf( |
431 | - __( 'Expected a PHP DateTime object, but instead received %1$s', 'event_espresso' ), |
|
432 | - print_r( $DateTime, true ) |
|
430 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
431 | + print_r($DateTime, true) |
|
433 | 432 | ) |
434 | 433 | ); |
435 | 434 | } |
436 | - switch ( $period ) { |
|
435 | + switch ($period) { |
|
437 | 436 | case 'years' : |
438 | - $value = 'P' . $value . 'Y'; |
|
437 | + $value = 'P'.$value.'Y'; |
|
439 | 438 | break; |
440 | 439 | case 'months' : |
441 | - $value = 'P' . $value . 'M'; |
|
440 | + $value = 'P'.$value.'M'; |
|
442 | 441 | break; |
443 | 442 | case 'weeks' : |
444 | - $value = 'P' . $value . 'W'; |
|
443 | + $value = 'P'.$value.'W'; |
|
445 | 444 | break; |
446 | 445 | case 'days' : |
447 | - $value = 'P' . $value . 'D'; |
|
446 | + $value = 'P'.$value.'D'; |
|
448 | 447 | break; |
449 | 448 | case 'hours' : |
450 | - $value = 'PT' . $value . 'H'; |
|
449 | + $value = 'PT'.$value.'H'; |
|
451 | 450 | break; |
452 | 451 | case 'minutes' : |
453 | - $value = 'PT' . $value . 'M'; |
|
452 | + $value = 'PT'.$value.'M'; |
|
454 | 453 | break; |
455 | 454 | case 'seconds' : |
456 | - $value = 'PT' . $value . 'S'; |
|
455 | + $value = 'PT'.$value.'S'; |
|
457 | 456 | break; |
458 | 457 | } |
459 | - switch ( $operand ) { |
|
458 | + switch ($operand) { |
|
460 | 459 | case '+': |
461 | - $DateTime->add( new DateInterval( $value ) ); |
|
460 | + $DateTime->add(new DateInterval($value)); |
|
462 | 461 | break; |
463 | 462 | case '-': |
464 | - $DateTime->sub( new DateInterval( $value ) ); |
|
463 | + $DateTime->sub(new DateInterval($value)); |
|
465 | 464 | break; |
466 | 465 | } |
467 | 466 | return $DateTime; |
@@ -477,16 +476,16 @@ discard block |
||
477 | 476 | * @return \DateTime return whatever type came in. |
478 | 477 | * @throws \EE_Error |
479 | 478 | */ |
480 | - protected static function _modify_timestamp( $timestamp, $period = 'years', $value = 1, $operand = '+' ) { |
|
481 | - if ( ! preg_match( EE_Datetime_Field::unix_timestamp_regex, $timestamp ) ) { |
|
479 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') { |
|
480 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
482 | 481 | throw new EE_Error( |
483 | 482 | sprintf( |
484 | - __( 'Expected a Unix timestamp, but instead received %1$s', 'event_espresso' ), |
|
485 | - print_r( $timestamp, true ) |
|
483 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
484 | + print_r($timestamp, true) |
|
486 | 485 | ) |
487 | 486 | ); |
488 | 487 | } |
489 | - switch ( $period ) { |
|
488 | + switch ($period) { |
|
490 | 489 | case 'years' : |
491 | 490 | $value = YEAR_IN_SECONDS * $value; |
492 | 491 | break; |
@@ -506,9 +505,9 @@ discard block |
||
506 | 505 | $value = MINUTE_IN_SECONDS * $value; |
507 | 506 | break; |
508 | 507 | } |
509 | - switch ( $operand ) { |
|
508 | + switch ($operand) { |
|
510 | 509 | case '+': |
511 | - $timestamp += $value; |
|
510 | + $timestamp += $value; |
|
512 | 511 | break; |
513 | 512 | case '-': |
514 | 513 | $timestamp -= $value; |
@@ -528,11 +527,11 @@ discard block |
||
528 | 527 | * @param string $operand What operand you wish to use for the calculation |
529 | 528 | * @return mixed string|DateTime return whatever type came in. |
530 | 529 | */ |
531 | - public static function calc_date( $DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+' ) { |
|
532 | - if ( $DateTime_or_timestamp instanceof DateTime ) { |
|
533 | - return EEH_DTT_Helper::_modify_datetime_object( $DateTime_or_timestamp, $period, $value, $operand ); |
|
534 | - } else if ( preg_match( EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp )) { |
|
535 | - return EEH_DTT_Helper::_modify_timestamp( $DateTime_or_timestamp, $period, $value, $operand ); |
|
530 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') { |
|
531 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
532 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
533 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
534 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
536 | 535 | } else { |
537 | 536 | //error |
538 | 537 | return $DateTime_or_timestamp; |
@@ -562,24 +561,24 @@ discard block |
||
562 | 561 | * 'moment' => //date and time format. |
563 | 562 | * ) |
564 | 563 | */ |
565 | - public static function convert_php_to_js_and_moment_date_formats( $date_format_string = null, $time_format_string = null ) { |
|
566 | - if ( $date_format_string === null ) { |
|
567 | - $date_format_string = get_option( 'date_format' ); |
|
564 | + public static function convert_php_to_js_and_moment_date_formats($date_format_string = null, $time_format_string = null) { |
|
565 | + if ($date_format_string === null) { |
|
566 | + $date_format_string = get_option('date_format'); |
|
568 | 567 | } |
569 | 568 | |
570 | - if ( $time_format_string === null ) { |
|
571 | - $time_format_string = get_option( 'time_format' ); |
|
569 | + if ($time_format_string === null) { |
|
570 | + $time_format_string = get_option('time_format'); |
|
572 | 571 | } |
573 | 572 | |
574 | - $date_format = self::_php_to_js_moment_converter( $date_format_string ); |
|
575 | - $time_format = self::_php_to_js_moment_converter( $time_format_string ); |
|
573 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
574 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
576 | 575 | |
577 | 576 | return array( |
578 | 577 | 'js' => array( |
579 | 578 | 'date' => $date_format['js'], |
580 | 579 | 'time' => $time_format['js'] |
581 | 580 | ), |
582 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment' ] |
|
581 | + 'moment' => $date_format['moment'].' '.$time_format['moment'] |
|
583 | 582 | ); |
584 | 583 | } |
585 | 584 | |
@@ -593,7 +592,7 @@ discard block |
||
593 | 592 | * |
594 | 593 | * @return array js and moment formats. |
595 | 594 | */ |
596 | - protected static function _php_to_js_moment_converter( $format_string ) { |
|
595 | + protected static function _php_to_js_moment_converter($format_string) { |
|
597 | 596 | /** |
598 | 597 | * This is a map of symbols for formats. |
599 | 598 | * The index is the php symbol, the equivalent values are in the array. |
@@ -750,15 +749,15 @@ discard block |
||
750 | 749 | $jquery_ui_format = ""; |
751 | 750 | $moment_format = ""; |
752 | 751 | $escaping = false; |
753 | - for ( $i = 0; $i < strlen($format_string); $i++ ) { |
|
752 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
754 | 753 | $char = $format_string[$i]; |
755 | - if ( $char === '\\' ) { // PHP date format escaping character |
|
754 | + if ($char === '\\') { // PHP date format escaping character |
|
756 | 755 | $i++; |
757 | - if ( $escaping ) { |
|
756 | + if ($escaping) { |
|
758 | 757 | $jquery_ui_format .= $format_string[$i]; |
759 | 758 | $moment_format .= $format_string[$i]; |
760 | 759 | } else { |
761 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
760 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
762 | 761 | $moment_format .= $format_string[$i]; |
763 | 762 | } |
764 | 763 | $escaping = true; |
@@ -777,7 +776,7 @@ discard block |
||
777 | 776 | } |
778 | 777 | } |
779 | 778 | } |
780 | - return array( 'js' => $jquery_ui_format, 'moment' => $moment_format ); |
|
779 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
781 | 780 | } |
782 | 781 | |
783 | 782 | |
@@ -792,25 +791,25 @@ discard block |
||
792 | 791 | * errors is returned. So for client code calling, check for is_array() to |
793 | 792 | * indicate failed validations. |
794 | 793 | */ |
795 | - public static function validate_format_string( $format_string ) { |
|
794 | + public static function validate_format_string($format_string) { |
|
796 | 795 | $error_msg = array(); |
797 | 796 | //time format checks |
798 | - switch ( true ) { |
|
799 | - case strpos( $format_string, 'h' ) !== false : |
|
800 | - case strpos( $format_string, 'g' ) !== false : |
|
797 | + switch (true) { |
|
798 | + case strpos($format_string, 'h') !== false : |
|
799 | + case strpos($format_string, 'g') !== false : |
|
801 | 800 | /** |
802 | 801 | * if the time string has a lowercase 'h' which == 12 hour time format and there |
803 | 802 | * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
804 | 803 | * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
805 | 804 | */ |
806 | - if ( strpos( strtoupper( $format_string ), 'A' ) === false ) { |
|
807 | - $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".', 'event_espresso' ); |
|
805 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
806 | + $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".', 'event_espresso'); |
|
808 | 807 | } |
809 | 808 | break; |
810 | 809 | |
811 | 810 | } |
812 | 811 | |
813 | - return empty( $error_msg ) ? true : $error_msg; |
|
812 | + return empty($error_msg) ? true : $error_msg; |
|
814 | 813 | } |
815 | 814 | |
816 | 815 | |
@@ -832,11 +831,11 @@ discard block |
||
832 | 831 | * @param mixed $date_2 |
833 | 832 | * @return bool |
834 | 833 | */ |
835 | - public static function dates_represent_one_24_hour_date( $date_1, $date_2 ) { |
|
834 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) { |
|
836 | 835 | |
837 | 836 | if ( |
838 | - ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime ) || |
|
839 | - ( $date_1->format( EE_Datetime_Field::mysql_time_format ) != '00:00:00' || $date_2->format( EE_Datetime_Field::mysql_time_format ) != '00:00:00' ) |
|
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') |
|
840 | 839 | ) { |
841 | 840 | return false; |
842 | 841 | } |
@@ -853,11 +852,11 @@ discard block |
||
853 | 852 | * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
854 | 853 | * @return string |
855 | 854 | */ |
856 | - public static function get_sql_query_interval_for_offset( $timezone_string, $field_for_interval ) { |
|
855 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) { |
|
857 | 856 | try { |
858 | 857 | /** need to account for timezone offset on the selects */ |
859 | - $DateTimeZone = new DateTimeZone( $timezone_string ); |
|
860 | - } catch ( Exception $e ) { |
|
858 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
859 | + } catch (Exception $e) { |
|
861 | 860 | $DateTimeZone = null; |
862 | 861 | } |
863 | 862 | |
@@ -865,10 +864,10 @@ discard block |
||
865 | 864 | * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
866 | 865 | * Hence we do the calc for DateTimeZone::getOffset. |
867 | 866 | */ |
868 | - $offset = $DateTimeZone instanceof DateTimeZone ? ( $DateTimeZone->getOffset( new DateTime('now') ) ) / HOUR_IN_SECONDS : get_option( 'gmt_offset' ); |
|
867 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
869 | 868 | $query_interval = $offset < 0 |
870 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset*-1 . ' HOUR)' |
|
871 | - : 'DATE_ADD(' . $field_for_interval .', INTERVAL ' . $offset . ' HOUR)'; |
|
869 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
870 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
872 | 871 | return $query_interval; |
873 | 872 | } |
874 | 873 | |
@@ -880,47 +879,47 @@ discard block |
||
880 | 879 | * @return string |
881 | 880 | */ |
882 | 881 | public static function get_timezone_string_for_display() { |
883 | - $pretty_timezone = apply_filters( 'FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '' ); |
|
884 | - if( ! empty( $pretty_timezone ) ) { |
|
885 | - return esc_html( $pretty_timezone ); |
|
882 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
883 | + if ( ! empty($pretty_timezone)) { |
|
884 | + return esc_html($pretty_timezone); |
|
886 | 885 | } |
887 | - $timezone_string = get_option( 'timezone_string' ); |
|
888 | - if( $timezone_string ) { |
|
886 | + $timezone_string = get_option('timezone_string'); |
|
887 | + if ($timezone_string) { |
|
889 | 888 | static $mo_loaded = false; |
890 | 889 | // Load translations for continents and cities just like wp_timezone_choice does |
891 | - if ( ! $mo_loaded ) { |
|
890 | + if ( ! $mo_loaded) { |
|
892 | 891 | $locale = get_locale(); |
893 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
894 | - load_textdomain( 'continents-cities', $mofile ); |
|
892 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
893 | + load_textdomain('continents-cities', $mofile); |
|
895 | 894 | $mo_loaded = true; |
896 | 895 | } |
897 | 896 | //well that was easy. |
898 | - $parts = explode('/', $timezone_string ); |
|
897 | + $parts = explode('/', $timezone_string); |
|
899 | 898 | //remove the continent |
900 | - unset( $parts[0] ); |
|
899 | + unset($parts[0]); |
|
901 | 900 | $t_parts = array(); |
902 | - foreach( $parts as $part ) { |
|
903 | - $t_parts[] = translate( str_replace( '_', ' ', $part ), 'continents-cities' ); |
|
901 | + foreach ($parts as $part) { |
|
902 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
904 | 903 | } |
905 | - return implode( ' - ', $t_parts ); |
|
904 | + return implode(' - ', $t_parts); |
|
906 | 905 | } |
907 | 906 | //they haven't set the timezone string, so let's return a string like "UTC+1" |
908 | - $gmt_offset = get_option( 'gmt_offset' ); |
|
909 | - if( intval( $gmt_offset ) >= 0 ) { |
|
907 | + $gmt_offset = get_option('gmt_offset'); |
|
908 | + if (intval($gmt_offset) >= 0) { |
|
910 | 909 | $prefix = '+'; |
911 | 910 | } else { |
912 | 911 | $prefix = ''; |
913 | 912 | } |
914 | - $parts = explode( '.', (string) $gmt_offset ); |
|
915 | - if( count( $parts ) === 1 ) { |
|
913 | + $parts = explode('.', (string) $gmt_offset); |
|
914 | + if (count($parts) === 1) { |
|
916 | 915 | $parts[1] = '00'; |
917 | 916 | } else { |
918 | 917 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
919 | 918 | //to minutes, eg 30 or 15, respectively |
920 | - $hour_fraction = (float)( '0.' . $parts[1] ); |
|
921 | - $parts[1] = (string)$hour_fraction * 60; |
|
919 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
920 | + $parts[1] = (string) $hour_fraction * 60; |
|
922 | 921 | } |
923 | - return sprintf( __( 'UTC%1$s', 'event_espresso' ), $prefix . implode( ':', $parts ) ); |
|
922 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
924 | 923 | } |
925 | 924 | |
926 | 925 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -26,485 +26,485 @@ discard block |
||
26 | 26 | class Model_Data_Translator |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
31 | - * fields that COULD contain -1; so we use null |
|
32 | - */ |
|
33 | - const ee_inf_in_rest = null; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Prepares a possible array of input values from JSON for use by the models |
|
39 | - * |
|
40 | - * @param \EE_Model_Field_Base $field_obj |
|
41 | - * @param mixed $original_value_maybe_array |
|
42 | - * @param string $requested_version |
|
43 | - * @param string $timezone_string treat values as being in this timezone |
|
44 | - * @return mixed |
|
45 | - * @throws \DomainException |
|
46 | - */ |
|
47 | - public static function prepare_field_values_from_json( |
|
48 | - $field_obj, |
|
49 | - $original_value_maybe_array, |
|
50 | - $requested_version, |
|
51 | - $timezone_string = 'UTC' |
|
52 | - ) { |
|
53 | - if (is_array($original_value_maybe_array)) { |
|
54 | - $new_value_maybe_array = array(); |
|
55 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
56 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
57 | - $field_obj, |
|
58 | - $array_item, |
|
59 | - $requested_version, |
|
60 | - $timezone_string |
|
61 | - ); |
|
62 | - } |
|
63 | - } else { |
|
64 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
65 | - $field_obj, |
|
66 | - $original_value_maybe_array, |
|
67 | - $requested_version, |
|
68 | - $timezone_string |
|
69 | - ); |
|
70 | - } |
|
71 | - return $new_value_maybe_array; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Prepares an array of field values FOR use in JSON/REST API |
|
78 | - * |
|
79 | - * @param \EE_Model_Field_Base $field_obj |
|
80 | - * @param mixed $original_value_maybe_array |
|
81 | - * @param string $request_version (eg 4.8.36) |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
85 | - { |
|
86 | - if (is_array($original_value_maybe_array)) { |
|
87 | - $new_value_maybe_array = array(); |
|
88 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
89 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
90 | - $field_obj, |
|
91 | - $array_item, |
|
92 | - $request_version |
|
93 | - ); |
|
94 | - } |
|
95 | - } else { |
|
96 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
97 | - $field_obj, |
|
98 | - $original_value_maybe_array, |
|
99 | - $request_version |
|
100 | - ); |
|
101 | - } |
|
102 | - return $new_value_maybe_array; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
109 | - * "$query_params". |
|
110 | - * |
|
111 | - * @param \EE_Model_Field_Base $field_obj |
|
112 | - * @param mixed $original_value |
|
113 | - * @param string $requested_version |
|
114 | - * @param string $timezone_string treat values as being in this timezone |
|
115 | - * @return mixed |
|
116 | - * @throws \DomainException |
|
117 | - */ |
|
118 | - public static function prepare_field_value_from_json( |
|
119 | - $field_obj, |
|
120 | - $original_value, |
|
121 | - $requested_version, |
|
122 | - $timezone_string = 'UTC' // UTC |
|
123 | - ) |
|
124 | - { |
|
125 | - $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
126 | - $new_value = null; |
|
127 | - if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
128 | - && in_array($original_value, array(null, ''), true) |
|
129 | - ) { |
|
130 | - $new_value = EE_INF; |
|
131 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
132 | - list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
133 | - $field_obj->get_timezone_offset( |
|
134 | - new \DateTimeZone($timezone_string) |
|
135 | - ) |
|
136 | - ); |
|
137 | - $offset_string = |
|
138 | - str_pad( |
|
139 | - floor($offset_secs / HOUR_IN_SECONDS), |
|
140 | - 2, |
|
141 | - '0', |
|
142 | - STR_PAD_LEFT |
|
143 | - ) |
|
144 | - . ':' |
|
145 | - . str_pad( |
|
146 | - ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
147 | - 2, |
|
148 | - '0', |
|
149 | - STR_PAD_LEFT |
|
150 | - ); |
|
151 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
152 | - } else { |
|
153 | - $new_value = $original_value; |
|
154 | - } |
|
155 | - return $new_value; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * determines what's going on with them timezone strings |
|
162 | - * |
|
163 | - * @param int $timezone_offset |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - private static function parse_timezone_offset($timezone_offset) |
|
167 | - { |
|
168 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
169 | - if ($first_char === '+' || $first_char === '-') { |
|
170 | - $offset_sign = $first_char; |
|
171 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
172 | - } else { |
|
173 | - $offset_sign = '+'; |
|
174 | - $offset_secs = $timezone_offset; |
|
175 | - } |
|
176 | - return array($offset_sign, $offset_secs); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Prepares a field's value for display in the API |
|
183 | - * |
|
184 | - * @param \EE_Model_Field_Base $field_obj |
|
185 | - * @param mixed $original_value |
|
186 | - * @param string $requested_version |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
190 | - { |
|
191 | - if ($original_value === EE_INF) { |
|
192 | - $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
193 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
194 | - if ($original_value instanceof \DateTime) { |
|
195 | - $new_value = $original_value->format('Y-m-d H:i:s'); |
|
196 | - } elseif (is_int($original_value)) { |
|
197 | - $new_value = date('Y-m-d H:i:s', $original_value); |
|
198 | - } else { |
|
199 | - $new_value = $original_value; |
|
200 | - } |
|
201 | - $new_value = mysql_to_rfc3339($new_value); |
|
202 | - } else { |
|
203 | - $new_value = $original_value; |
|
204 | - } |
|
205 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
206 | - $new_value, |
|
207 | - $field_obj, |
|
208 | - $original_value, |
|
209 | - $requested_version |
|
210 | - ); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Prepares condition-query-parameters (like what's in where and having) from |
|
217 | - * the format expected in the API to use in the models |
|
218 | - * |
|
219 | - * @param array $inputted_query_params_of_this_type |
|
220 | - * @param \EEM_Base $model |
|
221 | - * @param string $requested_version |
|
222 | - * @return array |
|
223 | - * @throws \DomainException |
|
224 | - * @throws \EE_Error |
|
225 | - */ |
|
226 | - public static function prepare_conditions_query_params_for_models( |
|
227 | - $inputted_query_params_of_this_type, |
|
228 | - \EEM_Base $model, |
|
229 | - $requested_version |
|
230 | - ) { |
|
231 | - $query_param_for_models = array(); |
|
232 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
233 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
234 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
235 | - $query_param_sans_stars, |
|
236 | - $model |
|
237 | - ); |
|
238 | - //double-check is it a *_gmt field? |
|
239 | - if ( ! $field instanceof \EE_Model_Field_Base |
|
240 | - && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
241 | - ) { |
|
242 | - //yep, take off '_gmt', and find the field |
|
243 | - $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
244 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
245 | - $query_param_key, |
|
246 | - $model |
|
247 | - ); |
|
248 | - $timezone = 'UTC'; |
|
249 | - } else { |
|
250 | - //so it's not a GMT field. Set the timezone on the model to the default |
|
251 | - $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
252 | - } |
|
253 | - if ($field instanceof \EE_Model_Field_Base) { |
|
254 | - //did they specify an operator? |
|
255 | - if (is_array($query_param_value)) { |
|
256 | - $op = $query_param_value[0]; |
|
257 | - $translated_value = array($op); |
|
258 | - if (isset($query_param_value[1])) { |
|
259 | - $value = $query_param_value[1]; |
|
260 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
261 | - $requested_version, $timezone); |
|
262 | - } |
|
263 | - } else { |
|
264 | - $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
265 | - $requested_version, $timezone); |
|
266 | - } |
|
267 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
268 | - } else { |
|
269 | - //so it's not for a field, assume it's a logic query param key |
|
270 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
271 | - $model, $requested_version); |
|
272 | - } |
|
273 | - } |
|
274 | - return $query_param_for_models; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
281 | - * gmt date field name |
|
282 | - * |
|
283 | - * @param string $field_name |
|
284 | - * @return boolean |
|
285 | - */ |
|
286 | - public static function is_gmt_date_field_name($field_name) |
|
287 | - { |
|
288 | - return substr( |
|
289 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
290 | - -4, |
|
291 | - 4 |
|
292 | - ) === '_gmt'; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
299 | - * |
|
300 | - * @param string $field_name |
|
301 | - * @return string |
|
302 | - */ |
|
303 | - public static function remove_gmt_from_field_name($field_name) |
|
304 | - { |
|
305 | - if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
306 | - return $field_name; |
|
307 | - } |
|
308 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
309 | - $query_param_sans_gmt_and_sans_stars = substr( |
|
310 | - $query_param_sans_stars, |
|
311 | - 0, |
|
312 | - strrpos( |
|
313 | - $field_name, |
|
314 | - '_gmt' |
|
315 | - ) |
|
316 | - ); |
|
317 | - return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Takes a field name from the REST API and prepares it for the model querying |
|
324 | - * |
|
325 | - * @param string $field_name |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public static function prepare_field_name_from_json($field_name) |
|
329 | - { |
|
330 | - if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
331 | - return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
332 | - } |
|
333 | - return $field_name; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Takes array of field names from REST API and prepares for models |
|
340 | - * |
|
341 | - * @param array $field_names |
|
342 | - * @return array of field names (possibly include model prefixes) |
|
343 | - */ |
|
344 | - public static function prepare_field_names_from_json(array $field_names) |
|
345 | - { |
|
346 | - $new_array = array(); |
|
347 | - foreach ($field_names as $key => $field_name) { |
|
348 | - $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
349 | - } |
|
350 | - return $new_array; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Takes array where array keys are field names (possibly with model path prefixes) |
|
357 | - * from the REST API and prepares them for model querying |
|
358 | - * |
|
359 | - * @param array $field_names_as_keys |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
363 | - { |
|
364 | - $new_array = array(); |
|
365 | - foreach ($field_names_as_keys as $field_name => $value) { |
|
366 | - $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
367 | - } |
|
368 | - return $new_array; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Prepares an array of model query params for use in the REST API |
|
375 | - * |
|
376 | - * @param array $model_query_params |
|
377 | - * @param \EEM_Base $model |
|
378 | - * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
379 | - * REST API |
|
380 | - * @return array which can be passed into the EE4 REST API when querying a model resource |
|
381 | - * @throws \EE_Error |
|
382 | - */ |
|
383 | - public static function prepare_query_params_for_rest_api( |
|
384 | - array $model_query_params, |
|
385 | - \EEM_Base $model, |
|
386 | - $requested_version = null |
|
387 | - ) { |
|
388 | - if ($requested_version === null) { |
|
389 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
390 | - } |
|
391 | - $rest_query_params = $model_query_params; |
|
392 | - if (isset($model_query_params[0])) { |
|
393 | - $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
394 | - $model_query_params[0], |
|
395 | - $model, |
|
396 | - $requested_version |
|
397 | - ); |
|
398 | - unset($rest_query_params[0]); |
|
399 | - } |
|
400 | - if (isset($model_query_params['having'])) { |
|
401 | - $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
402 | - $model_query_params['having'], |
|
403 | - $model, |
|
404 | - $requested_version |
|
405 | - ); |
|
406 | - } |
|
407 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
408 | - $rest_query_params, $model_query_params, $model, $requested_version); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
415 | - * |
|
416 | - * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
417 | - * passed into EEM_Base::get_all() |
|
418 | - * @param \EEM_Base $model |
|
419 | - * @param string $requested_version eg "4.8.36" |
|
420 | - * @return array ready for use in the rest api query params |
|
421 | - * @throws \EE_Error |
|
422 | - */ |
|
423 | - public static function prepare_conditions_query_params_for_rest_api( |
|
424 | - $inputted_query_params_of_this_type, |
|
425 | - \EEM_Base $model, |
|
426 | - $requested_version |
|
427 | - ) { |
|
428 | - $query_param_for_models = array(); |
|
429 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
430 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
431 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
432 | - $model |
|
433 | - ); |
|
434 | - if ($field instanceof \EE_Model_Field_Base) { |
|
435 | - //did they specify an operator? |
|
436 | - if (is_array($query_param_value)) { |
|
437 | - $op = $query_param_value[0]; |
|
438 | - $translated_value = array($op); |
|
439 | - if (isset($query_param_value[1])) { |
|
440 | - $value = $query_param_value[1]; |
|
441 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
442 | - $requested_version); |
|
443 | - } |
|
444 | - } else { |
|
445 | - $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
446 | - $requested_version); |
|
447 | - } |
|
448 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
449 | - } else { |
|
450 | - //so it's not for a field, assume it's a logic query param key |
|
451 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
452 | - $model, $requested_version); |
|
453 | - } |
|
454 | - } |
|
455 | - return $query_param_for_models; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * @param $condition_query_param_key |
|
462 | - * @return string |
|
463 | - */ |
|
464 | - public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
465 | - { |
|
466 | - $pos_of_star = strpos($condition_query_param_key, '*'); |
|
467 | - if ($pos_of_star === false) { |
|
468 | - return $condition_query_param_key; |
|
469 | - } else { |
|
470 | - $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
471 | - return $condition_query_param_sans_star; |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * Takes the input parameter and finds the model field that it indicates. |
|
479 | - * |
|
480 | - * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
481 | - * @param \EEM_Base $model |
|
482 | - * @return \EE_Model_Field_Base |
|
483 | - * @throws \EE_Error |
|
484 | - */ |
|
485 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
486 | - { |
|
487 | - //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
488 | - //which will help us find the database table and column |
|
489 | - $query_param_parts = explode('.', $query_param_name); |
|
490 | - if (empty($query_param_parts)) { |
|
491 | - throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
492 | - 'event_espresso'), $query_param_name)); |
|
493 | - } |
|
494 | - $number_of_parts = count($query_param_parts); |
|
495 | - $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
496 | - if ($number_of_parts === 1) { |
|
497 | - $field_name = $last_query_param_part; |
|
498 | - } else {// $number_of_parts >= 2 |
|
499 | - //the last part is the column name, and there are only 2parts. therefore... |
|
500 | - $field_name = $last_query_param_part; |
|
501 | - $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
502 | - } |
|
503 | - try { |
|
504 | - return $model->field_settings_for($field_name); |
|
505 | - } catch (\EE_Error $e) { |
|
506 | - return null; |
|
507 | - } |
|
508 | - } |
|
29 | + /** |
|
30 | + * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
31 | + * fields that COULD contain -1; so we use null |
|
32 | + */ |
|
33 | + const ee_inf_in_rest = null; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Prepares a possible array of input values from JSON for use by the models |
|
39 | + * |
|
40 | + * @param \EE_Model_Field_Base $field_obj |
|
41 | + * @param mixed $original_value_maybe_array |
|
42 | + * @param string $requested_version |
|
43 | + * @param string $timezone_string treat values as being in this timezone |
|
44 | + * @return mixed |
|
45 | + * @throws \DomainException |
|
46 | + */ |
|
47 | + public static function prepare_field_values_from_json( |
|
48 | + $field_obj, |
|
49 | + $original_value_maybe_array, |
|
50 | + $requested_version, |
|
51 | + $timezone_string = 'UTC' |
|
52 | + ) { |
|
53 | + if (is_array($original_value_maybe_array)) { |
|
54 | + $new_value_maybe_array = array(); |
|
55 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
56 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
57 | + $field_obj, |
|
58 | + $array_item, |
|
59 | + $requested_version, |
|
60 | + $timezone_string |
|
61 | + ); |
|
62 | + } |
|
63 | + } else { |
|
64 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
65 | + $field_obj, |
|
66 | + $original_value_maybe_array, |
|
67 | + $requested_version, |
|
68 | + $timezone_string |
|
69 | + ); |
|
70 | + } |
|
71 | + return $new_value_maybe_array; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Prepares an array of field values FOR use in JSON/REST API |
|
78 | + * |
|
79 | + * @param \EE_Model_Field_Base $field_obj |
|
80 | + * @param mixed $original_value_maybe_array |
|
81 | + * @param string $request_version (eg 4.8.36) |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
85 | + { |
|
86 | + if (is_array($original_value_maybe_array)) { |
|
87 | + $new_value_maybe_array = array(); |
|
88 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
89 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
90 | + $field_obj, |
|
91 | + $array_item, |
|
92 | + $request_version |
|
93 | + ); |
|
94 | + } |
|
95 | + } else { |
|
96 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
97 | + $field_obj, |
|
98 | + $original_value_maybe_array, |
|
99 | + $request_version |
|
100 | + ); |
|
101 | + } |
|
102 | + return $new_value_maybe_array; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
109 | + * "$query_params". |
|
110 | + * |
|
111 | + * @param \EE_Model_Field_Base $field_obj |
|
112 | + * @param mixed $original_value |
|
113 | + * @param string $requested_version |
|
114 | + * @param string $timezone_string treat values as being in this timezone |
|
115 | + * @return mixed |
|
116 | + * @throws \DomainException |
|
117 | + */ |
|
118 | + public static function prepare_field_value_from_json( |
|
119 | + $field_obj, |
|
120 | + $original_value, |
|
121 | + $requested_version, |
|
122 | + $timezone_string = 'UTC' // UTC |
|
123 | + ) |
|
124 | + { |
|
125 | + $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
126 | + $new_value = null; |
|
127 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
128 | + && in_array($original_value, array(null, ''), true) |
|
129 | + ) { |
|
130 | + $new_value = EE_INF; |
|
131 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
132 | + list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
133 | + $field_obj->get_timezone_offset( |
|
134 | + new \DateTimeZone($timezone_string) |
|
135 | + ) |
|
136 | + ); |
|
137 | + $offset_string = |
|
138 | + str_pad( |
|
139 | + floor($offset_secs / HOUR_IN_SECONDS), |
|
140 | + 2, |
|
141 | + '0', |
|
142 | + STR_PAD_LEFT |
|
143 | + ) |
|
144 | + . ':' |
|
145 | + . str_pad( |
|
146 | + ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
147 | + 2, |
|
148 | + '0', |
|
149 | + STR_PAD_LEFT |
|
150 | + ); |
|
151 | + $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
152 | + } else { |
|
153 | + $new_value = $original_value; |
|
154 | + } |
|
155 | + return $new_value; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * determines what's going on with them timezone strings |
|
162 | + * |
|
163 | + * @param int $timezone_offset |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + private static function parse_timezone_offset($timezone_offset) |
|
167 | + { |
|
168 | + $first_char = substr((string)$timezone_offset, 0, 1); |
|
169 | + if ($first_char === '+' || $first_char === '-') { |
|
170 | + $offset_sign = $first_char; |
|
171 | + $offset_secs = substr((string)$timezone_offset, 1); |
|
172 | + } else { |
|
173 | + $offset_sign = '+'; |
|
174 | + $offset_secs = $timezone_offset; |
|
175 | + } |
|
176 | + return array($offset_sign, $offset_secs); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Prepares a field's value for display in the API |
|
183 | + * |
|
184 | + * @param \EE_Model_Field_Base $field_obj |
|
185 | + * @param mixed $original_value |
|
186 | + * @param string $requested_version |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
190 | + { |
|
191 | + if ($original_value === EE_INF) { |
|
192 | + $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
193 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
194 | + if ($original_value instanceof \DateTime) { |
|
195 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
196 | + } elseif (is_int($original_value)) { |
|
197 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
198 | + } else { |
|
199 | + $new_value = $original_value; |
|
200 | + } |
|
201 | + $new_value = mysql_to_rfc3339($new_value); |
|
202 | + } else { |
|
203 | + $new_value = $original_value; |
|
204 | + } |
|
205 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
206 | + $new_value, |
|
207 | + $field_obj, |
|
208 | + $original_value, |
|
209 | + $requested_version |
|
210 | + ); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Prepares condition-query-parameters (like what's in where and having) from |
|
217 | + * the format expected in the API to use in the models |
|
218 | + * |
|
219 | + * @param array $inputted_query_params_of_this_type |
|
220 | + * @param \EEM_Base $model |
|
221 | + * @param string $requested_version |
|
222 | + * @return array |
|
223 | + * @throws \DomainException |
|
224 | + * @throws \EE_Error |
|
225 | + */ |
|
226 | + public static function prepare_conditions_query_params_for_models( |
|
227 | + $inputted_query_params_of_this_type, |
|
228 | + \EEM_Base $model, |
|
229 | + $requested_version |
|
230 | + ) { |
|
231 | + $query_param_for_models = array(); |
|
232 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
233 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
234 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
235 | + $query_param_sans_stars, |
|
236 | + $model |
|
237 | + ); |
|
238 | + //double-check is it a *_gmt field? |
|
239 | + if ( ! $field instanceof \EE_Model_Field_Base |
|
240 | + && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
241 | + ) { |
|
242 | + //yep, take off '_gmt', and find the field |
|
243 | + $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
244 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
245 | + $query_param_key, |
|
246 | + $model |
|
247 | + ); |
|
248 | + $timezone = 'UTC'; |
|
249 | + } else { |
|
250 | + //so it's not a GMT field. Set the timezone on the model to the default |
|
251 | + $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
252 | + } |
|
253 | + if ($field instanceof \EE_Model_Field_Base) { |
|
254 | + //did they specify an operator? |
|
255 | + if (is_array($query_param_value)) { |
|
256 | + $op = $query_param_value[0]; |
|
257 | + $translated_value = array($op); |
|
258 | + if (isset($query_param_value[1])) { |
|
259 | + $value = $query_param_value[1]; |
|
260 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
261 | + $requested_version, $timezone); |
|
262 | + } |
|
263 | + } else { |
|
264 | + $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
265 | + $requested_version, $timezone); |
|
266 | + } |
|
267 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
268 | + } else { |
|
269 | + //so it's not for a field, assume it's a logic query param key |
|
270 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
271 | + $model, $requested_version); |
|
272 | + } |
|
273 | + } |
|
274 | + return $query_param_for_models; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
281 | + * gmt date field name |
|
282 | + * |
|
283 | + * @param string $field_name |
|
284 | + * @return boolean |
|
285 | + */ |
|
286 | + public static function is_gmt_date_field_name($field_name) |
|
287 | + { |
|
288 | + return substr( |
|
289 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
290 | + -4, |
|
291 | + 4 |
|
292 | + ) === '_gmt'; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
299 | + * |
|
300 | + * @param string $field_name |
|
301 | + * @return string |
|
302 | + */ |
|
303 | + public static function remove_gmt_from_field_name($field_name) |
|
304 | + { |
|
305 | + if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
306 | + return $field_name; |
|
307 | + } |
|
308 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
309 | + $query_param_sans_gmt_and_sans_stars = substr( |
|
310 | + $query_param_sans_stars, |
|
311 | + 0, |
|
312 | + strrpos( |
|
313 | + $field_name, |
|
314 | + '_gmt' |
|
315 | + ) |
|
316 | + ); |
|
317 | + return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Takes a field name from the REST API and prepares it for the model querying |
|
324 | + * |
|
325 | + * @param string $field_name |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public static function prepare_field_name_from_json($field_name) |
|
329 | + { |
|
330 | + if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
331 | + return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
332 | + } |
|
333 | + return $field_name; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Takes array of field names from REST API and prepares for models |
|
340 | + * |
|
341 | + * @param array $field_names |
|
342 | + * @return array of field names (possibly include model prefixes) |
|
343 | + */ |
|
344 | + public static function prepare_field_names_from_json(array $field_names) |
|
345 | + { |
|
346 | + $new_array = array(); |
|
347 | + foreach ($field_names as $key => $field_name) { |
|
348 | + $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
349 | + } |
|
350 | + return $new_array; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Takes array where array keys are field names (possibly with model path prefixes) |
|
357 | + * from the REST API and prepares them for model querying |
|
358 | + * |
|
359 | + * @param array $field_names_as_keys |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
363 | + { |
|
364 | + $new_array = array(); |
|
365 | + foreach ($field_names_as_keys as $field_name => $value) { |
|
366 | + $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
367 | + } |
|
368 | + return $new_array; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Prepares an array of model query params for use in the REST API |
|
375 | + * |
|
376 | + * @param array $model_query_params |
|
377 | + * @param \EEM_Base $model |
|
378 | + * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
379 | + * REST API |
|
380 | + * @return array which can be passed into the EE4 REST API when querying a model resource |
|
381 | + * @throws \EE_Error |
|
382 | + */ |
|
383 | + public static function prepare_query_params_for_rest_api( |
|
384 | + array $model_query_params, |
|
385 | + \EEM_Base $model, |
|
386 | + $requested_version = null |
|
387 | + ) { |
|
388 | + if ($requested_version === null) { |
|
389 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
390 | + } |
|
391 | + $rest_query_params = $model_query_params; |
|
392 | + if (isset($model_query_params[0])) { |
|
393 | + $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
394 | + $model_query_params[0], |
|
395 | + $model, |
|
396 | + $requested_version |
|
397 | + ); |
|
398 | + unset($rest_query_params[0]); |
|
399 | + } |
|
400 | + if (isset($model_query_params['having'])) { |
|
401 | + $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
402 | + $model_query_params['having'], |
|
403 | + $model, |
|
404 | + $requested_version |
|
405 | + ); |
|
406 | + } |
|
407 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
408 | + $rest_query_params, $model_query_params, $model, $requested_version); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
415 | + * |
|
416 | + * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
417 | + * passed into EEM_Base::get_all() |
|
418 | + * @param \EEM_Base $model |
|
419 | + * @param string $requested_version eg "4.8.36" |
|
420 | + * @return array ready for use in the rest api query params |
|
421 | + * @throws \EE_Error |
|
422 | + */ |
|
423 | + public static function prepare_conditions_query_params_for_rest_api( |
|
424 | + $inputted_query_params_of_this_type, |
|
425 | + \EEM_Base $model, |
|
426 | + $requested_version |
|
427 | + ) { |
|
428 | + $query_param_for_models = array(); |
|
429 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
430 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
431 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
432 | + $model |
|
433 | + ); |
|
434 | + if ($field instanceof \EE_Model_Field_Base) { |
|
435 | + //did they specify an operator? |
|
436 | + if (is_array($query_param_value)) { |
|
437 | + $op = $query_param_value[0]; |
|
438 | + $translated_value = array($op); |
|
439 | + if (isset($query_param_value[1])) { |
|
440 | + $value = $query_param_value[1]; |
|
441 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
442 | + $requested_version); |
|
443 | + } |
|
444 | + } else { |
|
445 | + $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
446 | + $requested_version); |
|
447 | + } |
|
448 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
449 | + } else { |
|
450 | + //so it's not for a field, assume it's a logic query param key |
|
451 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
452 | + $model, $requested_version); |
|
453 | + } |
|
454 | + } |
|
455 | + return $query_param_for_models; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * @param $condition_query_param_key |
|
462 | + * @return string |
|
463 | + */ |
|
464 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
465 | + { |
|
466 | + $pos_of_star = strpos($condition_query_param_key, '*'); |
|
467 | + if ($pos_of_star === false) { |
|
468 | + return $condition_query_param_key; |
|
469 | + } else { |
|
470 | + $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
471 | + return $condition_query_param_sans_star; |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * Takes the input parameter and finds the model field that it indicates. |
|
479 | + * |
|
480 | + * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
481 | + * @param \EEM_Base $model |
|
482 | + * @return \EE_Model_Field_Base |
|
483 | + * @throws \EE_Error |
|
484 | + */ |
|
485 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
486 | + { |
|
487 | + //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
488 | + //which will help us find the database table and column |
|
489 | + $query_param_parts = explode('.', $query_param_name); |
|
490 | + if (empty($query_param_parts)) { |
|
491 | + throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
492 | + 'event_espresso'), $query_param_name)); |
|
493 | + } |
|
494 | + $number_of_parts = count($query_param_parts); |
|
495 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
496 | + if ($number_of_parts === 1) { |
|
497 | + $field_name = $last_query_param_part; |
|
498 | + } else {// $number_of_parts >= 2 |
|
499 | + //the last part is the column name, and there are only 2parts. therefore... |
|
500 | + $field_name = $last_query_param_part; |
|
501 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
502 | + } |
|
503 | + try { |
|
504 | + return $model->field_settings_for($field_name); |
|
505 | + } catch (\EE_Error $e) { |
|
506 | + return null; |
|
507 | + } |
|
508 | + } |
|
509 | 509 | |
510 | 510 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | '0', |
149 | 149 | STR_PAD_LEFT |
150 | 150 | ); |
151 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
151 | + $new_value = rest_parse_date($original_value.$offset_sign.$offset_string); |
|
152 | 152 | } else { |
153 | 153 | $new_value = $original_value; |
154 | 154 | } |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | */ |
166 | 166 | private static function parse_timezone_offset($timezone_offset) |
167 | 167 | { |
168 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
168 | + $first_char = substr((string) $timezone_offset, 0, 1); |
|
169 | 169 | if ($first_char === '+' || $first_char === '-') { |
170 | 170 | $offset_sign = $first_char; |
171 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
171 | + $offset_secs = substr((string) $timezone_offset, 1); |
|
172 | 172 | } else { |
173 | 173 | $offset_sign = '+'; |
174 | 174 | $offset_secs = $timezone_offset; |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | |
168 | 168 | |
169 | 169 | /** |
170 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even EE_Front_Controller's init phases have run |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @return void |
|
174 | - */ |
|
170 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even EE_Front_Controller's init phases have run |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @return void |
|
174 | + */ |
|
175 | 175 | public function init() { |
176 | 176 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
177 | 177 | if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
@@ -456,11 +456,11 @@ discard block |
||
456 | 456 | |
457 | 457 | |
458 | 458 | /** |
459 | - * admin_init |
|
460 | - * |
|
461 | - * @access public |
|
462 | - * @return void |
|
463 | - */ |
|
459 | + * admin_init |
|
460 | + * |
|
461 | + * @access public |
|
462 | + * @return void |
|
463 | + */ |
|
464 | 464 | public function admin_init() { |
465 | 465 | |
466 | 466 | /** |
@@ -612,24 +612,24 @@ discard block |
||
612 | 612 | |
613 | 613 | |
614 | 614 | /** |
615 | - * dismiss_persistent_admin_notice |
|
616 | - * |
|
617 | - * @access public |
|
618 | - * @return void |
|
619 | - */ |
|
615 | + * dismiss_persistent_admin_notice |
|
616 | + * |
|
617 | + * @access public |
|
618 | + * @return void |
|
619 | + */ |
|
620 | 620 | public function dismiss_ee_nag_notice_callback() { |
621 | 621 | EE_Error::dismiss_persistent_admin_notice(); |
622 | 622 | } |
623 | 623 | |
624 | 624 | |
625 | 625 | |
626 | - /** |
|
627 | - * @param array $elements |
|
628 | - * @return array |
|
629 | - * @throws \EE_Error |
|
630 | - */ |
|
626 | + /** |
|
627 | + * @param array $elements |
|
628 | + * @return array |
|
629 | + * @throws \EE_Error |
|
630 | + */ |
|
631 | 631 | public function dashboard_glance_items($elements) { |
632 | - $elements = is_array($elements) ? $elements : array($elements); |
|
632 | + $elements = is_array($elements) ? $elements : array($elements); |
|
633 | 633 | $events = EEM_Event::instance()->count(); |
634 | 634 | $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
635 | 635 | $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public static function instance() { |
42 | 42 | // check if class object is instantiated |
43 | - if ( ! self::$_instance instanceof EE_Admin ) { |
|
43 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -57,30 +57,30 @@ discard block |
||
57 | 57 | // define global EE_Admin constants |
58 | 58 | $this->_define_all_constants(); |
59 | 59 | // set autoloaders for our admin page classes based on included path information |
60 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN ); |
|
60 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
61 | 61 | // admin hooks |
62 | - add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 ); |
|
62 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
63 | 63 | // load EE_Request_Handler early |
64 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' )); |
|
65 | - add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' )); |
|
64 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
65 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
66 | 66 | // post shortcode tracking |
67 | 67 | add_action( |
68 | 68 | 'AHEE__EE_System__initialize_last', |
69 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'set_hooks_admin' ) |
|
69 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'set_hooks_admin') |
|
70 | 70 | ); |
71 | - add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 ); |
|
72 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 ); |
|
73 | - add_action( 'admin_init', array( $this, 'admin_init' ), 100 ); |
|
74 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 ); |
|
75 | - add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
76 | - add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
77 | - add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 ); |
|
78 | - add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' )); |
|
71 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
72 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
73 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
74 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
75 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
76 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
77 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
78 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
79 | 79 | |
80 | 80 | //reset Environment config (we only do this on admin page loads); |
81 | 81 | EE_Registry::instance()->CFG->environment->recheck_values(); |
82 | 82 | |
83 | - do_action( 'AHEE__EE_Admin__loaded' ); |
|
83 | + do_action('AHEE__EE_Admin__loaded'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | */ |
97 | 97 | private function _define_all_constants() { |
98 | - define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' ); |
|
99 | - define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' ); |
|
100 | - define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS ); |
|
101 | - define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' ); |
|
102 | - define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' )); |
|
98 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
99 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
100 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
101 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
102 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -112,23 +112,23 @@ discard block |
||
112 | 112 | * @param string $plugin |
113 | 113 | * @return array |
114 | 114 | */ |
115 | - public function filter_plugin_actions( $links, $plugin ) { |
|
115 | + public function filter_plugin_actions($links, $plugin) { |
|
116 | 116 | // set $main_file in stone |
117 | 117 | static $main_file; |
118 | 118 | // if $main_file is not set yet |
119 | - if ( ! $main_file ) { |
|
120 | - $main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE ); |
|
119 | + if ( ! $main_file) { |
|
120 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
121 | 121 | } |
122 | - if ( $plugin === $main_file ) { |
|
122 | + if ($plugin === $main_file) { |
|
123 | 123 | // compare current plugin to this one |
124 | - if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
125 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>'; |
|
126 | - array_unshift( $links, $maintenance_link ); |
|
124 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
125 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>'; |
|
126 | + array_unshift($links, $maintenance_link); |
|
127 | 127 | } else { |
128 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>'; |
|
129 | - $events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>'; |
|
128 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>'; |
|
129 | + $events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>'; |
|
130 | 130 | // add before other links |
131 | - array_unshift( $links, $org_settings_link, $events_link ); |
|
131 | + array_unshift($links, $org_settings_link, $events_link); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | return $links; |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | * @return void |
144 | 144 | */ |
145 | 145 | public function get_request() { |
146 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
147 | - EE_Registry::instance()->load_core( 'CPT_Strategy' ); |
|
146 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
147 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | * @param array $admin_page_folder_names |
157 | 157 | * @return array |
158 | 158 | */ |
159 | - public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){ |
|
159 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) { |
|
160 | 160 | return array( |
161 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
162 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
163 | - 'support' => EE_ADMIN_PAGES . 'support' . DS |
|
161 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
162 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
163 | + 'support' => EE_ADMIN_PAGES.'support'.DS |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | |
@@ -174,31 +174,31 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function init() { |
176 | 176 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
177 | - if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
177 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
178 | 178 | //ok so we want to enable the entire admin |
179 | - add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' )); |
|
180 | - add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
181 | - add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
179 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
180 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
181 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
182 | 182 | //at a glance dashboard widget |
183 | - add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 ); |
|
183 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
184 | 184 | //filter for get_edit_post_link used on comments for custom post types |
185 | - add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 ); |
|
185 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
186 | 186 | } |
187 | 187 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
188 | - if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) { |
|
188 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
189 | 189 | try { |
190 | 190 | //this loads the controller for the admin pages which will setup routing etc |
191 | - EE_Registry::instance()->load_core( 'Admin_Page_Loader' ); |
|
192 | - } catch ( EE_Error $e ) { |
|
191 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
192 | + } catch (EE_Error $e) { |
|
193 | 193 | $e->get_error(); |
194 | 194 | } |
195 | 195 | } |
196 | - add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 ); |
|
196 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
197 | 197 | //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
198 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 ); |
|
199 | - add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 ); |
|
198 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
199 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
200 | 200 | //exclude EE critical pages from all nav menus and wp_list_pages |
201 | - add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 ); |
|
201 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | * @param object $post_type WP post type object |
212 | 212 | * @return object WP post type object |
213 | 213 | */ |
214 | - public function remove_pages_from_nav_menu( $post_type ) { |
|
214 | + public function remove_pages_from_nav_menu($post_type) { |
|
215 | 215 | //if this isn't the "pages" post type let's get out |
216 | - if ( $post_type->name !== 'page' ) { |
|
216 | + if ($post_type->name !== 'page') { |
|
217 | 217 | return $post_type; |
218 | 218 | } |
219 | 219 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
@@ -233,28 +233,28 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function enable_hidden_ee_nav_menu_metaboxes() { |
235 | 235 | global $wp_meta_boxes, $pagenow; |
236 | - if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) { |
|
236 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
237 | 237 | return; |
238 | 238 | } |
239 | 239 | $user = wp_get_current_user(); |
240 | 240 | //has this been done yet? |
241 | - if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) { |
|
241 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | 244 | |
245 | - $hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID ); |
|
246 | - $initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) ); |
|
245 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
246 | + $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page')); |
|
247 | 247 | |
248 | - if ( is_array( $hidden_meta_boxes ) ) { |
|
249 | - foreach ( $hidden_meta_boxes as $key => $meta_box_id ) { |
|
250 | - if ( in_array( $meta_box_id, $initial_meta_boxes ) ) { |
|
251 | - unset( $hidden_meta_boxes[ $key ] ); |
|
248 | + if (is_array($hidden_meta_boxes)) { |
|
249 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
250 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
251 | + unset($hidden_meta_boxes[$key]); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | - update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); |
|
257 | - update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true ); |
|
256 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
257 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @return void |
274 | 274 | */ |
275 | 275 | public function register_custom_nav_menu_boxes() { |
276 | - add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' ); |
|
276 | + add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | |
@@ -289,16 +289,16 @@ discard block |
||
289 | 289 | * |
290 | 290 | * @return string the (maybe) modified link |
291 | 291 | */ |
292 | - public function modify_edit_post_link( $link, $id ) { |
|
293 | - if ( ! $post = get_post( $id ) ){ |
|
292 | + public function modify_edit_post_link($link, $id) { |
|
293 | + if ( ! $post = get_post($id)) { |
|
294 | 294 | return $link; |
295 | 295 | } |
296 | - if ( $post->post_type === 'espresso_attendees' ) { |
|
296 | + if ($post->post_type === 'espresso_attendees') { |
|
297 | 297 | $query_args = array( |
298 | 298 | 'action' => 'edit_attendee', |
299 | 299 | 'post' => $id |
300 | 300 | ); |
301 | - return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') ); |
|
301 | + return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
302 | 302 | } |
303 | 303 | return $link; |
304 | 304 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | global $nav_menu_selected_id; |
311 | 311 | |
312 | 312 | $db_fields = false; |
313 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
313 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
314 | 314 | $current_tab = 'event-archives'; |
315 | 315 | |
316 | 316 | /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | ?> |
330 | 330 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
331 | 331 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
332 | - <li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>> |
|
333 | - <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
334 | - <?php _e( 'Event Archive Pages', 'event_espresso' ); ?> |
|
332 | + <li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
|
333 | + <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
334 | + <?php _e('Event Archive Pages', 'event_espresso'); ?> |
|
335 | 335 | </a> |
336 | 336 | </li> |
337 | 337 | <?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs. |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | <?php */ ?> |
350 | 350 | |
351 | 351 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
352 | - echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
|
352 | + echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
353 | 353 | ?>"> |
354 | 354 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
355 | 355 | <?php |
356 | 356 | $pages = $this->_get_extra_nav_menu_pages_items(); |
357 | 357 | $args['walker'] = $walker; |
358 | - echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args ); |
|
358 | + echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args); |
|
359 | 359 | ?> |
360 | 360 | </ul> |
361 | 361 | </div><!-- /.tabs-panel --> |
@@ -363,18 +363,18 @@ discard block |
||
363 | 363 | <p class="button-controls"> |
364 | 364 | <span class="list-controls"> |
365 | 365 | <a href="<?php |
366 | - echo esc_url( add_query_arg( |
|
366 | + echo esc_url(add_query_arg( |
|
367 | 367 | array( |
368 | 368 | 'extra-nav-menu-pages-tab' => 'event-archives', |
369 | 369 | 'selectall' => 1, |
370 | 370 | ), |
371 | - remove_query_arg( $removed_args ) |
|
371 | + remove_query_arg($removed_args) |
|
372 | 372 | )); |
373 | 373 | ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
374 | 374 | </span> |
375 | 375 | |
376 | 376 | <span class="add-to-menu"> |
377 | - <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" /> |
|
377 | + <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" /> |
|
378 | 378 | <span class="spinner"></span> |
379 | 379 | </span> |
380 | 380 | </p> |
@@ -395,10 +395,10 @@ discard block |
||
395 | 395 | private function _get_extra_nav_menu_pages_items() { |
396 | 396 | $menuitems[] = array( |
397 | 397 | 'title' => __('Event List', 'event_espresso'), |
398 | - 'url' => get_post_type_archive_link( 'espresso_events' ), |
|
398 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
399 | 399 | 'description' => __('Archive page for all events.', 'event_espresso') |
400 | 400 | ); |
401 | - return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems ); |
|
401 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @param $menu_item_values |
411 | 411 | * @return stdClass |
412 | 412 | */ |
413 | - private function _setup_extra_nav_menu_pages_items( $menu_item_values ) { |
|
413 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) { |
|
414 | 414 | $menu_item = new stdClass(); |
415 | 415 | $keys = array( |
416 | 416 | 'ID' => 0, |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | 'xfn' => '' |
431 | 431 | ); |
432 | 432 | |
433 | - foreach ( $keys as $key => $value) { |
|
434 | - $menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value; |
|
433 | + foreach ($keys as $key => $value) { |
|
434 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
435 | 435 | } |
436 | 436 | return $menu_item; |
437 | 437 | } |
@@ -470,9 +470,9 @@ discard block |
||
470 | 470 | * - check if doing post processing of one of EE CPTs |
471 | 471 | * - instantiate the corresponding EE CPT model for the post_type being processed. |
472 | 472 | */ |
473 | - if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) { |
|
474 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
475 | - EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] ); |
|
473 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
474 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
475 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * 'options-reading.php' core WordPress admin settings page. This is for user-proofing. |
482 | 482 | */ |
483 | 483 | global $pagenow; |
484 | - if ( $pagenow === 'options-reading.php' ) { |
|
485 | - add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) ); |
|
484 | + if ($pagenow === 'options-reading.php') { |
|
485 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | } |
@@ -494,25 +494,25 @@ discard block |
||
494 | 494 | * @param string $output Current output. |
495 | 495 | * @return string |
496 | 496 | */ |
497 | - public function modify_dropdown_pages( $output ) { |
|
497 | + public function modify_dropdown_pages($output) { |
|
498 | 498 | //get critical pages |
499 | 499 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
500 | 500 | |
501 | 501 | //split current output by line break for easier parsing. |
502 | - $split_output = explode( "\n", $output ); |
|
502 | + $split_output = explode("\n", $output); |
|
503 | 503 | |
504 | 504 | //loop through to remove any critical pages from the array. |
505 | - foreach ( $critical_pages as $page_id ) { |
|
506 | - $needle = 'value="' . $page_id . '"'; |
|
507 | - foreach( $split_output as $key => $haystack ) { |
|
508 | - if( strpos( $haystack, $needle ) !== false ) { |
|
509 | - unset( $split_output[$key] ); |
|
505 | + foreach ($critical_pages as $page_id) { |
|
506 | + $needle = 'value="'.$page_id.'"'; |
|
507 | + foreach ($split_output as $key => $haystack) { |
|
508 | + if (strpos($haystack, $needle) !== false) { |
|
509 | + unset($split_output[$key]); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | 514 | //replace output with the new contents |
515 | - return implode( "\n", $split_output ); |
|
515 | + return implode("\n", $split_output); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | |
@@ -526,36 +526,36 @@ discard block |
||
526 | 526 | public function enqueue_admin_scripts() { |
527 | 527 | // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
528 | 528 | // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
529 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
529 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
530 | 530 | // register cookie script for future dependencies |
531 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE ); |
|
531 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE); |
|
532 | 532 | // jquery_validate loading is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
533 | - if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) { |
|
533 | + if (apply_filters('FHEE_load_jquery_validate', FALSE)) { |
|
534 | 534 | // register jQuery Validate |
535 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE); |
|
535 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', array('jquery'), '1.15.0', TRUE); |
|
536 | 536 | } |
537 | 537 | //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
538 | - if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) { |
|
538 | + if (apply_filters('FHEE_load_joyride', FALSE)) { |
|
539 | 539 | //joyride style |
540 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
541 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION ); |
|
542 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE ); |
|
540 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
541 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
542 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE); |
|
543 | 543 | //joyride JS |
544 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE ); |
|
544 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE); |
|
545 | 545 | // wanna go for a joyride? |
546 | 546 | wp_enqueue_style('ee-joyride-css'); |
547 | 547 | wp_enqueue_script('jquery-joyride'); |
548 | 548 | } |
549 | 549 | //qtip is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtips', '__return_true' ); |
550 | - if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) { |
|
550 | + if (apply_filters('FHEE_load_qtip', FALSE)) { |
|
551 | 551 | EEH_Qtip_Loader::instance()->register_and_enqueue(); |
552 | 552 | } |
553 | 553 | //accounting.js library |
554 | 554 | // @link http://josscrowcroft.github.io/accounting.js/ |
555 | - if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) { |
|
556 | - wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
557 | - wp_register_script( 'ee-accounting-core', EE_THIRD_PARTY_URL . 'accounting/accounting.js', array('underscore'), '0.3.2', TRUE ); |
|
558 | - wp_enqueue_script( 'ee-accounting' ); |
|
555 | + if (apply_filters('FHEE_load_accounting_js', FALSE)) { |
|
556 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE); |
|
557 | + wp_register_script('ee-accounting-core', EE_THIRD_PARTY_URL.'accounting/accounting.js', array('underscore'), '0.3.2', TRUE); |
|
558 | + wp_enqueue_script('ee-accounting'); |
|
559 | 559 | // array of settings to get converted to JSON array via wp_localize_script |
560 | 560 | $currency_config = array( |
561 | 561 | 'currency' => array( |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | public function get_persistent_admin_notices() { |
603 | 603 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
604 | 604 | $args = array( |
605 | - 'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '', |
|
606 | - 'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '', |
|
605 | + 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
606 | + 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
607 | 607 | ); |
608 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL ); |
|
609 | - echo EE_Error::get_persistent_admin_notices( $return_url ); |
|
608 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
609 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | |
@@ -631,24 +631,24 @@ discard block |
||
631 | 631 | public function dashboard_glance_items($elements) { |
632 | 632 | $elements = is_array($elements) ? $elements : array($elements); |
633 | 633 | $events = EEM_Event::instance()->count(); |
634 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
|
635 | - $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
|
634 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php')); |
|
635 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
636 | 636 | $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
637 | 637 | $registrations = EEM_Registration::instance()->count( |
638 | 638 | array( |
639 | 639 | array( |
640 | - 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) |
|
640 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete) |
|
641 | 641 | ) |
642 | 642 | ) |
643 | 643 | ); |
644 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') ); |
|
645 | - $items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) ); |
|
644 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php')); |
|
645 | + $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations)); |
|
646 | 646 | $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
647 | 647 | |
648 | - $items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items ); |
|
648 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
649 | 649 | |
650 | - foreach ( $items as $type => $item_properties ) { |
|
651 | - $elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] ); |
|
650 | + foreach ($items as $type => $item_properties) { |
|
651 | + $elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
652 | 652 | } |
653 | 653 | return $elements; |
654 | 654 | } |
@@ -665,31 +665,31 @@ discard block |
||
665 | 665 | * @throws EE_Error |
666 | 666 | * @return string |
667 | 667 | */ |
668 | - public function check_for_invalid_datetime_formats( $value, $option ) { |
|
668 | + public function check_for_invalid_datetime_formats($value, $option) { |
|
669 | 669 | // check for date_format or time_format |
670 | - switch ( $option ) { |
|
670 | + switch ($option) { |
|
671 | 671 | case 'date_format' : |
672 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
672 | + $date_time_format = $value.' '.get_option('time_format'); |
|
673 | 673 | break; |
674 | 674 | case 'time_format' : |
675 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
675 | + $date_time_format = get_option('date_format').' '.$value; |
|
676 | 676 | break; |
677 | 677 | default : |
678 | 678 | $date_time_format = FALSE; |
679 | 679 | } |
680 | 680 | // do we have a date_time format to check ? |
681 | - if ( $date_time_format ) { |
|
682 | - $error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format ); |
|
681 | + if ($date_time_format) { |
|
682 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
683 | 683 | |
684 | - if ( is_array( $error_msg ) ) { |
|
685 | - $msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format ) . '</p><p><ul>'; |
|
684 | + if (is_array($error_msg)) { |
|
685 | + $msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>'; |
|
686 | 686 | |
687 | 687 | |
688 | - foreach ( $error_msg as $error ) { |
|
689 | - $msg .= '<li>' . $error . '</li>'; |
|
688 | + foreach ($error_msg as $error) { |
|
689 | + $msg .= '<li>'.$error.'</li>'; |
|
690 | 690 | } |
691 | 691 | |
692 | - $msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>'; |
|
692 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
693 | 693 | |
694 | 694 | // trigger WP settings error |
695 | 695 | add_settings_error( |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | ); |
700 | 700 | |
701 | 701 | // set format to something valid |
702 | - switch ( $option ) { |
|
702 | + switch ($option) { |
|
703 | 703 | case 'date_format' : |
704 | 704 | $value = 'F j, Y'; |
705 | 705 | break; |
@@ -721,8 +721,8 @@ discard block |
||
721 | 721 | * @param $content |
722 | 722 | * @return string |
723 | 723 | */ |
724 | - public function its_eSpresso( $content ) { |
|
725 | - return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content ); |
|
724 | + public function its_eSpresso($content) { |
|
725 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * @return string |
735 | 735 | */ |
736 | 736 | public function espresso_admin_footer() { |
737 | - return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' )); |
|
737 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | |
@@ -753,12 +753,12 @@ discard block |
||
753 | 753 | * @param array $config |
754 | 754 | * @return void |
755 | 755 | */ |
756 | - public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) { |
|
757 | - EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' ); |
|
758 | - if ( class_exists( 'EE_Register_Admin_Page' ) ) { |
|
756 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) { |
|
757 | + EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3'); |
|
758 | + if (class_exists('EE_Register_Admin_Page')) { |
|
759 | 759 | $config['page_path'] = $page_path; |
760 | 760 | } |
761 | - EE_Register_Admin_Page::register( $page_basename, $config ); |
|
761 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
762 | 762 | |
763 | 763 | } |
764 | 764 | |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | * @param \WP_Post $post |
772 | 772 | * @return void |
773 | 773 | */ |
774 | - public static function parse_post_content_on_save( $post_ID, $post ) { |
|
774 | + public static function parse_post_content_on_save($post_ID, $post) { |
|
775 | 775 | EE_Error::doing_it_wrong( |
776 | 776 | __METHOD__, |
777 | 777 | __( |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | ), |
781 | 781 | '4.8.41' |
782 | 782 | ); |
783 | - EventEspresso\core\admin\PostShortcodeTracking::parse_post_content_on_save( $post_ID, $post ); |
|
783 | + EventEspresso\core\admin\PostShortcodeTracking::parse_post_content_on_save($post_ID, $post); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | * @param $value |
794 | 794 | * @return void |
795 | 795 | */ |
796 | - public function reset_page_for_posts_on_change( $option, $old_value, $value ) { |
|
796 | + public function reset_page_for_posts_on_change($option, $old_value, $value) { |
|
797 | 797 | EE_Error::doing_it_wrong( |
798 | 798 | __METHOD__, |
799 | 799 | __( |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | ), |
803 | 803 | '4.8.41' |
804 | 804 | ); |
805 | - EventEspresso\core\admin\PostShortcodeTracking::reset_page_for_posts_on_change( $option, $old_value, $value ); |
|
805 | + EventEspresso\core\admin\PostShortcodeTracking::reset_page_for_posts_on_change($option, $old_value, $value); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | } |