@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | <p class="spco-copy-all-attendee-pg"> |
| 13 | 13 | <label class="ee-checkbox-label-before ee-checkbox-label-wide"> |
| 14 | 14 | <?php esc_html_e( |
| 15 | - 'Use Attendee #1\'s information for ALL attendees', |
|
| 16 | - 'event_espresso' |
|
| 17 | - ); ?> |
|
| 15 | + 'Use Attendee #1\'s information for ALL attendees', |
|
| 16 | + 'event_espresso' |
|
| 17 | + ); ?> |
|
| 18 | 18 | <input class='spco-copy-all-attendee-chk ee-do-not-validate' |
| 19 | 19 | id="spco-copy-all-attendee-chk" |
| 20 | 20 | type="checkbox" |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | <p class="spco-copy-attendee-pg"> |
| 27 | 27 | <?php echo apply_filters( |
| 28 | - 'FHEE__registration_page_attendee_information__copy_attendee_pg', |
|
| 29 | - sprintf( |
|
| 30 | - esc_html__( |
|
| 31 | - 'This option allows you to use the above information for all additional attendee question fields. %sPlease note:%s some events may have additional questions that you may still be required to answer in order to complete your registration.', |
|
| 32 | - 'event_espresso' |
|
| 33 | - ), |
|
| 34 | - '<strong>', |
|
| 35 | - '</strong>' |
|
| 36 | - ) |
|
| 37 | - ); ?></p> |
|
| 28 | + 'FHEE__registration_page_attendee_information__copy_attendee_pg', |
|
| 29 | + sprintf( |
|
| 30 | + esc_html__( |
|
| 31 | + 'This option allows you to use the above information for all additional attendee question fields. %sPlease note:%s some events may have additional questions that you may still be required to answer in order to complete your registration.', |
|
| 32 | + 'event_espresso' |
|
| 33 | + ), |
|
| 34 | + '<strong>', |
|
| 35 | + '</strong>' |
|
| 36 | + ) |
|
| 37 | + ); ?></p> |
|
| 38 | 38 | |
| 39 | 39 | <a class='display-the-hidden smaller-text float-right' |
| 40 | 40 | id="display-more-attendee-copy-options" |
@@ -54,15 +54,15 @@ discard block |
||
| 54 | 54 | <div id="more-attendee-copy-options-dv" class="" style="display: none;"> |
| 55 | 55 | <p class="spco-copy-attendee-pg"> |
| 56 | 56 | <?php esc_html_e( |
| 57 | - 'Only copy the above information to the following selected additional attendees.', |
|
| 58 | - 'event_espresso' |
|
| 59 | - ); ?> |
|
| 57 | + 'Only copy the above information to the following selected additional attendees.', |
|
| 58 | + 'event_espresso' |
|
| 59 | + ); ?> |
|
| 60 | 60 | </p> |
| 61 | 61 | |
| 62 | 62 | <?php |
| 63 | - foreach ($spco_copy_attendee_chk as $spco_copy_chk) { |
|
| 64 | - echo wp_kses($spco_copy_chk, AllowedTags::getWithFormTags()); |
|
| 65 | - } ?> |
|
| 63 | + foreach ($spco_copy_attendee_chk as $spco_copy_chk) { |
|
| 64 | + echo wp_kses($spco_copy_chk, AllowedTags::getWithFormTags()); |
|
| 65 | + } ?> |
|
| 66 | 66 | |
| 67 | 67 | </div> |
| 68 | 68 | <div class="clear-float"></div> |
@@ -14,16 +14,16 @@ discard block |
||
| 14 | 14 | <?php if (! is_admin()) : ?> |
| 15 | 15 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 16 | 16 | <?php echo apply_filters( |
| 17 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
| 18 | - sprintf( |
|
| 19 | - esc_html__( |
|
| 20 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
| 21 | - 'event_espresso' |
|
| 22 | - ), |
|
| 23 | - '<br />', |
|
| 24 | - '<span class="asterisk">*</span>' |
|
| 25 | - ) |
|
| 26 | - ); ?> |
|
| 17 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
| 18 | + sprintf( |
|
| 19 | + esc_html__( |
|
| 20 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
| 21 | + 'event_espresso' |
|
| 22 | + ), |
|
| 23 | + '<br />', |
|
| 24 | + '<span class="asterisk">*</span>' |
|
| 25 | + ) |
|
| 26 | + ); ?> |
|
| 27 | 27 | </p> |
| 28 | 28 | <?php endif; ?> |
| 29 | 29 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | $prev_ticket = 0; |
| 34 | 34 | |
| 35 | 35 | if (count($registrations) > 0) { |
| 36 | - $ticketID = esc_attr(key($template_args['ticket_count'])); |
|
| 37 | - ?> |
|
| 36 | + $ticketID = esc_attr(key($template_args['ticket_count'])); |
|
| 37 | + ?> |
|
| 38 | 38 | |
| 39 | 39 | <div id="spco-attendee-panel-dv-<?php echo esc_attr($ticketID); ?>" |
| 40 | 40 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo sanitize_html_class($ticketID); ?>" |
@@ -62,37 +62,37 @@ discard block |
||
| 62 | 62 | </thead> |
| 63 | 63 | <tbody> |
| 64 | 64 | <?php |
| 65 | - // Store previous values to avoid duplicated rows. |
|
| 66 | - $prev_ticket = 0; |
|
| 67 | - // Display all tickets inside. |
|
| 68 | - foreach ($registrations as $registration) { |
|
| 69 | - if ($registration instanceof EE_Registration) { |
|
| 70 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 71 | - echo wp_kses($ticket_line_item[ $registration->ticket()->ID() ], AllowedTags::getWithFormTags()); |
|
| 72 | - } |
|
| 65 | + // Store previous values to avoid duplicated rows. |
|
| 66 | + $prev_ticket = 0; |
|
| 67 | + // Display all tickets inside. |
|
| 68 | + foreach ($registrations as $registration) { |
|
| 69 | + if ($registration instanceof EE_Registration) { |
|
| 70 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 71 | + echo wp_kses($ticket_line_item[ $registration->ticket()->ID() ], AllowedTags::getWithFormTags()); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $prev_ticket = $registration->ticket()->ID(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - ?> |
|
| 74 | + $prev_ticket = $registration->ticket()->ID(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + ?> |
|
| 78 | 78 | </tbody> |
| 79 | 79 | </table> |
| 80 | 80 | </div><!-- close spco-ticket-info-dv --> |
| 81 | 81 | |
| 82 | 82 | <?php |
| 83 | - // Display the forms below the table. |
|
| 84 | - foreach ($registrations as $registration) { |
|
| 85 | - if ($registration instanceof EE_Registration) { |
|
| 86 | - // Attendee Questions. |
|
| 87 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
| 88 | - echo wp_kses(${$reg_form}, AllowedTags::getWithFormTags()); |
|
| 89 | - } // if ( $registration instanceof EE_Registration ) |
|
| 90 | - } // end foreach ( $registrations as $registration ) |
|
| 83 | + // Display the forms below the table. |
|
| 84 | + foreach ($registrations as $registration) { |
|
| 85 | + if ($registration instanceof EE_Registration) { |
|
| 86 | + // Attendee Questions. |
|
| 87 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
| 88 | + echo wp_kses(${$reg_form}, AllowedTags::getWithFormTags()); |
|
| 89 | + } // if ( $registration instanceof EE_Registration ) |
|
| 90 | + } // end foreach ( $registrations as $registration ) |
|
| 91 | 91 | |
| 92 | - ?> |
|
| 92 | + ?> |
|
| 93 | 93 | </div><!-- close spco-attendee-panel-dv --> |
| 94 | 94 | <?php |
| 95 | - echo wp_kses($default_hidden_inputs, AllowedTags::getWithFormTags()); |
|
| 95 | + echo wp_kses($default_hidden_inputs, AllowedTags::getWithFormTags()); |
|
| 96 | 96 | } // end if ( count( $registrations ) > 0 ) |
| 97 | 97 | |
| 98 | 98 | ?> |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 12 | 12 | |
| 13 | 13 | ?> |
| 14 | -<?php if (! is_admin()) : ?> |
|
| 14 | +<?php if ( ! is_admin()) : ?> |
|
| 15 | 15 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 16 | 16 | <?php echo apply_filters( |
| 17 | 17 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | foreach ($registrations as $registration) { |
| 61 | 61 | if ($registration instanceof EE_Registration) { |
| 62 | 62 | if ($registration->ticket()->ID() !== $prev_ticket) { |
| 63 | - echo wp_kses($ticket_line_item[ $registration->ticket()->ID() ], AllowedTags::getWithFormTags()); |
|
| 63 | + echo wp_kses($ticket_line_item[$registration->ticket()->ID()], AllowedTags::getWithFormTags()); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $prev_ticket = $registration->ticket()->ID(); |
@@ -13,16 +13,16 @@ discard block |
||
| 13 | 13 | <?php if (! is_admin()) : ?> |
| 14 | 14 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 15 | 15 | <?php echo apply_filters( |
| 16 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
| 17 | - sprintf( |
|
| 18 | - esc_html__( |
|
| 19 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
| 20 | - 'event_espresso' |
|
| 21 | - ), |
|
| 22 | - '<br />', |
|
| 23 | - '<span class="asterisk">*</span>' |
|
| 24 | - ) |
|
| 25 | - ); ?> |
|
| 16 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
| 17 | + sprintf( |
|
| 18 | + esc_html__( |
|
| 19 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
| 20 | + 'event_espresso' |
|
| 21 | + ), |
|
| 22 | + '<br />', |
|
| 23 | + '<span class="asterisk">*</span>' |
|
| 24 | + ) |
|
| 25 | + ); ?> |
|
| 26 | 26 | </p> |
| 27 | 27 | <?php endif; ?> |
| 28 | 28 | |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | $prev_ticket = 0; |
| 33 | 33 | |
| 34 | 34 | if (count($registrations) > 0) { |
| 35 | - foreach ($registrations as $registration) { |
|
| 36 | - if ($registration instanceof EE_Registration) { |
|
| 37 | - $att_nmbr++; |
|
| 38 | - ?> |
|
| 35 | + foreach ($registrations as $registration) { |
|
| 36 | + if ($registration instanceof EE_Registration) { |
|
| 37 | + $att_nmbr++; |
|
| 38 | + ?> |
|
| 39 | 39 | |
| 40 | 40 | <div id="spco-attendee-panel-dv-<?php echo esc_url_raw($registration->reg_url_link()); ?>" |
| 41 | 41 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo esc_attr($registration->ticket()->ID()); |
| 42 | - ?>" |
|
| 42 | + ?>" |
|
| 43 | 43 | > |
| 44 | 44 | |
| 45 | 45 | <?php if (! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
@@ -81,19 +81,19 @@ discard block |
||
| 81 | 81 | <?php } ?> |
| 82 | 82 | |
| 83 | 83 | <?php |
| 84 | - // ATTENDEE QUESTIONS |
|
| 85 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
| 86 | - echo wp_kses(${$reg_form}, AllowedTags::getWithFormTags()); |
|
| 87 | - ?> |
|
| 84 | + // ATTENDEE QUESTIONS |
|
| 85 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
| 86 | + echo wp_kses(${$reg_form}, AllowedTags::getWithFormTags()); |
|
| 87 | + ?> |
|
| 88 | 88 | |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - $prev_event = $registration->event()->ID(); |
|
| 92 | - $prev_ticket = $registration->ticket()->ID(); |
|
| 93 | - } // if ( $registration instanceof EE_Registration ) |
|
| 94 | - } // end foreach ( $registrations as $registration ) |
|
| 91 | + $prev_event = $registration->event()->ID(); |
|
| 92 | + $prev_ticket = $registration->ticket()->ID(); |
|
| 93 | + } // if ( $registration instanceof EE_Registration ) |
|
| 94 | + } // end foreach ( $registrations as $registration ) |
|
| 95 | 95 | |
| 96 | - echo wp_kses($default_hidden_inputs, AllowedTags::getWithFormTags()); |
|
| 96 | + echo wp_kses($default_hidden_inputs, AllowedTags::getWithFormTags()); |
|
| 97 | 97 | } // end if ( count( $registrations ) > 0 ) |
| 98 | 98 | |
| 99 | 99 | ?> |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 11 | 11 | |
| 12 | 12 | ?> |
| 13 | -<?php if (! is_admin()) : ?> |
|
| 13 | +<?php if ( ! is_admin()) : ?> |
|
| 14 | 14 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 15 | 15 | <?php echo apply_filters( |
| 16 | 16 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | ?>" |
| 43 | 43 | > |
| 44 | 44 | |
| 45 | - <?php if (! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
| 45 | + <?php if ( ! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
| 46 | 46 | <h4 id="event_title-<?php echo esc_attr($registration->event()->ID()) ?>" |
| 47 | 47 | class="big-event-title-hdr" |
| 48 | 48 | > |
| 49 | 49 | <?php echo esc_html($registration->event()->name()); ?> |
| 50 | 50 | </h4> |
| 51 | 51 | <?php } ?> |
| 52 | - <?php if (! $revisit && $registration->ticket()->ID() !== $prev_ticket) { ?> |
|
| 52 | + <?php if ( ! $revisit && $registration->ticket()->ID() !== $prev_ticket) { ?> |
|
| 53 | 53 | <div class="spco-ticket-info-dv"> |
| 54 | 54 | <table class="spco-ticket-details"> |
| 55 | 55 | <thead> |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | </tr> |
| 68 | 68 | </thead> |
| 69 | 69 | <tbody> |
| 70 | - <?php echo wp_kses($ticket_line_item[ $registration->ticket()->ID() ], AllowedTags::getWithFormTags()); ?> |
|
| 70 | + <?php echo wp_kses($ticket_line_item[$registration->ticket()->ID()], AllowedTags::getWithFormTags()); ?> |
|
| 71 | 71 | </tbody> |
| 72 | 72 | </table> |
| 73 | 73 | </div> |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | <div id="espresso-thank-you-page-payment-details-dv"> |
| 18 | 18 | <?php |
| 19 | - if (! empty($payments)) { ?> |
|
| 19 | + if (! empty($payments)) { ?> |
|
| 20 | 20 | <table class="ee-table"> |
| 21 | 21 | <thead> |
| 22 | 22 | <tr> |
@@ -36,37 +36,37 @@ discard block |
||
| 36 | 36 | </thead> |
| 37 | 37 | <tbody> |
| 38 | 38 | <?php |
| 39 | - foreach ($payments as $payment) { |
|
| 40 | - echo wp_kses($payment, AllowedTags::getWithFormTags()); |
|
| 41 | - } |
|
| 42 | - ?> |
|
| 39 | + foreach ($payments as $payment) { |
|
| 40 | + echo wp_kses($payment, AllowedTags::getWithFormTags()); |
|
| 41 | + } |
|
| 42 | + ?> |
|
| 43 | 43 | </tbody> |
| 44 | 44 | </table> |
| 45 | 45 | <?php |
| 46 | - } else { |
|
| 47 | - if ($transaction->total()) { |
|
| 48 | - echo apply_filters( |
|
| 49 | - 'FHEE__payment_overview_template__no_payments_made', |
|
| 50 | - sprintf( |
|
| 51 | - esc_html__('%sNo payments towards this transaction have been received.%s', 'event_espresso'), |
|
| 52 | - '<p class="important-notice">', |
|
| 53 | - '</p>' |
|
| 54 | - ) |
|
| 55 | - ); |
|
| 56 | - do_action('AHEE__thank_you_page_payment_details_template__no_payments_made', $transaction); |
|
| 57 | - } else { |
|
| 58 | - echo apply_filters( |
|
| 59 | - 'FHEE__payment_overview_template__no_payment_required', |
|
| 60 | - sprintf( |
|
| 61 | - esc_html__('%sNo payment is required for this transaction.%s', 'event_espresso'), |
|
| 62 | - '<p>', |
|
| 63 | - '</p>' |
|
| 64 | - ) |
|
| 65 | - ); |
|
| 66 | - do_action('AHEE__thank_you_page_payment_details_template__no_payment_required'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - echo wp_kses($gateway_content, AllowedTags::getWithFormTags()); |
|
| 70 | - do_action('AHEE__thank_you_page_payment_details_template__after_gateway_content', $gateway_content); |
|
| 71 | - echo '<br/>'; |
|
| 72 | - do_action('AHEE__thank_you_page_payment_details_template__after_payment_details'); |
|
| 46 | + } else { |
|
| 47 | + if ($transaction->total()) { |
|
| 48 | + echo apply_filters( |
|
| 49 | + 'FHEE__payment_overview_template__no_payments_made', |
|
| 50 | + sprintf( |
|
| 51 | + esc_html__('%sNo payments towards this transaction have been received.%s', 'event_espresso'), |
|
| 52 | + '<p class="important-notice">', |
|
| 53 | + '</p>' |
|
| 54 | + ) |
|
| 55 | + ); |
|
| 56 | + do_action('AHEE__thank_you_page_payment_details_template__no_payments_made', $transaction); |
|
| 57 | + } else { |
|
| 58 | + echo apply_filters( |
|
| 59 | + 'FHEE__payment_overview_template__no_payment_required', |
|
| 60 | + sprintf( |
|
| 61 | + esc_html__('%sNo payment is required for this transaction.%s', 'event_espresso'), |
|
| 62 | + '<p>', |
|
| 63 | + '</p>' |
|
| 64 | + ) |
|
| 65 | + ); |
|
| 66 | + do_action('AHEE__thank_you_page_payment_details_template__no_payment_required'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + echo wp_kses($gateway_content, AllowedTags::getWithFormTags()); |
|
| 70 | + do_action('AHEE__thank_you_page_payment_details_template__after_gateway_content', $gateway_content); |
|
| 71 | + echo '<br/>'; |
|
| 72 | + do_action('AHEE__thank_you_page_payment_details_template__after_payment_details'); |
|
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function __construct($routing = true) |
| 22 | 22 | { |
| 23 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
| 24 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
| 25 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
| 27 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 23 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form/'); |
|
| 24 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets/'); |
|
| 25 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
| 26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates/'); |
|
| 27 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
| 28 | 28 | parent::__construct($routing); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | { |
| 359 | 359 | wp_register_script( |
| 360 | 360 | 'ee-question-sortable', |
| 361 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 361 | + REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', |
|
| 362 | 362 | array('jquery-ui-sortable'), |
| 363 | 363 | EVENT_ESPRESSO_VERSION, |
| 364 | 364 | true |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | protected function _questions_overview_list_table() |
| 448 | 448 | { |
| 449 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 449 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 450 | 450 | 'add_question', |
| 451 | 451 | 'add_question', |
| 452 | 452 | array(), |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | protected function _question_groups_overview_list_table() |
| 468 | 468 | { |
| 469 | 469 | $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
| 470 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 470 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 471 | 471 | 'add_question_group', |
| 472 | 472 | 'add_question_group', |
| 473 | 473 | array(), |
@@ -529,18 +529,18 @@ discard block |
||
| 529 | 529 | { |
| 530 | 530 | $success = 0; |
| 531 | 531 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 532 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 532 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 533 | 533 | // if array has more than one element than success message should be plural |
| 534 | 534 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 535 | 535 | // cycle thru bulk action checkboxes |
| 536 | 536 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
| 537 | - if (! $this->_delete_item($ID, $model)) { |
|
| 537 | + if ( ! $this->_delete_item($ID, $model)) { |
|
| 538 | 538 | $success = 0; |
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 541 | + } elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
| 542 | 542 | $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
| 543 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 543 | + } elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
| 544 | 544 | $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
| 545 | 545 | } else { |
| 546 | 546 | EE_Error::add_error( |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
| 610 | 610 | } |
| 611 | 611 | // add ID to title if editing |
| 612 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 612 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 613 | 613 | if ($ID) { |
| 614 | 614 | /** @var EE_Question_Group $questionGroup */ |
| 615 | 615 | $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
| 630 | 630 | $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
| 631 | 631 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 632 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 632 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', |
|
| 633 | 633 | $this->_template_args, |
| 634 | 634 | true |
| 635 | 635 | ); |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | // make sure identifier is unique |
| 674 | 674 | $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
| 675 | 675 | $where_values = ['QSG_identifier' => $set_column_values['QSG_identifier']]; |
| 676 | - if (! $new_question_group && isset($set_column_values['QSG_ID'])) { |
|
| 676 | + if ( ! $new_question_group && isset($set_column_values['QSG_ID'])) { |
|
| 677 | 677 | $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']]; |
| 678 | 678 | } |
| 679 | 679 | $identifier_exists = ! empty($identifier_value) |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | // update the existing related questions |
| 714 | 714 | // BUT FIRST... delete the phone question from the Question_Group_Question |
| 715 | 715 | // if it is being added to this question group (therefore removed from the existing group) |
| 716 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 716 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
| 717 | 717 | // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
| 718 | 718 | EEM_Question_Group_Question::instance()->delete( |
| 719 | 719 | array( |
@@ -728,22 +728,22 @@ discard block |
||
| 728 | 728 | $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
| 729 | 729 | $questions = $question_group->questions(); |
| 730 | 730 | // make sure system phone question is added to list of questions for this group |
| 731 | - if (! isset($questions[ $phone_question_id ])) { |
|
| 732 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 731 | + if ( ! isset($questions[$phone_question_id])) { |
|
| 732 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | foreach ($questions as $question_ID => $question) { |
| 736 | 736 | // first we always check for order. |
| 737 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 737 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 738 | 738 | // update question order |
| 739 | 739 | $question_group->update_question_order( |
| 740 | 740 | $question_ID, |
| 741 | - $this->_req_data['question_orders'][ $question_ID ] |
|
| 741 | + $this->_req_data['question_orders'][$question_ID] |
|
| 742 | 742 | ); |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | // then we always check if adding or removing. |
| 746 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 746 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
| 747 | 747 | $question_group->add_question($question_ID); |
| 748 | 748 | } else { |
| 749 | 749 | // not found, remove it (but only if not a system question for the personal group |
@@ -766,8 +766,8 @@ discard block |
||
| 766 | 766 | if (isset($this->_req_data['questions'])) { |
| 767 | 767 | foreach ($this->_req_data['questions'] as $QST_ID) { |
| 768 | 768 | $question_group->add_question($QST_ID); |
| 769 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 770 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 769 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
| 770 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | 773 | } |
@@ -908,33 +908,33 @@ discard block |
||
| 908 | 908 | // echo "trash $trash"; |
| 909 | 909 | // var_dump($this->_req_data['checkbox']);die; |
| 910 | 910 | if (isset($this->_req_data['checkbox'])) { |
| 911 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 911 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 912 | 912 | // if array has more than one element than success message should be plural |
| 913 | 913 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 914 | 914 | // cycle thru bulk action checkboxes |
| 915 | 915 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
| 916 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 916 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 917 | 917 | $success = 0; |
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | } else { |
| 921 | 921 | // grab single id and delete |
| 922 | 922 | $ID = absint($this->_req_data['checkbox']); |
| 923 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 923 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 924 | 924 | $success = 0; |
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | } else { |
| 928 | 928 | // delete via trash link |
| 929 | 929 | // grab single id and delete |
| 930 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 931 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 930 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
| 931 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 932 | 932 | $success = 0; |
| 933 | 933 | } |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | |
| 937 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 937 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; // strtolower( $model->item_name(2) ); |
|
| 938 | 938 | // echo "action :$action"; |
| 939 | 939 | // $action = 'questions' ? 'default' : $action; |
| 940 | 940 | if ($trash) { |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | ? (int) $this->_req_data['curpage'] |
| 1055 | 1055 | : null; |
| 1056 | 1056 | |
| 1057 | - if (! empty($row_ids)) { |
|
| 1057 | + if ( ! empty($row_ids)) { |
|
| 1058 | 1058 | // figure out where we start the row_id count at for the current page. |
| 1059 | 1059 | $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
| 1060 | 1060 | |
@@ -1063,7 +1063,7 @@ discard block |
||
| 1063 | 1063 | // Update the questions when re-ordering |
| 1064 | 1064 | $updated = EEM_Question_Group::instance()->update( |
| 1065 | 1065 | array('QSG_order' => $qsgcount), |
| 1066 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1066 | + array(array('QSG_ID' => $row_ids[$i])) |
|
| 1067 | 1067 | ); |
| 1068 | 1068 | if ($updated === false) { |
| 1069 | 1069 | $success = false; |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | $this->_set_add_edit_form_tags('update_reg_form_settings'); |
| 1115 | 1115 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 1116 | 1116 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 1117 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1117 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', |
|
| 1118 | 1118 | $this->_template_args, |
| 1119 | 1119 | true |
| 1120 | 1120 | ); |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | $prev_email_validation_level = 'basic'; |
| 1361 | 1361 | } |
| 1362 | 1362 | // confirm our i18n email validation will work on the server |
| 1363 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1363 | + if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1364 | 1364 | // or reset email validation level to previous value |
| 1365 | 1365 | $email_validation_level = $prev_email_validation_level; |
| 1366 | 1366 | } |
@@ -1406,7 +1406,7 @@ discard block |
||
| 1406 | 1406 | private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
| 1407 | 1407 | { |
| 1408 | 1408 | // first check that PCRE is enabled |
| 1409 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1409 | + if ( ! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1410 | 1410 | EE_Error::add_error( |
| 1411 | 1411 | sprintf( |
| 1412 | 1412 | esc_html__( |
@@ -14,1439 +14,1439 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | - */ |
|
| 20 | - public function __construct($routing = true) |
|
| 21 | - { |
|
| 22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
| 23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
| 24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
| 26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | - parent::__construct($routing); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - protected function _extend_page_config() |
|
| 35 | - { |
|
| 36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | - ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | - ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | - |
|
| 42 | - $new_page_routes = array( |
|
| 43 | - 'question_groups' => array( |
|
| 44 | - 'func' => '_question_groups_overview_list_table', |
|
| 45 | - 'capability' => 'ee_read_question_groups', |
|
| 46 | - ), |
|
| 47 | - 'add_question' => array( |
|
| 48 | - 'func' => '_edit_question', |
|
| 49 | - 'capability' => 'ee_edit_questions', |
|
| 50 | - ), |
|
| 51 | - 'insert_question' => array( |
|
| 52 | - 'func' => '_insert_or_update_question', |
|
| 53 | - 'args' => array('new_question' => true), |
|
| 54 | - 'capability' => 'ee_edit_questions', |
|
| 55 | - 'noheader' => true, |
|
| 56 | - ), |
|
| 57 | - 'duplicate_question' => array( |
|
| 58 | - 'func' => '_duplicate_question', |
|
| 59 | - 'capability' => 'ee_edit_questions', |
|
| 60 | - 'noheader' => true, |
|
| 61 | - ), |
|
| 62 | - 'trash_question' => array( |
|
| 63 | - 'func' => '_trash_question', |
|
| 64 | - 'capability' => 'ee_delete_question', |
|
| 65 | - 'obj_id' => $qst_id, |
|
| 66 | - 'noheader' => true, |
|
| 67 | - ), |
|
| 68 | - |
|
| 69 | - 'restore_question' => array( |
|
| 70 | - 'func' => '_trash_or_restore_questions', |
|
| 71 | - 'capability' => 'ee_delete_question', |
|
| 72 | - 'obj_id' => $qst_id, |
|
| 73 | - 'args' => array('trash' => false), |
|
| 74 | - 'noheader' => true, |
|
| 75 | - ), |
|
| 76 | - |
|
| 77 | - 'delete_question' => array( |
|
| 78 | - 'func' => '_delete_question', |
|
| 79 | - 'capability' => 'ee_delete_question', |
|
| 80 | - 'obj_id' => $qst_id, |
|
| 81 | - 'noheader' => true, |
|
| 82 | - ), |
|
| 83 | - |
|
| 84 | - 'trash_questions' => array( |
|
| 85 | - 'func' => '_trash_or_restore_questions', |
|
| 86 | - 'capability' => 'ee_delete_questions', |
|
| 87 | - 'args' => array('trash' => true), |
|
| 88 | - 'noheader' => true, |
|
| 89 | - ), |
|
| 90 | - |
|
| 91 | - 'restore_questions' => array( |
|
| 92 | - 'func' => '_trash_or_restore_questions', |
|
| 93 | - 'capability' => 'ee_delete_questions', |
|
| 94 | - 'args' => array('trash' => false), |
|
| 95 | - 'noheader' => true, |
|
| 96 | - ), |
|
| 97 | - |
|
| 98 | - 'delete_questions' => array( |
|
| 99 | - 'func' => '_delete_questions', |
|
| 100 | - 'args' => array(), |
|
| 101 | - 'capability' => 'ee_delete_questions', |
|
| 102 | - 'noheader' => true, |
|
| 103 | - ), |
|
| 104 | - |
|
| 105 | - 'add_question_group' => array( |
|
| 106 | - 'func' => '_edit_question_group', |
|
| 107 | - 'capability' => 'ee_edit_question_groups', |
|
| 108 | - ), |
|
| 109 | - |
|
| 110 | - 'edit_question_group' => array( |
|
| 111 | - 'func' => '_edit_question_group', |
|
| 112 | - 'capability' => 'ee_edit_question_group', |
|
| 113 | - 'obj_id' => $qsg_id, |
|
| 114 | - 'args' => array('edit'), |
|
| 115 | - ), |
|
| 116 | - |
|
| 117 | - 'delete_question_groups' => array( |
|
| 118 | - 'func' => '_delete_question_groups', |
|
| 119 | - 'capability' => 'ee_delete_question_groups', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'delete_question_group' => array( |
|
| 124 | - 'func' => '_delete_question_groups', |
|
| 125 | - 'capability' => 'ee_delete_question_group', |
|
| 126 | - 'obj_id' => $qsg_id, |
|
| 127 | - 'noheader' => true, |
|
| 128 | - ), |
|
| 129 | - |
|
| 130 | - 'trash_question_group' => array( |
|
| 131 | - 'func' => '_trash_or_restore_question_groups', |
|
| 132 | - 'args' => array('trash' => true), |
|
| 133 | - 'capability' => 'ee_delete_question_group', |
|
| 134 | - 'obj_id' => $qsg_id, |
|
| 135 | - 'noheader' => true, |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'restore_question_group' => array( |
|
| 139 | - 'func' => '_trash_or_restore_question_groups', |
|
| 140 | - 'args' => array('trash' => false), |
|
| 141 | - 'capability' => 'ee_delete_question_group', |
|
| 142 | - 'obj_id' => $qsg_id, |
|
| 143 | - 'noheader' => true, |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - 'insert_question_group' => array( |
|
| 147 | - 'func' => '_insert_or_update_question_group', |
|
| 148 | - 'args' => array('new_question_group' => true), |
|
| 149 | - 'capability' => 'ee_edit_question_groups', |
|
| 150 | - 'noheader' => true, |
|
| 151 | - ), |
|
| 152 | - |
|
| 153 | - 'update_question_group' => array( |
|
| 154 | - 'func' => '_insert_or_update_question_group', |
|
| 155 | - 'args' => array('new_question_group' => false), |
|
| 156 | - 'capability' => 'ee_edit_question_group', |
|
| 157 | - 'obj_id' => $qsg_id, |
|
| 158 | - 'noheader' => true, |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - 'trash_question_groups' => array( |
|
| 162 | - 'func' => '_trash_or_restore_question_groups', |
|
| 163 | - 'args' => array('trash' => true), |
|
| 164 | - 'capability' => 'ee_delete_question_groups', |
|
| 165 | - 'noheader' => array('trash' => false), |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - 'restore_question_groups' => array( |
|
| 169 | - 'func' => '_trash_or_restore_question_groups', |
|
| 170 | - 'args' => array('trash' => false), |
|
| 171 | - 'capability' => 'ee_delete_question_groups', |
|
| 172 | - 'noheader' => true, |
|
| 173 | - ), |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - 'espresso_update_question_group_order' => array( |
|
| 177 | - 'func' => 'update_question_group_order', |
|
| 178 | - 'capability' => 'ee_edit_question_groups', |
|
| 179 | - 'noheader' => true, |
|
| 180 | - ), |
|
| 181 | - |
|
| 182 | - 'view_reg_form_settings' => array( |
|
| 183 | - 'func' => '_reg_form_settings', |
|
| 184 | - 'capability' => 'manage_options', |
|
| 185 | - ), |
|
| 186 | - |
|
| 187 | - 'update_reg_form_settings' => array( |
|
| 188 | - 'func' => '_update_reg_form_settings', |
|
| 189 | - 'capability' => 'manage_options', |
|
| 190 | - 'noheader' => true, |
|
| 191 | - ), |
|
| 192 | - ); |
|
| 193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | - |
|
| 195 | - $new_page_config = array( |
|
| 196 | - |
|
| 197 | - 'question_groups' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | - 'order' => 20, |
|
| 201 | - ), |
|
| 202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | - 'help_tabs' => array( |
|
| 204 | - 'registration_form_question_groups_help_tab' => array( |
|
| 205 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | - 'filename' => 'registration_form_question_groups', |
|
| 207 | - ), |
|
| 208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | - ), |
|
| 212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | - ), |
|
| 216 | - ), |
|
| 217 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 218 | - 'require_nonce' => false, |
|
| 219 | - ), |
|
| 220 | - |
|
| 221 | - 'add_question' => array( |
|
| 222 | - 'nav' => array( |
|
| 223 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 224 | - 'order' => 5, |
|
| 225 | - 'persistent' => false, |
|
| 226 | - ), |
|
| 227 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 228 | - 'help_tabs' => array( |
|
| 229 | - 'registration_form_add_question_help_tab' => array( |
|
| 230 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 231 | - 'filename' => 'registration_form_add_question', |
|
| 232 | - ), |
|
| 233 | - ), |
|
| 234 | - 'require_nonce' => false, |
|
| 235 | - ), |
|
| 236 | - |
|
| 237 | - 'add_question_group' => array( |
|
| 238 | - 'nav' => array( |
|
| 239 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 240 | - 'order' => 5, |
|
| 241 | - 'persistent' => false, |
|
| 242 | - ), |
|
| 243 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 244 | - 'help_tabs' => array( |
|
| 245 | - 'registration_form_add_question_group_help_tab' => array( |
|
| 246 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 247 | - 'filename' => 'registration_form_add_question_group', |
|
| 248 | - ), |
|
| 249 | - ), |
|
| 250 | - 'require_nonce' => false, |
|
| 251 | - ), |
|
| 252 | - |
|
| 253 | - 'edit_question_group' => array( |
|
| 254 | - 'nav' => array( |
|
| 255 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 256 | - 'order' => 5, |
|
| 257 | - 'persistent' => false, |
|
| 258 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 259 | - array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 260 | - $this->_current_page_view_url |
|
| 261 | - ) : $this->_admin_base_url, |
|
| 262 | - ), |
|
| 263 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 264 | - 'help_tabs' => array( |
|
| 265 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 266 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 267 | - 'filename' => 'registration_form_edit_question_group', |
|
| 268 | - ), |
|
| 269 | - ), |
|
| 270 | - 'require_nonce' => false, |
|
| 271 | - ), |
|
| 272 | - |
|
| 273 | - 'view_reg_form_settings' => array( |
|
| 274 | - 'nav' => array( |
|
| 275 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 276 | - 'order' => 40, |
|
| 277 | - ), |
|
| 278 | - 'labels' => array( |
|
| 279 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 280 | - ), |
|
| 281 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 282 | - 'help_tabs' => array( |
|
| 283 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
| 284 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 285 | - 'filename' => 'registration_form_reg_form_settings', |
|
| 286 | - ), |
|
| 287 | - ), |
|
| 288 | - 'require_nonce' => false, |
|
| 289 | - ), |
|
| 290 | - |
|
| 291 | - ); |
|
| 292 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 293 | - |
|
| 294 | - // change the list table we're going to use so it's the NEW list table! |
|
| 295 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - // additional labels |
|
| 299 | - $new_labels = array( |
|
| 300 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 301 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 302 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 303 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 304 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 305 | - ); |
|
| 306 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @return void |
|
| 312 | - */ |
|
| 313 | - protected function _ajax_hooks() |
|
| 314 | - { |
|
| 315 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @return void |
|
| 321 | - */ |
|
| 322 | - public function load_scripts_styles_question_groups() |
|
| 323 | - { |
|
| 324 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @return void |
|
| 330 | - */ |
|
| 331 | - public function load_scripts_styles_add_question_group() |
|
| 332 | - { |
|
| 333 | - $this->load_scripts_styles_forms(); |
|
| 334 | - $this->load_sortable_question_script(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @return void |
|
| 340 | - */ |
|
| 341 | - public function load_scripts_styles_edit_question_group() |
|
| 342 | - { |
|
| 343 | - $this->load_scripts_styles_forms(); |
|
| 344 | - $this->load_sortable_question_script(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * registers and enqueues script for questions |
|
| 350 | - * |
|
| 351 | - * @return void |
|
| 352 | - */ |
|
| 353 | - public function load_sortable_question_script() |
|
| 354 | - { |
|
| 355 | - wp_register_script( |
|
| 356 | - 'ee-question-sortable', |
|
| 357 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 358 | - array('jquery-ui-sortable'), |
|
| 359 | - EVENT_ESPRESSO_VERSION, |
|
| 360 | - true |
|
| 361 | - ); |
|
| 362 | - wp_enqueue_script('ee-question-sortable'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - protected function _set_list_table_views_default() |
|
| 370 | - { |
|
| 371 | - $this->_views = array( |
|
| 372 | - 'all' => array( |
|
| 373 | - 'slug' => 'all', |
|
| 374 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 375 | - 'count' => 0, |
|
| 376 | - 'bulk_action' => array( |
|
| 377 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 378 | - ), |
|
| 379 | - ), |
|
| 380 | - ); |
|
| 381 | - |
|
| 382 | - if ( |
|
| 383 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 384 | - 'ee_delete_questions', |
|
| 385 | - 'espresso_registration_form_trash_questions' |
|
| 386 | - ) |
|
| 387 | - ) { |
|
| 388 | - $this->_views['trash'] = array( |
|
| 389 | - 'slug' => 'trash', |
|
| 390 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 391 | - 'count' => 0, |
|
| 392 | - 'bulk_action' => array( |
|
| 393 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 394 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 395 | - ), |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @return void |
|
| 403 | - */ |
|
| 404 | - protected function _set_list_table_views_question_groups() |
|
| 405 | - { |
|
| 406 | - $this->_views = array( |
|
| 407 | - 'all' => array( |
|
| 408 | - 'slug' => 'all', |
|
| 409 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 410 | - 'count' => 0, |
|
| 411 | - 'bulk_action' => array( |
|
| 412 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 413 | - ), |
|
| 414 | - ), |
|
| 415 | - ); |
|
| 416 | - |
|
| 417 | - if ( |
|
| 418 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 419 | - 'ee_delete_question_groups', |
|
| 420 | - 'espresso_registration_form_trash_question_groups' |
|
| 421 | - ) |
|
| 422 | - ) { |
|
| 423 | - $this->_views['trash'] = array( |
|
| 424 | - 'slug' => 'trash', |
|
| 425 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 426 | - 'count' => 0, |
|
| 427 | - 'bulk_action' => array( |
|
| 428 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 429 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 430 | - ), |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @return void |
|
| 438 | - * @throws EE_Error |
|
| 439 | - * @throws InvalidArgumentException |
|
| 440 | - * @throws InvalidDataTypeException |
|
| 441 | - * @throws InvalidInterfaceException |
|
| 442 | - */ |
|
| 443 | - protected function _questions_overview_list_table() |
|
| 444 | - { |
|
| 445 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 446 | - 'add_question', |
|
| 447 | - 'add_question', |
|
| 448 | - array(), |
|
| 449 | - 'add-new-h2' |
|
| 450 | - ); |
|
| 451 | - parent::_questions_overview_list_table(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @return void |
|
| 457 | - * @throws DomainException |
|
| 458 | - * @throws EE_Error |
|
| 459 | - * @throws InvalidArgumentException |
|
| 460 | - * @throws InvalidDataTypeException |
|
| 461 | - * @throws InvalidInterfaceException |
|
| 462 | - */ |
|
| 463 | - protected function _question_groups_overview_list_table() |
|
| 464 | - { |
|
| 465 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 466 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 467 | - 'add_question_group', |
|
| 468 | - 'add_question_group', |
|
| 469 | - array(), |
|
| 470 | - 'add-new-h2' |
|
| 471 | - ); |
|
| 472 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * @return void |
|
| 478 | - * @throws EE_Error |
|
| 479 | - * @throws InvalidArgumentException |
|
| 480 | - * @throws InvalidDataTypeException |
|
| 481 | - * @throws InvalidInterfaceException |
|
| 482 | - */ |
|
| 483 | - protected function _delete_question() |
|
| 484 | - { |
|
| 485 | - $success = $this->_delete_items($this->_question_model); |
|
| 486 | - $this->_redirect_after_action( |
|
| 487 | - $success, |
|
| 488 | - $this->_question_model->item_name($success), |
|
| 489 | - 'deleted', |
|
| 490 | - array('action' => 'default', 'status' => 'all') |
|
| 491 | - ); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @return void |
|
| 497 | - * @throws EE_Error |
|
| 498 | - * @throws InvalidArgumentException |
|
| 499 | - * @throws InvalidDataTypeException |
|
| 500 | - * @throws InvalidInterfaceException |
|
| 501 | - */ |
|
| 502 | - protected function _delete_questions() |
|
| 503 | - { |
|
| 504 | - $success = $this->_delete_items($this->_question_model); |
|
| 505 | - $this->_redirect_after_action( |
|
| 506 | - $success, |
|
| 507 | - $this->_question_model->item_name($success), |
|
| 508 | - 'deleted permanently', |
|
| 509 | - array('action' => 'default', 'status' => 'trash') |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Performs the deletion of a single or multiple questions or question groups. |
|
| 516 | - * |
|
| 517 | - * @param EEM_Soft_Delete_Base $model |
|
| 518 | - * @return int number of items deleted permanently |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws InvalidArgumentException |
|
| 521 | - * @throws InvalidDataTypeException |
|
| 522 | - * @throws InvalidInterfaceException |
|
| 523 | - */ |
|
| 524 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 525 | - { |
|
| 526 | - $success = 0; |
|
| 527 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 528 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 529 | - // if array has more than one element than success message should be plural |
|
| 530 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 531 | - // cycle thru bulk action checkboxes |
|
| 532 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 533 | - if (! $this->_delete_item($ID, $model)) { |
|
| 534 | - $success = 0; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 538 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 539 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 540 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 541 | - } else { |
|
| 542 | - EE_Error::add_error( |
|
| 543 | - sprintf( |
|
| 544 | - esc_html__( |
|
| 545 | - "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 546 | - "event_espresso" |
|
| 547 | - ) |
|
| 548 | - ), |
|
| 549 | - __FILE__, |
|
| 550 | - __FUNCTION__, |
|
| 551 | - __LINE__ |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return $success; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Deletes the specified question (and its associated question options) or question group |
|
| 560 | - * |
|
| 561 | - * @param int $id |
|
| 562 | - * @param EEM_Soft_Delete_Base $model |
|
| 563 | - * @return boolean |
|
| 564 | - * @throws EE_Error |
|
| 565 | - * @throws InvalidArgumentException |
|
| 566 | - * @throws InvalidDataTypeException |
|
| 567 | - * @throws InvalidInterfaceException |
|
| 568 | - */ |
|
| 569 | - protected function _delete_item($id, $model) |
|
| 570 | - { |
|
| 571 | - if ($model instanceof EEM_Question) { |
|
| 572 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 573 | - } |
|
| 574 | - return $model->delete_permanently_by_ID(absint($id)); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /****************************** QUESTION GROUPS ******************************/ |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @param string $type |
|
| 583 | - * @return void |
|
| 584 | - * @throws DomainException |
|
| 585 | - * @throws EE_Error |
|
| 586 | - * @throws InvalidArgumentException |
|
| 587 | - * @throws InvalidDataTypeException |
|
| 588 | - * @throws InvalidInterfaceException |
|
| 589 | - */ |
|
| 590 | - protected function _edit_question_group($type = 'add') |
|
| 591 | - { |
|
| 592 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 593 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 594 | - ? absint($this->_req_data['QSG_ID']) |
|
| 595 | - : false; |
|
| 596 | - |
|
| 597 | - switch ($this->_req_action) { |
|
| 598 | - case 'add_question_group': |
|
| 599 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 600 | - break; |
|
| 601 | - case 'edit_question_group': |
|
| 602 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 603 | - break; |
|
| 604 | - default: |
|
| 605 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 606 | - } |
|
| 607 | - // add ID to title if editing |
|
| 608 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 609 | - if ($ID) { |
|
| 610 | - /** @var EE_Question_Group $questionGroup */ |
|
| 611 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 612 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 613 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 614 | - } else { |
|
| 615 | - /** @var EE_Question_Group $questionGroup */ |
|
| 616 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 617 | - $questionGroup->set_order_to_latest(); |
|
| 618 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 619 | - } |
|
| 620 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 621 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 622 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 623 | - $this->_template_args['question_group'] = $questionGroup; |
|
| 624 | - |
|
| 625 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 626 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 627 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 628 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 629 | - $this->_template_args, |
|
| 630 | - true |
|
| 631 | - ); |
|
| 632 | - |
|
| 633 | - // the details template wrapper |
|
| 634 | - $this->display_admin_page_with_sidebar(); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * @return void |
|
| 640 | - * @throws EE_Error |
|
| 641 | - * @throws InvalidArgumentException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws InvalidInterfaceException |
|
| 644 | - */ |
|
| 645 | - protected function _delete_question_groups() |
|
| 646 | - { |
|
| 647 | - $success = $this->_delete_items($this->_question_group_model); |
|
| 648 | - $this->_redirect_after_action( |
|
| 649 | - $success, |
|
| 650 | - $this->_question_group_model->item_name($success), |
|
| 651 | - 'deleted permanently', |
|
| 652 | - array('action' => 'question_groups', 'status' => 'trash') |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * @param bool $new_question_group |
|
| 659 | - * @throws EE_Error |
|
| 660 | - * @throws InvalidArgumentException |
|
| 661 | - * @throws InvalidDataTypeException |
|
| 662 | - * @throws InvalidInterfaceException |
|
| 663 | - */ |
|
| 664 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
| 665 | - { |
|
| 666 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 667 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 668 | - |
|
| 669 | - // make sure identifier is unique |
|
| 670 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 671 | - $where_values = ['QSG_identifier' => $set_column_values['QSG_identifier']]; |
|
| 672 | - if (! $new_question_group && isset($set_column_values['QSG_ID'])) { |
|
| 673 | - $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']]; |
|
| 674 | - } |
|
| 675 | - $identifier_exists = ! empty($identifier_value) |
|
| 676 | - ? $this->_question_group_model->count([$where_values]) > 0 |
|
| 677 | - : false; |
|
| 678 | - if ($identifier_exists) { |
|
| 679 | - $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if ($new_question_group) { |
|
| 683 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 684 | - $success = $QSG_ID ? 1 : 0; |
|
| 685 | - if ($success === 0) { |
|
| 686 | - EE_Error::add_error( |
|
| 687 | - esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 688 | - __FILE__, |
|
| 689 | - __FUNCTION__, |
|
| 690 | - __LINE__ |
|
| 691 | - ); |
|
| 692 | - $this->_redirect_after_action( |
|
| 693 | - false, |
|
| 694 | - '', |
|
| 695 | - '', |
|
| 696 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 697 | - true |
|
| 698 | - ); |
|
| 699 | - } |
|
| 700 | - } else { |
|
| 701 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 702 | - unset($set_column_values['QSG_ID']); |
|
| 703 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 707 | - EEM_Attendee::system_question_phone |
|
| 708 | - ); |
|
| 709 | - // update the existing related questions |
|
| 710 | - // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 711 | - // if it is being added to this question group (therefore removed from the existing group) |
|
| 712 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 713 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 714 | - EEM_Question_Group_Question::instance()->delete( |
|
| 715 | - array( |
|
| 716 | - array( |
|
| 717 | - 'QST_ID' => $phone_question_id, |
|
| 718 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
| 719 | - ), |
|
| 720 | - ) |
|
| 721 | - ); |
|
| 722 | - } |
|
| 723 | - /** @type EE_Question_Group $question_group */ |
|
| 724 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 725 | - $questions = $question_group->questions(); |
|
| 726 | - // make sure system phone question is added to list of questions for this group |
|
| 727 | - if (! isset($questions[ $phone_question_id ])) { |
|
| 728 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - foreach ($questions as $question_ID => $question) { |
|
| 732 | - // first we always check for order. |
|
| 733 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 734 | - // update question order |
|
| 735 | - $question_group->update_question_order( |
|
| 736 | - $question_ID, |
|
| 737 | - $this->_req_data['question_orders'][ $question_ID ] |
|
| 738 | - ); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - // then we always check if adding or removing. |
|
| 742 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 743 | - $question_group->add_question($question_ID); |
|
| 744 | - } else { |
|
| 745 | - // not found, remove it (but only if not a system question for the personal group |
|
| 746 | - // with the exception of lname system question - we allow removal of it) |
|
| 747 | - if ( |
|
| 748 | - in_array( |
|
| 749 | - $question->system_ID(), |
|
| 750 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 751 | - $question_group->system_group() |
|
| 752 | - ) |
|
| 753 | - ) |
|
| 754 | - ) { |
|
| 755 | - continue; |
|
| 756 | - } else { |
|
| 757 | - $question_group->remove_question($question_ID); |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - // save new related questions |
|
| 762 | - if (isset($this->_req_data['questions'])) { |
|
| 763 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 764 | - $question_group->add_question($QST_ID); |
|
| 765 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 766 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - if ($success !== false) { |
|
| 772 | - $msg = $new_question_group |
|
| 773 | - ? sprintf( |
|
| 774 | - esc_html__('The %s has been created', 'event_espresso'), |
|
| 775 | - $this->_question_group_model->item_name() |
|
| 776 | - ) |
|
| 777 | - : sprintf( |
|
| 778 | - esc_html__( |
|
| 779 | - 'The %s has been updated', |
|
| 780 | - 'event_espresso' |
|
| 781 | - ), |
|
| 782 | - $this->_question_group_model->item_name() |
|
| 783 | - ); |
|
| 784 | - EE_Error::add_success($msg); |
|
| 785 | - } |
|
| 786 | - $this->_redirect_after_action( |
|
| 787 | - false, |
|
| 788 | - '', |
|
| 789 | - '', |
|
| 790 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 791 | - true |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * duplicates a question and all its question options and redirects to the new question. |
|
| 798 | - * |
|
| 799 | - * @return void |
|
| 800 | - * @throws EE_Error |
|
| 801 | - * @throws InvalidArgumentException |
|
| 802 | - * @throws ReflectionException |
|
| 803 | - * @throws InvalidDataTypeException |
|
| 804 | - * @throws InvalidInterfaceException |
|
| 805 | - */ |
|
| 806 | - public function _duplicate_question() |
|
| 807 | - { |
|
| 808 | - $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 809 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 810 | - if ($question instanceof EE_Question) { |
|
| 811 | - $new_question = $question->duplicate(); |
|
| 812 | - if ($new_question instanceof EE_Question) { |
|
| 813 | - $this->_redirect_after_action( |
|
| 814 | - true, |
|
| 815 | - esc_html__('Question', 'event_espresso'), |
|
| 816 | - esc_html__('Duplicated', 'event_espresso'), |
|
| 817 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 818 | - true |
|
| 819 | - ); |
|
| 820 | - } else { |
|
| 821 | - global $wpdb; |
|
| 822 | - EE_Error::add_error( |
|
| 823 | - sprintf( |
|
| 824 | - esc_html__( |
|
| 825 | - 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 826 | - 'event_espresso' |
|
| 827 | - ), |
|
| 828 | - $question_ID, |
|
| 829 | - $wpdb->last_error |
|
| 830 | - ), |
|
| 831 | - __FILE__, |
|
| 832 | - __FUNCTION__, |
|
| 833 | - __LINE__ |
|
| 834 | - ); |
|
| 835 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 836 | - } |
|
| 837 | - } else { |
|
| 838 | - EE_Error::add_error( |
|
| 839 | - sprintf( |
|
| 840 | - esc_html__( |
|
| 841 | - 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 842 | - 'event_espresso' |
|
| 843 | - ), |
|
| 844 | - $question_ID |
|
| 845 | - ), |
|
| 846 | - __FILE__, |
|
| 847 | - __FUNCTION__, |
|
| 848 | - __LINE__ |
|
| 849 | - ); |
|
| 850 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 851 | - } |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * @param bool $trash |
|
| 857 | - * @throws EE_Error |
|
| 858 | - */ |
|
| 859 | - protected function _trash_or_restore_question_groups($trash = true) |
|
| 860 | - { |
|
| 861 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - *_trash_question |
|
| 867 | - * |
|
| 868 | - * @return void |
|
| 869 | - * @throws EE_Error |
|
| 870 | - */ |
|
| 871 | - protected function _trash_question() |
|
| 872 | - { |
|
| 873 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 874 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 875 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * @param bool $trash |
|
| 881 | - * @throws EE_Error |
|
| 882 | - */ |
|
| 883 | - protected function _trash_or_restore_questions($trash = true) |
|
| 884 | - { |
|
| 885 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
| 891 | - * flexible between question or question groups |
|
| 892 | - * |
|
| 893 | - * @param EEM_Soft_Delete_Base $model |
|
| 894 | - * @param boolean $trash whether to trash or restore |
|
| 895 | - * @throws EE_Error |
|
| 896 | - */ |
|
| 897 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 898 | - { |
|
| 899 | - |
|
| 900 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 901 | - |
|
| 902 | - $success = 1; |
|
| 903 | - // Checkboxes |
|
| 904 | - // echo "trash $trash"; |
|
| 905 | - // var_dump($this->_req_data['checkbox']);die; |
|
| 906 | - if (isset($this->_req_data['checkbox'])) { |
|
| 907 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 908 | - // if array has more than one element than success message should be plural |
|
| 909 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 910 | - // cycle thru bulk action checkboxes |
|
| 911 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 912 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 913 | - $success = 0; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - } else { |
|
| 917 | - // grab single id and delete |
|
| 918 | - $ID = absint($this->_req_data['checkbox']); |
|
| 919 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 920 | - $success = 0; |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - } else { |
|
| 924 | - // delete via trash link |
|
| 925 | - // grab single id and delete |
|
| 926 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 927 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 928 | - $success = 0; |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - |
|
| 933 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 934 | - // echo "action :$action"; |
|
| 935 | - // $action = 'questions' ? 'default' : $action; |
|
| 936 | - if ($trash) { |
|
| 937 | - $action_desc = 'trashed'; |
|
| 938 | - $status = 'trash'; |
|
| 939 | - } else { |
|
| 940 | - $action_desc = 'restored'; |
|
| 941 | - $status = 'all'; |
|
| 942 | - } |
|
| 943 | - $this->_redirect_after_action( |
|
| 944 | - $success, |
|
| 945 | - $model->item_name($success), |
|
| 946 | - $action_desc, |
|
| 947 | - array('action' => $action, 'status' => $status) |
|
| 948 | - ); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * @param $per_page |
|
| 954 | - * @param int $current_page |
|
| 955 | - * @param bool|false $count |
|
| 956 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 957 | - * @throws EE_Error |
|
| 958 | - * @throws InvalidArgumentException |
|
| 959 | - * @throws InvalidDataTypeException |
|
| 960 | - * @throws InvalidInterfaceException |
|
| 961 | - */ |
|
| 962 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 963 | - { |
|
| 964 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 965 | - |
|
| 966 | - if ($count) { |
|
| 967 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 968 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 969 | - $results = $this->_question_model->count_deleted($where); |
|
| 970 | - } else { |
|
| 971 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 972 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
| 973 | - } |
|
| 974 | - return $results; |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * @param $per_page |
|
| 980 | - * @param int $current_page |
|
| 981 | - * @param bool|false $count |
|
| 982 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 983 | - * @throws EE_Error |
|
| 984 | - * @throws InvalidArgumentException |
|
| 985 | - * @throws InvalidDataTypeException |
|
| 986 | - * @throws InvalidInterfaceException |
|
| 987 | - */ |
|
| 988 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 989 | - { |
|
| 990 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 991 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 992 | - if ($count) { |
|
| 993 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 994 | - $results = $questionGroupModel->count($where); |
|
| 995 | - } else { |
|
| 996 | - $results = $questionGroupModel->get_all($query_params); |
|
| 997 | - } |
|
| 998 | - return $results; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * @param $per_page |
|
| 1004 | - * @param int $current_page |
|
| 1005 | - * @param bool $count |
|
| 1006 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1007 | - * @throws EE_Error |
|
| 1008 | - * @throws InvalidArgumentException |
|
| 1009 | - * @throws InvalidDataTypeException |
|
| 1010 | - * @throws InvalidInterfaceException |
|
| 1011 | - */ |
|
| 1012 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1013 | - { |
|
| 1014 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1015 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1016 | - if ($count) { |
|
| 1017 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1018 | - $query_params['limit'] = null; |
|
| 1019 | - $results = $questionGroupModel->count_deleted($where); |
|
| 1020 | - } else { |
|
| 1021 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1022 | - } |
|
| 1023 | - return $results; |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * method for performing updates to question order |
|
| 1029 | - * |
|
| 1030 | - * @return void results array |
|
| 1031 | - * @throws EE_Error |
|
| 1032 | - * @throws InvalidArgumentException |
|
| 1033 | - * @throws InvalidDataTypeException |
|
| 1034 | - * @throws InvalidInterfaceException |
|
| 1035 | - */ |
|
| 1036 | - public function update_question_group_order() |
|
| 1037 | - { |
|
| 1038 | - |
|
| 1039 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1040 | - |
|
| 1041 | - // grab our row IDs |
|
| 1042 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1043 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1044 | - : array(); |
|
| 1045 | - |
|
| 1046 | - $perpage = ! empty($this->_req_data['perpage']) |
|
| 1047 | - ? (int) $this->_req_data['perpage'] |
|
| 1048 | - : null; |
|
| 1049 | - $curpage = ! empty($this->_req_data['curpage']) |
|
| 1050 | - ? (int) $this->_req_data['curpage'] |
|
| 1051 | - : null; |
|
| 1052 | - |
|
| 1053 | - if (! empty($row_ids)) { |
|
| 1054 | - // figure out where we start the row_id count at for the current page. |
|
| 1055 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1056 | - |
|
| 1057 | - $row_count = count($row_ids); |
|
| 1058 | - for ($i = 0; $i < $row_count; $i++) { |
|
| 1059 | - // Update the questions when re-ordering |
|
| 1060 | - $updated = EEM_Question_Group::instance()->update( |
|
| 1061 | - array('QSG_order' => $qsgcount), |
|
| 1062 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1063 | - ); |
|
| 1064 | - if ($updated === false) { |
|
| 1065 | - $success = false; |
|
| 1066 | - } |
|
| 1067 | - $qsgcount++; |
|
| 1068 | - } |
|
| 1069 | - } else { |
|
| 1070 | - $success = false; |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - $errors = ! $success |
|
| 1074 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1075 | - : false; |
|
| 1076 | - |
|
| 1077 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1078 | - die(); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * @throws DomainException |
|
| 1088 | - * @throws EE_Error |
|
| 1089 | - * @throws InvalidArgumentException |
|
| 1090 | - * @throws InvalidDataTypeException |
|
| 1091 | - * @throws InvalidInterfaceException |
|
| 1092 | - */ |
|
| 1093 | - protected function _reg_form_settings() |
|
| 1094 | - { |
|
| 1095 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1096 | - add_action( |
|
| 1097 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1098 | - array($this, 'email_validation_settings_form'), |
|
| 1099 | - 2 |
|
| 1100 | - ); |
|
| 1101 | - add_action( |
|
| 1102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1103 | - array($this, 'copy_attendee_info_settings_form'), |
|
| 1104 | - 4 |
|
| 1105 | - ); |
|
| 1106 | - $this->_template_args = (array) apply_filters( |
|
| 1107 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1108 | - $this->_template_args |
|
| 1109 | - ); |
|
| 1110 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1111 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1112 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1113 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1114 | - $this->_template_args, |
|
| 1115 | - true |
|
| 1116 | - ); |
|
| 1117 | - $this->display_admin_page_with_sidebar(); |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * @return void |
|
| 1123 | - * @throws EE_Error |
|
| 1124 | - * @throws InvalidArgumentException |
|
| 1125 | - * @throws ReflectionException |
|
| 1126 | - * @throws InvalidDataTypeException |
|
| 1127 | - * @throws InvalidInterfaceException |
|
| 1128 | - */ |
|
| 1129 | - protected function _update_reg_form_settings() |
|
| 1130 | - { |
|
| 1131 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1132 | - EE_Registry::instance()->CFG->registration |
|
| 1133 | - ); |
|
| 1134 | - EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
| 1135 | - EE_Registry::instance()->CFG->registration |
|
| 1136 | - ); |
|
| 1137 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1138 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1139 | - EE_Registry::instance()->CFG->registration |
|
| 1140 | - ); |
|
| 1141 | - $success = $this->_update_espresso_configuration( |
|
| 1142 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1143 | - EE_Registry::instance()->CFG, |
|
| 1144 | - __FILE__, |
|
| 1145 | - __FUNCTION__, |
|
| 1146 | - __LINE__ |
|
| 1147 | - ); |
|
| 1148 | - $this->_redirect_after_action( |
|
| 1149 | - $success, |
|
| 1150 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1151 | - 'updated', |
|
| 1152 | - array('action' => 'view_reg_form_settings') |
|
| 1153 | - ); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * @return void |
|
| 1159 | - * @throws EE_Error |
|
| 1160 | - * @throws InvalidArgumentException |
|
| 1161 | - * @throws InvalidDataTypeException |
|
| 1162 | - * @throws InvalidInterfaceException |
|
| 1163 | - */ |
|
| 1164 | - public function copy_attendee_info_settings_form() |
|
| 1165 | - { |
|
| 1166 | - echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags()); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * _copy_attendee_info_settings_form |
|
| 1171 | - * |
|
| 1172 | - * @access protected |
|
| 1173 | - * @return EE_Form_Section_Proper |
|
| 1174 | - * @throws \EE_Error |
|
| 1175 | - */ |
|
| 1176 | - protected function _copy_attendee_info_settings_form() |
|
| 1177 | - { |
|
| 1178 | - return new EE_Form_Section_Proper( |
|
| 1179 | - array( |
|
| 1180 | - 'name' => 'copy_attendee_info_settings', |
|
| 1181 | - 'html_id' => 'copy_attendee_info_settings', |
|
| 1182 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1183 | - 'subsections' => apply_filters( |
|
| 1184 | - 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
| 1185 | - array( |
|
| 1186 | - 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
| 1187 | - EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
| 1188 | - ), |
|
| 1189 | - 'copy_attendee_info' => new EE_Yes_No_Input( |
|
| 1190 | - array( |
|
| 1191 | - 'html_label_text' => esc_html__( |
|
| 1192 | - 'Allow copy #1 attendee info to extra attendees?', |
|
| 1193 | - 'event_espresso' |
|
| 1194 | - ), |
|
| 1195 | - 'html_help_text' => esc_html__( |
|
| 1196 | - 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
| 1197 | - 'event_espresso' |
|
| 1198 | - ), |
|
| 1199 | - 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
| 1200 | - 'required' => false, |
|
| 1201 | - 'display_html_label_text' => false, |
|
| 1202 | - ) |
|
| 1203 | - ), |
|
| 1204 | - ) |
|
| 1205 | - ), |
|
| 1206 | - ) |
|
| 1207 | - ); |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1212 | - * @return EE_Registration_Config |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - * @throws InvalidArgumentException |
|
| 1215 | - * @throws ReflectionException |
|
| 1216 | - * @throws InvalidDataTypeException |
|
| 1217 | - * @throws InvalidInterfaceException |
|
| 1218 | - */ |
|
| 1219 | - public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1220 | - { |
|
| 1221 | - $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
| 1222 | - try { |
|
| 1223 | - $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
| 1224 | - // if not displaying a form, then check for form submission |
|
| 1225 | - if ($copy_attendee_info_settings_form->was_submitted()) { |
|
| 1226 | - // capture form data |
|
| 1227 | - $copy_attendee_info_settings_form->receive_form_submission(); |
|
| 1228 | - // validate form data |
|
| 1229 | - if ($copy_attendee_info_settings_form->is_valid()) { |
|
| 1230 | - // grab validated data from form |
|
| 1231 | - $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
| 1232 | - if (isset($valid_data['copy_attendee_info'])) { |
|
| 1233 | - $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
| 1234 | - } else { |
|
| 1235 | - EE_Error::add_error( |
|
| 1236 | - esc_html__( |
|
| 1237 | - 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
| 1238 | - 'event_espresso' |
|
| 1239 | - ), |
|
| 1240 | - __FILE__, |
|
| 1241 | - __FUNCTION__, |
|
| 1242 | - __LINE__ |
|
| 1243 | - ); |
|
| 1244 | - } |
|
| 1245 | - } else { |
|
| 1246 | - if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
| 1247 | - EE_Error::add_error( |
|
| 1248 | - $copy_attendee_info_settings_form->submission_error_message(), |
|
| 1249 | - __FILE__, |
|
| 1250 | - __FUNCTION__, |
|
| 1251 | - __LINE__ |
|
| 1252 | - ); |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - } catch (EE_Error $e) { |
|
| 1257 | - $e->get_error(); |
|
| 1258 | - } |
|
| 1259 | - return $EE_Registration_Config; |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - |
|
| 1263 | - /** |
|
| 1264 | - * @return void |
|
| 1265 | - * @throws EE_Error |
|
| 1266 | - * @throws InvalidArgumentException |
|
| 1267 | - * @throws InvalidDataTypeException |
|
| 1268 | - * @throws InvalidInterfaceException |
|
| 1269 | - */ |
|
| 1270 | - public function email_validation_settings_form() |
|
| 1271 | - { |
|
| 1272 | - echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags()); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * _email_validation_settings_form |
|
| 1278 | - * |
|
| 1279 | - * @access protected |
|
| 1280 | - * @return EE_Form_Section_Proper |
|
| 1281 | - * @throws \EE_Error |
|
| 1282 | - */ |
|
| 1283 | - protected function _email_validation_settings_form() |
|
| 1284 | - { |
|
| 1285 | - return new EE_Form_Section_Proper( |
|
| 1286 | - array( |
|
| 1287 | - 'name' => 'email_validation_settings', |
|
| 1288 | - 'html_id' => 'email_validation_settings', |
|
| 1289 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1290 | - 'subsections' => apply_filters( |
|
| 1291 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1292 | - array( |
|
| 1293 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1294 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1295 | - ), |
|
| 1296 | - 'email_validation_level' => new EE_Select_Input( |
|
| 1297 | - array( |
|
| 1298 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1299 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1300 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1301 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1302 | - ), |
|
| 1303 | - array( |
|
| 1304 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1305 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1306 | - 'html_help_text' => esc_html__( |
|
| 1307 | - 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1308 | - 'event_espresso' |
|
| 1309 | - ), |
|
| 1310 | - 'default' => isset( |
|
| 1311 | - EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1312 | - ) |
|
| 1313 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1314 | - : 'wp_default', |
|
| 1315 | - 'required' => false, |
|
| 1316 | - ) |
|
| 1317 | - ), |
|
| 1318 | - ) |
|
| 1319 | - ), |
|
| 1320 | - ) |
|
| 1321 | - ); |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1327 | - * @return EE_Registration_Config |
|
| 1328 | - * @throws EE_Error |
|
| 1329 | - * @throws InvalidArgumentException |
|
| 1330 | - * @throws ReflectionException |
|
| 1331 | - * @throws InvalidDataTypeException |
|
| 1332 | - * @throws InvalidInterfaceException |
|
| 1333 | - */ |
|
| 1334 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1335 | - { |
|
| 1336 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1337 | - try { |
|
| 1338 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1339 | - // if not displaying a form, then check for form submission |
|
| 1340 | - if ($email_validation_settings_form->was_submitted()) { |
|
| 1341 | - // capture form data |
|
| 1342 | - $email_validation_settings_form->receive_form_submission(); |
|
| 1343 | - // validate form data |
|
| 1344 | - if ($email_validation_settings_form->is_valid()) { |
|
| 1345 | - // grab validated data from form |
|
| 1346 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1347 | - if (isset($valid_data['email_validation_level'])) { |
|
| 1348 | - $email_validation_level = $valid_data['email_validation_level']; |
|
| 1349 | - // now if they want to use international email addresses |
|
| 1350 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1351 | - // in case we need to reset their email validation level, |
|
| 1352 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1353 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1354 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1355 | - // despite offering poor validation, supports i18n email addresses |
|
| 1356 | - $prev_email_validation_level = 'basic'; |
|
| 1357 | - } |
|
| 1358 | - // confirm our i18n email validation will work on the server |
|
| 1359 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1360 | - // or reset email validation level to previous value |
|
| 1361 | - $email_validation_level = $prev_email_validation_level; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1365 | - } else { |
|
| 1366 | - EE_Error::add_error( |
|
| 1367 | - esc_html__( |
|
| 1368 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1369 | - 'event_espresso' |
|
| 1370 | - ), |
|
| 1371 | - __FILE__, |
|
| 1372 | - __FUNCTION__, |
|
| 1373 | - __LINE__ |
|
| 1374 | - ); |
|
| 1375 | - } |
|
| 1376 | - } else { |
|
| 1377 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1378 | - EE_Error::add_error( |
|
| 1379 | - $email_validation_settings_form->submission_error_message(), |
|
| 1380 | - __FILE__, |
|
| 1381 | - __FUNCTION__, |
|
| 1382 | - __LINE__ |
|
| 1383 | - ); |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - } catch (EE_Error $e) { |
|
| 1388 | - $e->get_error(); |
|
| 1389 | - } |
|
| 1390 | - return $EE_Registration_Config; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1396 | - * and that the PCRE version works with our i18n email validation |
|
| 1397 | - * |
|
| 1398 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1399 | - * @param string $email_validation_level |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1403 | - { |
|
| 1404 | - // first check that PCRE is enabled |
|
| 1405 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1406 | - EE_Error::add_error( |
|
| 1407 | - sprintf( |
|
| 1408 | - esc_html__( |
|
| 1409 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1410 | - 'event_espresso' |
|
| 1411 | - ), |
|
| 1412 | - '<br />' |
|
| 1413 | - ), |
|
| 1414 | - __FILE__, |
|
| 1415 | - __FUNCTION__, |
|
| 1416 | - __LINE__ |
|
| 1417 | - ); |
|
| 1418 | - return false; |
|
| 1419 | - } else { |
|
| 1420 | - // PCRE support is enabled, but let's still |
|
| 1421 | - // perform a test to see if the server will support it. |
|
| 1422 | - // but first, save the updated validation level to the config, |
|
| 1423 | - // so that the validation strategy picks it up. |
|
| 1424 | - // this will get bumped back down if it doesn't work |
|
| 1425 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1426 | - try { |
|
| 1427 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1428 | - $i18n_email_address = apply_filters( |
|
| 1429 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1430 | - 'jägerjü[email protected]' |
|
| 1431 | - ); |
|
| 1432 | - $email_validator->validate($i18n_email_address); |
|
| 1433 | - } catch (Exception $e) { |
|
| 1434 | - EE_Error::add_error( |
|
| 1435 | - sprintf( |
|
| 1436 | - esc_html__( |
|
| 1437 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1438 | - 'event_espresso' |
|
| 1439 | - ), |
|
| 1440 | - '<br />', |
|
| 1441 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1442 | - ), |
|
| 1443 | - __FILE__, |
|
| 1444 | - __FUNCTION__, |
|
| 1445 | - __LINE__ |
|
| 1446 | - ); |
|
| 1447 | - return false; |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - return true; |
|
| 1451 | - } |
|
| 17 | + /** |
|
| 18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | + */ |
|
| 20 | + public function __construct($routing = true) |
|
| 21 | + { |
|
| 22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
| 23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
| 24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
| 26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | + parent::__construct($routing); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + protected function _extend_page_config() |
|
| 35 | + { |
|
| 36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | + ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | + ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | + |
|
| 42 | + $new_page_routes = array( |
|
| 43 | + 'question_groups' => array( |
|
| 44 | + 'func' => '_question_groups_overview_list_table', |
|
| 45 | + 'capability' => 'ee_read_question_groups', |
|
| 46 | + ), |
|
| 47 | + 'add_question' => array( |
|
| 48 | + 'func' => '_edit_question', |
|
| 49 | + 'capability' => 'ee_edit_questions', |
|
| 50 | + ), |
|
| 51 | + 'insert_question' => array( |
|
| 52 | + 'func' => '_insert_or_update_question', |
|
| 53 | + 'args' => array('new_question' => true), |
|
| 54 | + 'capability' => 'ee_edit_questions', |
|
| 55 | + 'noheader' => true, |
|
| 56 | + ), |
|
| 57 | + 'duplicate_question' => array( |
|
| 58 | + 'func' => '_duplicate_question', |
|
| 59 | + 'capability' => 'ee_edit_questions', |
|
| 60 | + 'noheader' => true, |
|
| 61 | + ), |
|
| 62 | + 'trash_question' => array( |
|
| 63 | + 'func' => '_trash_question', |
|
| 64 | + 'capability' => 'ee_delete_question', |
|
| 65 | + 'obj_id' => $qst_id, |
|
| 66 | + 'noheader' => true, |
|
| 67 | + ), |
|
| 68 | + |
|
| 69 | + 'restore_question' => array( |
|
| 70 | + 'func' => '_trash_or_restore_questions', |
|
| 71 | + 'capability' => 'ee_delete_question', |
|
| 72 | + 'obj_id' => $qst_id, |
|
| 73 | + 'args' => array('trash' => false), |
|
| 74 | + 'noheader' => true, |
|
| 75 | + ), |
|
| 76 | + |
|
| 77 | + 'delete_question' => array( |
|
| 78 | + 'func' => '_delete_question', |
|
| 79 | + 'capability' => 'ee_delete_question', |
|
| 80 | + 'obj_id' => $qst_id, |
|
| 81 | + 'noheader' => true, |
|
| 82 | + ), |
|
| 83 | + |
|
| 84 | + 'trash_questions' => array( |
|
| 85 | + 'func' => '_trash_or_restore_questions', |
|
| 86 | + 'capability' => 'ee_delete_questions', |
|
| 87 | + 'args' => array('trash' => true), |
|
| 88 | + 'noheader' => true, |
|
| 89 | + ), |
|
| 90 | + |
|
| 91 | + 'restore_questions' => array( |
|
| 92 | + 'func' => '_trash_or_restore_questions', |
|
| 93 | + 'capability' => 'ee_delete_questions', |
|
| 94 | + 'args' => array('trash' => false), |
|
| 95 | + 'noheader' => true, |
|
| 96 | + ), |
|
| 97 | + |
|
| 98 | + 'delete_questions' => array( |
|
| 99 | + 'func' => '_delete_questions', |
|
| 100 | + 'args' => array(), |
|
| 101 | + 'capability' => 'ee_delete_questions', |
|
| 102 | + 'noheader' => true, |
|
| 103 | + ), |
|
| 104 | + |
|
| 105 | + 'add_question_group' => array( |
|
| 106 | + 'func' => '_edit_question_group', |
|
| 107 | + 'capability' => 'ee_edit_question_groups', |
|
| 108 | + ), |
|
| 109 | + |
|
| 110 | + 'edit_question_group' => array( |
|
| 111 | + 'func' => '_edit_question_group', |
|
| 112 | + 'capability' => 'ee_edit_question_group', |
|
| 113 | + 'obj_id' => $qsg_id, |
|
| 114 | + 'args' => array('edit'), |
|
| 115 | + ), |
|
| 116 | + |
|
| 117 | + 'delete_question_groups' => array( |
|
| 118 | + 'func' => '_delete_question_groups', |
|
| 119 | + 'capability' => 'ee_delete_question_groups', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'delete_question_group' => array( |
|
| 124 | + 'func' => '_delete_question_groups', |
|
| 125 | + 'capability' => 'ee_delete_question_group', |
|
| 126 | + 'obj_id' => $qsg_id, |
|
| 127 | + 'noheader' => true, |
|
| 128 | + ), |
|
| 129 | + |
|
| 130 | + 'trash_question_group' => array( |
|
| 131 | + 'func' => '_trash_or_restore_question_groups', |
|
| 132 | + 'args' => array('trash' => true), |
|
| 133 | + 'capability' => 'ee_delete_question_group', |
|
| 134 | + 'obj_id' => $qsg_id, |
|
| 135 | + 'noheader' => true, |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'restore_question_group' => array( |
|
| 139 | + 'func' => '_trash_or_restore_question_groups', |
|
| 140 | + 'args' => array('trash' => false), |
|
| 141 | + 'capability' => 'ee_delete_question_group', |
|
| 142 | + 'obj_id' => $qsg_id, |
|
| 143 | + 'noheader' => true, |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + 'insert_question_group' => array( |
|
| 147 | + 'func' => '_insert_or_update_question_group', |
|
| 148 | + 'args' => array('new_question_group' => true), |
|
| 149 | + 'capability' => 'ee_edit_question_groups', |
|
| 150 | + 'noheader' => true, |
|
| 151 | + ), |
|
| 152 | + |
|
| 153 | + 'update_question_group' => array( |
|
| 154 | + 'func' => '_insert_or_update_question_group', |
|
| 155 | + 'args' => array('new_question_group' => false), |
|
| 156 | + 'capability' => 'ee_edit_question_group', |
|
| 157 | + 'obj_id' => $qsg_id, |
|
| 158 | + 'noheader' => true, |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + 'trash_question_groups' => array( |
|
| 162 | + 'func' => '_trash_or_restore_question_groups', |
|
| 163 | + 'args' => array('trash' => true), |
|
| 164 | + 'capability' => 'ee_delete_question_groups', |
|
| 165 | + 'noheader' => array('trash' => false), |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + 'restore_question_groups' => array( |
|
| 169 | + 'func' => '_trash_or_restore_question_groups', |
|
| 170 | + 'args' => array('trash' => false), |
|
| 171 | + 'capability' => 'ee_delete_question_groups', |
|
| 172 | + 'noheader' => true, |
|
| 173 | + ), |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + 'espresso_update_question_group_order' => array( |
|
| 177 | + 'func' => 'update_question_group_order', |
|
| 178 | + 'capability' => 'ee_edit_question_groups', |
|
| 179 | + 'noheader' => true, |
|
| 180 | + ), |
|
| 181 | + |
|
| 182 | + 'view_reg_form_settings' => array( |
|
| 183 | + 'func' => '_reg_form_settings', |
|
| 184 | + 'capability' => 'manage_options', |
|
| 185 | + ), |
|
| 186 | + |
|
| 187 | + 'update_reg_form_settings' => array( |
|
| 188 | + 'func' => '_update_reg_form_settings', |
|
| 189 | + 'capability' => 'manage_options', |
|
| 190 | + 'noheader' => true, |
|
| 191 | + ), |
|
| 192 | + ); |
|
| 193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | + |
|
| 195 | + $new_page_config = array( |
|
| 196 | + |
|
| 197 | + 'question_groups' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | + 'order' => 20, |
|
| 201 | + ), |
|
| 202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | + 'help_tabs' => array( |
|
| 204 | + 'registration_form_question_groups_help_tab' => array( |
|
| 205 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | + 'filename' => 'registration_form_question_groups', |
|
| 207 | + ), |
|
| 208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | + ), |
|
| 212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | + ), |
|
| 216 | + ), |
|
| 217 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 218 | + 'require_nonce' => false, |
|
| 219 | + ), |
|
| 220 | + |
|
| 221 | + 'add_question' => array( |
|
| 222 | + 'nav' => array( |
|
| 223 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 224 | + 'order' => 5, |
|
| 225 | + 'persistent' => false, |
|
| 226 | + ), |
|
| 227 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 228 | + 'help_tabs' => array( |
|
| 229 | + 'registration_form_add_question_help_tab' => array( |
|
| 230 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 231 | + 'filename' => 'registration_form_add_question', |
|
| 232 | + ), |
|
| 233 | + ), |
|
| 234 | + 'require_nonce' => false, |
|
| 235 | + ), |
|
| 236 | + |
|
| 237 | + 'add_question_group' => array( |
|
| 238 | + 'nav' => array( |
|
| 239 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 240 | + 'order' => 5, |
|
| 241 | + 'persistent' => false, |
|
| 242 | + ), |
|
| 243 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 244 | + 'help_tabs' => array( |
|
| 245 | + 'registration_form_add_question_group_help_tab' => array( |
|
| 246 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 247 | + 'filename' => 'registration_form_add_question_group', |
|
| 248 | + ), |
|
| 249 | + ), |
|
| 250 | + 'require_nonce' => false, |
|
| 251 | + ), |
|
| 252 | + |
|
| 253 | + 'edit_question_group' => array( |
|
| 254 | + 'nav' => array( |
|
| 255 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 256 | + 'order' => 5, |
|
| 257 | + 'persistent' => false, |
|
| 258 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 259 | + array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 260 | + $this->_current_page_view_url |
|
| 261 | + ) : $this->_admin_base_url, |
|
| 262 | + ), |
|
| 263 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 264 | + 'help_tabs' => array( |
|
| 265 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 266 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 267 | + 'filename' => 'registration_form_edit_question_group', |
|
| 268 | + ), |
|
| 269 | + ), |
|
| 270 | + 'require_nonce' => false, |
|
| 271 | + ), |
|
| 272 | + |
|
| 273 | + 'view_reg_form_settings' => array( |
|
| 274 | + 'nav' => array( |
|
| 275 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 276 | + 'order' => 40, |
|
| 277 | + ), |
|
| 278 | + 'labels' => array( |
|
| 279 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 280 | + ), |
|
| 281 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 282 | + 'help_tabs' => array( |
|
| 283 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
| 284 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 285 | + 'filename' => 'registration_form_reg_form_settings', |
|
| 286 | + ), |
|
| 287 | + ), |
|
| 288 | + 'require_nonce' => false, |
|
| 289 | + ), |
|
| 290 | + |
|
| 291 | + ); |
|
| 292 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 293 | + |
|
| 294 | + // change the list table we're going to use so it's the NEW list table! |
|
| 295 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + // additional labels |
|
| 299 | + $new_labels = array( |
|
| 300 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 301 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 302 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 303 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 304 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 305 | + ); |
|
| 306 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return void |
|
| 312 | + */ |
|
| 313 | + protected function _ajax_hooks() |
|
| 314 | + { |
|
| 315 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @return void |
|
| 321 | + */ |
|
| 322 | + public function load_scripts_styles_question_groups() |
|
| 323 | + { |
|
| 324 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @return void |
|
| 330 | + */ |
|
| 331 | + public function load_scripts_styles_add_question_group() |
|
| 332 | + { |
|
| 333 | + $this->load_scripts_styles_forms(); |
|
| 334 | + $this->load_sortable_question_script(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @return void |
|
| 340 | + */ |
|
| 341 | + public function load_scripts_styles_edit_question_group() |
|
| 342 | + { |
|
| 343 | + $this->load_scripts_styles_forms(); |
|
| 344 | + $this->load_sortable_question_script(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * registers and enqueues script for questions |
|
| 350 | + * |
|
| 351 | + * @return void |
|
| 352 | + */ |
|
| 353 | + public function load_sortable_question_script() |
|
| 354 | + { |
|
| 355 | + wp_register_script( |
|
| 356 | + 'ee-question-sortable', |
|
| 357 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 358 | + array('jquery-ui-sortable'), |
|
| 359 | + EVENT_ESPRESSO_VERSION, |
|
| 360 | + true |
|
| 361 | + ); |
|
| 362 | + wp_enqueue_script('ee-question-sortable'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + protected function _set_list_table_views_default() |
|
| 370 | + { |
|
| 371 | + $this->_views = array( |
|
| 372 | + 'all' => array( |
|
| 373 | + 'slug' => 'all', |
|
| 374 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 375 | + 'count' => 0, |
|
| 376 | + 'bulk_action' => array( |
|
| 377 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 378 | + ), |
|
| 379 | + ), |
|
| 380 | + ); |
|
| 381 | + |
|
| 382 | + if ( |
|
| 383 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 384 | + 'ee_delete_questions', |
|
| 385 | + 'espresso_registration_form_trash_questions' |
|
| 386 | + ) |
|
| 387 | + ) { |
|
| 388 | + $this->_views['trash'] = array( |
|
| 389 | + 'slug' => 'trash', |
|
| 390 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 391 | + 'count' => 0, |
|
| 392 | + 'bulk_action' => array( |
|
| 393 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 394 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 395 | + ), |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @return void |
|
| 403 | + */ |
|
| 404 | + protected function _set_list_table_views_question_groups() |
|
| 405 | + { |
|
| 406 | + $this->_views = array( |
|
| 407 | + 'all' => array( |
|
| 408 | + 'slug' => 'all', |
|
| 409 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 410 | + 'count' => 0, |
|
| 411 | + 'bulk_action' => array( |
|
| 412 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 413 | + ), |
|
| 414 | + ), |
|
| 415 | + ); |
|
| 416 | + |
|
| 417 | + if ( |
|
| 418 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 419 | + 'ee_delete_question_groups', |
|
| 420 | + 'espresso_registration_form_trash_question_groups' |
|
| 421 | + ) |
|
| 422 | + ) { |
|
| 423 | + $this->_views['trash'] = array( |
|
| 424 | + 'slug' => 'trash', |
|
| 425 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 426 | + 'count' => 0, |
|
| 427 | + 'bulk_action' => array( |
|
| 428 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 429 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 430 | + ), |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @return void |
|
| 438 | + * @throws EE_Error |
|
| 439 | + * @throws InvalidArgumentException |
|
| 440 | + * @throws InvalidDataTypeException |
|
| 441 | + * @throws InvalidInterfaceException |
|
| 442 | + */ |
|
| 443 | + protected function _questions_overview_list_table() |
|
| 444 | + { |
|
| 445 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 446 | + 'add_question', |
|
| 447 | + 'add_question', |
|
| 448 | + array(), |
|
| 449 | + 'add-new-h2' |
|
| 450 | + ); |
|
| 451 | + parent::_questions_overview_list_table(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @return void |
|
| 457 | + * @throws DomainException |
|
| 458 | + * @throws EE_Error |
|
| 459 | + * @throws InvalidArgumentException |
|
| 460 | + * @throws InvalidDataTypeException |
|
| 461 | + * @throws InvalidInterfaceException |
|
| 462 | + */ |
|
| 463 | + protected function _question_groups_overview_list_table() |
|
| 464 | + { |
|
| 465 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 466 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 467 | + 'add_question_group', |
|
| 468 | + 'add_question_group', |
|
| 469 | + array(), |
|
| 470 | + 'add-new-h2' |
|
| 471 | + ); |
|
| 472 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * @return void |
|
| 478 | + * @throws EE_Error |
|
| 479 | + * @throws InvalidArgumentException |
|
| 480 | + * @throws InvalidDataTypeException |
|
| 481 | + * @throws InvalidInterfaceException |
|
| 482 | + */ |
|
| 483 | + protected function _delete_question() |
|
| 484 | + { |
|
| 485 | + $success = $this->_delete_items($this->_question_model); |
|
| 486 | + $this->_redirect_after_action( |
|
| 487 | + $success, |
|
| 488 | + $this->_question_model->item_name($success), |
|
| 489 | + 'deleted', |
|
| 490 | + array('action' => 'default', 'status' => 'all') |
|
| 491 | + ); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @return void |
|
| 497 | + * @throws EE_Error |
|
| 498 | + * @throws InvalidArgumentException |
|
| 499 | + * @throws InvalidDataTypeException |
|
| 500 | + * @throws InvalidInterfaceException |
|
| 501 | + */ |
|
| 502 | + protected function _delete_questions() |
|
| 503 | + { |
|
| 504 | + $success = $this->_delete_items($this->_question_model); |
|
| 505 | + $this->_redirect_after_action( |
|
| 506 | + $success, |
|
| 507 | + $this->_question_model->item_name($success), |
|
| 508 | + 'deleted permanently', |
|
| 509 | + array('action' => 'default', 'status' => 'trash') |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Performs the deletion of a single or multiple questions or question groups. |
|
| 516 | + * |
|
| 517 | + * @param EEM_Soft_Delete_Base $model |
|
| 518 | + * @return int number of items deleted permanently |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws InvalidArgumentException |
|
| 521 | + * @throws InvalidDataTypeException |
|
| 522 | + * @throws InvalidInterfaceException |
|
| 523 | + */ |
|
| 524 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 525 | + { |
|
| 526 | + $success = 0; |
|
| 527 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 528 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 529 | + // if array has more than one element than success message should be plural |
|
| 530 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 531 | + // cycle thru bulk action checkboxes |
|
| 532 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 533 | + if (! $this->_delete_item($ID, $model)) { |
|
| 534 | + $success = 0; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 538 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 539 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 540 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 541 | + } else { |
|
| 542 | + EE_Error::add_error( |
|
| 543 | + sprintf( |
|
| 544 | + esc_html__( |
|
| 545 | + "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 546 | + "event_espresso" |
|
| 547 | + ) |
|
| 548 | + ), |
|
| 549 | + __FILE__, |
|
| 550 | + __FUNCTION__, |
|
| 551 | + __LINE__ |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return $success; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Deletes the specified question (and its associated question options) or question group |
|
| 560 | + * |
|
| 561 | + * @param int $id |
|
| 562 | + * @param EEM_Soft_Delete_Base $model |
|
| 563 | + * @return boolean |
|
| 564 | + * @throws EE_Error |
|
| 565 | + * @throws InvalidArgumentException |
|
| 566 | + * @throws InvalidDataTypeException |
|
| 567 | + * @throws InvalidInterfaceException |
|
| 568 | + */ |
|
| 569 | + protected function _delete_item($id, $model) |
|
| 570 | + { |
|
| 571 | + if ($model instanceof EEM_Question) { |
|
| 572 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 573 | + } |
|
| 574 | + return $model->delete_permanently_by_ID(absint($id)); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /****************************** QUESTION GROUPS ******************************/ |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @param string $type |
|
| 583 | + * @return void |
|
| 584 | + * @throws DomainException |
|
| 585 | + * @throws EE_Error |
|
| 586 | + * @throws InvalidArgumentException |
|
| 587 | + * @throws InvalidDataTypeException |
|
| 588 | + * @throws InvalidInterfaceException |
|
| 589 | + */ |
|
| 590 | + protected function _edit_question_group($type = 'add') |
|
| 591 | + { |
|
| 592 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 593 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 594 | + ? absint($this->_req_data['QSG_ID']) |
|
| 595 | + : false; |
|
| 596 | + |
|
| 597 | + switch ($this->_req_action) { |
|
| 598 | + case 'add_question_group': |
|
| 599 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 600 | + break; |
|
| 601 | + case 'edit_question_group': |
|
| 602 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 603 | + break; |
|
| 604 | + default: |
|
| 605 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 606 | + } |
|
| 607 | + // add ID to title if editing |
|
| 608 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 609 | + if ($ID) { |
|
| 610 | + /** @var EE_Question_Group $questionGroup */ |
|
| 611 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 612 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 613 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 614 | + } else { |
|
| 615 | + /** @var EE_Question_Group $questionGroup */ |
|
| 616 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 617 | + $questionGroup->set_order_to_latest(); |
|
| 618 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 619 | + } |
|
| 620 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 621 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 622 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 623 | + $this->_template_args['question_group'] = $questionGroup; |
|
| 624 | + |
|
| 625 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 626 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 627 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 628 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 629 | + $this->_template_args, |
|
| 630 | + true |
|
| 631 | + ); |
|
| 632 | + |
|
| 633 | + // the details template wrapper |
|
| 634 | + $this->display_admin_page_with_sidebar(); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * @return void |
|
| 640 | + * @throws EE_Error |
|
| 641 | + * @throws InvalidArgumentException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws InvalidInterfaceException |
|
| 644 | + */ |
|
| 645 | + protected function _delete_question_groups() |
|
| 646 | + { |
|
| 647 | + $success = $this->_delete_items($this->_question_group_model); |
|
| 648 | + $this->_redirect_after_action( |
|
| 649 | + $success, |
|
| 650 | + $this->_question_group_model->item_name($success), |
|
| 651 | + 'deleted permanently', |
|
| 652 | + array('action' => 'question_groups', 'status' => 'trash') |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * @param bool $new_question_group |
|
| 659 | + * @throws EE_Error |
|
| 660 | + * @throws InvalidArgumentException |
|
| 661 | + * @throws InvalidDataTypeException |
|
| 662 | + * @throws InvalidInterfaceException |
|
| 663 | + */ |
|
| 664 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
| 665 | + { |
|
| 666 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 667 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 668 | + |
|
| 669 | + // make sure identifier is unique |
|
| 670 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 671 | + $where_values = ['QSG_identifier' => $set_column_values['QSG_identifier']]; |
|
| 672 | + if (! $new_question_group && isset($set_column_values['QSG_ID'])) { |
|
| 673 | + $where_values['QSG_ID'] = ['!=', $set_column_values['QSG_ID']]; |
|
| 674 | + } |
|
| 675 | + $identifier_exists = ! empty($identifier_value) |
|
| 676 | + ? $this->_question_group_model->count([$where_values]) > 0 |
|
| 677 | + : false; |
|
| 678 | + if ($identifier_exists) { |
|
| 679 | + $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if ($new_question_group) { |
|
| 683 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 684 | + $success = $QSG_ID ? 1 : 0; |
|
| 685 | + if ($success === 0) { |
|
| 686 | + EE_Error::add_error( |
|
| 687 | + esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 688 | + __FILE__, |
|
| 689 | + __FUNCTION__, |
|
| 690 | + __LINE__ |
|
| 691 | + ); |
|
| 692 | + $this->_redirect_after_action( |
|
| 693 | + false, |
|
| 694 | + '', |
|
| 695 | + '', |
|
| 696 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 697 | + true |
|
| 698 | + ); |
|
| 699 | + } |
|
| 700 | + } else { |
|
| 701 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 702 | + unset($set_column_values['QSG_ID']); |
|
| 703 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 707 | + EEM_Attendee::system_question_phone |
|
| 708 | + ); |
|
| 709 | + // update the existing related questions |
|
| 710 | + // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 711 | + // if it is being added to this question group (therefore removed from the existing group) |
|
| 712 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 713 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 714 | + EEM_Question_Group_Question::instance()->delete( |
|
| 715 | + array( |
|
| 716 | + array( |
|
| 717 | + 'QST_ID' => $phone_question_id, |
|
| 718 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
| 719 | + ), |
|
| 720 | + ) |
|
| 721 | + ); |
|
| 722 | + } |
|
| 723 | + /** @type EE_Question_Group $question_group */ |
|
| 724 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 725 | + $questions = $question_group->questions(); |
|
| 726 | + // make sure system phone question is added to list of questions for this group |
|
| 727 | + if (! isset($questions[ $phone_question_id ])) { |
|
| 728 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + foreach ($questions as $question_ID => $question) { |
|
| 732 | + // first we always check for order. |
|
| 733 | + if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 734 | + // update question order |
|
| 735 | + $question_group->update_question_order( |
|
| 736 | + $question_ID, |
|
| 737 | + $this->_req_data['question_orders'][ $question_ID ] |
|
| 738 | + ); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + // then we always check if adding or removing. |
|
| 742 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 743 | + $question_group->add_question($question_ID); |
|
| 744 | + } else { |
|
| 745 | + // not found, remove it (but only if not a system question for the personal group |
|
| 746 | + // with the exception of lname system question - we allow removal of it) |
|
| 747 | + if ( |
|
| 748 | + in_array( |
|
| 749 | + $question->system_ID(), |
|
| 750 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 751 | + $question_group->system_group() |
|
| 752 | + ) |
|
| 753 | + ) |
|
| 754 | + ) { |
|
| 755 | + continue; |
|
| 756 | + } else { |
|
| 757 | + $question_group->remove_question($question_ID); |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + // save new related questions |
|
| 762 | + if (isset($this->_req_data['questions'])) { |
|
| 763 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 764 | + $question_group->add_question($QST_ID); |
|
| 765 | + if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 766 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + if ($success !== false) { |
|
| 772 | + $msg = $new_question_group |
|
| 773 | + ? sprintf( |
|
| 774 | + esc_html__('The %s has been created', 'event_espresso'), |
|
| 775 | + $this->_question_group_model->item_name() |
|
| 776 | + ) |
|
| 777 | + : sprintf( |
|
| 778 | + esc_html__( |
|
| 779 | + 'The %s has been updated', |
|
| 780 | + 'event_espresso' |
|
| 781 | + ), |
|
| 782 | + $this->_question_group_model->item_name() |
|
| 783 | + ); |
|
| 784 | + EE_Error::add_success($msg); |
|
| 785 | + } |
|
| 786 | + $this->_redirect_after_action( |
|
| 787 | + false, |
|
| 788 | + '', |
|
| 789 | + '', |
|
| 790 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 791 | + true |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * duplicates a question and all its question options and redirects to the new question. |
|
| 798 | + * |
|
| 799 | + * @return void |
|
| 800 | + * @throws EE_Error |
|
| 801 | + * @throws InvalidArgumentException |
|
| 802 | + * @throws ReflectionException |
|
| 803 | + * @throws InvalidDataTypeException |
|
| 804 | + * @throws InvalidInterfaceException |
|
| 805 | + */ |
|
| 806 | + public function _duplicate_question() |
|
| 807 | + { |
|
| 808 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 809 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 810 | + if ($question instanceof EE_Question) { |
|
| 811 | + $new_question = $question->duplicate(); |
|
| 812 | + if ($new_question instanceof EE_Question) { |
|
| 813 | + $this->_redirect_after_action( |
|
| 814 | + true, |
|
| 815 | + esc_html__('Question', 'event_espresso'), |
|
| 816 | + esc_html__('Duplicated', 'event_espresso'), |
|
| 817 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 818 | + true |
|
| 819 | + ); |
|
| 820 | + } else { |
|
| 821 | + global $wpdb; |
|
| 822 | + EE_Error::add_error( |
|
| 823 | + sprintf( |
|
| 824 | + esc_html__( |
|
| 825 | + 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 826 | + 'event_espresso' |
|
| 827 | + ), |
|
| 828 | + $question_ID, |
|
| 829 | + $wpdb->last_error |
|
| 830 | + ), |
|
| 831 | + __FILE__, |
|
| 832 | + __FUNCTION__, |
|
| 833 | + __LINE__ |
|
| 834 | + ); |
|
| 835 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 836 | + } |
|
| 837 | + } else { |
|
| 838 | + EE_Error::add_error( |
|
| 839 | + sprintf( |
|
| 840 | + esc_html__( |
|
| 841 | + 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 842 | + 'event_espresso' |
|
| 843 | + ), |
|
| 844 | + $question_ID |
|
| 845 | + ), |
|
| 846 | + __FILE__, |
|
| 847 | + __FUNCTION__, |
|
| 848 | + __LINE__ |
|
| 849 | + ); |
|
| 850 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 851 | + } |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * @param bool $trash |
|
| 857 | + * @throws EE_Error |
|
| 858 | + */ |
|
| 859 | + protected function _trash_or_restore_question_groups($trash = true) |
|
| 860 | + { |
|
| 861 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + *_trash_question |
|
| 867 | + * |
|
| 868 | + * @return void |
|
| 869 | + * @throws EE_Error |
|
| 870 | + */ |
|
| 871 | + protected function _trash_question() |
|
| 872 | + { |
|
| 873 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 874 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 875 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * @param bool $trash |
|
| 881 | + * @throws EE_Error |
|
| 882 | + */ |
|
| 883 | + protected function _trash_or_restore_questions($trash = true) |
|
| 884 | + { |
|
| 885 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
| 891 | + * flexible between question or question groups |
|
| 892 | + * |
|
| 893 | + * @param EEM_Soft_Delete_Base $model |
|
| 894 | + * @param boolean $trash whether to trash or restore |
|
| 895 | + * @throws EE_Error |
|
| 896 | + */ |
|
| 897 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 898 | + { |
|
| 899 | + |
|
| 900 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 901 | + |
|
| 902 | + $success = 1; |
|
| 903 | + // Checkboxes |
|
| 904 | + // echo "trash $trash"; |
|
| 905 | + // var_dump($this->_req_data['checkbox']);die; |
|
| 906 | + if (isset($this->_req_data['checkbox'])) { |
|
| 907 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 908 | + // if array has more than one element than success message should be plural |
|
| 909 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 910 | + // cycle thru bulk action checkboxes |
|
| 911 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 912 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 913 | + $success = 0; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + } else { |
|
| 917 | + // grab single id and delete |
|
| 918 | + $ID = absint($this->_req_data['checkbox']); |
|
| 919 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 920 | + $success = 0; |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + } else { |
|
| 924 | + // delete via trash link |
|
| 925 | + // grab single id and delete |
|
| 926 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 927 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 928 | + $success = 0; |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + |
|
| 933 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 934 | + // echo "action :$action"; |
|
| 935 | + // $action = 'questions' ? 'default' : $action; |
|
| 936 | + if ($trash) { |
|
| 937 | + $action_desc = 'trashed'; |
|
| 938 | + $status = 'trash'; |
|
| 939 | + } else { |
|
| 940 | + $action_desc = 'restored'; |
|
| 941 | + $status = 'all'; |
|
| 942 | + } |
|
| 943 | + $this->_redirect_after_action( |
|
| 944 | + $success, |
|
| 945 | + $model->item_name($success), |
|
| 946 | + $action_desc, |
|
| 947 | + array('action' => $action, 'status' => $status) |
|
| 948 | + ); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * @param $per_page |
|
| 954 | + * @param int $current_page |
|
| 955 | + * @param bool|false $count |
|
| 956 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 957 | + * @throws EE_Error |
|
| 958 | + * @throws InvalidArgumentException |
|
| 959 | + * @throws InvalidDataTypeException |
|
| 960 | + * @throws InvalidInterfaceException |
|
| 961 | + */ |
|
| 962 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 963 | + { |
|
| 964 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 965 | + |
|
| 966 | + if ($count) { |
|
| 967 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 968 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 969 | + $results = $this->_question_model->count_deleted($where); |
|
| 970 | + } else { |
|
| 971 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 972 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
| 973 | + } |
|
| 974 | + return $results; |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * @param $per_page |
|
| 980 | + * @param int $current_page |
|
| 981 | + * @param bool|false $count |
|
| 982 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 983 | + * @throws EE_Error |
|
| 984 | + * @throws InvalidArgumentException |
|
| 985 | + * @throws InvalidDataTypeException |
|
| 986 | + * @throws InvalidInterfaceException |
|
| 987 | + */ |
|
| 988 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 989 | + { |
|
| 990 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 991 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 992 | + if ($count) { |
|
| 993 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 994 | + $results = $questionGroupModel->count($where); |
|
| 995 | + } else { |
|
| 996 | + $results = $questionGroupModel->get_all($query_params); |
|
| 997 | + } |
|
| 998 | + return $results; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * @param $per_page |
|
| 1004 | + * @param int $current_page |
|
| 1005 | + * @param bool $count |
|
| 1006 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1007 | + * @throws EE_Error |
|
| 1008 | + * @throws InvalidArgumentException |
|
| 1009 | + * @throws InvalidDataTypeException |
|
| 1010 | + * @throws InvalidInterfaceException |
|
| 1011 | + */ |
|
| 1012 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1013 | + { |
|
| 1014 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1015 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1016 | + if ($count) { |
|
| 1017 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1018 | + $query_params['limit'] = null; |
|
| 1019 | + $results = $questionGroupModel->count_deleted($where); |
|
| 1020 | + } else { |
|
| 1021 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1022 | + } |
|
| 1023 | + return $results; |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * method for performing updates to question order |
|
| 1029 | + * |
|
| 1030 | + * @return void results array |
|
| 1031 | + * @throws EE_Error |
|
| 1032 | + * @throws InvalidArgumentException |
|
| 1033 | + * @throws InvalidDataTypeException |
|
| 1034 | + * @throws InvalidInterfaceException |
|
| 1035 | + */ |
|
| 1036 | + public function update_question_group_order() |
|
| 1037 | + { |
|
| 1038 | + |
|
| 1039 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1040 | + |
|
| 1041 | + // grab our row IDs |
|
| 1042 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1043 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1044 | + : array(); |
|
| 1045 | + |
|
| 1046 | + $perpage = ! empty($this->_req_data['perpage']) |
|
| 1047 | + ? (int) $this->_req_data['perpage'] |
|
| 1048 | + : null; |
|
| 1049 | + $curpage = ! empty($this->_req_data['curpage']) |
|
| 1050 | + ? (int) $this->_req_data['curpage'] |
|
| 1051 | + : null; |
|
| 1052 | + |
|
| 1053 | + if (! empty($row_ids)) { |
|
| 1054 | + // figure out where we start the row_id count at for the current page. |
|
| 1055 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1056 | + |
|
| 1057 | + $row_count = count($row_ids); |
|
| 1058 | + for ($i = 0; $i < $row_count; $i++) { |
|
| 1059 | + // Update the questions when re-ordering |
|
| 1060 | + $updated = EEM_Question_Group::instance()->update( |
|
| 1061 | + array('QSG_order' => $qsgcount), |
|
| 1062 | + array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1063 | + ); |
|
| 1064 | + if ($updated === false) { |
|
| 1065 | + $success = false; |
|
| 1066 | + } |
|
| 1067 | + $qsgcount++; |
|
| 1068 | + } |
|
| 1069 | + } else { |
|
| 1070 | + $success = false; |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + $errors = ! $success |
|
| 1074 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1075 | + : false; |
|
| 1076 | + |
|
| 1077 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1078 | + die(); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * @throws DomainException |
|
| 1088 | + * @throws EE_Error |
|
| 1089 | + * @throws InvalidArgumentException |
|
| 1090 | + * @throws InvalidDataTypeException |
|
| 1091 | + * @throws InvalidInterfaceException |
|
| 1092 | + */ |
|
| 1093 | + protected function _reg_form_settings() |
|
| 1094 | + { |
|
| 1095 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1096 | + add_action( |
|
| 1097 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1098 | + array($this, 'email_validation_settings_form'), |
|
| 1099 | + 2 |
|
| 1100 | + ); |
|
| 1101 | + add_action( |
|
| 1102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1103 | + array($this, 'copy_attendee_info_settings_form'), |
|
| 1104 | + 4 |
|
| 1105 | + ); |
|
| 1106 | + $this->_template_args = (array) apply_filters( |
|
| 1107 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1108 | + $this->_template_args |
|
| 1109 | + ); |
|
| 1110 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1111 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1112 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1113 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1114 | + $this->_template_args, |
|
| 1115 | + true |
|
| 1116 | + ); |
|
| 1117 | + $this->display_admin_page_with_sidebar(); |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + |
|
| 1121 | + /** |
|
| 1122 | + * @return void |
|
| 1123 | + * @throws EE_Error |
|
| 1124 | + * @throws InvalidArgumentException |
|
| 1125 | + * @throws ReflectionException |
|
| 1126 | + * @throws InvalidDataTypeException |
|
| 1127 | + * @throws InvalidInterfaceException |
|
| 1128 | + */ |
|
| 1129 | + protected function _update_reg_form_settings() |
|
| 1130 | + { |
|
| 1131 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1132 | + EE_Registry::instance()->CFG->registration |
|
| 1133 | + ); |
|
| 1134 | + EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
| 1135 | + EE_Registry::instance()->CFG->registration |
|
| 1136 | + ); |
|
| 1137 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1138 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1139 | + EE_Registry::instance()->CFG->registration |
|
| 1140 | + ); |
|
| 1141 | + $success = $this->_update_espresso_configuration( |
|
| 1142 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1143 | + EE_Registry::instance()->CFG, |
|
| 1144 | + __FILE__, |
|
| 1145 | + __FUNCTION__, |
|
| 1146 | + __LINE__ |
|
| 1147 | + ); |
|
| 1148 | + $this->_redirect_after_action( |
|
| 1149 | + $success, |
|
| 1150 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1151 | + 'updated', |
|
| 1152 | + array('action' => 'view_reg_form_settings') |
|
| 1153 | + ); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * @return void |
|
| 1159 | + * @throws EE_Error |
|
| 1160 | + * @throws InvalidArgumentException |
|
| 1161 | + * @throws InvalidDataTypeException |
|
| 1162 | + * @throws InvalidInterfaceException |
|
| 1163 | + */ |
|
| 1164 | + public function copy_attendee_info_settings_form() |
|
| 1165 | + { |
|
| 1166 | + echo wp_kses($this->_copy_attendee_info_settings_form()->get_html(), AllowedTags::getWithFormTags()); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * _copy_attendee_info_settings_form |
|
| 1171 | + * |
|
| 1172 | + * @access protected |
|
| 1173 | + * @return EE_Form_Section_Proper |
|
| 1174 | + * @throws \EE_Error |
|
| 1175 | + */ |
|
| 1176 | + protected function _copy_attendee_info_settings_form() |
|
| 1177 | + { |
|
| 1178 | + return new EE_Form_Section_Proper( |
|
| 1179 | + array( |
|
| 1180 | + 'name' => 'copy_attendee_info_settings', |
|
| 1181 | + 'html_id' => 'copy_attendee_info_settings', |
|
| 1182 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1183 | + 'subsections' => apply_filters( |
|
| 1184 | + 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
| 1185 | + array( |
|
| 1186 | + 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
| 1187 | + EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
| 1188 | + ), |
|
| 1189 | + 'copy_attendee_info' => new EE_Yes_No_Input( |
|
| 1190 | + array( |
|
| 1191 | + 'html_label_text' => esc_html__( |
|
| 1192 | + 'Allow copy #1 attendee info to extra attendees?', |
|
| 1193 | + 'event_espresso' |
|
| 1194 | + ), |
|
| 1195 | + 'html_help_text' => esc_html__( |
|
| 1196 | + 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
| 1197 | + 'event_espresso' |
|
| 1198 | + ), |
|
| 1199 | + 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
| 1200 | + 'required' => false, |
|
| 1201 | + 'display_html_label_text' => false, |
|
| 1202 | + ) |
|
| 1203 | + ), |
|
| 1204 | + ) |
|
| 1205 | + ), |
|
| 1206 | + ) |
|
| 1207 | + ); |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1212 | + * @return EE_Registration_Config |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + * @throws InvalidArgumentException |
|
| 1215 | + * @throws ReflectionException |
|
| 1216 | + * @throws InvalidDataTypeException |
|
| 1217 | + * @throws InvalidInterfaceException |
|
| 1218 | + */ |
|
| 1219 | + public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1220 | + { |
|
| 1221 | + $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
| 1222 | + try { |
|
| 1223 | + $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
| 1224 | + // if not displaying a form, then check for form submission |
|
| 1225 | + if ($copy_attendee_info_settings_form->was_submitted()) { |
|
| 1226 | + // capture form data |
|
| 1227 | + $copy_attendee_info_settings_form->receive_form_submission(); |
|
| 1228 | + // validate form data |
|
| 1229 | + if ($copy_attendee_info_settings_form->is_valid()) { |
|
| 1230 | + // grab validated data from form |
|
| 1231 | + $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
| 1232 | + if (isset($valid_data['copy_attendee_info'])) { |
|
| 1233 | + $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
| 1234 | + } else { |
|
| 1235 | + EE_Error::add_error( |
|
| 1236 | + esc_html__( |
|
| 1237 | + 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
| 1238 | + 'event_espresso' |
|
| 1239 | + ), |
|
| 1240 | + __FILE__, |
|
| 1241 | + __FUNCTION__, |
|
| 1242 | + __LINE__ |
|
| 1243 | + ); |
|
| 1244 | + } |
|
| 1245 | + } else { |
|
| 1246 | + if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
| 1247 | + EE_Error::add_error( |
|
| 1248 | + $copy_attendee_info_settings_form->submission_error_message(), |
|
| 1249 | + __FILE__, |
|
| 1250 | + __FUNCTION__, |
|
| 1251 | + __LINE__ |
|
| 1252 | + ); |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + } catch (EE_Error $e) { |
|
| 1257 | + $e->get_error(); |
|
| 1258 | + } |
|
| 1259 | + return $EE_Registration_Config; |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + |
|
| 1263 | + /** |
|
| 1264 | + * @return void |
|
| 1265 | + * @throws EE_Error |
|
| 1266 | + * @throws InvalidArgumentException |
|
| 1267 | + * @throws InvalidDataTypeException |
|
| 1268 | + * @throws InvalidInterfaceException |
|
| 1269 | + */ |
|
| 1270 | + public function email_validation_settings_form() |
|
| 1271 | + { |
|
| 1272 | + echo wp_kses($this->_email_validation_settings_form()->get_html(), AllowedTags::getWithFormTags()); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * _email_validation_settings_form |
|
| 1278 | + * |
|
| 1279 | + * @access protected |
|
| 1280 | + * @return EE_Form_Section_Proper |
|
| 1281 | + * @throws \EE_Error |
|
| 1282 | + */ |
|
| 1283 | + protected function _email_validation_settings_form() |
|
| 1284 | + { |
|
| 1285 | + return new EE_Form_Section_Proper( |
|
| 1286 | + array( |
|
| 1287 | + 'name' => 'email_validation_settings', |
|
| 1288 | + 'html_id' => 'email_validation_settings', |
|
| 1289 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1290 | + 'subsections' => apply_filters( |
|
| 1291 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1292 | + array( |
|
| 1293 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1294 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1295 | + ), |
|
| 1296 | + 'email_validation_level' => new EE_Select_Input( |
|
| 1297 | + array( |
|
| 1298 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1299 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1300 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1301 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1302 | + ), |
|
| 1303 | + array( |
|
| 1304 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1305 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1306 | + 'html_help_text' => esc_html__( |
|
| 1307 | + 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1308 | + 'event_espresso' |
|
| 1309 | + ), |
|
| 1310 | + 'default' => isset( |
|
| 1311 | + EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1312 | + ) |
|
| 1313 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1314 | + : 'wp_default', |
|
| 1315 | + 'required' => false, |
|
| 1316 | + ) |
|
| 1317 | + ), |
|
| 1318 | + ) |
|
| 1319 | + ), |
|
| 1320 | + ) |
|
| 1321 | + ); |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1327 | + * @return EE_Registration_Config |
|
| 1328 | + * @throws EE_Error |
|
| 1329 | + * @throws InvalidArgumentException |
|
| 1330 | + * @throws ReflectionException |
|
| 1331 | + * @throws InvalidDataTypeException |
|
| 1332 | + * @throws InvalidInterfaceException |
|
| 1333 | + */ |
|
| 1334 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1335 | + { |
|
| 1336 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1337 | + try { |
|
| 1338 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1339 | + // if not displaying a form, then check for form submission |
|
| 1340 | + if ($email_validation_settings_form->was_submitted()) { |
|
| 1341 | + // capture form data |
|
| 1342 | + $email_validation_settings_form->receive_form_submission(); |
|
| 1343 | + // validate form data |
|
| 1344 | + if ($email_validation_settings_form->is_valid()) { |
|
| 1345 | + // grab validated data from form |
|
| 1346 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1347 | + if (isset($valid_data['email_validation_level'])) { |
|
| 1348 | + $email_validation_level = $valid_data['email_validation_level']; |
|
| 1349 | + // now if they want to use international email addresses |
|
| 1350 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1351 | + // in case we need to reset their email validation level, |
|
| 1352 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1353 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1354 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1355 | + // despite offering poor validation, supports i18n email addresses |
|
| 1356 | + $prev_email_validation_level = 'basic'; |
|
| 1357 | + } |
|
| 1358 | + // confirm our i18n email validation will work on the server |
|
| 1359 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1360 | + // or reset email validation level to previous value |
|
| 1361 | + $email_validation_level = $prev_email_validation_level; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1365 | + } else { |
|
| 1366 | + EE_Error::add_error( |
|
| 1367 | + esc_html__( |
|
| 1368 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1369 | + 'event_espresso' |
|
| 1370 | + ), |
|
| 1371 | + __FILE__, |
|
| 1372 | + __FUNCTION__, |
|
| 1373 | + __LINE__ |
|
| 1374 | + ); |
|
| 1375 | + } |
|
| 1376 | + } else { |
|
| 1377 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1378 | + EE_Error::add_error( |
|
| 1379 | + $email_validation_settings_form->submission_error_message(), |
|
| 1380 | + __FILE__, |
|
| 1381 | + __FUNCTION__, |
|
| 1382 | + __LINE__ |
|
| 1383 | + ); |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + } catch (EE_Error $e) { |
|
| 1388 | + $e->get_error(); |
|
| 1389 | + } |
|
| 1390 | + return $EE_Registration_Config; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1396 | + * and that the PCRE version works with our i18n email validation |
|
| 1397 | + * |
|
| 1398 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1399 | + * @param string $email_validation_level |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1403 | + { |
|
| 1404 | + // first check that PCRE is enabled |
|
| 1405 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1406 | + EE_Error::add_error( |
|
| 1407 | + sprintf( |
|
| 1408 | + esc_html__( |
|
| 1409 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1410 | + 'event_espresso' |
|
| 1411 | + ), |
|
| 1412 | + '<br />' |
|
| 1413 | + ), |
|
| 1414 | + __FILE__, |
|
| 1415 | + __FUNCTION__, |
|
| 1416 | + __LINE__ |
|
| 1417 | + ); |
|
| 1418 | + return false; |
|
| 1419 | + } else { |
|
| 1420 | + // PCRE support is enabled, but let's still |
|
| 1421 | + // perform a test to see if the server will support it. |
|
| 1422 | + // but first, save the updated validation level to the config, |
|
| 1423 | + // so that the validation strategy picks it up. |
|
| 1424 | + // this will get bumped back down if it doesn't work |
|
| 1425 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1426 | + try { |
|
| 1427 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1428 | + $i18n_email_address = apply_filters( |
|
| 1429 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1430 | + 'jägerjü[email protected]' |
|
| 1431 | + ); |
|
| 1432 | + $email_validator->validate($i18n_email_address); |
|
| 1433 | + } catch (Exception $e) { |
|
| 1434 | + EE_Error::add_error( |
|
| 1435 | + sprintf( |
|
| 1436 | + esc_html__( |
|
| 1437 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1438 | + 'event_espresso' |
|
| 1439 | + ), |
|
| 1440 | + '<br />', |
|
| 1441 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1442 | + ), |
|
| 1443 | + __FILE__, |
|
| 1444 | + __FUNCTION__, |
|
| 1445 | + __LINE__ |
|
| 1446 | + ); |
|
| 1447 | + return false; |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + return true; |
|
| 1451 | + } |
|
| 1452 | 1452 | } |
@@ -26,9 +26,9 @@ |
||
| 26 | 26 | <?php echo wp_kses($nav_tabs, AllowedTags::getWithFormTags()); ?> |
| 27 | 27 | |
| 28 | 28 | <?php |
| 29 | - do_action('AHEE__admin_wrapper__template__before_about_admin_page_content'); |
|
| 30 | - echo wp_kses($about_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 31 | - do_action('AHEE__admin_wrapper__template__after_about_admin_page_content'); |
|
| 32 | - ?> |
|
| 29 | + do_action('AHEE__admin_wrapper__template__before_about_admin_page_content'); |
|
| 30 | + echo wp_kses($about_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 31 | + do_action('AHEE__admin_wrapper__template__after_about_admin_page_content'); |
|
| 32 | + ?> |
|
| 33 | 33 | |
| 34 | 34 | </div> |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | <?php echo wp_kses($nav_tabs, AllowedTags::getWithFormTags()); ?> |
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | - do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
| 25 | - echo wp_kses($before_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 26 | - echo wp_kses($admin_page_content, AllowedTags::getWithFormTags()); |
|
| 27 | - echo wp_kses($after_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 28 | - do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
| 29 | - ?> |
|
| 24 | + do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
| 25 | + echo wp_kses($before_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 26 | + echo wp_kses($admin_page_content, AllowedTags::getWithFormTags()); |
|
| 27 | + echo wp_kses($after_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 28 | + do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
| 29 | + ?> |
|
| 30 | 30 | |
| 31 | 31 | </div> |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | |
| 18 | 18 | <div class="ee-notices"><?php echo isset($ajax_notices) ? $ajax_notices : '';// already escaped ?></div> |
| 19 | 19 | <?php |
| 20 | - do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
| 21 | - echo wp_kses($before_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 22 | - echo wp_kses($admin_page_content, AllowedTags::getWithFormTags()); |
|
| 23 | - echo wp_kses($after_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 24 | - do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
| 25 | - ?> |
|
| 20 | + do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
| 21 | + echo wp_kses($before_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 22 | + echo wp_kses($admin_page_content, AllowedTags::getWithFormTags()); |
|
| 23 | + echo wp_kses($after_admin_page_content, AllowedTags::getWithFormTags()); |
|
| 24 | + do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
| 25 | + ?> |
|
| 26 | 26 | </div> |
| 27 | 27 | <!-- espresso-admin --> |
| 28 | 28 | \ No newline at end of file |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | <div class="wrap espresso-admin"> |
| 16 | 16 | <h1><?php esc_attr_e('Event Espresso', 'event_espresso'); ?> - <?php echo wp_kses($admin_page_title, AllowedTags::getWithFormTags()); ?></h1> |
| 17 | 17 | |
| 18 | - <div class="ee-notices"><?php echo isset($ajax_notices) ? $ajax_notices : '';// already escaped ?></div> |
|
| 18 | + <div class="ee-notices"><?php echo isset($ajax_notices) ? $ajax_notices : ''; // already escaped ?></div> |
|
| 19 | 19 | <?php |
| 20 | 20 | do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
| 21 | 21 | echo wp_kses($before_admin_page_content, AllowedTags::getWithFormTags()); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | 88 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
| 89 | - Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 89 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
| 104 | - if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 105 | - $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 106 | - unset(Benchmark::$start_times[ $timer_name ]); |
|
| 104 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 105 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
| 106 | + unset(Benchmark::$start_times[$timer_name]); |
|
| 107 | 107 | } else { |
| 108 | 108 | $start_time = array_pop(Benchmark::$start_times); |
| 109 | 109 | } |
| 110 | - Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | 127 | $memory_used = Benchmark::convert(memory_get_usage(true)); |
| 128 | - Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 128 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
| 129 | 129 | if ($output_now) { |
| 130 | 130 | echo ($formatted |
| 131 | 131 | ? "<br>{$label} : {$memory_used}" |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | Benchmark::resetOutput(); |
| 146 | 146 | add_action( |
| 147 | 147 | 'shutdown', |
| 148 | - function () use ($formatted) { |
|
| 148 | + function() use ($formatted) { |
|
| 149 | 149 | Benchmark::displayResults(true, $formatted); |
| 150 | 150 | }, |
| 151 | 151 | 999999 |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | Benchmark::resetOutput(); |
| 167 | 167 | add_action( |
| 168 | 168 | 'shutdown', |
| 169 | - function () use ($filepath, $formatted, $append) { |
|
| 169 | + function() use ($filepath, $formatted, $append) { |
|
| 170 | 170 | Benchmark::writeResultsToFile($filepath, $formatted, $append); |
| 171 | 171 | }, |
| 172 | 172 | 999999 |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if (Benchmark::doNotRun()) { |
| 184 | 184 | return ''; |
| 185 | 185 | } |
| 186 | - if (! empty(Benchmark::$times)) { |
|
| 186 | + if ( ! empty(Benchmark::$times)) { |
|
| 187 | 187 | $total = 0; |
| 188 | 188 | Benchmark::$output .= $formatted |
| 189 | 189 | ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 211 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
| 212 | 212 | Benchmark::$output .= $formatted |
| 213 | 213 | ? '<h5>Memory</h5>' |
| 214 | 214 | : "\nMemory"; |
@@ -263,12 +263,12 @@ discard block |
||
| 263 | 263 | ? $filepath |
| 264 | 264 | : ''; |
| 265 | 265 | if (empty($filepath)) { |
| 266 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 266 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html'; |
|
| 267 | 267 | } |
| 268 | 268 | EEH_File::ensure_file_exists_and_is_writable($filepath); |
| 269 | 269 | file_put_contents( |
| 270 | 270 | $filepath, |
| 271 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 271 | + "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted), |
|
| 272 | 272 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 273 | 273 | ); |
| 274 | 274 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | return round( |
| 287 | 287 | $size / pow(1024, $i = floor(log($size, 1024))), |
| 288 | 288 | 2 |
| 289 | - ) . ' ' . $unit[ absint($i) ]; |
|
| 289 | + ).' '.$unit[absint($i)]; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
@@ -15,324 +15,324 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Benchmark |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var string $output |
|
| 20 | - */ |
|
| 21 | - private static $output; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var array $start_times array containing the start time for the timers |
|
| 25 | - */ |
|
| 26 | - private static $start_times; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array $times array containing all the timer'd times, which can be outputted via show_times() |
|
| 30 | - */ |
|
| 31 | - private static $times = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array $memory_usage |
|
| 35 | - */ |
|
| 36 | - protected static $memory_usage = array(); |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param string $output |
|
| 41 | - * @param bool $formatted |
|
| 42 | - */ |
|
| 43 | - public static function addOutput($output, $formatted = true) |
|
| 44 | - { |
|
| 45 | - Benchmark::$output .= $formatted |
|
| 46 | - ? "<br />{$output}" |
|
| 47 | - : "\n{$output}"; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public static function resetOutput() |
|
| 55 | - { |
|
| 56 | - Benchmark::$output = ''; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * whether to benchmark code or not |
|
| 61 | - */ |
|
| 62 | - public static function doNotRun() |
|
| 63 | - { |
|
| 64 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * resetTimes |
|
| 70 | - */ |
|
| 71 | - public static function resetTimes() |
|
| 72 | - { |
|
| 73 | - Benchmark::$times = array(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 79 | - * |
|
| 80 | - * @param null $timer_name |
|
| 81 | - */ |
|
| 82 | - public static function startTimer($timer_name = null) |
|
| 83 | - { |
|
| 84 | - if (Benchmark::doNotRun()) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 88 | - Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 94 | - * |
|
| 95 | - * @param string $timer_name |
|
| 96 | - */ |
|
| 97 | - public static function stopTimer($timer_name = '') |
|
| 98 | - { |
|
| 99 | - if (Benchmark::doNotRun()) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 103 | - if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 104 | - $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 105 | - unset(Benchmark::$start_times[ $timer_name ]); |
|
| 106 | - } else { |
|
| 107 | - $start_time = array_pop(Benchmark::$start_times); |
|
| 108 | - } |
|
| 109 | - Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Measure the memory usage by PHP so far. |
|
| 115 | - * |
|
| 116 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 117 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 118 | - * @param bool $formatted |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 122 | - { |
|
| 123 | - if (Benchmark::doNotRun()) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 127 | - Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 128 | - if ($output_now) { |
|
| 129 | - echo ($formatted |
|
| 130 | - ? "<br>{$label} : {$memory_used}" |
|
| 131 | - : "\n {$label} : {$memory_used}"); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * will display the benchmarking results at shutdown |
|
| 138 | - * |
|
| 139 | - * @param bool $formatted |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public static function displayResultsAtShutdown($formatted = true) |
|
| 143 | - { |
|
| 144 | - Benchmark::resetOutput(); |
|
| 145 | - add_action( |
|
| 146 | - 'shutdown', |
|
| 147 | - function () use ($formatted) { |
|
| 148 | - Benchmark::displayResults(true, $formatted); |
|
| 149 | - }, |
|
| 150 | - 999999 |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * will display the benchmarking results at shutdown |
|
| 157 | - * |
|
| 158 | - * @param string $filepath |
|
| 159 | - * @param bool $formatted |
|
| 160 | - * @param bool $append |
|
| 161 | - * @return void |
|
| 162 | - */ |
|
| 163 | - public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 164 | - { |
|
| 165 | - Benchmark::resetOutput(); |
|
| 166 | - add_action( |
|
| 167 | - 'shutdown', |
|
| 168 | - function () use ($filepath, $formatted, $append) { |
|
| 169 | - Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 170 | - }, |
|
| 171 | - 999999 |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param bool $formatted |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - private static function generateResults($formatted = true) |
|
| 181 | - { |
|
| 182 | - if (Benchmark::doNotRun()) { |
|
| 183 | - return ''; |
|
| 184 | - } |
|
| 185 | - if (! empty(Benchmark::$times)) { |
|
| 186 | - $total = 0; |
|
| 187 | - Benchmark::$output .= $formatted |
|
| 188 | - ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 189 | - : ''; |
|
| 190 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 191 | - Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 192 | - Benchmark::$output .= $formatted ? '<br />' : "\n"; |
|
| 193 | - $total += $total_time; |
|
| 194 | - } |
|
| 195 | - if ($formatted) { |
|
| 196 | - Benchmark::$output .= '<br />'; |
|
| 197 | - Benchmark::$output .= '<h4>TOTAL TIME</h4>'; |
|
| 198 | - Benchmark::$output .= Benchmark::formatTime('', $total, $formatted); |
|
| 199 | - Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 200 | - Benchmark::$output .= '<br />'; |
|
| 201 | - Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 202 | - Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 203 | - Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 204 | - Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 205 | - Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 206 | - Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 207 | - Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 211 | - Benchmark::$output .= $formatted |
|
| 212 | - ? '<h5>Memory</h5>' |
|
| 213 | - : "\nMemory"; |
|
| 214 | - foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
| 215 | - Benchmark::$output .= $formatted |
|
| 216 | - ? "<br />{$memory_usage} : {$label}" |
|
| 217 | - : "\n{$memory_usage} : {$label}"; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - if (empty(Benchmark::$output)) { |
|
| 221 | - return ''; |
|
| 222 | - } |
|
| 223 | - Benchmark::$output = $formatted |
|
| 224 | - ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 225 | - . (is_admin() |
|
| 226 | - ? ' margin:2em 2em 2em 180px;' |
|
| 227 | - : ' margin:2em;') |
|
| 228 | - . ' padding:2em;">' |
|
| 229 | - . '<h4>BENCHMARKING</h4>' |
|
| 230 | - . Benchmark::$output |
|
| 231 | - . '</div>' |
|
| 232 | - : Benchmark::$output; |
|
| 233 | - return Benchmark::$output; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @param bool $echo |
|
| 239 | - * @param bool $formatted |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public static function displayResults($echo = true, $formatted = true) |
|
| 243 | - { |
|
| 244 | - $results = Benchmark::generateResults($formatted); |
|
| 245 | - if ($echo) { |
|
| 246 | - echo wp_kses($results, AllowedTags::getWithFormTags()); |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - return $results; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @param string $filepath |
|
| 255 | - * @param bool $formatted |
|
| 256 | - * @param bool $append |
|
| 257 | - * @throws EE_Error |
|
| 258 | - */ |
|
| 259 | - public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 260 | - { |
|
| 261 | - $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 262 | - ? $filepath |
|
| 263 | - : ''; |
|
| 264 | - if (empty($filepath)) { |
|
| 265 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 266 | - } |
|
| 267 | - EEH_File::ensure_file_exists_and_is_writable($filepath); |
|
| 268 | - file_put_contents( |
|
| 269 | - $filepath, |
|
| 270 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 271 | - $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 278 | - * |
|
| 279 | - * @param int $size |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - public static function convert($size) |
|
| 283 | - { |
|
| 284 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 285 | - return round( |
|
| 286 | - $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 287 | - 2 |
|
| 288 | - ) . ' ' . $unit[ absint($i) ]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param string $timer_name |
|
| 294 | - * @param float $total_time |
|
| 295 | - * @param bool $formatted |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 299 | - { |
|
| 300 | - $total_time *= 1000; |
|
| 301 | - switch ($total_time) { |
|
| 302 | - case $total_time > 12500: |
|
| 303 | - $color = 'red'; |
|
| 304 | - $bold = 'bold'; |
|
| 305 | - break; |
|
| 306 | - case $total_time > 2500: |
|
| 307 | - $color = 'darkorange'; |
|
| 308 | - $bold = 'bold'; |
|
| 309 | - break; |
|
| 310 | - case $total_time > 500: |
|
| 311 | - $color = 'gold'; |
|
| 312 | - $bold = 'bold'; |
|
| 313 | - break; |
|
| 314 | - case $total_time > 100: |
|
| 315 | - $color = 'limegreen'; |
|
| 316 | - $bold = 'normal'; |
|
| 317 | - break; |
|
| 318 | - case $total_time > 20: |
|
| 319 | - $color = 'deepskyblue'; |
|
| 320 | - $bold = 'normal'; |
|
| 321 | - break; |
|
| 322 | - default: |
|
| 323 | - $color = 'mediumpurple'; |
|
| 324 | - $bold = 'normal'; |
|
| 325 | - break; |
|
| 326 | - } |
|
| 327 | - return $formatted |
|
| 328 | - ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 329 | - . $color |
|
| 330 | - . '; font-weight:' |
|
| 331 | - . $bold |
|
| 332 | - . '; font-size:1.2em;">' |
|
| 333 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 334 | - . '</span> ' |
|
| 335 | - . $timer_name |
|
| 336 | - : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 337 | - } |
|
| 18 | + /** |
|
| 19 | + * @var string $output |
|
| 20 | + */ |
|
| 21 | + private static $output; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var array $start_times array containing the start time for the timers |
|
| 25 | + */ |
|
| 26 | + private static $start_times; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array $times array containing all the timer'd times, which can be outputted via show_times() |
|
| 30 | + */ |
|
| 31 | + private static $times = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array $memory_usage |
|
| 35 | + */ |
|
| 36 | + protected static $memory_usage = array(); |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param string $output |
|
| 41 | + * @param bool $formatted |
|
| 42 | + */ |
|
| 43 | + public static function addOutput($output, $formatted = true) |
|
| 44 | + { |
|
| 45 | + Benchmark::$output .= $formatted |
|
| 46 | + ? "<br />{$output}" |
|
| 47 | + : "\n{$output}"; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public static function resetOutput() |
|
| 55 | + { |
|
| 56 | + Benchmark::$output = ''; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * whether to benchmark code or not |
|
| 61 | + */ |
|
| 62 | + public static function doNotRun() |
|
| 63 | + { |
|
| 64 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * resetTimes |
|
| 70 | + */ |
|
| 71 | + public static function resetTimes() |
|
| 72 | + { |
|
| 73 | + Benchmark::$times = array(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 79 | + * |
|
| 80 | + * @param null $timer_name |
|
| 81 | + */ |
|
| 82 | + public static function startTimer($timer_name = null) |
|
| 83 | + { |
|
| 84 | + if (Benchmark::doNotRun()) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 88 | + Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 94 | + * |
|
| 95 | + * @param string $timer_name |
|
| 96 | + */ |
|
| 97 | + public static function stopTimer($timer_name = '') |
|
| 98 | + { |
|
| 99 | + if (Benchmark::doNotRun()) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 103 | + if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 104 | + $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 105 | + unset(Benchmark::$start_times[ $timer_name ]); |
|
| 106 | + } else { |
|
| 107 | + $start_time = array_pop(Benchmark::$start_times); |
|
| 108 | + } |
|
| 109 | + Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Measure the memory usage by PHP so far. |
|
| 115 | + * |
|
| 116 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 117 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 118 | + * @param bool $formatted |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 122 | + { |
|
| 123 | + if (Benchmark::doNotRun()) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 127 | + Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 128 | + if ($output_now) { |
|
| 129 | + echo ($formatted |
|
| 130 | + ? "<br>{$label} : {$memory_used}" |
|
| 131 | + : "\n {$label} : {$memory_used}"); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * will display the benchmarking results at shutdown |
|
| 138 | + * |
|
| 139 | + * @param bool $formatted |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public static function displayResultsAtShutdown($formatted = true) |
|
| 143 | + { |
|
| 144 | + Benchmark::resetOutput(); |
|
| 145 | + add_action( |
|
| 146 | + 'shutdown', |
|
| 147 | + function () use ($formatted) { |
|
| 148 | + Benchmark::displayResults(true, $formatted); |
|
| 149 | + }, |
|
| 150 | + 999999 |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * will display the benchmarking results at shutdown |
|
| 157 | + * |
|
| 158 | + * @param string $filepath |
|
| 159 | + * @param bool $formatted |
|
| 160 | + * @param bool $append |
|
| 161 | + * @return void |
|
| 162 | + */ |
|
| 163 | + public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 164 | + { |
|
| 165 | + Benchmark::resetOutput(); |
|
| 166 | + add_action( |
|
| 167 | + 'shutdown', |
|
| 168 | + function () use ($filepath, $formatted, $append) { |
|
| 169 | + Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 170 | + }, |
|
| 171 | + 999999 |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param bool $formatted |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + private static function generateResults($formatted = true) |
|
| 181 | + { |
|
| 182 | + if (Benchmark::doNotRun()) { |
|
| 183 | + return ''; |
|
| 184 | + } |
|
| 185 | + if (! empty(Benchmark::$times)) { |
|
| 186 | + $total = 0; |
|
| 187 | + Benchmark::$output .= $formatted |
|
| 188 | + ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 189 | + : ''; |
|
| 190 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 191 | + Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 192 | + Benchmark::$output .= $formatted ? '<br />' : "\n"; |
|
| 193 | + $total += $total_time; |
|
| 194 | + } |
|
| 195 | + if ($formatted) { |
|
| 196 | + Benchmark::$output .= '<br />'; |
|
| 197 | + Benchmark::$output .= '<h4>TOTAL TIME</h4>'; |
|
| 198 | + Benchmark::$output .= Benchmark::formatTime('', $total, $formatted); |
|
| 199 | + Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 200 | + Benchmark::$output .= '<br />'; |
|
| 201 | + Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 202 | + Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 203 | + Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 204 | + Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 205 | + Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 206 | + Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 207 | + Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + if (! empty(Benchmark::$memory_usage)) { |
|
| 211 | + Benchmark::$output .= $formatted |
|
| 212 | + ? '<h5>Memory</h5>' |
|
| 213 | + : "\nMemory"; |
|
| 214 | + foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
| 215 | + Benchmark::$output .= $formatted |
|
| 216 | + ? "<br />{$memory_usage} : {$label}" |
|
| 217 | + : "\n{$memory_usage} : {$label}"; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + if (empty(Benchmark::$output)) { |
|
| 221 | + return ''; |
|
| 222 | + } |
|
| 223 | + Benchmark::$output = $formatted |
|
| 224 | + ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 225 | + . (is_admin() |
|
| 226 | + ? ' margin:2em 2em 2em 180px;' |
|
| 227 | + : ' margin:2em;') |
|
| 228 | + . ' padding:2em;">' |
|
| 229 | + . '<h4>BENCHMARKING</h4>' |
|
| 230 | + . Benchmark::$output |
|
| 231 | + . '</div>' |
|
| 232 | + : Benchmark::$output; |
|
| 233 | + return Benchmark::$output; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @param bool $echo |
|
| 239 | + * @param bool $formatted |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public static function displayResults($echo = true, $formatted = true) |
|
| 243 | + { |
|
| 244 | + $results = Benchmark::generateResults($formatted); |
|
| 245 | + if ($echo) { |
|
| 246 | + echo wp_kses($results, AllowedTags::getWithFormTags()); |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + return $results; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @param string $filepath |
|
| 255 | + * @param bool $formatted |
|
| 256 | + * @param bool $append |
|
| 257 | + * @throws EE_Error |
|
| 258 | + */ |
|
| 259 | + public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 260 | + { |
|
| 261 | + $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 262 | + ? $filepath |
|
| 263 | + : ''; |
|
| 264 | + if (empty($filepath)) { |
|
| 265 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 266 | + } |
|
| 267 | + EEH_File::ensure_file_exists_and_is_writable($filepath); |
|
| 268 | + file_put_contents( |
|
| 269 | + $filepath, |
|
| 270 | + "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 271 | + $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 278 | + * |
|
| 279 | + * @param int $size |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + public static function convert($size) |
|
| 283 | + { |
|
| 284 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 285 | + return round( |
|
| 286 | + $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 287 | + 2 |
|
| 288 | + ) . ' ' . $unit[ absint($i) ]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param string $timer_name |
|
| 294 | + * @param float $total_time |
|
| 295 | + * @param bool $formatted |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | + public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 299 | + { |
|
| 300 | + $total_time *= 1000; |
|
| 301 | + switch ($total_time) { |
|
| 302 | + case $total_time > 12500: |
|
| 303 | + $color = 'red'; |
|
| 304 | + $bold = 'bold'; |
|
| 305 | + break; |
|
| 306 | + case $total_time > 2500: |
|
| 307 | + $color = 'darkorange'; |
|
| 308 | + $bold = 'bold'; |
|
| 309 | + break; |
|
| 310 | + case $total_time > 500: |
|
| 311 | + $color = 'gold'; |
|
| 312 | + $bold = 'bold'; |
|
| 313 | + break; |
|
| 314 | + case $total_time > 100: |
|
| 315 | + $color = 'limegreen'; |
|
| 316 | + $bold = 'normal'; |
|
| 317 | + break; |
|
| 318 | + case $total_time > 20: |
|
| 319 | + $color = 'deepskyblue'; |
|
| 320 | + $bold = 'normal'; |
|
| 321 | + break; |
|
| 322 | + default: |
|
| 323 | + $color = 'mediumpurple'; |
|
| 324 | + $bold = 'normal'; |
|
| 325 | + break; |
|
| 326 | + } |
|
| 327 | + return $formatted |
|
| 328 | + ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 329 | + . $color |
|
| 330 | + . '; font-weight:' |
|
| 331 | + . $bold |
|
| 332 | + . '; font-size:1.2em;">' |
|
| 333 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 334 | + . '</span> ' |
|
| 335 | + . $timer_name |
|
| 336 | + : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 337 | + } |
|
| 338 | 338 | } |