@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public function normalize($value_to_normalize) { |
17 | 17 | if(is_array($value_to_normalize)) { |
18 | - return array_shift($value_to_normalize); |
|
19 | - //consider `"null"` values to be equivalent to null. |
|
20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
21 | - return null; |
|
18 | + return array_shift($value_to_normalize); |
|
19 | + //consider `"null"` values to be equivalent to null. |
|
20 | + }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
21 | + return null; |
|
22 | 22 | }else{ |
23 | 23 | return $value_to_normalize; |
24 | 24 | } |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * @return string |
30 | 30 | */ |
31 | 31 | public function unnormalize( $normalized_value ){ |
32 | - //account for default "select here" option values |
|
33 | - if ($normalized_value === null) { |
|
34 | - return ''; |
|
35 | - } |
|
32 | + //account for default "select here" option values |
|
33 | + if ($normalized_value === null) { |
|
34 | + return ''; |
|
35 | + } |
|
36 | 36 | return $normalized_value; |
37 | 37 | } |
38 | 38 | } |
@@ -7,19 +7,19 @@ discard block |
||
7 | 7 | * @subpackage |
8 | 8 | * @author Mike Nelson |
9 | 9 | */ |
10 | -class EE_Text_Normalization extends EE_Normalization_Strategy_Base{ |
|
10 | +class EE_Text_Normalization extends EE_Normalization_Strategy_Base { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
14 | 14 | * @return array|mixed|string |
15 | 15 | */ |
16 | 16 | public function normalize($value_to_normalize) { |
17 | - if(is_array($value_to_normalize)) { |
|
17 | + if (is_array($value_to_normalize)) { |
|
18 | 18 | return array_shift($value_to_normalize); |
19 | 19 | //consider `"null"` values to be equivalent to null. |
20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
20 | + }elseif ($value_to_normalize === '' || $value_to_normalize === null) { |
|
21 | 21 | return null; |
22 | - }else{ |
|
22 | + } else { |
|
23 | 23 | return $value_to_normalize; |
24 | 24 | } |
25 | 25 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $normalized_value |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function unnormalize( $normalized_value ){ |
|
31 | + public function unnormalize($normalized_value) { |
|
32 | 32 | //account for default "select here" option values |
33 | 33 | if ($normalized_value === null) { |
34 | 34 | return ''; |
@@ -17,9 +17,9 @@ |
||
17 | 17 | if(is_array($value_to_normalize)) { |
18 | 18 | return array_shift($value_to_normalize); |
19 | 19 | //consider `"null"` values to be equivalent to null. |
20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
20 | + } elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
21 | 21 | return null; |
22 | - }else{ |
|
22 | + } else{ |
|
23 | 23 | return $value_to_normalize; |
24 | 24 | } |
25 | 25 | } |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
446 | 446 | $new_question->set_system_ID( null ); |
447 | 447 | $new_question->set_wp_user( get_current_user_id() ); |
448 | - //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | - $new_question->set_deleted( false ); |
|
448 | + //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | + $new_question->set_deleted( false ); |
|
450 | 450 | $success = $new_question->save(); |
451 | 451 | if( $success ) { |
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | 503 | if ( $answer instanceof EE_Answer |
504 | - && $answer->value() !== '' |
|
505 | - ) { |
|
504 | + && $answer->value() !== '' |
|
505 | + ) { |
|
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * date_format and the second value is the time format |
38 | 38 | * @return EE_Question |
39 | 39 | */ |
40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * the website will be used. |
51 | 51 | * @return EE_Question |
52 | 52 | */ |
53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
54 | + return new self($props_n_values, TRUE, $timezone); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @access public |
63 | 63 | * @param string $QST_display_text |
64 | 64 | */ |
65 | - public function set_display_text( $QST_display_text = '' ) { |
|
66 | - $this->set( 'QST_display_text', $QST_display_text ); |
|
65 | + public function set_display_text($QST_display_text = '') { |
|
66 | + $this->set('QST_display_text', $QST_display_text); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @access public |
75 | 75 | * @param string $QST_admin_label |
76 | 76 | */ |
77 | - public function set_admin_label( $QST_admin_label = '' ) { |
|
78 | - $this->set( 'QST_admin_label', $QST_admin_label ); |
|
77 | + public function set_admin_label($QST_admin_label = '') { |
|
78 | + $this->set('QST_admin_label', $QST_admin_label); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @param mixed $QST_system |
88 | 88 | */ |
89 | - public function set_system_ID( $QST_system = '' ) { |
|
90 | - $this->set( 'QST_system', $QST_system ); |
|
89 | + public function set_system_ID($QST_system = '') { |
|
90 | + $this->set('QST_system', $QST_system); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @access public |
99 | 99 | * @param string $QST_type |
100 | 100 | */ |
101 | - public function set_question_type( $QST_type = '' ) { |
|
102 | - $this->set( 'QST_type', $QST_type ); |
|
101 | + public function set_question_type($QST_type = '') { |
|
102 | + $this->set('QST_type', $QST_type); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @access public |
111 | 111 | * @param bool $QST_required |
112 | 112 | */ |
113 | - public function set_required( $QST_required = FALSE ) { |
|
114 | - $this->set( 'QST_required', $QST_required ); |
|
113 | + public function set_required($QST_required = FALSE) { |
|
114 | + $this->set('QST_required', $QST_required); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @access public |
123 | 123 | * @param string $QST_required_text |
124 | 124 | */ |
125 | - public function set_required_text( $QST_required_text = '' ) { |
|
126 | - $this->set( 'QST_required_text', $QST_required_text ); |
|
125 | + public function set_required_text($QST_required_text = '') { |
|
126 | + $this->set('QST_required_text', $QST_required_text); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @access public |
135 | 135 | * @param int $QST_order |
136 | 136 | */ |
137 | - public function set_order( $QST_order = 0 ) { |
|
138 | - $this->set( 'QST_order', $QST_order ); |
|
137 | + public function set_order($QST_order = 0) { |
|
138 | + $this->set('QST_order', $QST_order); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | * @param bool $QST_admin_only |
148 | 148 | */ |
149 | - public function set_admin_only( $QST_admin_only = FALSE ) { |
|
150 | - $this->set( 'QST_admin_only', $QST_admin_only ); |
|
149 | + public function set_admin_only($QST_admin_only = FALSE) { |
|
150 | + $this->set('QST_admin_only', $QST_admin_only); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @access public |
159 | 159 | * @param int $QST_wp_user |
160 | 160 | */ |
161 | - public function set_wp_user( $QST_wp_user = 1 ) { |
|
162 | - $this->set( 'QST_wp_user', $QST_wp_user ); |
|
161 | + public function set_wp_user($QST_wp_user = 1) { |
|
162 | + $this->set('QST_wp_user', $QST_wp_user); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @access public |
176 | 176 | * @param bool $QST_deleted |
177 | 177 | */ |
178 | - public function set_deleted( $QST_deleted = FALSE ) { |
|
179 | - $this->set( 'QST_deleted', $QST_deleted ); |
|
178 | + public function set_deleted($QST_deleted = FALSE) { |
|
179 | + $this->set('QST_deleted', $QST_deleted); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @return string |
188 | 188 | */ |
189 | 189 | public function display_text() { |
190 | - return $this->get( 'QST_display_text' ); |
|
190 | + return $this->get('QST_display_text'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return string |
199 | 199 | */ |
200 | 200 | public function admin_label() { |
201 | - return $this->get( 'QST_admin_label' ); |
|
201 | + return $this->get('QST_admin_label'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | public function system_ID() { |
212 | - return $this->get( 'QST_system' ); |
|
212 | + return $this->get('QST_system'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | 222 | public function required() { |
223 | - return $this->get( 'QST_required' ); |
|
223 | + return $this->get('QST_required'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | */ |
234 | 234 | public function required_text() { |
235 | - return $this->get( 'QST_required_text' ); |
|
235 | + return $this->get('QST_required_text'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string |
244 | 244 | */ |
245 | 245 | public function type() { |
246 | - return $this->get( 'QST_type' ); |
|
246 | + return $this->get('QST_type'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return int |
256 | 256 | */ |
257 | 257 | public function order() { |
258 | - return $this->get( 'QST_order' ); |
|
258 | + return $this->get('QST_order'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | 269 | public function admin_only() { |
270 | - return $this->get( 'QST_admin_only' ); |
|
270 | + return $this->get('QST_admin_only'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return int |
279 | 279 | */ |
280 | 280 | public function wp_user() { |
281 | - return $this->get( 'QST_wp_user' ); |
|
281 | + return $this->get('QST_wp_user'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | 291 | public function deleted() { |
292 | - return $this->get( 'QST_deleted' ); |
|
292 | + return $this->get('QST_deleted'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return EE_Answer[] |
300 | 300 | */ |
301 | 301 | public function answers() { |
302 | - return $this->get_many_related( 'Answer' ); |
|
302 | + return $this->get_many_related('Answer'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @return boolean true = has answers, false = no answers. |
310 | 310 | */ |
311 | 311 | public function has_answers() { |
312 | - return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE; |
|
312 | + return $this->count_related('Answer') > 0 ? TRUE : FALSE; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return EE_Question_Group[] |
320 | 320 | */ |
321 | 321 | public function question_groups() { |
322 | - return $this->get_many_related( 'Question_Group' ); |
|
322 | + return $this->get_many_related('Question_Group'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * whether it was trashed or not. |
334 | 334 | * @return EE_Question_Option[] |
335 | 335 | */ |
336 | - public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) { |
|
337 | - if ( ! $this->ID() ) { |
|
336 | + public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) { |
|
337 | + if ( ! $this->ID()) { |
|
338 | 338 | return array(); |
339 | 339 | } |
340 | 340 | $query_params = array(); |
341 | - if ( $selected_value_to_always_include ) { |
|
342 | - if ( is_array( $selected_value_to_always_include ) ) { |
|
343 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include ); |
|
341 | + if ($selected_value_to_always_include) { |
|
342 | + if (is_array($selected_value_to_always_include)) { |
|
343 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
344 | 344 | } else { |
345 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include; |
|
345 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if ( $notDeletedOptionsOnly ) { |
|
349 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE; |
|
348 | + if ($notDeletedOptionsOnly) { |
|
349 | + $query_params[0]['OR*options-query']['QSO_deleted'] = FALSE; |
|
350 | 350 | } |
351 | 351 | //order by QSO_order |
352 | - $query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' ); |
|
353 | - return $this->get_many_related( 'Question_Option', $query_params ); |
|
352 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
353 | + return $this->get_many_related('Question_Option', $query_params); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @return \EE_Question_Option[] |
361 | 361 | */ |
362 | 362 | public function temp_options() { |
363 | - return $this->_model_relations[ 'Question_Option' ]; |
|
363 | + return $this->_model_relations['Question_Option']; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param EE_Question_Option $option |
372 | 372 | * @return boolean success |
373 | 373 | */ |
374 | - public function add_option( EE_Question_Option $option ) { |
|
375 | - return $this->_add_relation_to( $option, 'Question_Option' ); |
|
374 | + public function add_option(EE_Question_Option $option) { |
|
375 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param EE_Question_Option $option |
383 | 383 | * @return boolean success |
384 | 384 | */ |
385 | - public function add_temp_option( EE_Question_Option $option ) { |
|
386 | - $this->_model_relations[ 'Question_Option' ][ ] = $option; |
|
385 | + public function add_temp_option(EE_Question_Option $option) { |
|
386 | + $this->_model_relations['Question_Option'][] = $option; |
|
387 | 387 | return TRUE; |
388 | 388 | } |
389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param EE_Question_Option $option |
395 | 395 | * @return boolean success |
396 | 396 | */ |
397 | - public function remove_option( EE_Question_Option $option ) { |
|
398 | - return $this->_remove_relation_to( $option, 'Question_Option' ); |
|
397 | + public function remove_option(EE_Question_Option $option) { |
|
398 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * @return bool |
405 | 405 | */ |
406 | 406 | public function is_system_question() { |
407 | - $system_ID = $this->get( 'QST_system' ); |
|
408 | - return ! empty( $system_ID ) ? TRUE : FALSE; |
|
407 | + $system_ID = $this->get('QST_system'); |
|
408 | + return ! empty($system_ID) ? TRUE : FALSE; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function set_order_to_latest() { |
420 | 420 | $latest_order = $this->get_model()->get_latest_question_order(); |
421 | - $latest_order ++; |
|
422 | - $this->set( 'QST_order', $latest_order ); |
|
421 | + $latest_order++; |
|
422 | + $this->set('QST_order', $latest_order); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -438,20 +438,20 @@ discard block |
||
438 | 438 | * Duplicates this question and its question options |
439 | 439 | * @return \EE_Question |
440 | 440 | */ |
441 | - public function duplicate( $options = array() ) { |
|
441 | + public function duplicate($options = array()) { |
|
442 | 442 | $new_question = clone $this; |
443 | - $new_question->set( 'QST_ID', null ); |
|
444 | - $new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) ); |
|
445 | - $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
|
446 | - $new_question->set_system_ID( null ); |
|
447 | - $new_question->set_wp_user( get_current_user_id() ); |
|
443 | + $new_question->set('QST_ID', null); |
|
444 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
445 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
446 | + $new_question->set_system_ID(null); |
|
447 | + $new_question->set_wp_user(get_current_user_id()); |
|
448 | 448 | //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
449 | - $new_question->set_deleted( false ); |
|
449 | + $new_question->set_deleted(false); |
|
450 | 450 | $success = $new_question->save(); |
451 | - if( $success ) { |
|
451 | + if ($success) { |
|
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
453 | - foreach( $this->options() as $question_option ) { |
|
454 | - $question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) ); |
|
453 | + foreach ($this->options() as $question_option) { |
|
454 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
455 | 455 | } |
456 | 456 | return $new_question; |
457 | 457 | } else { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @return int|float |
465 | 465 | */ |
466 | 466 | public function max() { |
467 | - return $this->get( 'QST_max' ); |
|
467 | + return $this->get('QST_max'); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int|float $new_max |
473 | 473 | * @return void |
474 | 474 | */ |
475 | - public function set_max( $new_max ) { |
|
476 | - $this->set( 'QST_max', $new_max ); |
|
475 | + public function set_max($new_max) { |
|
476 | + $this->set('QST_max', $new_max); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @param array $input_constructor_args |
486 | 486 | * @return EE_Form_Input_Base |
487 | 487 | */ |
488 | - public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) { |
|
488 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) { |
|
489 | 489 | $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
490 | 490 | |
491 | 491 | $input_constructor_args = array_merge( |
@@ -496,29 +496,29 @@ discard block |
||
496 | 496 | ), |
497 | 497 | $input_constructor_args |
498 | 498 | ); |
499 | - if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) { |
|
500 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() ); |
|
499 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
500 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | - if ( $answer instanceof EE_Answer |
|
503 | + if ($answer instanceof EE_Answer |
|
504 | 504 | && $answer->value() !== '' |
505 | 505 | ) { |
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
509 | 509 | $values_with_html_special_chars = $answer->value(); |
510 | - if( is_array( $values_with_html_special_chars ) ) { |
|
511 | - $default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars ); |
|
510 | + if (is_array($values_with_html_special_chars)) { |
|
511 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
512 | 512 | } else { |
513 | - $default_value = htmlspecialchars_decode( $values_with_html_special_chars ); |
|
513 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
514 | 514 | } |
515 | 515 | $input_constructor_args['default'] = $default_value; |
516 | 516 | } |
517 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
|
518 | - if( EEM_Question::instance()->question_type_is_in_category( $this->type(), 'text' ) ) { |
|
519 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
517 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
518 | + if (EEM_Question::instance()->question_type_is_in_category($this->type(), 'text')) { |
|
519 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
520 | 520 | null, |
521 | - min( $max_max_for_question, $this->max() ) |
|
521 | + min($max_max_for_question, $this->max()) |
|
522 | 522 | ); |
523 | 523 | } |
524 | 524 | $input_constructor_args = apply_filters( |
@@ -530,22 +530,22 @@ discard block |
||
530 | 530 | ); |
531 | 531 | |
532 | 532 | $result = null; |
533 | - switch ( $this->type() ) { |
|
533 | + switch ($this->type()) { |
|
534 | 534 | // Text |
535 | 535 | case EEM_Question::QST_type_text : |
536 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
536 | + $result = new EE_Text_Input($input_constructor_args); |
|
537 | 537 | break; |
538 | 538 | // Textarea |
539 | 539 | case EEM_Question::QST_type_textarea : |
540 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
540 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
541 | 541 | break; |
542 | 542 | // Radio Buttons |
543 | 543 | case EEM_Question::QST_type_radio : |
544 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
544 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
545 | 545 | break; |
546 | 546 | // Dropdown |
547 | 547 | case EEM_Question::QST_type_dropdown : |
548 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
548 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
549 | 549 | break; |
550 | 550 | // State Dropdown |
551 | 551 | case EEM_Question::QST_type_state : |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | $registration, |
557 | 557 | $answer |
558 | 558 | ); |
559 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
559 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
560 | 560 | break; |
561 | 561 | // Country Dropdown |
562 | 562 | case EEM_Question::QST_type_country : |
@@ -567,49 +567,49 @@ discard block |
||
567 | 567 | $registration, |
568 | 568 | $answer |
569 | 569 | ); |
570 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
570 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
571 | 571 | break; |
572 | 572 | // Checkboxes |
573 | 573 | case EEM_Question::QST_type_checkbox : |
574 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
574 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
575 | 575 | break; |
576 | 576 | // Date |
577 | 577 | case EEM_Question::QST_type_date : |
578 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
578 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
579 | 579 | break; |
580 | 580 | case EEM_Question::QST_type_html_textarea : |
581 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
582 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
583 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
581 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
582 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
583 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
584 | 584 | break; |
585 | 585 | case EEM_Question::QST_type_email : |
586 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
586 | + $result = new EE_Email_Input($input_constructor_args); |
|
587 | 587 | break; |
588 | 588 | case EEM_Question::QST_type_us_phone : |
589 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
589 | + $result = new EE_Phone_Input($input_constructor_args); |
|
590 | 590 | break; |
591 | 591 | case EEM_Question::QST_type_int : |
592 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Int_Validation_Strategy(); |
|
593 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
592 | + $input_constructor_args['validation_strategies'][] = new EE_Int_Validation_Strategy(); |
|
593 | + $result = new EE_Text_Input($input_constructor_args); |
|
594 | 594 | break; |
595 | 595 | case EEM_Question::QST_type_decimal : |
596 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Float_Validation_Strategy(); |
|
597 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
596 | + $input_constructor_args['validation_strategies'][] = new EE_Float_Validation_Strategy(); |
|
597 | + $result = new EE_Text_Input($input_constructor_args); |
|
598 | 598 | break; |
599 | 599 | case EEM_Question::QST_type_url : |
600 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
601 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
600 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
601 | + $result = new EE_Text_Input($input_constructor_args); |
|
602 | 602 | break; |
603 | 603 | case EEM_Question::QST_type_year : |
604 | 604 | $result = new EE_Year_Input( |
605 | 605 | $input_constructor_args, |
606 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
607 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
608 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
606 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
607 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
608 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
609 | 609 | ); |
610 | 610 | break; |
611 | 611 | case EEM_Question::QST_type_multi_select : |
612 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
612 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
613 | 613 | break; |
614 | 614 | // fallback |
615 | 615 | default : |
@@ -620,12 +620,12 @@ discard block |
||
620 | 620 | $this, |
621 | 621 | $input_constructor_args |
622 | 622 | ); |
623 | - if( ! $default_input ){ |
|
624 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
623 | + if ( ! $default_input) { |
|
624 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
625 | 625 | } |
626 | 626 | $result = $default_input; |
627 | 627 | } |
628 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
628 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,1428 +16,1428 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
21 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
22 | - */ |
|
23 | - const req_type_normal = 0; |
|
24 | - |
|
25 | - /** |
|
26 | - * Indicates this is a brand new installation of EE so we should install |
|
27 | - * tables and default data etc |
|
28 | - */ |
|
29 | - const req_type_new_activation = 1; |
|
30 | - |
|
31 | - /** |
|
32 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
33 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
34 | - * and that default data is setup too |
|
35 | - */ |
|
36 | - const req_type_reactivation = 2; |
|
37 | - |
|
38 | - /** |
|
39 | - * indicates that EE has been upgraded since its previous request. |
|
40 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
41 | - */ |
|
42 | - const req_type_upgrade = 3; |
|
43 | - |
|
44 | - /** |
|
45 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
46 | - */ |
|
47 | - const req_type_downgrade = 4; |
|
48 | - |
|
49 | - /** |
|
50 | - * @deprecated since version 4.6.0.dev.006 |
|
51 | - * Now whenever a new_activation is detected the request type is still just |
|
52 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
53 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
54 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
55 | - * (Specifically, when the migration manager indicates migrations are finished |
|
56 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
57 | - */ |
|
58 | - const req_type_activation_but_not_installed = 5; |
|
59 | - |
|
60 | - /** |
|
61 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
62 | - */ |
|
63 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * instance of the EE_System object |
|
68 | - * |
|
69 | - * @var $_instance |
|
70 | - * @access private |
|
71 | - */ |
|
72 | - private static $_instance = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type EE_Registry $Registry |
|
76 | - * @access protected |
|
77 | - */ |
|
78 | - protected $registry; |
|
79 | - |
|
80 | - /** |
|
81 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
82 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
83 | - * |
|
84 | - * @var int |
|
85 | - */ |
|
86 | - private $_req_type; |
|
87 | - |
|
88 | - /** |
|
89 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
90 | - * |
|
91 | - * @var boolean |
|
92 | - */ |
|
93 | - private $_major_version_change = false; |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @singleton method used to instantiate class object |
|
99 | - * @access public |
|
100 | - * @param \EE_Registry $Registry |
|
101 | - * @return \EE_System |
|
102 | - */ |
|
103 | - public static function instance(EE_Registry $Registry = null) |
|
104 | - { |
|
105 | - // check if class object is instantiated |
|
106 | - if ( ! self::$_instance instanceof EE_System) { |
|
107 | - self::$_instance = new self($Registry); |
|
108 | - } |
|
109 | - return self::$_instance; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * resets the instance and returns it |
|
116 | - * |
|
117 | - * @return EE_System |
|
118 | - */ |
|
119 | - public static function reset() |
|
120 | - { |
|
121 | - self::$_instance->_req_type = null; |
|
122 | - //make sure none of the old hooks are left hanging around |
|
123 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
124 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
125 | - EE_Data_Migration_Manager::reset(); |
|
126 | - self::instance()->detect_activations_or_upgrades(); |
|
127 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
128 | - return self::instance(); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * sets hooks for running rest of system |
|
135 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
136 | - * starting EE Addons from any other point may lead to problems |
|
137 | - * |
|
138 | - * @access private |
|
139 | - * @param \EE_Registry $Registry |
|
140 | - */ |
|
141 | - private function __construct(EE_Registry $Registry) |
|
142 | - { |
|
143 | - $this->registry = $Registry; |
|
144 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
145 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
146 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
147 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
148 | - // because the newly-activated addon didn't get a chance to run at all |
|
149 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
150 | - // detect whether install or upgrade |
|
151 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
152 | - 3); |
|
153 | - // load EE_Config, EE_Textdomain, etc |
|
154 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
155 | - // load EE_Config, EE_Textdomain, etc |
|
156 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
157 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
158 | - // you wanna get going? I wanna get going... let's get going! |
|
159 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
160 | - //other housekeeping |
|
161 | - //exclude EE critical pages from wp_list_pages |
|
162 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
163 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
164 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
165 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * load_espresso_addons |
|
172 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
173 | - * this is hooked into both: |
|
174 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
175 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
176 | - * and the WP 'activate_plugin' hookpoint |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - public function load_espresso_addons() |
|
182 | - { |
|
183 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
184 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
185 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
186 | - //load and setup EE_Capabilities |
|
187 | - $this->registry->load_core('Capabilities'); |
|
188 | - //caps need to be initialized on every request so that capability maps are set. |
|
189 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
190 | - $this->registry->CAP->init_caps(); |
|
191 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
192 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
193 | - //We want it for mobile apps. Just include the entire plugin |
|
194 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
195 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
196 | - //and causes a fatal error |
|
197 | - if ( ! function_exists('json_basic_auth_handler') |
|
198 | - && ! function_exists('json_basic_auth_error') |
|
199 | - && ! ( |
|
200 | - isset($_GET['action']) |
|
201 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
202 | - ) |
|
203 | - && ! ( |
|
204 | - isset($_GET['activate']) |
|
205 | - && $_GET['activate'] === 'true' |
|
206 | - ) |
|
207 | - ) { |
|
208 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
209 | - } |
|
210 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * detect_activations_or_upgrades |
|
217 | - * Checks for activation or upgrade of core first; |
|
218 | - * then also checks if any registered addons have been activated or upgraded |
|
219 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
220 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return void |
|
224 | - */ |
|
225 | - public function detect_activations_or_upgrades() |
|
226 | - { |
|
227 | - //first off: let's make sure to handle core |
|
228 | - $this->detect_if_activation_or_upgrade(); |
|
229 | - foreach ($this->registry->addons as $addon) { |
|
230 | - //detect teh request type for that addon |
|
231 | - $addon->detect_activation_or_upgrade(); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * detect_if_activation_or_upgrade |
|
239 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
240 | - * and either setting up the DB or setting up maintenance mode etc. |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - public function detect_if_activation_or_upgrade() |
|
246 | - { |
|
247 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
248 | - // load M-Mode class |
|
249 | - $this->registry->load_core('Maintenance_Mode'); |
|
250 | - // check if db has been updated, or if its a brand-new installation |
|
251 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
252 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
253 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
254 | - switch ($request_type) { |
|
255 | - case EE_System::req_type_new_activation: |
|
256 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
257 | - $this->_handle_core_version_change($espresso_db_update); |
|
258 | - break; |
|
259 | - case EE_System::req_type_reactivation: |
|
260 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
261 | - $this->_handle_core_version_change($espresso_db_update); |
|
262 | - break; |
|
263 | - case EE_System::req_type_upgrade: |
|
264 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
265 | - //migrations may be required now that we've upgraded |
|
266 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
267 | - $this->_handle_core_version_change($espresso_db_update); |
|
268 | - // echo "done upgrade";die; |
|
269 | - break; |
|
270 | - case EE_System::req_type_downgrade: |
|
271 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
272 | - //its possible migrations are no longer required |
|
273 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
274 | - $this->_handle_core_version_change($espresso_db_update); |
|
275 | - break; |
|
276 | - case EE_System::req_type_normal: |
|
277 | - default: |
|
278 | - // $this->_maybe_redirect_to_ee_about(); |
|
279 | - break; |
|
280 | - } |
|
281 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Updates the list of installed versions and sets hooks for |
|
288 | - * initializing the database later during the request |
|
289 | - * |
|
290 | - * @param array $espresso_db_update |
|
291 | - */ |
|
292 | - protected function _handle_core_version_change($espresso_db_update) |
|
293 | - { |
|
294 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
295 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
296 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
297 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
304 | - * information about what versions of EE have been installed and activated, |
|
305 | - * NOT necessarily the state of the database |
|
306 | - * |
|
307 | - * @param null $espresso_db_update |
|
308 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
309 | - * from the options table |
|
310 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
311 | - */ |
|
312 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
313 | - { |
|
314 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
315 | - if ( ! $espresso_db_update) { |
|
316 | - $espresso_db_update = get_option('espresso_db_update'); |
|
317 | - } |
|
318 | - // check that option is an array |
|
319 | - if ( ! is_array($espresso_db_update)) { |
|
320 | - // if option is FALSE, then it never existed |
|
321 | - if ($espresso_db_update === false) { |
|
322 | - // make $espresso_db_update an array and save option with autoload OFF |
|
323 | - $espresso_db_update = array(); |
|
324 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
325 | - } else { |
|
326 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
327 | - $espresso_db_update = array($espresso_db_update => array()); |
|
328 | - update_option('espresso_db_update', $espresso_db_update); |
|
329 | - } |
|
330 | - } else { |
|
331 | - $corrected_db_update = array(); |
|
332 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
333 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
334 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
335 | - //the key is an int, and the value IS NOT an array |
|
336 | - //so it must be numerically-indexed, where values are versions installed... |
|
337 | - //fix it! |
|
338 | - $version_string = $should_be_array; |
|
339 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
340 | - } else { |
|
341 | - //ok it checks out |
|
342 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
343 | - } |
|
344 | - } |
|
345 | - $espresso_db_update = $corrected_db_update; |
|
346 | - update_option('espresso_db_update', $espresso_db_update); |
|
347 | - } |
|
348 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
349 | - return $espresso_db_update; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
356 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
357 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
358 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
359 | - * so that it will be done when migrations are finished |
|
360 | - * |
|
361 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
362 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
363 | - * This is a resource-intensive job |
|
364 | - * so we prefer to only do it when necessary |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
368 | - { |
|
369 | - $request_type = $this->detect_req_type(); |
|
370 | - //only initialize system if we're not in maintenance mode. |
|
371 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
372 | - update_option('ee_flush_rewrite_rules', true); |
|
373 | - if ($verify_schema) { |
|
374 | - EEH_Activation::initialize_db_and_folders(); |
|
375 | - } |
|
376 | - EEH_Activation::initialize_db_content(); |
|
377 | - EEH_Activation::system_initialization(); |
|
378 | - if ($initialize_addons_too) { |
|
379 | - $this->initialize_addons(); |
|
380 | - } |
|
381 | - } else { |
|
382 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
383 | - } |
|
384 | - if ($request_type === EE_System::req_type_new_activation |
|
385 | - || $request_type === EE_System::req_type_reactivation |
|
386 | - || ( |
|
387 | - $request_type === EE_System::req_type_upgrade |
|
388 | - && $this->is_major_version_change() |
|
389 | - ) |
|
390 | - ) { |
|
391 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * Initializes the db for all registered addons |
|
399 | - */ |
|
400 | - public function initialize_addons() |
|
401 | - { |
|
402 | - //foreach registered addon, make sure its db is up-to-date too |
|
403 | - foreach ($this->registry->addons as $addon) { |
|
404 | - $addon->initialize_db_if_no_migrations_required(); |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
412 | - * |
|
413 | - * @param array $version_history |
|
414 | - * @param string $current_version_to_add version to be added to the version history |
|
415 | - * @return boolean success as to whether or not this option was changed |
|
416 | - */ |
|
417 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
418 | - { |
|
419 | - if ( ! $version_history) { |
|
420 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
421 | - } |
|
422 | - if ($current_version_to_add == null) { |
|
423 | - $current_version_to_add = espresso_version(); |
|
424 | - } |
|
425 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
426 | - // re-save |
|
427 | - return update_option('espresso_db_update', $version_history); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * Detects if the current version indicated in the has existed in the list of |
|
434 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
435 | - * |
|
436 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
437 | - * If not supplied, fetches it from the options table. |
|
438 | - * Also, caches its result so later parts of the code can also know whether |
|
439 | - * there's been an update or not. This way we can add the current version to |
|
440 | - * espresso_db_update, but still know if this is a new install or not |
|
441 | - * @return int one of the constants on EE_System::req_type_ |
|
442 | - */ |
|
443 | - public function detect_req_type($espresso_db_update = null) |
|
444 | - { |
|
445 | - if ($this->_req_type === null) { |
|
446 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
447 | - : $this->fix_espresso_db_upgrade_option(); |
|
448 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
449 | - 'ee_espresso_activation', espresso_version()); |
|
450 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
451 | - } |
|
452 | - return $this->_req_type; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
459 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
460 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
461 | - * |
|
462 | - * @param $activation_history |
|
463 | - * @return bool |
|
464 | - */ |
|
465 | - protected function _detect_major_version_change($activation_history) |
|
466 | - { |
|
467 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
468 | - $previous_version_parts = explode('.', $previous_version); |
|
469 | - $current_version_parts = explode('.', espresso_version()); |
|
470 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
471 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
472 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
473 | - ); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * Returns true if either the major or minor version of EE changed during this request. |
|
480 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
481 | - * |
|
482 | - * @return bool |
|
483 | - */ |
|
484 | - public function is_major_version_change() |
|
485 | - { |
|
486 | - return $this->_major_version_change; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
493 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
494 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
495 | - * just activated to (for core that will always be espresso_version()) |
|
496 | - * |
|
497 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
498 | - * ee plugin. for core that's 'espresso_db_update' |
|
499 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
500 | - * indicate that this plugin was just activated |
|
501 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
502 | - * espresso_version()) |
|
503 | - * @return int one of the constants on EE_System::req_type_* |
|
504 | - */ |
|
505 | - public static function detect_req_type_given_activation_history( |
|
506 | - $activation_history_for_addon, |
|
507 | - $activation_indicator_option_name, |
|
508 | - $version_to_upgrade_to |
|
509 | - ) { |
|
510 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
511 | - if ($activation_history_for_addon) { |
|
512 | - //it exists, so this isn't a completely new install |
|
513 | - //check if this version already in that list of previously installed versions |
|
514 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
515 | - //it a version we haven't seen before |
|
516 | - if ($version_is_higher === 1) { |
|
517 | - $req_type = EE_System::req_type_upgrade; |
|
518 | - } else { |
|
519 | - $req_type = EE_System::req_type_downgrade; |
|
520 | - } |
|
521 | - delete_option($activation_indicator_option_name); |
|
522 | - } else { |
|
523 | - // its not an update. maybe a reactivation? |
|
524 | - if (get_option($activation_indicator_option_name, false)) { |
|
525 | - if ($version_is_higher === -1) { |
|
526 | - $req_type = EE_System::req_type_downgrade; |
|
527 | - } elseif ($version_is_higher === 0) { |
|
528 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
529 | - $req_type = EE_System::req_type_reactivation; |
|
530 | - } else {//$version_is_higher === 1 |
|
531 | - $req_type = EE_System::req_type_upgrade; |
|
532 | - } |
|
533 | - delete_option($activation_indicator_option_name); |
|
534 | - } else { |
|
535 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
536 | - if ($version_is_higher === -1) { |
|
537 | - $req_type = EE_System::req_type_downgrade; |
|
538 | - } elseif ($version_is_higher === 0) { |
|
539 | - //we've seen this version before and it's not an activation. its normal request |
|
540 | - $req_type = EE_System::req_type_normal; |
|
541 | - } else {//$version_is_higher === 1 |
|
542 | - $req_type = EE_System::req_type_upgrade; |
|
543 | - } |
|
544 | - } |
|
545 | - } |
|
546 | - } else { |
|
547 | - //brand new install |
|
548 | - $req_type = EE_System::req_type_new_activation; |
|
549 | - delete_option($activation_indicator_option_name); |
|
550 | - } |
|
551 | - return $req_type; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
558 | - * the $activation_history_for_addon |
|
559 | - * |
|
560 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
561 | - * sometimes containing 'unknown-date' |
|
562 | - * @param string $version_to_upgrade_to (current version) |
|
563 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
564 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
565 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
566 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
567 | - */ |
|
568 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
569 | - { |
|
570 | - //find the most recently-activated version |
|
571 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
572 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Gets the most recently active version listed in the activation history, |
|
579 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
580 | - * |
|
581 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
582 | - * sometimes containing 'unknown-date' |
|
583 | - * @return string |
|
584 | - */ |
|
585 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
586 | - { |
|
587 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
588 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
589 | - if (is_array($activation_history)) { |
|
590 | - foreach ($activation_history as $version => $times_activated) { |
|
591 | - //check there is a record of when this version was activated. Otherwise, |
|
592 | - //mark it as unknown |
|
593 | - if ( ! $times_activated) { |
|
594 | - $times_activated = array('unknown-date'); |
|
595 | - } |
|
596 | - if (is_string($times_activated)) { |
|
597 | - $times_activated = array($times_activated); |
|
598 | - } |
|
599 | - foreach ($times_activated as $an_activation) { |
|
600 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
601 | - $most_recently_active_version = $version; |
|
602 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
603 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
604 | - } |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - return $most_recently_active_version; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * This redirects to the about EE page after activation |
|
615 | - * |
|
616 | - * @return void |
|
617 | - */ |
|
618 | - public function redirect_to_about_ee() |
|
619 | - { |
|
620 | - $notices = EE_Error::get_notices(false); |
|
621 | - //if current user is an admin and it's not an ajax or rest request |
|
622 | - if ( |
|
623 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
624 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
625 | - && ! isset($notices['errors']) |
|
626 | - && apply_filters( |
|
627 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
628 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
629 | - ) |
|
630 | - ) { |
|
631 | - $query_params = array('page' => 'espresso_about'); |
|
632 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
633 | - $query_params['new_activation'] = true; |
|
634 | - } |
|
635 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
636 | - $query_params['reactivation'] = true; |
|
637 | - } |
|
638 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
639 | - wp_safe_redirect($url); |
|
640 | - exit(); |
|
641 | - } |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * load_core_configuration |
|
648 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
649 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
650 | - * |
|
651 | - * @return void |
|
652 | - */ |
|
653 | - public function load_core_configuration() |
|
654 | - { |
|
655 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
656 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
657 | - //load textdomain |
|
658 | - EE_Load_Textdomain::load_textdomain(); |
|
659 | - // load and setup EE_Config and EE_Network_Config |
|
660 | - $this->registry->load_core('Config'); |
|
661 | - $this->registry->load_core('Network_Config'); |
|
662 | - // setup autoloaders |
|
663 | - // enable logging? |
|
664 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
665 | - $this->registry->load_core('Log'); |
|
666 | - } |
|
667 | - // check for activation errors |
|
668 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
669 | - if ($activation_errors) { |
|
670 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
671 | - update_option('ee_plugin_activation_errors', false); |
|
672 | - } |
|
673 | - // get model names |
|
674 | - $this->_parse_model_names(); |
|
675 | - //load caf stuff a chance to play during the activation process too. |
|
676 | - $this->_maybe_brew_regular(); |
|
677 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
684 | - * |
|
685 | - * @return void |
|
686 | - */ |
|
687 | - private function _parse_model_names() |
|
688 | - { |
|
689 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
690 | - $models = glob(EE_MODELS . '*.model.php'); |
|
691 | - $model_names = array(); |
|
692 | - $non_abstract_db_models = array(); |
|
693 | - foreach ($models as $model) { |
|
694 | - // get model classname |
|
695 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
696 | - $short_name = str_replace('EEM_', '', $classname); |
|
697 | - $reflectionClass = new ReflectionClass($classname); |
|
698 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
699 | - $non_abstract_db_models[$short_name] = $classname; |
|
700 | - } |
|
701 | - $model_names[$short_name] = $classname; |
|
702 | - } |
|
703 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
704 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
705 | - $non_abstract_db_models); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
712 | - * that need to be setup before our EE_System launches. |
|
713 | - * |
|
714 | - * @return void |
|
715 | - */ |
|
716 | - private function _maybe_brew_regular() |
|
717 | - { |
|
718 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
719 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
720 | - } |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * register_shortcodes_modules_and_widgets |
|
727 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
728 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
729 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
730 | - * |
|
731 | - * @access public |
|
732 | - * @return void |
|
733 | - */ |
|
734 | - public function register_shortcodes_modules_and_widgets() |
|
735 | - { |
|
736 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
737 | - // check for addons using old hookpoint |
|
738 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
739 | - $this->_incompatible_addon_error(); |
|
740 | - } |
|
741 | - } |
|
742 | - |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * _incompatible_addon_error |
|
747 | - * |
|
748 | - * @access public |
|
749 | - * @return void |
|
750 | - */ |
|
751 | - private function _incompatible_addon_error() |
|
752 | - { |
|
753 | - // get array of classes hooking into here |
|
754 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
755 | - if ( ! empty($class_names)) { |
|
756 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
757 | - 'event_espresso'); |
|
758 | - $msg .= '<ul>'; |
|
759 | - foreach ($class_names as $class_name) { |
|
760 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
761 | - $class_name) . '</b></li>'; |
|
762 | - } |
|
763 | - $msg .= '</ul>'; |
|
764 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
765 | - 'event_espresso'); |
|
766 | - // save list of incompatible addons to wp-options for later use |
|
767 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
768 | - if (is_admin()) { |
|
769 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - |
|
776 | - /** |
|
777 | - * brew_espresso |
|
778 | - * begins the process of setting hooks for initializing EE in the correct order |
|
779 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
780 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
781 | - * |
|
782 | - * @return void |
|
783 | - */ |
|
784 | - public function brew_espresso() |
|
785 | - { |
|
786 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
787 | - // load some final core systems |
|
788 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
789 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
790 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
791 | - add_action('init', array($this, 'load_controllers'), 7); |
|
792 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
793 | - add_action('init', array($this, 'initialize'), 10); |
|
794 | - add_action('init', array($this, 'initialize_last'), 100); |
|
795 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
796 | - add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
797 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
798 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
799 | - // pew pew pew |
|
800 | - $this->registry->load_core('PUE'); |
|
801 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
802 | - } |
|
803 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * set_hooks_for_core |
|
810 | - * |
|
811 | - * @access public |
|
812 | - * @return void |
|
813 | - */ |
|
814 | - public function set_hooks_for_core() |
|
815 | - { |
|
816 | - $this->_deactivate_incompatible_addons(); |
|
817 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
824 | - * deactivates any addons considered incompatible with the current version of EE |
|
825 | - */ |
|
826 | - private function _deactivate_incompatible_addons() |
|
827 | - { |
|
828 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
829 | - if ( ! empty($incompatible_addons)) { |
|
830 | - $active_plugins = get_option('active_plugins', array()); |
|
831 | - foreach ($active_plugins as $active_plugin) { |
|
832 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
833 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
834 | - unset($_GET['activate']); |
|
835 | - espresso_deactivate_plugin($active_plugin); |
|
836 | - } |
|
837 | - } |
|
838 | - } |
|
839 | - } |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * perform_activations_upgrades_and_migrations |
|
846 | - * |
|
847 | - * @access public |
|
848 | - * @return void |
|
849 | - */ |
|
850 | - public function perform_activations_upgrades_and_migrations() |
|
851 | - { |
|
852 | - //first check if we had previously attempted to setup EE's directories but failed |
|
853 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
854 | - EEH_Activation::create_upload_directories(); |
|
855 | - } |
|
856 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * load_CPTs_and_session |
|
863 | - * |
|
864 | - * @access public |
|
865 | - * @return void |
|
866 | - */ |
|
867 | - public function load_CPTs_and_session() |
|
868 | - { |
|
869 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
870 | - // register Custom Post Types |
|
871 | - $this->registry->load_core('Register_CPTs'); |
|
872 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - /** |
|
878 | - * load_controllers |
|
879 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
880 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
881 | - * time |
|
882 | - * |
|
883 | - * @access public |
|
884 | - * @return void |
|
885 | - */ |
|
886 | - public function load_controllers() |
|
887 | - { |
|
888 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
889 | - // let's get it started |
|
890 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
891 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
892 | - $this->registry->load_core('Front_Controller', array(), false, true); |
|
893 | - } else if ( ! EE_FRONT_AJAX) { |
|
894 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
895 | - EE_Registry::instance()->load_core('Admin'); |
|
896 | - } |
|
897 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * core_loaded_and_ready |
|
904 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
905 | - * |
|
906 | - * @access public |
|
907 | - * @return void |
|
908 | - */ |
|
909 | - public function core_loaded_and_ready() |
|
910 | - { |
|
911 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
912 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
913 | - $this->registry->load_core('Session'); |
|
914 | - // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * initialize |
|
921 | - * this is the best place to begin initializing client code |
|
922 | - * |
|
923 | - * @access public |
|
924 | - * @return void |
|
925 | - */ |
|
926 | - public function initialize() |
|
927 | - { |
|
928 | - do_action('AHEE__EE_System__initialize'); |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * initialize_last |
|
935 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
936 | - * initialize has done so |
|
937 | - * |
|
938 | - * @access public |
|
939 | - * @return void |
|
940 | - */ |
|
941 | - public function initialize_last() |
|
942 | - { |
|
943 | - do_action('AHEE__EE_System__initialize_last'); |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * set_hooks_for_shortcodes_modules_and_addons |
|
950 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
951 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
952 | - * |
|
953 | - * @access public |
|
954 | - * @return void |
|
955 | - */ |
|
956 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
957 | - { |
|
958 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - |
|
963 | - /** |
|
964 | - * do_not_cache |
|
965 | - * sets no cache headers and defines no cache constants for WP plugins |
|
966 | - * |
|
967 | - * @access public |
|
968 | - * @return void |
|
969 | - */ |
|
970 | - public static function do_not_cache() |
|
971 | - { |
|
972 | - // set no cache constants |
|
973 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
974 | - define('DONOTCACHEPAGE', true); |
|
975 | - } |
|
976 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
977 | - define('DONOTCACHCEOBJECT', true); |
|
978 | - } |
|
979 | - if ( ! defined('DONOTCACHEDB')) { |
|
980 | - define('DONOTCACHEDB', true); |
|
981 | - } |
|
982 | - // add no cache headers |
|
983 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
984 | - // plus a little extra for nginx and Google Chrome |
|
985 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
986 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
987 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - |
|
992 | - /** |
|
993 | - * extra_nocache_headers |
|
994 | - * |
|
995 | - * @access public |
|
996 | - * @param $headers |
|
997 | - * @return array |
|
998 | - */ |
|
999 | - public static function extra_nocache_headers($headers) |
|
1000 | - { |
|
1001 | - // for NGINX |
|
1002 | - $headers['X-Accel-Expires'] = 0; |
|
1003 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1004 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1005 | - return $headers; |
|
1006 | - } |
|
1007 | - |
|
1008 | - |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * nocache_headers |
|
1012 | - * |
|
1013 | - * @access public |
|
1014 | - * @return void |
|
1015 | - */ |
|
1016 | - public static function nocache_headers() |
|
1017 | - { |
|
1018 | - nocache_headers(); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * espresso_toolbar_items |
|
1025 | - * |
|
1026 | - * @access public |
|
1027 | - * @param WP_Admin_Bar $admin_bar |
|
1028 | - * @return void |
|
1029 | - */ |
|
1030 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1031 | - { |
|
1032 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1033 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1034 | - || defined('DOING_AJAX') |
|
1035 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1036 | - ) { |
|
1037 | - return; |
|
1038 | - } |
|
1039 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1040 | - $menu_class = 'espresso_menu_item_class'; |
|
1041 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1042 | - //because they're only defined in each of their respective constructors |
|
1043 | - //and this might be a frontend request, in which case they aren't available |
|
1044 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1045 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1046 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1047 | - //Top Level |
|
1048 | - $admin_bar->add_menu(array( |
|
1049 | - 'id' => 'espresso-toolbar', |
|
1050 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1051 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1052 | - . '</span>', |
|
1053 | - 'href' => $events_admin_url, |
|
1054 | - 'meta' => array( |
|
1055 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1056 | - 'class' => $menu_class . 'first', |
|
1057 | - ), |
|
1058 | - )); |
|
1059 | - //Events |
|
1060 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1061 | - $admin_bar->add_menu(array( |
|
1062 | - 'id' => 'espresso-toolbar-events', |
|
1063 | - 'parent' => 'espresso-toolbar', |
|
1064 | - 'title' => __('Events', 'event_espresso'), |
|
1065 | - 'href' => $events_admin_url, |
|
1066 | - 'meta' => array( |
|
1067 | - 'title' => __('Events', 'event_espresso'), |
|
1068 | - 'target' => '', |
|
1069 | - 'class' => $menu_class, |
|
1070 | - ), |
|
1071 | - )); |
|
1072 | - } |
|
1073 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1074 | - //Events Add New |
|
1075 | - $admin_bar->add_menu(array( |
|
1076 | - 'id' => 'espresso-toolbar-events-new', |
|
1077 | - 'parent' => 'espresso-toolbar-events', |
|
1078 | - 'title' => __('Add New', 'event_espresso'), |
|
1079 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1080 | - 'meta' => array( |
|
1081 | - 'title' => __('Add New', 'event_espresso'), |
|
1082 | - 'target' => '', |
|
1083 | - 'class' => $menu_class, |
|
1084 | - ), |
|
1085 | - )); |
|
1086 | - } |
|
1087 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1088 | - //Current post |
|
1089 | - global $post; |
|
1090 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1091 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1092 | - ) { |
|
1093 | - //Events Edit Current Event |
|
1094 | - $admin_bar->add_menu(array( |
|
1095 | - 'id' => 'espresso-toolbar-events-edit', |
|
1096 | - 'parent' => 'espresso-toolbar-events', |
|
1097 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1098 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1099 | - $events_admin_url), |
|
1100 | - 'meta' => array( |
|
1101 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1102 | - 'target' => '', |
|
1103 | - 'class' => $menu_class, |
|
1104 | - ), |
|
1105 | - )); |
|
1106 | - } |
|
1107 | - } |
|
1108 | - //Events View |
|
1109 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1110 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1111 | - ) { |
|
1112 | - $admin_bar->add_menu(array( |
|
1113 | - 'id' => 'espresso-toolbar-events-view', |
|
1114 | - 'parent' => 'espresso-toolbar-events', |
|
1115 | - 'title' => __('View', 'event_espresso'), |
|
1116 | - 'href' => $events_admin_url, |
|
1117 | - 'meta' => array( |
|
1118 | - 'title' => __('View', 'event_espresso'), |
|
1119 | - 'target' => '', |
|
1120 | - 'class' => $menu_class, |
|
1121 | - ), |
|
1122 | - )); |
|
1123 | - } |
|
1124 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1125 | - //Events View All |
|
1126 | - $admin_bar->add_menu(array( |
|
1127 | - 'id' => 'espresso-toolbar-events-all', |
|
1128 | - 'parent' => 'espresso-toolbar-events-view', |
|
1129 | - 'title' => __('All', 'event_espresso'), |
|
1130 | - 'href' => $events_admin_url, |
|
1131 | - 'meta' => array( |
|
1132 | - 'title' => __('All', 'event_espresso'), |
|
1133 | - 'target' => '', |
|
1134 | - 'class' => $menu_class, |
|
1135 | - ), |
|
1136 | - )); |
|
1137 | - } |
|
1138 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1139 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1140 | - ) { |
|
1141 | - //Events View Today |
|
1142 | - $admin_bar->add_menu(array( |
|
1143 | - 'id' => 'espresso-toolbar-events-today', |
|
1144 | - 'parent' => 'espresso-toolbar-events-view', |
|
1145 | - 'title' => __('Today', 'event_espresso'), |
|
1146 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1147 | - $events_admin_url), |
|
1148 | - 'meta' => array( |
|
1149 | - 'title' => __('Today', 'event_espresso'), |
|
1150 | - 'target' => '', |
|
1151 | - 'class' => $menu_class, |
|
1152 | - ), |
|
1153 | - )); |
|
1154 | - } |
|
1155 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1156 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1157 | - ) { |
|
1158 | - //Events View This Month |
|
1159 | - $admin_bar->add_menu(array( |
|
1160 | - 'id' => 'espresso-toolbar-events-month', |
|
1161 | - 'parent' => 'espresso-toolbar-events-view', |
|
1162 | - 'title' => __('This Month', 'event_espresso'), |
|
1163 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1164 | - $events_admin_url), |
|
1165 | - 'meta' => array( |
|
1166 | - 'title' => __('This Month', 'event_espresso'), |
|
1167 | - 'target' => '', |
|
1168 | - 'class' => $menu_class, |
|
1169 | - ), |
|
1170 | - )); |
|
1171 | - } |
|
1172 | - //Registration Overview |
|
1173 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1174 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1175 | - ) { |
|
1176 | - $admin_bar->add_menu(array( |
|
1177 | - 'id' => 'espresso-toolbar-registrations', |
|
1178 | - 'parent' => 'espresso-toolbar', |
|
1179 | - 'title' => __('Registrations', 'event_espresso'), |
|
1180 | - 'href' => $reg_admin_url, |
|
1181 | - 'meta' => array( |
|
1182 | - 'title' => __('Registrations', 'event_espresso'), |
|
1183 | - 'target' => '', |
|
1184 | - 'class' => $menu_class, |
|
1185 | - ), |
|
1186 | - )); |
|
1187 | - } |
|
1188 | - //Registration Overview Today |
|
1189 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1190 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1191 | - ) { |
|
1192 | - $admin_bar->add_menu(array( |
|
1193 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1194 | - 'parent' => 'espresso-toolbar-registrations', |
|
1195 | - 'title' => __('Today', 'event_espresso'), |
|
1196 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1197 | - $reg_admin_url), |
|
1198 | - 'meta' => array( |
|
1199 | - 'title' => __('Today', 'event_espresso'), |
|
1200 | - 'target' => '', |
|
1201 | - 'class' => $menu_class, |
|
1202 | - ), |
|
1203 | - )); |
|
1204 | - } |
|
1205 | - //Registration Overview Today Completed |
|
1206 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1207 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1208 | - ) { |
|
1209 | - $admin_bar->add_menu(array( |
|
1210 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1211 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1212 | - 'title' => __('Approved', 'event_espresso'), |
|
1213 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1214 | - 'action' => 'default', |
|
1215 | - 'status' => 'today', |
|
1216 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1217 | - ), $reg_admin_url), |
|
1218 | - 'meta' => array( |
|
1219 | - 'title' => __('Approved', 'event_espresso'), |
|
1220 | - 'target' => '', |
|
1221 | - 'class' => $menu_class, |
|
1222 | - ), |
|
1223 | - )); |
|
1224 | - } |
|
1225 | - //Registration Overview Today Pending\ |
|
1226 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1227 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1228 | - ) { |
|
1229 | - $admin_bar->add_menu(array( |
|
1230 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1231 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1232 | - 'title' => __('Pending', 'event_espresso'), |
|
1233 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1234 | - 'action' => 'default', |
|
1235 | - 'status' => 'today', |
|
1236 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1237 | - ), $reg_admin_url), |
|
1238 | - 'meta' => array( |
|
1239 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1240 | - 'target' => '', |
|
1241 | - 'class' => $menu_class, |
|
1242 | - ), |
|
1243 | - )); |
|
1244 | - } |
|
1245 | - //Registration Overview Today Incomplete |
|
1246 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1247 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1248 | - ) { |
|
1249 | - $admin_bar->add_menu(array( |
|
1250 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1251 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1252 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1253 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1254 | - 'action' => 'default', |
|
1255 | - 'status' => 'today', |
|
1256 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1257 | - ), $reg_admin_url), |
|
1258 | - 'meta' => array( |
|
1259 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1260 | - 'target' => '', |
|
1261 | - 'class' => $menu_class, |
|
1262 | - ), |
|
1263 | - )); |
|
1264 | - } |
|
1265 | - //Registration Overview Today Incomplete |
|
1266 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1267 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1268 | - ) { |
|
1269 | - $admin_bar->add_menu(array( |
|
1270 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1271 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1272 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1273 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1274 | - 'action' => 'default', |
|
1275 | - 'status' => 'today', |
|
1276 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1277 | - ), $reg_admin_url), |
|
1278 | - 'meta' => array( |
|
1279 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1280 | - 'target' => '', |
|
1281 | - 'class' => $menu_class, |
|
1282 | - ), |
|
1283 | - )); |
|
1284 | - } |
|
1285 | - //Registration Overview This Month |
|
1286 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1287 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1288 | - ) { |
|
1289 | - $admin_bar->add_menu(array( |
|
1290 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1291 | - 'parent' => 'espresso-toolbar-registrations', |
|
1292 | - 'title' => __('This Month', 'event_espresso'), |
|
1293 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1294 | - $reg_admin_url), |
|
1295 | - 'meta' => array( |
|
1296 | - 'title' => __('This Month', 'event_espresso'), |
|
1297 | - 'target' => '', |
|
1298 | - 'class' => $menu_class, |
|
1299 | - ), |
|
1300 | - )); |
|
1301 | - } |
|
1302 | - //Registration Overview This Month Approved |
|
1303 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1304 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1305 | - ) { |
|
1306 | - $admin_bar->add_menu(array( |
|
1307 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1308 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1309 | - 'title' => __('Approved', 'event_espresso'), |
|
1310 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1311 | - 'action' => 'default', |
|
1312 | - 'status' => 'month', |
|
1313 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1314 | - ), $reg_admin_url), |
|
1315 | - 'meta' => array( |
|
1316 | - 'title' => __('Approved', 'event_espresso'), |
|
1317 | - 'target' => '', |
|
1318 | - 'class' => $menu_class, |
|
1319 | - ), |
|
1320 | - )); |
|
1321 | - } |
|
1322 | - //Registration Overview This Month Pending |
|
1323 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1324 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1325 | - ) { |
|
1326 | - $admin_bar->add_menu(array( |
|
1327 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1328 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1329 | - 'title' => __('Pending', 'event_espresso'), |
|
1330 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1331 | - 'action' => 'default', |
|
1332 | - 'status' => 'month', |
|
1333 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1334 | - ), $reg_admin_url), |
|
1335 | - 'meta' => array( |
|
1336 | - 'title' => __('Pending', 'event_espresso'), |
|
1337 | - 'target' => '', |
|
1338 | - 'class' => $menu_class, |
|
1339 | - ), |
|
1340 | - )); |
|
1341 | - } |
|
1342 | - //Registration Overview This Month Not Approved |
|
1343 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1344 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1345 | - ) { |
|
1346 | - $admin_bar->add_menu(array( |
|
1347 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1348 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1349 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1350 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1351 | - 'action' => 'default', |
|
1352 | - 'status' => 'month', |
|
1353 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1354 | - ), $reg_admin_url), |
|
1355 | - 'meta' => array( |
|
1356 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1357 | - 'target' => '', |
|
1358 | - 'class' => $menu_class, |
|
1359 | - ), |
|
1360 | - )); |
|
1361 | - } |
|
1362 | - //Registration Overview This Month Cancelled |
|
1363 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1364 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1365 | - ) { |
|
1366 | - $admin_bar->add_menu(array( |
|
1367 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1368 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1369 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1370 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1371 | - 'action' => 'default', |
|
1372 | - 'status' => 'month', |
|
1373 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1374 | - ), $reg_admin_url), |
|
1375 | - 'meta' => array( |
|
1376 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1377 | - 'target' => '', |
|
1378 | - 'class' => $menu_class, |
|
1379 | - ), |
|
1380 | - )); |
|
1381 | - } |
|
1382 | - //Extensions & Services |
|
1383 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1384 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1385 | - ) { |
|
1386 | - $admin_bar->add_menu(array( |
|
1387 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1388 | - 'parent' => 'espresso-toolbar', |
|
1389 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1390 | - 'href' => $extensions_admin_url, |
|
1391 | - 'meta' => array( |
|
1392 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | - 'target' => '', |
|
1394 | - 'class' => $menu_class, |
|
1395 | - ), |
|
1396 | - )); |
|
1397 | - } |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1404 | - * never returned with the function. |
|
1405 | - * |
|
1406 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1407 | - * @return array |
|
1408 | - */ |
|
1409 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1410 | - { |
|
1411 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1412 | - } |
|
1413 | - |
|
1414 | - |
|
1415 | - |
|
1416 | - |
|
1417 | - |
|
1418 | - |
|
1419 | - /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
1420 | - /** |
|
1421 | - * wp_enqueue_scripts |
|
1422 | - * |
|
1423 | - * @access public |
|
1424 | - * @return void |
|
1425 | - */ |
|
1426 | - public function wp_enqueue_scripts() |
|
1427 | - { |
|
1428 | - // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
1429 | - if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
1430 | - // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
1431 | - if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
1432 | - // register jQuery Validate and additional methods |
|
1433 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
1434 | - array('jquery'), '1.15.0', true); |
|
1435 | - wp_register_script('jquery-validate-extra-methods', |
|
1436 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
1437 | - array('jquery', 'jquery-validate'), '1.15.0', true); |
|
1438 | - } |
|
1439 | - } |
|
1440 | - } |
|
19 | + /** |
|
20 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
21 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
22 | + */ |
|
23 | + const req_type_normal = 0; |
|
24 | + |
|
25 | + /** |
|
26 | + * Indicates this is a brand new installation of EE so we should install |
|
27 | + * tables and default data etc |
|
28 | + */ |
|
29 | + const req_type_new_activation = 1; |
|
30 | + |
|
31 | + /** |
|
32 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
33 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
34 | + * and that default data is setup too |
|
35 | + */ |
|
36 | + const req_type_reactivation = 2; |
|
37 | + |
|
38 | + /** |
|
39 | + * indicates that EE has been upgraded since its previous request. |
|
40 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
41 | + */ |
|
42 | + const req_type_upgrade = 3; |
|
43 | + |
|
44 | + /** |
|
45 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
46 | + */ |
|
47 | + const req_type_downgrade = 4; |
|
48 | + |
|
49 | + /** |
|
50 | + * @deprecated since version 4.6.0.dev.006 |
|
51 | + * Now whenever a new_activation is detected the request type is still just |
|
52 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
53 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
54 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
55 | + * (Specifically, when the migration manager indicates migrations are finished |
|
56 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
57 | + */ |
|
58 | + const req_type_activation_but_not_installed = 5; |
|
59 | + |
|
60 | + /** |
|
61 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
62 | + */ |
|
63 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * instance of the EE_System object |
|
68 | + * |
|
69 | + * @var $_instance |
|
70 | + * @access private |
|
71 | + */ |
|
72 | + private static $_instance = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type EE_Registry $Registry |
|
76 | + * @access protected |
|
77 | + */ |
|
78 | + protected $registry; |
|
79 | + |
|
80 | + /** |
|
81 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
82 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
83 | + * |
|
84 | + * @var int |
|
85 | + */ |
|
86 | + private $_req_type; |
|
87 | + |
|
88 | + /** |
|
89 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
90 | + * |
|
91 | + * @var boolean |
|
92 | + */ |
|
93 | + private $_major_version_change = false; |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @singleton method used to instantiate class object |
|
99 | + * @access public |
|
100 | + * @param \EE_Registry $Registry |
|
101 | + * @return \EE_System |
|
102 | + */ |
|
103 | + public static function instance(EE_Registry $Registry = null) |
|
104 | + { |
|
105 | + // check if class object is instantiated |
|
106 | + if ( ! self::$_instance instanceof EE_System) { |
|
107 | + self::$_instance = new self($Registry); |
|
108 | + } |
|
109 | + return self::$_instance; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * resets the instance and returns it |
|
116 | + * |
|
117 | + * @return EE_System |
|
118 | + */ |
|
119 | + public static function reset() |
|
120 | + { |
|
121 | + self::$_instance->_req_type = null; |
|
122 | + //make sure none of the old hooks are left hanging around |
|
123 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
124 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
125 | + EE_Data_Migration_Manager::reset(); |
|
126 | + self::instance()->detect_activations_or_upgrades(); |
|
127 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
128 | + return self::instance(); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * sets hooks for running rest of system |
|
135 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
136 | + * starting EE Addons from any other point may lead to problems |
|
137 | + * |
|
138 | + * @access private |
|
139 | + * @param \EE_Registry $Registry |
|
140 | + */ |
|
141 | + private function __construct(EE_Registry $Registry) |
|
142 | + { |
|
143 | + $this->registry = $Registry; |
|
144 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
145 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
146 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
147 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
148 | + // because the newly-activated addon didn't get a chance to run at all |
|
149 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
150 | + // detect whether install or upgrade |
|
151 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
152 | + 3); |
|
153 | + // load EE_Config, EE_Textdomain, etc |
|
154 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
155 | + // load EE_Config, EE_Textdomain, etc |
|
156 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
157 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
158 | + // you wanna get going? I wanna get going... let's get going! |
|
159 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
160 | + //other housekeeping |
|
161 | + //exclude EE critical pages from wp_list_pages |
|
162 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
163 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
164 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
165 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * load_espresso_addons |
|
172 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
173 | + * this is hooked into both: |
|
174 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
175 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
176 | + * and the WP 'activate_plugin' hookpoint |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + public function load_espresso_addons() |
|
182 | + { |
|
183 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
184 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
185 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
186 | + //load and setup EE_Capabilities |
|
187 | + $this->registry->load_core('Capabilities'); |
|
188 | + //caps need to be initialized on every request so that capability maps are set. |
|
189 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
190 | + $this->registry->CAP->init_caps(); |
|
191 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
192 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
193 | + //We want it for mobile apps. Just include the entire plugin |
|
194 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
195 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
196 | + //and causes a fatal error |
|
197 | + if ( ! function_exists('json_basic_auth_handler') |
|
198 | + && ! function_exists('json_basic_auth_error') |
|
199 | + && ! ( |
|
200 | + isset($_GET['action']) |
|
201 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
202 | + ) |
|
203 | + && ! ( |
|
204 | + isset($_GET['activate']) |
|
205 | + && $_GET['activate'] === 'true' |
|
206 | + ) |
|
207 | + ) { |
|
208 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
209 | + } |
|
210 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * detect_activations_or_upgrades |
|
217 | + * Checks for activation or upgrade of core first; |
|
218 | + * then also checks if any registered addons have been activated or upgraded |
|
219 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
220 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return void |
|
224 | + */ |
|
225 | + public function detect_activations_or_upgrades() |
|
226 | + { |
|
227 | + //first off: let's make sure to handle core |
|
228 | + $this->detect_if_activation_or_upgrade(); |
|
229 | + foreach ($this->registry->addons as $addon) { |
|
230 | + //detect teh request type for that addon |
|
231 | + $addon->detect_activation_or_upgrade(); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * detect_if_activation_or_upgrade |
|
239 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
240 | + * and either setting up the DB or setting up maintenance mode etc. |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + public function detect_if_activation_or_upgrade() |
|
246 | + { |
|
247 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
248 | + // load M-Mode class |
|
249 | + $this->registry->load_core('Maintenance_Mode'); |
|
250 | + // check if db has been updated, or if its a brand-new installation |
|
251 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
252 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
253 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
254 | + switch ($request_type) { |
|
255 | + case EE_System::req_type_new_activation: |
|
256 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
257 | + $this->_handle_core_version_change($espresso_db_update); |
|
258 | + break; |
|
259 | + case EE_System::req_type_reactivation: |
|
260 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
261 | + $this->_handle_core_version_change($espresso_db_update); |
|
262 | + break; |
|
263 | + case EE_System::req_type_upgrade: |
|
264 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
265 | + //migrations may be required now that we've upgraded |
|
266 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
267 | + $this->_handle_core_version_change($espresso_db_update); |
|
268 | + // echo "done upgrade";die; |
|
269 | + break; |
|
270 | + case EE_System::req_type_downgrade: |
|
271 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
272 | + //its possible migrations are no longer required |
|
273 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
274 | + $this->_handle_core_version_change($espresso_db_update); |
|
275 | + break; |
|
276 | + case EE_System::req_type_normal: |
|
277 | + default: |
|
278 | + // $this->_maybe_redirect_to_ee_about(); |
|
279 | + break; |
|
280 | + } |
|
281 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Updates the list of installed versions and sets hooks for |
|
288 | + * initializing the database later during the request |
|
289 | + * |
|
290 | + * @param array $espresso_db_update |
|
291 | + */ |
|
292 | + protected function _handle_core_version_change($espresso_db_update) |
|
293 | + { |
|
294 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
295 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
296 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
297 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
304 | + * information about what versions of EE have been installed and activated, |
|
305 | + * NOT necessarily the state of the database |
|
306 | + * |
|
307 | + * @param null $espresso_db_update |
|
308 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
309 | + * from the options table |
|
310 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
311 | + */ |
|
312 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
313 | + { |
|
314 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
315 | + if ( ! $espresso_db_update) { |
|
316 | + $espresso_db_update = get_option('espresso_db_update'); |
|
317 | + } |
|
318 | + // check that option is an array |
|
319 | + if ( ! is_array($espresso_db_update)) { |
|
320 | + // if option is FALSE, then it never existed |
|
321 | + if ($espresso_db_update === false) { |
|
322 | + // make $espresso_db_update an array and save option with autoload OFF |
|
323 | + $espresso_db_update = array(); |
|
324 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
325 | + } else { |
|
326 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
327 | + $espresso_db_update = array($espresso_db_update => array()); |
|
328 | + update_option('espresso_db_update', $espresso_db_update); |
|
329 | + } |
|
330 | + } else { |
|
331 | + $corrected_db_update = array(); |
|
332 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
333 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
334 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
335 | + //the key is an int, and the value IS NOT an array |
|
336 | + //so it must be numerically-indexed, where values are versions installed... |
|
337 | + //fix it! |
|
338 | + $version_string = $should_be_array; |
|
339 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
340 | + } else { |
|
341 | + //ok it checks out |
|
342 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
343 | + } |
|
344 | + } |
|
345 | + $espresso_db_update = $corrected_db_update; |
|
346 | + update_option('espresso_db_update', $espresso_db_update); |
|
347 | + } |
|
348 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
349 | + return $espresso_db_update; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
356 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
357 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
358 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
359 | + * so that it will be done when migrations are finished |
|
360 | + * |
|
361 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
362 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
363 | + * This is a resource-intensive job |
|
364 | + * so we prefer to only do it when necessary |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
368 | + { |
|
369 | + $request_type = $this->detect_req_type(); |
|
370 | + //only initialize system if we're not in maintenance mode. |
|
371 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
372 | + update_option('ee_flush_rewrite_rules', true); |
|
373 | + if ($verify_schema) { |
|
374 | + EEH_Activation::initialize_db_and_folders(); |
|
375 | + } |
|
376 | + EEH_Activation::initialize_db_content(); |
|
377 | + EEH_Activation::system_initialization(); |
|
378 | + if ($initialize_addons_too) { |
|
379 | + $this->initialize_addons(); |
|
380 | + } |
|
381 | + } else { |
|
382 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
383 | + } |
|
384 | + if ($request_type === EE_System::req_type_new_activation |
|
385 | + || $request_type === EE_System::req_type_reactivation |
|
386 | + || ( |
|
387 | + $request_type === EE_System::req_type_upgrade |
|
388 | + && $this->is_major_version_change() |
|
389 | + ) |
|
390 | + ) { |
|
391 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * Initializes the db for all registered addons |
|
399 | + */ |
|
400 | + public function initialize_addons() |
|
401 | + { |
|
402 | + //foreach registered addon, make sure its db is up-to-date too |
|
403 | + foreach ($this->registry->addons as $addon) { |
|
404 | + $addon->initialize_db_if_no_migrations_required(); |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
412 | + * |
|
413 | + * @param array $version_history |
|
414 | + * @param string $current_version_to_add version to be added to the version history |
|
415 | + * @return boolean success as to whether or not this option was changed |
|
416 | + */ |
|
417 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
418 | + { |
|
419 | + if ( ! $version_history) { |
|
420 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
421 | + } |
|
422 | + if ($current_version_to_add == null) { |
|
423 | + $current_version_to_add = espresso_version(); |
|
424 | + } |
|
425 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
426 | + // re-save |
|
427 | + return update_option('espresso_db_update', $version_history); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * Detects if the current version indicated in the has existed in the list of |
|
434 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
435 | + * |
|
436 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
437 | + * If not supplied, fetches it from the options table. |
|
438 | + * Also, caches its result so later parts of the code can also know whether |
|
439 | + * there's been an update or not. This way we can add the current version to |
|
440 | + * espresso_db_update, but still know if this is a new install or not |
|
441 | + * @return int one of the constants on EE_System::req_type_ |
|
442 | + */ |
|
443 | + public function detect_req_type($espresso_db_update = null) |
|
444 | + { |
|
445 | + if ($this->_req_type === null) { |
|
446 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
447 | + : $this->fix_espresso_db_upgrade_option(); |
|
448 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
449 | + 'ee_espresso_activation', espresso_version()); |
|
450 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
451 | + } |
|
452 | + return $this->_req_type; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
459 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
460 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
461 | + * |
|
462 | + * @param $activation_history |
|
463 | + * @return bool |
|
464 | + */ |
|
465 | + protected function _detect_major_version_change($activation_history) |
|
466 | + { |
|
467 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
468 | + $previous_version_parts = explode('.', $previous_version); |
|
469 | + $current_version_parts = explode('.', espresso_version()); |
|
470 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
471 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
472 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
473 | + ); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * Returns true if either the major or minor version of EE changed during this request. |
|
480 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
481 | + * |
|
482 | + * @return bool |
|
483 | + */ |
|
484 | + public function is_major_version_change() |
|
485 | + { |
|
486 | + return $this->_major_version_change; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
493 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
494 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
495 | + * just activated to (for core that will always be espresso_version()) |
|
496 | + * |
|
497 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
498 | + * ee plugin. for core that's 'espresso_db_update' |
|
499 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
500 | + * indicate that this plugin was just activated |
|
501 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
502 | + * espresso_version()) |
|
503 | + * @return int one of the constants on EE_System::req_type_* |
|
504 | + */ |
|
505 | + public static function detect_req_type_given_activation_history( |
|
506 | + $activation_history_for_addon, |
|
507 | + $activation_indicator_option_name, |
|
508 | + $version_to_upgrade_to |
|
509 | + ) { |
|
510 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
511 | + if ($activation_history_for_addon) { |
|
512 | + //it exists, so this isn't a completely new install |
|
513 | + //check if this version already in that list of previously installed versions |
|
514 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
515 | + //it a version we haven't seen before |
|
516 | + if ($version_is_higher === 1) { |
|
517 | + $req_type = EE_System::req_type_upgrade; |
|
518 | + } else { |
|
519 | + $req_type = EE_System::req_type_downgrade; |
|
520 | + } |
|
521 | + delete_option($activation_indicator_option_name); |
|
522 | + } else { |
|
523 | + // its not an update. maybe a reactivation? |
|
524 | + if (get_option($activation_indicator_option_name, false)) { |
|
525 | + if ($version_is_higher === -1) { |
|
526 | + $req_type = EE_System::req_type_downgrade; |
|
527 | + } elseif ($version_is_higher === 0) { |
|
528 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
529 | + $req_type = EE_System::req_type_reactivation; |
|
530 | + } else {//$version_is_higher === 1 |
|
531 | + $req_type = EE_System::req_type_upgrade; |
|
532 | + } |
|
533 | + delete_option($activation_indicator_option_name); |
|
534 | + } else { |
|
535 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
536 | + if ($version_is_higher === -1) { |
|
537 | + $req_type = EE_System::req_type_downgrade; |
|
538 | + } elseif ($version_is_higher === 0) { |
|
539 | + //we've seen this version before and it's not an activation. its normal request |
|
540 | + $req_type = EE_System::req_type_normal; |
|
541 | + } else {//$version_is_higher === 1 |
|
542 | + $req_type = EE_System::req_type_upgrade; |
|
543 | + } |
|
544 | + } |
|
545 | + } |
|
546 | + } else { |
|
547 | + //brand new install |
|
548 | + $req_type = EE_System::req_type_new_activation; |
|
549 | + delete_option($activation_indicator_option_name); |
|
550 | + } |
|
551 | + return $req_type; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
558 | + * the $activation_history_for_addon |
|
559 | + * |
|
560 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
561 | + * sometimes containing 'unknown-date' |
|
562 | + * @param string $version_to_upgrade_to (current version) |
|
563 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
564 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
565 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
566 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
567 | + */ |
|
568 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
569 | + { |
|
570 | + //find the most recently-activated version |
|
571 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
572 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Gets the most recently active version listed in the activation history, |
|
579 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
580 | + * |
|
581 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
582 | + * sometimes containing 'unknown-date' |
|
583 | + * @return string |
|
584 | + */ |
|
585 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
586 | + { |
|
587 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
588 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
589 | + if (is_array($activation_history)) { |
|
590 | + foreach ($activation_history as $version => $times_activated) { |
|
591 | + //check there is a record of when this version was activated. Otherwise, |
|
592 | + //mark it as unknown |
|
593 | + if ( ! $times_activated) { |
|
594 | + $times_activated = array('unknown-date'); |
|
595 | + } |
|
596 | + if (is_string($times_activated)) { |
|
597 | + $times_activated = array($times_activated); |
|
598 | + } |
|
599 | + foreach ($times_activated as $an_activation) { |
|
600 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
601 | + $most_recently_active_version = $version; |
|
602 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
603 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
604 | + } |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + return $most_recently_active_version; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * This redirects to the about EE page after activation |
|
615 | + * |
|
616 | + * @return void |
|
617 | + */ |
|
618 | + public function redirect_to_about_ee() |
|
619 | + { |
|
620 | + $notices = EE_Error::get_notices(false); |
|
621 | + //if current user is an admin and it's not an ajax or rest request |
|
622 | + if ( |
|
623 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
624 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
625 | + && ! isset($notices['errors']) |
|
626 | + && apply_filters( |
|
627 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
628 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
629 | + ) |
|
630 | + ) { |
|
631 | + $query_params = array('page' => 'espresso_about'); |
|
632 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
633 | + $query_params['new_activation'] = true; |
|
634 | + } |
|
635 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
636 | + $query_params['reactivation'] = true; |
|
637 | + } |
|
638 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
639 | + wp_safe_redirect($url); |
|
640 | + exit(); |
|
641 | + } |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * load_core_configuration |
|
648 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
649 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
650 | + * |
|
651 | + * @return void |
|
652 | + */ |
|
653 | + public function load_core_configuration() |
|
654 | + { |
|
655 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
656 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
657 | + //load textdomain |
|
658 | + EE_Load_Textdomain::load_textdomain(); |
|
659 | + // load and setup EE_Config and EE_Network_Config |
|
660 | + $this->registry->load_core('Config'); |
|
661 | + $this->registry->load_core('Network_Config'); |
|
662 | + // setup autoloaders |
|
663 | + // enable logging? |
|
664 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
665 | + $this->registry->load_core('Log'); |
|
666 | + } |
|
667 | + // check for activation errors |
|
668 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
669 | + if ($activation_errors) { |
|
670 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
671 | + update_option('ee_plugin_activation_errors', false); |
|
672 | + } |
|
673 | + // get model names |
|
674 | + $this->_parse_model_names(); |
|
675 | + //load caf stuff a chance to play during the activation process too. |
|
676 | + $this->_maybe_brew_regular(); |
|
677 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
684 | + * |
|
685 | + * @return void |
|
686 | + */ |
|
687 | + private function _parse_model_names() |
|
688 | + { |
|
689 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
690 | + $models = glob(EE_MODELS . '*.model.php'); |
|
691 | + $model_names = array(); |
|
692 | + $non_abstract_db_models = array(); |
|
693 | + foreach ($models as $model) { |
|
694 | + // get model classname |
|
695 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
696 | + $short_name = str_replace('EEM_', '', $classname); |
|
697 | + $reflectionClass = new ReflectionClass($classname); |
|
698 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
699 | + $non_abstract_db_models[$short_name] = $classname; |
|
700 | + } |
|
701 | + $model_names[$short_name] = $classname; |
|
702 | + } |
|
703 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
704 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
705 | + $non_abstract_db_models); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
712 | + * that need to be setup before our EE_System launches. |
|
713 | + * |
|
714 | + * @return void |
|
715 | + */ |
|
716 | + private function _maybe_brew_regular() |
|
717 | + { |
|
718 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
719 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
720 | + } |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * register_shortcodes_modules_and_widgets |
|
727 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
728 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
729 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
730 | + * |
|
731 | + * @access public |
|
732 | + * @return void |
|
733 | + */ |
|
734 | + public function register_shortcodes_modules_and_widgets() |
|
735 | + { |
|
736 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
737 | + // check for addons using old hookpoint |
|
738 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
739 | + $this->_incompatible_addon_error(); |
|
740 | + } |
|
741 | + } |
|
742 | + |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * _incompatible_addon_error |
|
747 | + * |
|
748 | + * @access public |
|
749 | + * @return void |
|
750 | + */ |
|
751 | + private function _incompatible_addon_error() |
|
752 | + { |
|
753 | + // get array of classes hooking into here |
|
754 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
755 | + if ( ! empty($class_names)) { |
|
756 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
757 | + 'event_espresso'); |
|
758 | + $msg .= '<ul>'; |
|
759 | + foreach ($class_names as $class_name) { |
|
760 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
761 | + $class_name) . '</b></li>'; |
|
762 | + } |
|
763 | + $msg .= '</ul>'; |
|
764 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
765 | + 'event_espresso'); |
|
766 | + // save list of incompatible addons to wp-options for later use |
|
767 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
768 | + if (is_admin()) { |
|
769 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + |
|
776 | + /** |
|
777 | + * brew_espresso |
|
778 | + * begins the process of setting hooks for initializing EE in the correct order |
|
779 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
780 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
781 | + * |
|
782 | + * @return void |
|
783 | + */ |
|
784 | + public function brew_espresso() |
|
785 | + { |
|
786 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
787 | + // load some final core systems |
|
788 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
789 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
790 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
791 | + add_action('init', array($this, 'load_controllers'), 7); |
|
792 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
793 | + add_action('init', array($this, 'initialize'), 10); |
|
794 | + add_action('init', array($this, 'initialize_last'), 100); |
|
795 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
796 | + add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
797 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
798 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
799 | + // pew pew pew |
|
800 | + $this->registry->load_core('PUE'); |
|
801 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
802 | + } |
|
803 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * set_hooks_for_core |
|
810 | + * |
|
811 | + * @access public |
|
812 | + * @return void |
|
813 | + */ |
|
814 | + public function set_hooks_for_core() |
|
815 | + { |
|
816 | + $this->_deactivate_incompatible_addons(); |
|
817 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
824 | + * deactivates any addons considered incompatible with the current version of EE |
|
825 | + */ |
|
826 | + private function _deactivate_incompatible_addons() |
|
827 | + { |
|
828 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
829 | + if ( ! empty($incompatible_addons)) { |
|
830 | + $active_plugins = get_option('active_plugins', array()); |
|
831 | + foreach ($active_plugins as $active_plugin) { |
|
832 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
833 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
834 | + unset($_GET['activate']); |
|
835 | + espresso_deactivate_plugin($active_plugin); |
|
836 | + } |
|
837 | + } |
|
838 | + } |
|
839 | + } |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * perform_activations_upgrades_and_migrations |
|
846 | + * |
|
847 | + * @access public |
|
848 | + * @return void |
|
849 | + */ |
|
850 | + public function perform_activations_upgrades_and_migrations() |
|
851 | + { |
|
852 | + //first check if we had previously attempted to setup EE's directories but failed |
|
853 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
854 | + EEH_Activation::create_upload_directories(); |
|
855 | + } |
|
856 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * load_CPTs_and_session |
|
863 | + * |
|
864 | + * @access public |
|
865 | + * @return void |
|
866 | + */ |
|
867 | + public function load_CPTs_and_session() |
|
868 | + { |
|
869 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
870 | + // register Custom Post Types |
|
871 | + $this->registry->load_core('Register_CPTs'); |
|
872 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + /** |
|
878 | + * load_controllers |
|
879 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
880 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
881 | + * time |
|
882 | + * |
|
883 | + * @access public |
|
884 | + * @return void |
|
885 | + */ |
|
886 | + public function load_controllers() |
|
887 | + { |
|
888 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
889 | + // let's get it started |
|
890 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
891 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
892 | + $this->registry->load_core('Front_Controller', array(), false, true); |
|
893 | + } else if ( ! EE_FRONT_AJAX) { |
|
894 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
895 | + EE_Registry::instance()->load_core('Admin'); |
|
896 | + } |
|
897 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * core_loaded_and_ready |
|
904 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
905 | + * |
|
906 | + * @access public |
|
907 | + * @return void |
|
908 | + */ |
|
909 | + public function core_loaded_and_ready() |
|
910 | + { |
|
911 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
912 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
913 | + $this->registry->load_core('Session'); |
|
914 | + // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * initialize |
|
921 | + * this is the best place to begin initializing client code |
|
922 | + * |
|
923 | + * @access public |
|
924 | + * @return void |
|
925 | + */ |
|
926 | + public function initialize() |
|
927 | + { |
|
928 | + do_action('AHEE__EE_System__initialize'); |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * initialize_last |
|
935 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
936 | + * initialize has done so |
|
937 | + * |
|
938 | + * @access public |
|
939 | + * @return void |
|
940 | + */ |
|
941 | + public function initialize_last() |
|
942 | + { |
|
943 | + do_action('AHEE__EE_System__initialize_last'); |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * set_hooks_for_shortcodes_modules_and_addons |
|
950 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
951 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
952 | + * |
|
953 | + * @access public |
|
954 | + * @return void |
|
955 | + */ |
|
956 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
957 | + { |
|
958 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + |
|
963 | + /** |
|
964 | + * do_not_cache |
|
965 | + * sets no cache headers and defines no cache constants for WP plugins |
|
966 | + * |
|
967 | + * @access public |
|
968 | + * @return void |
|
969 | + */ |
|
970 | + public static function do_not_cache() |
|
971 | + { |
|
972 | + // set no cache constants |
|
973 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
974 | + define('DONOTCACHEPAGE', true); |
|
975 | + } |
|
976 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
977 | + define('DONOTCACHCEOBJECT', true); |
|
978 | + } |
|
979 | + if ( ! defined('DONOTCACHEDB')) { |
|
980 | + define('DONOTCACHEDB', true); |
|
981 | + } |
|
982 | + // add no cache headers |
|
983 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
984 | + // plus a little extra for nginx and Google Chrome |
|
985 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
986 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
987 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + |
|
992 | + /** |
|
993 | + * extra_nocache_headers |
|
994 | + * |
|
995 | + * @access public |
|
996 | + * @param $headers |
|
997 | + * @return array |
|
998 | + */ |
|
999 | + public static function extra_nocache_headers($headers) |
|
1000 | + { |
|
1001 | + // for NGINX |
|
1002 | + $headers['X-Accel-Expires'] = 0; |
|
1003 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1004 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1005 | + return $headers; |
|
1006 | + } |
|
1007 | + |
|
1008 | + |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * nocache_headers |
|
1012 | + * |
|
1013 | + * @access public |
|
1014 | + * @return void |
|
1015 | + */ |
|
1016 | + public static function nocache_headers() |
|
1017 | + { |
|
1018 | + nocache_headers(); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * espresso_toolbar_items |
|
1025 | + * |
|
1026 | + * @access public |
|
1027 | + * @param WP_Admin_Bar $admin_bar |
|
1028 | + * @return void |
|
1029 | + */ |
|
1030 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1031 | + { |
|
1032 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1033 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1034 | + || defined('DOING_AJAX') |
|
1035 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1036 | + ) { |
|
1037 | + return; |
|
1038 | + } |
|
1039 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1040 | + $menu_class = 'espresso_menu_item_class'; |
|
1041 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1042 | + //because they're only defined in each of their respective constructors |
|
1043 | + //and this might be a frontend request, in which case they aren't available |
|
1044 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1045 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1046 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1047 | + //Top Level |
|
1048 | + $admin_bar->add_menu(array( |
|
1049 | + 'id' => 'espresso-toolbar', |
|
1050 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1051 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1052 | + . '</span>', |
|
1053 | + 'href' => $events_admin_url, |
|
1054 | + 'meta' => array( |
|
1055 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1056 | + 'class' => $menu_class . 'first', |
|
1057 | + ), |
|
1058 | + )); |
|
1059 | + //Events |
|
1060 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1061 | + $admin_bar->add_menu(array( |
|
1062 | + 'id' => 'espresso-toolbar-events', |
|
1063 | + 'parent' => 'espresso-toolbar', |
|
1064 | + 'title' => __('Events', 'event_espresso'), |
|
1065 | + 'href' => $events_admin_url, |
|
1066 | + 'meta' => array( |
|
1067 | + 'title' => __('Events', 'event_espresso'), |
|
1068 | + 'target' => '', |
|
1069 | + 'class' => $menu_class, |
|
1070 | + ), |
|
1071 | + )); |
|
1072 | + } |
|
1073 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1074 | + //Events Add New |
|
1075 | + $admin_bar->add_menu(array( |
|
1076 | + 'id' => 'espresso-toolbar-events-new', |
|
1077 | + 'parent' => 'espresso-toolbar-events', |
|
1078 | + 'title' => __('Add New', 'event_espresso'), |
|
1079 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1080 | + 'meta' => array( |
|
1081 | + 'title' => __('Add New', 'event_espresso'), |
|
1082 | + 'target' => '', |
|
1083 | + 'class' => $menu_class, |
|
1084 | + ), |
|
1085 | + )); |
|
1086 | + } |
|
1087 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1088 | + //Current post |
|
1089 | + global $post; |
|
1090 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1091 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1092 | + ) { |
|
1093 | + //Events Edit Current Event |
|
1094 | + $admin_bar->add_menu(array( |
|
1095 | + 'id' => 'espresso-toolbar-events-edit', |
|
1096 | + 'parent' => 'espresso-toolbar-events', |
|
1097 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1098 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1099 | + $events_admin_url), |
|
1100 | + 'meta' => array( |
|
1101 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1102 | + 'target' => '', |
|
1103 | + 'class' => $menu_class, |
|
1104 | + ), |
|
1105 | + )); |
|
1106 | + } |
|
1107 | + } |
|
1108 | + //Events View |
|
1109 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1110 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1111 | + ) { |
|
1112 | + $admin_bar->add_menu(array( |
|
1113 | + 'id' => 'espresso-toolbar-events-view', |
|
1114 | + 'parent' => 'espresso-toolbar-events', |
|
1115 | + 'title' => __('View', 'event_espresso'), |
|
1116 | + 'href' => $events_admin_url, |
|
1117 | + 'meta' => array( |
|
1118 | + 'title' => __('View', 'event_espresso'), |
|
1119 | + 'target' => '', |
|
1120 | + 'class' => $menu_class, |
|
1121 | + ), |
|
1122 | + )); |
|
1123 | + } |
|
1124 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1125 | + //Events View All |
|
1126 | + $admin_bar->add_menu(array( |
|
1127 | + 'id' => 'espresso-toolbar-events-all', |
|
1128 | + 'parent' => 'espresso-toolbar-events-view', |
|
1129 | + 'title' => __('All', 'event_espresso'), |
|
1130 | + 'href' => $events_admin_url, |
|
1131 | + 'meta' => array( |
|
1132 | + 'title' => __('All', 'event_espresso'), |
|
1133 | + 'target' => '', |
|
1134 | + 'class' => $menu_class, |
|
1135 | + ), |
|
1136 | + )); |
|
1137 | + } |
|
1138 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1139 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1140 | + ) { |
|
1141 | + //Events View Today |
|
1142 | + $admin_bar->add_menu(array( |
|
1143 | + 'id' => 'espresso-toolbar-events-today', |
|
1144 | + 'parent' => 'espresso-toolbar-events-view', |
|
1145 | + 'title' => __('Today', 'event_espresso'), |
|
1146 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1147 | + $events_admin_url), |
|
1148 | + 'meta' => array( |
|
1149 | + 'title' => __('Today', 'event_espresso'), |
|
1150 | + 'target' => '', |
|
1151 | + 'class' => $menu_class, |
|
1152 | + ), |
|
1153 | + )); |
|
1154 | + } |
|
1155 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1156 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1157 | + ) { |
|
1158 | + //Events View This Month |
|
1159 | + $admin_bar->add_menu(array( |
|
1160 | + 'id' => 'espresso-toolbar-events-month', |
|
1161 | + 'parent' => 'espresso-toolbar-events-view', |
|
1162 | + 'title' => __('This Month', 'event_espresso'), |
|
1163 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1164 | + $events_admin_url), |
|
1165 | + 'meta' => array( |
|
1166 | + 'title' => __('This Month', 'event_espresso'), |
|
1167 | + 'target' => '', |
|
1168 | + 'class' => $menu_class, |
|
1169 | + ), |
|
1170 | + )); |
|
1171 | + } |
|
1172 | + //Registration Overview |
|
1173 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1174 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1175 | + ) { |
|
1176 | + $admin_bar->add_menu(array( |
|
1177 | + 'id' => 'espresso-toolbar-registrations', |
|
1178 | + 'parent' => 'espresso-toolbar', |
|
1179 | + 'title' => __('Registrations', 'event_espresso'), |
|
1180 | + 'href' => $reg_admin_url, |
|
1181 | + 'meta' => array( |
|
1182 | + 'title' => __('Registrations', 'event_espresso'), |
|
1183 | + 'target' => '', |
|
1184 | + 'class' => $menu_class, |
|
1185 | + ), |
|
1186 | + )); |
|
1187 | + } |
|
1188 | + //Registration Overview Today |
|
1189 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1190 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1191 | + ) { |
|
1192 | + $admin_bar->add_menu(array( |
|
1193 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1194 | + 'parent' => 'espresso-toolbar-registrations', |
|
1195 | + 'title' => __('Today', 'event_espresso'), |
|
1196 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1197 | + $reg_admin_url), |
|
1198 | + 'meta' => array( |
|
1199 | + 'title' => __('Today', 'event_espresso'), |
|
1200 | + 'target' => '', |
|
1201 | + 'class' => $menu_class, |
|
1202 | + ), |
|
1203 | + )); |
|
1204 | + } |
|
1205 | + //Registration Overview Today Completed |
|
1206 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1207 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1208 | + ) { |
|
1209 | + $admin_bar->add_menu(array( |
|
1210 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1211 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1212 | + 'title' => __('Approved', 'event_espresso'), |
|
1213 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1214 | + 'action' => 'default', |
|
1215 | + 'status' => 'today', |
|
1216 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1217 | + ), $reg_admin_url), |
|
1218 | + 'meta' => array( |
|
1219 | + 'title' => __('Approved', 'event_espresso'), |
|
1220 | + 'target' => '', |
|
1221 | + 'class' => $menu_class, |
|
1222 | + ), |
|
1223 | + )); |
|
1224 | + } |
|
1225 | + //Registration Overview Today Pending\ |
|
1226 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1227 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1228 | + ) { |
|
1229 | + $admin_bar->add_menu(array( |
|
1230 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1231 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1232 | + 'title' => __('Pending', 'event_espresso'), |
|
1233 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1234 | + 'action' => 'default', |
|
1235 | + 'status' => 'today', |
|
1236 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1237 | + ), $reg_admin_url), |
|
1238 | + 'meta' => array( |
|
1239 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1240 | + 'target' => '', |
|
1241 | + 'class' => $menu_class, |
|
1242 | + ), |
|
1243 | + )); |
|
1244 | + } |
|
1245 | + //Registration Overview Today Incomplete |
|
1246 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1247 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1248 | + ) { |
|
1249 | + $admin_bar->add_menu(array( |
|
1250 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1251 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1252 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1253 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1254 | + 'action' => 'default', |
|
1255 | + 'status' => 'today', |
|
1256 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1257 | + ), $reg_admin_url), |
|
1258 | + 'meta' => array( |
|
1259 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1260 | + 'target' => '', |
|
1261 | + 'class' => $menu_class, |
|
1262 | + ), |
|
1263 | + )); |
|
1264 | + } |
|
1265 | + //Registration Overview Today Incomplete |
|
1266 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1267 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1268 | + ) { |
|
1269 | + $admin_bar->add_menu(array( |
|
1270 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1271 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1272 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1273 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1274 | + 'action' => 'default', |
|
1275 | + 'status' => 'today', |
|
1276 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1277 | + ), $reg_admin_url), |
|
1278 | + 'meta' => array( |
|
1279 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1280 | + 'target' => '', |
|
1281 | + 'class' => $menu_class, |
|
1282 | + ), |
|
1283 | + )); |
|
1284 | + } |
|
1285 | + //Registration Overview This Month |
|
1286 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1287 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1288 | + ) { |
|
1289 | + $admin_bar->add_menu(array( |
|
1290 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1291 | + 'parent' => 'espresso-toolbar-registrations', |
|
1292 | + 'title' => __('This Month', 'event_espresso'), |
|
1293 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1294 | + $reg_admin_url), |
|
1295 | + 'meta' => array( |
|
1296 | + 'title' => __('This Month', 'event_espresso'), |
|
1297 | + 'target' => '', |
|
1298 | + 'class' => $menu_class, |
|
1299 | + ), |
|
1300 | + )); |
|
1301 | + } |
|
1302 | + //Registration Overview This Month Approved |
|
1303 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1304 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1305 | + ) { |
|
1306 | + $admin_bar->add_menu(array( |
|
1307 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1308 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1309 | + 'title' => __('Approved', 'event_espresso'), |
|
1310 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1311 | + 'action' => 'default', |
|
1312 | + 'status' => 'month', |
|
1313 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1314 | + ), $reg_admin_url), |
|
1315 | + 'meta' => array( |
|
1316 | + 'title' => __('Approved', 'event_espresso'), |
|
1317 | + 'target' => '', |
|
1318 | + 'class' => $menu_class, |
|
1319 | + ), |
|
1320 | + )); |
|
1321 | + } |
|
1322 | + //Registration Overview This Month Pending |
|
1323 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1324 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1325 | + ) { |
|
1326 | + $admin_bar->add_menu(array( |
|
1327 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1328 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1329 | + 'title' => __('Pending', 'event_espresso'), |
|
1330 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1331 | + 'action' => 'default', |
|
1332 | + 'status' => 'month', |
|
1333 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1334 | + ), $reg_admin_url), |
|
1335 | + 'meta' => array( |
|
1336 | + 'title' => __('Pending', 'event_espresso'), |
|
1337 | + 'target' => '', |
|
1338 | + 'class' => $menu_class, |
|
1339 | + ), |
|
1340 | + )); |
|
1341 | + } |
|
1342 | + //Registration Overview This Month Not Approved |
|
1343 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1344 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1345 | + ) { |
|
1346 | + $admin_bar->add_menu(array( |
|
1347 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1348 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1349 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1350 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1351 | + 'action' => 'default', |
|
1352 | + 'status' => 'month', |
|
1353 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1354 | + ), $reg_admin_url), |
|
1355 | + 'meta' => array( |
|
1356 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1357 | + 'target' => '', |
|
1358 | + 'class' => $menu_class, |
|
1359 | + ), |
|
1360 | + )); |
|
1361 | + } |
|
1362 | + //Registration Overview This Month Cancelled |
|
1363 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1364 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1365 | + ) { |
|
1366 | + $admin_bar->add_menu(array( |
|
1367 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1368 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1369 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1370 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1371 | + 'action' => 'default', |
|
1372 | + 'status' => 'month', |
|
1373 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1374 | + ), $reg_admin_url), |
|
1375 | + 'meta' => array( |
|
1376 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1377 | + 'target' => '', |
|
1378 | + 'class' => $menu_class, |
|
1379 | + ), |
|
1380 | + )); |
|
1381 | + } |
|
1382 | + //Extensions & Services |
|
1383 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1384 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1385 | + ) { |
|
1386 | + $admin_bar->add_menu(array( |
|
1387 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1388 | + 'parent' => 'espresso-toolbar', |
|
1389 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1390 | + 'href' => $extensions_admin_url, |
|
1391 | + 'meta' => array( |
|
1392 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | + 'target' => '', |
|
1394 | + 'class' => $menu_class, |
|
1395 | + ), |
|
1396 | + )); |
|
1397 | + } |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1404 | + * never returned with the function. |
|
1405 | + * |
|
1406 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1407 | + * @return array |
|
1408 | + */ |
|
1409 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1410 | + { |
|
1411 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1412 | + } |
|
1413 | + |
|
1414 | + |
|
1415 | + |
|
1416 | + |
|
1417 | + |
|
1418 | + |
|
1419 | + /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
1420 | + /** |
|
1421 | + * wp_enqueue_scripts |
|
1422 | + * |
|
1423 | + * @access public |
|
1424 | + * @return void |
|
1425 | + */ |
|
1426 | + public function wp_enqueue_scripts() |
|
1427 | + { |
|
1428 | + // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
1429 | + if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
1430 | + // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
1431 | + if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
1432 | + // register jQuery Validate and additional methods |
|
1433 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
1434 | + array('jquery'), '1.15.0', true); |
|
1435 | + wp_register_script('jquery-validate-extra-methods', |
|
1436 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
1437 | + array('jquery', 'jquery-validate'), '1.15.0', true); |
|
1438 | + } |
|
1439 | + } |
|
1440 | + } |
|
1441 | 1441 | |
1442 | 1442 | |
1443 | 1443 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,314 +16,314 @@ discard block |
||
16 | 16 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * array of available options to choose as an answer |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $_options = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the html_label_text above the checkbox/radio button options |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - protected $_display_html_label_text = true; |
|
32 | - |
|
33 | - /** |
|
34 | - * whether to display an question option description as part of the input label |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_use_desc_in_label = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | - * this is used to apply a css class to the input label |
|
43 | - * |
|
44 | - * @var int |
|
45 | - */ |
|
46 | - protected $_label_size = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * whether to enforce the label size value passed in the constructor |
|
50 | - * |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - protected $_enforce_label_size = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | - * or not (ie, the value should be a simple int, string, etc) |
|
58 | - * |
|
59 | - * @var boolean |
|
60 | - */ |
|
61 | - protected $_multiple_selections = false; |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param array $answer_options |
|
67 | - * @param array $input_settings { |
|
68 | - * @type int|string $label_size |
|
69 | - * @type boolean $display_html_label_text |
|
70 | - * } |
|
71 | - * And all the options accepted by EE_Form_Input_Base |
|
72 | - */ |
|
73 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | - { |
|
75 | - if (isset($input_settings['label_size'])) { |
|
76 | - $this->_set_label_size($input_settings['label_size']); |
|
77 | - if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | - $this->_enforce_label_size = true; |
|
79 | - } |
|
80 | - } |
|
81 | - if (isset($input_settings['display_html_label_text'])) { |
|
82 | - $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | - } |
|
84 | - $this->set_select_options($answer_options); |
|
85 | - parent::__construct($input_settings); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Sets the allowed options for this input. Also has the side-effect of |
|
92 | - * updating the normalization strategy to match the keys provided in the array |
|
93 | - * |
|
94 | - * @param array $answer_options |
|
95 | - * @return void just has the side-effect of setting the options for this input |
|
96 | - */ |
|
97 | - public function set_select_options($answer_options = array()) |
|
98 | - { |
|
99 | - $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | - //get the first item in the select options and check it's type |
|
101 | - $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | - ? $this->_process_question_options($answer_options) |
|
103 | - : $answer_options; |
|
104 | - //d( $this->_options ); |
|
105 | - $select_option_keys = array_keys($this->_options); |
|
106 | - // attempt to determine data type for values in order to set normalization type |
|
107 | - if ( |
|
108 | - count($this->_options) === 2 |
|
109 | - && ( |
|
110 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
111 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
112 | - ) |
|
113 | - ) { |
|
114 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
115 | - $normalization = new EE_Boolean_Normalization(); |
|
116 | - } else { |
|
117 | - //are ALL the options ints? If so use int validation |
|
118 | - $all_ints = true; |
|
119 | - foreach ($select_option_keys as $value) { |
|
120 | - //allow for a default value which may be empty. |
|
121 | - if ( ! is_int($value) && $value !== '' && $value !== null) { |
|
122 | - $all_ints = false; |
|
123 | - break; |
|
124 | - } |
|
125 | - } |
|
126 | - if ($all_ints) { |
|
127 | - $normalization = new EE_Int_Normalization(); |
|
128 | - } else { |
|
129 | - $normalization = new EE_Text_Normalization(); |
|
130 | - } |
|
131 | - } |
|
132 | - // does input type have multiple options ? |
|
133 | - if ($this->_multiple_selections) { |
|
134 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
135 | - } else { |
|
136 | - $this->_set_normalization_strategy($normalization); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function options() |
|
146 | - { |
|
147 | - return $this->_options; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns an array which is guaranteed to not be multidimensional |
|
154 | - * |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - public function flat_options() |
|
158 | - { |
|
159 | - return $this->_flatten_select_options($this->options()); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
166 | - * |
|
167 | - * @param array $arr |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function _flatten_select_options($arr) |
|
171 | - { |
|
172 | - $flat_array = array(); |
|
173 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
174 | - foreach ($arr as $sub_array) { |
|
175 | - foreach ((array)$sub_array as $key => $value) { |
|
176 | - $flat_array[$key] = $value; |
|
177 | - $this->_set_label_size($value); |
|
178 | - } |
|
179 | - } |
|
180 | - } else { |
|
181 | - foreach ($arr as $key => $value) { |
|
182 | - $flat_array[$key] = $value; |
|
183 | - $this->_set_label_size($value); |
|
184 | - } |
|
185 | - } |
|
186 | - return $flat_array; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param EE_Question_Option[] $question_options_array |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - protected function _process_question_options($question_options_array = array()) |
|
196 | - { |
|
197 | - $flat_array = array(); |
|
198 | - foreach ($question_options_array as $question_option) { |
|
199 | - if ($question_option instanceof EE_Question_Option) { |
|
200 | - $desc = ''; |
|
201 | - if ($this->_use_desc_in_label) { |
|
202 | - $desc = $question_option->desc(); |
|
203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
204 | - } |
|
205 | - $value = $question_option->value(); |
|
206 | - // add value even if it's empty |
|
207 | - $flat_array[$value] = $value; |
|
208 | - // if both value and desc are not empty, then separate with a dash |
|
209 | - if ( ! empty($value) && ! empty($desc)) { |
|
210 | - $flat_array[$value] .= ' - ' . $desc; |
|
211 | - } else { |
|
212 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
213 | - $flat_array[$value] .= $desc; |
|
214 | - } |
|
215 | - } elseif (is_array($question_option)) { |
|
216 | - $flat_array += $this->_flatten_select_options($question_option); |
|
217 | - } |
|
218 | - } |
|
219 | - return $flat_array; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * set_label_sizes |
|
226 | - * |
|
227 | - * @return void |
|
228 | - */ |
|
229 | - public function set_label_sizes() |
|
230 | - { |
|
231 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
232 | - if ( ! $this->_enforce_label_size) { |
|
233 | - foreach ($this->_options as $option) { |
|
234 | - // calculate the strlen of the label |
|
235 | - $this->_set_label_size($option); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * _set_label_size_class |
|
244 | - * |
|
245 | - * @param int|string $value |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - private function _set_label_size($value = '') |
|
249 | - { |
|
250 | - // determine length of option value |
|
251 | - $val_size = is_int($value) ? $value : strlen($value); |
|
252 | - // use new value if bigger than existing |
|
253 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * get_label_size_class |
|
260 | - * |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function get_label_size_class() |
|
264 | - { |
|
265 | - $size = ' medium-lbl'; |
|
266 | - // use maximum option value length to determine label size |
|
267 | - if ($this->_label_size < 3) { |
|
268 | - $size = ' nano-lbl'; |
|
269 | - } else if ($this->_label_size < 6) { |
|
270 | - $size = ' micro-lbl'; |
|
271 | - } else if ($this->_label_size < 12) { |
|
272 | - $size = ' tiny-lbl'; |
|
273 | - } else if ($this->_label_size < 25) { |
|
274 | - $size = ' small-lbl'; |
|
275 | - } else if ($this->_label_size < 50) { |
|
276 | - $size = ' medium-lbl'; |
|
277 | - } else if ($this->_label_size >= 100) { |
|
278 | - $size = ' big-lbl'; |
|
279 | - } |
|
280 | - return $size; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Returns the pretty value for the normalized value |
|
287 | - * |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - public function pretty_value() |
|
291 | - { |
|
292 | - $options = $this->flat_options(); |
|
293 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
294 | - if ( ! $this->_multiple_selections) { |
|
295 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
296 | - } |
|
297 | - $pretty_strings = array(); |
|
298 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
299 | - if (isset($options[$unnormalized_value_choice])) { |
|
300 | - $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
301 | - } else { |
|
302 | - $pretty_strings[] = $this->normalized_value(); |
|
303 | - } |
|
304 | - } |
|
305 | - return implode(', ', $pretty_strings); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @return boolean |
|
312 | - */ |
|
313 | - public function display_html_label_text() |
|
314 | - { |
|
315 | - return $this->_display_html_label_text; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param boolean $display_html_label_text |
|
322 | - */ |
|
323 | - public function set_display_html_label_text($display_html_label_text) |
|
324 | - { |
|
325 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
326 | - } |
|
19 | + /** |
|
20 | + * array of available options to choose as an answer |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $_options = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the html_label_text above the checkbox/radio button options |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + protected $_display_html_label_text = true; |
|
32 | + |
|
33 | + /** |
|
34 | + * whether to display an question option description as part of the input label |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_use_desc_in_label = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | + * this is used to apply a css class to the input label |
|
43 | + * |
|
44 | + * @var int |
|
45 | + */ |
|
46 | + protected $_label_size = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * whether to enforce the label size value passed in the constructor |
|
50 | + * |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + protected $_enforce_label_size = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | + * or not (ie, the value should be a simple int, string, etc) |
|
58 | + * |
|
59 | + * @var boolean |
|
60 | + */ |
|
61 | + protected $_multiple_selections = false; |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param array $answer_options |
|
67 | + * @param array $input_settings { |
|
68 | + * @type int|string $label_size |
|
69 | + * @type boolean $display_html_label_text |
|
70 | + * } |
|
71 | + * And all the options accepted by EE_Form_Input_Base |
|
72 | + */ |
|
73 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | + { |
|
75 | + if (isset($input_settings['label_size'])) { |
|
76 | + $this->_set_label_size($input_settings['label_size']); |
|
77 | + if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | + $this->_enforce_label_size = true; |
|
79 | + } |
|
80 | + } |
|
81 | + if (isset($input_settings['display_html_label_text'])) { |
|
82 | + $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | + } |
|
84 | + $this->set_select_options($answer_options); |
|
85 | + parent::__construct($input_settings); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Sets the allowed options for this input. Also has the side-effect of |
|
92 | + * updating the normalization strategy to match the keys provided in the array |
|
93 | + * |
|
94 | + * @param array $answer_options |
|
95 | + * @return void just has the side-effect of setting the options for this input |
|
96 | + */ |
|
97 | + public function set_select_options($answer_options = array()) |
|
98 | + { |
|
99 | + $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | + //get the first item in the select options and check it's type |
|
101 | + $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | + ? $this->_process_question_options($answer_options) |
|
103 | + : $answer_options; |
|
104 | + //d( $this->_options ); |
|
105 | + $select_option_keys = array_keys($this->_options); |
|
106 | + // attempt to determine data type for values in order to set normalization type |
|
107 | + if ( |
|
108 | + count($this->_options) === 2 |
|
109 | + && ( |
|
110 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
111 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
112 | + ) |
|
113 | + ) { |
|
114 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
115 | + $normalization = new EE_Boolean_Normalization(); |
|
116 | + } else { |
|
117 | + //are ALL the options ints? If so use int validation |
|
118 | + $all_ints = true; |
|
119 | + foreach ($select_option_keys as $value) { |
|
120 | + //allow for a default value which may be empty. |
|
121 | + if ( ! is_int($value) && $value !== '' && $value !== null) { |
|
122 | + $all_ints = false; |
|
123 | + break; |
|
124 | + } |
|
125 | + } |
|
126 | + if ($all_ints) { |
|
127 | + $normalization = new EE_Int_Normalization(); |
|
128 | + } else { |
|
129 | + $normalization = new EE_Text_Normalization(); |
|
130 | + } |
|
131 | + } |
|
132 | + // does input type have multiple options ? |
|
133 | + if ($this->_multiple_selections) { |
|
134 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
135 | + } else { |
|
136 | + $this->_set_normalization_strategy($normalization); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function options() |
|
146 | + { |
|
147 | + return $this->_options; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns an array which is guaranteed to not be multidimensional |
|
154 | + * |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + public function flat_options() |
|
158 | + { |
|
159 | + return $this->_flatten_select_options($this->options()); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
166 | + * |
|
167 | + * @param array $arr |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function _flatten_select_options($arr) |
|
171 | + { |
|
172 | + $flat_array = array(); |
|
173 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
174 | + foreach ($arr as $sub_array) { |
|
175 | + foreach ((array)$sub_array as $key => $value) { |
|
176 | + $flat_array[$key] = $value; |
|
177 | + $this->_set_label_size($value); |
|
178 | + } |
|
179 | + } |
|
180 | + } else { |
|
181 | + foreach ($arr as $key => $value) { |
|
182 | + $flat_array[$key] = $value; |
|
183 | + $this->_set_label_size($value); |
|
184 | + } |
|
185 | + } |
|
186 | + return $flat_array; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param EE_Question_Option[] $question_options_array |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + protected function _process_question_options($question_options_array = array()) |
|
196 | + { |
|
197 | + $flat_array = array(); |
|
198 | + foreach ($question_options_array as $question_option) { |
|
199 | + if ($question_option instanceof EE_Question_Option) { |
|
200 | + $desc = ''; |
|
201 | + if ($this->_use_desc_in_label) { |
|
202 | + $desc = $question_option->desc(); |
|
203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
204 | + } |
|
205 | + $value = $question_option->value(); |
|
206 | + // add value even if it's empty |
|
207 | + $flat_array[$value] = $value; |
|
208 | + // if both value and desc are not empty, then separate with a dash |
|
209 | + if ( ! empty($value) && ! empty($desc)) { |
|
210 | + $flat_array[$value] .= ' - ' . $desc; |
|
211 | + } else { |
|
212 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
213 | + $flat_array[$value] .= $desc; |
|
214 | + } |
|
215 | + } elseif (is_array($question_option)) { |
|
216 | + $flat_array += $this->_flatten_select_options($question_option); |
|
217 | + } |
|
218 | + } |
|
219 | + return $flat_array; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * set_label_sizes |
|
226 | + * |
|
227 | + * @return void |
|
228 | + */ |
|
229 | + public function set_label_sizes() |
|
230 | + { |
|
231 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
232 | + if ( ! $this->_enforce_label_size) { |
|
233 | + foreach ($this->_options as $option) { |
|
234 | + // calculate the strlen of the label |
|
235 | + $this->_set_label_size($option); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * _set_label_size_class |
|
244 | + * |
|
245 | + * @param int|string $value |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + private function _set_label_size($value = '') |
|
249 | + { |
|
250 | + // determine length of option value |
|
251 | + $val_size = is_int($value) ? $value : strlen($value); |
|
252 | + // use new value if bigger than existing |
|
253 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * get_label_size_class |
|
260 | + * |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function get_label_size_class() |
|
264 | + { |
|
265 | + $size = ' medium-lbl'; |
|
266 | + // use maximum option value length to determine label size |
|
267 | + if ($this->_label_size < 3) { |
|
268 | + $size = ' nano-lbl'; |
|
269 | + } else if ($this->_label_size < 6) { |
|
270 | + $size = ' micro-lbl'; |
|
271 | + } else if ($this->_label_size < 12) { |
|
272 | + $size = ' tiny-lbl'; |
|
273 | + } else if ($this->_label_size < 25) { |
|
274 | + $size = ' small-lbl'; |
|
275 | + } else if ($this->_label_size < 50) { |
|
276 | + $size = ' medium-lbl'; |
|
277 | + } else if ($this->_label_size >= 100) { |
|
278 | + $size = ' big-lbl'; |
|
279 | + } |
|
280 | + return $size; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Returns the pretty value for the normalized value |
|
287 | + * |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + public function pretty_value() |
|
291 | + { |
|
292 | + $options = $this->flat_options(); |
|
293 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
294 | + if ( ! $this->_multiple_selections) { |
|
295 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
296 | + } |
|
297 | + $pretty_strings = array(); |
|
298 | + foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
299 | + if (isset($options[$unnormalized_value_choice])) { |
|
300 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
301 | + } else { |
|
302 | + $pretty_strings[] = $this->normalized_value(); |
|
303 | + } |
|
304 | + } |
|
305 | + return implode(', ', $pretty_strings); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @return boolean |
|
312 | + */ |
|
313 | + public function display_html_label_text() |
|
314 | + { |
|
315 | + return $this->_display_html_label_text; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param boolean $display_html_label_text |
|
322 | + */ |
|
323 | + public function set_display_html_label_text($display_html_label_text) |
|
324 | + { |
|
325 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
326 | + } |
|
327 | 327 | |
328 | 328 | |
329 | 329 |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $flat_array = array(); |
173 | 173 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
174 | 174 | foreach ($arr as $sub_array) { |
175 | - foreach ((array)$sub_array as $key => $value) { |
|
175 | + foreach ((array) $sub_array as $key => $value) { |
|
176 | 176 | $flat_array[$key] = $value; |
177 | 177 | $this->_set_label_size($value); |
178 | 178 | } |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | $desc = ''; |
201 | 201 | if ($this->_use_desc_in_label) { |
202 | 202 | $desc = $question_option->desc(); |
203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
204 | 204 | } |
205 | 205 | $value = $question_option->value(); |
206 | 206 | // add value even if it's empty |
207 | 207 | $flat_array[$value] = $value; |
208 | 208 | // if both value and desc are not empty, then separate with a dash |
209 | 209 | if ( ! empty($value) && ! empty($desc)) { |
210 | - $flat_array[$value] .= ' - ' . $desc; |
|
210 | + $flat_array[$value] .= ' - '.$desc; |
|
211 | 211 | } else { |
212 | 212 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
213 | 213 | $flat_array[$value] .= $desc; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | $unnormalized_value_choices = array($unnormalized_value_choices); |
296 | 296 | } |
297 | 297 | $pretty_strings = array(); |
298 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
298 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
299 | 299 | if (isset($options[$unnormalized_value_choice])) { |
300 | 300 | $pretty_strings[] = $options[$unnormalized_value_choice]; |
301 | 301 | } else { |
@@ -13,93 +13,93 @@ |
||
13 | 13 | class EE_Has_Many_Relation extends EE_Model_Relation_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
18 | - * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
19 | - * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
20 | - * related models across the relation, and add-and-remove the relationships. |
|
21 | - * |
|
22 | - * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
23 | - * related models across this relation, block (prevent and add an |
|
24 | - * error) the deletion of this model |
|
25 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
26 | - * default |
|
27 | - */ |
|
28 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
29 | - { |
|
30 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
31 | - } |
|
16 | + /** |
|
17 | + * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
18 | + * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
19 | + * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
20 | + * related models across the relation, and add-and-remove the relationships. |
|
21 | + * |
|
22 | + * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
23 | + * related models across this relation, block (prevent and add an |
|
24 | + * error) the deletion of this model |
|
25 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
26 | + * default |
|
27 | + */ |
|
28 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
29 | + { |
|
30 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Gets the SQL string for performing the join between this model and the other model. |
|
36 | - * |
|
37 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
38 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
39 | - * other_model_primary_table.fk" etc |
|
40 | - * @throws \EE_Error |
|
41 | - */ |
|
42 | - public function get_join_statement($model_relation_chain) |
|
43 | - { |
|
44 | - //create the sql string like |
|
45 | - // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
46 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
47 | - $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
48 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
49 | - $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
50 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
51 | - $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
52 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
34 | + /** |
|
35 | + * Gets the SQL string for performing the join between this model and the other model. |
|
36 | + * |
|
37 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
38 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
39 | + * other_model_primary_table.fk" etc |
|
40 | + * @throws \EE_Error |
|
41 | + */ |
|
42 | + public function get_join_statement($model_relation_chain) |
|
43 | + { |
|
44 | + //create the sql string like |
|
45 | + // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
46 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
47 | + $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
48 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
49 | + $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
50 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
51 | + $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
52 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
53 | 53 | |
54 | - return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
55 | - $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
56 | - } |
|
54 | + return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
55 | + $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
61 | - * you like. |
|
62 | - * |
|
63 | - * @param EE_Base_Class|int $this_obj_or_id |
|
64 | - * @param EE_Base_Class|int $other_obj_or_id |
|
65 | - * @param array $extra_join_model_fields_n_values |
|
66 | - * @return \EE_Base_Class |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
70 | - { |
|
71 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
72 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
59 | + /** |
|
60 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
61 | + * you like. |
|
62 | + * |
|
63 | + * @param EE_Base_Class|int $this_obj_or_id |
|
64 | + * @param EE_Base_Class|int $other_obj_or_id |
|
65 | + * @param array $extra_join_model_fields_n_values |
|
66 | + * @return \EE_Base_Class |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
70 | + { |
|
71 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
72 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
73 | 73 | |
74 | - //find the field on the other model which is a foreign key to this model |
|
75 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
76 | - if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
77 | - //set that field on the other model to this model's ID |
|
78 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
79 | - $other_model_obj->save(); |
|
80 | - } |
|
81 | - return $other_model_obj; |
|
82 | - } |
|
74 | + //find the field on the other model which is a foreign key to this model |
|
75 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
76 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
77 | + //set that field on the other model to this model's ID |
|
78 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
79 | + $other_model_obj->save(); |
|
80 | + } |
|
81 | + return $other_model_obj; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
87 | - * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
88 | - * |
|
89 | - * @param EE_Base_Class|int $this_obj_or_id |
|
90 | - * @param EE_Base_Class|int $other_obj_or_id |
|
91 | - * @param array $where_query |
|
92 | - * @return \EE_Base_Class |
|
93 | - * @throws \EE_Error |
|
94 | - */ |
|
95 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
96 | - { |
|
97 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
98 | - //find the field on the other model which is a foreign key to this model |
|
99 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
100 | - //set that field on the other model to this model's ID |
|
101 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
102 | - $other_model_obj->save(); |
|
103 | - return $other_model_obj; |
|
104 | - } |
|
85 | + /** |
|
86 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
87 | + * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
88 | + * |
|
89 | + * @param EE_Base_Class|int $this_obj_or_id |
|
90 | + * @param EE_Base_Class|int $other_obj_or_id |
|
91 | + * @param array $where_query |
|
92 | + * @return \EE_Base_Class |
|
93 | + * @throws \EE_Error |
|
94 | + */ |
|
95 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
96 | + { |
|
97 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
98 | + //find the field on the other model which is a foreign key to this model |
|
99 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
100 | + //set that field on the other model to this model's ID |
|
101 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
102 | + $other_model_obj->save(); |
|
103 | + return $other_model_obj; |
|
104 | + } |
|
105 | 105 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | interface EEI_Attendee { |
191 | 191 | public function fname(); |
192 | 192 | public function lname(); |
193 | - public function full_name(); |
|
193 | + public function full_name(); |
|
194 | 194 | public function email(); |
195 | 195 | public function phone(); |
196 | 196 | public function address(); |
@@ -311,23 +311,23 @@ discard block |
||
311 | 311 | * @param float $amount |
312 | 312 | * @param string $name |
313 | 313 | * @param string $description |
314 | - * @param string $code |
|
315 | - * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
316 | - * the same code is found, $amount will be added onto it; otherwise will simply |
|
317 | - * set the taxes to match $amount |
|
314 | + * @param string $code |
|
315 | + * @param boolean $add_to_existing_line_item if true and a duplicate line item with |
|
316 | + * the same code is found, $amount will be added onto it; otherwise will simply |
|
317 | + * set the taxes to match $amount |
|
318 | 318 | * @return EE_Line_Item the new tax created |
319 | 319 | */ |
320 | 320 | public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ); |
321 | 321 | |
322 | - /** |
|
323 | - * Makes all the line items which are children of $line_item taxable (or not). |
|
324 | - * Does NOT save the line items |
|
325 | - * @param EE_Line_Item $line_item |
|
326 | - * @param boolean $taxable |
|
327 | - * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
328 | - * it will be whitelisted (ie, except from becoming taxable) |
|
329 | - */ |
|
330 | - public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ); |
|
322 | + /** |
|
323 | + * Makes all the line items which are children of $line_item taxable (or not). |
|
324 | + * Does NOT save the line items |
|
325 | + * @param EE_Line_Item $line_item |
|
326 | + * @param boolean $taxable |
|
327 | + * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
328 | + * it will be whitelisted (ie, except from becoming taxable) |
|
329 | + */ |
|
330 | + public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ); |
|
331 | 331 | |
332 | 332 | /** |
333 | 333 | * Adds a simple item ( unrelated to any other model object) to the total line item, |
@@ -357,15 +357,15 @@ discard block |
||
357 | 357 | */ |
358 | 358 | interface EEHI_Money{ |
359 | 359 | /** |
360 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
361 | - * This should be used to compare floats instead of normal '==' because floats |
|
362 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
363 | - * but actually differ by 0.00000001. |
|
364 | - * @param float $float1 |
|
365 | - * @param float $float2 |
|
366 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
367 | - * @return boolean whether the equation is true or false |
|
368 | - */ |
|
360 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
361 | + * This should be used to compare floats instead of normal '==' because floats |
|
362 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
363 | + * but actually differ by 0.00000001. |
|
364 | + * @param float $float1 |
|
365 | + * @param float $float2 |
|
366 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
367 | + * @return boolean whether the equation is true or false |
|
368 | + */ |
|
369 | 369 | public function compare_floats( $float1, $float2, $operator='=' ); |
370 | 370 | } |
371 | 371 |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * increments reserved by amount passed by $qty |
254 | 254 | * |
255 | 255 | * @param int $qty |
256 | - * @return boolean |
|
256 | + * @return boolean|null |
|
257 | 257 | */ |
258 | 258 | public function increase_reserved( $qty = 1 ) { |
259 | 259 | $reserved = $this->reserved() + absint( $qty ); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * decrements (subtracts) reserved by amount passed by $qty |
267 | 267 | * |
268 | 268 | * @param int $qty |
269 | - * @return boolean |
|
269 | + * @return boolean|null |
|
270 | 270 | */ |
271 | 271 | public function decrease_reserved( $qty = 1 ) { |
272 | 272 | $reserved = $this->reserved() - absint( $qty ); |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @param string $dt_frmt - string representation of date format defaults to WP settings |
412 | 412 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
413 | 413 | * the end date ie: Jan 01 "to" Dec 31 |
414 | - * @return mixed string on success, FALSE on fail |
|
414 | + * @return string string on success, FALSE on fail |
|
415 | 415 | * @throws \EE_Error |
416 | 416 | */ |
417 | 417 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @param string $tm_format string representation of time format defaults to 'g:i a' |
484 | 484 | * @param string $conjunction conjunction junction what's your function ? |
485 | 485 | * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
486 | - * @return mixed string on success, FALSE on fail |
|
486 | + * @return string string on success, FALSE on fail |
|
487 | 487 | * @throws \EE_Error |
488 | 488 | */ |
489 | 489 | public function time_range( $tm_format = '', $conjunction = ' - ' ) { |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | |
359 | 359 | |
360 | 360 | |
361 | - /** |
|
362 | - * get event start date. Provide either the date format, or NULL to re-use the |
|
363 | - * last-used format, or '' to use the default date format |
|
364 | - * |
|
365 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
366 | - * @return mixed string on success, FALSE on fail |
|
367 | - */ |
|
361 | + /** |
|
362 | + * get event start date. Provide either the date format, or NULL to re-use the |
|
363 | + * last-used format, or '' to use the default date format |
|
364 | + * |
|
365 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
366 | + * @return mixed string on success, FALSE on fail |
|
367 | + */ |
|
368 | 368 | public function start_date( $dt_frmt = '' ) { |
369 | 369 | return $this->_show_datetime( 'D', 'start', $dt_frmt ); |
370 | 370 | } |
@@ -381,13 +381,13 @@ discard block |
||
381 | 381 | |
382 | 382 | |
383 | 383 | |
384 | - /** |
|
385 | - * get end date. Provide either the date format, or NULL to re-use the |
|
386 | - * last-used format, or '' to use the default date format |
|
387 | - * |
|
388 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
389 | - * @return mixed string on success, FALSE on fail |
|
390 | - */ |
|
384 | + /** |
|
385 | + * get end date. Provide either the date format, or NULL to re-use the |
|
386 | + * last-used format, or '' to use the default date format |
|
387 | + * |
|
388 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
389 | + * @return mixed string on success, FALSE on fail |
|
390 | + */ |
|
391 | 391 | public function end_date( $dt_frmt = '' ) { |
392 | 392 | return $this->_show_datetime( 'D', 'end', $dt_frmt ); |
393 | 393 | } |
@@ -509,23 +509,23 @@ discard block |
||
509 | 509 | /** |
510 | 510 | * This returns a range representation of the date and times. |
511 | 511 | * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
512 | - * Also, the return value is localized. |
|
513 | - * |
|
514 | - * @param string $dt_format |
|
512 | + * Also, the return value is localized. |
|
513 | + * |
|
514 | + * @param string $dt_format |
|
515 | 515 | * @param string $tm_format |
516 | 516 | * @param string $conjunction used between two different dates or times. |
517 | - * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
518 | - * @param string $separator used between the date and time formats. |
|
519 | - * ex: Dec 1, 2016{$separator}2pm |
|
517 | + * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
518 | + * @param string $separator used between the date and time formats. |
|
519 | + * ex: Dec 1, 2016{$separator}2pm |
|
520 | 520 | * @return string |
521 | 521 | * @throws \EE_Error |
522 | 522 | */ |
523 | 523 | public function date_and_time_range( |
524 | - $dt_format = '', |
|
525 | - $tm_format = '', |
|
526 | - $conjunction = ' - ' , |
|
527 | - $separator = ' ' |
|
528 | - ) { |
|
524 | + $dt_format = '', |
|
525 | + $tm_format = '', |
|
526 | + $conjunction = ' - ' , |
|
527 | + $separator = ' ' |
|
528 | + ) { |
|
529 | 529 | $dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt; |
530 | 530 | $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
531 | 531 | $full_format = $dt_format . $separator . $tm_format; |
@@ -539,14 +539,14 @@ discard block |
||
539 | 539 | //start and end date are the same but times are different |
540 | 540 | case ( $this->start_date() === $this->end_date() ) : |
541 | 541 | $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
542 | - . $conjunction |
|
543 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
542 | + . $conjunction |
|
543 | + . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
544 | 544 | break; |
545 | 545 | //all other conditions |
546 | 546 | default : |
547 | 547 | $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
548 | - . $conjunction |
|
549 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
548 | + . $conjunction |
|
549 | + . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
550 | 550 | break; |
551 | 551 | } |
552 | 552 | return $output; |
@@ -630,13 +630,13 @@ discard block |
||
630 | 630 | |
631 | 631 | |
632 | 632 | /** |
633 | - * get end date and time |
|
634 | - * |
|
635 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
636 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
637 | - * @return mixed string on success, FALSE on fail |
|
638 | - */ |
|
639 | - public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
633 | + * get end date and time |
|
634 | + * |
|
635 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
636 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
637 | + * @return mixed string on success, FALSE on fail |
|
638 | + */ |
|
639 | + public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
640 | 640 | return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format ); |
641 | 641 | } |
642 | 642 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | * date_format and the second value is the time format |
75 | 75 | * @return EE_Datetime |
76 | 76 | */ |
77 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
78 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
79 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
77 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
78 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
79 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * the website will be used. |
88 | 88 | * @return EE_Datetime |
89 | 89 | */ |
90 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
91 | - return new self( $props_n_values, TRUE, $timezone ); |
|
90 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
91 | + return new self($props_n_values, TRUE, $timezone); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @param $name |
98 | 98 | */ |
99 | - public function set_name( $name ) { |
|
100 | - $this->set( 'DTT_name', $name ); |
|
99 | + public function set_name($name) { |
|
100 | + $this->set('DTT_name', $name); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * @param $description |
107 | 107 | */ |
108 | - public function set_description( $description ) { |
|
109 | - $this->set( 'DTT_description', $description ); |
|
108 | + public function set_description($description) { |
|
109 | + $this->set('DTT_description', $description); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
120 | 120 | */ |
121 | - public function set_start_date( $date ) { |
|
122 | - $this->_set_date_for( $date, 'DTT_EVT_start' ); |
|
121 | + public function set_start_date($date) { |
|
122 | + $this->_set_date_for($date, 'DTT_EVT_start'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
133 | 133 | */ |
134 | - public function set_start_time( $time ) { |
|
135 | - $this->_set_time_for( $time, 'DTT_EVT_start' ); |
|
134 | + public function set_start_time($time) { |
|
135 | + $this->_set_time_for($time, 'DTT_EVT_start'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
146 | 146 | */ |
147 | - public function set_end_date( $date ) { |
|
148 | - $this->_set_date_for( $date, 'DTT_EVT_end' ); |
|
147 | + public function set_end_date($date) { |
|
148 | + $this->_set_date_for($date, 'DTT_EVT_end'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
159 | 159 | */ |
160 | - public function set_end_time( $time ) { |
|
161 | - $this->_set_time_for( $time, 'DTT_EVT_end' ); |
|
160 | + public function set_end_time($time) { |
|
161 | + $this->_set_time_for($time, 'DTT_EVT_end'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @param int $reg_limit |
172 | 172 | */ |
173 | - public function set_reg_limit( $reg_limit ) { |
|
174 | - $this->set( 'DTT_reg_limit', $reg_limit ); |
|
173 | + public function set_reg_limit($reg_limit) { |
|
174 | + $this->set('DTT_reg_limit', $reg_limit); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return mixed int on success, FALSE on fail |
184 | 184 | */ |
185 | 185 | public function sold() { |
186 | - return $this->get_raw( 'DTT_sold' ); |
|
186 | + return $this->get_raw('DTT_sold'); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param int $sold |
195 | 195 | */ |
196 | - public function set_sold( $sold ) { |
|
196 | + public function set_sold($sold) { |
|
197 | 197 | // sold can not go below zero |
198 | - $sold = max( 0, $sold ); |
|
199 | - $this->set( 'DTT_sold', $sold ); |
|
198 | + $sold = max(0, $sold); |
|
199 | + $this->set('DTT_sold', $sold); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | * increments sold by amount passed by $qty |
206 | 206 | * @param int $qty |
207 | 207 | */ |
208 | - public function increase_sold( $qty = 1 ) { |
|
208 | + public function increase_sold($qty = 1) { |
|
209 | 209 | $sold = $this->sold() + $qty; |
210 | 210 | // remove ticket reservation |
211 | - $this->decrease_reserved( $qty ); |
|
212 | - $this->set_sold( $sold ); |
|
211 | + $this->decrease_reserved($qty); |
|
212 | + $this->set_sold($sold); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | * decrements (subtracts) sold amount passed by $qty |
219 | 219 | * @param int $qty |
220 | 220 | */ |
221 | - public function decrease_sold( $qty = 1 ) { |
|
221 | + public function decrease_sold($qty = 1) { |
|
222 | 222 | $sold = $this->sold() - $qty; |
223 | - $this->set_sold( $sold ); |
|
223 | + $this->set_sold($sold); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return int |
232 | 232 | */ |
233 | 233 | public function reserved() { |
234 | - return $this->get_raw( 'DTT_reserved' ); |
|
234 | + return $this->get_raw('DTT_reserved'); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @param int $reserved |
243 | 243 | */ |
244 | - public function set_reserved( $reserved ) { |
|
244 | + public function set_reserved($reserved) { |
|
245 | 245 | // reserved can not go below zero |
246 | - $reserved = max( 0, (int) $reserved ); |
|
247 | - $this->set( 'DTT_reserved', $reserved ); |
|
246 | + $reserved = max(0, (int) $reserved); |
|
247 | + $this->set('DTT_reserved', $reserved); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | * @param int $qty |
256 | 256 | * @return boolean |
257 | 257 | */ |
258 | - public function increase_reserved( $qty = 1 ) { |
|
259 | - $reserved = $this->reserved() + absint( $qty ); |
|
260 | - return $this->set_reserved( $reserved ); |
|
258 | + public function increase_reserved($qty = 1) { |
|
259 | + $reserved = $this->reserved() + absint($qty); |
|
260 | + return $this->set_reserved($reserved); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param int $qty |
269 | 269 | * @return boolean |
270 | 270 | */ |
271 | - public function decrease_reserved( $qty = 1 ) { |
|
272 | - $reserved = $this->reserved() - absint( $qty ); |
|
273 | - return $this->set_reserved( $reserved ); |
|
271 | + public function decrease_reserved($qty = 1) { |
|
272 | + $reserved = $this->reserved() - absint($qty); |
|
273 | + return $this->set_reserved($reserved); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return string |
292 | 292 | */ |
293 | 293 | public function name() { |
294 | - return $this->get( 'DTT_name' ); |
|
294 | + return $this->get('DTT_name'); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @return string |
302 | 302 | */ |
303 | 303 | public function description() { |
304 | - return $this->get( 'DTT_description' ); |
|
304 | + return $this->get('DTT_description'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @return boolean TRUE if is primary, FALSE if not. |
312 | 312 | */ |
313 | 313 | public function is_primary() { |
314 | - return $this->get( 'DTT_is_primary' ); |
|
314 | + return $this->get('DTT_is_primary'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @return int The order of the datetime for this event. |
322 | 322 | */ |
323 | 323 | public function order() { |
324 | - return $this->get( 'DTT_order' ); |
|
324 | + return $this->get('DTT_order'); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @return int |
332 | 332 | */ |
333 | 333 | public function parent() { |
334 | - return $this->get( 'DTT_parent' ); |
|
334 | + return $this->get('DTT_parent'); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | |
@@ -347,10 +347,10 @@ discard block |
||
347 | 347 | * @param bool $echo - whether we echo or return (note echoing uses "pretty" formats, otherwise we use the standard formats) |
348 | 348 | * @return string|bool string on success, FALSE on fail |
349 | 349 | */ |
350 | - private function _show_datetime( $date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE ) { |
|
350 | + private function _show_datetime($date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE) { |
|
351 | 351 | $field_name = "DTT_EVT_{$start_or_end}"; |
352 | - $dtt = $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo ); |
|
353 | - if ( ! $echo ) { |
|
352 | + $dtt = $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo); |
|
353 | + if ( ! $echo) { |
|
354 | 354 | return $dtt; |
355 | 355 | } |
356 | 356 | return ''; |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
366 | 366 | * @return mixed string on success, FALSE on fail |
367 | 367 | */ |
368 | - public function start_date( $dt_frmt = '' ) { |
|
369 | - return $this->_show_datetime( 'D', 'start', $dt_frmt ); |
|
368 | + public function start_date($dt_frmt = '') { |
|
369 | + return $this->_show_datetime('D', 'start', $dt_frmt); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * Echoes start_date() |
376 | 376 | * @param string $dt_frmt |
377 | 377 | */ |
378 | - public function e_start_date( $dt_frmt = '' ) { |
|
379 | - $this->_show_datetime( 'D', 'start', $dt_frmt, NULL, TRUE ); |
|
378 | + public function e_start_date($dt_frmt = '') { |
|
379 | + $this->_show_datetime('D', 'start', $dt_frmt, NULL, TRUE); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
389 | 389 | * @return mixed string on success, FALSE on fail |
390 | 390 | */ |
391 | - public function end_date( $dt_frmt = '' ) { |
|
392 | - return $this->_show_datetime( 'D', 'end', $dt_frmt ); |
|
391 | + public function end_date($dt_frmt = '') { |
|
392 | + return $this->_show_datetime('D', 'end', $dt_frmt); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * Echoes the end date. See end_date() |
399 | 399 | * @param string $dt_frmt |
400 | 400 | */ |
401 | - public function e_end_date( $dt_frmt = '' ) { |
|
402 | - $this->_show_datetime( 'D', 'end', $dt_frmt, NULL, TRUE ); |
|
401 | + public function e_end_date($dt_frmt = '') { |
|
402 | + $this->_show_datetime('D', 'end', $dt_frmt, NULL, TRUE); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | * @return mixed string on success, FALSE on fail |
415 | 415 | * @throws \EE_Error |
416 | 416 | */ |
417 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
418 | - $dt_frmt = ! empty( $dt_frmt ) ? $dt_frmt : $this->_dt_frmt; |
|
419 | - $start = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_start', $dt_frmt ) ); |
|
420 | - $end = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_end', $dt_frmt ) ); |
|
421 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
417 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
418 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
419 | + $start = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt)); |
|
420 | + $end = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt)); |
|
421 | + return $start !== $end ? $start.$conjunction.$end : $start; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param string $conjunction |
429 | 429 | * @throws \EE_Error |
430 | 430 | */ |
431 | - public function e_date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
432 | - echo $this->date_range( $dt_frmt, $conjunction ); |
|
431 | + public function e_date_range($dt_frmt = '', $conjunction = ' - ') { |
|
432 | + echo $this->date_range($dt_frmt, $conjunction); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
441 | 441 | * @return mixed string on success, FALSE on fail |
442 | 442 | */ |
443 | - public function start_time( $tm_format = '' ) { |
|
444 | - return $this->_show_datetime( 'T', 'start', NULL, $tm_format ); |
|
443 | + public function start_time($tm_format = '') { |
|
444 | + return $this->_show_datetime('T', 'start', NULL, $tm_format); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | /** |
450 | 450 | * @param string $tm_format |
451 | 451 | */ |
452 | - public function e_start_time( $tm_format = '' ) { |
|
453 | - $this->_show_datetime( 'T', 'start', NULL, $tm_format, TRUE ); |
|
452 | + public function e_start_time($tm_format = '') { |
|
453 | + $this->_show_datetime('T', 'start', NULL, $tm_format, TRUE); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
462 | 462 | * @return mixed string on success, FALSE on fail |
463 | 463 | */ |
464 | - public function end_time( $tm_format = '' ) { |
|
465 | - return $this->_show_datetime( 'T', 'end', NULL, $tm_format ); |
|
464 | + public function end_time($tm_format = '') { |
|
465 | + return $this->_show_datetime('T', 'end', NULL, $tm_format); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | /** |
471 | 471 | * @param string $tm_format |
472 | 472 | */ |
473 | - public function e_end_time( $tm_format = '' ) { |
|
474 | - $this->_show_datetime( 'T', 'end', NULL, $tm_format, TRUE ); |
|
473 | + public function e_end_time($tm_format = '') { |
|
474 | + $this->_show_datetime('T', 'end', NULL, $tm_format, TRUE); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | |
@@ -486,11 +486,11 @@ discard block |
||
486 | 486 | * @return mixed string on success, FALSE on fail |
487 | 487 | * @throws \EE_Error |
488 | 488 | */ |
489 | - public function time_range( $tm_format = '', $conjunction = ' - ' ) { |
|
490 | - $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
|
491 | - $start = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_start', $tm_format ) ); |
|
492 | - $end = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ) ); |
|
493 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
489 | + public function time_range($tm_format = '', $conjunction = ' - ') { |
|
490 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
491 | + $start = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_start', $tm_format)); |
|
492 | + $end = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_end', $tm_format)); |
|
493 | + return $start !== $end ? $start.$conjunction.$end : $start; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param string $conjunction |
501 | 501 | * @throws \EE_Error |
502 | 502 | */ |
503 | - public function e_time_range( $tm_format = '', $conjunction = ' - ' ) { |
|
504 | - echo $this->time_range( $tm_format, $conjunction ); |
|
503 | + public function e_time_range($tm_format = '', $conjunction = ' - ') { |
|
504 | + echo $this->time_range($tm_format, $conjunction); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | |
@@ -523,30 +523,30 @@ discard block |
||
523 | 523 | public function date_and_time_range( |
524 | 524 | $dt_format = '', |
525 | 525 | $tm_format = '', |
526 | - $conjunction = ' - ' , |
|
526 | + $conjunction = ' - ', |
|
527 | 527 | $separator = ' ' |
528 | 528 | ) { |
529 | - $dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt; |
|
530 | - $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
|
531 | - $full_format = $dt_format . $separator . $tm_format; |
|
529 | + $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
530 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
531 | + $full_format = $dt_format.$separator.$tm_format; |
|
532 | 532 | |
533 | 533 | //the range output depends on various conditions |
534 | - switch ( true ) { |
|
534 | + switch (true) { |
|
535 | 535 | //start date timestamp and end date timestamp are the same. |
536 | - case ( $this->get_raw( 'DTT_EVT_start' ) === $this->get_raw( 'DTT_EVT_end' ) ) : |
|
537 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ); |
|
536 | + case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')) : |
|
537 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
538 | 538 | break; |
539 | 539 | //start and end date are the same but times are different |
540 | - case ( $this->start_date() === $this->end_date() ) : |
|
541 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
|
540 | + case ($this->start_date() === $this->end_date()) : |
|
541 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
542 | 542 | . $conjunction |
543 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
543 | + . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
544 | 544 | break; |
545 | 545 | //all other conditions |
546 | 546 | default : |
547 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
|
547 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
548 | 548 | . $conjunction |
549 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
549 | + . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
550 | 550 | break; |
551 | 551 | } |
552 | 552 | return $output; |
@@ -564,8 +564,8 @@ discard block |
||
564 | 564 | * @return void |
565 | 565 | * @throws \EE_Error |
566 | 566 | */ |
567 | - public function e_date_and_time_range( $dt_format = '', $tm_format = '', $conjunction = ' - ' ) { |
|
568 | - echo $this->date_and_time_range( $dt_format, $tm_format, $conjunction ); |
|
567 | + public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') { |
|
568 | + echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | |
@@ -577,8 +577,8 @@ discard block |
||
577 | 577 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
578 | 578 | * @return mixed string on success, FALSE on fail |
579 | 579 | */ |
580 | - public function start_date_and_time( $dt_format = '', $tm_format = '' ) { |
|
581 | - return $this->_show_datetime( '', 'start', $dt_format, $tm_format ); |
|
580 | + public function start_date_and_time($dt_format = '', $tm_format = '') { |
|
581 | + return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | |
@@ -587,8 +587,8 @@ discard block |
||
587 | 587 | * @param string $dt_frmt |
588 | 588 | * @param string $tm_format |
589 | 589 | */ |
590 | - public function e_start_date_and_time( $dt_frmt = '', $tm_format = '' ) { |
|
591 | - $this->_show_datetime( '', 'start', $dt_frmt, $tm_format, TRUE ); |
|
590 | + public function e_start_date_and_time($dt_frmt = '', $tm_format = '') { |
|
591 | + $this->_show_datetime('', 'start', $dt_frmt, $tm_format, TRUE); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | * @param bool $round_up |
603 | 603 | * @return float|int|mixed |
604 | 604 | */ |
605 | - public function length( $units = 'seconds', $round_up = FALSE ) { |
|
606 | - $start = $this->get_raw( 'DTT_EVT_start' ); |
|
607 | - $end = $this->get_raw( 'DTT_EVT_end' ); |
|
605 | + public function length($units = 'seconds', $round_up = FALSE) { |
|
606 | + $start = $this->get_raw('DTT_EVT_start'); |
|
607 | + $end = $this->get_raw('DTT_EVT_end'); |
|
608 | 608 | $length_in_units = $end - $start; |
609 | - switch ( $units ) { |
|
609 | + switch ($units) { |
|
610 | 610 | //NOTE: We purposefully don't use "break;" in order to chain the divisions |
611 | 611 | /** @noinspection PhpMissingBreakStatementInspection */ |
612 | 612 | case 'days': |
@@ -619,10 +619,10 @@ discard block |
||
619 | 619 | $length_in_units /= 60; |
620 | 620 | case 'seconds': |
621 | 621 | default: |
622 | - $length_in_units = ceil( $length_in_units ); |
|
622 | + $length_in_units = ceil($length_in_units); |
|
623 | 623 | } |
624 | - if ( $round_up ) { |
|
625 | - $length_in_units = max( $length_in_units, 1 ); |
|
624 | + if ($round_up) { |
|
625 | + $length_in_units = max($length_in_units, 1); |
|
626 | 626 | } |
627 | 627 | return $length_in_units; |
628 | 628 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | * @return mixed string on success, FALSE on fail |
638 | 638 | */ |
639 | 639 | public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
640 | - return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format ); |
|
640 | + return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | |
@@ -646,8 +646,8 @@ discard block |
||
646 | 646 | * @param string $dt_frmt |
647 | 647 | * @param string $tm_format |
648 | 648 | */ |
649 | - public function e_end_date_and_time( $dt_frmt = '', $tm_format = '' ) { |
|
650 | - $this->_show_datetime( '', 'end', $dt_frmt, $tm_format, TRUE ); |
|
649 | + public function e_end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
650 | + $this->_show_datetime('', 'end', $dt_frmt, $tm_format, TRUE); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | * @return int |
659 | 659 | */ |
660 | 660 | public function start() { |
661 | - return $this->get_raw( 'DTT_EVT_start' ); |
|
661 | + return $this->get_raw('DTT_EVT_start'); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | * @return int |
670 | 670 | */ |
671 | 671 | public function end() { |
672 | - return $this->get_raw( 'DTT_EVT_end' ); |
|
672 | + return $this->get_raw('DTT_EVT_end'); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | * @return mixed int on success, FALSE on fail |
681 | 681 | */ |
682 | 682 | public function reg_limit() { |
683 | - return $this->get_raw( 'DTT_reg_limit' ); |
|
683 | + return $this->get_raw('DTT_reg_limit'); |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | |
@@ -708,15 +708,15 @@ discard block |
||
708 | 708 | * the spaces remaining for this particular datetime, hence the flag. |
709 | 709 | * @return int |
710 | 710 | */ |
711 | - public function spaces_remaining( $consider_tickets = FALSE ) { |
|
711 | + public function spaces_remaining($consider_tickets = FALSE) { |
|
712 | 712 | // tickets remaining available for purchase |
713 | 713 | //no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
714 | 714 | $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
715 | - if ( ! $consider_tickets ) { |
|
715 | + if ( ! $consider_tickets) { |
|
716 | 716 | return $dtt_remaining; |
717 | 717 | } |
718 | 718 | $tickets_remaining = $this->tickets_remaining(); |
719 | - return min( $dtt_remaining, $tickets_remaining ); |
|
719 | + return min($dtt_remaining, $tickets_remaining); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | |
@@ -727,19 +727,19 @@ discard block |
||
727 | 727 | * @param array $query_params like EEM_Base::get_all's |
728 | 728 | * @return int |
729 | 729 | */ |
730 | - public function tickets_remaining( $query_params = array() ) { |
|
730 | + public function tickets_remaining($query_params = array()) { |
|
731 | 731 | $sum = 0; |
732 | - $tickets = $this->tickets( $query_params ); |
|
733 | - if ( ! empty( $tickets ) ) { |
|
734 | - foreach ( $tickets as $ticket ) { |
|
735 | - if ( $ticket instanceof EE_Ticket ) { |
|
732 | + $tickets = $this->tickets($query_params); |
|
733 | + if ( ! empty($tickets)) { |
|
734 | + foreach ($tickets as $ticket) { |
|
735 | + if ($ticket instanceof EE_Ticket) { |
|
736 | 736 | // get the actual amount of tickets that can be sold |
737 | - $qty = $ticket->qty( 'saleable' ); |
|
738 | - if ( $qty === EE_INF ) { |
|
737 | + $qty = $ticket->qty('saleable'); |
|
738 | + if ($qty === EE_INF) { |
|
739 | 739 | return EE_INF; |
740 | 740 | } |
741 | 741 | // no negative ticket quantities plz |
742 | - if ( $qty > 0 ) { |
|
742 | + if ($qty > 0) { |
|
743 | 743 | $sum += $qty; |
744 | 744 | } |
745 | 745 | } |
@@ -756,8 +756,8 @@ discard block |
||
756 | 756 | * @param array $query_params like EEM_Base::get_all's |
757 | 757 | * @return int |
758 | 758 | */ |
759 | - public function sum_tickets_initially_available( $query_params = array() ) { |
|
760 | - return $this->sum_related( 'Ticket', $query_params, 'TKT_qty' ); |
|
759 | + public function sum_tickets_initially_available($query_params = array()) { |
|
760 | + return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | * @return int |
770 | 770 | */ |
771 | 771 | public function total_tickets_available_at_this_datetime() { |
772 | - return $this->spaces_remaining( true ); |
|
772 | + return $this->spaces_remaining(true); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | * @return boolean |
781 | 781 | */ |
782 | 782 | public function is_upcoming() { |
783 | - return ( $this->get_raw( 'DTT_EVT_start' ) > time() ); |
|
783 | + return ($this->get_raw('DTT_EVT_start') > time()); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * @return boolean |
791 | 791 | */ |
792 | 792 | public function is_active() { |
793 | - return ( $this->get_raw( 'DTT_EVT_start' ) < time() && $this->get_raw( 'DTT_EVT_end' ) > time() ); |
|
793 | + return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | * @return boolean |
801 | 801 | */ |
802 | 802 | public function is_expired() { |
803 | - return ( $this->get_raw( 'DTT_EVT_end' ) < time() ); |
|
803 | + return ($this->get_raw('DTT_EVT_end') < time()); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | |
@@ -811,16 +811,16 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function get_active_status() { |
813 | 813 | $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
814 | - if ( $total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1 ) { |
|
814 | + if ($total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1) { |
|
815 | 815 | return EE_Datetime::sold_out; |
816 | 816 | } |
817 | - if ( $this->is_expired() ) { |
|
817 | + if ($this->is_expired()) { |
|
818 | 818 | return EE_Datetime::expired; |
819 | 819 | } |
820 | - if ( $this->is_upcoming() ) { |
|
820 | + if ($this->is_upcoming()) { |
|
821 | 821 | return EE_Datetime::upcoming; |
822 | 822 | } |
823 | - if ( $this->is_active() ) { |
|
823 | + if ($this->is_active()) { |
|
824 | 824 | return EE_Datetime::active; |
825 | 825 | } |
826 | 826 | return NULL; |
@@ -834,24 +834,24 @@ discard block |
||
834 | 834 | * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
835 | 835 | * @return string |
836 | 836 | */ |
837 | - public function get_dtt_display_name( $use_dtt_name = FALSE ) { |
|
838 | - if ( $use_dtt_name ) { |
|
837 | + public function get_dtt_display_name($use_dtt_name = FALSE) { |
|
838 | + if ($use_dtt_name) { |
|
839 | 839 | $dtt_name = $this->name(); |
840 | - if ( !empty( $dtt_name ) ) { |
|
840 | + if ( ! empty($dtt_name)) { |
|
841 | 841 | return $dtt_name; |
842 | 842 | } |
843 | 843 | } |
844 | 844 | //first condition is to see if the months are different |
845 | - if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) ) { |
|
846 | - $display_date = $this->start_date( 'M j\, Y g:i a' ) . ' - ' . $this->end_date( 'M j\, Y g:i a' ); |
|
845 | + if (date('m', $this->get_raw('DTT_EVT_start')) != date('m', $this->get_raw('DTT_EVT_end'))) { |
|
846 | + $display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a'); |
|
847 | 847 | //next condition is if its the same month but different day |
848 | 848 | } |
849 | 849 | else { |
850 | - if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) == date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) && date( 'd', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'd', $this->get_raw( 'DTT_EVT_end' ) ) ) { |
|
851 | - $display_date = $this->start_date( 'M j\, g:i a' ) . ' - ' . $this->end_date( 'M j\, g:i a Y' ); |
|
850 | + if (date('m', $this->get_raw('DTT_EVT_start')) == date('m', $this->get_raw('DTT_EVT_end')) && date('d', $this->get_raw('DTT_EVT_start')) != date('d', $this->get_raw('DTT_EVT_end'))) { |
|
851 | + $display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y'); |
|
852 | 852 | } |
853 | 853 | else { |
854 | - $display_date = $this->start_date( 'F j\, Y' ) . ' @ ' . $this->start_date( 'g:i a' ) . ' - ' . $this->end_date( 'g:i a' ); |
|
854 | + $display_date = $this->start_date('F j\, Y').' @ '.$this->start_date('g:i a').' - '.$this->end_date('g:i a'); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | return $display_date; |
@@ -865,8 +865,8 @@ discard block |
||
865 | 865 | *@param array $query_params see EEM_Base::get_all() |
866 | 866 | * @return EE_Ticket[] |
867 | 867 | */ |
868 | - public function tickets( $query_params = array() ) { |
|
869 | - return $this->get_many_related( 'Ticket', $query_params ); |
|
868 | + public function tickets($query_params = array()) { |
|
869 | + return $this->get_many_related('Ticket', $query_params); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | |
@@ -876,21 +876,21 @@ discard block |
||
876 | 876 | * @param array $query_params like EEM_Base::get_all's |
877 | 877 | * @return EE_Ticket[] |
878 | 878 | */ |
879 | - public function ticket_types_available_for_purchase( $query_params = array() ) { |
|
879 | + public function ticket_types_available_for_purchase($query_params = array()) { |
|
880 | 880 | // first check if datetime is valid |
881 | - if ( ! ( $this->is_upcoming() || $this->is_active() ) || $this->sold_out() ) { |
|
881 | + if ( ! ($this->is_upcoming() || $this->is_active()) || $this->sold_out()) { |
|
882 | 882 | return array(); |
883 | 883 | } |
884 | - if ( empty( $query_params ) ) { |
|
884 | + if (empty($query_params)) { |
|
885 | 885 | $query_params = array( |
886 | 886 | array( |
887 | - 'TKT_start_date' => array( '<=', EEM_Ticket::instance()->current_time_for_query( 'TKT_start_date' ) ), |
|
888 | - 'TKT_end_date' => array( '>=', EEM_Ticket::instance()->current_time_for_query( 'TKT_end_date' ) ), |
|
887 | + 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
888 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
889 | 889 | 'TKT_deleted' => false |
890 | 890 | ) |
891 | 891 | ); |
892 | 892 | } |
893 | - return $this->tickets( $query_params ); |
|
893 | + return $this->tickets($query_params); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * @return EE_Event |
901 | 901 | */ |
902 | 902 | public function event() { |
903 | - return $this->get_first_related( 'Event' ); |
|
903 | + return $this->get_first_related('Event'); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | |
@@ -912,13 +912,13 @@ discard block |
||
912 | 912 | */ |
913 | 913 | public function update_sold() { |
914 | 914 | $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
915 | - array( array( |
|
915 | + array(array( |
|
916 | 916 | 'STS_ID' => EEM_Registration::status_id_approved, |
917 | 917 | 'REG_deleted' => 0, |
918 | 918 | 'Ticket.Datetime.DTT_ID' => $this->ID(), |
919 | - ) ) |
|
919 | + )) |
|
920 | 920 | ); |
921 | - $this->set( 'DTT_sold', $count_regs_for_this_datetime ); |
|
921 | + $this->set('DTT_sold', $count_regs_for_this_datetime); |
|
922 | 922 | $this->save(); |
923 | 923 | return $count_regs_for_this_datetime; |
924 | 924 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @access public |
40 | 40 | * @param int $EVT_ID |
41 | - * @return object |
|
41 | + * @return null|boolean |
|
42 | 42 | */ |
43 | 43 | public static function get_event( $EVT_ID = 0 ) { |
44 | 44 | $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint( $EVT_ID ); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @access public |
118 | 118 | * @param int $EVT_ID |
119 | - * @return string |
|
119 | + * @return boolean |
|
120 | 120 | */ |
121 | 121 | public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
122 | 122 | $event = EEH_Event_View::get_event( $EVT_ID ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * event_active_status |
137 | 137 | * |
138 | 138 | * @access public |
139 | - * @param null $num_words |
|
139 | + * @param integer $num_words |
|
140 | 140 | * @param null $more |
141 | 141 | * @return string |
142 | 142 | */ |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * |
429 | 429 | * @access public |
430 | 430 | * @param int $EVT_ID |
431 | - * @param null $include_expired |
|
431 | + * @param false|null $include_expired |
|
432 | 432 | * @param bool $include_deleted |
433 | 433 | * @param null $limit |
434 | 434 | * @return EE_Datetime[] |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
149 | 149 | the_content(); |
150 | 150 | } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
151 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
151 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
152 | 152 | // AND an excerpt actually exists |
153 | 153 | the_excerpt(); |
154 | 154 | } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
155 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
155 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
156 | 156 | // but NO excerpt actually exists, so we need to create one |
157 | 157 | if ( ! empty( $num_words )) { |
158 | 158 | if ( empty( $more )) { |
@@ -161,32 +161,32 @@ discard block |
||
161 | 161 | $more .= ' class="more-link"'; |
162 | 162 | $more .= \EED_Events_Archive::link_target(); |
163 | 163 | $more .= '>' . $more_link_text . '</a>'; |
164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
164 | + $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
165 | 165 | } |
166 | 166 | $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
167 | 167 | |
168 | 168 | $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
169 | - } else { |
|
170 | - $content = get_the_content(); |
|
169 | + } else { |
|
170 | + $content = get_the_content(); |
|
171 | 171 | } |
172 | 172 | global $allowedtags; |
173 | 173 | // make sure links are allowed |
174 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
175 | - ? $allowedtags['a'] |
|
176 | - : array(); |
|
177 | - // as well as target attribute |
|
178 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
179 | - ? $allowedtags['a']['target'] |
|
180 | - : false; |
|
181 | - // but get previous value so we can reset it |
|
182 | - $prev_value = $allowedtags['a']['target']; |
|
183 | - $allowedtags['a']['target'] = true; |
|
174 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
175 | + ? $allowedtags['a'] |
|
176 | + : array(); |
|
177 | + // as well as target attribute |
|
178 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
179 | + ? $allowedtags['a']['target'] |
|
180 | + : false; |
|
181 | + // but get previous value so we can reset it |
|
182 | + $prev_value = $allowedtags['a']['target']; |
|
183 | + $allowedtags['a']['target'] = true; |
|
184 | 184 | $content = wp_kses( $content, $allowedtags ); |
185 | 185 | $content = strip_shortcodes( $content ); |
186 | 186 | echo apply_filters( 'the_content', $content ); |
187 | 187 | $allowedtags['a']['target'] = $prev_value; |
188 | - } else { |
|
189 | - // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
188 | + } else { |
|
189 | + // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
190 | 190 | echo apply_filters( 'the_content', '' ); |
191 | 191 | } |
192 | 192 | return ob_get_clean(); |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | $url = get_term_link( $term, 'espresso_venue_categories' ); |
235 | 235 | if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
236 | 236 | $category_links[] = '<a href="' . esc_url( $url ) |
237 | - . '" rel="tag"' |
|
238 | - . \EED_Events_Archive::link_target() |
|
239 | - .'>' |
|
240 | - . $term->name |
|
241 | - . '</a>'; |
|
237 | + . '" rel="tag"' |
|
238 | + . \EED_Events_Archive::link_target() |
|
239 | + .'>' |
|
240 | + . $term->name |
|
241 | + . '</a>'; |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
@@ -40,27 +40,27 @@ discard block |
||
40 | 40 | * @param int $EVT_ID |
41 | 41 | * @return object |
42 | 42 | */ |
43 | - public static function get_event( $EVT_ID = 0 ) { |
|
44 | - $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint( $EVT_ID ); |
|
43 | + public static function get_event($EVT_ID = 0) { |
|
44 | + $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint($EVT_ID); |
|
45 | 45 | // do we already have the Event you are looking for? |
46 | - if ( EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID ) { |
|
46 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
47 | 47 | return EEH_Event_View::$_event; |
48 | 48 | } |
49 | 49 | EEH_Event_View::$_event = NULL; |
50 | 50 | // international newspaper? |
51 | 51 | global $post; |
52 | 52 | // if this is being called from an EE_Event post, then we can just grab the attached EE_Event object |
53 | - if ( isset( $post->post_type ) && $post->post_type == 'espresso_events' || $EVT_ID ) { |
|
53 | + if (isset($post->post_type) && $post->post_type == 'espresso_events' || $EVT_ID) { |
|
54 | 54 | // d( $post ); |
55 | 55 | // grab the event we're looking for |
56 | - if ( isset( $post->EE_Event ) && ( $EVT_ID == 0 || ( $EVT_ID == $post->ID ))) { |
|
56 | + if (isset($post->EE_Event) && ($EVT_ID == 0 || ($EVT_ID == $post->ID))) { |
|
57 | 57 | EEH_Event_View::$_event = $post->EE_Event; |
58 | 58 | // d( EEH_Event_View::$_event ); |
59 | 59 | } |
60 | 60 | // now if we STILL do NOT have an EE_Event model object, BUT we have an Event ID... |
61 | - if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID ) { |
|
61 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
62 | 62 | // sigh... pull it from the db |
63 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
63 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
64 | 64 | // d( EEH_Event_View::$_event ); |
65 | 65 | } |
66 | 66 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param int $EVT_ID |
77 | 77 | * @return boolean |
78 | 78 | */ |
79 | - public static function display_ticket_selector( $EVT_ID = 0 ) { |
|
80 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
79 | + public static function display_ticket_selector($EVT_ID = 0) { |
|
80 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
81 | 81 | return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE; |
82 | 82 | } |
83 | 83 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param int $EVT_ID |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - public static function event_status( $EVT_ID = 0 ) { |
|
94 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
95 | - return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : ''; |
|
93 | + public static function event_status($EVT_ID = 0) { |
|
94 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
95 | + return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : ''; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param int $EVT_ID |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public static function event_active_status( $EVT_ID = 0 ) { |
|
108 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
107 | + public static function event_active_status($EVT_ID = 0) { |
|
108 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
109 | 109 | return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive'; |
110 | 110 | } |
111 | 111 | |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | * @param int $EVT_ID |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
|
122 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
121 | + public static function event_has_content_or_excerpt($EVT_ID = 0) { |
|
122 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
123 | 123 | $has_content_or_excerpt = FALSE; |
124 | - if ( $event instanceof EE_Event ) { |
|
125 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE; |
|
124 | + if ($event instanceof EE_Event) { |
|
125 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE; |
|
126 | 126 | } |
127 | - if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
127 | + if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) { |
|
128 | 128 | $has_content_or_excerpt = FALSE; |
129 | 129 | } |
130 | 130 | return $has_content_or_excerpt; |
@@ -140,34 +140,34 @@ discard block |
||
140 | 140 | * @param null $more |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
|
143 | + public static function event_content_or_excerpt($num_words = NULL, $more = NULL) { |
|
144 | 144 | global $post; |
145 | 145 | |
146 | 146 | ob_start(); |
147 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
147 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
149 | 149 | the_content(); |
150 | - } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
|
150 | + } else if ((is_archive() && has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
151 | 151 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
152 | 152 | // AND an excerpt actually exists |
153 | 153 | the_excerpt(); |
154 | - } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
|
154 | + } else if ((is_archive() && ! has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
155 | 155 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
156 | 156 | // but NO excerpt actually exists, so we need to create one |
157 | - if ( ! empty( $num_words )) { |
|
158 | - if ( empty( $more )) { |
|
159 | - $more_link_text = __( '(more…)' ); |
|
160 | - $more = ' <a href="' . get_permalink() . '"'; |
|
157 | + if ( ! empty($num_words)) { |
|
158 | + if (empty($more)) { |
|
159 | + $more_link_text = __('(more…)'); |
|
160 | + $more = ' <a href="'.get_permalink().'"'; |
|
161 | 161 | $more .= ' class="more-link"'; |
162 | 162 | $more .= \EED_Events_Archive::link_target(); |
163 | - $more .= '>' . $more_link_text . '</a>'; |
|
164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
163 | + $more .= '>'.$more_link_text.'</a>'; |
|
164 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
165 | 165 | } |
166 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
166 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
167 | 167 | |
168 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
168 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
169 | 169 | } else { |
170 | - $content = get_the_content(); |
|
170 | + $content = get_the_content(); |
|
171 | 171 | } |
172 | 172 | global $allowedtags; |
173 | 173 | // make sure links are allowed |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | // but get previous value so we can reset it |
182 | 182 | $prev_value = $allowedtags['a']['target']; |
183 | 183 | $allowedtags['a']['target'] = true; |
184 | - $content = wp_kses( $content, $allowedtags ); |
|
185 | - $content = strip_shortcodes( $content ); |
|
186 | - echo apply_filters( 'the_content', $content ); |
|
184 | + $content = wp_kses($content, $allowedtags); |
|
185 | + $content = strip_shortcodes($content); |
|
186 | + echo apply_filters('the_content', $content); |
|
187 | 187 | $allowedtags['a']['target'] = $prev_value; |
188 | 188 | } else { |
189 | 189 | // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
190 | - echo apply_filters( 'the_content', '' ); |
|
190 | + echo apply_filters('the_content', ''); |
|
191 | 191 | } |
192 | 192 | return ob_get_clean(); |
193 | 193 | } |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | * @param int $EVT_ID |
202 | 202 | * @return EE_Ticket[] |
203 | 203 | */ |
204 | - public static function event_tickets_available( $EVT_ID = 0 ) { |
|
205 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
204 | + public static function event_tickets_available($EVT_ID = 0) { |
|
205 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
206 | 206 | $tickets_available_for_purchase = array(); |
207 | - if( $event instanceof EE_Event ) { |
|
208 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE ); |
|
209 | - foreach( $datetimes as $datetime ) { |
|
210 | - $tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() ); |
|
207 | + if ($event instanceof EE_Event) { |
|
208 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE); |
|
209 | + foreach ($datetimes as $datetime) { |
|
210 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | return $tickets_available_for_purchase; |
@@ -223,17 +223,17 @@ discard block |
||
223 | 223 | * @param bool $hide_uncategorized |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) { |
|
226 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) { |
|
227 | 227 | $category_links = array(); |
228 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
229 | - if ( $event instanceof EE_Event ) { |
|
230 | - $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' ); |
|
231 | - if ( $event_categories ) { |
|
228 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
229 | + if ($event instanceof EE_Event) { |
|
230 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
231 | + if ($event_categories) { |
|
232 | 232 | // loop thru terms and create links |
233 | - foreach ( $event_categories as $term ) { |
|
234 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
235 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
236 | - $category_links[] = '<a href="' . esc_url( $url ) |
|
233 | + foreach ($event_categories as $term) { |
|
234 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
235 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
236 | + $category_links[] = '<a href="'.esc_url($url) |
|
237 | 237 | . '" rel="tag"' |
238 | 238 | . \EED_Events_Archive::link_target() |
239 | 239 | .'>' |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | - return implode( ', ', $category_links ); |
|
246 | + return implode(', ', $category_links); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | * @param int $EVT_ID |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
261 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
262 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
263 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
260 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
261 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
262 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
263 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | |
@@ -274,10 +274,10 @@ discard block |
||
274 | 274 | * @param int $EVT_ID |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
278 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
279 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
280 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
277 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
278 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
279 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
280 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | |
@@ -291,10 +291,10 @@ discard block |
||
291 | 291 | * @param int $EVT_ID |
292 | 292 | * @return string |
293 | 293 | */ |
294 | - public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
295 | - $datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID ); |
|
296 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
297 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
294 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
295 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
296 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
297 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | * @param int $EVT_ID |
309 | 309 | * @return string |
310 | 310 | */ |
311 | - public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
312 | - $datetime = EEH_Event_View::get_latest_date_obj( $EVT_ID ); |
|
313 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
314 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
311 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
312 | + $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
313 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
314 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | * @param int $EVT_ID |
324 | 324 | * @return string |
325 | 325 | */ |
326 | - public static function event_date_as_calendar_page( $EVT_ID = 0 ) { |
|
327 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
328 | - if ( $datetime instanceof EE_Datetime ) { |
|
326 | + public static function event_date_as_calendar_page($EVT_ID = 0) { |
|
327 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
328 | + if ($datetime instanceof EE_Datetime) { |
|
329 | 329 | ?> |
330 | 330 | <div class="event-date-calendar-page-dv"> |
331 | - <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div> |
|
332 | - <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div> |
|
331 | + <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div> |
|
332 | + <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div> |
|
333 | 333 | </div> |
334 | 334 | <?php |
335 | 335 | } |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | * @param int $EVT_ID |
345 | 345 | * @return string |
346 | 346 | */ |
347 | - public static function get_primary_date_obj( $EVT_ID = 0 ) { |
|
348 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
349 | - if ( $event instanceof EE_Event ) { |
|
347 | + public static function get_primary_date_obj($EVT_ID = 0) { |
|
348 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
349 | + if ($event instanceof EE_Event) { |
|
350 | 350 | $datetimes = $event->get_many_related( |
351 | 351 | 'Datetime', |
352 | 352 | array( |
353 | 353 | 'limit' => 1, |
354 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
354 | + 'order_by' => array('DTT_order' => 'ASC') |
|
355 | 355 | ) |
356 | 356 | ); |
357 | - return reset( $datetimes ); |
|
357 | + return reset($datetimes); |
|
358 | 358 | } else { |
359 | 359 | return FALSE; |
360 | 360 | } |
@@ -369,17 +369,17 @@ discard block |
||
369 | 369 | * @param int $EVT_ID |
370 | 370 | * @return string |
371 | 371 | */ |
372 | - public static function get_last_date_obj( $EVT_ID = 0 ) { |
|
373 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
374 | - if ( $event instanceof EE_Event ) { |
|
372 | + public static function get_last_date_obj($EVT_ID = 0) { |
|
373 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
374 | + if ($event instanceof EE_Event) { |
|
375 | 375 | $datetimes = $event->get_many_related( |
376 | 376 | 'Datetime', |
377 | 377 | array( |
378 | 378 | 'limit' => 1, |
379 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
379 | + 'order_by' => array('DTT_order' => 'DESC') |
|
380 | 380 | ) |
381 | 381 | ); |
382 | - return end( $datetimes ); |
|
382 | + return end($datetimes); |
|
383 | 383 | } else { |
384 | 384 | return FALSE; |
385 | 385 | } |
@@ -394,17 +394,17 @@ discard block |
||
394 | 394 | * @param int $EVT_ID |
395 | 395 | * @return string |
396 | 396 | */ |
397 | - public static function get_earliest_date_obj( $EVT_ID = 0 ) { |
|
398 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
399 | - if ( $event instanceof EE_Event ) { |
|
397 | + public static function get_earliest_date_obj($EVT_ID = 0) { |
|
398 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
399 | + if ($event instanceof EE_Event) { |
|
400 | 400 | $datetimes = $event->get_many_related( |
401 | 401 | 'Datetime', |
402 | 402 | array( |
403 | 403 | 'limit' => 1, |
404 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
404 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
405 | 405 | ) |
406 | 406 | ); |
407 | - return reset( $datetimes ); |
|
407 | + return reset($datetimes); |
|
408 | 408 | } else { |
409 | 409 | return FALSE; |
410 | 410 | } |
@@ -419,17 +419,17 @@ discard block |
||
419 | 419 | * @param int $EVT_ID |
420 | 420 | * @return string |
421 | 421 | */ |
422 | - public static function get_latest_date_obj( $EVT_ID = 0 ) { |
|
423 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
424 | - if ( $event instanceof EE_Event ) { |
|
422 | + public static function get_latest_date_obj($EVT_ID = 0) { |
|
423 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
424 | + if ($event instanceof EE_Event) { |
|
425 | 425 | $datetimes = $event->get_many_related( |
426 | 426 | 'Datetime', |
427 | 427 | array( |
428 | 428 | 'limit' => 1, |
429 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
429 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
430 | 430 | ) |
431 | 431 | ); |
432 | - return end( $datetimes ); |
|
432 | + return end($datetimes); |
|
433 | 433 | } else { |
434 | 434 | return FALSE; |
435 | 435 | } |
@@ -447,17 +447,17 @@ discard block |
||
447 | 447 | * @param null $limit |
448 | 448 | * @return EE_Datetime[] |
449 | 449 | */ |
450 | - public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) { |
|
451 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
452 | - if($include_expired === null){ |
|
453 | - if($event instanceof EE_Event && $event->is_expired()){ |
|
450 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) { |
|
451 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
452 | + if ($include_expired === null) { |
|
453 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
454 | 454 | $include_expired = true; |
455 | - }else{ |
|
455 | + } else { |
|
456 | 456 | $include_expired = false; |
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - if ( $event instanceof EE_Event ) { |
|
460 | + if ($event instanceof EE_Event) { |
|
461 | 461 | return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
462 | 462 | } else { |
463 | 463 | return array(); |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | * @param int $EVT_ID |
474 | 474 | * @return string |
475 | 475 | */ |
476 | - public static function event_link_url( $EVT_ID = 0 ) { |
|
477 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
478 | - if ( $event instanceof EE_Event ) { |
|
479 | - $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() ); |
|
480 | - return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url; |
|
476 | + public static function event_link_url($EVT_ID = 0) { |
|
477 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
478 | + if ($event instanceof EE_Event) { |
|
479 | + $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
480 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url; |
|
481 | 481 | } |
482 | 482 | return NULL; |
483 | 483 | } |
@@ -491,10 +491,10 @@ discard block |
||
491 | 491 | * @param int $EVT_ID |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - public static function event_phone( $EVT_ID = 0 ) { |
|
495 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
496 | - if ( $event instanceof EE_Event ) { |
|
497 | - return EEH_Schema::telephone( $event->phone() ); |
|
494 | + public static function event_phone($EVT_ID = 0) { |
|
495 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
496 | + if ($event instanceof EE_Event) { |
|
497 | + return EEH_Schema::telephone($event->phone()); |
|
498 | 498 | } |
499 | 499 | return NULL; |
500 | 500 | } |
@@ -511,26 +511,26 @@ discard block |
||
511 | 511 | * @param string $after |
512 | 512 | * @return string |
513 | 513 | */ |
514 | - public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) { |
|
515 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
516 | - if ( $event instanceof EE_Event ) { |
|
514 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') { |
|
515 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
516 | + if ($event instanceof EE_Event) { |
|
517 | 517 | // can the user edit this post ? |
518 | - if ( current_user_can( 'edit_post', $event->ID() )) { |
|
518 | + if (current_user_can('edit_post', $event->ID())) { |
|
519 | 519 | // set link text |
520 | - $link_text = ! empty( $link ) ? $link : __('edit this event'); |
|
520 | + $link_text = ! empty($link) ? $link : __('edit this event'); |
|
521 | 521 | // generate nonce |
522 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
522 | + $nonce = wp_create_nonce('edit_nonce'); |
|
523 | 523 | // generate url to event editor for this event |
524 | - $url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() ); |
|
524 | + $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url()); |
|
525 | 525 | // get edit CPT text |
526 | - $post_type_obj = get_post_type_object( 'espresso_events' ); |
|
526 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
527 | 527 | // build final link html |
528 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
529 | - $link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"'; |
|
528 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
529 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
530 | 530 | $link .= \EED_Events_Archive::link_target(); |
531 | - $link .='>' . $link_text . '</a>'; |
|
531 | + $link .= '>'.$link_text.'</a>'; |
|
532 | 532 | // put it all together |
533 | - return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after; |
|
533 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
534 | 534 | } |
535 | 535 | } |
536 | 536 | return ''; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $VNU_ID |
70 | 70 | ); |
71 | 71 | extract($template_args, EXTR_OVERWRITE); |
72 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
72 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @param string $location |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - public static function location( $location = null ) { |
|
86 | - return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
85 | + public static function location($location = null) { |
|
86 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
87 | 87 | . $location |
88 | 88 | . '</div>' : ''; |
89 | 89 | } |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @param string $name |
99 | 99 | * @return string |
100 | 100 | */ |
101 | - public static function name( $name = null ) { |
|
102 | - return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
101 | + public static function name($name = null) { |
|
102 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * @param EEI_Address $obj_with_address |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - public static function streetAddress( EEI_Address $obj_with_address = null ) { |
|
115 | + public static function streetAddress(EEI_Address $obj_with_address = null) { |
|
116 | 116 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
117 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
117 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | * @param EEI_Address $obj_with_address |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) { |
|
130 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) { |
|
131 | 131 | // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
132 | - if ( preg_match( |
|
132 | + if (preg_match( |
|
133 | 133 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
134 | 134 | $obj_with_address->address2() |
135 | - ) ) { |
|
135 | + )) { |
|
136 | 136 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
137 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
137 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
138 | 138 | } else { |
139 | 139 | return $obj_with_address->address2(); |
140 | 140 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * @param EEI_Address $obj_with_address |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public static function addressLocality( EEI_Address $obj_with_address = null ) { |
|
153 | + public static function addressLocality(EEI_Address $obj_with_address = null) { |
|
154 | 154 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
155 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
155 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * @param EEI_Address $obj_with_address |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - public static function addressRegion( EEI_Address $obj_with_address = null ) { |
|
168 | + public static function addressRegion(EEI_Address $obj_with_address = null) { |
|
169 | 169 | $state = $obj_with_address->state_name(); |
170 | - if ( ! empty( $state ) ) { |
|
171 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
170 | + if ( ! empty($state)) { |
|
171 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
172 | 172 | } else { |
173 | 173 | return ''; |
174 | 174 | } |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * @param EEI_Address $obj_with_address |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - public static function addressCountry( EEI_Address $obj_with_address = null ) { |
|
187 | + public static function addressCountry(EEI_Address $obj_with_address = null) { |
|
188 | 188 | $country = $obj_with_address->country_name(); |
189 | - if ( ! empty( $country ) ) { |
|
190 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
189 | + if ( ! empty($country)) { |
|
190 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
191 | 191 | } else { |
192 | 192 | return ''; |
193 | 193 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param EEI_Address $obj_with_address |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - public static function postalCode( EEI_Address $obj_with_address = null ) { |
|
206 | + public static function postalCode(EEI_Address $obj_with_address = null) { |
|
207 | 207 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
208 | 208 | . $obj_with_address->zip() |
209 | 209 | . '</span>' : ''; |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @param string $phone_nmbr |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - public static function telephone( $phone_nmbr = null ) { |
|
223 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
222 | + public static function telephone($phone_nmbr = null) { |
|
223 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
224 | 224 | : ''; |
225 | 225 | } |
226 | 226 | |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
237 | 237 | * @return string (link) |
238 | 238 | */ |
239 | - public static function url( $url = null, $text = null, $attributes = array() ) { |
|
239 | + public static function url($url = null, $text = null, $attributes = array()) { |
|
240 | 240 | $atts = ''; |
241 | - foreach ( $attributes as $attribute => $value ) { |
|
242 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
241 | + foreach ($attributes as $attribute => $value) { |
|
242 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
243 | 243 | } |
244 | 244 | $text = $text !== null && $text !== '' ? $text : $url; |
245 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
245 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
246 | 246 | : ''; |
247 | 247 | } |
248 | 248 |
@@ -17,62 +17,62 @@ discard block |
||
17 | 17 | class EEH_Schema { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * generates JSON-based linked data for an event |
|
22 | - * |
|
23 | - * @param \EE_Event $event |
|
24 | - */ |
|
25 | - public static function add_json_linked_data_for_event(\EE_Event $event) |
|
26 | - { |
|
27 | - $template_args = array( |
|
28 | - 'event_permalink' => '', |
|
29 | - 'event_name' => '', |
|
30 | - 'event_description' => '', |
|
31 | - 'event_start' => '', |
|
32 | - 'event_end' => '', |
|
33 | - 'currency' => '', |
|
34 | - 'event_tickets' => array(), |
|
35 | - 'venue_name' => '', |
|
36 | - 'venue_url' => '', |
|
37 | - 'venue_locality' => '', |
|
38 | - 'venue_region' => '', |
|
39 | - 'event_image' => '', |
|
40 | - ); |
|
41 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
42 | - $template_args['event_name'] = $event->name(); |
|
43 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
44 | - $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM); |
|
45 | - $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM); |
|
46 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
47 | - foreach ($event->tickets() as $ticket) { |
|
48 | - $ID = $ticket->ID(); |
|
49 | - $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
50 | - $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
51 | - $template_args['event_tickets'][$ID]['price'] = number_format( |
|
52 | - $ticket->price(), |
|
53 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
54 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
55 | - EE_Registry::instance()->CFG->currency->thsnds |
|
56 | - ); |
|
57 | - } |
|
58 | - $VNU_ID = espresso_venue_id(); |
|
59 | - if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
60 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
61 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
62 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
63 | - $template_args['venue_locality'] = $venue->city(); |
|
64 | - $template_args['venue_region'] = $venue->state_name(); |
|
65 | - } |
|
66 | - $template_args['event_image'] = $event->feature_image_url(); |
|
67 | - $template_args = apply_filters( |
|
68 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
69 | - $template_args, |
|
70 | - $event, |
|
71 | - $VNU_ID |
|
72 | - ); |
|
73 | - extract($template_args, EXTR_OVERWRITE); |
|
74 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
75 | - } |
|
20 | + /** |
|
21 | + * generates JSON-based linked data for an event |
|
22 | + * |
|
23 | + * @param \EE_Event $event |
|
24 | + */ |
|
25 | + public static function add_json_linked_data_for_event(\EE_Event $event) |
|
26 | + { |
|
27 | + $template_args = array( |
|
28 | + 'event_permalink' => '', |
|
29 | + 'event_name' => '', |
|
30 | + 'event_description' => '', |
|
31 | + 'event_start' => '', |
|
32 | + 'event_end' => '', |
|
33 | + 'currency' => '', |
|
34 | + 'event_tickets' => array(), |
|
35 | + 'venue_name' => '', |
|
36 | + 'venue_url' => '', |
|
37 | + 'venue_locality' => '', |
|
38 | + 'venue_region' => '', |
|
39 | + 'event_image' => '', |
|
40 | + ); |
|
41 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
42 | + $template_args['event_name'] = $event->name(); |
|
43 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
44 | + $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM); |
|
45 | + $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM); |
|
46 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
47 | + foreach ($event->tickets() as $ticket) { |
|
48 | + $ID = $ticket->ID(); |
|
49 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
50 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
51 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
52 | + $ticket->price(), |
|
53 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
54 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
55 | + EE_Registry::instance()->CFG->currency->thsnds |
|
56 | + ); |
|
57 | + } |
|
58 | + $VNU_ID = espresso_venue_id(); |
|
59 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
60 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
61 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
62 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
63 | + $template_args['venue_locality'] = $venue->city(); |
|
64 | + $template_args['venue_region'] = $venue->state_name(); |
|
65 | + } |
|
66 | + $template_args['event_image'] = $event->feature_image_url(); |
|
67 | + $template_args = apply_filters( |
|
68 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
69 | + $template_args, |
|
70 | + $event, |
|
71 | + $VNU_ID |
|
72 | + ); |
|
73 | + extract($template_args, EXTR_OVERWRITE); |
|
74 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | /** |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public static function location( $location = null ) { |
88 | 88 | return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
89 | - . $location |
|
90 | - . '</div>' : ''; |
|
89 | + . $location |
|
90 | + . '</div>' : ''; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public static function postalCode( EEI_Address $obj_with_address = null ) { |
209 | 209 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
210 | - . $obj_with_address->zip() |
|
211 | - . '</span>' : ''; |
|
210 | + . $obj_with_address->zip() |
|
211 | + . '</span>' : ''; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 |