@@ -83,25 +83,25 @@ discard block |
||
83 | 83 | </div> |
84 | 84 | <br class="clear" /> |
85 | 85 | <?php |
86 | - $no_payments = $grand_raw_total > 0 |
|
87 | - || $TXN_status !== EEM_Transaction::complete_status_code |
|
88 | - || ! empty($payments); |
|
89 | - ?> |
|
86 | + $no_payments = $grand_raw_total > 0 |
|
87 | + || $TXN_status !== EEM_Transaction::complete_status_code |
|
88 | + || ! empty($payments); |
|
89 | + ?> |
|
90 | 90 | <?php if ($attendee instanceof EE_Attendee && $no_payments) : ?> |
91 | 91 | <?php $no_payment_text = $can_edit_payments |
92 | - ? esc_html__( |
|
93 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
94 | - 'event_espresso' |
|
95 | - ) |
|
96 | - : esc_html__( |
|
97 | - 'No payments have been applied to this transaction yet.', |
|
98 | - 'event_espresso' |
|
99 | - ); |
|
100 | - ?> |
|
92 | + ? esc_html__( |
|
93 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
94 | + 'event_espresso' |
|
95 | + ) |
|
96 | + : esc_html__( |
|
97 | + 'No payments have been applied to this transaction yet.', |
|
98 | + 'event_espresso' |
|
99 | + ); |
|
100 | + ?> |
|
101 | 101 | |
102 | 102 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
103 | 103 | <span class="ee-icon ee-icon-cash"></span><?php |
104 | - esc_html_e('Payment Details', 'event_espresso'); ?> |
|
104 | + esc_html_e('Payment Details', 'event_espresso'); ?> |
|
105 | 105 | </h3> |
106 | 106 | |
107 | 107 | <div class="admin-primary-mbox-tbl-wrap"> |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | <th class="jst-left"><?php esc_html_e('TXN ID / CHQ #', 'event_espresso'); ?></th> |
118 | 118 | <th class="jst-left"><?php esc_html_e('P.O. / S.O. #', 'event_espresso'); ?></th> |
119 | 119 | <th class="jst-left"><?php esc_html_e( |
120 | - 'Notes / Extra Accounting', |
|
121 | - 'event_espresso' |
|
122 | - ); ?></th> |
|
120 | + 'Notes / Extra Accounting', |
|
121 | + 'event_espresso' |
|
122 | + ); ?></th> |
|
123 | 123 | <th class="jst-cntr"><?php esc_html_e('Amount', 'event_espresso'); ?></th> |
124 | 124 | </tr> |
125 | 125 | </thead> |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | <?php if ($payments) : ?> |
128 | 128 | <?php $payment_total = 0; ?> |
129 | 129 | <?php foreach ($payments as $PAY_ID => $payment) : |
130 | - if (! $payment instanceof EE_Payment) { |
|
131 | - continue; |
|
132 | - } |
|
133 | - $PAY_ID = absint($PAY_ID); |
|
134 | - $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
135 | - ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
136 | - : '{}'; |
|
137 | - ?> |
|
130 | + if (! $payment instanceof EE_Payment) { |
|
131 | + continue; |
|
132 | + } |
|
133 | + $PAY_ID = absint($PAY_ID); |
|
134 | + $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
135 | + ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
136 | + : '{}'; |
|
137 | + ?> |
|
138 | 138 | <tr id="txn-admin-payment-tr-<?php echo absint($PAY_ID); ?>"> |
139 | 139 | <td> |
140 | 140 | <span id="payment-status-<?php echo absint($PAY_ID); ?>" |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | </div> |
189 | 189 | <div id="payment-gateway-<?php echo absint($PAY_ID); ?>"> |
190 | 190 | <?php echo ($payment->payment_method() instanceof EE_Payment_Method |
191 | - ? esc_html($payment->payment_method()->admin_name()) |
|
192 | - : esc_html__("Unknown", 'event_espresso')); ?> |
|
191 | + ? esc_html($payment->payment_method()->admin_name()) |
|
192 | + : esc_html__("Unknown", 'event_espresso')); ?> |
|
193 | 193 | </div> |
194 | 194 | <div id="payment-gateway-id-<?php echo absint($PAY_ID); ?>" |
195 | 195 | class="hidden" |
196 | 196 | > |
197 | 197 | <?php echo ($payment->payment_method() instanceof EE_Payment_Method |
198 | - ? esc_html($payment->payment_method()->ID()) |
|
199 | - : 0); ?> |
|
198 | + ? esc_html($payment->payment_method()->ID()) |
|
199 | + : 0); ?> |
|
200 | 200 | </div> |
201 | 201 | </td> |
202 | 202 | <td class=" jst-left"> |
@@ -221,18 +221,18 @@ discard block |
||
221 | 221 | </td> |
222 | 222 | <td class=" jst-rght"> |
223 | 223 | <?php |
224 | - $payment_class = $payment->amount() > 0 |
|
225 | - ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
226 | - : 'txn-admin-payment-status-PDC'; |
|
227 | - ?> |
|
224 | + $payment_class = $payment->amount() > 0 |
|
225 | + ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
226 | + : 'txn-admin-payment-status-PDC'; |
|
227 | + ?> |
|
228 | 228 | <span class="<?php echo esc_attr($payment_class); ?>"> |
229 | 229 | <span id="payment-amount-<?php echo absint($PAY_ID); ?>" style="display:inline;"> |
230 | 230 | <?php echo EEH_Template::format_currency( |
231 | - $payment->amount(), |
|
232 | - false, |
|
233 | - false |
|
234 | - ); // already escaped |
|
235 | - ?> |
|
231 | + $payment->amount(), |
|
232 | + false, |
|
233 | + false |
|
234 | + ); // already escaped |
|
235 | + ?> |
|
236 | 236 | </span> |
237 | 237 | </span> |
238 | 238 | </td> |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | <?php $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; ?> |
241 | 241 | <?php endforeach; ?> |
242 | 242 | <?php $pay_totals_class = $payment_total > $grand_raw_total |
243 | - ? ' important-notice' |
|
244 | - : ''; |
|
245 | - ?> |
|
243 | + ? ' important-notice' |
|
244 | + : ''; |
|
245 | + ?> |
|
246 | 246 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
247 | 247 | <td class=" jst-rght" colspan="10"> |
248 | 248 | <span class="important-notice"><?php echo wp_kses($no_payment_text, AllowedTags::getAllowedTags()); ?></span> |
@@ -254,29 +254,29 @@ discard block |
||
254 | 254 | <th class=" jst-rght" colspan="9"> |
255 | 255 | <span id="payments-total-spn"> |
256 | 256 | <?php |
257 | - $overpaid = $payment_total > $grand_raw_total |
|
258 | - ? '<span id="overpaid">' |
|
259 | - . __('This transaction has been overpaid ! ', 'event_espresso') |
|
260 | - . '</span>' |
|
261 | - : ''; |
|
262 | - echo wp_kses( |
|
263 | - $overpaid |
|
264 | - . sprintf( |
|
265 | - __('Payments Total %s', 'event_espresso'), |
|
266 | - '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
267 | - ), |
|
268 | - AllowedTags::getAllowedTags() |
|
269 | - ); ?> |
|
257 | + $overpaid = $payment_total > $grand_raw_total |
|
258 | + ? '<span id="overpaid">' |
|
259 | + . __('This transaction has been overpaid ! ', 'event_espresso') |
|
260 | + . '</span>' |
|
261 | + : ''; |
|
262 | + echo wp_kses( |
|
263 | + $overpaid |
|
264 | + . sprintf( |
|
265 | + __('Payments Total %s', 'event_espresso'), |
|
266 | + '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
267 | + ), |
|
268 | + AllowedTags::getAllowedTags() |
|
269 | + ); ?> |
|
270 | 270 | </span> |
271 | 271 | </th> |
272 | 272 | <th class=" jst-rght"> |
273 | 273 | <span id="txn-admin-payment-total"> |
274 | 274 | <?php |
275 | - echo EEH_Template::format_currency( |
|
276 | - $payment_total, |
|
277 | - false, |
|
278 | - false |
|
279 | - ); // already escaped ?> |
|
275 | + echo EEH_Template::format_currency( |
|
276 | + $payment_total, |
|
277 | + false, |
|
278 | + false |
|
279 | + ); // already escaped ?> |
|
280 | 280 | </span> |
281 | 281 | </th> |
282 | 282 | </tr> |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | <ul id="txn-admin-payment-options-ul"> |
361 | 361 | <?php if ($can_edit_payments) : |
362 | - ?> |
|
362 | + ?> |
|
363 | 363 | <li> |
364 | 364 | <a id="display-txn-admin-apply-payment" |
365 | 365 | class="button-primary no-icon no-hide" |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | </li> |
385 | 385 | <?php endif; ?> |
386 | 386 | <?php |
387 | - // Allows extend the fields at actions area. |
|
388 | - do_action( |
|
389 | - 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
390 | - $can_edit_payments |
|
391 | - ); |
|
392 | - ?> |
|
387 | + // Allows extend the fields at actions area. |
|
388 | + do_action( |
|
389 | + 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
390 | + $can_edit_payments |
|
391 | + ); |
|
392 | + ?> |
|
393 | 393 | </ul> |
394 | 394 | <br class="clear" /> |
395 | 395 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | > |
401 | 401 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
402 | 402 | <?php |
403 | - echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?> |
|
403 | + echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?> |
|
404 | 404 | </h2> |
405 | 405 | |
406 | 406 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -408,23 +408,23 @@ discard block |
||
408 | 408 | > |
409 | 409 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
410 | 410 | <?php |
411 | - printf( |
|
412 | - esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
413 | - '<span></span>', |
|
414 | - $txn_nmbr['value'] |
|
415 | - ); |
|
416 | - ?> |
|
411 | + printf( |
|
412 | + esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
413 | + '<span></span>', |
|
414 | + $txn_nmbr['value'] |
|
415 | + ); |
|
416 | + ?> |
|
417 | 417 | </h2> |
418 | 418 | |
419 | 419 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
420 | 420 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
421 | 421 | <?php |
422 | - printf( |
|
423 | - esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
424 | - '<span></span>', |
|
425 | - $txn_nmbr['value'] |
|
426 | - ); |
|
427 | - ?> |
|
422 | + printf( |
|
423 | + esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
424 | + '<span></span>', |
|
425 | + $txn_nmbr['value'] |
|
426 | + ); |
|
427 | + ?> |
|
428 | 428 | </h2> |
429 | 429 | |
430 | 430 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -432,9 +432,9 @@ discard block |
||
432 | 432 | > |
433 | 433 | <div class="ee-icon ee-icon-cash-remove float-left"></div> |
434 | 434 | <?php |
435 | - echo esc_html__('Apply a Refund to Transaction #', 'event_espresso'); |
|
436 | - echo esc_html($txn_nmbr['value']); |
|
437 | - ?> |
|
435 | + echo esc_html__('Apply a Refund to Transaction #', 'event_espresso'); |
|
436 | + echo esc_html($txn_nmbr['value']); |
|
437 | + ?> |
|
438 | 438 | </h2> |
439 | 439 | |
440 | 440 | <form name="txn-admin-apply-payment-frm" |
@@ -533,29 +533,29 @@ discard block |
||
533 | 533 | > |
534 | 534 | <?php foreach ($payment_methods as $method) : ?> |
535 | 535 | <?php |
536 | - $selected = $method->slug() == 'cash' |
|
537 | - ? ' selected' |
|
538 | - : ''; |
|
539 | - ?> |
|
536 | + $selected = $method->slug() == 'cash' |
|
537 | + ? ' selected' |
|
538 | + : ''; |
|
539 | + ?> |
|
540 | 540 | <option id="payment-method-opt-<?php echo esc_attr($method->slug()); ?>" |
541 | 541 | value="<?php echo esc_attr($method->ID()); ?>" |
542 | 542 | <?php echo esc_attr($selected); ?> |
543 | 543 | > |
544 | 544 | <?php |
545 | - echo esc_html( |
|
546 | - sanitize_key($method->admin_desc()) |
|
547 | - ? substr($method->admin_desc(), 0, 128) |
|
548 | - : $method->admin_name() |
|
549 | - ); |
|
550 | - ?> |
|
545 | + echo esc_html( |
|
546 | + sanitize_key($method->admin_desc()) |
|
547 | + ? substr($method->admin_desc(), 0, 128) |
|
548 | + : $method->admin_name() |
|
549 | + ); |
|
550 | + ?> |
|
551 | 551 | </option> |
552 | 552 | <?php endforeach; ?> |
553 | 553 | </select> |
554 | 554 | <p class="description"> |
555 | 555 | <?php esc_html_e( |
556 | - 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
557 | - 'event_espresso' |
|
558 | - ); ?> |
|
556 | + 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
557 | + 'event_espresso' |
|
558 | + ); ?> |
|
559 | 559 | </p> |
560 | 560 | </div> |
561 | 561 | |
@@ -563,9 +563,9 @@ discard block |
||
563 | 563 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
564 | 564 | <label for="txn-admin-payment-txn-id-chq-nmbr-inp" class=""> |
565 | 565 | <?php esc_html_e( |
566 | - 'TXN ID / CHQ #', |
|
567 | - 'event_espresso' |
|
568 | - ); ?> |
|
566 | + 'TXN ID / CHQ #', |
|
567 | + 'event_espresso' |
|
568 | + ); ?> |
|
569 | 569 | </label> |
570 | 570 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
571 | 571 | id="txn-admin-payment-txn-id-chq-nmbr-inp" |
@@ -574,9 +574,9 @@ discard block |
||
574 | 574 | /> |
575 | 575 | <p class="description"> |
576 | 576 | <?php esc_html_e( |
577 | - 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
578 | - 'event_espresso' |
|
579 | - ); ?> |
|
577 | + 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
578 | + 'event_espresso' |
|
579 | + ); ?> |
|
580 | 580 | </p> |
581 | 581 | </div> |
582 | 582 | </div> |
@@ -593,9 +593,9 @@ discard block |
||
593 | 593 | /> |
594 | 594 | <p class="description"> |
595 | 595 | <?php esc_html_e( |
596 | - 'The gateway response string (optional)', |
|
597 | - 'event_espresso' |
|
598 | - ); ?> |
|
596 | + 'The gateway response string (optional)', |
|
597 | + 'event_espresso' |
|
598 | + ); ?> |
|
599 | 599 | </p> |
600 | 600 | </div> |
601 | 601 | </div> |
@@ -604,9 +604,9 @@ discard block |
||
604 | 604 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
605 | 605 | <label for="txn-admin-payment-status-slct" class=""> |
606 | 606 | <?php esc_html_e( |
607 | - 'Payment Status', |
|
608 | - 'event_espresso' |
|
609 | - ); ?> |
|
607 | + 'Payment Status', |
|
608 | + 'event_espresso' |
|
609 | + ); ?> |
|
610 | 610 | </label> |
611 | 611 | <select name="txn_admin_payment[status]" |
612 | 612 | id="txn-admin-payment-status-slct" |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | > |
616 | 616 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
617 | 617 | <?php |
618 | - $selected = $STS_ID == 'PAP' |
|
619 | - ? 'selected' |
|
620 | - : ''; |
|
621 | - ?> |
|
618 | + $selected = $STS_ID == 'PAP' |
|
619 | + ? 'selected' |
|
620 | + : ''; |
|
621 | + ?> |
|
622 | 622 | <option id="payment-status-opt-<?php echo esc_attr($STS_ID); ?>" |
623 | 623 | value="<?php echo esc_attr($STS_ID); ?>" |
624 | 624 | <?php echo esc_attr($selected); ?> |
@@ -629,10 +629,10 @@ discard block |
||
629 | 629 | </select> |
630 | 630 | <p class="description"> |
631 | 631 | <?php |
632 | - esc_html_e( |
|
633 | - 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
634 | - 'event_espresso' |
|
635 | - ); ?> |
|
632 | + esc_html_e( |
|
633 | + 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
634 | + 'event_espresso' |
|
635 | + ); ?> |
|
636 | 636 | </p> |
637 | 637 | </div> |
638 | 638 | </div> |
@@ -649,9 +649,9 @@ discard block |
||
649 | 649 | /> |
650 | 650 | <p class="description"> |
651 | 651 | <?php esc_html_e( |
652 | - 'The Purchase or Sales Order Number if any (optional)', |
|
653 | - 'event_espresso' |
|
654 | - ); ?> |
|
652 | + 'The Purchase or Sales Order Number if any (optional)', |
|
653 | + 'event_espresso' |
|
654 | + ); ?> |
|
655 | 655 | </p> |
656 | 656 | </div> |
657 | 657 | |
@@ -672,9 +672,9 @@ discard block |
||
672 | 672 | /> |
673 | 673 | <p class="description"> |
674 | 674 | <?php esc_html_e( |
675 | - 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
676 | - 'event_espresso' |
|
677 | - ); ?> |
|
675 | + 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
676 | + 'event_espresso' |
|
677 | + ); ?> |
|
678 | 678 | </p> |
679 | 679 | </div> |
680 | 680 | |
@@ -709,9 +709,9 @@ discard block |
||
709 | 709 | <?php echo wp_kses($status_change_select, AllowedTags::getWithFormTags()); ?> |
710 | 710 | <p class="description"> |
711 | 711 | <?php esc_html_e( |
712 | - 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
713 | - 'event_espresso' |
|
714 | - ); ?> |
|
712 | + 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
713 | + 'event_espresso' |
|
714 | + ); ?> |
|
715 | 715 | </p> |
716 | 716 | <br /> |
717 | 717 | </div> |
@@ -742,14 +742,14 @@ discard block |
||
742 | 742 | <br class="clear-float" /> |
743 | 743 | <p class="description"> |
744 | 744 | <?php printf( |
745 | - esc_html__( |
|
746 | - 'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
|
747 | - 'event_espresso' |
|
748 | - ), |
|
749 | - '<strong>', |
|
750 | - '</strong>', |
|
751 | - '<br />' |
|
752 | - ); ?> |
|
745 | + esc_html__( |
|
746 | + 'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
|
747 | + 'event_espresso' |
|
748 | + ), |
|
749 | + '<strong>', |
|
750 | + '</strong>', |
|
751 | + '<br />' |
|
752 | + ); ?> |
|
753 | 753 | </p> |
754 | 754 | </div> |
755 | 755 | <div class="clear"></div> |
@@ -814,10 +814,10 @@ discard block |
||
814 | 814 | > |
815 | 815 | <span class="ee-icon ee-icon-cash-add"></span> |
816 | 816 | <?php printf( |
817 | - esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'), |
|
818 | - $txn_nmbr['value'] |
|
819 | - ); |
|
820 | - ?> |
|
817 | + esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'), |
|
818 | + $txn_nmbr['value'] |
|
819 | + ); |
|
820 | + ?> |
|
821 | 821 | </h2> |
822 | 822 | |
823 | 823 | <form name="txn-admin-delete-payment-frm" |
@@ -853,13 +853,13 @@ discard block |
||
853 | 853 | <?php echo wp_kses($delete_status_change_select, AllowedTags::getWithFormTags()); ?> |
854 | 854 | <p class="description"> |
855 | 855 | <?php printf( |
856 | - esc_html__( |
|
857 | - 'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
|
858 | - 'event_espresso' |
|
859 | - ), |
|
860 | - '<strong>', |
|
861 | - '</strong>' |
|
862 | - ); ?> |
|
856 | + esc_html__( |
|
857 | + 'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
|
858 | + 'event_espresso' |
|
859 | + ), |
|
860 | + '<strong>', |
|
861 | + '</strong>' |
|
862 | + ); ?> |
|
863 | 863 | </p> |
864 | 864 | </div> |
865 | 865 | |
@@ -874,10 +874,10 @@ discard block |
||
874 | 874 | /> |
875 | 875 | <p class="description"> |
876 | 876 | <?php |
877 | - esc_html_e( |
|
878 | - 'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
|
879 | - 'event_espresso' |
|
880 | - ); ?> |
|
877 | + esc_html_e( |
|
878 | + 'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
|
879 | + 'event_espresso' |
|
880 | + ); ?> |
|
881 | 881 | </p> |
882 | 882 | </div> |
883 | 883 | <div class="clear"></div> |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | <?php endif; // $grand_raw_total > 0?> |
911 | 911 | |
912 | 912 | <?php if (WP_DEBUG) { |
913 | - $delivered_messages = get_option('EED_Messages__payment', []); |
|
914 | - if (isset($delivered_messages[ $TXN_ID ])) { ?> |
|
913 | + $delivered_messages = get_option('EED_Messages__payment', []); |
|
914 | + if (isset($delivered_messages[ $TXN_ID ])) { ?> |
|
915 | 915 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"> |
916 | 916 | <span class="dashicons dashicons-email-alt"></span> |
917 | 917 | <?php esc_html_e('Messages Sent to Primary Registrant', 'event_espresso'); ?> |
@@ -923,39 +923,39 @@ discard block |
||
923 | 923 | <th class="jst-left"><?php esc_html_e('Date & Time', 'event_espresso'); ?></th> |
924 | 924 | <th class="jst-left"><?php esc_html_e('Message Type', 'event_espresso'); ?></th> |
925 | 925 | <th class="jst-left"><?php esc_html_e( |
926 | - 'Payment Status Upon Sending', |
|
927 | - 'event_espresso' |
|
928 | - ); ?></th> |
|
926 | + 'Payment Status Upon Sending', |
|
927 | + 'event_espresso' |
|
928 | + ); ?></th> |
|
929 | 929 | <th class="jst-left"><?php esc_html_e('TXN Status Upon Sending', 'event_espresso'); ?></th> |
930 | 930 | </tr> |
931 | 931 | </thead> |
932 | 932 | <tbody> |
933 | 933 | <?php |
934 | - foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
|
935 | - ?> |
|
934 | + foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
|
935 | + ?> |
|
936 | 936 | <tr> |
937 | 937 | <td class="jst-left"> |
938 | 938 | <?php echo esc_html( |
939 | - date( |
|
940 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
941 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
942 | - ) |
|
943 | - ); ?> |
|
939 | + date( |
|
940 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
941 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
942 | + ) |
|
943 | + ); ?> |
|
944 | 944 | </td> |
945 | 945 | <td class="jst-left"><?php |
946 | - echo isset($delivered_message['message_type']) |
|
947 | - ? esc_html($delivered_message['message_type']) |
|
948 | - : ''; ?> |
|
946 | + echo isset($delivered_message['message_type']) |
|
947 | + ? esc_html($delivered_message['message_type']) |
|
948 | + : ''; ?> |
|
949 | 949 | </td> |
950 | 950 | <td class="jst-left"><?php |
951 | - echo isset($delivered_message['pay_status']) |
|
952 | - ? esc_html($delivered_message['pay_status']) |
|
953 | - : ''; ?> |
|
951 | + echo isset($delivered_message['pay_status']) |
|
952 | + ? esc_html($delivered_message['pay_status']) |
|
953 | + : ''; ?> |
|
954 | 954 | </td> |
955 | 955 | <td class="jst-left"><?php |
956 | - echo isset($delivered_message['txn_status']) |
|
957 | - ? esc_html($delivered_message['txn_status']) |
|
958 | - : ''; ?> |
|
956 | + echo isset($delivered_message['txn_status']) |
|
957 | + ? esc_html($delivered_message['txn_status']) |
|
958 | + : ''; ?> |
|
959 | 959 | </td> |
960 | 960 | </tr> |
961 | 961 | <?php endforeach; // $delivered_messages?> |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | </table> |
964 | 964 | </div> |
965 | 965 | <?php |
966 | - } |
|
967 | - } |
|
968 | - ?> |
|
966 | + } |
|
967 | + } |
|
968 | + ?> |
|
969 | 969 | </div> |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | <?php if ($payments) : ?> |
128 | 128 | <?php $payment_total = 0; ?> |
129 | 129 | <?php foreach ($payments as $PAY_ID => $payment) : |
130 | - if (! $payment instanceof EE_Payment) { |
|
130 | + if ( ! $payment instanceof EE_Payment) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $PAY_ID = absint($PAY_ID); |
134 | - $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
135 | - ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
134 | + $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
135 | + ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
136 | 136 | : '{}'; |
137 | 137 | ?> |
138 | 138 | <tr id="txn-admin-payment-tr-<?php echo absint($PAY_ID); ?>"> |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | <td class=" jst-rght"> |
223 | 223 | <?php |
224 | 224 | $payment_class = $payment->amount() > 0 |
225 | - ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
225 | + ? 'txn-admin-payment-status-'.$payment->STS_ID() |
|
226 | 226 | : 'txn-admin-payment-status-PDC'; |
227 | 227 | ?> |
228 | 228 | <span class="<?php echo esc_attr($payment_class); ?>"> |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $overpaid |
264 | 264 | . sprintf( |
265 | 265 | __('Payments Total %s', 'event_espresso'), |
266 | - '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
266 | + '('.EE_Registry::instance()->CFG->currency->code.')' |
|
267 | 267 | ), |
268 | 268 | AllowedTags::getAllowedTags() |
269 | 269 | ); ?> |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | > |
401 | 401 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
402 | 402 | <?php |
403 | - echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?> |
|
403 | + echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').esc_html($txn_nmbr['value']); ?> |
|
404 | 404 | </h2> |
405 | 405 | |
406 | 406 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | |
912 | 912 | <?php if (WP_DEBUG) { |
913 | 913 | $delivered_messages = get_option('EED_Messages__payment', []); |
914 | - if (isset($delivered_messages[ $TXN_ID ])) { ?> |
|
914 | + if (isset($delivered_messages[$TXN_ID])) { ?> |
|
915 | 915 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"> |
916 | 916 | <span class="dashicons dashicons-email-alt"></span> |
917 | 917 | <?php esc_html_e('Messages Sent to Primary Registrant', 'event_espresso'); ?> |
@@ -931,13 +931,13 @@ discard block |
||
931 | 931 | </thead> |
932 | 932 | <tbody> |
933 | 933 | <?php |
934 | - foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
|
934 | + foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
|
935 | 935 | ?> |
936 | 936 | <tr> |
937 | 937 | <td class="jst-left"> |
938 | 938 | <?php echo esc_html( |
939 | 939 | date( |
940 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
940 | + get_option('date_format').' '.get_option('time_format'), |
|
941 | 941 | ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
942 | 942 | ) |
943 | 943 | ); ?> |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.013'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.013'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -15,486 +15,486 @@ |
||
15 | 15 | abstract class EE_Form_Section_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * the URL the form is submitted to |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_action; |
|
24 | - |
|
25 | - /** |
|
26 | - * POST (default) or GET |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $_method; |
|
31 | - |
|
32 | - /** |
|
33 | - * html_id and html_name are derived from this by default |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $_name; |
|
38 | - |
|
39 | - /** |
|
40 | - * $_html_id |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $_html_id; |
|
44 | - |
|
45 | - /** |
|
46 | - * $_html_class |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_html_class; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_html_style |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - protected $_html_style; |
|
56 | - |
|
57 | - /** |
|
58 | - * $_other_html_attributes |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $_other_html_attributes; |
|
62 | - |
|
63 | - /** |
|
64 | - * The form section of which this form section is a part |
|
65 | - * |
|
66 | - * @var EE_Form_Section_Proper |
|
67 | - */ |
|
68 | - protected $_parent_section; |
|
69 | - |
|
70 | - /** |
|
71 | - * flag indicating that _construct_finalize has been called. |
|
72 | - * If it has not been called and we try to use functions which require it, we call it |
|
73 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
74 | - * |
|
75 | - * @var boolean |
|
76 | - */ |
|
77 | - protected $_construction_finalized; |
|
78 | - |
|
79 | - /** |
|
80 | - * Strategy for parsing the form HTML upon display |
|
81 | - * |
|
82 | - * @var FormHtmlFilter |
|
83 | - */ |
|
84 | - protected $_form_html_filter; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $options_array { |
|
89 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
90 | - * } |
|
91 | - * @throws InvalidDataTypeException |
|
92 | - */ |
|
93 | - public function __construct($options_array = array()) |
|
94 | - { |
|
95 | - // used by display strategies |
|
96 | - // assign incoming values to properties |
|
97 | - foreach ($options_array as $key => $value) { |
|
98 | - $key = '_' . $key; |
|
99 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
100 | - $this->{$key} = $value; |
|
101 | - if ($key === '_subsections' && ! is_array($value)) { |
|
102 | - throw new InvalidDataTypeException($key, $value, 'array'); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - // set parser which allows the form section's rendered HTML to be filtered |
|
107 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
108 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param $parent_form_section |
|
116 | - * @param $name |
|
117 | - * @throws \EE_Error |
|
118 | - */ |
|
119 | - protected function _construct_finalize($parent_form_section, $name) |
|
120 | - { |
|
121 | - $this->_construction_finalized = true; |
|
122 | - $this->_parent_section = $parent_form_section; |
|
123 | - if ($name !== null) { |
|
124 | - $this->_name = $name; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * make sure construction finalized was called, otherwise children might not be ready |
|
132 | - * |
|
133 | - * @return void |
|
134 | - * @throws \EE_Error |
|
135 | - */ |
|
136 | - public function ensure_construct_finalized_called() |
|
137 | - { |
|
138 | - if (! $this->_construction_finalized) { |
|
139 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function action() |
|
149 | - { |
|
150 | - return $this->_action; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $action |
|
157 | - */ |
|
158 | - public function set_action($action) |
|
159 | - { |
|
160 | - $this->_action = $action; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function method() |
|
169 | - { |
|
170 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param string $method |
|
177 | - */ |
|
178 | - public function set_method($method) |
|
179 | - { |
|
180 | - switch ($method) { |
|
181 | - case 'get': |
|
182 | - case 'GET': |
|
183 | - $this->_method = 'GET'; |
|
184 | - break; |
|
185 | - default: |
|
186 | - $this->_method = 'POST'; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
194 | - * Calculation involves using the name and the parent's html id |
|
195 | - * return void |
|
196 | - * |
|
197 | - * @throws \EE_Error |
|
198 | - */ |
|
199 | - protected function _set_default_html_id_if_empty() |
|
200 | - { |
|
201 | - if (! $this->_html_id) { |
|
202 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
203 | - $this->_html_id = $this->_parent_section->html_id() |
|
204 | - . '-' |
|
205 | - . $this->_prep_name_for_html_id($this->name()); |
|
206 | - } else { |
|
207 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * _prep_name_for_html_id |
|
216 | - * |
|
217 | - * @param $name |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - private function _prep_name_for_html_id($name) |
|
221 | - { |
|
222 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
223 | - } |
|
18 | + /** |
|
19 | + * the URL the form is submitted to |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_action; |
|
24 | + |
|
25 | + /** |
|
26 | + * POST (default) or GET |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $_method; |
|
31 | + |
|
32 | + /** |
|
33 | + * html_id and html_name are derived from this by default |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $_name; |
|
38 | + |
|
39 | + /** |
|
40 | + * $_html_id |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $_html_id; |
|
44 | + |
|
45 | + /** |
|
46 | + * $_html_class |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_html_class; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_html_style |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + protected $_html_style; |
|
56 | + |
|
57 | + /** |
|
58 | + * $_other_html_attributes |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $_other_html_attributes; |
|
62 | + |
|
63 | + /** |
|
64 | + * The form section of which this form section is a part |
|
65 | + * |
|
66 | + * @var EE_Form_Section_Proper |
|
67 | + */ |
|
68 | + protected $_parent_section; |
|
69 | + |
|
70 | + /** |
|
71 | + * flag indicating that _construct_finalize has been called. |
|
72 | + * If it has not been called and we try to use functions which require it, we call it |
|
73 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
74 | + * |
|
75 | + * @var boolean |
|
76 | + */ |
|
77 | + protected $_construction_finalized; |
|
78 | + |
|
79 | + /** |
|
80 | + * Strategy for parsing the form HTML upon display |
|
81 | + * |
|
82 | + * @var FormHtmlFilter |
|
83 | + */ |
|
84 | + protected $_form_html_filter; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $options_array { |
|
89 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
90 | + * } |
|
91 | + * @throws InvalidDataTypeException |
|
92 | + */ |
|
93 | + public function __construct($options_array = array()) |
|
94 | + { |
|
95 | + // used by display strategies |
|
96 | + // assign incoming values to properties |
|
97 | + foreach ($options_array as $key => $value) { |
|
98 | + $key = '_' . $key; |
|
99 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
100 | + $this->{$key} = $value; |
|
101 | + if ($key === '_subsections' && ! is_array($value)) { |
|
102 | + throw new InvalidDataTypeException($key, $value, 'array'); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + // set parser which allows the form section's rendered HTML to be filtered |
|
107 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
108 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param $parent_form_section |
|
116 | + * @param $name |
|
117 | + * @throws \EE_Error |
|
118 | + */ |
|
119 | + protected function _construct_finalize($parent_form_section, $name) |
|
120 | + { |
|
121 | + $this->_construction_finalized = true; |
|
122 | + $this->_parent_section = $parent_form_section; |
|
123 | + if ($name !== null) { |
|
124 | + $this->_name = $name; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * make sure construction finalized was called, otherwise children might not be ready |
|
132 | + * |
|
133 | + * @return void |
|
134 | + * @throws \EE_Error |
|
135 | + */ |
|
136 | + public function ensure_construct_finalized_called() |
|
137 | + { |
|
138 | + if (! $this->_construction_finalized) { |
|
139 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function action() |
|
149 | + { |
|
150 | + return $this->_action; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $action |
|
157 | + */ |
|
158 | + public function set_action($action) |
|
159 | + { |
|
160 | + $this->_action = $action; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function method() |
|
169 | + { |
|
170 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param string $method |
|
177 | + */ |
|
178 | + public function set_method($method) |
|
179 | + { |
|
180 | + switch ($method) { |
|
181 | + case 'get': |
|
182 | + case 'GET': |
|
183 | + $this->_method = 'GET'; |
|
184 | + break; |
|
185 | + default: |
|
186 | + $this->_method = 'POST'; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
194 | + * Calculation involves using the name and the parent's html id |
|
195 | + * return void |
|
196 | + * |
|
197 | + * @throws \EE_Error |
|
198 | + */ |
|
199 | + protected function _set_default_html_id_if_empty() |
|
200 | + { |
|
201 | + if (! $this->_html_id) { |
|
202 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
203 | + $this->_html_id = $this->_parent_section->html_id() |
|
204 | + . '-' |
|
205 | + . $this->_prep_name_for_html_id($this->name()); |
|
206 | + } else { |
|
207 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * _prep_name_for_html_id |
|
216 | + * |
|
217 | + * @param $name |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + private function _prep_name_for_html_id($name) |
|
221 | + { |
|
222 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | 226 | |
227 | - /** |
|
228 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
229 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
230 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
231 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
232 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
233 | - * and so might stop working anytime. |
|
234 | - * |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function get_html_and_js() |
|
238 | - { |
|
239 | - return $this->get_html(); |
|
240 | - } |
|
227 | + /** |
|
228 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
229 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
230 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
231 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
232 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
233 | + * and so might stop working anytime. |
|
234 | + * |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function get_html_and_js() |
|
238 | + { |
|
239 | + return $this->get_html(); |
|
240 | + } |
|
241 | 241 | |
242 | 242 | |
243 | - |
|
244 | - /** |
|
245 | - * Gets the HTML for displaying this form section |
|
246 | - * |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - abstract public function get_html(); |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param bool $add_pound_sign |
|
254 | - * @return string |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - public function html_id($add_pound_sign = false) |
|
258 | - { |
|
259 | - $this->_set_default_html_id_if_empty(); |
|
260 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function html_class() |
|
269 | - { |
|
270 | - return $this->_html_class; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public function html_style() |
|
279 | - { |
|
280 | - return $this->_html_style; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @param mixed $html_class |
|
287 | - */ |
|
288 | - public function set_html_class($html_class) |
|
289 | - { |
|
290 | - $this->_html_class = $html_class; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param mixed $html_id |
|
297 | - */ |
|
298 | - public function set_html_id($html_id) |
|
299 | - { |
|
300 | - $this->_html_id = $html_id; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param mixed $html_style |
|
307 | - */ |
|
308 | - public function set_html_style($html_style) |
|
309 | - { |
|
310 | - $this->_html_style = $html_style; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @param string $other_html_attributes |
|
317 | - */ |
|
318 | - public function set_other_html_attributes($other_html_attributes) |
|
319 | - { |
|
320 | - $this->_other_html_attributes = $other_html_attributes; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function other_html_attributes() |
|
329 | - { |
|
330 | - return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
337 | - * |
|
338 | - * @throws EE_Error |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - public function name() |
|
342 | - { |
|
343 | - if (! $this->_construction_finalized) { |
|
344 | - throw new EE_Error(sprintf(esc_html__( |
|
345 | - 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | - 'event_espresso' |
|
347 | - ), get_class($this))); |
|
348 | - } |
|
349 | - return $this->_name; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Gets the parent section |
|
356 | - * |
|
357 | - * @return EE_Form_Section_Proper |
|
358 | - */ |
|
359 | - public function parent_section() |
|
360 | - { |
|
361 | - return $this->_parent_section; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | - * |
|
368 | - * @param string $action the URL the form is submitted to |
|
369 | - * @param string $method POST (default) or GET |
|
370 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | - * @return string |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
375 | - { |
|
376 | - if (! empty($action)) { |
|
377 | - $this->set_action($action); |
|
378 | - } |
|
379 | - if (! empty($method)) { |
|
380 | - $this->set_method($method); |
|
381 | - } |
|
382 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
383 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
384 | - $html .= ' action="' . $this->action() . '"'; |
|
385 | - $html .= ' method="' . $this->method() . '"'; |
|
386 | - $html .= ' name="' . $this->name() . '"'; |
|
387 | - $html .= ' ' . $other_attributes . '>'; |
|
388 | - return $html; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
395 | - * so that id doesn't conflict/collide with other elements |
|
396 | - * |
|
397 | - * @param string $html_id |
|
398 | - * @return string |
|
399 | - */ |
|
400 | - protected function get_html_id_for_form($html_id) |
|
401 | - { |
|
402 | - $strlen = strlen($html_id); |
|
403 | - $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
404 | - ? $html_id |
|
405 | - : $html_id . '-frm'; |
|
406 | - return $html_id; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
412 | - * |
|
413 | - * @return string |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - public function form_close() |
|
417 | - { |
|
418 | - return EEH_HTML::nl(-1, 'form') |
|
419 | - . '</form>' |
|
420 | - . EEH_HTML::nl() |
|
421 | - . '<!-- end of ee-' |
|
422 | - . $this->html_id() |
|
423 | - . '-form -->' |
|
424 | - . EEH_HTML::nl(); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
431 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
432 | - * Default does nothing, but child classes can override |
|
433 | - * |
|
434 | - * @return void |
|
435 | - */ |
|
436 | - public function enqueue_js() |
|
437 | - { |
|
438 | - // defaults to enqueue NO js or css |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
445 | - * with it, and it will be on each form section's 'other_data' property. |
|
446 | - * By default nothing is added, but child classes can extend this method to add something. |
|
447 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
448 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
449 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
450 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
451 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
452 | - * |
|
453 | - * @param array $form_other_js_data |
|
454 | - * @return array |
|
455 | - */ |
|
456 | - public function get_other_js_data($form_other_js_data = array()) |
|
457 | - { |
|
458 | - return $form_other_js_data; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
465 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
466 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
467 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
468 | - * which will be returned. |
|
469 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
470 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
471 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
472 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
473 | - * Etc |
|
474 | - * |
|
475 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
476 | - * @return EE_Form_Section_Base |
|
477 | - */ |
|
478 | - public function find_section_from_path($form_section_path) |
|
479 | - { |
|
480 | - if (strpos($form_section_path, '/') === 0) { |
|
481 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
482 | - } |
|
483 | - if (empty($form_section_path)) { |
|
484 | - return $this; |
|
485 | - } |
|
486 | - if (strpos($form_section_path, '../') === 0) { |
|
487 | - $parent = $this->parent_section(); |
|
488 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
489 | - if ($parent instanceof EE_Form_Section_Base) { |
|
490 | - return $parent->find_section_from_path($form_section_path); |
|
491 | - } |
|
492 | - if (empty($form_section_path)) { |
|
493 | - return $this; |
|
494 | - } |
|
495 | - } |
|
496 | - // couldn't find it using simple parent following |
|
497 | - return null; |
|
498 | - } |
|
243 | + |
|
244 | + /** |
|
245 | + * Gets the HTML for displaying this form section |
|
246 | + * |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + abstract public function get_html(); |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param bool $add_pound_sign |
|
254 | + * @return string |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + public function html_id($add_pound_sign = false) |
|
258 | + { |
|
259 | + $this->_set_default_html_id_if_empty(); |
|
260 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function html_class() |
|
269 | + { |
|
270 | + return $this->_html_class; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public function html_style() |
|
279 | + { |
|
280 | + return $this->_html_style; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @param mixed $html_class |
|
287 | + */ |
|
288 | + public function set_html_class($html_class) |
|
289 | + { |
|
290 | + $this->_html_class = $html_class; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param mixed $html_id |
|
297 | + */ |
|
298 | + public function set_html_id($html_id) |
|
299 | + { |
|
300 | + $this->_html_id = $html_id; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param mixed $html_style |
|
307 | + */ |
|
308 | + public function set_html_style($html_style) |
|
309 | + { |
|
310 | + $this->_html_style = $html_style; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @param string $other_html_attributes |
|
317 | + */ |
|
318 | + public function set_other_html_attributes($other_html_attributes) |
|
319 | + { |
|
320 | + $this->_other_html_attributes = $other_html_attributes; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function other_html_attributes() |
|
329 | + { |
|
330 | + return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
337 | + * |
|
338 | + * @throws EE_Error |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + public function name() |
|
342 | + { |
|
343 | + if (! $this->_construction_finalized) { |
|
344 | + throw new EE_Error(sprintf(esc_html__( |
|
345 | + 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | + 'event_espresso' |
|
347 | + ), get_class($this))); |
|
348 | + } |
|
349 | + return $this->_name; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Gets the parent section |
|
356 | + * |
|
357 | + * @return EE_Form_Section_Proper |
|
358 | + */ |
|
359 | + public function parent_section() |
|
360 | + { |
|
361 | + return $this->_parent_section; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | + * |
|
368 | + * @param string $action the URL the form is submitted to |
|
369 | + * @param string $method POST (default) or GET |
|
370 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | + * @return string |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
375 | + { |
|
376 | + if (! empty($action)) { |
|
377 | + $this->set_action($action); |
|
378 | + } |
|
379 | + if (! empty($method)) { |
|
380 | + $this->set_method($method); |
|
381 | + } |
|
382 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
383 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
384 | + $html .= ' action="' . $this->action() . '"'; |
|
385 | + $html .= ' method="' . $this->method() . '"'; |
|
386 | + $html .= ' name="' . $this->name() . '"'; |
|
387 | + $html .= ' ' . $other_attributes . '>'; |
|
388 | + return $html; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
395 | + * so that id doesn't conflict/collide with other elements |
|
396 | + * |
|
397 | + * @param string $html_id |
|
398 | + * @return string |
|
399 | + */ |
|
400 | + protected function get_html_id_for_form($html_id) |
|
401 | + { |
|
402 | + $strlen = strlen($html_id); |
|
403 | + $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
404 | + ? $html_id |
|
405 | + : $html_id . '-frm'; |
|
406 | + return $html_id; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
412 | + * |
|
413 | + * @return string |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + public function form_close() |
|
417 | + { |
|
418 | + return EEH_HTML::nl(-1, 'form') |
|
419 | + . '</form>' |
|
420 | + . EEH_HTML::nl() |
|
421 | + . '<!-- end of ee-' |
|
422 | + . $this->html_id() |
|
423 | + . '-form -->' |
|
424 | + . EEH_HTML::nl(); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
431 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
432 | + * Default does nothing, but child classes can override |
|
433 | + * |
|
434 | + * @return void |
|
435 | + */ |
|
436 | + public function enqueue_js() |
|
437 | + { |
|
438 | + // defaults to enqueue NO js or css |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
445 | + * with it, and it will be on each form section's 'other_data' property. |
|
446 | + * By default nothing is added, but child classes can extend this method to add something. |
|
447 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
448 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
449 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
450 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
451 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
452 | + * |
|
453 | + * @param array $form_other_js_data |
|
454 | + * @return array |
|
455 | + */ |
|
456 | + public function get_other_js_data($form_other_js_data = array()) |
|
457 | + { |
|
458 | + return $form_other_js_data; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
465 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
466 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
467 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
468 | + * which will be returned. |
|
469 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
470 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
471 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
472 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
473 | + * Etc |
|
474 | + * |
|
475 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
476 | + * @return EE_Form_Section_Base |
|
477 | + */ |
|
478 | + public function find_section_from_path($form_section_path) |
|
479 | + { |
|
480 | + if (strpos($form_section_path, '/') === 0) { |
|
481 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
482 | + } |
|
483 | + if (empty($form_section_path)) { |
|
484 | + return $this; |
|
485 | + } |
|
486 | + if (strpos($form_section_path, '../') === 0) { |
|
487 | + $parent = $this->parent_section(); |
|
488 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
489 | + if ($parent instanceof EE_Form_Section_Base) { |
|
490 | + return $parent->find_section_from_path($form_section_path); |
|
491 | + } |
|
492 | + if (empty($form_section_path)) { |
|
493 | + return $this; |
|
494 | + } |
|
495 | + } |
|
496 | + // couldn't find it using simple parent following |
|
497 | + return null; |
|
498 | + } |
|
499 | 499 | } |
500 | 500 | // End of file EE_Form_Section_Base.form.php |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | // used by display strategies |
96 | 96 | // assign incoming values to properties |
97 | 97 | foreach ($options_array as $key => $value) { |
98 | - $key = '_' . $key; |
|
98 | + $key = '_'.$key; |
|
99 | 99 | if (property_exists($this, $key) && empty($this->{$key})) { |
100 | 100 | $this->{$key} = $value; |
101 | 101 | if ($key === '_subsections' && ! is_array($value)) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function ensure_construct_finalized_called() |
137 | 137 | { |
138 | - if (! $this->_construction_finalized) { |
|
138 | + if ( ! $this->_construction_finalized) { |
|
139 | 139 | $this->_construct_finalize($this->_parent_section, $this->_name); |
140 | 140 | } |
141 | 141 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function _set_default_html_id_if_empty() |
200 | 200 | { |
201 | - if (! $this->_html_id) { |
|
201 | + if ( ! $this->_html_id) { |
|
202 | 202 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
203 | 203 | $this->_html_id = $this->_parent_section->html_id() |
204 | 204 | . '-' |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | public function html_id($add_pound_sign = false) |
258 | 258 | { |
259 | 259 | $this->_set_default_html_id_if_empty(); |
260 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
260 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function other_html_attributes() |
329 | 329 | { |
330 | - return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
330 | + return ! empty($this->_other_html_attributes) ? ' '.$this->_other_html_attributes : ''; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | */ |
341 | 341 | public function name() |
342 | 342 | { |
343 | - if (! $this->_construction_finalized) { |
|
343 | + if ( ! $this->_construction_finalized) { |
|
344 | 344 | throw new EE_Error(sprintf(esc_html__( |
345 | 345 | 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
346 | 346 | 'event_espresso' |
@@ -373,18 +373,18 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function form_open($action = '', $method = '', $other_attributes = '') |
375 | 375 | { |
376 | - if (! empty($action)) { |
|
376 | + if ( ! empty($action)) { |
|
377 | 377 | $this->set_action($action); |
378 | 378 | } |
379 | - if (! empty($method)) { |
|
379 | + if ( ! empty($method)) { |
|
380 | 380 | $this->set_method($method); |
381 | 381 | } |
382 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
383 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
384 | - $html .= ' action="' . $this->action() . '"'; |
|
385 | - $html .= ' method="' . $this->method() . '"'; |
|
386 | - $html .= ' name="' . $this->name() . '"'; |
|
387 | - $html .= ' ' . $other_attributes . '>'; |
|
382 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
383 | + $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : ''; |
|
384 | + $html .= ' action="'.$this->action().'"'; |
|
385 | + $html .= ' method="'.$this->method().'"'; |
|
386 | + $html .= ' name="'.$this->name().'"'; |
|
387 | + $html .= ' '.$other_attributes.'>'; |
|
388 | 388 | return $html; |
389 | 389 | } |
390 | 390 | |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $strlen = strlen($html_id); |
403 | 403 | $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
404 | 404 | ? $html_id |
405 | - : $html_id . '-frm'; |
|
405 | + : $html_id.'-frm'; |
|
406 | 406 | return $html_id; |
407 | 407 | } |
408 | 408 |
@@ -29,643 +29,643 @@ |
||
29 | 29 | abstract class FormHandler implements FormHandlerInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * will add opening and closing HTML form tags as well as a submit button |
|
34 | - */ |
|
35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | - |
|
37 | - /** |
|
38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
39 | - */ |
|
40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | - |
|
42 | - /** |
|
43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | - */ |
|
45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | - |
|
47 | - /** |
|
48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | - */ |
|
50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | - |
|
52 | - /** |
|
53 | - * if set to false, then this form has no displayable content, |
|
54 | - * and will only be used for processing data sent passed via GET or POST |
|
55 | - * defaults to true ( ie: form has displayable content ) |
|
56 | - * |
|
57 | - * @var boolean $displayable |
|
58 | - */ |
|
59 | - private $displayable = true; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $form_name |
|
63 | - */ |
|
64 | - private $form_name; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $admin_name |
|
68 | - */ |
|
69 | - private $admin_name; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $slug |
|
73 | - */ |
|
74 | - private $slug; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string $submit_btn_text |
|
78 | - */ |
|
79 | - private $submit_btn_text; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string $form_action |
|
83 | - */ |
|
84 | - private $form_action; |
|
85 | - |
|
86 | - /** |
|
87 | - * form params in key value pairs |
|
88 | - * can be added to form action URL or as hidden inputs |
|
89 | - * |
|
90 | - * @var array $form_args |
|
91 | - */ |
|
92 | - private $form_args = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * value of one of the string constant above |
|
96 | - * |
|
97 | - * @var string $form_config |
|
98 | - */ |
|
99 | - private $form_config; |
|
100 | - |
|
101 | - /** |
|
102 | - * whether or not the form was determined to be invalid |
|
103 | - * |
|
104 | - * @var boolean $form_has_errors |
|
105 | - */ |
|
106 | - private $form_has_errors; |
|
107 | - |
|
108 | - /** |
|
109 | - * the absolute top level form section being used on the page |
|
110 | - * |
|
111 | - * @var EE_Form_Section_Proper $form |
|
112 | - */ |
|
113 | - private $form; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var EE_Registry $registry |
|
117 | - */ |
|
118 | - protected $registry; |
|
119 | - |
|
120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | - /** |
|
122 | - * Form constructor. |
|
123 | - * |
|
124 | - * @param string $form_name |
|
125 | - * @param string $admin_name |
|
126 | - * @param string $slug |
|
127 | - * @param string $form_action |
|
128 | - * @param string $form_config |
|
129 | - * @param EE_Registry $registry |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $form_name, |
|
136 | - $admin_name, |
|
137 | - $slug, |
|
138 | - $form_action = '', |
|
139 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | - EE_Registry $registry |
|
141 | - ) { |
|
142 | - $this->setFormName($form_name); |
|
143 | - $this->setAdminName($admin_name); |
|
144 | - $this->setSlug($slug); |
|
145 | - $this->setFormAction($form_action); |
|
146 | - $this->setFormConfig($form_config); |
|
147 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | - $this->registry = $registry; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public static function getFormConfigConstants() |
|
156 | - { |
|
157 | - return array( |
|
158 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | - FormHandler::DO_NOT_SETUP_FORM, |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param bool $for_display |
|
168 | - * @return EE_Form_Section_Proper |
|
169 | - * @throws EE_Error |
|
170 | - * @throws LogicException |
|
171 | - */ |
|
172 | - public function form($for_display = false) |
|
173 | - { |
|
174 | - if (! $this->formIsValid()) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - if ($for_display) { |
|
178 | - $form_config = $this->formConfig(); |
|
179 | - if ( |
|
180 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
181 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
182 | - ) { |
|
183 | - $this->appendSubmitButton(); |
|
184 | - $this->clearFormButtonFloats(); |
|
185 | - } |
|
186 | - } |
|
187 | - return $this->form; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @return boolean |
|
193 | - * @throws LogicException |
|
194 | - */ |
|
195 | - public function formIsValid() |
|
196 | - { |
|
197 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
198 | - return true; |
|
199 | - } |
|
200 | - $form = apply_filters( |
|
201 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
202 | - $this->generate(), |
|
203 | - $this |
|
204 | - ); |
|
205 | - if ($this->verifyForm($form)) { |
|
206 | - $this->setForm($form); |
|
207 | - } |
|
208 | - return true; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Form_Section_Proper|null $form |
|
214 | - * @return bool |
|
215 | - * @throws LogicException |
|
216 | - */ |
|
217 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
218 | - { |
|
219 | - $form = $form !== null ? $form : $this->form; |
|
220 | - if ($form instanceof EE_Form_Section_Proper) { |
|
221 | - return true; |
|
222 | - } |
|
223 | - throw new LogicException( |
|
224 | - sprintf( |
|
225 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
226 | - $this->form_name, |
|
227 | - var_export($form, true) |
|
228 | - ) |
|
229 | - ); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @param EE_Form_Section_Proper $form |
|
235 | - */ |
|
236 | - public function setForm(EE_Form_Section_Proper $form) |
|
237 | - { |
|
238 | - $this->form = $form; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @return boolean |
|
244 | - */ |
|
245 | - public function displayable() |
|
246 | - { |
|
247 | - return $this->displayable; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @param boolean $displayable |
|
253 | - */ |
|
254 | - public function setDisplayable($displayable = false) |
|
255 | - { |
|
256 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * a public name for the form that can be displayed on the frontend of a site |
|
262 | - * |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function formName() |
|
266 | - { |
|
267 | - return $this->form_name; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $form_name |
|
273 | - * @throws InvalidDataTypeException |
|
274 | - */ |
|
275 | - public function setFormName($form_name) |
|
276 | - { |
|
277 | - if (! is_string($form_name)) { |
|
278 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
279 | - } |
|
280 | - $this->form_name = $form_name; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * a public name for the form that can be displayed, but only in the admin |
|
286 | - * |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function adminName() |
|
290 | - { |
|
291 | - return $this->admin_name; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param string $admin_name |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - */ |
|
299 | - public function setAdminName($admin_name) |
|
300 | - { |
|
301 | - if (! is_string($admin_name)) { |
|
302 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
303 | - } |
|
304 | - $this->admin_name = $admin_name; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * a URL friendly string that can be used for identifying the form |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - public function slug() |
|
314 | - { |
|
315 | - return $this->slug; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * @param string $slug |
|
321 | - * @throws InvalidDataTypeException |
|
322 | - */ |
|
323 | - public function setSlug($slug) |
|
324 | - { |
|
325 | - if (! is_string($slug)) { |
|
326 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
327 | - } |
|
328 | - $this->slug = $slug; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @return string |
|
334 | - */ |
|
335 | - public function submitBtnText() |
|
336 | - { |
|
337 | - return $this->submit_btn_text; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @param string $submit_btn_text |
|
343 | - * @throws InvalidDataTypeException |
|
344 | - * @throws InvalidArgumentException |
|
345 | - */ |
|
346 | - public function setSubmitBtnText($submit_btn_text) |
|
347 | - { |
|
348 | - if (! is_string($submit_btn_text)) { |
|
349 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
350 | - } |
|
351 | - if (empty($submit_btn_text)) { |
|
352 | - throw new InvalidArgumentException( |
|
353 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
354 | - ); |
|
355 | - } |
|
356 | - $this->submit_btn_text = $submit_btn_text; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function formAction() |
|
364 | - { |
|
365 | - return ! empty($this->form_args) |
|
366 | - ? add_query_arg($this->form_args, $this->form_action) |
|
367 | - : $this->form_action; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * @param string $form_action |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - */ |
|
375 | - public function setFormAction($form_action) |
|
376 | - { |
|
377 | - if (! is_string($form_action)) { |
|
378 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
379 | - } |
|
380 | - $this->form_action = $form_action; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @param array $form_args |
|
386 | - * @throws InvalidDataTypeException |
|
387 | - * @throws InvalidArgumentException |
|
388 | - */ |
|
389 | - public function addFormActionArgs($form_args = array()) |
|
390 | - { |
|
391 | - if (is_object($form_args)) { |
|
392 | - throw new InvalidDataTypeException( |
|
393 | - '$form_args', |
|
394 | - $form_args, |
|
395 | - 'anything other than an object was expected.' |
|
396 | - ); |
|
397 | - } |
|
398 | - if (empty($form_args)) { |
|
399 | - throw new InvalidArgumentException( |
|
400 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
401 | - ); |
|
402 | - } |
|
403 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - public function formConfig() |
|
411 | - { |
|
412 | - return $this->form_config; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $form_config |
|
418 | - * @throws DomainException |
|
419 | - */ |
|
420 | - public function setFormConfig($form_config) |
|
421 | - { |
|
422 | - if ( |
|
423 | - ! in_array( |
|
424 | - $form_config, |
|
425 | - array( |
|
426 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
427 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
428 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
429 | - FormHandler::DO_NOT_SETUP_FORM, |
|
430 | - ), |
|
431 | - true |
|
432 | - ) |
|
433 | - ) { |
|
434 | - throw new DomainException( |
|
435 | - sprintf( |
|
436 | - esc_html__( |
|
437 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
438 | - 'event_espresso' |
|
439 | - ), |
|
440 | - $form_config |
|
441 | - ) |
|
442 | - ); |
|
443 | - } |
|
444 | - $this->form_config = $form_config; |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * called after the form is instantiated |
|
450 | - * and used for performing any logic that needs to occur early |
|
451 | - * before any of the other methods are called. |
|
452 | - * returns true if everything is ok to proceed, |
|
453 | - * and false if no further form logic should be implemented |
|
454 | - * |
|
455 | - * @return boolean |
|
456 | - */ |
|
457 | - public function initialize() |
|
458 | - { |
|
459 | - $this->form_has_errors = EE_Error::has_error(true); |
|
460 | - return true; |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * used for setting up css and js |
|
466 | - * |
|
467 | - * @return void |
|
468 | - * @throws LogicException |
|
469 | - * @throws EE_Error |
|
470 | - */ |
|
471 | - public function enqueueStylesAndScripts() |
|
472 | - { |
|
473 | - $this->form()->enqueue_js(); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * creates and returns the actual form |
|
479 | - * |
|
480 | - * @return EE_Form_Section_Proper |
|
481 | - */ |
|
482 | - abstract public function generate(); |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
487 | - * |
|
488 | - * @param string $text |
|
489 | - * @return EE_Submit_Input |
|
490 | - */ |
|
491 | - public function generateSubmitButton($text = '') |
|
492 | - { |
|
493 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
494 | - return new EE_Submit_Input( |
|
495 | - array( |
|
496 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
497 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
498 | - 'html_class' => 'ee-form-submit', |
|
499 | - 'html_label' => ' ', |
|
500 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
501 | - 'default' => $text, |
|
502 | - ) |
|
503 | - ); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
509 | - * |
|
510 | - * @param string $text |
|
511 | - * @return void |
|
512 | - * @throws EE_Error |
|
513 | - */ |
|
514 | - public function appendSubmitButton($text = '') |
|
515 | - { |
|
516 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
517 | - return; |
|
518 | - } |
|
519 | - $this->form->add_subsections( |
|
520 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
521 | - null, |
|
522 | - false |
|
523 | - ); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
529 | - * |
|
530 | - * @param string $text |
|
531 | - * @return EE_Submit_Input |
|
532 | - */ |
|
533 | - public function generateCancelButton($text = '') |
|
534 | - { |
|
535 | - $cancel_button = new EE_Submit_Input( |
|
536 | - array( |
|
537 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
538 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
539 | - 'html_class' => 'ee-cancel-form', |
|
540 | - 'html_label' => ' ', |
|
541 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
542 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
543 | - ) |
|
544 | - ); |
|
545 | - $cancel_button->set_button_css_attributes(false); |
|
546 | - return $cancel_button; |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * appends a float clearing div onto end of form |
|
552 | - * |
|
553 | - * @return void |
|
554 | - * @throws EE_Error |
|
555 | - */ |
|
556 | - public function clearFormButtonFloats() |
|
557 | - { |
|
558 | - $this->form->add_subsections( |
|
559 | - array( |
|
560 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
561 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
562 | - ), |
|
563 | - ), |
|
564 | - null, |
|
565 | - false |
|
566 | - ); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
572 | - * returns a string of HTML that can be directly echoed in a template |
|
573 | - * |
|
574 | - * @return string |
|
575 | - * @throws \InvalidArgumentException |
|
576 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
577 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
578 | - * @throws LogicException |
|
579 | - * @throws EE_Error |
|
580 | - */ |
|
581 | - public function display() |
|
582 | - { |
|
583 | - $form_html = apply_filters( |
|
584 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
585 | - '' |
|
586 | - ); |
|
587 | - $form_config = $this->formConfig(); |
|
588 | - if ( |
|
589 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
590 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
591 | - ) { |
|
592 | - $additional_props = $this->requiresMultipartEnctype() |
|
593 | - ? ' enctype="multipart/form-data"' |
|
594 | - : ''; |
|
595 | - $form_html .= $this->form()->form_open( |
|
596 | - $this->formAction(), |
|
597 | - 'POST', |
|
598 | - $additional_props |
|
599 | - ); |
|
600 | - } |
|
601 | - $form_html .= $this->form(true)->get_html(); |
|
602 | - if ( |
|
603 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
604 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
605 | - ) { |
|
606 | - $form_html .= $this->form()->form_close(); |
|
607 | - } |
|
608 | - $form_html .= apply_filters( |
|
609 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
610 | - '' |
|
611 | - ); |
|
612 | - return $form_html; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
617 | - * @since 4.9.80.p |
|
618 | - * @return bool |
|
619 | - * @throws EE_Error |
|
620 | - */ |
|
621 | - public function requiresMultipartEnctype() |
|
622 | - { |
|
623 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
624 | - if ($input instanceof EE_File_Input) { |
|
625 | - return true; |
|
626 | - } |
|
627 | - } |
|
628 | - return false; |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * handles processing the form submission |
|
634 | - * returns true or false depending on whether the form was processed successfully or not |
|
635 | - * |
|
636 | - * @param array $submitted_form_data |
|
637 | - * @return array |
|
638 | - * @throws \InvalidArgumentException |
|
639 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
640 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
641 | - * @throws EE_Error |
|
642 | - * @throws LogicException |
|
643 | - * @throws InvalidFormSubmissionException |
|
644 | - */ |
|
645 | - public function process($submitted_form_data = array()) |
|
646 | - { |
|
647 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
648 | - throw new InvalidFormSubmissionException($this->form_name); |
|
649 | - } |
|
650 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
651 | - if (! $this->form()->is_valid()) { |
|
652 | - throw new InvalidFormSubmissionException( |
|
653 | - $this->form_name, |
|
654 | - sprintf( |
|
655 | - esc_html__( |
|
656 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
657 | - 'event_espresso' |
|
658 | - ), |
|
659 | - $this->form_name, |
|
660 | - '<br />', |
|
661 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
662 | - ) |
|
663 | - ); |
|
664 | - } |
|
665 | - return apply_filters( |
|
666 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
667 | - $this->form()->valid_data(), |
|
668 | - $this |
|
669 | - ); |
|
670 | - } |
|
32 | + /** |
|
33 | + * will add opening and closing HTML form tags as well as a submit button |
|
34 | + */ |
|
35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | + |
|
37 | + /** |
|
38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
39 | + */ |
|
40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | + |
|
42 | + /** |
|
43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | + */ |
|
45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | + |
|
47 | + /** |
|
48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | + */ |
|
50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | + |
|
52 | + /** |
|
53 | + * if set to false, then this form has no displayable content, |
|
54 | + * and will only be used for processing data sent passed via GET or POST |
|
55 | + * defaults to true ( ie: form has displayable content ) |
|
56 | + * |
|
57 | + * @var boolean $displayable |
|
58 | + */ |
|
59 | + private $displayable = true; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $form_name |
|
63 | + */ |
|
64 | + private $form_name; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $admin_name |
|
68 | + */ |
|
69 | + private $admin_name; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $slug |
|
73 | + */ |
|
74 | + private $slug; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string $submit_btn_text |
|
78 | + */ |
|
79 | + private $submit_btn_text; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string $form_action |
|
83 | + */ |
|
84 | + private $form_action; |
|
85 | + |
|
86 | + /** |
|
87 | + * form params in key value pairs |
|
88 | + * can be added to form action URL or as hidden inputs |
|
89 | + * |
|
90 | + * @var array $form_args |
|
91 | + */ |
|
92 | + private $form_args = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * value of one of the string constant above |
|
96 | + * |
|
97 | + * @var string $form_config |
|
98 | + */ |
|
99 | + private $form_config; |
|
100 | + |
|
101 | + /** |
|
102 | + * whether or not the form was determined to be invalid |
|
103 | + * |
|
104 | + * @var boolean $form_has_errors |
|
105 | + */ |
|
106 | + private $form_has_errors; |
|
107 | + |
|
108 | + /** |
|
109 | + * the absolute top level form section being used on the page |
|
110 | + * |
|
111 | + * @var EE_Form_Section_Proper $form |
|
112 | + */ |
|
113 | + private $form; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var EE_Registry $registry |
|
117 | + */ |
|
118 | + protected $registry; |
|
119 | + |
|
120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | + /** |
|
122 | + * Form constructor. |
|
123 | + * |
|
124 | + * @param string $form_name |
|
125 | + * @param string $admin_name |
|
126 | + * @param string $slug |
|
127 | + * @param string $form_action |
|
128 | + * @param string $form_config |
|
129 | + * @param EE_Registry $registry |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $form_name, |
|
136 | + $admin_name, |
|
137 | + $slug, |
|
138 | + $form_action = '', |
|
139 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | + EE_Registry $registry |
|
141 | + ) { |
|
142 | + $this->setFormName($form_name); |
|
143 | + $this->setAdminName($admin_name); |
|
144 | + $this->setSlug($slug); |
|
145 | + $this->setFormAction($form_action); |
|
146 | + $this->setFormConfig($form_config); |
|
147 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | + $this->registry = $registry; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public static function getFormConfigConstants() |
|
156 | + { |
|
157 | + return array( |
|
158 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | + FormHandler::DO_NOT_SETUP_FORM, |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param bool $for_display |
|
168 | + * @return EE_Form_Section_Proper |
|
169 | + * @throws EE_Error |
|
170 | + * @throws LogicException |
|
171 | + */ |
|
172 | + public function form($for_display = false) |
|
173 | + { |
|
174 | + if (! $this->formIsValid()) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + if ($for_display) { |
|
178 | + $form_config = $this->formConfig(); |
|
179 | + if ( |
|
180 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
181 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
182 | + ) { |
|
183 | + $this->appendSubmitButton(); |
|
184 | + $this->clearFormButtonFloats(); |
|
185 | + } |
|
186 | + } |
|
187 | + return $this->form; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @return boolean |
|
193 | + * @throws LogicException |
|
194 | + */ |
|
195 | + public function formIsValid() |
|
196 | + { |
|
197 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
198 | + return true; |
|
199 | + } |
|
200 | + $form = apply_filters( |
|
201 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
202 | + $this->generate(), |
|
203 | + $this |
|
204 | + ); |
|
205 | + if ($this->verifyForm($form)) { |
|
206 | + $this->setForm($form); |
|
207 | + } |
|
208 | + return true; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Form_Section_Proper|null $form |
|
214 | + * @return bool |
|
215 | + * @throws LogicException |
|
216 | + */ |
|
217 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
218 | + { |
|
219 | + $form = $form !== null ? $form : $this->form; |
|
220 | + if ($form instanceof EE_Form_Section_Proper) { |
|
221 | + return true; |
|
222 | + } |
|
223 | + throw new LogicException( |
|
224 | + sprintf( |
|
225 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
226 | + $this->form_name, |
|
227 | + var_export($form, true) |
|
228 | + ) |
|
229 | + ); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @param EE_Form_Section_Proper $form |
|
235 | + */ |
|
236 | + public function setForm(EE_Form_Section_Proper $form) |
|
237 | + { |
|
238 | + $this->form = $form; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @return boolean |
|
244 | + */ |
|
245 | + public function displayable() |
|
246 | + { |
|
247 | + return $this->displayable; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @param boolean $displayable |
|
253 | + */ |
|
254 | + public function setDisplayable($displayable = false) |
|
255 | + { |
|
256 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * a public name for the form that can be displayed on the frontend of a site |
|
262 | + * |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function formName() |
|
266 | + { |
|
267 | + return $this->form_name; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $form_name |
|
273 | + * @throws InvalidDataTypeException |
|
274 | + */ |
|
275 | + public function setFormName($form_name) |
|
276 | + { |
|
277 | + if (! is_string($form_name)) { |
|
278 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
279 | + } |
|
280 | + $this->form_name = $form_name; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * a public name for the form that can be displayed, but only in the admin |
|
286 | + * |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function adminName() |
|
290 | + { |
|
291 | + return $this->admin_name; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param string $admin_name |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + */ |
|
299 | + public function setAdminName($admin_name) |
|
300 | + { |
|
301 | + if (! is_string($admin_name)) { |
|
302 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
303 | + } |
|
304 | + $this->admin_name = $admin_name; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * a URL friendly string that can be used for identifying the form |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + public function slug() |
|
314 | + { |
|
315 | + return $this->slug; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * @param string $slug |
|
321 | + * @throws InvalidDataTypeException |
|
322 | + */ |
|
323 | + public function setSlug($slug) |
|
324 | + { |
|
325 | + if (! is_string($slug)) { |
|
326 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
327 | + } |
|
328 | + $this->slug = $slug; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @return string |
|
334 | + */ |
|
335 | + public function submitBtnText() |
|
336 | + { |
|
337 | + return $this->submit_btn_text; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @param string $submit_btn_text |
|
343 | + * @throws InvalidDataTypeException |
|
344 | + * @throws InvalidArgumentException |
|
345 | + */ |
|
346 | + public function setSubmitBtnText($submit_btn_text) |
|
347 | + { |
|
348 | + if (! is_string($submit_btn_text)) { |
|
349 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
350 | + } |
|
351 | + if (empty($submit_btn_text)) { |
|
352 | + throw new InvalidArgumentException( |
|
353 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
354 | + ); |
|
355 | + } |
|
356 | + $this->submit_btn_text = $submit_btn_text; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function formAction() |
|
364 | + { |
|
365 | + return ! empty($this->form_args) |
|
366 | + ? add_query_arg($this->form_args, $this->form_action) |
|
367 | + : $this->form_action; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * @param string $form_action |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + */ |
|
375 | + public function setFormAction($form_action) |
|
376 | + { |
|
377 | + if (! is_string($form_action)) { |
|
378 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
379 | + } |
|
380 | + $this->form_action = $form_action; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @param array $form_args |
|
386 | + * @throws InvalidDataTypeException |
|
387 | + * @throws InvalidArgumentException |
|
388 | + */ |
|
389 | + public function addFormActionArgs($form_args = array()) |
|
390 | + { |
|
391 | + if (is_object($form_args)) { |
|
392 | + throw new InvalidDataTypeException( |
|
393 | + '$form_args', |
|
394 | + $form_args, |
|
395 | + 'anything other than an object was expected.' |
|
396 | + ); |
|
397 | + } |
|
398 | + if (empty($form_args)) { |
|
399 | + throw new InvalidArgumentException( |
|
400 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
401 | + ); |
|
402 | + } |
|
403 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + public function formConfig() |
|
411 | + { |
|
412 | + return $this->form_config; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $form_config |
|
418 | + * @throws DomainException |
|
419 | + */ |
|
420 | + public function setFormConfig($form_config) |
|
421 | + { |
|
422 | + if ( |
|
423 | + ! in_array( |
|
424 | + $form_config, |
|
425 | + array( |
|
426 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
427 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
428 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
429 | + FormHandler::DO_NOT_SETUP_FORM, |
|
430 | + ), |
|
431 | + true |
|
432 | + ) |
|
433 | + ) { |
|
434 | + throw new DomainException( |
|
435 | + sprintf( |
|
436 | + esc_html__( |
|
437 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
438 | + 'event_espresso' |
|
439 | + ), |
|
440 | + $form_config |
|
441 | + ) |
|
442 | + ); |
|
443 | + } |
|
444 | + $this->form_config = $form_config; |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * called after the form is instantiated |
|
450 | + * and used for performing any logic that needs to occur early |
|
451 | + * before any of the other methods are called. |
|
452 | + * returns true if everything is ok to proceed, |
|
453 | + * and false if no further form logic should be implemented |
|
454 | + * |
|
455 | + * @return boolean |
|
456 | + */ |
|
457 | + public function initialize() |
|
458 | + { |
|
459 | + $this->form_has_errors = EE_Error::has_error(true); |
|
460 | + return true; |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * used for setting up css and js |
|
466 | + * |
|
467 | + * @return void |
|
468 | + * @throws LogicException |
|
469 | + * @throws EE_Error |
|
470 | + */ |
|
471 | + public function enqueueStylesAndScripts() |
|
472 | + { |
|
473 | + $this->form()->enqueue_js(); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * creates and returns the actual form |
|
479 | + * |
|
480 | + * @return EE_Form_Section_Proper |
|
481 | + */ |
|
482 | + abstract public function generate(); |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
487 | + * |
|
488 | + * @param string $text |
|
489 | + * @return EE_Submit_Input |
|
490 | + */ |
|
491 | + public function generateSubmitButton($text = '') |
|
492 | + { |
|
493 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
494 | + return new EE_Submit_Input( |
|
495 | + array( |
|
496 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
497 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
498 | + 'html_class' => 'ee-form-submit', |
|
499 | + 'html_label' => ' ', |
|
500 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
501 | + 'default' => $text, |
|
502 | + ) |
|
503 | + ); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
509 | + * |
|
510 | + * @param string $text |
|
511 | + * @return void |
|
512 | + * @throws EE_Error |
|
513 | + */ |
|
514 | + public function appendSubmitButton($text = '') |
|
515 | + { |
|
516 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
517 | + return; |
|
518 | + } |
|
519 | + $this->form->add_subsections( |
|
520 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
521 | + null, |
|
522 | + false |
|
523 | + ); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
529 | + * |
|
530 | + * @param string $text |
|
531 | + * @return EE_Submit_Input |
|
532 | + */ |
|
533 | + public function generateCancelButton($text = '') |
|
534 | + { |
|
535 | + $cancel_button = new EE_Submit_Input( |
|
536 | + array( |
|
537 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
538 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
539 | + 'html_class' => 'ee-cancel-form', |
|
540 | + 'html_label' => ' ', |
|
541 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
542 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
543 | + ) |
|
544 | + ); |
|
545 | + $cancel_button->set_button_css_attributes(false); |
|
546 | + return $cancel_button; |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * appends a float clearing div onto end of form |
|
552 | + * |
|
553 | + * @return void |
|
554 | + * @throws EE_Error |
|
555 | + */ |
|
556 | + public function clearFormButtonFloats() |
|
557 | + { |
|
558 | + $this->form->add_subsections( |
|
559 | + array( |
|
560 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
561 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
562 | + ), |
|
563 | + ), |
|
564 | + null, |
|
565 | + false |
|
566 | + ); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
572 | + * returns a string of HTML that can be directly echoed in a template |
|
573 | + * |
|
574 | + * @return string |
|
575 | + * @throws \InvalidArgumentException |
|
576 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
577 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
578 | + * @throws LogicException |
|
579 | + * @throws EE_Error |
|
580 | + */ |
|
581 | + public function display() |
|
582 | + { |
|
583 | + $form_html = apply_filters( |
|
584 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
585 | + '' |
|
586 | + ); |
|
587 | + $form_config = $this->formConfig(); |
|
588 | + if ( |
|
589 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
590 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
591 | + ) { |
|
592 | + $additional_props = $this->requiresMultipartEnctype() |
|
593 | + ? ' enctype="multipart/form-data"' |
|
594 | + : ''; |
|
595 | + $form_html .= $this->form()->form_open( |
|
596 | + $this->formAction(), |
|
597 | + 'POST', |
|
598 | + $additional_props |
|
599 | + ); |
|
600 | + } |
|
601 | + $form_html .= $this->form(true)->get_html(); |
|
602 | + if ( |
|
603 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
604 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
605 | + ) { |
|
606 | + $form_html .= $this->form()->form_close(); |
|
607 | + } |
|
608 | + $form_html .= apply_filters( |
|
609 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
610 | + '' |
|
611 | + ); |
|
612 | + return $form_html; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
617 | + * @since 4.9.80.p |
|
618 | + * @return bool |
|
619 | + * @throws EE_Error |
|
620 | + */ |
|
621 | + public function requiresMultipartEnctype() |
|
622 | + { |
|
623 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
624 | + if ($input instanceof EE_File_Input) { |
|
625 | + return true; |
|
626 | + } |
|
627 | + } |
|
628 | + return false; |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * handles processing the form submission |
|
634 | + * returns true or false depending on whether the form was processed successfully or not |
|
635 | + * |
|
636 | + * @param array $submitted_form_data |
|
637 | + * @return array |
|
638 | + * @throws \InvalidArgumentException |
|
639 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
640 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
641 | + * @throws EE_Error |
|
642 | + * @throws LogicException |
|
643 | + * @throws InvalidFormSubmissionException |
|
644 | + */ |
|
645 | + public function process($submitted_form_data = array()) |
|
646 | + { |
|
647 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
648 | + throw new InvalidFormSubmissionException($this->form_name); |
|
649 | + } |
|
650 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
651 | + if (! $this->form()->is_valid()) { |
|
652 | + throw new InvalidFormSubmissionException( |
|
653 | + $this->form_name, |
|
654 | + sprintf( |
|
655 | + esc_html__( |
|
656 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
657 | + 'event_espresso' |
|
658 | + ), |
|
659 | + $this->form_name, |
|
660 | + '<br />', |
|
661 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
662 | + ) |
|
663 | + ); |
|
664 | + } |
|
665 | + return apply_filters( |
|
666 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
667 | + $this->form()->valid_data(), |
|
668 | + $this |
|
669 | + ); |
|
670 | + } |
|
671 | 671 | } |
@@ -13,285 +13,285 @@ |
||
13 | 13 | class AllowedTags |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array[] |
|
18 | - */ |
|
19 | - private static $attributes = [ |
|
20 | - 'accept-charset' => 1, |
|
21 | - 'action' => 1, |
|
22 | - 'alt' => 1, |
|
23 | - 'allow' => 1, |
|
24 | - 'allowfullscreen' => 1, |
|
25 | - 'align' => 1, |
|
26 | - 'aria-*' => 1, |
|
27 | - 'autocomplete' => 1, |
|
28 | - 'bgcolor' => 1, |
|
29 | - 'border' => 1, |
|
30 | - 'cellpadding' => 1, |
|
31 | - 'cellspacing' => 1, |
|
32 | - 'checked' => 1, |
|
33 | - 'class' => 1, |
|
34 | - 'cols' => 1, |
|
35 | - 'content' => 1, |
|
36 | - 'data-*' => 1, |
|
37 | - 'dir' => 1, |
|
38 | - 'disabled' => 1, |
|
39 | - 'enctype' => 1, |
|
40 | - 'extension' => 1, |
|
41 | - 'for' => 1, |
|
42 | - 'frameborder' => 1, |
|
43 | - 'height' => 1, |
|
44 | - 'href' => 1, |
|
45 | - 'id' => 1, |
|
46 | - 'itemprop' => 1, |
|
47 | - 'itemscope' => 1, |
|
48 | - 'itemtype' => 1, |
|
49 | - 'label' => 1, |
|
50 | - 'lang' => 1, |
|
51 | - 'leftmargin' => 1, |
|
52 | - 'marginheight' => 1, |
|
53 | - 'marginwidth' => 1, |
|
54 | - 'max' => 1, |
|
55 | - 'maxlength' => 1, |
|
56 | - 'media' => 1, |
|
57 | - 'method' => 1, |
|
58 | - 'min' => 1, |
|
59 | - 'multiple' => 1, |
|
60 | - 'name' => 1, |
|
61 | - 'novalidate' => 1, |
|
62 | - 'placeholder' => 1, |
|
63 | - 'property' => 1, |
|
64 | - 'readonly' => 1, |
|
65 | - 'rel' => 1, |
|
66 | - 'required' => 1, |
|
67 | - 'rows' => 1, |
|
68 | - 'selected' => 1, |
|
69 | - 'src' => 1, |
|
70 | - 'size' => 1, |
|
71 | - 'style' => 1, |
|
72 | - 'step' => 1, |
|
73 | - 'tabindex' => 1, |
|
74 | - 'target' => 1, |
|
75 | - 'title' => 1, |
|
76 | - 'topmargin' => 1, |
|
77 | - 'type' => 1, |
|
78 | - 'value' => 1, |
|
79 | - 'width' => 1, |
|
80 | - ]; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @var array |
|
85 | - */ |
|
86 | - private static $tags = [ |
|
87 | - 'a', |
|
88 | - 'abbr', |
|
89 | - 'b', |
|
90 | - 'br', |
|
91 | - 'code', |
|
92 | - 'div', |
|
93 | - 'em', |
|
94 | - 'h1', |
|
95 | - 'h2', |
|
96 | - 'h3', |
|
97 | - 'h4', |
|
98 | - 'h5', |
|
99 | - 'h6', |
|
100 | - 'hr', |
|
101 | - 'i', |
|
102 | - 'img', |
|
103 | - 'li', |
|
104 | - 'ol', |
|
105 | - 'p', |
|
106 | - 'pre', |
|
107 | - 'small', |
|
108 | - 'span', |
|
109 | - 'strong', |
|
110 | - 'table', |
|
111 | - 'td', |
|
112 | - 'tr', |
|
113 | - 'ul', |
|
114 | - ]; |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @var array |
|
119 | - */ |
|
120 | - private static $allowed_tags; |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @var array |
|
125 | - */ |
|
126 | - private static $allowed_with_embed_tags; |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @var array |
|
131 | - */ |
|
132 | - private static $allowed_with_form_tags; |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @var array |
|
137 | - */ |
|
138 | - private static $allowed_with_script_and_style_tags; |
|
139 | - |
|
140 | - /** |
|
141 | - * @var array |
|
142 | - */ |
|
143 | - private static $allowed_with_full_tags; |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * merges additional tags and attributes into the WP post tags |
|
148 | - */ |
|
149 | - private static function initializeAllowedTags() |
|
150 | - { |
|
151 | - $allowed_post_tags = wp_kses_allowed_html('post'); |
|
152 | - $allowed_tags = []; |
|
153 | - foreach (AllowedTags::$tags as $tag) { |
|
154 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
155 | - } |
|
156 | - AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * merges embed tags and attributes into the EE all tags |
|
162 | - */ |
|
163 | - private static function initializeWithEmbedTags() |
|
164 | - { |
|
165 | - $all_tags = AllowedTags::getAllowedTags(); |
|
166 | - $embed_tags = [ |
|
167 | - 'iframe' => AllowedTags::$attributes |
|
168 | - ]; |
|
169 | - AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * merges form tags and attributes into the EE all tags |
|
175 | - */ |
|
176 | - private static function initializeWithFormTags() |
|
177 | - { |
|
178 | - $all_tags = AllowedTags::getAllowedTags(); |
|
179 | - $form_tags = [ |
|
180 | - 'form' => AllowedTags::$attributes, |
|
181 | - 'label' => AllowedTags::$attributes, |
|
182 | - 'input' => AllowedTags::$attributes, |
|
183 | - 'select' => AllowedTags::$attributes, |
|
184 | - 'option' => AllowedTags::$attributes, |
|
185 | - 'optgroup' => AllowedTags::$attributes, |
|
186 | - 'textarea' => AllowedTags::$attributes, |
|
187 | - 'button' => AllowedTags::$attributes, |
|
188 | - 'fieldset' => AllowedTags::$attributes, |
|
189 | - 'output' => AllowedTags::$attributes, |
|
190 | - ]; |
|
191 | - AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * merges form script and style tags and attributes into the EE all tags |
|
197 | - */ |
|
198 | - private static function initializeWithScriptAndStyleTags() |
|
199 | - { |
|
200 | - $all_tags = AllowedTags::getAllowedTags(); |
|
201 | - $script_and_style_tags = [ |
|
202 | - 'script' => AllowedTags::$attributes, |
|
203 | - 'style' => AllowedTags::$attributes, |
|
204 | - 'link' => AllowedTags::$attributes, |
|
205 | - 'noscript' => AllowedTags::$attributes, |
|
206 | - ]; |
|
207 | - AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * merges all head and body tags and attributes into the EE all tags |
|
212 | - */ |
|
213 | - private static function initializeWithFullTags() |
|
214 | - { |
|
215 | - $all_tags = AllowedTags::getAllowedTags(); |
|
216 | - $full_tags = [ |
|
217 | - 'script' => AllowedTags::$attributes, |
|
218 | - 'style' => AllowedTags::$attributes, |
|
219 | - 'link' => AllowedTags::$attributes, |
|
220 | - 'title' => AllowedTags::$attributes, |
|
221 | - 'meta' => AllowedTags::$attributes, |
|
222 | - 'iframe' => AllowedTags::$attributes, |
|
223 | - 'form' => AllowedTags::$attributes, |
|
224 | - 'label' => AllowedTags::$attributes, |
|
225 | - 'input' => AllowedTags::$attributes, |
|
226 | - 'select' => AllowedTags::$attributes, |
|
227 | - 'option' => AllowedTags::$attributes, |
|
228 | - 'optgroup' => AllowedTags::$attributes, |
|
229 | - 'textarea' => AllowedTags::$attributes, |
|
230 | - 'button' => AllowedTags::$attributes, |
|
231 | - 'fieldset' => AllowedTags::$attributes, |
|
232 | - 'output' => AllowedTags::$attributes, |
|
233 | - 'noscript' => AllowedTags::$attributes, |
|
234 | - ]; |
|
235 | - AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @return array[] |
|
241 | - */ |
|
242 | - public static function getAllowedTags() |
|
243 | - { |
|
244 | - if (empty(AllowedTags::$allowed_tags)) { |
|
245 | - AllowedTags::initializeAllowedTags(); |
|
246 | - } |
|
247 | - return AllowedTags::$allowed_tags; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @return array[] |
|
253 | - */ |
|
254 | - public static function getWithEmbedTags() |
|
255 | - { |
|
256 | - if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
257 | - AllowedTags::initializeWithEmbedTags(); |
|
258 | - } |
|
259 | - return AllowedTags::$allowed_with_embed_tags; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return array[] |
|
265 | - */ |
|
266 | - public static function getWithFormTags() |
|
267 | - { |
|
268 | - if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
269 | - AllowedTags::initializeWithFormTags(); |
|
270 | - } |
|
271 | - return AllowedTags::$allowed_with_form_tags; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return array[] |
|
277 | - */ |
|
278 | - public static function getWithScriptAndStyleTags() |
|
279 | - { |
|
280 | - if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
281 | - AllowedTags::initializeWithScriptAndStyleTags(); |
|
282 | - } |
|
283 | - return AllowedTags::$allowed_with_script_and_style_tags; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return array[] |
|
289 | - */ |
|
290 | - public static function getWithFullTags() |
|
291 | - { |
|
292 | - if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
293 | - AllowedTags::initializeWithFullTags(); |
|
294 | - } |
|
295 | - return AllowedTags::$allowed_with_full_tags; |
|
296 | - } |
|
16 | + /** |
|
17 | + * @var array[] |
|
18 | + */ |
|
19 | + private static $attributes = [ |
|
20 | + 'accept-charset' => 1, |
|
21 | + 'action' => 1, |
|
22 | + 'alt' => 1, |
|
23 | + 'allow' => 1, |
|
24 | + 'allowfullscreen' => 1, |
|
25 | + 'align' => 1, |
|
26 | + 'aria-*' => 1, |
|
27 | + 'autocomplete' => 1, |
|
28 | + 'bgcolor' => 1, |
|
29 | + 'border' => 1, |
|
30 | + 'cellpadding' => 1, |
|
31 | + 'cellspacing' => 1, |
|
32 | + 'checked' => 1, |
|
33 | + 'class' => 1, |
|
34 | + 'cols' => 1, |
|
35 | + 'content' => 1, |
|
36 | + 'data-*' => 1, |
|
37 | + 'dir' => 1, |
|
38 | + 'disabled' => 1, |
|
39 | + 'enctype' => 1, |
|
40 | + 'extension' => 1, |
|
41 | + 'for' => 1, |
|
42 | + 'frameborder' => 1, |
|
43 | + 'height' => 1, |
|
44 | + 'href' => 1, |
|
45 | + 'id' => 1, |
|
46 | + 'itemprop' => 1, |
|
47 | + 'itemscope' => 1, |
|
48 | + 'itemtype' => 1, |
|
49 | + 'label' => 1, |
|
50 | + 'lang' => 1, |
|
51 | + 'leftmargin' => 1, |
|
52 | + 'marginheight' => 1, |
|
53 | + 'marginwidth' => 1, |
|
54 | + 'max' => 1, |
|
55 | + 'maxlength' => 1, |
|
56 | + 'media' => 1, |
|
57 | + 'method' => 1, |
|
58 | + 'min' => 1, |
|
59 | + 'multiple' => 1, |
|
60 | + 'name' => 1, |
|
61 | + 'novalidate' => 1, |
|
62 | + 'placeholder' => 1, |
|
63 | + 'property' => 1, |
|
64 | + 'readonly' => 1, |
|
65 | + 'rel' => 1, |
|
66 | + 'required' => 1, |
|
67 | + 'rows' => 1, |
|
68 | + 'selected' => 1, |
|
69 | + 'src' => 1, |
|
70 | + 'size' => 1, |
|
71 | + 'style' => 1, |
|
72 | + 'step' => 1, |
|
73 | + 'tabindex' => 1, |
|
74 | + 'target' => 1, |
|
75 | + 'title' => 1, |
|
76 | + 'topmargin' => 1, |
|
77 | + 'type' => 1, |
|
78 | + 'value' => 1, |
|
79 | + 'width' => 1, |
|
80 | + ]; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @var array |
|
85 | + */ |
|
86 | + private static $tags = [ |
|
87 | + 'a', |
|
88 | + 'abbr', |
|
89 | + 'b', |
|
90 | + 'br', |
|
91 | + 'code', |
|
92 | + 'div', |
|
93 | + 'em', |
|
94 | + 'h1', |
|
95 | + 'h2', |
|
96 | + 'h3', |
|
97 | + 'h4', |
|
98 | + 'h5', |
|
99 | + 'h6', |
|
100 | + 'hr', |
|
101 | + 'i', |
|
102 | + 'img', |
|
103 | + 'li', |
|
104 | + 'ol', |
|
105 | + 'p', |
|
106 | + 'pre', |
|
107 | + 'small', |
|
108 | + 'span', |
|
109 | + 'strong', |
|
110 | + 'table', |
|
111 | + 'td', |
|
112 | + 'tr', |
|
113 | + 'ul', |
|
114 | + ]; |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @var array |
|
119 | + */ |
|
120 | + private static $allowed_tags; |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @var array |
|
125 | + */ |
|
126 | + private static $allowed_with_embed_tags; |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @var array |
|
131 | + */ |
|
132 | + private static $allowed_with_form_tags; |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @var array |
|
137 | + */ |
|
138 | + private static $allowed_with_script_and_style_tags; |
|
139 | + |
|
140 | + /** |
|
141 | + * @var array |
|
142 | + */ |
|
143 | + private static $allowed_with_full_tags; |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * merges additional tags and attributes into the WP post tags |
|
148 | + */ |
|
149 | + private static function initializeAllowedTags() |
|
150 | + { |
|
151 | + $allowed_post_tags = wp_kses_allowed_html('post'); |
|
152 | + $allowed_tags = []; |
|
153 | + foreach (AllowedTags::$tags as $tag) { |
|
154 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
155 | + } |
|
156 | + AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * merges embed tags and attributes into the EE all tags |
|
162 | + */ |
|
163 | + private static function initializeWithEmbedTags() |
|
164 | + { |
|
165 | + $all_tags = AllowedTags::getAllowedTags(); |
|
166 | + $embed_tags = [ |
|
167 | + 'iframe' => AllowedTags::$attributes |
|
168 | + ]; |
|
169 | + AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * merges form tags and attributes into the EE all tags |
|
175 | + */ |
|
176 | + private static function initializeWithFormTags() |
|
177 | + { |
|
178 | + $all_tags = AllowedTags::getAllowedTags(); |
|
179 | + $form_tags = [ |
|
180 | + 'form' => AllowedTags::$attributes, |
|
181 | + 'label' => AllowedTags::$attributes, |
|
182 | + 'input' => AllowedTags::$attributes, |
|
183 | + 'select' => AllowedTags::$attributes, |
|
184 | + 'option' => AllowedTags::$attributes, |
|
185 | + 'optgroup' => AllowedTags::$attributes, |
|
186 | + 'textarea' => AllowedTags::$attributes, |
|
187 | + 'button' => AllowedTags::$attributes, |
|
188 | + 'fieldset' => AllowedTags::$attributes, |
|
189 | + 'output' => AllowedTags::$attributes, |
|
190 | + ]; |
|
191 | + AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * merges form script and style tags and attributes into the EE all tags |
|
197 | + */ |
|
198 | + private static function initializeWithScriptAndStyleTags() |
|
199 | + { |
|
200 | + $all_tags = AllowedTags::getAllowedTags(); |
|
201 | + $script_and_style_tags = [ |
|
202 | + 'script' => AllowedTags::$attributes, |
|
203 | + 'style' => AllowedTags::$attributes, |
|
204 | + 'link' => AllowedTags::$attributes, |
|
205 | + 'noscript' => AllowedTags::$attributes, |
|
206 | + ]; |
|
207 | + AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * merges all head and body tags and attributes into the EE all tags |
|
212 | + */ |
|
213 | + private static function initializeWithFullTags() |
|
214 | + { |
|
215 | + $all_tags = AllowedTags::getAllowedTags(); |
|
216 | + $full_tags = [ |
|
217 | + 'script' => AllowedTags::$attributes, |
|
218 | + 'style' => AllowedTags::$attributes, |
|
219 | + 'link' => AllowedTags::$attributes, |
|
220 | + 'title' => AllowedTags::$attributes, |
|
221 | + 'meta' => AllowedTags::$attributes, |
|
222 | + 'iframe' => AllowedTags::$attributes, |
|
223 | + 'form' => AllowedTags::$attributes, |
|
224 | + 'label' => AllowedTags::$attributes, |
|
225 | + 'input' => AllowedTags::$attributes, |
|
226 | + 'select' => AllowedTags::$attributes, |
|
227 | + 'option' => AllowedTags::$attributes, |
|
228 | + 'optgroup' => AllowedTags::$attributes, |
|
229 | + 'textarea' => AllowedTags::$attributes, |
|
230 | + 'button' => AllowedTags::$attributes, |
|
231 | + 'fieldset' => AllowedTags::$attributes, |
|
232 | + 'output' => AllowedTags::$attributes, |
|
233 | + 'noscript' => AllowedTags::$attributes, |
|
234 | + ]; |
|
235 | + AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @return array[] |
|
241 | + */ |
|
242 | + public static function getAllowedTags() |
|
243 | + { |
|
244 | + if (empty(AllowedTags::$allowed_tags)) { |
|
245 | + AllowedTags::initializeAllowedTags(); |
|
246 | + } |
|
247 | + return AllowedTags::$allowed_tags; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @return array[] |
|
253 | + */ |
|
254 | + public static function getWithEmbedTags() |
|
255 | + { |
|
256 | + if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
257 | + AllowedTags::initializeWithEmbedTags(); |
|
258 | + } |
|
259 | + return AllowedTags::$allowed_with_embed_tags; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return array[] |
|
265 | + */ |
|
266 | + public static function getWithFormTags() |
|
267 | + { |
|
268 | + if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
269 | + AllowedTags::initializeWithFormTags(); |
|
270 | + } |
|
271 | + return AllowedTags::$allowed_with_form_tags; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return array[] |
|
277 | + */ |
|
278 | + public static function getWithScriptAndStyleTags() |
|
279 | + { |
|
280 | + if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
281 | + AllowedTags::initializeWithScriptAndStyleTags(); |
|
282 | + } |
|
283 | + return AllowedTags::$allowed_with_script_and_style_tags; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return array[] |
|
289 | + */ |
|
290 | + public static function getWithFullTags() |
|
291 | + { |
|
292 | + if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
293 | + AllowedTags::initializeWithFullTags(); |
|
294 | + } |
|
295 | + return AllowedTags::$allowed_with_full_tags; |
|
296 | + } |
|
297 | 297 | } |