@@ -14,817 +14,817 @@ discard block |
||
14 | 14 | class EEM_Registration extends EEM_Soft_Delete_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var EEM_Registration $_instance |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values |
|
24 | - * are status codes (eg, approved, cancelled, etc) |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - private static $_reg_status; |
|
29 | - |
|
30 | - /** |
|
31 | - * The value of REG_count for a primary registrant |
|
32 | - */ |
|
33 | - const PRIMARY_REGISTRANT_COUNT = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration. |
|
37 | - * Initial status for registrations when they are first created |
|
38 | - * Payments are NOT allowed. |
|
39 | - * Automatically toggled to whatever the default Event registration status is upon completion of the attendee |
|
40 | - * information reg step NO space reserved. Registration is NOT active |
|
41 | - */ |
|
42 | - const status_id_incomplete = 'RIC'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration. |
|
46 | - * Payments are NOT allowed. |
|
47 | - * Event Admin must manually toggle STS_ID for it to change |
|
48 | - * No space reserved. |
|
49 | - * Registration is active |
|
50 | - */ |
|
51 | - const status_id_not_approved = 'RNA'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT . |
|
55 | - * Payments are allowed. |
|
56 | - * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
57 | - * No space reserved. |
|
58 | - * Registration is active |
|
59 | - */ |
|
60 | - const status_id_pending_payment = 'RPP'; |
|
61 | - |
|
62 | - /** |
|
63 | - * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST . |
|
64 | - * Payments are allowed. |
|
65 | - * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
66 | - * No space reserved. |
|
67 | - * Registration is active |
|
68 | - */ |
|
69 | - const status_id_wait_list = 'RWL'; |
|
70 | - |
|
71 | - /** |
|
72 | - * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration. |
|
73 | - * the TXN may or may not be completed ( paid in full ) |
|
74 | - * Payments are allowed. |
|
75 | - * A space IS reserved. |
|
76 | - * Registration is active |
|
77 | - */ |
|
78 | - const status_id_approved = 'RAP'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee. |
|
82 | - * Payments are NOT allowed. |
|
83 | - * NO space reserved. |
|
84 | - * Registration is NOT active |
|
85 | - */ |
|
86 | - const status_id_cancelled = 'RCN'; |
|
87 | - |
|
88 | - /** |
|
89 | - * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin |
|
90 | - * Payments are NOT allowed. |
|
91 | - * No space reserved. |
|
92 | - * Registration is NOT active |
|
93 | - */ |
|
94 | - const status_id_declined = 'RDC'; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var TableAnalysis $table_analysis |
|
98 | - */ |
|
99 | - protected $_table_analysis; |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * private constructor to prevent direct creation |
|
104 | - * |
|
105 | - * @Constructor |
|
106 | - * @access protected |
|
107 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
108 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
109 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
110 | - * timezone in the 'timezone_string' wp option) |
|
111 | - * @throws EE_Error |
|
112 | - */ |
|
113 | - protected function __construct($timezone = null) |
|
114 | - { |
|
115 | - $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
116 | - $this->singular_item = esc_html__('Registration', 'event_espresso'); |
|
117 | - $this->plural_item = esc_html__('Registrations', 'event_espresso'); |
|
118 | - $this->_tables = array( |
|
119 | - 'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'), |
|
120 | - ); |
|
121 | - $this->_fields = array( |
|
122 | - 'Registration' => array( |
|
123 | - 'REG_ID' => new EE_Primary_Key_Int_Field( |
|
124 | - 'REG_ID', |
|
125 | - esc_html__('Registration ID', 'event_espresso') |
|
126 | - ), |
|
127 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
128 | - 'EVT_ID', |
|
129 | - esc_html__('Event ID', 'event_espresso'), |
|
130 | - false, |
|
131 | - 0, |
|
132 | - 'Event' |
|
133 | - ), |
|
134 | - 'ATT_ID' => new EE_Foreign_Key_Int_Field( |
|
135 | - 'ATT_ID', |
|
136 | - esc_html__('Attendee ID', 'event_espresso'), |
|
137 | - false, |
|
138 | - 0, |
|
139 | - 'Attendee' |
|
140 | - ), |
|
141 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | - 'TXN_ID', |
|
143 | - esc_html__('Transaction ID', 'event_espresso'), |
|
144 | - false, |
|
145 | - 0, |
|
146 | - 'Transaction' |
|
147 | - ), |
|
148 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | - 'TKT_ID', |
|
150 | - esc_html__('Ticket ID', 'event_espresso'), |
|
151 | - false, |
|
152 | - 0, |
|
153 | - 'Ticket' |
|
154 | - ), |
|
155 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
156 | - 'STS_ID', |
|
157 | - esc_html__('Status ID', 'event_espresso'), |
|
158 | - false, |
|
159 | - EEM_Registration::status_id_incomplete, |
|
160 | - 'Status' |
|
161 | - ), |
|
162 | - 'REG_date' => new EE_Datetime_Field( |
|
163 | - 'REG_date', |
|
164 | - esc_html__('Time registration occurred', 'event_espresso'), |
|
165 | - false, |
|
166 | - EE_Datetime_Field::now, |
|
167 | - $timezone |
|
168 | - ), |
|
169 | - 'REG_final_price' => new EE_Money_Field( |
|
170 | - 'REG_final_price', |
|
171 | - esc_html__('Registration\'s share of the transaction total', 'event_espresso'), |
|
172 | - false, |
|
173 | - 0 |
|
174 | - ), |
|
175 | - 'REG_paid' => new EE_Money_Field( |
|
176 | - 'REG_paid', |
|
177 | - esc_html__('Amount paid to date towards registration', 'event_espresso'), |
|
178 | - false, |
|
179 | - 0 |
|
180 | - ), |
|
181 | - 'REG_session' => new EE_Plain_Text_Field( |
|
182 | - 'REG_session', |
|
183 | - esc_html__('Session ID of registration', 'event_espresso'), |
|
184 | - false, |
|
185 | - '' |
|
186 | - ), |
|
187 | - 'REG_code' => new EE_Plain_Text_Field( |
|
188 | - 'REG_code', |
|
189 | - esc_html__('Unique Code for this registration', 'event_espresso'), |
|
190 | - false, |
|
191 | - '' |
|
192 | - ), |
|
193 | - 'REG_url_link' => new EE_Plain_Text_Field( |
|
194 | - 'REG_url_link', |
|
195 | - esc_html__('String to be used in URL for identifying registration', 'event_espresso'), |
|
196 | - false, |
|
197 | - '' |
|
198 | - ), |
|
199 | - 'REG_count' => new EE_Integer_Field( |
|
200 | - 'REG_count', |
|
201 | - esc_html__('Count of this registration in the group registration ', 'event_espresso'), |
|
202 | - true, |
|
203 | - 1 |
|
204 | - ), |
|
205 | - 'REG_group_size' => new EE_Integer_Field( |
|
206 | - 'REG_group_size', |
|
207 | - esc_html__('Number of registrations on this group', 'event_espresso'), |
|
208 | - false, |
|
209 | - 1 |
|
210 | - ), |
|
211 | - 'REG_att_is_going' => new EE_Boolean_Field( |
|
212 | - 'REG_att_is_going', |
|
213 | - esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'), |
|
214 | - false, |
|
215 | - false |
|
216 | - ), |
|
217 | - 'REG_deleted' => new EE_Trashed_Flag_Field( |
|
218 | - 'REG_deleted', |
|
219 | - esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'), |
|
220 | - false, |
|
221 | - false |
|
222 | - ), |
|
223 | - ), |
|
224 | - ); |
|
225 | - $this->_model_relations = array( |
|
226 | - 'Event' => new EE_Belongs_To_Relation(), |
|
227 | - 'Attendee' => new EE_Belongs_To_Relation(), |
|
228 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
229 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
230 | - 'Status' => new EE_Belongs_To_Relation(), |
|
231 | - 'Answer' => new EE_Has_Many_Relation(), |
|
232 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
233 | - 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
234 | - 'Payment' => new EE_HABTM_Relation('Registration_Payment'), |
|
235 | - 'Message' => new EE_Has_Many_Any_Relation(false) |
|
236 | - // allow deletes even if there are messages in the queue related |
|
237 | - ); |
|
238 | - $this->_model_chain_to_wp_user = 'Event'; |
|
239 | - parent::__construct($timezone); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * a list of ALL valid registration statuses currently in use within the system |
|
245 | - * generated by combining the filterable active and inactive reg status arrays |
|
246 | - * |
|
247 | - * @return array |
|
248 | - */ |
|
249 | - public static function reg_statuses() |
|
250 | - { |
|
251 | - return array_unique( |
|
252 | - array_merge( |
|
253 | - EEM_Registration::active_reg_statuses(), |
|
254 | - EEM_Registration::inactive_reg_statuses() |
|
255 | - ) |
|
256 | - ); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * reg_statuses_that_allow_payment |
|
262 | - * a filterable list of registration statuses that allow a registrant to make a payment |
|
263 | - * |
|
264 | - * @access public |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - public static function reg_statuses_that_allow_payment() |
|
268 | - { |
|
269 | - return apply_filters( |
|
270 | - 'FHEE__EEM_Registration__reg_statuses_that_allow_payment', |
|
271 | - array( |
|
272 | - EEM_Registration::status_id_approved, |
|
273 | - EEM_Registration::status_id_pending_payment, |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * active_reg_statuses |
|
281 | - * a filterable list of registration statuses that are considered active |
|
282 | - * |
|
283 | - * @access public |
|
284 | - * @return array |
|
285 | - */ |
|
286 | - public static function active_reg_statuses() |
|
287 | - { |
|
288 | - return apply_filters( |
|
289 | - 'FHEE__EEM_Registration__active_reg_statuses', |
|
290 | - array( |
|
291 | - EEM_Registration::status_id_approved, |
|
292 | - EEM_Registration::status_id_pending_payment, |
|
293 | - EEM_Registration::status_id_wait_list, |
|
294 | - EEM_Registration::status_id_not_approved, |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * inactive_reg_statuses |
|
302 | - * a filterable list of registration statuses that are not considered active |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - public static function inactive_reg_statuses() |
|
308 | - { |
|
309 | - return apply_filters( |
|
310 | - 'FHEE__EEM_Registration__inactive_reg_statuses', |
|
311 | - array( |
|
312 | - EEM_Registration::status_id_incomplete, |
|
313 | - EEM_Registration::status_id_cancelled, |
|
314 | - EEM_Registration::status_id_declined, |
|
315 | - ) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * closed_reg_statuses |
|
322 | - * a filterable list of registration statuses that are considered "closed" |
|
323 | - * meaning they should not be considered in any calculations involving monies owing |
|
324 | - * |
|
325 | - * @access public |
|
326 | - * @return array |
|
327 | - */ |
|
328 | - public static function closed_reg_statuses() |
|
329 | - { |
|
330 | - return apply_filters( |
|
331 | - 'FHEE__EEM_Registration__closed_reg_statuses', |
|
332 | - array( |
|
333 | - EEM_Registration::status_id_cancelled, |
|
334 | - EEM_Registration::status_id_declined, |
|
335 | - EEM_Registration::status_id_wait_list, |
|
336 | - ) |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * get list of registration statuses |
|
343 | - * |
|
344 | - * @access public |
|
345 | - * @param array $exclude The status ids to exclude from the returned results |
|
346 | - * @param bool $translated If true will return the values as singular localized strings |
|
347 | - * @return array |
|
348 | - * @throws EE_Error |
|
349 | - */ |
|
350 | - public static function reg_status_array($exclude = array(), $translated = false) |
|
351 | - { |
|
352 | - EEM_Registration::instance()->_get_registration_status_array($exclude); |
|
353 | - return $translated |
|
354 | - ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence') |
|
355 | - : self::$_reg_status; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * get list of registration statuses |
|
361 | - * |
|
362 | - * @access private |
|
363 | - * @param array $exclude |
|
364 | - * @return void |
|
365 | - * @throws EE_Error |
|
366 | - */ |
|
367 | - private function _get_registration_status_array($exclude = array()) |
|
368 | - { |
|
369 | - // in the very rare circumstance that we are deleting a model's table's data |
|
370 | - // and the table hasn't actually been created, this could have an error |
|
371 | - /** @type WPDB $wpdb */ |
|
372 | - global $wpdb; |
|
373 | - if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) { |
|
374 | - $results = $wpdb->get_results( |
|
375 | - "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'" |
|
376 | - ); |
|
377 | - self::$_reg_status = array(); |
|
378 | - foreach ($results as $status) { |
|
379 | - if (!in_array($status->STS_ID, $exclude, true)) { |
|
380 | - self::$_reg_status[ $status->STS_ID ] = $status->STS_code; |
|
381 | - } |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * Gets the injected table analyzer, or throws an exception |
|
389 | - * |
|
390 | - * @return TableAnalysis |
|
391 | - * @throws EE_Error |
|
392 | - */ |
|
393 | - protected function _get_table_analysis() |
|
394 | - { |
|
395 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
396 | - return $this->_table_analysis; |
|
397 | - } |
|
398 | - throw new EE_Error( |
|
399 | - sprintf( |
|
400 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
401 | - get_class($this) |
|
402 | - ) |
|
403 | - ); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * This returns a wpdb->results array of all registration date month and years matching the incoming query params |
|
409 | - * and grouped by month and year. |
|
410 | - * |
|
411 | - * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
412 | - * @return array |
|
413 | - * @throws EE_Error |
|
414 | - */ |
|
415 | - public function get_reg_months_and_years($where_params) |
|
416 | - { |
|
417 | - $query_params[0] = $where_params; |
|
418 | - $query_params['group_by'] = array('reg_year', 'reg_month'); |
|
419 | - $query_params['order_by'] = array('REG_date' => 'DESC'); |
|
420 | - $columns_to_select = array( |
|
421 | - 'reg_year' => array('YEAR(REG_date)', '%s'), |
|
422 | - 'reg_month' => array('MONTHNAME(REG_date)', '%s'), |
|
423 | - ); |
|
424 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * retrieve ALL registrations for a particular Attendee from db |
|
430 | - * |
|
431 | - * @param int $ATT_ID |
|
432 | - * @return EE_Base_Class[]|EE_Registration[]|null |
|
433 | - * @throws EE_Error |
|
434 | - */ |
|
435 | - public function get_all_registrations_for_attendee($ATT_ID = 0) |
|
436 | - { |
|
437 | - if (!$ATT_ID) { |
|
438 | - return null; |
|
439 | - } |
|
440 | - return $this->get_all(array(array('ATT_ID' => $ATT_ID))); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets a registration given their REG_url_link. Yes, this should usually |
|
446 | - * be passed via a GET parameter. |
|
447 | - * |
|
448 | - * @param string $REG_url_link |
|
449 | - * @return EE_Base_Class|EE_Registration|null |
|
450 | - * @throws EE_Error |
|
451 | - */ |
|
452 | - public function get_registration_for_reg_url_link($REG_url_link) |
|
453 | - { |
|
454 | - if (!$REG_url_link) { |
|
455 | - return null; |
|
456 | - } |
|
457 | - return $this->get_one(array(array('REG_url_link' => $REG_url_link))); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * retrieve registration for a specific transaction attendee from db |
|
463 | - * |
|
464 | - * @access public |
|
465 | - * @param int $TXN_ID |
|
466 | - * @param int $ATT_ID |
|
467 | - * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the |
|
468 | - * attendee number is required |
|
469 | - * @return mixed array on success, FALSE on fail |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) |
|
473 | - { |
|
474 | - return $this->get_one(array( |
|
475 | - array( |
|
476 | - 'TXN_ID' => $TXN_ID, |
|
477 | - 'ATT_ID' => $ATT_ID, |
|
478 | - ), |
|
479 | - 'limit' => array(min($att_nmbr - 1, 0), 1), |
|
480 | - )); |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * get the number of registrations per day for the Registration Admin page Reports Tab. |
|
486 | - * (doesn't utilize models because it's a fairly specialized query) |
|
487 | - * |
|
488 | - * @access public |
|
489 | - * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
|
490 | - * @return stdClass[] with properties regDate and total |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - public function get_registrations_per_day_report($period = '-1 month') |
|
494 | - { |
|
495 | - $sql_date = $this->convert_datetime_for_query( |
|
496 | - 'REG_date', |
|
497 | - date('Y-m-d H:i:s', strtotime($period)), |
|
498 | - 'Y-m-d H:i:s', |
|
499 | - 'UTC' |
|
500 | - ); |
|
501 | - $where = array( |
|
502 | - 'REG_date' => array('>=', $sql_date), |
|
503 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
504 | - ); |
|
505 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
506 | - $where['Event.EVT_wp_user'] = get_current_user_id(); |
|
507 | - } |
|
508 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date'); |
|
509 | - $results = $this->_get_all_wpdb_results( |
|
510 | - array( |
|
511 | - $where, |
|
512 | - 'group_by' => 'regDate', |
|
513 | - 'order_by' => array('REG_date' => 'ASC'), |
|
514 | - ), |
|
515 | - OBJECT, |
|
516 | - array( |
|
517 | - 'regDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
518 | - 'total' => array('count(REG_ID)', '%d'), |
|
519 | - ) |
|
520 | - ); |
|
521 | - return $results; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * Get the number of registrations per day including the count of registrations for each Registration Status. |
|
527 | - * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results. |
|
528 | - * |
|
529 | - * @param string $period |
|
530 | - * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID |
|
531 | - * @throws EE_Error |
|
532 | - * (i.e. RAP) |
|
533 | - */ |
|
534 | - public function get_registrations_per_day_and_per_status_report($period = '-1 month') |
|
535 | - { |
|
536 | - global $wpdb; |
|
537 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
538 | - $event_table = $wpdb->posts; |
|
539 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
540 | - // prepare the query interval for displaying offset |
|
541 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date'); |
|
542 | - // inner date query |
|
543 | - $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} "; |
|
544 | - $inner_where = ' WHERE'; |
|
545 | - // exclude events not authored by user if permissions in effect |
|
546 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
547 | - $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
|
548 | - $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
549 | - } |
|
550 | - $inner_where .= " REG_date >= '{$sql_date}'"; |
|
551 | - $inner_date_query .= $inner_where; |
|
552 | - // start main query |
|
553 | - $select = "SELECT DATE({$query_interval}) as Registration_REG_date, "; |
|
554 | - $join = ''; |
|
555 | - $join_parts = array(); |
|
556 | - $select_parts = array(); |
|
557 | - // loop through registration stati to do parts for each status. |
|
558 | - foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
559 | - if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
560 | - continue; |
|
561 | - } |
|
562 | - $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
|
563 | - $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'"; |
|
564 | - } |
|
565 | - // setup the selects |
|
566 | - $select .= implode(', ', $select_parts); |
|
567 | - $select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; |
|
568 | - // setup the joins |
|
569 | - $join .= implode(' LEFT JOIN ', $join_parts); |
|
570 | - // now let's put it all together |
|
571 | - $query = $select . $join . ' GROUP BY Registration_REG_date'; |
|
572 | - // and execute it |
|
573 | - return $wpdb->get_results($query, ARRAY_A); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * get the number of registrations per event for the Registration Admin page Reports Tab |
|
579 | - * |
|
580 | - * @access public |
|
581 | - * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
|
582 | - * @return stdClass[] each with properties event_name, reg_limit, and total |
|
583 | - * @throws EE_Error |
|
584 | - */ |
|
585 | - public function get_registrations_per_event_report($period = '-1 month') |
|
586 | - { |
|
587 | - $date_sql = $this->convert_datetime_for_query( |
|
588 | - 'REG_date', |
|
589 | - date('Y-m-d H:i:s', strtotime($period)), |
|
590 | - 'Y-m-d H:i:s', |
|
591 | - 'UTC' |
|
592 | - ); |
|
593 | - $where = array( |
|
594 | - 'REG_date' => array('>=', $date_sql), |
|
595 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
596 | - ); |
|
597 | - if ( |
|
598 | - !EE_Registry::instance()->CAP->current_user_can( |
|
599 | - 'ee_read_others_registrations', |
|
600 | - 'reg_per_event_report' |
|
601 | - ) |
|
602 | - ) { |
|
603 | - $where['Event.EVT_wp_user'] = get_current_user_id(); |
|
604 | - } |
|
605 | - $results = $this->_get_all_wpdb_results( |
|
606 | - array( |
|
607 | - $where, |
|
608 | - 'group_by' => 'Event.EVT_name', |
|
609 | - 'order_by' => 'Event.EVT_name', |
|
610 | - 'limit' => array(0, 24), |
|
611 | - ), |
|
612 | - OBJECT, |
|
613 | - array( |
|
614 | - 'event_name' => array('Event_CPT.post_title', '%s'), |
|
615 | - 'total' => array('COUNT(REG_ID)', '%s'), |
|
616 | - ) |
|
617 | - ); |
|
618 | - return $results; |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * Get the number of registrations per event grouped by registration status. |
|
624 | - * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results. |
|
625 | - * |
|
626 | - * @param string $period |
|
627 | - * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID |
|
628 | - * @throws EE_Error |
|
629 | - * (i.e. RAP) |
|
630 | - */ |
|
631 | - public function get_registrations_per_event_and_per_status_report($period = '-1 month') |
|
632 | - { |
|
633 | - global $wpdb; |
|
634 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
635 | - $event_table = $wpdb->posts; |
|
636 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
637 | - // inner date query |
|
638 | - $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
|
639 | - $inner_where = ' WHERE'; |
|
640 | - // exclude events not authored by user if permissions in effect |
|
641 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
642 | - $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
|
643 | - $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
644 | - } |
|
645 | - $inner_where .= " REG_date >= '{$sql_date}'"; |
|
646 | - $inner_date_query .= $inner_where; |
|
647 | - // build main query |
|
648 | - $select = 'SELECT Event.post_title as Registration_Event, '; |
|
649 | - $join = ''; |
|
650 | - $join_parts = array(); |
|
651 | - $select_parts = array(); |
|
652 | - // loop through registration stati to do parts for each status. |
|
653 | - foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
654 | - if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
655 | - continue; |
|
656 | - } |
|
657 | - $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
|
658 | - $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date"; |
|
659 | - } |
|
660 | - // setup the selects |
|
661 | - $select .= implode(', ', $select_parts); |
|
662 | - $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; |
|
663 | - // setup remaining joins |
|
664 | - $join .= implode(' LEFT JOIN ', $join_parts); |
|
665 | - // now put it all together |
|
666 | - $query = $select . $join . ' GROUP BY Registration_Event'; |
|
667 | - // and execute |
|
668 | - return $wpdb->get_results($query, ARRAY_A); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Returns the EE_Registration of the primary attendee on the transaction id provided |
|
674 | - * |
|
675 | - * @param int $TXN_ID |
|
676 | - * @return EE_Base_Class|EE_Registration|null |
|
677 | - * @throws EE_Error |
|
678 | - */ |
|
679 | - public function get_primary_registration_for_transaction_ID($TXN_ID = 0) |
|
680 | - { |
|
681 | - if (!$TXN_ID) { |
|
682 | - return null; |
|
683 | - } |
|
684 | - return $this->get_one(array( |
|
685 | - array( |
|
686 | - 'TXN_ID' => $TXN_ID, |
|
687 | - 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT, |
|
688 | - ), |
|
689 | - )); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * get_event_registration_count |
|
695 | - * |
|
696 | - * @access public |
|
697 | - * @param int $EVT_ID |
|
698 | - * @param boolean $for_incomplete_payments |
|
699 | - * @return int |
|
700 | - * @throws EE_Error |
|
701 | - */ |
|
702 | - public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false) |
|
703 | - { |
|
704 | - // we only count approved registrations towards registration limits |
|
705 | - $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved)); |
|
706 | - if ($for_incomplete_payments) { |
|
707 | - $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code); |
|
708 | - } |
|
709 | - return $this->count($query_params); |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * Deletes all registrations with no transactions. Note that this needs to be very efficient |
|
715 | - * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete |
|
716 | - * when joining tables like this. |
|
717 | - * |
|
718 | - * @global WPDB $wpdb |
|
719 | - * @return int number deleted |
|
720 | - * @throws EE_Error |
|
721 | - */ |
|
722 | - public function delete_registrations_with_no_transaction() |
|
723 | - { |
|
724 | - /** @type WPDB $wpdb */ |
|
725 | - global $wpdb; |
|
726 | - return $wpdb->query( |
|
727 | - 'DELETE r FROM ' |
|
728 | - . $this->table() |
|
729 | - . ' r LEFT JOIN ' |
|
730 | - . EEM_Transaction::instance()->table() |
|
731 | - . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' |
|
732 | - ); |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Count registrations checked into (or out of) a datetime |
|
738 | - * |
|
739 | - * @param int $DTT_ID datetime ID |
|
740 | - * @param boolean $checked_in whether to count registrations checked IN or OUT |
|
741 | - * @return int |
|
742 | - * @throws EE_Error |
|
743 | - */ |
|
744 | - public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true) |
|
745 | - { |
|
746 | - global $wpdb; |
|
747 | - // subquery to get latest checkin |
|
748 | - $query = $wpdb->prepare( |
|
749 | - 'SELECT ' |
|
750 | - . 'COUNT( DISTINCT checkins.REG_ID ) ' |
|
751 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
752 | - . '( SELECT ' |
|
753 | - . 'max( CHK_timestamp ) AS latest_checkin, ' |
|
754 | - . 'REG_ID AS REG_ID ' |
|
755 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' ' |
|
756 | - . 'WHERE DTT_ID=%d ' |
|
757 | - . 'GROUP BY REG_ID' |
|
758 | - . ') AS most_recent_checkin_per_reg ' |
|
759 | - . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID ' |
|
760 | - . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin ' |
|
761 | - . 'WHERE ' |
|
762 | - . 'checkins.CHK_in=%d', |
|
763 | - $DTT_ID, |
|
764 | - $checked_in |
|
765 | - ); |
|
766 | - return (int) $wpdb->get_var($query); |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * Count registrations checked into (or out of) an event. |
|
772 | - * |
|
773 | - * @param int $EVT_ID event ID |
|
774 | - * @param boolean $checked_in whether to count registrations checked IN or OUT |
|
775 | - * @return int |
|
776 | - * @throws EE_Error |
|
777 | - */ |
|
778 | - public function count_registrations_checked_into_event($EVT_ID, $checked_in = true) |
|
779 | - { |
|
780 | - global $wpdb; |
|
781 | - // subquery to get latest checkin |
|
782 | - $query = $wpdb->prepare( |
|
783 | - 'SELECT ' |
|
784 | - . 'COUNT( DISTINCT checkins.REG_ID ) ' |
|
785 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
786 | - . '( SELECT ' |
|
787 | - . 'max( CHK_timestamp ) AS latest_checkin, ' |
|
788 | - . 'REG_ID AS REG_ID ' |
|
789 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c ' |
|
790 | - . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d ' |
|
791 | - . 'ON c.DTT_ID=d.DTT_ID ' |
|
792 | - . 'WHERE d.EVT_ID=%d ' |
|
793 | - . 'GROUP BY REG_ID' |
|
794 | - . ') AS most_recent_checkin_per_reg ' |
|
795 | - . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID ' |
|
796 | - . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin ' |
|
797 | - . 'WHERE ' |
|
798 | - . 'checkins.CHK_in=%d', |
|
799 | - $EVT_ID, |
|
800 | - $checked_in |
|
801 | - ); |
|
802 | - return (int) $wpdb->get_var($query); |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * The purpose of this method is to retrieve an array of |
|
808 | - * EE_Registration objects that represent the latest registration |
|
809 | - * for each ATT_ID given in the function argument. |
|
810 | - * |
|
811 | - * @param array $attendee_ids |
|
812 | - * @return EE_Base_Class[]|EE_Registration[] |
|
813 | - * @throws EE_Error |
|
814 | - */ |
|
815 | - public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array()) |
|
816 | - { |
|
817 | - // first do a native wp_query to get the latest REG_ID's matching these attendees. |
|
818 | - global $wpdb; |
|
819 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
820 | - $attendee_table = $wpdb->posts; |
|
821 | - $attendee_ids = is_array($attendee_ids) |
|
822 | - ? array_map('absint', $attendee_ids) |
|
823 | - : array((int) $attendee_ids); |
|
824 | - $ATT_IDs = implode(',', $attendee_ids); |
|
825 | - // first we do a query to get the registration ids |
|
826 | - // (because a group by before order by causes the order by to be ignored.) |
|
827 | - $registration_id_query = " |
|
17 | + /** |
|
18 | + * @var EEM_Registration $_instance |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values |
|
24 | + * are status codes (eg, approved, cancelled, etc) |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + private static $_reg_status; |
|
29 | + |
|
30 | + /** |
|
31 | + * The value of REG_count for a primary registrant |
|
32 | + */ |
|
33 | + const PRIMARY_REGISTRANT_COUNT = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration. |
|
37 | + * Initial status for registrations when they are first created |
|
38 | + * Payments are NOT allowed. |
|
39 | + * Automatically toggled to whatever the default Event registration status is upon completion of the attendee |
|
40 | + * information reg step NO space reserved. Registration is NOT active |
|
41 | + */ |
|
42 | + const status_id_incomplete = 'RIC'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration. |
|
46 | + * Payments are NOT allowed. |
|
47 | + * Event Admin must manually toggle STS_ID for it to change |
|
48 | + * No space reserved. |
|
49 | + * Registration is active |
|
50 | + */ |
|
51 | + const status_id_not_approved = 'RNA'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT . |
|
55 | + * Payments are allowed. |
|
56 | + * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
57 | + * No space reserved. |
|
58 | + * Registration is active |
|
59 | + */ |
|
60 | + const status_id_pending_payment = 'RPP'; |
|
61 | + |
|
62 | + /** |
|
63 | + * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST . |
|
64 | + * Payments are allowed. |
|
65 | + * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee |
|
66 | + * No space reserved. |
|
67 | + * Registration is active |
|
68 | + */ |
|
69 | + const status_id_wait_list = 'RWL'; |
|
70 | + |
|
71 | + /** |
|
72 | + * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration. |
|
73 | + * the TXN may or may not be completed ( paid in full ) |
|
74 | + * Payments are allowed. |
|
75 | + * A space IS reserved. |
|
76 | + * Registration is active |
|
77 | + */ |
|
78 | + const status_id_approved = 'RAP'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee. |
|
82 | + * Payments are NOT allowed. |
|
83 | + * NO space reserved. |
|
84 | + * Registration is NOT active |
|
85 | + */ |
|
86 | + const status_id_cancelled = 'RCN'; |
|
87 | + |
|
88 | + /** |
|
89 | + * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin |
|
90 | + * Payments are NOT allowed. |
|
91 | + * No space reserved. |
|
92 | + * Registration is NOT active |
|
93 | + */ |
|
94 | + const status_id_declined = 'RDC'; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var TableAnalysis $table_analysis |
|
98 | + */ |
|
99 | + protected $_table_analysis; |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * private constructor to prevent direct creation |
|
104 | + * |
|
105 | + * @Constructor |
|
106 | + * @access protected |
|
107 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
108 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
109 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
110 | + * timezone in the 'timezone_string' wp option) |
|
111 | + * @throws EE_Error |
|
112 | + */ |
|
113 | + protected function __construct($timezone = null) |
|
114 | + { |
|
115 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
116 | + $this->singular_item = esc_html__('Registration', 'event_espresso'); |
|
117 | + $this->plural_item = esc_html__('Registrations', 'event_espresso'); |
|
118 | + $this->_tables = array( |
|
119 | + 'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'), |
|
120 | + ); |
|
121 | + $this->_fields = array( |
|
122 | + 'Registration' => array( |
|
123 | + 'REG_ID' => new EE_Primary_Key_Int_Field( |
|
124 | + 'REG_ID', |
|
125 | + esc_html__('Registration ID', 'event_espresso') |
|
126 | + ), |
|
127 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
128 | + 'EVT_ID', |
|
129 | + esc_html__('Event ID', 'event_espresso'), |
|
130 | + false, |
|
131 | + 0, |
|
132 | + 'Event' |
|
133 | + ), |
|
134 | + 'ATT_ID' => new EE_Foreign_Key_Int_Field( |
|
135 | + 'ATT_ID', |
|
136 | + esc_html__('Attendee ID', 'event_espresso'), |
|
137 | + false, |
|
138 | + 0, |
|
139 | + 'Attendee' |
|
140 | + ), |
|
141 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | + 'TXN_ID', |
|
143 | + esc_html__('Transaction ID', 'event_espresso'), |
|
144 | + false, |
|
145 | + 0, |
|
146 | + 'Transaction' |
|
147 | + ), |
|
148 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | + 'TKT_ID', |
|
150 | + esc_html__('Ticket ID', 'event_espresso'), |
|
151 | + false, |
|
152 | + 0, |
|
153 | + 'Ticket' |
|
154 | + ), |
|
155 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
156 | + 'STS_ID', |
|
157 | + esc_html__('Status ID', 'event_espresso'), |
|
158 | + false, |
|
159 | + EEM_Registration::status_id_incomplete, |
|
160 | + 'Status' |
|
161 | + ), |
|
162 | + 'REG_date' => new EE_Datetime_Field( |
|
163 | + 'REG_date', |
|
164 | + esc_html__('Time registration occurred', 'event_espresso'), |
|
165 | + false, |
|
166 | + EE_Datetime_Field::now, |
|
167 | + $timezone |
|
168 | + ), |
|
169 | + 'REG_final_price' => new EE_Money_Field( |
|
170 | + 'REG_final_price', |
|
171 | + esc_html__('Registration\'s share of the transaction total', 'event_espresso'), |
|
172 | + false, |
|
173 | + 0 |
|
174 | + ), |
|
175 | + 'REG_paid' => new EE_Money_Field( |
|
176 | + 'REG_paid', |
|
177 | + esc_html__('Amount paid to date towards registration', 'event_espresso'), |
|
178 | + false, |
|
179 | + 0 |
|
180 | + ), |
|
181 | + 'REG_session' => new EE_Plain_Text_Field( |
|
182 | + 'REG_session', |
|
183 | + esc_html__('Session ID of registration', 'event_espresso'), |
|
184 | + false, |
|
185 | + '' |
|
186 | + ), |
|
187 | + 'REG_code' => new EE_Plain_Text_Field( |
|
188 | + 'REG_code', |
|
189 | + esc_html__('Unique Code for this registration', 'event_espresso'), |
|
190 | + false, |
|
191 | + '' |
|
192 | + ), |
|
193 | + 'REG_url_link' => new EE_Plain_Text_Field( |
|
194 | + 'REG_url_link', |
|
195 | + esc_html__('String to be used in URL for identifying registration', 'event_espresso'), |
|
196 | + false, |
|
197 | + '' |
|
198 | + ), |
|
199 | + 'REG_count' => new EE_Integer_Field( |
|
200 | + 'REG_count', |
|
201 | + esc_html__('Count of this registration in the group registration ', 'event_espresso'), |
|
202 | + true, |
|
203 | + 1 |
|
204 | + ), |
|
205 | + 'REG_group_size' => new EE_Integer_Field( |
|
206 | + 'REG_group_size', |
|
207 | + esc_html__('Number of registrations on this group', 'event_espresso'), |
|
208 | + false, |
|
209 | + 1 |
|
210 | + ), |
|
211 | + 'REG_att_is_going' => new EE_Boolean_Field( |
|
212 | + 'REG_att_is_going', |
|
213 | + esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'), |
|
214 | + false, |
|
215 | + false |
|
216 | + ), |
|
217 | + 'REG_deleted' => new EE_Trashed_Flag_Field( |
|
218 | + 'REG_deleted', |
|
219 | + esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'), |
|
220 | + false, |
|
221 | + false |
|
222 | + ), |
|
223 | + ), |
|
224 | + ); |
|
225 | + $this->_model_relations = array( |
|
226 | + 'Event' => new EE_Belongs_To_Relation(), |
|
227 | + 'Attendee' => new EE_Belongs_To_Relation(), |
|
228 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
229 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
230 | + 'Status' => new EE_Belongs_To_Relation(), |
|
231 | + 'Answer' => new EE_Has_Many_Relation(), |
|
232 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
233 | + 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
234 | + 'Payment' => new EE_HABTM_Relation('Registration_Payment'), |
|
235 | + 'Message' => new EE_Has_Many_Any_Relation(false) |
|
236 | + // allow deletes even if there are messages in the queue related |
|
237 | + ); |
|
238 | + $this->_model_chain_to_wp_user = 'Event'; |
|
239 | + parent::__construct($timezone); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * a list of ALL valid registration statuses currently in use within the system |
|
245 | + * generated by combining the filterable active and inactive reg status arrays |
|
246 | + * |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + public static function reg_statuses() |
|
250 | + { |
|
251 | + return array_unique( |
|
252 | + array_merge( |
|
253 | + EEM_Registration::active_reg_statuses(), |
|
254 | + EEM_Registration::inactive_reg_statuses() |
|
255 | + ) |
|
256 | + ); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * reg_statuses_that_allow_payment |
|
262 | + * a filterable list of registration statuses that allow a registrant to make a payment |
|
263 | + * |
|
264 | + * @access public |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + public static function reg_statuses_that_allow_payment() |
|
268 | + { |
|
269 | + return apply_filters( |
|
270 | + 'FHEE__EEM_Registration__reg_statuses_that_allow_payment', |
|
271 | + array( |
|
272 | + EEM_Registration::status_id_approved, |
|
273 | + EEM_Registration::status_id_pending_payment, |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * active_reg_statuses |
|
281 | + * a filterable list of registration statuses that are considered active |
|
282 | + * |
|
283 | + * @access public |
|
284 | + * @return array |
|
285 | + */ |
|
286 | + public static function active_reg_statuses() |
|
287 | + { |
|
288 | + return apply_filters( |
|
289 | + 'FHEE__EEM_Registration__active_reg_statuses', |
|
290 | + array( |
|
291 | + EEM_Registration::status_id_approved, |
|
292 | + EEM_Registration::status_id_pending_payment, |
|
293 | + EEM_Registration::status_id_wait_list, |
|
294 | + EEM_Registration::status_id_not_approved, |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * inactive_reg_statuses |
|
302 | + * a filterable list of registration statuses that are not considered active |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + public static function inactive_reg_statuses() |
|
308 | + { |
|
309 | + return apply_filters( |
|
310 | + 'FHEE__EEM_Registration__inactive_reg_statuses', |
|
311 | + array( |
|
312 | + EEM_Registration::status_id_incomplete, |
|
313 | + EEM_Registration::status_id_cancelled, |
|
314 | + EEM_Registration::status_id_declined, |
|
315 | + ) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * closed_reg_statuses |
|
322 | + * a filterable list of registration statuses that are considered "closed" |
|
323 | + * meaning they should not be considered in any calculations involving monies owing |
|
324 | + * |
|
325 | + * @access public |
|
326 | + * @return array |
|
327 | + */ |
|
328 | + public static function closed_reg_statuses() |
|
329 | + { |
|
330 | + return apply_filters( |
|
331 | + 'FHEE__EEM_Registration__closed_reg_statuses', |
|
332 | + array( |
|
333 | + EEM_Registration::status_id_cancelled, |
|
334 | + EEM_Registration::status_id_declined, |
|
335 | + EEM_Registration::status_id_wait_list, |
|
336 | + ) |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * get list of registration statuses |
|
343 | + * |
|
344 | + * @access public |
|
345 | + * @param array $exclude The status ids to exclude from the returned results |
|
346 | + * @param bool $translated If true will return the values as singular localized strings |
|
347 | + * @return array |
|
348 | + * @throws EE_Error |
|
349 | + */ |
|
350 | + public static function reg_status_array($exclude = array(), $translated = false) |
|
351 | + { |
|
352 | + EEM_Registration::instance()->_get_registration_status_array($exclude); |
|
353 | + return $translated |
|
354 | + ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence') |
|
355 | + : self::$_reg_status; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * get list of registration statuses |
|
361 | + * |
|
362 | + * @access private |
|
363 | + * @param array $exclude |
|
364 | + * @return void |
|
365 | + * @throws EE_Error |
|
366 | + */ |
|
367 | + private function _get_registration_status_array($exclude = array()) |
|
368 | + { |
|
369 | + // in the very rare circumstance that we are deleting a model's table's data |
|
370 | + // and the table hasn't actually been created, this could have an error |
|
371 | + /** @type WPDB $wpdb */ |
|
372 | + global $wpdb; |
|
373 | + if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) { |
|
374 | + $results = $wpdb->get_results( |
|
375 | + "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'" |
|
376 | + ); |
|
377 | + self::$_reg_status = array(); |
|
378 | + foreach ($results as $status) { |
|
379 | + if (!in_array($status->STS_ID, $exclude, true)) { |
|
380 | + self::$_reg_status[ $status->STS_ID ] = $status->STS_code; |
|
381 | + } |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * Gets the injected table analyzer, or throws an exception |
|
389 | + * |
|
390 | + * @return TableAnalysis |
|
391 | + * @throws EE_Error |
|
392 | + */ |
|
393 | + protected function _get_table_analysis() |
|
394 | + { |
|
395 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
396 | + return $this->_table_analysis; |
|
397 | + } |
|
398 | + throw new EE_Error( |
|
399 | + sprintf( |
|
400 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
401 | + get_class($this) |
|
402 | + ) |
|
403 | + ); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * This returns a wpdb->results array of all registration date month and years matching the incoming query params |
|
409 | + * and grouped by month and year. |
|
410 | + * |
|
411 | + * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
412 | + * @return array |
|
413 | + * @throws EE_Error |
|
414 | + */ |
|
415 | + public function get_reg_months_and_years($where_params) |
|
416 | + { |
|
417 | + $query_params[0] = $where_params; |
|
418 | + $query_params['group_by'] = array('reg_year', 'reg_month'); |
|
419 | + $query_params['order_by'] = array('REG_date' => 'DESC'); |
|
420 | + $columns_to_select = array( |
|
421 | + 'reg_year' => array('YEAR(REG_date)', '%s'), |
|
422 | + 'reg_month' => array('MONTHNAME(REG_date)', '%s'), |
|
423 | + ); |
|
424 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * retrieve ALL registrations for a particular Attendee from db |
|
430 | + * |
|
431 | + * @param int $ATT_ID |
|
432 | + * @return EE_Base_Class[]|EE_Registration[]|null |
|
433 | + * @throws EE_Error |
|
434 | + */ |
|
435 | + public function get_all_registrations_for_attendee($ATT_ID = 0) |
|
436 | + { |
|
437 | + if (!$ATT_ID) { |
|
438 | + return null; |
|
439 | + } |
|
440 | + return $this->get_all(array(array('ATT_ID' => $ATT_ID))); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets a registration given their REG_url_link. Yes, this should usually |
|
446 | + * be passed via a GET parameter. |
|
447 | + * |
|
448 | + * @param string $REG_url_link |
|
449 | + * @return EE_Base_Class|EE_Registration|null |
|
450 | + * @throws EE_Error |
|
451 | + */ |
|
452 | + public function get_registration_for_reg_url_link($REG_url_link) |
|
453 | + { |
|
454 | + if (!$REG_url_link) { |
|
455 | + return null; |
|
456 | + } |
|
457 | + return $this->get_one(array(array('REG_url_link' => $REG_url_link))); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * retrieve registration for a specific transaction attendee from db |
|
463 | + * |
|
464 | + * @access public |
|
465 | + * @param int $TXN_ID |
|
466 | + * @param int $ATT_ID |
|
467 | + * @param int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the |
|
468 | + * attendee number is required |
|
469 | + * @return mixed array on success, FALSE on fail |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) |
|
473 | + { |
|
474 | + return $this->get_one(array( |
|
475 | + array( |
|
476 | + 'TXN_ID' => $TXN_ID, |
|
477 | + 'ATT_ID' => $ATT_ID, |
|
478 | + ), |
|
479 | + 'limit' => array(min($att_nmbr - 1, 0), 1), |
|
480 | + )); |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * get the number of registrations per day for the Registration Admin page Reports Tab. |
|
486 | + * (doesn't utilize models because it's a fairly specialized query) |
|
487 | + * |
|
488 | + * @access public |
|
489 | + * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
|
490 | + * @return stdClass[] with properties regDate and total |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + public function get_registrations_per_day_report($period = '-1 month') |
|
494 | + { |
|
495 | + $sql_date = $this->convert_datetime_for_query( |
|
496 | + 'REG_date', |
|
497 | + date('Y-m-d H:i:s', strtotime($period)), |
|
498 | + 'Y-m-d H:i:s', |
|
499 | + 'UTC' |
|
500 | + ); |
|
501 | + $where = array( |
|
502 | + 'REG_date' => array('>=', $sql_date), |
|
503 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
504 | + ); |
|
505 | + if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
506 | + $where['Event.EVT_wp_user'] = get_current_user_id(); |
|
507 | + } |
|
508 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date'); |
|
509 | + $results = $this->_get_all_wpdb_results( |
|
510 | + array( |
|
511 | + $where, |
|
512 | + 'group_by' => 'regDate', |
|
513 | + 'order_by' => array('REG_date' => 'ASC'), |
|
514 | + ), |
|
515 | + OBJECT, |
|
516 | + array( |
|
517 | + 'regDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
518 | + 'total' => array('count(REG_ID)', '%d'), |
|
519 | + ) |
|
520 | + ); |
|
521 | + return $results; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * Get the number of registrations per day including the count of registrations for each Registration Status. |
|
527 | + * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results. |
|
528 | + * |
|
529 | + * @param string $period |
|
530 | + * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID |
|
531 | + * @throws EE_Error |
|
532 | + * (i.e. RAP) |
|
533 | + */ |
|
534 | + public function get_registrations_per_day_and_per_status_report($period = '-1 month') |
|
535 | + { |
|
536 | + global $wpdb; |
|
537 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
538 | + $event_table = $wpdb->posts; |
|
539 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
540 | + // prepare the query interval for displaying offset |
|
541 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date'); |
|
542 | + // inner date query |
|
543 | + $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} "; |
|
544 | + $inner_where = ' WHERE'; |
|
545 | + // exclude events not authored by user if permissions in effect |
|
546 | + if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
547 | + $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
|
548 | + $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
549 | + } |
|
550 | + $inner_where .= " REG_date >= '{$sql_date}'"; |
|
551 | + $inner_date_query .= $inner_where; |
|
552 | + // start main query |
|
553 | + $select = "SELECT DATE({$query_interval}) as Registration_REG_date, "; |
|
554 | + $join = ''; |
|
555 | + $join_parts = array(); |
|
556 | + $select_parts = array(); |
|
557 | + // loop through registration stati to do parts for each status. |
|
558 | + foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
559 | + if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
560 | + continue; |
|
561 | + } |
|
562 | + $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
|
563 | + $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'"; |
|
564 | + } |
|
565 | + // setup the selects |
|
566 | + $select .= implode(', ', $select_parts); |
|
567 | + $select .= " FROM ($inner_date_query) AS dates LEFT JOIN "; |
|
568 | + // setup the joins |
|
569 | + $join .= implode(' LEFT JOIN ', $join_parts); |
|
570 | + // now let's put it all together |
|
571 | + $query = $select . $join . ' GROUP BY Registration_REG_date'; |
|
572 | + // and execute it |
|
573 | + return $wpdb->get_results($query, ARRAY_A); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * get the number of registrations per event for the Registration Admin page Reports Tab |
|
579 | + * |
|
580 | + * @access public |
|
581 | + * @param $period string which can be passed to php's strtotime function (eg "-1 month") |
|
582 | + * @return stdClass[] each with properties event_name, reg_limit, and total |
|
583 | + * @throws EE_Error |
|
584 | + */ |
|
585 | + public function get_registrations_per_event_report($period = '-1 month') |
|
586 | + { |
|
587 | + $date_sql = $this->convert_datetime_for_query( |
|
588 | + 'REG_date', |
|
589 | + date('Y-m-d H:i:s', strtotime($period)), |
|
590 | + 'Y-m-d H:i:s', |
|
591 | + 'UTC' |
|
592 | + ); |
|
593 | + $where = array( |
|
594 | + 'REG_date' => array('>=', $date_sql), |
|
595 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
596 | + ); |
|
597 | + if ( |
|
598 | + !EE_Registry::instance()->CAP->current_user_can( |
|
599 | + 'ee_read_others_registrations', |
|
600 | + 'reg_per_event_report' |
|
601 | + ) |
|
602 | + ) { |
|
603 | + $where['Event.EVT_wp_user'] = get_current_user_id(); |
|
604 | + } |
|
605 | + $results = $this->_get_all_wpdb_results( |
|
606 | + array( |
|
607 | + $where, |
|
608 | + 'group_by' => 'Event.EVT_name', |
|
609 | + 'order_by' => 'Event.EVT_name', |
|
610 | + 'limit' => array(0, 24), |
|
611 | + ), |
|
612 | + OBJECT, |
|
613 | + array( |
|
614 | + 'event_name' => array('Event_CPT.post_title', '%s'), |
|
615 | + 'total' => array('COUNT(REG_ID)', '%s'), |
|
616 | + ) |
|
617 | + ); |
|
618 | + return $results; |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * Get the number of registrations per event grouped by registration status. |
|
624 | + * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results. |
|
625 | + * |
|
626 | + * @param string $period |
|
627 | + * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID |
|
628 | + * @throws EE_Error |
|
629 | + * (i.e. RAP) |
|
630 | + */ |
|
631 | + public function get_registrations_per_event_and_per_status_report($period = '-1 month') |
|
632 | + { |
|
633 | + global $wpdb; |
|
634 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
635 | + $event_table = $wpdb->posts; |
|
636 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
637 | + // inner date query |
|
638 | + $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
|
639 | + $inner_where = ' WHERE'; |
|
640 | + // exclude events not authored by user if permissions in effect |
|
641 | + if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
642 | + $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
|
643 | + $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
644 | + } |
|
645 | + $inner_where .= " REG_date >= '{$sql_date}'"; |
|
646 | + $inner_date_query .= $inner_where; |
|
647 | + // build main query |
|
648 | + $select = 'SELECT Event.post_title as Registration_Event, '; |
|
649 | + $join = ''; |
|
650 | + $join_parts = array(); |
|
651 | + $select_parts = array(); |
|
652 | + // loop through registration stati to do parts for each status. |
|
653 | + foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) { |
|
654 | + if ($STS_ID === EEM_Registration::status_id_incomplete) { |
|
655 | + continue; |
|
656 | + } |
|
657 | + $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}"; |
|
658 | + $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date"; |
|
659 | + } |
|
660 | + // setup the selects |
|
661 | + $select .= implode(', ', $select_parts); |
|
662 | + $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN "; |
|
663 | + // setup remaining joins |
|
664 | + $join .= implode(' LEFT JOIN ', $join_parts); |
|
665 | + // now put it all together |
|
666 | + $query = $select . $join . ' GROUP BY Registration_Event'; |
|
667 | + // and execute |
|
668 | + return $wpdb->get_results($query, ARRAY_A); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Returns the EE_Registration of the primary attendee on the transaction id provided |
|
674 | + * |
|
675 | + * @param int $TXN_ID |
|
676 | + * @return EE_Base_Class|EE_Registration|null |
|
677 | + * @throws EE_Error |
|
678 | + */ |
|
679 | + public function get_primary_registration_for_transaction_ID($TXN_ID = 0) |
|
680 | + { |
|
681 | + if (!$TXN_ID) { |
|
682 | + return null; |
|
683 | + } |
|
684 | + return $this->get_one(array( |
|
685 | + array( |
|
686 | + 'TXN_ID' => $TXN_ID, |
|
687 | + 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT, |
|
688 | + ), |
|
689 | + )); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * get_event_registration_count |
|
695 | + * |
|
696 | + * @access public |
|
697 | + * @param int $EVT_ID |
|
698 | + * @param boolean $for_incomplete_payments |
|
699 | + * @return int |
|
700 | + * @throws EE_Error |
|
701 | + */ |
|
702 | + public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false) |
|
703 | + { |
|
704 | + // we only count approved registrations towards registration limits |
|
705 | + $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved)); |
|
706 | + if ($for_incomplete_payments) { |
|
707 | + $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code); |
|
708 | + } |
|
709 | + return $this->count($query_params); |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * Deletes all registrations with no transactions. Note that this needs to be very efficient |
|
715 | + * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete |
|
716 | + * when joining tables like this. |
|
717 | + * |
|
718 | + * @global WPDB $wpdb |
|
719 | + * @return int number deleted |
|
720 | + * @throws EE_Error |
|
721 | + */ |
|
722 | + public function delete_registrations_with_no_transaction() |
|
723 | + { |
|
724 | + /** @type WPDB $wpdb */ |
|
725 | + global $wpdb; |
|
726 | + return $wpdb->query( |
|
727 | + 'DELETE r FROM ' |
|
728 | + . $this->table() |
|
729 | + . ' r LEFT JOIN ' |
|
730 | + . EEM_Transaction::instance()->table() |
|
731 | + . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' |
|
732 | + ); |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Count registrations checked into (or out of) a datetime |
|
738 | + * |
|
739 | + * @param int $DTT_ID datetime ID |
|
740 | + * @param boolean $checked_in whether to count registrations checked IN or OUT |
|
741 | + * @return int |
|
742 | + * @throws EE_Error |
|
743 | + */ |
|
744 | + public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true) |
|
745 | + { |
|
746 | + global $wpdb; |
|
747 | + // subquery to get latest checkin |
|
748 | + $query = $wpdb->prepare( |
|
749 | + 'SELECT ' |
|
750 | + . 'COUNT( DISTINCT checkins.REG_ID ) ' |
|
751 | + . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
752 | + . '( SELECT ' |
|
753 | + . 'max( CHK_timestamp ) AS latest_checkin, ' |
|
754 | + . 'REG_ID AS REG_ID ' |
|
755 | + . 'FROM ' . EEM_Checkin::instance()->table() . ' ' |
|
756 | + . 'WHERE DTT_ID=%d ' |
|
757 | + . 'GROUP BY REG_ID' |
|
758 | + . ') AS most_recent_checkin_per_reg ' |
|
759 | + . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID ' |
|
760 | + . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin ' |
|
761 | + . 'WHERE ' |
|
762 | + . 'checkins.CHK_in=%d', |
|
763 | + $DTT_ID, |
|
764 | + $checked_in |
|
765 | + ); |
|
766 | + return (int) $wpdb->get_var($query); |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * Count registrations checked into (or out of) an event. |
|
772 | + * |
|
773 | + * @param int $EVT_ID event ID |
|
774 | + * @param boolean $checked_in whether to count registrations checked IN or OUT |
|
775 | + * @return int |
|
776 | + * @throws EE_Error |
|
777 | + */ |
|
778 | + public function count_registrations_checked_into_event($EVT_ID, $checked_in = true) |
|
779 | + { |
|
780 | + global $wpdb; |
|
781 | + // subquery to get latest checkin |
|
782 | + $query = $wpdb->prepare( |
|
783 | + 'SELECT ' |
|
784 | + . 'COUNT( DISTINCT checkins.REG_ID ) ' |
|
785 | + . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
786 | + . '( SELECT ' |
|
787 | + . 'max( CHK_timestamp ) AS latest_checkin, ' |
|
788 | + . 'REG_ID AS REG_ID ' |
|
789 | + . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c ' |
|
790 | + . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d ' |
|
791 | + . 'ON c.DTT_ID=d.DTT_ID ' |
|
792 | + . 'WHERE d.EVT_ID=%d ' |
|
793 | + . 'GROUP BY REG_ID' |
|
794 | + . ') AS most_recent_checkin_per_reg ' |
|
795 | + . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID ' |
|
796 | + . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin ' |
|
797 | + . 'WHERE ' |
|
798 | + . 'checkins.CHK_in=%d', |
|
799 | + $EVT_ID, |
|
800 | + $checked_in |
|
801 | + ); |
|
802 | + return (int) $wpdb->get_var($query); |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * The purpose of this method is to retrieve an array of |
|
808 | + * EE_Registration objects that represent the latest registration |
|
809 | + * for each ATT_ID given in the function argument. |
|
810 | + * |
|
811 | + * @param array $attendee_ids |
|
812 | + * @return EE_Base_Class[]|EE_Registration[] |
|
813 | + * @throws EE_Error |
|
814 | + */ |
|
815 | + public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array()) |
|
816 | + { |
|
817 | + // first do a native wp_query to get the latest REG_ID's matching these attendees. |
|
818 | + global $wpdb; |
|
819 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
820 | + $attendee_table = $wpdb->posts; |
|
821 | + $attendee_ids = is_array($attendee_ids) |
|
822 | + ? array_map('absint', $attendee_ids) |
|
823 | + : array((int) $attendee_ids); |
|
824 | + $ATT_IDs = implode(',', $attendee_ids); |
|
825 | + // first we do a query to get the registration ids |
|
826 | + // (because a group by before order by causes the order by to be ignored.) |
|
827 | + $registration_id_query = " |
|
828 | 828 | SELECT registrations.registration_ids as registration_id |
829 | 829 | FROM ( |
830 | 830 | SELECT |
@@ -838,61 +838,61 @@ discard block |
||
838 | 838 | ) AS registrations |
839 | 839 | GROUP BY registrations.attendee_ids |
840 | 840 | "; |
841 | - $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A); |
|
842 | - if (empty($registration_ids)) { |
|
843 | - return array(); |
|
844 | - } |
|
845 | - $ids_for_model_query = array(); |
|
846 | - // let's flatten the ids so they can be used in the model query. |
|
847 | - foreach ($registration_ids as $registration_id) { |
|
848 | - if (isset($registration_id['registration_id'])) { |
|
849 | - $ids_for_model_query[] = $registration_id['registration_id']; |
|
850 | - } |
|
851 | - } |
|
852 | - // construct query |
|
853 | - $_where = array( |
|
854 | - 'REG_ID' => array('IN', $ids_for_model_query), |
|
855 | - ); |
|
856 | - return $this->get_all(array($_where)); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * returns a count of registrations for the supplied event having the status as specified |
|
863 | - * |
|
864 | - * @param int $EVT_ID |
|
865 | - * @param array $statuses |
|
866 | - * @return int |
|
867 | - * @throws InvalidArgumentException |
|
868 | - * @throws InvalidStatusException |
|
869 | - * @throws EE_Error |
|
870 | - */ |
|
871 | - public function event_reg_count_for_statuses($EVT_ID, $statuses = array()) |
|
872 | - { |
|
873 | - $EVT_ID = absint($EVT_ID); |
|
874 | - if (! $EVT_ID) { |
|
875 | - throw new InvalidArgumentException( |
|
876 | - esc_html__('An invalid Event ID was supplied.', 'event_espresso') |
|
877 | - ); |
|
878 | - } |
|
879 | - $statuses = is_array($statuses) ? $statuses : array($statuses); |
|
880 | - $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved); |
|
881 | - $valid_reg_statuses = EEM_Registration::reg_statuses(); |
|
882 | - foreach ($statuses as $status) { |
|
883 | - if (! in_array($status, $valid_reg_statuses, true)) { |
|
884 | - throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso')); |
|
885 | - } |
|
886 | - } |
|
887 | - return $this->count( |
|
888 | - array( |
|
889 | - array( |
|
890 | - 'EVT_ID' => $EVT_ID, |
|
891 | - 'STS_ID' => array('IN', $statuses), |
|
892 | - ), |
|
893 | - ), |
|
894 | - 'REG_ID', |
|
895 | - true |
|
896 | - ); |
|
897 | - } |
|
841 | + $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A); |
|
842 | + if (empty($registration_ids)) { |
|
843 | + return array(); |
|
844 | + } |
|
845 | + $ids_for_model_query = array(); |
|
846 | + // let's flatten the ids so they can be used in the model query. |
|
847 | + foreach ($registration_ids as $registration_id) { |
|
848 | + if (isset($registration_id['registration_id'])) { |
|
849 | + $ids_for_model_query[] = $registration_id['registration_id']; |
|
850 | + } |
|
851 | + } |
|
852 | + // construct query |
|
853 | + $_where = array( |
|
854 | + 'REG_ID' => array('IN', $ids_for_model_query), |
|
855 | + ); |
|
856 | + return $this->get_all(array($_where)); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * returns a count of registrations for the supplied event having the status as specified |
|
863 | + * |
|
864 | + * @param int $EVT_ID |
|
865 | + * @param array $statuses |
|
866 | + * @return int |
|
867 | + * @throws InvalidArgumentException |
|
868 | + * @throws InvalidStatusException |
|
869 | + * @throws EE_Error |
|
870 | + */ |
|
871 | + public function event_reg_count_for_statuses($EVT_ID, $statuses = array()) |
|
872 | + { |
|
873 | + $EVT_ID = absint($EVT_ID); |
|
874 | + if (! $EVT_ID) { |
|
875 | + throw new InvalidArgumentException( |
|
876 | + esc_html__('An invalid Event ID was supplied.', 'event_espresso') |
|
877 | + ); |
|
878 | + } |
|
879 | + $statuses = is_array($statuses) ? $statuses : array($statuses); |
|
880 | + $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved); |
|
881 | + $valid_reg_statuses = EEM_Registration::reg_statuses(); |
|
882 | + foreach ($statuses as $status) { |
|
883 | + if (! in_array($status, $valid_reg_statuses, true)) { |
|
884 | + throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso')); |
|
885 | + } |
|
886 | + } |
|
887 | + return $this->count( |
|
888 | + array( |
|
889 | + array( |
|
890 | + 'EVT_ID' => $EVT_ID, |
|
891 | + 'STS_ID' => array('IN', $statuses), |
|
892 | + ), |
|
893 | + ), |
|
894 | + 'REG_ID', |
|
895 | + true |
|
896 | + ); |
|
897 | + } |
|
898 | 898 | } |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | // and the table hasn't actually been created, this could have an error |
371 | 371 | /** @type WPDB $wpdb */ |
372 | 372 | global $wpdb; |
373 | - if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) { |
|
373 | + if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) { |
|
374 | 374 | $results = $wpdb->get_results( |
375 | 375 | "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'" |
376 | 376 | ); |
377 | 377 | self::$_reg_status = array(); |
378 | 378 | foreach ($results as $status) { |
379 | - if (!in_array($status->STS_ID, $exclude, true)) { |
|
380 | - self::$_reg_status[ $status->STS_ID ] = $status->STS_code; |
|
379 | + if ( ! in_array($status->STS_ID, $exclude, true)) { |
|
380 | + self::$_reg_status[$status->STS_ID] = $status->STS_code; |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_all_registrations_for_attendee($ATT_ID = 0) |
436 | 436 | { |
437 | - if (!$ATT_ID) { |
|
437 | + if ( ! $ATT_ID) { |
|
438 | 438 | return null; |
439 | 439 | } |
440 | 440 | return $this->get_all(array(array('ATT_ID' => $ATT_ID))); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | */ |
452 | 452 | public function get_registration_for_reg_url_link($REG_url_link) |
453 | 453 | { |
454 | - if (!$REG_url_link) { |
|
454 | + if ( ! $REG_url_link) { |
|
455 | 455 | return null; |
456 | 456 | } |
457 | 457 | return $this->get_one(array(array('REG_url_link' => $REG_url_link))); |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | 'REG_date' => array('>=', $sql_date), |
503 | 503 | 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
504 | 504 | ); |
505 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
505 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) { |
|
506 | 506 | $where['Event.EVT_wp_user'] = get_current_user_id(); |
507 | 507 | } |
508 | 508 | $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date'); |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | ), |
515 | 515 | OBJECT, |
516 | 516 | array( |
517 | - 'regDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
517 | + 'regDate' => array('DATE('.$query_interval.')', '%s'), |
|
518 | 518 | 'total' => array('count(REG_ID)', '%d'), |
519 | 519 | ) |
520 | 520 | ); |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | public function get_registrations_per_day_and_per_status_report($period = '-1 month') |
535 | 535 | { |
536 | 536 | global $wpdb; |
537 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
537 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
538 | 538 | $event_table = $wpdb->posts; |
539 | 539 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
540 | 540 | // prepare the query interval for displaying offset |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} "; |
544 | 544 | $inner_where = ' WHERE'; |
545 | 545 | // exclude events not authored by user if permissions in effect |
546 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
546 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
547 | 547 | $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
548 | - $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
548 | + $inner_where .= ' post_author = '.get_current_user_id().' AND'; |
|
549 | 549 | } |
550 | 550 | $inner_where .= " REG_date >= '{$sql_date}'"; |
551 | 551 | $inner_date_query .= $inner_where; |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | // setup the joins |
569 | 569 | $join .= implode(' LEFT JOIN ', $join_parts); |
570 | 570 | // now let's put it all together |
571 | - $query = $select . $join . ' GROUP BY Registration_REG_date'; |
|
571 | + $query = $select.$join.' GROUP BY Registration_REG_date'; |
|
572 | 572 | // and execute it |
573 | 573 | return $wpdb->get_results($query, ARRAY_A); |
574 | 574 | } |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
596 | 596 | ); |
597 | 597 | if ( |
598 | - !EE_Registry::instance()->CAP->current_user_can( |
|
598 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
599 | 599 | 'ee_read_others_registrations', |
600 | 600 | 'reg_per_event_report' |
601 | 601 | ) |
@@ -631,16 +631,16 @@ discard block |
||
631 | 631 | public function get_registrations_per_event_and_per_status_report($period = '-1 month') |
632 | 632 | { |
633 | 633 | global $wpdb; |
634 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
634 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
635 | 635 | $event_table = $wpdb->posts; |
636 | 636 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
637 | 637 | // inner date query |
638 | 638 | $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table "; |
639 | 639 | $inner_where = ' WHERE'; |
640 | 640 | // exclude events not authored by user if permissions in effect |
641 | - if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
641 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
642 | 642 | $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID"; |
643 | - $inner_where .= ' post_author = ' . get_current_user_id() . ' AND'; |
|
643 | + $inner_where .= ' post_author = '.get_current_user_id().' AND'; |
|
644 | 644 | } |
645 | 645 | $inner_where .= " REG_date >= '{$sql_date}'"; |
646 | 646 | $inner_date_query .= $inner_where; |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | // setup remaining joins |
664 | 664 | $join .= implode(' LEFT JOIN ', $join_parts); |
665 | 665 | // now put it all together |
666 | - $query = $select . $join . ' GROUP BY Registration_Event'; |
|
666 | + $query = $select.$join.' GROUP BY Registration_Event'; |
|
667 | 667 | // and execute |
668 | 668 | return $wpdb->get_results($query, ARRAY_A); |
669 | 669 | } |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | */ |
679 | 679 | public function get_primary_registration_for_transaction_ID($TXN_ID = 0) |
680 | 680 | { |
681 | - if (!$TXN_ID) { |
|
681 | + if ( ! $TXN_ID) { |
|
682 | 682 | return null; |
683 | 683 | } |
684 | 684 | return $this->get_one(array( |
@@ -748,11 +748,11 @@ discard block |
||
748 | 748 | $query = $wpdb->prepare( |
749 | 749 | 'SELECT ' |
750 | 750 | . 'COUNT( DISTINCT checkins.REG_ID ) ' |
751 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
751 | + . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN' |
|
752 | 752 | . '( SELECT ' |
753 | 753 | . 'max( CHK_timestamp ) AS latest_checkin, ' |
754 | 754 | . 'REG_ID AS REG_ID ' |
755 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' ' |
|
755 | + . 'FROM '.EEM_Checkin::instance()->table().' ' |
|
756 | 756 | . 'WHERE DTT_ID=%d ' |
757 | 757 | . 'GROUP BY REG_ID' |
758 | 758 | . ') AS most_recent_checkin_per_reg ' |
@@ -782,12 +782,12 @@ discard block |
||
782 | 782 | $query = $wpdb->prepare( |
783 | 783 | 'SELECT ' |
784 | 784 | . 'COUNT( DISTINCT checkins.REG_ID ) ' |
785 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN' |
|
785 | + . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN' |
|
786 | 786 | . '( SELECT ' |
787 | 787 | . 'max( CHK_timestamp ) AS latest_checkin, ' |
788 | 788 | . 'REG_ID AS REG_ID ' |
789 | - . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c ' |
|
790 | - . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d ' |
|
789 | + . 'FROM '.EEM_Checkin::instance()->table().' AS c ' |
|
790 | + . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d ' |
|
791 | 791 | . 'ON c.DTT_ID=d.DTT_ID ' |
792 | 792 | . 'WHERE d.EVT_ID=%d ' |
793 | 793 | . 'GROUP BY REG_ID' |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | { |
817 | 817 | // first do a native wp_query to get the latest REG_ID's matching these attendees. |
818 | 818 | global $wpdb; |
819 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
819 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
820 | 820 | $attendee_table = $wpdb->posts; |
821 | 821 | $attendee_ids = is_array($attendee_ids) |
822 | 822 | ? array_map('absint', $attendee_ids) |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | public function event_reg_count_for_statuses($EVT_ID, $statuses = array()) |
872 | 872 | { |
873 | 873 | $EVT_ID = absint($EVT_ID); |
874 | - if (! $EVT_ID) { |
|
874 | + if ( ! $EVT_ID) { |
|
875 | 875 | throw new InvalidArgumentException( |
876 | 876 | esc_html__('An invalid Event ID was supplied.', 'event_espresso') |
877 | 877 | ); |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved); |
881 | 881 | $valid_reg_statuses = EEM_Registration::reg_statuses(); |
882 | 882 | foreach ($statuses as $status) { |
883 | - if (! in_array($status, $valid_reg_statuses, true)) { |
|
883 | + if ( ! in_array($status, $valid_reg_statuses, true)) { |
|
884 | 884 | throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso')); |
885 | 885 | } |
886 | 886 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | protected function __construct($timezone = null) |
34 | 34 | { |
35 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
35 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
36 | 36 | $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
37 | 37 | } |
38 | 38 | parent::__construct($timezone); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected function _alter_query_params_so_only_trashed_items_included($query_params) |
134 | 134 | { |
135 | 135 | $deletedFlagFieldName = $this->deleted_field_name(); |
136 | - $query_params[0][ $deletedFlagFieldName ] = true; |
|
136 | + $query_params[0][$deletedFlagFieldName] = true; |
|
137 | 137 | return $query_params; |
138 | 138 | } |
139 | 139 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
175 | 175 | { |
176 | - if (! isset($query_params['default_where_conditions'])) { |
|
176 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
177 | 177 | $query_params['default_where_conditions'] = 'minimum'; |
178 | 178 | } |
179 | 179 | return $query_params; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | */ |
302 | 302 | public function delete_or_restore_by_ID($delete = true, $ID = false) |
303 | 303 | { |
304 | - if (! $ID) { |
|
304 | + if ( ! $ID) { |
|
305 | 305 | return false; |
306 | 306 | } |
307 | 307 | if ( |
@@ -27,364 +27,364 @@ |
||
27 | 27 | abstract class EEM_Soft_Delete_Base extends EEM_Base |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @param null $timezone |
|
32 | - */ |
|
33 | - protected function __construct($timezone = null) |
|
34 | - { |
|
35 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
36 | - $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
|
37 | - } |
|
38 | - parent::__construct($timezone); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
45 | - * returns it's name. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - public function deleted_field_name() |
|
51 | - { |
|
52 | - $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
53 | - if ($field) { |
|
54 | - return $field->get_name(); |
|
55 | - } else { |
|
56 | - throw new EE_Error(sprintf(esc_html__( |
|
57 | - 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
58 | - 'event_espresso' |
|
59 | - ), get_class($this), get_class($this))); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Gets one item that's been deleted, according to $query_params |
|
67 | - * |
|
68 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
69 | - * @return EE_Soft_Delete_Base_Class |
|
70 | - */ |
|
71 | - public function get_one_deleted($query_params = array()) |
|
72 | - { |
|
73 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
74 | - return parent::get_one($query_params); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Gets one item from the DB, regardless of whether it's been soft-deleted or not |
|
81 | - * |
|
82 | - * @param array $query_params like EEM_base::get_all's $query_params |
|
83 | - * @return EE_Soft_Delete_Base_Class |
|
84 | - */ |
|
85 | - public function get_one_deleted_or_undeleted($query_params = array()) |
|
86 | - { |
|
87 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
88 | - return parent::get_one($query_params); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist. |
|
95 | - * |
|
96 | - * @param int|string $id |
|
97 | - * @return EE_Soft_Delete_Base_Class |
|
98 | - */ |
|
99 | - public function get_one_by_ID_but_ignore_deleted($id) |
|
100 | - { |
|
101 | - return $this->get_one( |
|
102 | - $this->alter_query_params_to_restrict_by_ID( |
|
103 | - $id, |
|
104 | - array('default_where_conditions' => 'default') |
|
105 | - ) |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Counts all the deleted/trashed items |
|
113 | - * |
|
114 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
115 | - * @param string $field_to_count |
|
116 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
117 | - * @return int |
|
118 | - */ |
|
119 | - public function count_deleted($query_params = null, $field_to_count = null, $distinct = false) |
|
120 | - { |
|
121 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
122 | - return parent::count($query_params, $field_to_count, $distinct); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
129 | - * |
|
130 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
131 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
132 | - */ |
|
133 | - protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
134 | - { |
|
135 | - $deletedFlagFieldName = $this->deleted_field_name(); |
|
136 | - $query_params[0][ $deletedFlagFieldName ] = true; |
|
137 | - return $query_params; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
144 | - * |
|
145 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
146 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
147 | - */ |
|
148 | - public function alter_query_params_so_only_trashed_items_included($query_params) |
|
149 | - { |
|
150 | - return $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Alters the query params so each item's deleted status is ignored. |
|
157 | - * |
|
158 | - * @param array $query_params |
|
159 | - * @return array |
|
160 | - */ |
|
161 | - public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) |
|
162 | - { |
|
163 | - return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Alters the query params so each item's deleted status is ignored. |
|
170 | - * |
|
171 | - * @param array $query_params |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
175 | - { |
|
176 | - if (! isset($query_params['default_where_conditions'])) { |
|
177 | - $query_params['default_where_conditions'] = 'minimum'; |
|
178 | - } |
|
179 | - return $query_params; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Counts all deleted and undeleted items |
|
186 | - * |
|
187 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
188 | - * @param string $field_to_count |
|
189 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false) |
|
193 | - { |
|
194 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
195 | - return parent::count($query_params, $field_to_count, $distinct); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Sum all the deleted items. |
|
202 | - * |
|
203 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
204 | - * @param string $field_to_sum |
|
205 | - * @return int |
|
206 | - */ |
|
207 | - public function sum_deleted($query_params = null, $field_to_sum = null) |
|
208 | - { |
|
209 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
210 | - return parent::sum($query_params, $field_to_sum); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Sums all the deleted and undeleted items. |
|
217 | - * |
|
218 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | - * @param string $field_to_sum |
|
220 | - * @return int |
|
221 | - */ |
|
222 | - public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) |
|
223 | - { |
|
224 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
225 | - parent::sum($query_params, $field_to_sum); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of |
|
232 | - * whether they've been soft-deleted or not |
|
233 | - * |
|
234 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
235 | - * @return EE_Soft_Delete_Base_Class[] |
|
236 | - */ |
|
237 | - public function get_all_deleted_and_undeleted($query_params = array()) |
|
238 | - { |
|
239 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
240 | - return parent::get_all($query_params); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params. |
|
247 | - * |
|
248 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
249 | - * @return EE_Soft_Delete_Base_Class[] |
|
250 | - */ |
|
251 | - public function get_all_deleted($query_params = array()) |
|
252 | - { |
|
253 | - $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
254 | - return parent::get_all($query_params); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Permanently deletes the selected rows. When selecting rows for deletion, ignores |
|
261 | - * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects |
|
262 | - * before you can permanently delete them). |
|
263 | - * Because this will cause a real deletion, related models may block this deletion (ie, add an error |
|
264 | - * and abort the delete) |
|
265 | - * |
|
266 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
267 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
268 | - * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
269 | - * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
270 | - * @return boolean success |
|
271 | - */ |
|
272 | - public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
273 | - { |
|
274 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
275 | - return parent::delete_permanently($query_params, $allow_blocking); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Restores a particular item by its ID (primary key). Ignores the fact whether the item |
|
282 | - * has been soft-deleted or not. |
|
283 | - * |
|
284 | - * @param mixed $ID int if primary key is an int, string otherwise |
|
285 | - * @return boolean success |
|
286 | - */ |
|
287 | - public function restore_by_ID($ID = false) |
|
288 | - { |
|
289 | - return $this->delete_or_restore_by_ID(false, $ID); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However, |
|
296 | - * this function will ignore whether the items have been soft-deleted or not. |
|
297 | - * |
|
298 | - * @param boolean $delete true for delete, false for restore |
|
299 | - * @param mixed $ID int if primary key is an int, string otherwise |
|
300 | - * @return boolean |
|
301 | - */ |
|
302 | - public function delete_or_restore_by_ID($delete = true, $ID = false) |
|
303 | - { |
|
304 | - if (! $ID) { |
|
305 | - return false; |
|
306 | - } |
|
307 | - if ( |
|
308 | - $this->delete_or_restore( |
|
309 | - $delete, |
|
310 | - $this->alter_query_params_to_restrict_by_ID($ID) |
|
311 | - ) |
|
312 | - ) { |
|
313 | - return true; |
|
314 | - } else { |
|
315 | - return false; |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Overrides parent's 'delete' method to instead do a soft delete on all rows that |
|
323 | - * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not. |
|
324 | - * Note: because this item will be soft-deleted only, |
|
325 | - * doesn't block because of model dependencies |
|
326 | - * |
|
327 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
328 | - * @param bool $block_deletes |
|
329 | - * @return boolean |
|
330 | - */ |
|
331 | - public function delete($query_params = array(), $block_deletes = false) |
|
332 | - { |
|
333 | - // no matter what, we WON'T block soft deletes. |
|
334 | - return $this->delete_or_restore(true, $query_params); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted |
|
341 | - * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not. |
|
342 | - * |
|
343 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
344 | - * @return boolean |
|
345 | - */ |
|
346 | - public function restore($query_params = array()) |
|
347 | - { |
|
348 | - return $this->delete_or_restore(false, $query_params); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
355 | - * |
|
356 | - * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
357 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
358 | - * @return boolean |
|
359 | - */ |
|
360 | - public function delete_or_restore($delete = true, $query_params = array()) |
|
361 | - { |
|
362 | - $deletedFlagFieldName = $this->deleted_field_name(); |
|
363 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
364 | - if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) { |
|
365 | - return true; |
|
366 | - } else { |
|
367 | - return false; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Updates all the items of this model which match the $query params, regardless of whether |
|
375 | - * they've been soft-deleted or not |
|
376 | - * |
|
377 | - * @param array $fields_n_values like EEM_Base::update's $fields_n_value |
|
378 | - * @param array $query_params like EEM_base::get_all's $query_params |
|
379 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
380 | - * in this model's entity map according to $fields_n_values that match $query_params. This |
|
381 | - * obviously has some overhead, so you can disable it by setting this to FALSE, but |
|
382 | - * be aware that model objects being used could get out-of-sync with the database |
|
383 | - * @return int number of items updated |
|
384 | - */ |
|
385 | - public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
386 | - { |
|
387 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
388 | - return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
389 | - } |
|
30 | + /** |
|
31 | + * @param null $timezone |
|
32 | + */ |
|
33 | + protected function __construct($timezone = null) |
|
34 | + { |
|
35 | + if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
36 | + $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions(); |
|
37 | + } |
|
38 | + parent::__construct($timezone); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
45 | + * returns it's name. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + public function deleted_field_name() |
|
51 | + { |
|
52 | + $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
53 | + if ($field) { |
|
54 | + return $field->get_name(); |
|
55 | + } else { |
|
56 | + throw new EE_Error(sprintf(esc_html__( |
|
57 | + 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
58 | + 'event_espresso' |
|
59 | + ), get_class($this), get_class($this))); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Gets one item that's been deleted, according to $query_params |
|
67 | + * |
|
68 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
69 | + * @return EE_Soft_Delete_Base_Class |
|
70 | + */ |
|
71 | + public function get_one_deleted($query_params = array()) |
|
72 | + { |
|
73 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
74 | + return parent::get_one($query_params); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Gets one item from the DB, regardless of whether it's been soft-deleted or not |
|
81 | + * |
|
82 | + * @param array $query_params like EEM_base::get_all's $query_params |
|
83 | + * @return EE_Soft_Delete_Base_Class |
|
84 | + */ |
|
85 | + public function get_one_deleted_or_undeleted($query_params = array()) |
|
86 | + { |
|
87 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
88 | + return parent::get_one($query_params); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist. |
|
95 | + * |
|
96 | + * @param int|string $id |
|
97 | + * @return EE_Soft_Delete_Base_Class |
|
98 | + */ |
|
99 | + public function get_one_by_ID_but_ignore_deleted($id) |
|
100 | + { |
|
101 | + return $this->get_one( |
|
102 | + $this->alter_query_params_to_restrict_by_ID( |
|
103 | + $id, |
|
104 | + array('default_where_conditions' => 'default') |
|
105 | + ) |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Counts all the deleted/trashed items |
|
113 | + * |
|
114 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
115 | + * @param string $field_to_count |
|
116 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
117 | + * @return int |
|
118 | + */ |
|
119 | + public function count_deleted($query_params = null, $field_to_count = null, $distinct = false) |
|
120 | + { |
|
121 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
122 | + return parent::count($query_params, $field_to_count, $distinct); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
129 | + * |
|
130 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
131 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
132 | + */ |
|
133 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
134 | + { |
|
135 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
136 | + $query_params[0][ $deletedFlagFieldName ] = true; |
|
137 | + return $query_params; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
144 | + * |
|
145 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
146 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
147 | + */ |
|
148 | + public function alter_query_params_so_only_trashed_items_included($query_params) |
|
149 | + { |
|
150 | + return $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Alters the query params so each item's deleted status is ignored. |
|
157 | + * |
|
158 | + * @param array $query_params |
|
159 | + * @return array |
|
160 | + */ |
|
161 | + public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) |
|
162 | + { |
|
163 | + return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Alters the query params so each item's deleted status is ignored. |
|
170 | + * |
|
171 | + * @param array $query_params |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
175 | + { |
|
176 | + if (! isset($query_params['default_where_conditions'])) { |
|
177 | + $query_params['default_where_conditions'] = 'minimum'; |
|
178 | + } |
|
179 | + return $query_params; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Counts all deleted and undeleted items |
|
186 | + * |
|
187 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
188 | + * @param string $field_to_count |
|
189 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false) |
|
193 | + { |
|
194 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
195 | + return parent::count($query_params, $field_to_count, $distinct); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Sum all the deleted items. |
|
202 | + * |
|
203 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
204 | + * @param string $field_to_sum |
|
205 | + * @return int |
|
206 | + */ |
|
207 | + public function sum_deleted($query_params = null, $field_to_sum = null) |
|
208 | + { |
|
209 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
210 | + return parent::sum($query_params, $field_to_sum); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Sums all the deleted and undeleted items. |
|
217 | + * |
|
218 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | + * @param string $field_to_sum |
|
220 | + * @return int |
|
221 | + */ |
|
222 | + public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) |
|
223 | + { |
|
224 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
225 | + parent::sum($query_params, $field_to_sum); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of |
|
232 | + * whether they've been soft-deleted or not |
|
233 | + * |
|
234 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
235 | + * @return EE_Soft_Delete_Base_Class[] |
|
236 | + */ |
|
237 | + public function get_all_deleted_and_undeleted($query_params = array()) |
|
238 | + { |
|
239 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
240 | + return parent::get_all($query_params); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params. |
|
247 | + * |
|
248 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
249 | + * @return EE_Soft_Delete_Base_Class[] |
|
250 | + */ |
|
251 | + public function get_all_deleted($query_params = array()) |
|
252 | + { |
|
253 | + $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params); |
|
254 | + return parent::get_all($query_params); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Permanently deletes the selected rows. When selecting rows for deletion, ignores |
|
261 | + * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects |
|
262 | + * before you can permanently delete them). |
|
263 | + * Because this will cause a real deletion, related models may block this deletion (ie, add an error |
|
264 | + * and abort the delete) |
|
265 | + * |
|
266 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
267 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
268 | + * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
269 | + * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
270 | + * @return boolean success |
|
271 | + */ |
|
272 | + public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
273 | + { |
|
274 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
275 | + return parent::delete_permanently($query_params, $allow_blocking); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Restores a particular item by its ID (primary key). Ignores the fact whether the item |
|
282 | + * has been soft-deleted or not. |
|
283 | + * |
|
284 | + * @param mixed $ID int if primary key is an int, string otherwise |
|
285 | + * @return boolean success |
|
286 | + */ |
|
287 | + public function restore_by_ID($ID = false) |
|
288 | + { |
|
289 | + return $this->delete_or_restore_by_ID(false, $ID); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However, |
|
296 | + * this function will ignore whether the items have been soft-deleted or not. |
|
297 | + * |
|
298 | + * @param boolean $delete true for delete, false for restore |
|
299 | + * @param mixed $ID int if primary key is an int, string otherwise |
|
300 | + * @return boolean |
|
301 | + */ |
|
302 | + public function delete_or_restore_by_ID($delete = true, $ID = false) |
|
303 | + { |
|
304 | + if (! $ID) { |
|
305 | + return false; |
|
306 | + } |
|
307 | + if ( |
|
308 | + $this->delete_or_restore( |
|
309 | + $delete, |
|
310 | + $this->alter_query_params_to_restrict_by_ID($ID) |
|
311 | + ) |
|
312 | + ) { |
|
313 | + return true; |
|
314 | + } else { |
|
315 | + return false; |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Overrides parent's 'delete' method to instead do a soft delete on all rows that |
|
323 | + * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not. |
|
324 | + * Note: because this item will be soft-deleted only, |
|
325 | + * doesn't block because of model dependencies |
|
326 | + * |
|
327 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
328 | + * @param bool $block_deletes |
|
329 | + * @return boolean |
|
330 | + */ |
|
331 | + public function delete($query_params = array(), $block_deletes = false) |
|
332 | + { |
|
333 | + // no matter what, we WON'T block soft deletes. |
|
334 | + return $this->delete_or_restore(true, $query_params); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted |
|
341 | + * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not. |
|
342 | + * |
|
343 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
344 | + * @return boolean |
|
345 | + */ |
|
346 | + public function restore($query_params = array()) |
|
347 | + { |
|
348 | + return $this->delete_or_restore(false, $query_params); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
355 | + * |
|
356 | + * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
357 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
358 | + * @return boolean |
|
359 | + */ |
|
360 | + public function delete_or_restore($delete = true, $query_params = array()) |
|
361 | + { |
|
362 | + $deletedFlagFieldName = $this->deleted_field_name(); |
|
363 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
364 | + if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) { |
|
365 | + return true; |
|
366 | + } else { |
|
367 | + return false; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Updates all the items of this model which match the $query params, regardless of whether |
|
375 | + * they've been soft-deleted or not |
|
376 | + * |
|
377 | + * @param array $fields_n_values like EEM_Base::update's $fields_n_value |
|
378 | + * @param array $query_params like EEM_base::get_all's $query_params |
|
379 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
380 | + * in this model's entity map according to $fields_n_values that match $query_params. This |
|
381 | + * obviously has some overhead, so you can disable it by setting this to FALSE, but |
|
382 | + * be aware that model objects being used could get out-of-sync with the database |
|
383 | + * @return int number of items updated |
|
384 | + */ |
|
385 | + public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
386 | + { |
|
387 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
388 | + return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
389 | + } |
|
390 | 390 | } |
@@ -1,876 +1,876 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * |
|
5 | - * Class EEH_HTML |
|
6 | - * |
|
4 | + * |
|
5 | + * Class EEH_HTML |
|
6 | + * |
|
7 | 7 | * Sometimes when writing PHP you need to generate some standard HTML, |
8 | 8 | * but either not enough to warrant creating a template file, |
9 | 9 | * or the amount of PHP conditionals and/or loops peppered throughout the HTML |
10 | 10 | * just make it really ugly and difficult to read. |
11 | 11 | * This class simply adds a bunch of methods for generating basic HTML tags. |
12 | 12 | * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters. |
13 | - * |
|
14 | - * @package Event Espresso |
|
15 | - * @subpackage core |
|
16 | - * @author Brent Christensen |
|
17 | - * |
|
18 | - * |
|
19 | - */ |
|
13 | + * |
|
14 | + * @package Event Espresso |
|
15 | + * @subpackage core |
|
16 | + * @author Brent Christensen |
|
17 | + * |
|
18 | + * |
|
19 | + */ |
|
20 | 20 | class EEH_HTML |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * instance of the EEH_Autoloader object |
|
25 | - * @var $_instance |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array $_indent |
|
32 | - * @access private |
|
33 | - */ |
|
34 | - private static $_indent = array(); |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @singleton method used to instantiate class object |
|
40 | - * @access public |
|
41 | - * @return EEH_HTML |
|
42 | - */ |
|
43 | - public static function instance() |
|
44 | - { |
|
45 | - // check if class object is instantiated, and instantiated properly |
|
46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
47 | - self::$_instance = new EEH_HTML(); |
|
48 | - } |
|
49 | - return self::$_instance; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * class constructor |
|
56 | - * |
|
57 | - * @access private |
|
58 | - * @return \EEH_HTML |
|
59 | - */ |
|
60 | - private function __construct() |
|
61 | - { |
|
62 | - // set some initial formatting for table indentation |
|
63 | - EEH_HTML::$_indent = array( |
|
64 | - 'table' => 0, |
|
65 | - 'thead' => 1, |
|
66 | - 'tbody' => 1, |
|
67 | - 'tr' => 2, |
|
68 | - 'th' => 3, |
|
69 | - 'td' => 3, |
|
70 | - 'div' => 0, |
|
71 | - 'h1' => 0, |
|
72 | - 'h2' => 0, |
|
73 | - 'h3' => 0, |
|
74 | - 'h4' => 0, |
|
75 | - 'h5' => 0, |
|
76 | - 'h6' => 0, |
|
77 | - 'p' => 0, |
|
78 | - 'ul' => 0, |
|
79 | - 'li' => 1 |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Generates an opening HTML <XX> tag and adds any passed attributes |
|
87 | - * if passed content, it will also add that, as well as the closing </XX> tag |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @param string $tag |
|
91 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
92 | - * @param string $id - html id attribute |
|
93 | - * @param string $class - html class attribute |
|
94 | - * @param string $style - html style attribute for applying inline styles |
|
95 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
96 | - * @param bool $force_close |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - protected static function _open_tag( |
|
100 | - $tag = 'div', |
|
101 | - $content = '', |
|
102 | - $id = '', |
|
103 | - $class = '', |
|
104 | - $style = '', |
|
105 | - $other_attributes = '', |
|
106 | - $force_close = false |
|
107 | - ) { |
|
108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
114 | - $indent = ! empty($content) || $force_close ? true : false; |
|
115 | - $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
116 | - return $html; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
123 | - * used for the opening tag, will append a comment |
|
124 | - * |
|
23 | + /** |
|
24 | + * instance of the EEH_Autoloader object |
|
25 | + * @var $_instance |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array $_indent |
|
32 | + * @access private |
|
33 | + */ |
|
34 | + private static $_indent = array(); |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @singleton method used to instantiate class object |
|
40 | + * @access public |
|
41 | + * @return EEH_HTML |
|
42 | + */ |
|
43 | + public static function instance() |
|
44 | + { |
|
45 | + // check if class object is instantiated, and instantiated properly |
|
46 | + if (! self::$_instance instanceof EEH_HTML) { |
|
47 | + self::$_instance = new EEH_HTML(); |
|
48 | + } |
|
49 | + return self::$_instance; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * class constructor |
|
56 | + * |
|
57 | + * @access private |
|
58 | + * @return \EEH_HTML |
|
59 | + */ |
|
60 | + private function __construct() |
|
61 | + { |
|
62 | + // set some initial formatting for table indentation |
|
63 | + EEH_HTML::$_indent = array( |
|
64 | + 'table' => 0, |
|
65 | + 'thead' => 1, |
|
66 | + 'tbody' => 1, |
|
67 | + 'tr' => 2, |
|
68 | + 'th' => 3, |
|
69 | + 'td' => 3, |
|
70 | + 'div' => 0, |
|
71 | + 'h1' => 0, |
|
72 | + 'h2' => 0, |
|
73 | + 'h3' => 0, |
|
74 | + 'h4' => 0, |
|
75 | + 'h5' => 0, |
|
76 | + 'h6' => 0, |
|
77 | + 'p' => 0, |
|
78 | + 'ul' => 0, |
|
79 | + 'li' => 1 |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Generates an opening HTML <XX> tag and adds any passed attributes |
|
87 | + * if passed content, it will also add that, as well as the closing </XX> tag |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @param string $tag |
|
91 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
92 | + * @param string $id - html id attribute |
|
93 | + * @param string $class - html class attribute |
|
94 | + * @param string $style - html style attribute for applying inline styles |
|
95 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
96 | + * @param bool $force_close |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + protected static function _open_tag( |
|
100 | + $tag = 'div', |
|
101 | + $content = '', |
|
102 | + $id = '', |
|
103 | + $class = '', |
|
104 | + $style = '', |
|
105 | + $other_attributes = '', |
|
106 | + $force_close = false |
|
107 | + ) { |
|
108 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | + $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
114 | + $indent = ! empty($content) || $force_close ? true : false; |
|
115 | + $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
116 | + return $html; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
123 | + * used for the opening tag, will append a comment |
|
124 | + * |
|
125 | 125 | *@access protected |
126 | - * @param string $tag |
|
127 | - * @param string $id - html id attribute |
|
128 | - * @param string $class - html class attribute |
|
129 | - * @param bool $indent |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
133 | - { |
|
134 | - $comment = ''; |
|
135 | - if ($id) { |
|
136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
137 | - } elseif ($class) { |
|
138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
139 | - } |
|
140 | - $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
141 | - $html .= '</' . $tag . '>' . $comment; |
|
142 | - return $html; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * div - generates HTML opening <div> tag and adds any passed attributes |
|
149 | - * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
150 | - * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
151 | - * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
152 | - * |
|
153 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
154 | - * @param string $id - html id attribute |
|
155 | - * @param string $class - html class attribute |
|
156 | - * @param string $style - html style attribute for applying inline styles |
|
157 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
161 | - { |
|
162 | - return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
169 | - * usage: echo EEH_HTML::divx(); |
|
170 | - * |
|
171 | - * @param string $id - html id attribute |
|
172 | - * @param string $class - html class attribute |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public static function divx($id = '', $class = '') |
|
176 | - { |
|
177 | - return EEH_HTML::_close_tag('div', $id, $class); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
184 | - * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
185 | - * |
|
186 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
187 | - * @param string $id - html id attribute |
|
188 | - * @param string $class - html class attribute |
|
189 | - * @param string $style - html style attribute for applying inline styles |
|
190 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
194 | - { |
|
195 | - return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
202 | - * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
203 | - * |
|
204 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
205 | - * @param string $id - html id attribute |
|
206 | - * @param string $class - html class attribute |
|
207 | - * @param string $style - html style attribute for applying inline styles |
|
208 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
212 | - { |
|
213 | - return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
220 | - * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
221 | - * |
|
222 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
223 | - * @param string $id - html id attribute |
|
224 | - * @param string $class - html class attribute |
|
225 | - * @param string $style - html style attribute for applying inline styles |
|
226 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
230 | - { |
|
231 | - return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
238 | - * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
239 | - * |
|
240 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
241 | - * @param string $id - html id attribute |
|
242 | - * @param string $class - html class attribute |
|
243 | - * @param string $style - html style attribute for applying inline styles |
|
244 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
248 | - { |
|
249 | - return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
256 | - * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
257 | - * |
|
258 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
259 | - * @param string $id - html id attribute |
|
260 | - * @param string $class - html class attribute |
|
261 | - * @param string $style - html style attribute for applying inline styles |
|
262 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
266 | - { |
|
267 | - return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
274 | - * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
275 | - * |
|
276 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
277 | - * @param string $id - html id attribute |
|
278 | - * @param string $class - html class attribute |
|
279 | - * @param string $style - html style attribute for applying inline styles |
|
280 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
284 | - { |
|
285 | - return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
292 | - * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
293 | - * |
|
294 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
295 | - * @param string $id - html id attribute |
|
296 | - * @param string $class - html class attribute |
|
297 | - * @param string $style - html style attribute for applying inline styles |
|
298 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
302 | - { |
|
303 | - return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
310 | - * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
311 | - * |
|
312 | - * @param string $id - html id attribute |
|
313 | - * @param string $class - html class attribute |
|
314 | - * @param string $style - html style attribute for applying inline styles |
|
315 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
319 | - { |
|
320 | - return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
327 | - * usage: echo EEH_HTML::ulx(); |
|
328 | - * |
|
329 | - * @param string $id - html id attribute |
|
330 | - * @param string $class - html class attribute |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public static function ulx($id = '', $class = '') |
|
334 | - { |
|
335 | - return EEH_HTML::_close_tag('ul', $id, $class); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
342 | - * if passed content, it will also add that, as well as the closing </li> tag |
|
343 | - * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
344 | - * |
|
345 | - * @param string $id - html id attribute |
|
346 | - * @param string $class - html class attribute |
|
347 | - * @param string $style - html style attribute for applying inline styles |
|
348 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
349 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
353 | - { |
|
354 | - return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
361 | - * usage: echo EEH_HTML::lix(); |
|
362 | - * |
|
363 | - * @param string $id - html id attribute |
|
364 | - * @param string $class - html class attribute |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public static function lix($id = '', $class = '') |
|
368 | - { |
|
369 | - return EEH_HTML::_close_tag('li', $id, $class); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * table - generates an HTML <table> tag and adds any passed attributes |
|
376 | - * usage: echo EEH_HTML::table(); |
|
377 | - * |
|
378 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
379 | - * @param string $id - html id attribute |
|
380 | - * @param string $class - html class attribute |
|
381 | - * @param string $style - html style attribute for applying inline styles |
|
382 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
386 | - { |
|
387 | - return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
394 | - * |
|
395 | - * @param string $id - html id attribute |
|
396 | - * @param string $class - html class attribute |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - public static function tablex($id = '', $class = '') |
|
400 | - { |
|
401 | - return EEH_HTML::_close_tag('table', $id, $class); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * thead - generates an HTML <thead> tag and adds any passed attributes |
|
408 | - * usage: echo EEH_HTML::thead(); |
|
409 | - * |
|
410 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
411 | - * @param string $id - html id attribute |
|
412 | - * @param string $class - html class attribute |
|
413 | - * @param string $style - html style attribute for applying inline styles |
|
414 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
418 | - { |
|
419 | - return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
426 | - * |
|
427 | - * @param string $id - html id attribute |
|
428 | - * @param string $class - html class attribute |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public static function theadx($id = '', $class = '') |
|
432 | - { |
|
433 | - return EEH_HTML::_close_tag('thead', $id, $class); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
440 | - * usage: echo EEH_HTML::tbody(); |
|
441 | - * |
|
442 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
443 | - * @param string $id - html id attribute |
|
444 | - * @param string $class - html class attribute |
|
445 | - * @param string $style - html style attribute for applying inline styles |
|
446 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
450 | - { |
|
451 | - return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
458 | - * |
|
459 | - * @param string $id - html id attribute |
|
460 | - * @param string $class - html class attribute |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public static function tbodyx($id = '', $class = '') |
|
464 | - { |
|
465 | - return EEH_HTML::_close_tag('tbody', $id, $class); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * tr - generates an HTML <tr> tag and adds any passed attributes |
|
472 | - * usage: echo EEH_HTML::tr(); |
|
473 | - * |
|
474 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
475 | - * @param string $id - html id attribute |
|
476 | - * @param string $class - html class attribute |
|
477 | - * @param string $style - html style attribute for applying inline styles |
|
478 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
482 | - { |
|
483 | - return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
490 | - * |
|
491 | - * @param string $id - html id attribute |
|
492 | - * @param string $class - html class attribute |
|
493 | - * @return string |
|
494 | - */ |
|
495 | - public static function trx($id = '', $class = '') |
|
496 | - { |
|
497 | - return EEH_HTML::_close_tag('tr', $id, $class); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * th - generates an HTML <th> tag and adds any passed attributes |
|
504 | - * usage: echo EEH_HTML::th(); |
|
505 | - * |
|
506 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
507 | - * @param string $id - html id attribute |
|
508 | - * @param string $class - html class attribute |
|
509 | - * @param string $style - html style attribute for applying inline styles |
|
510 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
511 | - * @return string |
|
512 | - */ |
|
513 | - public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
514 | - { |
|
515 | - return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
522 | - * |
|
523 | - * @param string $id - html id attribute |
|
524 | - * @param string $class - html class attribute |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public static function thx($id = '', $class = '') |
|
528 | - { |
|
529 | - return EEH_HTML::_close_tag('th', $id, $class); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * td - generates an HTML <td> tag and adds any passed attributes |
|
536 | - * usage: echo EEH_HTML::td(); |
|
537 | - * |
|
538 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
539 | - * @param string $id - html id attribute |
|
540 | - * @param string $class - html class attribute |
|
541 | - * @param string $style - html style attribute for applying inline styles |
|
542 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
546 | - { |
|
547 | - return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
554 | - * |
|
555 | - * @param string $id - html id attribute |
|
556 | - * @param string $class - html class attribute |
|
557 | - * @return string |
|
558 | - */ |
|
559 | - public static function tdx($id = '', $class = '') |
|
560 | - { |
|
561 | - return EEH_HTML::_close_tag('td', $id, $class); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
568 | - * generates a new table row with one td cell that spans however many columns you set |
|
569 | - * removes all styles from the tr and td |
|
570 | - * |
|
571 | - * @param string $content |
|
572 | - * @param int $colspan |
|
573 | - * @return string |
|
574 | - */ |
|
575 | - public static function no_row($content = '', $colspan = 2) |
|
576 | - { |
|
577 | - return EEH_HTML::tr( |
|
578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
579 | - '', |
|
580 | - '', |
|
581 | - 'padding:0; border:none;' |
|
582 | - ); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
589 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
590 | - * |
|
591 | - * @access public |
|
592 | - * @param string $href URL to link to |
|
593 | - * @param string $link_text - the text that will become "hyperlinked" |
|
594 | - * @param string $title - html title attribute |
|
595 | - * @param string $id - html id attribute |
|
596 | - * @param string $class - html class attribute |
|
597 | - * @param string $style - html style attribute for applying inline styles |
|
598 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
599 | - * @return string |
|
600 | - */ |
|
601 | - public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
602 | - { |
|
603 | - $link_text = ! empty($link_text) ? $link_text : $href; |
|
604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
610 | - return "<a{$attributes}>{$link_text}</a>"; |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * img - generates an HTML <img> tag and adds any passed attributes |
|
617 | - * usage: echo EEH_HTML::img(); |
|
618 | - * |
|
619 | - * @param string $src - html src attribute ie: the path or URL to the image |
|
620 | - * @param string $alt - html alt attribute |
|
621 | - * @param string $id - html id attribute |
|
622 | - * @param string $class - html class attribute |
|
623 | - * @param string $style - html style attribute for applying inline styles |
|
624 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
625 | - * @return string |
|
626 | - */ |
|
627 | - public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
628 | - { |
|
629 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
630 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
631 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
632 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
633 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
634 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
635 | - return '<img' . $attributes . '/>'; |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
642 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
643 | - * |
|
644 | - * @access protected |
|
645 | - * @param string $tag |
|
646 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
647 | - * @param string $id - html id attribute |
|
648 | - * @param string $class - html class attribute |
|
649 | - * @param string $style - html style attribute for applying inline styles |
|
650 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
651 | - * @return string |
|
652 | - */ |
|
653 | - protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
654 | - { |
|
655 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
656 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
657 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
658 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
659 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
666 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
667 | - * |
|
668 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
669 | - * @param string $id - html id attribute |
|
670 | - * @param string $class - html class attribute |
|
671 | - * @param string $style - html style attribute for applying inline styles |
|
672 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
673 | - * @return string |
|
674 | - */ |
|
675 | - public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
676 | - { |
|
677 | - return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
684 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
685 | - * |
|
686 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
687 | - * @param string $id - html id attribute |
|
688 | - * @param string $class - html class attribute |
|
689 | - * @param string $style - html style attribute for applying inline styles |
|
690 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
691 | - * @return string |
|
692 | - */ |
|
693 | - public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
694 | - { |
|
695 | - return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
702 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
703 | - * |
|
704 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
705 | - * @param string $id - html id attribute |
|
706 | - * @param string $class - html class attribute |
|
707 | - * @param string $style - html style attribute for applying inline styles |
|
708 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
709 | - * @return string |
|
710 | - */ |
|
711 | - public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
712 | - { |
|
713 | - return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * Generates an html <-- comment --> tag |
|
720 | - * usage: echo comment( 'this is a comment' ); |
|
721 | - * |
|
722 | - * @param string $comment |
|
723 | - * @return string |
|
724 | - */ |
|
725 | - public static function comment($comment = '') |
|
726 | - { |
|
727 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * br - generates a line break |
|
734 | - * |
|
735 | - * @param int $nmbr - the number of line breaks to return |
|
736 | - * @return string |
|
737 | - */ |
|
738 | - public static function br($nmbr = 1) |
|
739 | - { |
|
740 | - return str_repeat('<br />', $nmbr); |
|
741 | - } |
|
742 | - |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * nbsp - generates non-breaking space entities based on number supplied |
|
747 | - * |
|
748 | - * @param int $nmbr - the number of non-breaking spaces to return |
|
749 | - * @return string |
|
750 | - */ |
|
751 | - public static function nbsp($nmbr = 1) |
|
752 | - { |
|
753 | - return str_repeat(' ', $nmbr); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - |
|
758 | - /** |
|
759 | - * sanitize_id |
|
760 | - * |
|
761 | - * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
762 | - * strtolower and allows capitals. |
|
763 | - * |
|
764 | - * @param string $id |
|
765 | - * @return string |
|
766 | - */ |
|
767 | - public static function sanitize_id($id = '') |
|
768 | - { |
|
769 | - $key = str_replace(' ', '-', trim($id)); |
|
770 | - return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * return a newline and tabs ("nl" stands for "new line") |
|
777 | - * |
|
778 | - * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
779 | - * @param string $tag |
|
780 | - * @return string - newline character plus # of indents passed (can be + or -) |
|
781 | - */ |
|
782 | - public static function nl($indent = 0, $tag = 'none') |
|
783 | - { |
|
784 | - $html = "\n"; |
|
785 | - EEH_HTML::indent($indent, $tag); |
|
786 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
787 | - $html .= "\t"; |
|
788 | - } |
|
789 | - return $html; |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
796 | - * the indentation level without actually creating a new line |
|
797 | - * |
|
798 | - * @param int $indent can be negative to decrease the indentation level |
|
799 | - * @param string $tag |
|
800 | - */ |
|
801 | - public static function indent($indent, $tag = 'none') |
|
802 | - { |
|
803 | - static $default_indentation = false; |
|
804 | - if (! $default_indentation) { |
|
805 | - EEH_HTML::_set_default_indentation(); |
|
806 | - $default_indentation = true; |
|
807 | - } |
|
808 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
809 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
810 | - } |
|
811 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
812 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * class _set_default_indentation |
|
818 | - * |
|
819 | - * @access private |
|
820 | - */ |
|
821 | - private static function _set_default_indentation() |
|
822 | - { |
|
823 | - // set some initial formatting for table indentation |
|
824 | - EEH_HTML::$_indent = array( |
|
825 | - 'none' => 0, |
|
826 | - 'form' => 0, |
|
827 | - 'radio' => 0, |
|
828 | - 'checkbox' => 0, |
|
829 | - 'select' => 0, |
|
830 | - 'option' => 0, |
|
831 | - 'optgroup' => 0, |
|
832 | - 'table' => 1, |
|
833 | - 'thead' => 2, |
|
834 | - 'tbody' => 2, |
|
835 | - 'tr' => 3, |
|
836 | - 'th' => 4, |
|
837 | - 'td' => 4, |
|
838 | - 'div' => 0, |
|
839 | - 'h1' => 0, |
|
840 | - 'h2' => 0, |
|
841 | - 'h3' => 0, |
|
842 | - 'h4' => 0, |
|
843 | - 'h5' => 0, |
|
844 | - 'h6' => 0, |
|
845 | - 'p' => 0, |
|
846 | - 'ul' => 0, |
|
847 | - 'li' => 1 |
|
848 | - ); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * Retrieves the list of tags considered "simple", that are probably safe for |
|
855 | - * use in inputs |
|
856 | - * @global array $allowedtags |
|
857 | - * @return array |
|
858 | - */ |
|
859 | - public static function get_simple_tags() |
|
860 | - { |
|
861 | - global $allowedtags; |
|
862 | - $tags_we_allow['p'] = array(); |
|
863 | - $tags_we_allow = array_merge_recursive( |
|
864 | - $allowedtags, |
|
865 | - array( |
|
866 | - 'ol' => array(), |
|
867 | - 'ul' => array(), |
|
868 | - 'li' => array(), |
|
869 | - 'br' => array(), |
|
870 | - 'p' => array(), |
|
871 | - 'a' => array('target') |
|
872 | - ) |
|
873 | - ); |
|
874 | - return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
875 | - } |
|
126 | + * @param string $tag |
|
127 | + * @param string $id - html id attribute |
|
128 | + * @param string $class - html class attribute |
|
129 | + * @param bool $indent |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
133 | + { |
|
134 | + $comment = ''; |
|
135 | + if ($id) { |
|
136 | + $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
137 | + } elseif ($class) { |
|
138 | + $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
139 | + } |
|
140 | + $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
141 | + $html .= '</' . $tag . '>' . $comment; |
|
142 | + return $html; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * div - generates HTML opening <div> tag and adds any passed attributes |
|
149 | + * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
150 | + * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
151 | + * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
152 | + * |
|
153 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
154 | + * @param string $id - html id attribute |
|
155 | + * @param string $class - html class attribute |
|
156 | + * @param string $style - html style attribute for applying inline styles |
|
157 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
161 | + { |
|
162 | + return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
169 | + * usage: echo EEH_HTML::divx(); |
|
170 | + * |
|
171 | + * @param string $id - html id attribute |
|
172 | + * @param string $class - html class attribute |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public static function divx($id = '', $class = '') |
|
176 | + { |
|
177 | + return EEH_HTML::_close_tag('div', $id, $class); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
184 | + * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
185 | + * |
|
186 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
187 | + * @param string $id - html id attribute |
|
188 | + * @param string $class - html class attribute |
|
189 | + * @param string $style - html style attribute for applying inline styles |
|
190 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
194 | + { |
|
195 | + return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
202 | + * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
203 | + * |
|
204 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
205 | + * @param string $id - html id attribute |
|
206 | + * @param string $class - html class attribute |
|
207 | + * @param string $style - html style attribute for applying inline styles |
|
208 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
212 | + { |
|
213 | + return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
220 | + * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
221 | + * |
|
222 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
223 | + * @param string $id - html id attribute |
|
224 | + * @param string $class - html class attribute |
|
225 | + * @param string $style - html style attribute for applying inline styles |
|
226 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
230 | + { |
|
231 | + return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
238 | + * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
239 | + * |
|
240 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
241 | + * @param string $id - html id attribute |
|
242 | + * @param string $class - html class attribute |
|
243 | + * @param string $style - html style attribute for applying inline styles |
|
244 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
248 | + { |
|
249 | + return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
256 | + * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
257 | + * |
|
258 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
259 | + * @param string $id - html id attribute |
|
260 | + * @param string $class - html class attribute |
|
261 | + * @param string $style - html style attribute for applying inline styles |
|
262 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
266 | + { |
|
267 | + return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
274 | + * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
275 | + * |
|
276 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
277 | + * @param string $id - html id attribute |
|
278 | + * @param string $class - html class attribute |
|
279 | + * @param string $style - html style attribute for applying inline styles |
|
280 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
284 | + { |
|
285 | + return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
292 | + * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
293 | + * |
|
294 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
295 | + * @param string $id - html id attribute |
|
296 | + * @param string $class - html class attribute |
|
297 | + * @param string $style - html style attribute for applying inline styles |
|
298 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
302 | + { |
|
303 | + return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
310 | + * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
311 | + * |
|
312 | + * @param string $id - html id attribute |
|
313 | + * @param string $class - html class attribute |
|
314 | + * @param string $style - html style attribute for applying inline styles |
|
315 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
319 | + { |
|
320 | + return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
327 | + * usage: echo EEH_HTML::ulx(); |
|
328 | + * |
|
329 | + * @param string $id - html id attribute |
|
330 | + * @param string $class - html class attribute |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public static function ulx($id = '', $class = '') |
|
334 | + { |
|
335 | + return EEH_HTML::_close_tag('ul', $id, $class); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
342 | + * if passed content, it will also add that, as well as the closing </li> tag |
|
343 | + * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
344 | + * |
|
345 | + * @param string $id - html id attribute |
|
346 | + * @param string $class - html class attribute |
|
347 | + * @param string $style - html style attribute for applying inline styles |
|
348 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
349 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
353 | + { |
|
354 | + return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
361 | + * usage: echo EEH_HTML::lix(); |
|
362 | + * |
|
363 | + * @param string $id - html id attribute |
|
364 | + * @param string $class - html class attribute |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public static function lix($id = '', $class = '') |
|
368 | + { |
|
369 | + return EEH_HTML::_close_tag('li', $id, $class); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * table - generates an HTML <table> tag and adds any passed attributes |
|
376 | + * usage: echo EEH_HTML::table(); |
|
377 | + * |
|
378 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
379 | + * @param string $id - html id attribute |
|
380 | + * @param string $class - html class attribute |
|
381 | + * @param string $style - html style attribute for applying inline styles |
|
382 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
386 | + { |
|
387 | + return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
394 | + * |
|
395 | + * @param string $id - html id attribute |
|
396 | + * @param string $class - html class attribute |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + public static function tablex($id = '', $class = '') |
|
400 | + { |
|
401 | + return EEH_HTML::_close_tag('table', $id, $class); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * thead - generates an HTML <thead> tag and adds any passed attributes |
|
408 | + * usage: echo EEH_HTML::thead(); |
|
409 | + * |
|
410 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
411 | + * @param string $id - html id attribute |
|
412 | + * @param string $class - html class attribute |
|
413 | + * @param string $style - html style attribute for applying inline styles |
|
414 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
418 | + { |
|
419 | + return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
426 | + * |
|
427 | + * @param string $id - html id attribute |
|
428 | + * @param string $class - html class attribute |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public static function theadx($id = '', $class = '') |
|
432 | + { |
|
433 | + return EEH_HTML::_close_tag('thead', $id, $class); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
440 | + * usage: echo EEH_HTML::tbody(); |
|
441 | + * |
|
442 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
443 | + * @param string $id - html id attribute |
|
444 | + * @param string $class - html class attribute |
|
445 | + * @param string $style - html style attribute for applying inline styles |
|
446 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
450 | + { |
|
451 | + return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
458 | + * |
|
459 | + * @param string $id - html id attribute |
|
460 | + * @param string $class - html class attribute |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public static function tbodyx($id = '', $class = '') |
|
464 | + { |
|
465 | + return EEH_HTML::_close_tag('tbody', $id, $class); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * tr - generates an HTML <tr> tag and adds any passed attributes |
|
472 | + * usage: echo EEH_HTML::tr(); |
|
473 | + * |
|
474 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
475 | + * @param string $id - html id attribute |
|
476 | + * @param string $class - html class attribute |
|
477 | + * @param string $style - html style attribute for applying inline styles |
|
478 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
482 | + { |
|
483 | + return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
490 | + * |
|
491 | + * @param string $id - html id attribute |
|
492 | + * @param string $class - html class attribute |
|
493 | + * @return string |
|
494 | + */ |
|
495 | + public static function trx($id = '', $class = '') |
|
496 | + { |
|
497 | + return EEH_HTML::_close_tag('tr', $id, $class); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * th - generates an HTML <th> tag and adds any passed attributes |
|
504 | + * usage: echo EEH_HTML::th(); |
|
505 | + * |
|
506 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
507 | + * @param string $id - html id attribute |
|
508 | + * @param string $class - html class attribute |
|
509 | + * @param string $style - html style attribute for applying inline styles |
|
510 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
511 | + * @return string |
|
512 | + */ |
|
513 | + public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
514 | + { |
|
515 | + return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
522 | + * |
|
523 | + * @param string $id - html id attribute |
|
524 | + * @param string $class - html class attribute |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public static function thx($id = '', $class = '') |
|
528 | + { |
|
529 | + return EEH_HTML::_close_tag('th', $id, $class); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * td - generates an HTML <td> tag and adds any passed attributes |
|
536 | + * usage: echo EEH_HTML::td(); |
|
537 | + * |
|
538 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
539 | + * @param string $id - html id attribute |
|
540 | + * @param string $class - html class attribute |
|
541 | + * @param string $style - html style attribute for applying inline styles |
|
542 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
546 | + { |
|
547 | + return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
554 | + * |
|
555 | + * @param string $id - html id attribute |
|
556 | + * @param string $class - html class attribute |
|
557 | + * @return string |
|
558 | + */ |
|
559 | + public static function tdx($id = '', $class = '') |
|
560 | + { |
|
561 | + return EEH_HTML::_close_tag('td', $id, $class); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
568 | + * generates a new table row with one td cell that spans however many columns you set |
|
569 | + * removes all styles from the tr and td |
|
570 | + * |
|
571 | + * @param string $content |
|
572 | + * @param int $colspan |
|
573 | + * @return string |
|
574 | + */ |
|
575 | + public static function no_row($content = '', $colspan = 2) |
|
576 | + { |
|
577 | + return EEH_HTML::tr( |
|
578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
579 | + '', |
|
580 | + '', |
|
581 | + 'padding:0; border:none;' |
|
582 | + ); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
589 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
590 | + * |
|
591 | + * @access public |
|
592 | + * @param string $href URL to link to |
|
593 | + * @param string $link_text - the text that will become "hyperlinked" |
|
594 | + * @param string $title - html title attribute |
|
595 | + * @param string $id - html id attribute |
|
596 | + * @param string $class - html class attribute |
|
597 | + * @param string $style - html style attribute for applying inline styles |
|
598 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
599 | + * @return string |
|
600 | + */ |
|
601 | + public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
602 | + { |
|
603 | + $link_text = ! empty($link_text) ? $link_text : $href; |
|
604 | + $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | + $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
610 | + return "<a{$attributes}>{$link_text}</a>"; |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * img - generates an HTML <img> tag and adds any passed attributes |
|
617 | + * usage: echo EEH_HTML::img(); |
|
618 | + * |
|
619 | + * @param string $src - html src attribute ie: the path or URL to the image |
|
620 | + * @param string $alt - html alt attribute |
|
621 | + * @param string $id - html id attribute |
|
622 | + * @param string $class - html class attribute |
|
623 | + * @param string $style - html style attribute for applying inline styles |
|
624 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
625 | + * @return string |
|
626 | + */ |
|
627 | + public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
628 | + { |
|
629 | + $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
630 | + $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
631 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
632 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
633 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
634 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
635 | + return '<img' . $attributes . '/>'; |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
642 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
643 | + * |
|
644 | + * @access protected |
|
645 | + * @param string $tag |
|
646 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
647 | + * @param string $id - html id attribute |
|
648 | + * @param string $class - html class attribute |
|
649 | + * @param string $style - html style attribute for applying inline styles |
|
650 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
651 | + * @return string |
|
652 | + */ |
|
653 | + protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
654 | + { |
|
655 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
656 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
657 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
658 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
659 | + return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
666 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
667 | + * |
|
668 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
669 | + * @param string $id - html id attribute |
|
670 | + * @param string $class - html class attribute |
|
671 | + * @param string $style - html style attribute for applying inline styles |
|
672 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
673 | + * @return string |
|
674 | + */ |
|
675 | + public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
676 | + { |
|
677 | + return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
684 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
685 | + * |
|
686 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
687 | + * @param string $id - html id attribute |
|
688 | + * @param string $class - html class attribute |
|
689 | + * @param string $style - html style attribute for applying inline styles |
|
690 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
691 | + * @return string |
|
692 | + */ |
|
693 | + public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
694 | + { |
|
695 | + return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
702 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
703 | + * |
|
704 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
705 | + * @param string $id - html id attribute |
|
706 | + * @param string $class - html class attribute |
|
707 | + * @param string $style - html style attribute for applying inline styles |
|
708 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
709 | + * @return string |
|
710 | + */ |
|
711 | + public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
712 | + { |
|
713 | + return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * Generates an html <-- comment --> tag |
|
720 | + * usage: echo comment( 'this is a comment' ); |
|
721 | + * |
|
722 | + * @param string $comment |
|
723 | + * @return string |
|
724 | + */ |
|
725 | + public static function comment($comment = '') |
|
726 | + { |
|
727 | + return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * br - generates a line break |
|
734 | + * |
|
735 | + * @param int $nmbr - the number of line breaks to return |
|
736 | + * @return string |
|
737 | + */ |
|
738 | + public static function br($nmbr = 1) |
|
739 | + { |
|
740 | + return str_repeat('<br />', $nmbr); |
|
741 | + } |
|
742 | + |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * nbsp - generates non-breaking space entities based on number supplied |
|
747 | + * |
|
748 | + * @param int $nmbr - the number of non-breaking spaces to return |
|
749 | + * @return string |
|
750 | + */ |
|
751 | + public static function nbsp($nmbr = 1) |
|
752 | + { |
|
753 | + return str_repeat(' ', $nmbr); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + |
|
758 | + /** |
|
759 | + * sanitize_id |
|
760 | + * |
|
761 | + * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
762 | + * strtolower and allows capitals. |
|
763 | + * |
|
764 | + * @param string $id |
|
765 | + * @return string |
|
766 | + */ |
|
767 | + public static function sanitize_id($id = '') |
|
768 | + { |
|
769 | + $key = str_replace(' ', '-', trim($id)); |
|
770 | + return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * return a newline and tabs ("nl" stands for "new line") |
|
777 | + * |
|
778 | + * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
779 | + * @param string $tag |
|
780 | + * @return string - newline character plus # of indents passed (can be + or -) |
|
781 | + */ |
|
782 | + public static function nl($indent = 0, $tag = 'none') |
|
783 | + { |
|
784 | + $html = "\n"; |
|
785 | + EEH_HTML::indent($indent, $tag); |
|
786 | + for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
787 | + $html .= "\t"; |
|
788 | + } |
|
789 | + return $html; |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
796 | + * the indentation level without actually creating a new line |
|
797 | + * |
|
798 | + * @param int $indent can be negative to decrease the indentation level |
|
799 | + * @param string $tag |
|
800 | + */ |
|
801 | + public static function indent($indent, $tag = 'none') |
|
802 | + { |
|
803 | + static $default_indentation = false; |
|
804 | + if (! $default_indentation) { |
|
805 | + EEH_HTML::_set_default_indentation(); |
|
806 | + $default_indentation = true; |
|
807 | + } |
|
808 | + if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
809 | + EEH_HTML::$_indent[ $tag ] = 0; |
|
810 | + } |
|
811 | + EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
812 | + EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * class _set_default_indentation |
|
818 | + * |
|
819 | + * @access private |
|
820 | + */ |
|
821 | + private static function _set_default_indentation() |
|
822 | + { |
|
823 | + // set some initial formatting for table indentation |
|
824 | + EEH_HTML::$_indent = array( |
|
825 | + 'none' => 0, |
|
826 | + 'form' => 0, |
|
827 | + 'radio' => 0, |
|
828 | + 'checkbox' => 0, |
|
829 | + 'select' => 0, |
|
830 | + 'option' => 0, |
|
831 | + 'optgroup' => 0, |
|
832 | + 'table' => 1, |
|
833 | + 'thead' => 2, |
|
834 | + 'tbody' => 2, |
|
835 | + 'tr' => 3, |
|
836 | + 'th' => 4, |
|
837 | + 'td' => 4, |
|
838 | + 'div' => 0, |
|
839 | + 'h1' => 0, |
|
840 | + 'h2' => 0, |
|
841 | + 'h3' => 0, |
|
842 | + 'h4' => 0, |
|
843 | + 'h5' => 0, |
|
844 | + 'h6' => 0, |
|
845 | + 'p' => 0, |
|
846 | + 'ul' => 0, |
|
847 | + 'li' => 1 |
|
848 | + ); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * Retrieves the list of tags considered "simple", that are probably safe for |
|
855 | + * use in inputs |
|
856 | + * @global array $allowedtags |
|
857 | + * @return array |
|
858 | + */ |
|
859 | + public static function get_simple_tags() |
|
860 | + { |
|
861 | + global $allowedtags; |
|
862 | + $tags_we_allow['p'] = array(); |
|
863 | + $tags_we_allow = array_merge_recursive( |
|
864 | + $allowedtags, |
|
865 | + array( |
|
866 | + 'ol' => array(), |
|
867 | + 'ul' => array(), |
|
868 | + 'li' => array(), |
|
869 | + 'br' => array(), |
|
870 | + 'p' => array(), |
|
871 | + 'a' => array('target') |
|
872 | + ) |
|
873 | + ); |
|
874 | + return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
875 | + } |
|
876 | 876 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public static function instance() |
44 | 44 | { |
45 | 45 | // check if class object is instantiated, and instantiated properly |
46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
46 | + if ( ! self::$_instance instanceof EEH_HTML) { |
|
47 | 47 | self::$_instance = new EEH_HTML(); |
48 | 48 | } |
49 | 49 | return self::$_instance; |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | $other_attributes = '', |
106 | 106 | $force_close = false |
107 | 107 | ) { |
108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
108 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
109 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
110 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
111 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
112 | + $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>'; |
|
113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : ''; |
|
114 | 114 | $indent = ! empty($content) || $force_close ? true : false; |
115 | 115 | $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
116 | 116 | return $html; |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | { |
134 | 134 | $comment = ''; |
135 | 135 | if ($id) { |
136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
136 | + $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag); |
|
137 | 137 | } elseif ($class) { |
138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
138 | + $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag); |
|
139 | 139 | } |
140 | 140 | $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
141 | - $html .= '</' . $tag . '>' . $comment; |
|
141 | + $html .= '</'.$tag.'>'.$comment; |
|
142 | 142 | return $html; |
143 | 143 | } |
144 | 144 | |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | public static function no_row($content = '', $colspan = 2) |
576 | 576 | { |
577 | 577 | return EEH_HTML::tr( |
578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'), |
|
579 | 579 | '', |
580 | 580 | '', |
581 | 581 | 'padding:0; border:none;' |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
602 | 602 | { |
603 | 603 | $link_text = ! empty($link_text) ? $link_text : $href; |
604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
604 | + $attributes = ! empty($href) ? ' href="'.$href.'"' : ''; |
|
605 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
606 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
607 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
608 | + $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : ''; |
|
609 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
610 | 610 | return "<a{$attributes}>{$link_text}</a>"; |
611 | 611 | } |
612 | 612 | |
@@ -626,13 +626,13 @@ discard block |
||
626 | 626 | */ |
627 | 627 | public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
628 | 628 | { |
629 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
630 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
631 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
632 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
633 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
634 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
635 | - return '<img' . $attributes . '/>'; |
|
629 | + $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : ''; |
|
630 | + $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : ''; |
|
631 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
632 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
633 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
634 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
635 | + return '<img'.$attributes.'/>'; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -652,11 +652,11 @@ discard block |
||
652 | 652 | */ |
653 | 653 | protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
654 | 654 | { |
655 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
656 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
657 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
658 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
659 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
655 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
656 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
657 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
658 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
659 | + return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>'; |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | */ |
725 | 725 | public static function comment($comment = '') |
726 | 726 | { |
727 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
727 | + return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : ''; |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | { |
784 | 784 | $html = "\n"; |
785 | 785 | EEH_HTML::indent($indent, $tag); |
786 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
786 | + for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { |
|
787 | 787 | $html .= "\t"; |
788 | 788 | } |
789 | 789 | return $html; |
@@ -801,15 +801,15 @@ discard block |
||
801 | 801 | public static function indent($indent, $tag = 'none') |
802 | 802 | { |
803 | 803 | static $default_indentation = false; |
804 | - if (! $default_indentation) { |
|
804 | + if ( ! $default_indentation) { |
|
805 | 805 | EEH_HTML::_set_default_indentation(); |
806 | 806 | $default_indentation = true; |
807 | 807 | } |
808 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
809 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
808 | + if ( ! isset(EEH_HTML::$_indent[$tag])) { |
|
809 | + EEH_HTML::$_indent[$tag] = 0; |
|
810 | 810 | } |
811 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
812 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
811 | + EEH_HTML::$_indent[$tag] += (int) $indent; |
|
812 | + EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0; |
|
813 | 813 | } |
814 | 814 | |
815 | 815 |
@@ -12,131 +12,131 @@ |
||
12 | 12 | class EEH_Class_Tools |
13 | 13 | { |
14 | 14 | |
15 | - public static $i = 0; |
|
16 | - public static $file_line = null; |
|
15 | + public static $i = 0; |
|
16 | + public static $file_line = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * get_called_class - for PHP versions < 5.3 |
|
20 | - * |
|
21 | - * @access public |
|
22 | - * @author origins: http://stackoverflow.com/a/1542045 |
|
23 | - * return string |
|
24 | - */ |
|
25 | - public static function get_called_class() |
|
26 | - { |
|
27 | - $backtrace = debug_backtrace(); |
|
28 | - if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) { |
|
29 | - return $backtrace[2]['class']; |
|
30 | - } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
|
31 | - return $backtrace[3]['class']; |
|
32 | - } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
|
33 | - if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
34 | - self::$i++; |
|
35 | - } else { |
|
36 | - self::$i = 0; |
|
37 | - self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
38 | - } |
|
39 | - // was class method called via call_user_func ? |
|
40 | - if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
|
41 | - if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) { |
|
42 | - $called_class = $backtrace[2]['args'][0][0]; |
|
43 | - // is it an EE function ? |
|
44 | - if (strpos($called_class, 'EE') === 0) { |
|
45 | - $prefix_chars = strpos($called_class, '_') + 1; |
|
46 | - $prefix = substr($called_class, 0, $prefix_chars); |
|
47 | - $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
|
48 | - $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
49 | - return $classname; |
|
50 | - } |
|
51 | - } |
|
52 | - } else { |
|
53 | - $lines = file($backtrace[2]['file']); |
|
54 | - preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches); |
|
55 | - if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
56 | - return $matches[1][ self::$i ]; |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
60 | - return false; |
|
61 | - } |
|
18 | + /** |
|
19 | + * get_called_class - for PHP versions < 5.3 |
|
20 | + * |
|
21 | + * @access public |
|
22 | + * @author origins: http://stackoverflow.com/a/1542045 |
|
23 | + * return string |
|
24 | + */ |
|
25 | + public static function get_called_class() |
|
26 | + { |
|
27 | + $backtrace = debug_backtrace(); |
|
28 | + if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) { |
|
29 | + return $backtrace[2]['class']; |
|
30 | + } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
|
31 | + return $backtrace[3]['class']; |
|
32 | + } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
|
33 | + if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
34 | + self::$i++; |
|
35 | + } else { |
|
36 | + self::$i = 0; |
|
37 | + self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
38 | + } |
|
39 | + // was class method called via call_user_func ? |
|
40 | + if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
|
41 | + if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) { |
|
42 | + $called_class = $backtrace[2]['args'][0][0]; |
|
43 | + // is it an EE function ? |
|
44 | + if (strpos($called_class, 'EE') === 0) { |
|
45 | + $prefix_chars = strpos($called_class, '_') + 1; |
|
46 | + $prefix = substr($called_class, 0, $prefix_chars); |
|
47 | + $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
|
48 | + $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
49 | + return $classname; |
|
50 | + } |
|
51 | + } |
|
52 | + } else { |
|
53 | + $lines = file($backtrace[2]['file']); |
|
54 | + preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches); |
|
55 | + if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
56 | + return $matches[1][ self::$i ]; |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * get_class_names_for_all_callbacks_on_hook |
|
68 | - * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook |
|
69 | - * @access public |
|
70 | - * @param string $hook |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public static function get_class_names_for_all_callbacks_on_hook($hook = null) |
|
74 | - { |
|
75 | - global $wp_filter; |
|
76 | - $class_names = array(); |
|
77 | - // are any callbacks registered for this hook ? |
|
78 | - if (isset($wp_filter[ $hook ])) { |
|
79 | - // loop thru all of the callbacks attached to the deprecated hookpoint |
|
80 | - foreach ($wp_filter[ $hook ] as $priority) { |
|
81 | - foreach ($priority as $callback) { |
|
82 | - // is the callback a non-static class method ? |
|
83 | - if (isset($callback['function']) && is_array($callback['function'])) { |
|
84 | - if (isset($callback['function'][0]) && is_object($callback['function'][0])) { |
|
85 | - $class_names[] = get_class($callback['function'][0]); |
|
86 | - } |
|
87 | - // test for static method |
|
88 | - } elseif (strpos($callback['function'], '::') !== false) { |
|
89 | - $class = explode('::', $callback['function']); |
|
90 | - $class_names[] = $class[0]; |
|
91 | - } else { |
|
92 | - // just a function |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - return $class_names; |
|
98 | - } |
|
66 | + /** |
|
67 | + * get_class_names_for_all_callbacks_on_hook |
|
68 | + * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook |
|
69 | + * @access public |
|
70 | + * @param string $hook |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public static function get_class_names_for_all_callbacks_on_hook($hook = null) |
|
74 | + { |
|
75 | + global $wp_filter; |
|
76 | + $class_names = array(); |
|
77 | + // are any callbacks registered for this hook ? |
|
78 | + if (isset($wp_filter[ $hook ])) { |
|
79 | + // loop thru all of the callbacks attached to the deprecated hookpoint |
|
80 | + foreach ($wp_filter[ $hook ] as $priority) { |
|
81 | + foreach ($priority as $callback) { |
|
82 | + // is the callback a non-static class method ? |
|
83 | + if (isset($callback['function']) && is_array($callback['function'])) { |
|
84 | + if (isset($callback['function'][0]) && is_object($callback['function'][0])) { |
|
85 | + $class_names[] = get_class($callback['function'][0]); |
|
86 | + } |
|
87 | + // test for static method |
|
88 | + } elseif (strpos($callback['function'], '::') !== false) { |
|
89 | + $class = explode('::', $callback['function']); |
|
90 | + $class_names[] = $class[0]; |
|
91 | + } else { |
|
92 | + // just a function |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + return $class_names; |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * property_exists() with fallback for PHP versions < 5.3 |
|
105 | - * @access public |
|
106 | - * @param mixed object | string $class |
|
107 | - * @param string $property |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - public static function has_property($class = null, $property = null) |
|
111 | - { |
|
112 | - // if $class or $property don't exist, then get out, cuz that would be like... fatal dude |
|
113 | - if (empty($class) || empty($property)) { |
|
114 | - return false; |
|
115 | - } |
|
116 | - // if your hosting company doesn't cut the mustard |
|
117 | - if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
118 | - // just in case $class is an actual instantiated object |
|
119 | - if (is_object($class)) { |
|
120 | - return isset($class->{$property}) ? true : false; |
|
121 | - } else { |
|
122 | - // use reflection for < PHP 5.3 to get details using just the class name |
|
123 | - $reflector = new ReflectionClass($class); |
|
124 | - return $reflector->hasProperty($property); |
|
125 | - } |
|
126 | - } else { |
|
127 | - // or try regular property exists method which works as expected in PHP 5.3+ |
|
128 | - return property_exists($class, $property); |
|
129 | - } |
|
130 | - } |
|
103 | + /** |
|
104 | + * property_exists() with fallback for PHP versions < 5.3 |
|
105 | + * @access public |
|
106 | + * @param mixed object | string $class |
|
107 | + * @param string $property |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + public static function has_property($class = null, $property = null) |
|
111 | + { |
|
112 | + // if $class or $property don't exist, then get out, cuz that would be like... fatal dude |
|
113 | + if (empty($class) || empty($property)) { |
|
114 | + return false; |
|
115 | + } |
|
116 | + // if your hosting company doesn't cut the mustard |
|
117 | + if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
118 | + // just in case $class is an actual instantiated object |
|
119 | + if (is_object($class)) { |
|
120 | + return isset($class->{$property}) ? true : false; |
|
121 | + } else { |
|
122 | + // use reflection for < PHP 5.3 to get details using just the class name |
|
123 | + $reflector = new ReflectionClass($class); |
|
124 | + return $reflector->hasProperty($property); |
|
125 | + } |
|
126 | + } else { |
|
127 | + // or try regular property exists method which works as expected in PHP 5.3+ |
|
128 | + return property_exists($class, $property); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | // if PHP version < 5.3 |
134 | 134 | if (! function_exists('get_called_class')) { |
135 | - /** |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - function get_called_class() |
|
139 | - { |
|
140 | - return EEH_Class_Tools::get_called_class(); |
|
141 | - } |
|
135 | + /** |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + function get_called_class() |
|
139 | + { |
|
140 | + return EEH_Class_Tools::get_called_class(); |
|
141 | + } |
|
142 | 142 | } |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
31 | 31 | return $backtrace[3]['class']; |
32 | 32 | } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
33 | - if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
33 | + if (self::$file_line == $backtrace[2]['file'].$backtrace[2]['line']) { |
|
34 | 34 | self::$i++; |
35 | 35 | } else { |
36 | 36 | self::$i = 0; |
37 | - self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
37 | + self::$file_line = $backtrace[2]['file'].$backtrace[2]['line']; |
|
38 | 38 | } |
39 | 39 | // was class method called via call_user_func ? |
40 | 40 | if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | $prefix_chars = strpos($called_class, '_') + 1; |
46 | 46 | $prefix = substr($called_class, 0, $prefix_chars); |
47 | 47 | $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
48 | - $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
48 | + $classname = $prefix.str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
49 | 49 | return $classname; |
50 | 50 | } |
51 | 51 | } |
52 | 52 | } else { |
53 | 53 | $lines = file($backtrace[2]['file']); |
54 | - preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches); |
|
55 | - if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
56 | - return $matches[1][ self::$i ]; |
|
54 | + preg_match_all('/([a-zA-Z0-9\_]+)::'.$backtrace[2]['function'].'/', $lines[$backtrace[2]['line'] - 1], $matches); |
|
55 | + if (isset($matches[1]) && isset($matches[1][self::$i])) { |
|
56 | + return $matches[1][self::$i]; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | global $wp_filter; |
76 | 76 | $class_names = array(); |
77 | 77 | // are any callbacks registered for this hook ? |
78 | - if (isset($wp_filter[ $hook ])) { |
|
78 | + if (isset($wp_filter[$hook])) { |
|
79 | 79 | // loop thru all of the callbacks attached to the deprecated hookpoint |
80 | - foreach ($wp_filter[ $hook ] as $priority) { |
|
80 | + foreach ($wp_filter[$hook] as $priority) { |
|
81 | 81 | foreach ($priority as $callback) { |
82 | 82 | // is the callback a non-static class method ? |
83 | 83 | if (isset($callback['function']) && is_array($callback['function'])) { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | // if PHP version < 5.3 |
134 | -if (! function_exists('get_called_class')) { |
|
134 | +if ( ! function_exists('get_called_class')) { |
|
135 | 135 | /** |
136 | 136 | * @return string |
137 | 137 | */ |
@@ -33,384 +33,384 @@ |
||
33 | 33 | */ |
34 | 34 | class EEH_Inflector |
35 | 35 | { |
36 | - // ------ CLASS METHODS ------ // |
|
37 | - // ---- Public methods ---- // |
|
38 | - // {{{ pluralize() |
|
39 | - |
|
40 | - /** |
|
41 | - * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | - * @param string $word |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function pluralize_and_lower($word) |
|
46 | - { |
|
47 | - return strtolower(self::pluralize($word)); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param string $word |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public static function singularize_and_upper($word) |
|
57 | - { |
|
58 | - return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Pluralizes English nouns. |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @static |
|
68 | - * @param string $word English noun to pluralize |
|
69 | - * @return string Plural noun |
|
70 | - */ |
|
71 | - public static function pluralize($word) |
|
72 | - { |
|
73 | - $plural = array( |
|
74 | - '/(quiz)$/i' => '\1zes', |
|
75 | - '/^(ox)$/i' => '\1en', |
|
76 | - '/([m|l])ouse$/i' => '\1ice', |
|
77 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | - '/(hive)$/i' => '\1s', |
|
82 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | - '/sis$/i' => 'ses', |
|
84 | - '/([ti])um$/i' => '\1a', |
|
85 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | - '/(bu)s$/i' => '\1ses', |
|
87 | - '/(alias|status)/i' => '\1es', |
|
88 | - '/(octop|vir)us$/i' => '\1i', |
|
89 | - '/(ax|test)is$/i' => '\1es', |
|
90 | - '/s$/i' => 's', |
|
91 | - '/$/' => 's'); |
|
92 | - |
|
93 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | - |
|
95 | - $irregular = array( |
|
96 | - 'person' => 'people', |
|
97 | - 'man' => 'men', |
|
98 | - 'child' => 'children', |
|
99 | - 'sex' => 'sexes', |
|
100 | - 'move' => 'moves'); |
|
101 | - |
|
102 | - $lowercased_word = strtolower($word); |
|
103 | - |
|
104 | - foreach ($uncountable as $_uncountable) { |
|
105 | - if ( |
|
106 | - substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | - ) { |
|
109 | - return $word; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - foreach ($irregular as $_plural => $_singular) { |
|
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - foreach ($plural as $rule => $replacement) { |
|
120 | - if (preg_match($rule, $word)) { |
|
121 | - return preg_replace($rule, $replacement, $word); |
|
122 | - } |
|
123 | - } |
|
124 | - return false; |
|
125 | - } |
|
126 | - |
|
127 | - // }}} |
|
128 | - // {{{ singularize() |
|
129 | - |
|
130 | - /** |
|
131 | - * Singularizes English nouns. |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @static |
|
135 | - * @param string $word English noun to singularize |
|
136 | - * @return string Singular noun. |
|
137 | - */ |
|
138 | - public static function singularize($word) |
|
139 | - { |
|
140 | - $singular = array( |
|
141 | - '/(quiz)zes$/i' => '\1', |
|
142 | - '/(matr)ices$/i' => '\1ix', |
|
143 | - '/(vert|ind)ices$/i' => '\1ex', |
|
144 | - '/^(ox)en/i' => '\1', |
|
145 | - '/(alias|status)es$/i' => '\1', |
|
146 | - '/([octop|vir])i$/i' => '\1us', |
|
147 | - '/(cris|ax|test)es$/i' => '\1is', |
|
148 | - '/(shoe)s$/i' => '\1', |
|
149 | - '/(o)es$/i' => '\1', |
|
150 | - '/(bus)es$/i' => '\1', |
|
151 | - '/([m|l])ice$/i' => '\1ouse', |
|
152 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | - '/(m)ovies$/i' => '\1ovie', |
|
154 | - '/(s)eries$/i' => '\1eries', |
|
155 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | - '/([lr])ves$/i' => '\1f', |
|
157 | - '/(tive)s$/i' => '\1', |
|
158 | - '/(hive)s$/i' => '\1', |
|
159 | - '/([^f])ves$/i' => '\1fe', |
|
160 | - '/(^analy)ses$/i' => '\1sis', |
|
161 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | - '/([ti])a$/i' => '\1um', |
|
163 | - '/(n)ews$/i' => '\1ews', |
|
164 | - '/s$/i' => '', |
|
165 | - ); |
|
166 | - |
|
167 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | - |
|
169 | - $irregular = array( |
|
170 | - 'person' => 'people', |
|
171 | - 'man' => 'men', |
|
172 | - 'child' => 'children', |
|
173 | - 'sex' => 'sexes', |
|
174 | - 'move' => 'moves'); |
|
175 | - |
|
176 | - $lowercased_word = strtolower($word); |
|
177 | - foreach ($uncountable as $_uncountable) { |
|
178 | - if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | - return $word; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - foreach ($irregular as $_plural => $_singular) { |
|
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - foreach ($singular as $rule => $replacement) { |
|
190 | - if (preg_match($rule, $word)) { |
|
191 | - return preg_replace($rule, $replacement, $word); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - return $word; |
|
196 | - } |
|
197 | - |
|
198 | - // }}} |
|
199 | - // {{{ titleize() |
|
200 | - |
|
201 | - /** |
|
202 | - * Converts an underscored or CamelCase word into a English |
|
203 | - * sentence. |
|
204 | - * |
|
205 | - * The titleize static function converts text like "WelcomePage", |
|
206 | - * "welcome_page" or "welcome page" to this "Welcome |
|
207 | - * Page". |
|
208 | - * If second parameter is set to 'first' it will only |
|
209 | - * capitalize the first character of the title. |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @static |
|
213 | - * @param string $word Word to format as tile |
|
214 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | - * first character. Otherwise it will uppercase all |
|
216 | - * the words in the title. |
|
217 | - * @return string Text formatted as title |
|
218 | - */ |
|
219 | - public static function titleize($word, $uppercase = '') |
|
220 | - { |
|
221 | - $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | - } |
|
224 | - |
|
225 | - // }}} |
|
226 | - // {{{ camelize() |
|
227 | - |
|
228 | - /** |
|
229 | - * Returns given word as CamelCased |
|
230 | - * |
|
231 | - * Converts a word like "send_email" to "SendEmail". It |
|
232 | - * will remove non alphanumeric character from the word, so |
|
233 | - * "who's online" will be converted to "WhoSOnline" |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @static |
|
237 | - * @see variablize |
|
238 | - * @param string $word Word to convert to camel case |
|
239 | - * @return string UpperCamelCasedWord |
|
240 | - */ |
|
241 | - public static function camelize($word) |
|
242 | - { |
|
243 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | - * with the new PSR-based naming conventions |
|
251 | - * @param $word |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public static function camelize_all_but_first($word) |
|
255 | - { |
|
256 | - return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | - } |
|
258 | - // }}} |
|
259 | - // {{{ underscore() |
|
260 | - |
|
261 | - /** |
|
262 | - * Converts a word "into_it_s_underscored_version" |
|
263 | - * |
|
264 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | - * "underscored_word". |
|
266 | - * |
|
267 | - * This can be really useful for creating friendly URLs. |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @static |
|
271 | - * @param string $word Word to underscore |
|
272 | - * @return string Underscored word |
|
273 | - */ |
|
274 | - public static function underscore($word) |
|
275 | - { |
|
276 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | - } |
|
278 | - |
|
279 | - // }}} |
|
280 | - // {{{ humanize() |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns a human-readable string from $word |
|
284 | - * |
|
285 | - * Returns a human-readable string from $word, by replacing |
|
286 | - * underscores with a space, and by upper-casing the initial |
|
287 | - * character by default. |
|
288 | - * |
|
289 | - * If you need to uppercase all the words you just have to |
|
290 | - * pass 'all' as a second parameter. |
|
291 | - * |
|
292 | - * @access public |
|
293 | - * @static |
|
294 | - * @param string $word String to "humanize" |
|
295 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | - * instead of just the first one. |
|
297 | - * @return string Human-readable word |
|
298 | - */ |
|
299 | - public static function humanize($word, $uppercase = '') |
|
300 | - { |
|
301 | - // make special exceptions for acronyms |
|
302 | - $word = str_replace('wp_', 'WP_', $word); |
|
303 | - $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | - } |
|
306 | - |
|
307 | - // }}} |
|
308 | - // {{{ variablize() |
|
309 | - |
|
310 | - /** |
|
311 | - * Same as camelize but first char is underscored |
|
312 | - * |
|
313 | - * Converts a word like "send_email" to "sendEmail". It |
|
314 | - * will remove non alphanumeric character from the word, so |
|
315 | - * "who's online" will be converted to "whoSOnline" |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @see camelize |
|
320 | - * @param string $word Word to lowerCamelCase |
|
321 | - * @return string Returns a lowerCamelCasedWord |
|
322 | - */ |
|
323 | - public static function variablize($word) |
|
324 | - { |
|
325 | - $word = EEH_Inflector::camelize($word); |
|
326 | - return strtolower($word[0]) . substr($word, 1); |
|
327 | - } |
|
328 | - |
|
329 | - // }}} |
|
330 | - // {{{ tableize() |
|
331 | - |
|
332 | - /** |
|
333 | - * Converts a class name to its table name according to rails |
|
334 | - * naming conventions. |
|
335 | - * |
|
336 | - * Converts "Person" to "people" |
|
337 | - * |
|
338 | - * @access public |
|
339 | - * @static |
|
340 | - * @see classify |
|
341 | - * @param string $class_name Class name for getting related table_name. |
|
342 | - * @return string plural_table_name |
|
343 | - */ |
|
344 | - public static function tableize($class_name) |
|
345 | - { |
|
346 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | - } |
|
348 | - |
|
349 | - // }}} |
|
350 | - // {{{ classify() |
|
351 | - |
|
352 | - /** |
|
353 | - * Converts a table name to its class name according to rails |
|
354 | - * naming conventions. |
|
355 | - * |
|
356 | - * Converts "people" to "Person" |
|
357 | - * |
|
358 | - * @access public |
|
359 | - * @static |
|
360 | - * @see tableize |
|
361 | - * @param string $table_name Table name for getting related ClassName. |
|
362 | - * @return string SingularClassName |
|
363 | - */ |
|
364 | - public static function classify($table_name) |
|
365 | - { |
|
366 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | - } |
|
368 | - |
|
369 | - // }}} |
|
370 | - // {{{ ordinalize() |
|
371 | - |
|
372 | - /** |
|
373 | - * Converts number to its ordinal English form. |
|
374 | - * |
|
375 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @static |
|
379 | - * @param integer $number Number to get its ordinal value |
|
380 | - * @return string Ordinal representation of given string. |
|
381 | - */ |
|
382 | - public static function ordinalize($number) |
|
383 | - { |
|
384 | - if (in_array(($number % 100), range(11, 13))) { |
|
385 | - return $number . 'th'; |
|
386 | - } else { |
|
387 | - switch (($number % 10)) { |
|
388 | - case 1: |
|
389 | - return $number . 'st'; |
|
390 | - break; |
|
391 | - case 2: |
|
392 | - return $number . 'nd'; |
|
393 | - break; |
|
394 | - case 3: |
|
395 | - return $number . 'rd'; |
|
396 | - default: |
|
397 | - return $number . 'th'; |
|
398 | - break; |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param $string |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public static function add_indefinite_article($string) |
|
410 | - { |
|
411 | - if (strtolower($string) === 'null') { |
|
412 | - return $string; |
|
413 | - } |
|
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | - } |
|
36 | + // ------ CLASS METHODS ------ // |
|
37 | + // ---- Public methods ---- // |
|
38 | + // {{{ pluralize() |
|
39 | + |
|
40 | + /** |
|
41 | + * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | + * @param string $word |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function pluralize_and_lower($word) |
|
46 | + { |
|
47 | + return strtolower(self::pluralize($word)); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param string $word |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public static function singularize_and_upper($word) |
|
57 | + { |
|
58 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Pluralizes English nouns. |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @static |
|
68 | + * @param string $word English noun to pluralize |
|
69 | + * @return string Plural noun |
|
70 | + */ |
|
71 | + public static function pluralize($word) |
|
72 | + { |
|
73 | + $plural = array( |
|
74 | + '/(quiz)$/i' => '\1zes', |
|
75 | + '/^(ox)$/i' => '\1en', |
|
76 | + '/([m|l])ouse$/i' => '\1ice', |
|
77 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | + '/(hive)$/i' => '\1s', |
|
82 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | + '/sis$/i' => 'ses', |
|
84 | + '/([ti])um$/i' => '\1a', |
|
85 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | + '/(bu)s$/i' => '\1ses', |
|
87 | + '/(alias|status)/i' => '\1es', |
|
88 | + '/(octop|vir)us$/i' => '\1i', |
|
89 | + '/(ax|test)is$/i' => '\1es', |
|
90 | + '/s$/i' => 's', |
|
91 | + '/$/' => 's'); |
|
92 | + |
|
93 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | + |
|
95 | + $irregular = array( |
|
96 | + 'person' => 'people', |
|
97 | + 'man' => 'men', |
|
98 | + 'child' => 'children', |
|
99 | + 'sex' => 'sexes', |
|
100 | + 'move' => 'moves'); |
|
101 | + |
|
102 | + $lowercased_word = strtolower($word); |
|
103 | + |
|
104 | + foreach ($uncountable as $_uncountable) { |
|
105 | + if ( |
|
106 | + substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | + ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | + ) { |
|
109 | + return $word; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + foreach ($irregular as $_plural => $_singular) { |
|
114 | + if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + foreach ($plural as $rule => $replacement) { |
|
120 | + if (preg_match($rule, $word)) { |
|
121 | + return preg_replace($rule, $replacement, $word); |
|
122 | + } |
|
123 | + } |
|
124 | + return false; |
|
125 | + } |
|
126 | + |
|
127 | + // }}} |
|
128 | + // {{{ singularize() |
|
129 | + |
|
130 | + /** |
|
131 | + * Singularizes English nouns. |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @static |
|
135 | + * @param string $word English noun to singularize |
|
136 | + * @return string Singular noun. |
|
137 | + */ |
|
138 | + public static function singularize($word) |
|
139 | + { |
|
140 | + $singular = array( |
|
141 | + '/(quiz)zes$/i' => '\1', |
|
142 | + '/(matr)ices$/i' => '\1ix', |
|
143 | + '/(vert|ind)ices$/i' => '\1ex', |
|
144 | + '/^(ox)en/i' => '\1', |
|
145 | + '/(alias|status)es$/i' => '\1', |
|
146 | + '/([octop|vir])i$/i' => '\1us', |
|
147 | + '/(cris|ax|test)es$/i' => '\1is', |
|
148 | + '/(shoe)s$/i' => '\1', |
|
149 | + '/(o)es$/i' => '\1', |
|
150 | + '/(bus)es$/i' => '\1', |
|
151 | + '/([m|l])ice$/i' => '\1ouse', |
|
152 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | + '/(m)ovies$/i' => '\1ovie', |
|
154 | + '/(s)eries$/i' => '\1eries', |
|
155 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | + '/([lr])ves$/i' => '\1f', |
|
157 | + '/(tive)s$/i' => '\1', |
|
158 | + '/(hive)s$/i' => '\1', |
|
159 | + '/([^f])ves$/i' => '\1fe', |
|
160 | + '/(^analy)ses$/i' => '\1sis', |
|
161 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | + '/([ti])a$/i' => '\1um', |
|
163 | + '/(n)ews$/i' => '\1ews', |
|
164 | + '/s$/i' => '', |
|
165 | + ); |
|
166 | + |
|
167 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | + |
|
169 | + $irregular = array( |
|
170 | + 'person' => 'people', |
|
171 | + 'man' => 'men', |
|
172 | + 'child' => 'children', |
|
173 | + 'sex' => 'sexes', |
|
174 | + 'move' => 'moves'); |
|
175 | + |
|
176 | + $lowercased_word = strtolower($word); |
|
177 | + foreach ($uncountable as $_uncountable) { |
|
178 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | + return $word; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + foreach ($irregular as $_plural => $_singular) { |
|
184 | + if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + foreach ($singular as $rule => $replacement) { |
|
190 | + if (preg_match($rule, $word)) { |
|
191 | + return preg_replace($rule, $replacement, $word); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + return $word; |
|
196 | + } |
|
197 | + |
|
198 | + // }}} |
|
199 | + // {{{ titleize() |
|
200 | + |
|
201 | + /** |
|
202 | + * Converts an underscored or CamelCase word into a English |
|
203 | + * sentence. |
|
204 | + * |
|
205 | + * The titleize static function converts text like "WelcomePage", |
|
206 | + * "welcome_page" or "welcome page" to this "Welcome |
|
207 | + * Page". |
|
208 | + * If second parameter is set to 'first' it will only |
|
209 | + * capitalize the first character of the title. |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @static |
|
213 | + * @param string $word Word to format as tile |
|
214 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | + * first character. Otherwise it will uppercase all |
|
216 | + * the words in the title. |
|
217 | + * @return string Text formatted as title |
|
218 | + */ |
|
219 | + public static function titleize($word, $uppercase = '') |
|
220 | + { |
|
221 | + $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | + } |
|
224 | + |
|
225 | + // }}} |
|
226 | + // {{{ camelize() |
|
227 | + |
|
228 | + /** |
|
229 | + * Returns given word as CamelCased |
|
230 | + * |
|
231 | + * Converts a word like "send_email" to "SendEmail". It |
|
232 | + * will remove non alphanumeric character from the word, so |
|
233 | + * "who's online" will be converted to "WhoSOnline" |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @static |
|
237 | + * @see variablize |
|
238 | + * @param string $word Word to convert to camel case |
|
239 | + * @return string UpperCamelCasedWord |
|
240 | + */ |
|
241 | + public static function camelize($word) |
|
242 | + { |
|
243 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | + * with the new PSR-based naming conventions |
|
251 | + * @param $word |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public static function camelize_all_but_first($word) |
|
255 | + { |
|
256 | + return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | + } |
|
258 | + // }}} |
|
259 | + // {{{ underscore() |
|
260 | + |
|
261 | + /** |
|
262 | + * Converts a word "into_it_s_underscored_version" |
|
263 | + * |
|
264 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | + * "underscored_word". |
|
266 | + * |
|
267 | + * This can be really useful for creating friendly URLs. |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @static |
|
271 | + * @param string $word Word to underscore |
|
272 | + * @return string Underscored word |
|
273 | + */ |
|
274 | + public static function underscore($word) |
|
275 | + { |
|
276 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | + } |
|
278 | + |
|
279 | + // }}} |
|
280 | + // {{{ humanize() |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns a human-readable string from $word |
|
284 | + * |
|
285 | + * Returns a human-readable string from $word, by replacing |
|
286 | + * underscores with a space, and by upper-casing the initial |
|
287 | + * character by default. |
|
288 | + * |
|
289 | + * If you need to uppercase all the words you just have to |
|
290 | + * pass 'all' as a second parameter. |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @static |
|
294 | + * @param string $word String to "humanize" |
|
295 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | + * instead of just the first one. |
|
297 | + * @return string Human-readable word |
|
298 | + */ |
|
299 | + public static function humanize($word, $uppercase = '') |
|
300 | + { |
|
301 | + // make special exceptions for acronyms |
|
302 | + $word = str_replace('wp_', 'WP_', $word); |
|
303 | + $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | + } |
|
306 | + |
|
307 | + // }}} |
|
308 | + // {{{ variablize() |
|
309 | + |
|
310 | + /** |
|
311 | + * Same as camelize but first char is underscored |
|
312 | + * |
|
313 | + * Converts a word like "send_email" to "sendEmail". It |
|
314 | + * will remove non alphanumeric character from the word, so |
|
315 | + * "who's online" will be converted to "whoSOnline" |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @see camelize |
|
320 | + * @param string $word Word to lowerCamelCase |
|
321 | + * @return string Returns a lowerCamelCasedWord |
|
322 | + */ |
|
323 | + public static function variablize($word) |
|
324 | + { |
|
325 | + $word = EEH_Inflector::camelize($word); |
|
326 | + return strtolower($word[0]) . substr($word, 1); |
|
327 | + } |
|
328 | + |
|
329 | + // }}} |
|
330 | + // {{{ tableize() |
|
331 | + |
|
332 | + /** |
|
333 | + * Converts a class name to its table name according to rails |
|
334 | + * naming conventions. |
|
335 | + * |
|
336 | + * Converts "Person" to "people" |
|
337 | + * |
|
338 | + * @access public |
|
339 | + * @static |
|
340 | + * @see classify |
|
341 | + * @param string $class_name Class name for getting related table_name. |
|
342 | + * @return string plural_table_name |
|
343 | + */ |
|
344 | + public static function tableize($class_name) |
|
345 | + { |
|
346 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | + } |
|
348 | + |
|
349 | + // }}} |
|
350 | + // {{{ classify() |
|
351 | + |
|
352 | + /** |
|
353 | + * Converts a table name to its class name according to rails |
|
354 | + * naming conventions. |
|
355 | + * |
|
356 | + * Converts "people" to "Person" |
|
357 | + * |
|
358 | + * @access public |
|
359 | + * @static |
|
360 | + * @see tableize |
|
361 | + * @param string $table_name Table name for getting related ClassName. |
|
362 | + * @return string SingularClassName |
|
363 | + */ |
|
364 | + public static function classify($table_name) |
|
365 | + { |
|
366 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | + } |
|
368 | + |
|
369 | + // }}} |
|
370 | + // {{{ ordinalize() |
|
371 | + |
|
372 | + /** |
|
373 | + * Converts number to its ordinal English form. |
|
374 | + * |
|
375 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @static |
|
379 | + * @param integer $number Number to get its ordinal value |
|
380 | + * @return string Ordinal representation of given string. |
|
381 | + */ |
|
382 | + public static function ordinalize($number) |
|
383 | + { |
|
384 | + if (in_array(($number % 100), range(11, 13))) { |
|
385 | + return $number . 'th'; |
|
386 | + } else { |
|
387 | + switch (($number % 10)) { |
|
388 | + case 1: |
|
389 | + return $number . 'st'; |
|
390 | + break; |
|
391 | + case 2: |
|
392 | + return $number . 'nd'; |
|
393 | + break; |
|
394 | + case 3: |
|
395 | + return $number . 'rd'; |
|
396 | + default: |
|
397 | + return $number . 'th'; |
|
398 | + break; |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param $string |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public static function add_indefinite_article($string) |
|
410 | + { |
|
411 | + if (strtolower($string) === 'null') { |
|
412 | + return $string; |
|
413 | + } |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | + } |
|
416 | 416 | } |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | foreach ($uncountable as $_uncountable) { |
105 | 105 | if ( |
106 | 106 | substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
107 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)]) |
|
108 | 108 | ) { |
109 | 109 | return $word; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | 113 | foreach ($irregular as $_plural => $_singular) { |
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
114 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | foreach ($irregular as $_plural => $_singular) { |
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
184 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | public static function variablize($word) |
324 | 324 | { |
325 | 325 | $word = EEH_Inflector::camelize($word); |
326 | - return strtolower($word[0]) . substr($word, 1); |
|
326 | + return strtolower($word[0]).substr($word, 1); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // }}} |
@@ -382,19 +382,19 @@ discard block |
||
382 | 382 | public static function ordinalize($number) |
383 | 383 | { |
384 | 384 | if (in_array(($number % 100), range(11, 13))) { |
385 | - return $number . 'th'; |
|
385 | + return $number.'th'; |
|
386 | 386 | } else { |
387 | 387 | switch (($number % 10)) { |
388 | 388 | case 1: |
389 | - return $number . 'st'; |
|
389 | + return $number.'st'; |
|
390 | 390 | break; |
391 | 391 | case 2: |
392 | - return $number . 'nd'; |
|
392 | + return $number.'nd'; |
|
393 | 393 | break; |
394 | 394 | case 3: |
395 | - return $number . 'rd'; |
|
395 | + return $number.'rd'; |
|
396 | 396 | default: |
397 | - return $number . 'th'; |
|
397 | + return $number.'th'; |
|
398 | 398 | break; |
399 | 399 | } |
400 | 400 | } |
@@ -411,6 +411,6 @@ discard block |
||
411 | 411 | if (strtolower($string) === 'null') { |
412 | 412 | return $string; |
413 | 413 | } |
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string; |
|
415 | 415 | } |
416 | 416 | } |
@@ -13,268 +13,268 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * holds the template |
|
18 | - * |
|
19 | - * @access private |
|
20 | - * @var mixed (string|array) |
|
21 | - */ |
|
22 | - private $_template; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * holds the incoming data object |
|
27 | - * |
|
28 | - * @access private |
|
29 | - * @var object |
|
30 | - */ |
|
31 | - private $_data; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * will hold an array of EE_Shortcodes library objects. |
|
36 | - * |
|
37 | - * @access private |
|
38 | - * @var EE_Shortcodes[] |
|
39 | - */ |
|
40 | - private $_shortcode_objs = array(); |
|
41 | - |
|
42 | - |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This kicks off the parsing of shortcodes in message templates |
|
50 | - * |
|
51 | - * @param string $template This is the incoming string to be parsed |
|
52 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
53 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
54 | - * @param EE_message_type $message_type The message type that called the parser |
|
55 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
56 | - * @param EE_Message $message |
|
57 | - * @return string The parsed template string |
|
58 | - */ |
|
59 | - public function parse_message_template( |
|
60 | - $template, |
|
61 | - EE_Messages_Addressee $data, |
|
62 | - $valid_shortcodes, |
|
63 | - EE_message_type $message_type, |
|
64 | - EE_messenger $messenger, |
|
65 | - EE_Message $message |
|
66 | - ) { |
|
67 | - $extra_data = array( |
|
68 | - 'messenger' => $messenger, |
|
69 | - 'message_type' => $message_type, |
|
70 | - 'message' => $message, |
|
71 | - ); |
|
72 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
73 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
74 | - return $this->_parse_message_template(); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - public function parse_attendee_list_template( |
|
79 | - $template, |
|
80 | - EE_Registration $registration, |
|
81 | - $valid_shortcodes, |
|
82 | - $extra_data = array() |
|
83 | - ) { |
|
84 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
85 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
86 | - return $this->_parse_message_template(); |
|
87 | - } |
|
88 | - |
|
89 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
90 | - { |
|
91 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
92 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
93 | - return $this->_parse_message_template(); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
98 | - { |
|
99 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
100 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
101 | - return $this->_parse_message_template(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - public function parse_line_item_list_template( |
|
106 | - $template, |
|
107 | - EE_Line_Item $line_item, |
|
108 | - $valid_shortcodes, |
|
109 | - $extra_data = array() |
|
110 | - ) { |
|
111 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
112 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
113 | - return $this->_parse_message_template(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - public function parse_payment_list_template( |
|
118 | - $template, |
|
119 | - EE_Payment $payment_item, |
|
120 | - $valid_shortcodes, |
|
121 | - $extra_data = array() |
|
122 | - ) { |
|
123 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
124 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
125 | - return $this->_parse_message_template(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - public function parse_datetime_list_template( |
|
130 | - $template, |
|
131 | - EE_Datetime $datetime, |
|
132 | - $valid_shortcodes, |
|
133 | - $extra_data = array() |
|
134 | - ) { |
|
135 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
136 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
137 | - return $this->_parse_message_template(); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
142 | - { |
|
143 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
144 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
145 | - return $this->_parse_message_template(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
150 | - { |
|
151 | - $this->_reset_props(); |
|
152 | - $this->_data['template'] = $template; |
|
153 | - $this->_data['data'] = $data; |
|
154 | - $this->_data['extra_data'] = $extra_data; |
|
155 | - $this->_set_shortcodes($valid_shortcodes); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - private function _reset_props() |
|
160 | - { |
|
161 | - $this->_template = $this->_data = null; |
|
162 | - $this->_shortcode_objs = array(); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * takes the given template and parses it with the $_shortcodes property |
|
168 | - * |
|
169 | - * @access private |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - private function _parse_message_template() |
|
173 | - { |
|
174 | - // now let's get a list of shortcodes that are found in the given template |
|
175 | - preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
176 | - $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
177 | - |
|
178 | - $matched_code = array(); |
|
179 | - $sc_values = array(); |
|
180 | - |
|
181 | - $list_type_shortcodes = array( |
|
182 | - '[ATTENDEE_LIST]', |
|
183 | - '[EVENT_LIST]', |
|
184 | - '[TICKET_LIST]', |
|
185 | - '[DATETIME_LIST]', |
|
186 | - '[QUESTION_LIST]', |
|
187 | - '[RECIPIENT_QUESTION_LIST]', |
|
188 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
189 | - '[RECIPIENT_TICKET_LIST]', |
|
190 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
191 | - '[RECIPIENT_DATETIME_LIST]', |
|
192 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
193 | - '[TICKET_LINE_ITEM_LIST]', |
|
194 | - '[TAX_LINE_ITEM_LIST]', |
|
195 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
196 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
197 | - '[PAYMENT_LIST_*]', |
|
198 | - ); |
|
199 | - |
|
200 | - $list_type_shortcodes = apply_filters( |
|
201 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
202 | - $list_type_shortcodes |
|
203 | - ); |
|
204 | - |
|
205 | - // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
206 | - foreach ($shortcodes as $shortcode) { |
|
207 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
208 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
209 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
210 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
211 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
212 | - |
|
213 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | - continue; // the given shortcode isn't in this object |
|
215 | - } |
|
216 | - |
|
217 | - // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
218 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
220 | - } else { |
|
221 | - $data_send = $this->_data; |
|
222 | - } |
|
223 | - |
|
224 | - // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
225 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
226 | - // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
227 | - // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
228 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
229 | - if ($parsed) { |
|
230 | - $this->_template = $parsed; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
235 | - |
|
236 | - $matched_code[] = $shortcode; |
|
237 | - $sc_values[] = $parsed; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
243 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
244 | - return $parsed; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
250 | - * |
|
251 | - * Does it match this format: `[IF_` |
|
252 | - * |
|
253 | - * @param $shortcode |
|
254 | - */ |
|
255 | - protected function _is_conditional_shortcode($shortcode) |
|
256 | - { |
|
257 | - return strpos($shortcode, '[IF_') === 0; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
263 | - * various EE_Shortcode library objects |
|
264 | - * |
|
265 | - * @access private |
|
266 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
267 | - * @return void |
|
268 | - */ |
|
269 | - private function _set_shortcodes($valid_shortcodes) |
|
270 | - { |
|
271 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
272 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
273 | - $ref = str_replace(' ', '_', $ref); |
|
274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
275 | - if (class_exists($classname)) { |
|
276 | - $this->_shortcode_objs[] = new $classname(); |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
16 | + /** |
|
17 | + * holds the template |
|
18 | + * |
|
19 | + * @access private |
|
20 | + * @var mixed (string|array) |
|
21 | + */ |
|
22 | + private $_template; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * holds the incoming data object |
|
27 | + * |
|
28 | + * @access private |
|
29 | + * @var object |
|
30 | + */ |
|
31 | + private $_data; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * will hold an array of EE_Shortcodes library objects. |
|
36 | + * |
|
37 | + * @access private |
|
38 | + * @var EE_Shortcodes[] |
|
39 | + */ |
|
40 | + private $_shortcode_objs = array(); |
|
41 | + |
|
42 | + |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This kicks off the parsing of shortcodes in message templates |
|
50 | + * |
|
51 | + * @param string $template This is the incoming string to be parsed |
|
52 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
53 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
54 | + * @param EE_message_type $message_type The message type that called the parser |
|
55 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
56 | + * @param EE_Message $message |
|
57 | + * @return string The parsed template string |
|
58 | + */ |
|
59 | + public function parse_message_template( |
|
60 | + $template, |
|
61 | + EE_Messages_Addressee $data, |
|
62 | + $valid_shortcodes, |
|
63 | + EE_message_type $message_type, |
|
64 | + EE_messenger $messenger, |
|
65 | + EE_Message $message |
|
66 | + ) { |
|
67 | + $extra_data = array( |
|
68 | + 'messenger' => $messenger, |
|
69 | + 'message_type' => $message_type, |
|
70 | + 'message' => $message, |
|
71 | + ); |
|
72 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
73 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
74 | + return $this->_parse_message_template(); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + public function parse_attendee_list_template( |
|
79 | + $template, |
|
80 | + EE_Registration $registration, |
|
81 | + $valid_shortcodes, |
|
82 | + $extra_data = array() |
|
83 | + ) { |
|
84 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
85 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
86 | + return $this->_parse_message_template(); |
|
87 | + } |
|
88 | + |
|
89 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
90 | + { |
|
91 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
92 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
93 | + return $this->_parse_message_template(); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
98 | + { |
|
99 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
100 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
101 | + return $this->_parse_message_template(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + public function parse_line_item_list_template( |
|
106 | + $template, |
|
107 | + EE_Line_Item $line_item, |
|
108 | + $valid_shortcodes, |
|
109 | + $extra_data = array() |
|
110 | + ) { |
|
111 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
112 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
113 | + return $this->_parse_message_template(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + public function parse_payment_list_template( |
|
118 | + $template, |
|
119 | + EE_Payment $payment_item, |
|
120 | + $valid_shortcodes, |
|
121 | + $extra_data = array() |
|
122 | + ) { |
|
123 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
124 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
125 | + return $this->_parse_message_template(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + public function parse_datetime_list_template( |
|
130 | + $template, |
|
131 | + EE_Datetime $datetime, |
|
132 | + $valid_shortcodes, |
|
133 | + $extra_data = array() |
|
134 | + ) { |
|
135 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
136 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
137 | + return $this->_parse_message_template(); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
142 | + { |
|
143 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
144 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
145 | + return $this->_parse_message_template(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
150 | + { |
|
151 | + $this->_reset_props(); |
|
152 | + $this->_data['template'] = $template; |
|
153 | + $this->_data['data'] = $data; |
|
154 | + $this->_data['extra_data'] = $extra_data; |
|
155 | + $this->_set_shortcodes($valid_shortcodes); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + private function _reset_props() |
|
160 | + { |
|
161 | + $this->_template = $this->_data = null; |
|
162 | + $this->_shortcode_objs = array(); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * takes the given template and parses it with the $_shortcodes property |
|
168 | + * |
|
169 | + * @access private |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + private function _parse_message_template() |
|
173 | + { |
|
174 | + // now let's get a list of shortcodes that are found in the given template |
|
175 | + preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
176 | + $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
177 | + |
|
178 | + $matched_code = array(); |
|
179 | + $sc_values = array(); |
|
180 | + |
|
181 | + $list_type_shortcodes = array( |
|
182 | + '[ATTENDEE_LIST]', |
|
183 | + '[EVENT_LIST]', |
|
184 | + '[TICKET_LIST]', |
|
185 | + '[DATETIME_LIST]', |
|
186 | + '[QUESTION_LIST]', |
|
187 | + '[RECIPIENT_QUESTION_LIST]', |
|
188 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
189 | + '[RECIPIENT_TICKET_LIST]', |
|
190 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
191 | + '[RECIPIENT_DATETIME_LIST]', |
|
192 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
193 | + '[TICKET_LINE_ITEM_LIST]', |
|
194 | + '[TAX_LINE_ITEM_LIST]', |
|
195 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
196 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
197 | + '[PAYMENT_LIST_*]', |
|
198 | + ); |
|
199 | + |
|
200 | + $list_type_shortcodes = apply_filters( |
|
201 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
202 | + $list_type_shortcodes |
|
203 | + ); |
|
204 | + |
|
205 | + // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
206 | + foreach ($shortcodes as $shortcode) { |
|
207 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
208 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
209 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
210 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
211 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
212 | + |
|
213 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | + continue; // the given shortcode isn't in this object |
|
215 | + } |
|
216 | + |
|
217 | + // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
218 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
220 | + } else { |
|
221 | + $data_send = $this->_data; |
|
222 | + } |
|
223 | + |
|
224 | + // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
225 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
226 | + // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
227 | + // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
228 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
229 | + if ($parsed) { |
|
230 | + $this->_template = $parsed; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
235 | + |
|
236 | + $matched_code[] = $shortcode; |
|
237 | + $sc_values[] = $parsed; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
243 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
244 | + return $parsed; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
250 | + * |
|
251 | + * Does it match this format: `[IF_` |
|
252 | + * |
|
253 | + * @param $shortcode |
|
254 | + */ |
|
255 | + protected function _is_conditional_shortcode($shortcode) |
|
256 | + { |
|
257 | + return strpos($shortcode, '[IF_') === 0; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
263 | + * various EE_Shortcode library objects |
|
264 | + * |
|
265 | + * @access private |
|
266 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
267 | + * @return void |
|
268 | + */ |
|
269 | + private function _set_shortcodes($valid_shortcodes) |
|
270 | + { |
|
271 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
272 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
273 | + $ref = str_replace(' ', '_', $ref); |
|
274 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
275 | + if (class_exists($classname)) { |
|
276 | + $this->_shortcode_objs[] = new $classname(); |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | 280 | } |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | if ($sc_obj instanceof EE_Shortcodes) { |
209 | 209 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
210 | 210 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
211 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
211 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
212 | 212 | |
213 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
213 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | 214 | continue; // the given shortcode isn't in this object |
215 | 215 | } |
216 | 216 | |
217 | 217 | // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
218 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
218 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | 219 | $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
220 | 220 | } else { |
221 | 221 | $data_send = $this->_data; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | foreach ($valid_shortcodes as $shortcode_ref) { |
272 | 272 | $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
273 | 273 | $ref = str_replace(' ', '_', $ref); |
274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
274 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
275 | 275 | if (class_exists($classname)) { |
276 | 276 | $this->_shortcode_objs[] = new $classname(); |
277 | 277 | } |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | ) { |
75 | 75 | // its associative, so we want to output its keys as column headers |
76 | 76 | $keys = array_keys($item_in_top_level_array); |
77 | - $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
77 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
78 | 78 | } |
79 | 79 | // start writing data |
80 | 80 | foreach ($data as $data_row) { |
81 | 81 | $new_file_contents .= EEH_Export::get_csv_row($data_row); |
82 | 82 | } |
83 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
83 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents); |
|
84 | 84 | } else { |
85 | 85 | // no data TO write... so we can assume that's a success |
86 | 86 | return true; |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
121 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
121 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value; |
|
122 | 122 | } |
123 | 123 | |
124 | - return implode($delimiter, $output) . PHP_EOL; |
|
124 | + return implode($delimiter, $output).PHP_EOL; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 |
@@ -13,165 +13,165 @@ |
||
13 | 13 | */ |
14 | 14 | class EEH_Export |
15 | 15 | { |
16 | - /** |
|
17 | - * Gets the 'normal' column named for fields |
|
18 | - * @param EE_Model_Field_Base $field |
|
19 | - * @return string |
|
20 | - * @throws EE_Error |
|
21 | - */ |
|
22 | - public static function get_column_name_for_field(EE_Model_Field_Base $field) |
|
23 | - { |
|
24 | - $column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES); |
|
25 | - if ( |
|
26 | - apply_filters( |
|
27 | - 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
28 | - false, |
|
29 | - $column_name, |
|
30 | - $field |
|
31 | - ) |
|
32 | - ) { |
|
33 | - $column_name .= "[" |
|
34 | - . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
35 | - . "]"; |
|
36 | - } |
|
37 | - return $column_name; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
42 | - * |
|
43 | - * @param string $filepath |
|
44 | - * @param array $data 2D array, first numerically-indexed, |
|
45 | - * and next-level-down preferably indexed by string |
|
46 | - * @param boolean $write_column_headers whether or not we should add the keys in the bottom-most array |
|
47 | - * as a row for headers in the CSV. |
|
48 | - * Eg, if $data looked like: |
|
49 | - * array( |
|
50 | - * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
51 | - * 1=>array(...,...) |
|
52 | - * ) |
|
53 | - * |
|
54 | - * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
55 | - * we consider that a success (because we wrote everything there was...nothing) |
|
56 | - * @throws EE_Error |
|
57 | - */ |
|
58 | - public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) |
|
59 | - { |
|
60 | - |
|
61 | - $new_file_contents = ''; |
|
62 | - // determine if $data is actually a 2d array |
|
63 | - if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
64 | - // make sure top level is numerically indexed, |
|
65 | - |
|
66 | - if (EEH_Array::is_associative_array($data)) { |
|
67 | - throw new EE_Error(sprintf(esc_html__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
68 | - } |
|
69 | - $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
70 | - // now, is the last item in the top-level array of $data an associative or numeric array? |
|
71 | - if ( |
|
72 | - $write_column_headers && |
|
73 | - EEH_Array::is_associative_array($item_in_top_level_array) |
|
74 | - ) { |
|
75 | - // its associative, so we want to output its keys as column headers |
|
76 | - $keys = array_keys($item_in_top_level_array); |
|
77 | - $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
78 | - } |
|
79 | - // start writing data |
|
80 | - foreach ($data as $data_row) { |
|
81 | - $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
82 | - } |
|
83 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
84 | - } else { |
|
85 | - // no data TO write... so we can assume that's a success |
|
86 | - return true; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * |
|
94 | - * Writes a row to the csv file |
|
95 | - * @param array $row - individual row of csv data |
|
96 | - * @param string $delimiter - csv delimiter |
|
97 | - * @param string $enclosure - csv enclosure |
|
98 | - * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
99 | - * @return string of text for teh csv file |
|
100 | - */ |
|
101 | - public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
102 | - { |
|
103 | - // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
104 | - $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
105 | - $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
106 | - |
|
107 | - $delimiter_esc = preg_quote($delimiter, '/'); |
|
108 | - $enclosure_esc = preg_quote($enclosure, '/'); |
|
109 | - |
|
110 | - $output = array(); |
|
111 | - foreach ($row as $field_value) { |
|
112 | - if (is_object($field_value) || is_array($field_value)) { |
|
113 | - $field_value = serialize($field_value); |
|
114 | - } |
|
115 | - if ($field_value === null && $mysql_null) { |
|
116 | - $output[] = 'NULL'; |
|
117 | - continue; |
|
118 | - } |
|
119 | - |
|
120 | - $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
121 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
122 | - } |
|
123 | - |
|
124 | - return implode($delimiter, $output) . PHP_EOL; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Shortcut for preparing a database result for display |
|
131 | - * @param EEM_Base $model |
|
132 | - * @param string $field_name |
|
133 | - * @param string $raw_db_value |
|
134 | - * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
138 | - { |
|
139 | - $field_obj = $model->field_settings_for($field_name); |
|
140 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
141 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
142 | - $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
143 | - $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
144 | - } |
|
145 | - if ($pretty_schema === true) { |
|
146 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
147 | - } elseif (is_string($pretty_schema)) { |
|
148 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
149 | - } else { |
|
150 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Gets the date format to use in exports. filterable |
|
158 | - * @param string $current_format |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public static function get_date_format_for_export($current_format = null) |
|
162 | - { |
|
163 | - return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Gets the time format we want to use in exports. Filterable |
|
170 | - * @param string $current_format |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public static function get_time_format_for_export($current_format = null) |
|
174 | - { |
|
175 | - return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
176 | - } |
|
16 | + /** |
|
17 | + * Gets the 'normal' column named for fields |
|
18 | + * @param EE_Model_Field_Base $field |
|
19 | + * @return string |
|
20 | + * @throws EE_Error |
|
21 | + */ |
|
22 | + public static function get_column_name_for_field(EE_Model_Field_Base $field) |
|
23 | + { |
|
24 | + $column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES); |
|
25 | + if ( |
|
26 | + apply_filters( |
|
27 | + 'FHEE__EEH_Export__get_column_name_for_field__add_field_name', |
|
28 | + false, |
|
29 | + $column_name, |
|
30 | + $field |
|
31 | + ) |
|
32 | + ) { |
|
33 | + $column_name .= "[" |
|
34 | + . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
35 | + . "]"; |
|
36 | + } |
|
37 | + return $column_name; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
42 | + * |
|
43 | + * @param string $filepath |
|
44 | + * @param array $data 2D array, first numerically-indexed, |
|
45 | + * and next-level-down preferably indexed by string |
|
46 | + * @param boolean $write_column_headers whether or not we should add the keys in the bottom-most array |
|
47 | + * as a row for headers in the CSV. |
|
48 | + * Eg, if $data looked like: |
|
49 | + * array( |
|
50 | + * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
51 | + * 1=>array(...,...) |
|
52 | + * ) |
|
53 | + * |
|
54 | + * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
55 | + * we consider that a success (because we wrote everything there was...nothing) |
|
56 | + * @throws EE_Error |
|
57 | + */ |
|
58 | + public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) |
|
59 | + { |
|
60 | + |
|
61 | + $new_file_contents = ''; |
|
62 | + // determine if $data is actually a 2d array |
|
63 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
64 | + // make sure top level is numerically indexed, |
|
65 | + |
|
66 | + if (EEH_Array::is_associative_array($data)) { |
|
67 | + throw new EE_Error(sprintf(esc_html__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
68 | + } |
|
69 | + $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
70 | + // now, is the last item in the top-level array of $data an associative or numeric array? |
|
71 | + if ( |
|
72 | + $write_column_headers && |
|
73 | + EEH_Array::is_associative_array($item_in_top_level_array) |
|
74 | + ) { |
|
75 | + // its associative, so we want to output its keys as column headers |
|
76 | + $keys = array_keys($item_in_top_level_array); |
|
77 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
78 | + } |
|
79 | + // start writing data |
|
80 | + foreach ($data as $data_row) { |
|
81 | + $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
82 | + } |
|
83 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
84 | + } else { |
|
85 | + // no data TO write... so we can assume that's a success |
|
86 | + return true; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * |
|
94 | + * Writes a row to the csv file |
|
95 | + * @param array $row - individual row of csv data |
|
96 | + * @param string $delimiter - csv delimiter |
|
97 | + * @param string $enclosure - csv enclosure |
|
98 | + * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
99 | + * @return string of text for teh csv file |
|
100 | + */ |
|
101 | + public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
102 | + { |
|
103 | + // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
104 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
105 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
106 | + |
|
107 | + $delimiter_esc = preg_quote($delimiter, '/'); |
|
108 | + $enclosure_esc = preg_quote($enclosure, '/'); |
|
109 | + |
|
110 | + $output = array(); |
|
111 | + foreach ($row as $field_value) { |
|
112 | + if (is_object($field_value) || is_array($field_value)) { |
|
113 | + $field_value = serialize($field_value); |
|
114 | + } |
|
115 | + if ($field_value === null && $mysql_null) { |
|
116 | + $output[] = 'NULL'; |
|
117 | + continue; |
|
118 | + } |
|
119 | + |
|
120 | + $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
121 | + ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
122 | + } |
|
123 | + |
|
124 | + return implode($delimiter, $output) . PHP_EOL; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Shortcut for preparing a database result for display |
|
131 | + * @param EEM_Base $model |
|
132 | + * @param string $field_name |
|
133 | + * @param string $raw_db_value |
|
134 | + * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
138 | + { |
|
139 | + $field_obj = $model->field_settings_for($field_name); |
|
140 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
141 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
142 | + $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
143 | + $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
144 | + } |
|
145 | + if ($pretty_schema === true) { |
|
146 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
147 | + } elseif (is_string($pretty_schema)) { |
|
148 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
149 | + } else { |
|
150 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Gets the date format to use in exports. filterable |
|
158 | + * @param string $current_format |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public static function get_date_format_for_export($current_format = null) |
|
162 | + { |
|
163 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Gets the time format we want to use in exports. Filterable |
|
170 | + * @param string $current_format |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public static function get_time_format_for_export($current_format = null) |
|
174 | + { |
|
175 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
176 | + } |
|
177 | 177 | } |
@@ -17,340 +17,340 @@ |
||
17 | 17 | */ |
18 | 18 | class CustomSelects |
19 | 19 | { |
20 | - const TYPE_SIMPLE = 'simple'; |
|
21 | - const TYPE_COMPLEX = 'complex'; |
|
22 | - const TYPE_STRUCTURED = 'structured'; |
|
23 | - |
|
24 | - private $valid_operators = array('COUNT', 'SUM'); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Original incoming select array |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $original_selects; |
|
33 | - |
|
34 | - /** |
|
35 | - * Select string that can be added to the query |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $columns_to_select_expression; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * An array of aliases for the columns included in the incoming select array. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private $column_aliases_in_select; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Enum representation of the "type" of array coming into this value object. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $type = ''; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * CustomSelects constructor. |
|
60 | - * Incoming selects can be in one of the following formats: |
|
61 | - * ---- self::TYPE_SIMPLE array ---- |
|
62 | - * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | - * multiple columns to select as the values. |
|
64 | - * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | - * eg. array( '*' ) |
|
66 | - * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | - * "structured" method. |
|
68 | - * ---- self::TYPE_COMPLEX array ---- |
|
69 | - * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | - * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | - * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | - * EEM_Base::$_valid_wpdb_data_types. |
|
73 | - * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | - * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | - * ---- self::TYPE_STRUCTURED array --- |
|
76 | - * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | - * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | - * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | - * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | - * the second value. |
|
81 | - * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | - * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | - * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | - * |
|
85 | - * @param array $selects |
|
86 | - * @throws InvalidArgumentException |
|
87 | - */ |
|
88 | - public function __construct(array $selects) |
|
89 | - { |
|
90 | - $this->original_selects = $selects; |
|
91 | - $this->deriveType($selects); |
|
92 | - $this->deriveParts($selects); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Derives what type of custom select has been sent in. |
|
98 | - * |
|
99 | - * @param array $selects |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - private function deriveType(array $selects) |
|
103 | - { |
|
104 | - // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | - // ensure all elements of the array are simple. |
|
106 | - if (is_int(key($selects))) { |
|
107 | - // let's ensure all keys are ints |
|
108 | - $invalid_keys = array_filter( |
|
109 | - array_keys($selects), |
|
110 | - function ($value) { |
|
111 | - return ! is_int($value); |
|
112 | - } |
|
113 | - ); |
|
114 | - if (! empty($invalid_keys)) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - self::TYPE_SIMPLE |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $this->type = self::TYPE_SIMPLE; |
|
126 | - return; |
|
127 | - } |
|
128 | - // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | - // the first array element off. |
|
130 | - $first_element = reset($selects); |
|
131 | - |
|
132 | - if (! is_array($first_element)) { |
|
133 | - throw new InvalidArgumentException( |
|
134 | - sprintf( |
|
135 | - esc_html__( |
|
136 | - 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - self::TYPE_COMPLEX, |
|
140 | - self::TYPE_STRUCTURED |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - $this->type = count($first_element) === 2 |
|
145 | - ? self::TYPE_COMPLEX |
|
146 | - : self::TYPE_STRUCTURED; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Sets up the various properties for the vo depending on type. |
|
152 | - * |
|
153 | - * @param array $selects |
|
154 | - * @throws InvalidArgumentException |
|
155 | - */ |
|
156 | - private function deriveParts(array $selects) |
|
157 | - { |
|
158 | - $column_parts = array(); |
|
159 | - switch ($this->type) { |
|
160 | - case self::TYPE_SIMPLE: |
|
161 | - $column_parts = $selects; |
|
162 | - $this->column_aliases_in_select = $selects; |
|
163 | - break; |
|
164 | - case self::TYPE_COMPLEX: |
|
165 | - foreach ($selects as $alias => $parts) { |
|
166 | - $this->validateSelectValueForType($parts, $alias); |
|
167 | - $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | - $this->column_aliases_in_select[] = $alias; |
|
169 | - } |
|
170 | - break; |
|
171 | - case self::TYPE_STRUCTURED: |
|
172 | - foreach ($selects as $alias => $parts) { |
|
173 | - $this->validateSelectValueForType($parts, $alias); |
|
174 | - $column_parts[] = $parts[1] !== '' |
|
175 | - ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | - : "{$parts[0]} AS {$alias}"; |
|
177 | - $this->column_aliases_in_select[] = $alias; |
|
178 | - } |
|
179 | - break; |
|
180 | - } |
|
181 | - $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | - * |
|
188 | - * @param array $select_parts |
|
189 | - * @param string $alias |
|
190 | - * @throws InvalidArgumentException |
|
191 | - */ |
|
192 | - private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | - { |
|
194 | - $valid_data_types = array('%d', '%s', '%f'); |
|
195 | - if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | - throw new InvalidArgumentException( |
|
197 | - sprintf( |
|
198 | - esc_html__( |
|
199 | - 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | - 'event_espresso' |
|
201 | - ), |
|
202 | - $alias, |
|
203 | - $this->expectedSelectPartCountForType(), |
|
204 | - $this->type, |
|
205 | - count($select_parts) |
|
206 | - ) |
|
207 | - ); |
|
208 | - } |
|
209 | - // validate data type. |
|
210 | - $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | - $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | - |
|
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | - throw new InvalidArgumentException( |
|
215 | - sprintf( |
|
216 | - esc_html__( |
|
217 | - 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - $data_type, |
|
221 | - $select_parts[0], |
|
222 | - $alias, |
|
223 | - implode(', ', $valid_data_types) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | - * |
|
233 | - * @param string $type |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - private function expectedSelectPartCountForType($type = '') |
|
237 | - { |
|
238 | - $type = $type === '' ? $this->type : $type; |
|
239 | - $types_count_map = array( |
|
240 | - self::TYPE_COMPLEX => 2, |
|
241 | - self::TYPE_STRUCTURED => 3, |
|
242 | - ); |
|
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Prepares the select statement part for for structured type selects. |
|
249 | - * |
|
250 | - * @param array $select_parts |
|
251 | - * @param string $alias |
|
252 | - * @return string |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | - { |
|
257 | - $operator = strtoupper($select_parts[1]); |
|
258 | - // validate operator |
|
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | - throw new InvalidArgumentException( |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - $operator, |
|
267 | - $alias, |
|
268 | - implode(', ', $this->valid_operators) |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Return the datatype from the given select part. |
|
278 | - * Remember the select_part has already been validated on object instantiation. |
|
279 | - * |
|
280 | - * @param array $select_part |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function getDataTypeForSelectType(array $select_part) |
|
284 | - { |
|
285 | - switch ($this->type) { |
|
286 | - case self::TYPE_COMPLEX: |
|
287 | - return $select_part[1]; |
|
288 | - case self::TYPE_STRUCTURED: |
|
289 | - return $select_part[2]; |
|
290 | - default: |
|
291 | - return ''; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the original select array sent into the VO. |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function originalSelects() |
|
302 | - { |
|
303 | - return $this->original_selects; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns the final assembled select expression derived from the incoming select array. |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function columnsToSelectExpression() |
|
313 | - { |
|
314 | - return $this->columns_to_select_expression; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns all the column aliases derived from the incoming select array. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - public function columnAliases() |
|
324 | - { |
|
325 | - return $this->column_aliases_in_select; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns the enum type for the incoming select array. |
|
331 | - * |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function type() |
|
335 | - { |
|
336 | - return $this->type; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Return the datatype for the given column_alias |
|
342 | - * |
|
343 | - * @param string $column_alias |
|
344 | - * @return string (if there's no data type we return string as the default). |
|
345 | - */ |
|
346 | - public function getDataTypeForAlias($column_alias) |
|
347 | - { |
|
348 | - if ( |
|
349 | - isset($this->original_selects[ $column_alias ]) |
|
350 | - && in_array($column_alias, $this->columnAliases(), true) |
|
351 | - ) { |
|
352 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
353 | - } |
|
354 | - return '%s'; |
|
355 | - } |
|
20 | + const TYPE_SIMPLE = 'simple'; |
|
21 | + const TYPE_COMPLEX = 'complex'; |
|
22 | + const TYPE_STRUCTURED = 'structured'; |
|
23 | + |
|
24 | + private $valid_operators = array('COUNT', 'SUM'); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Original incoming select array |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $original_selects; |
|
33 | + |
|
34 | + /** |
|
35 | + * Select string that can be added to the query |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $columns_to_select_expression; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * An array of aliases for the columns included in the incoming select array. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private $column_aliases_in_select; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Enum representation of the "type" of array coming into this value object. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $type = ''; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * CustomSelects constructor. |
|
60 | + * Incoming selects can be in one of the following formats: |
|
61 | + * ---- self::TYPE_SIMPLE array ---- |
|
62 | + * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | + * multiple columns to select as the values. |
|
64 | + * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | + * eg. array( '*' ) |
|
66 | + * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | + * "structured" method. |
|
68 | + * ---- self::TYPE_COMPLEX array ---- |
|
69 | + * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | + * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | + * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | + * EEM_Base::$_valid_wpdb_data_types. |
|
73 | + * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | + * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | + * ---- self::TYPE_STRUCTURED array --- |
|
76 | + * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | + * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | + * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | + * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | + * the second value. |
|
81 | + * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | + * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | + * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | + * |
|
85 | + * @param array $selects |
|
86 | + * @throws InvalidArgumentException |
|
87 | + */ |
|
88 | + public function __construct(array $selects) |
|
89 | + { |
|
90 | + $this->original_selects = $selects; |
|
91 | + $this->deriveType($selects); |
|
92 | + $this->deriveParts($selects); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Derives what type of custom select has been sent in. |
|
98 | + * |
|
99 | + * @param array $selects |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + private function deriveType(array $selects) |
|
103 | + { |
|
104 | + // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | + // ensure all elements of the array are simple. |
|
106 | + if (is_int(key($selects))) { |
|
107 | + // let's ensure all keys are ints |
|
108 | + $invalid_keys = array_filter( |
|
109 | + array_keys($selects), |
|
110 | + function ($value) { |
|
111 | + return ! is_int($value); |
|
112 | + } |
|
113 | + ); |
|
114 | + if (! empty($invalid_keys)) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + self::TYPE_SIMPLE |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $this->type = self::TYPE_SIMPLE; |
|
126 | + return; |
|
127 | + } |
|
128 | + // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | + // the first array element off. |
|
130 | + $first_element = reset($selects); |
|
131 | + |
|
132 | + if (! is_array($first_element)) { |
|
133 | + throw new InvalidArgumentException( |
|
134 | + sprintf( |
|
135 | + esc_html__( |
|
136 | + 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + self::TYPE_COMPLEX, |
|
140 | + self::TYPE_STRUCTURED |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + $this->type = count($first_element) === 2 |
|
145 | + ? self::TYPE_COMPLEX |
|
146 | + : self::TYPE_STRUCTURED; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Sets up the various properties for the vo depending on type. |
|
152 | + * |
|
153 | + * @param array $selects |
|
154 | + * @throws InvalidArgumentException |
|
155 | + */ |
|
156 | + private function deriveParts(array $selects) |
|
157 | + { |
|
158 | + $column_parts = array(); |
|
159 | + switch ($this->type) { |
|
160 | + case self::TYPE_SIMPLE: |
|
161 | + $column_parts = $selects; |
|
162 | + $this->column_aliases_in_select = $selects; |
|
163 | + break; |
|
164 | + case self::TYPE_COMPLEX: |
|
165 | + foreach ($selects as $alias => $parts) { |
|
166 | + $this->validateSelectValueForType($parts, $alias); |
|
167 | + $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | + $this->column_aliases_in_select[] = $alias; |
|
169 | + } |
|
170 | + break; |
|
171 | + case self::TYPE_STRUCTURED: |
|
172 | + foreach ($selects as $alias => $parts) { |
|
173 | + $this->validateSelectValueForType($parts, $alias); |
|
174 | + $column_parts[] = $parts[1] !== '' |
|
175 | + ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | + : "{$parts[0]} AS {$alias}"; |
|
177 | + $this->column_aliases_in_select[] = $alias; |
|
178 | + } |
|
179 | + break; |
|
180 | + } |
|
181 | + $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | + * |
|
188 | + * @param array $select_parts |
|
189 | + * @param string $alias |
|
190 | + * @throws InvalidArgumentException |
|
191 | + */ |
|
192 | + private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | + { |
|
194 | + $valid_data_types = array('%d', '%s', '%f'); |
|
195 | + if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | + throw new InvalidArgumentException( |
|
197 | + sprintf( |
|
198 | + esc_html__( |
|
199 | + 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | + 'event_espresso' |
|
201 | + ), |
|
202 | + $alias, |
|
203 | + $this->expectedSelectPartCountForType(), |
|
204 | + $this->type, |
|
205 | + count($select_parts) |
|
206 | + ) |
|
207 | + ); |
|
208 | + } |
|
209 | + // validate data type. |
|
210 | + $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | + $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | + |
|
213 | + if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | + throw new InvalidArgumentException( |
|
215 | + sprintf( |
|
216 | + esc_html__( |
|
217 | + 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + $data_type, |
|
221 | + $select_parts[0], |
|
222 | + $alias, |
|
223 | + implode(', ', $valid_data_types) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | + * |
|
233 | + * @param string $type |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + private function expectedSelectPartCountForType($type = '') |
|
237 | + { |
|
238 | + $type = $type === '' ? $this->type : $type; |
|
239 | + $types_count_map = array( |
|
240 | + self::TYPE_COMPLEX => 2, |
|
241 | + self::TYPE_STRUCTURED => 3, |
|
242 | + ); |
|
243 | + return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Prepares the select statement part for for structured type selects. |
|
249 | + * |
|
250 | + * @param array $select_parts |
|
251 | + * @param string $alias |
|
252 | + * @return string |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | + { |
|
257 | + $operator = strtoupper($select_parts[1]); |
|
258 | + // validate operator |
|
259 | + if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | + throw new InvalidArgumentException( |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + $operator, |
|
267 | + $alias, |
|
268 | + implode(', ', $this->valid_operators) |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Return the datatype from the given select part. |
|
278 | + * Remember the select_part has already been validated on object instantiation. |
|
279 | + * |
|
280 | + * @param array $select_part |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + private function getDataTypeForSelectType(array $select_part) |
|
284 | + { |
|
285 | + switch ($this->type) { |
|
286 | + case self::TYPE_COMPLEX: |
|
287 | + return $select_part[1]; |
|
288 | + case self::TYPE_STRUCTURED: |
|
289 | + return $select_part[2]; |
|
290 | + default: |
|
291 | + return ''; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the original select array sent into the VO. |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function originalSelects() |
|
302 | + { |
|
303 | + return $this->original_selects; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns the final assembled select expression derived from the incoming select array. |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function columnsToSelectExpression() |
|
313 | + { |
|
314 | + return $this->columns_to_select_expression; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns all the column aliases derived from the incoming select array. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + public function columnAliases() |
|
324 | + { |
|
325 | + return $this->column_aliases_in_select; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns the enum type for the incoming select array. |
|
331 | + * |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function type() |
|
335 | + { |
|
336 | + return $this->type; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Return the datatype for the given column_alias |
|
342 | + * |
|
343 | + * @param string $column_alias |
|
344 | + * @return string (if there's no data type we return string as the default). |
|
345 | + */ |
|
346 | + public function getDataTypeForAlias($column_alias) |
|
347 | + { |
|
348 | + if ( |
|
349 | + isset($this->original_selects[ $column_alias ]) |
|
350 | + && in_array($column_alias, $this->columnAliases(), true) |
|
351 | + ) { |
|
352 | + return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
353 | + } |
|
354 | + return '%s'; |
|
355 | + } |
|
356 | 356 | } |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | // let's ensure all keys are ints |
108 | 108 | $invalid_keys = array_filter( |
109 | 109 | array_keys($selects), |
110 | - function ($value) { |
|
110 | + function($value) { |
|
111 | 111 | return ! is_int($value); |
112 | 112 | } |
113 | 113 | ); |
114 | - if (! empty($invalid_keys)) { |
|
114 | + if ( ! empty($invalid_keys)) { |
|
115 | 115 | throw new InvalidArgumentException( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | // the first array element off. |
130 | 130 | $first_element = reset($selects); |
131 | 131 | |
132 | - if (! is_array($first_element)) { |
|
132 | + if ( ! is_array($first_element)) { |
|
133 | 133 | throw new InvalidArgumentException( |
134 | 134 | sprintf( |
135 | 135 | esc_html__( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
211 | 211 | $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
212 | 212 | |
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
213 | + if ( ! in_array($data_type, $valid_data_types, true)) { |
|
214 | 214 | throw new InvalidArgumentException( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | self::TYPE_COMPLEX => 2, |
241 | 241 | self::TYPE_STRUCTURED => 3, |
242 | 242 | ); |
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
243 | + return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | { |
257 | 257 | $operator = strtoupper($select_parts[1]); |
258 | 258 | // validate operator |
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
259 | + if ( ! in_array($operator, $this->valid_operators, true)) { |
|
260 | 260 | throw new InvalidArgumentException( |
261 | 261 | sprintf( |
262 | 262 | esc_html__( |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | } |
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
272 | + return $operator.'('.$select_parts[0].') AS '.$alias; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | public function getDataTypeForAlias($column_alias) |
347 | 347 | { |
348 | 348 | if ( |
349 | - isset($this->original_selects[ $column_alias ]) |
|
349 | + isset($this->original_selects[$column_alias]) |
|
350 | 350 | && in_array($column_alias, $this->columnAliases(), true) |
351 | 351 | ) { |
352 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | + return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
353 | 353 | } |
354 | 354 | return '%s'; |
355 | 355 | } |
@@ -15,27 +15,27 @@ |
||
15 | 15 | class International extends Basic |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $email_address |
|
20 | - * @return bool |
|
21 | - * @throws \EventEspresso\core\domain\services\validation\email\EmailValidationException |
|
22 | - */ |
|
23 | - public function validate($email_address) |
|
24 | - { |
|
25 | - parent::validate($email_address); |
|
26 | - if ( |
|
18 | + /** |
|
19 | + * @param string $email_address |
|
20 | + * @return bool |
|
21 | + * @throws \EventEspresso\core\domain\services\validation\email\EmailValidationException |
|
22 | + */ |
|
23 | + public function validate($email_address) |
|
24 | + { |
|
25 | + parent::validate($email_address); |
|
26 | + if ( |
|
27 | 27 | // plz see http://stackoverflow.com/a/24817336 re: the following regex |
28 | - ! preg_match( |
|
29 | - // @codingStandardsIgnoreStart |
|
30 | - '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
31 | - // @codingStandardsIgnoreEnd |
|
32 | - $email_address |
|
33 | - ) |
|
34 | - ) { |
|
35 | - throw new EmailValidationException( |
|
36 | - esc_html__('Email address is invalid.', 'event_espresso') |
|
37 | - ); |
|
38 | - } |
|
39 | - return true; |
|
40 | - } |
|
28 | + ! preg_match( |
|
29 | + // @codingStandardsIgnoreStart |
|
30 | + '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
31 | + // @codingStandardsIgnoreEnd |
|
32 | + $email_address |
|
33 | + ) |
|
34 | + ) { |
|
35 | + throw new EmailValidationException( |
|
36 | + esc_html__('Email address is invalid.', 'event_espresso') |
|
37 | + ); |
|
38 | + } |
|
39 | + return true; |
|
40 | + } |
|
41 | 41 | } |