@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\interfaces\InterminableInterface; |
| 5 | 5 | use EventEspresso\core\services\licensing\LicenseService; |
| 6 | 6 | |
| 7 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 8 | - exit( 'No direct script access allowed' ); |
|
| 7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | /** |
| 11 | 11 | * ************************************************************************ |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | $action_or_filter = 'action' |
| 49 | 49 | ) { |
| 50 | 50 | $action_or_filter = $action_or_filter === 'action' |
| 51 | - ? esc_html__( 'action', 'event_espresso' ) |
|
| 52 | - : esc_html__( 'filter', 'event_espresso' ); |
|
| 51 | + ? esc_html__('action', 'event_espresso') |
|
| 52 | + : esc_html__('filter', 'event_espresso'); |
|
| 53 | 53 | EE_Error::doing_it_wrong( |
| 54 | 54 | $deprecated_filter, |
| 55 | 55 | sprintf( |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param \EE_Checkout $checkout |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | -function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) { |
|
| 76 | +function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) { |
|
| 77 | 77 | // list of old filters |
| 78 | 78 | $deprecated_filters = array( |
| 79 | 79 | 'update_registration_details' => true, |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | 'proceed_to' => true, |
| 84 | 84 | ); |
| 85 | 85 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
| 86 | - foreach ( $deprecated_filters as $deprecated_filter => $on ) { |
|
| 86 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
| 87 | 87 | // was this filter called ? |
| 88 | - if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) { |
|
| 88 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
| 89 | 89 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
| 90 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) { |
|
| 90 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) { |
|
| 91 | 91 | EE_Error::doing_it_wrong( |
| 92 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
| 92 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
| 93 | 93 | sprintf( |
| 94 | - __( 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ), |
|
| 95 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
| 94 | + __('The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'), |
|
| 95 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
| 96 | 96 | '<br />', |
| 97 | 97 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
| 98 | 98 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -101,24 +101,24 @@ discard block |
||
| 101 | 101 | ); |
| 102 | 102 | } |
| 103 | 103 | } else { |
| 104 | - unset( $deprecated_filters[ $deprecated_filter ] ); |
|
| 104 | + unset($deprecated_filters[$deprecated_filter]); |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | - if ( ! empty( $deprecated_filters )) { |
|
| 108 | - |
|
| 109 | - if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) { |
|
| 110 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text ); |
|
| 111 | - } else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) { |
|
| 112 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text ); |
|
| 113 | - } else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) { |
|
| 114 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text ); |
|
| 107 | + if ( ! empty($deprecated_filters)) { |
|
| 108 | + |
|
| 109 | + if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
| 110 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text); |
|
| 111 | + } else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
| 112 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text); |
|
| 113 | + } else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
| 114 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text); |
|
| 115 | 115 | } |
| 116 | - if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
| 117 | - if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) { |
|
| 118 | - $submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text ); |
|
| 116 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 117 | + if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
| 118 | + $submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text); |
|
| 119 | 119 | } |
| 120 | - if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) { |
|
| 121 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name(); |
|
| 120 | + if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
| 121 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name(); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | return $submit_button_text; |
| 127 | 127 | |
| 128 | 128 | } |
| 129 | -add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 ); |
|
| 129 | +add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | * @param \EE_Checkout $checkout |
| 138 | 138 | * @param boolean $status_updates |
| 139 | 139 | */ |
| 140 | -function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) { |
|
| 140 | +function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) { |
|
| 141 | 141 | $action_ref = NULL; |
| 142 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
| 143 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
| 144 | - if ( $action_ref ) { |
|
| 142 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
| 143 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
| 144 | + if ($action_ref) { |
|
| 145 | 145 | |
| 146 | 146 | EE_Error::doing_it_wrong( |
| 147 | 147 | $action_ref, |
| 148 | 148 | sprintf( |
| 149 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ), |
|
| 149 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'), |
|
| 150 | 150 | '<br />', |
| 151 | 151 | '/core/business/EE_Transaction_Processor.class.php', |
| 152 | 152 | 'AHEE__EE_Transaction_Processor__finalize', |
@@ -156,39 +156,39 @@ discard block |
||
| 156 | 156 | ), |
| 157 | 157 | '4.6.0' |
| 158 | 158 | ); |
| 159 | - switch ( $action_ref ) { |
|
| 159 | + switch ($action_ref) { |
|
| 160 | 160 | case 'AHEE__EE_Transaction__finalize__new_transaction' : |
| 161 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request ); |
|
| 161 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request); |
|
| 162 | 162 | break; |
| 163 | 163 | case 'AHEE__EE_Transaction__finalize__all_transaction' : |
| 164 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request ); |
|
| 164 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request); |
|
| 165 | 165 | break; |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | -add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 ); |
|
| 169 | +add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2); |
|
| 170 | 170 | /** |
| 171 | 171 | * ee_deprecated_finalize_registration |
| 172 | 172 | * |
| 173 | 173 | * @param EE_Registration $registration |
| 174 | 174 | */ |
| 175 | -function ee_deprecated_finalize_registration( EE_Registration $registration ) { |
|
| 176 | - $action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
| 177 | - if ( $action_ref ) { |
|
| 175 | +function ee_deprecated_finalize_registration(EE_Registration $registration) { |
|
| 176 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
| 177 | + if ($action_ref) { |
|
| 178 | 178 | EE_Error::doing_it_wrong( |
| 179 | 179 | $action_ref, |
| 180 | 180 | sprintf( |
| 181 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ), |
|
| 181 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'), |
|
| 182 | 182 | '<br />', |
| 183 | 183 | '/core/business/EE_Registration_Processor.class.php', |
| 184 | 184 | 'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook' |
| 185 | 185 | ), |
| 186 | 186 | '4.6.0' |
| 187 | 187 | ); |
| 188 | - do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ))); |
|
| 188 | + do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | -add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 ); |
|
| 191 | +add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1); |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | 194 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called. |
| 197 | 197 | * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately. |
| 198 | 198 | */ |
| 199 | -function ee_deprecated_hooks(){ |
|
| 199 | +function ee_deprecated_hooks() { |
|
| 200 | 200 | /** |
| 201 | 201 | * @var $hooks array where keys are hook names, and their values are array{ |
| 202 | 202 | * @type string $version when deprecated |
@@ -207,25 +207,25 @@ discard block |
||
| 207 | 207 | $hooks = array( |
| 208 | 208 | 'AHEE__EE_System___do_setup_validations' => array( |
| 209 | 209 | 'version' => '4.6.0', |
| 210 | - 'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ), |
|
| 210 | + 'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'), |
|
| 211 | 211 | 'still_works' => FALSE |
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - foreach( $hooks as $name => $deprecation_info ){ |
|
| 215 | - if( has_action( $name ) ){ |
|
| 214 | + foreach ($hooks as $name => $deprecation_info) { |
|
| 215 | + if (has_action($name)) { |
|
| 216 | 216 | EE_Error::doing_it_wrong( |
| 217 | 217 | $name, |
| 218 | 218 | sprintf( |
| 219 | - __('This filter is deprecated. %1$s%2$s','event_espresso'), |
|
| 220 | - $deprecation_info[ 'still_works' ] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ), |
|
| 221 | - isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' ) |
|
| 219 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
| 220 | + $deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'), |
|
| 221 | + isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso') |
|
| 222 | 222 | ), |
| 223 | - isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' ) |
|
| 223 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
| 224 | 224 | ); |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | -add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' ); |
|
| 228 | +add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | * @return boolean |
| 237 | 237 | */ |
| 238 | 238 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() { |
| 239 | - $in_use = has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' ) |
|
| 240 | - || has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' ); |
|
| 241 | - if( $in_use ) { |
|
| 239 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
| 240 | + || has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'); |
|
| 241 | + if ($in_use) { |
|
| 242 | 242 | $msg = __( |
| 243 | 243 | 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
| 244 | 244 | . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
@@ -247,18 +247,18 @@ discard block |
||
| 247 | 247 | 'event_espresso' ) |
| 248 | 248 | ; |
| 249 | 249 | EE_Error::doing_it_wrong( |
| 250 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 250 | + __CLASS__.'::'.__FUNCTION__, |
|
| 251 | 251 | $msg, |
| 252 | 252 | '4.8.32.rc.000' |
| 253 | 253 | ); |
| 254 | 254 | //it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
| 255 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 256 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 255 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
| 256 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | return $in_use; |
| 260 | 260 | } |
| 261 | -add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' ); |
|
| 261 | +add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'); |
|
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | 264 | * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165 |
@@ -267,34 +267,34 @@ discard block |
||
| 267 | 267 | * @param EE_Admin_Page $admin_page |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | -function ee_deprecated_update_attendee_registration_form_old( $admin_page ) { |
|
| 270 | +function ee_deprecated_update_attendee_registration_form_old($admin_page) { |
|
| 271 | 271 | //check if the old hooks are in use. If not, do the default |
| 272 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 273 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
| 272 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 273 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
| 274 | 274 | return; |
| 275 | 275 | } |
| 276 | 276 | $req_data = $admin_page->get_request_data(); |
| 277 | - $qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE; |
|
| 278 | - $REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE; |
|
| 279 | - $qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns ); |
|
| 280 | - if ( ! $REG_ID || ! $qstns ) { |
|
| 281 | - EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 277 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE; |
|
| 278 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE; |
|
| 279 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
| 280 | + if ( ! $REG_ID || ! $qstns) { |
|
| 281 | + EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 282 | 282 | } |
| 283 | 283 | $success = TRUE; |
| 284 | 284 | |
| 285 | 285 | // allow others to get in on this awesome fun :D |
| 286 | - do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns ); |
|
| 286 | + do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns); |
|
| 287 | 287 | // loop thru questions... FINALLY!!! |
| 288 | 288 | |
| 289 | - foreach ( $qstns as $QST_ID => $qstn ) { |
|
| 289 | + foreach ($qstns as $QST_ID => $qstn) { |
|
| 290 | 290 | //if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
| 291 | - if ( !is_array($qstn) ) { |
|
| 292 | - $success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn); |
|
| 291 | + if ( ! is_array($qstn)) { |
|
| 292 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
| 293 | 293 | continue; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
| 297 | - foreach ( $qstn as $ANS_ID => $ANS_value ) { |
|
| 297 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
| 298 | 298 | //get answer |
| 299 | 299 | $query_params = array( |
| 300 | 300 | 0 => array( |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | ); |
| 306 | 306 | $answer = EEM_Answer::instance()->get_one($query_params); |
| 307 | 307 | //this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
| 308 | - if ( ! $answer instanceof EE_Answer ) { |
|
| 308 | + if ( ! $answer instanceof EE_Answer) { |
|
| 309 | 309 | $set_values = array( |
| 310 | 310 | 'QST_ID' => $QST_ID, |
| 311 | 311 | 'REG_ID' => $REG_ID, |
@@ -320,11 +320,11 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | $what = __('Registration Form', 'event_espresso'); |
| 323 | - $route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' ); |
|
| 324 | - $admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route ); |
|
| 323 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
| 324 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 325 | 325 | exit; |
| 326 | 326 | } |
| 327 | -add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 ); |
|
| 327 | +add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1); |
|
| 328 | 328 | /** |
| 329 | 329 | * Render the registration admin page's custom questions area in the old fashion |
| 330 | 330 | * and firing the old hooks. When this method is removed, we can probably also |
@@ -337,31 +337,31 @@ discard block |
||
| 337 | 337 | * @return bool |
| 338 | 338 | * @throws \EE_Error |
| 339 | 339 | */ |
| 340 | -function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) { |
|
| 340 | +function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) { |
|
| 341 | 341 | //check if the old hooks are in use. If not, do the default |
| 342 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 343 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
| 342 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 343 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
| 344 | 344 | return $do_default_action; |
| 345 | 345 | } |
| 346 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 ); |
|
| 347 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 ); |
|
| 348 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 ); |
|
| 349 | - add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 ); |
|
| 346 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1); |
|
| 347 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1); |
|
| 348 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
| 349 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
| 350 | 350 | |
| 351 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') ); |
|
| 351 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID')); |
|
| 352 | 352 | |
| 353 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
| 353 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
| 354 | 354 | $template_args = array( |
| 355 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ), |
|
| 355 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
| 356 | 356 | 'reg_questions_form_action' => 'edit_registration', |
| 357 | 357 | 'REG_ID' => $registration->ID() |
| 358 | 358 | ); |
| 359 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 360 | - echo EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
| 359 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 360 | + echo EEH_Template::display_template($template_path, $template_args, TRUE); |
|
| 361 | 361 | //indicate that we should not do the default admin page code |
| 362 | 362 | return false; |
| 363 | 363 | } |
| 364 | -add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 ); |
|
| 364 | +add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3); |
|
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | |
@@ -402,9 +402,9 @@ discard block |
||
| 402 | 402 | '4.9.0' |
| 403 | 403 | ); |
| 404 | 404 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
| 405 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 406 | - $messenger = $message_resource_manager->get_messenger( $messenger_name ); |
|
| 407 | - $message_type = $message_resource_manager->get_message_type( $message_type_name ); |
|
| 405 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 406 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
| 407 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
| 408 | 408 | return EE_Registry::instance()->load_lib( |
| 409 | 409 | 'Messages_Template_Defaults', |
| 410 | 410 | array( |
@@ -469,15 +469,15 @@ discard block |
||
| 469 | 469 | /** |
| 470 | 470 | * @param string $method |
| 471 | 471 | */ |
| 472 | - public function _class_is_deprecated( $method ) { |
|
| 472 | + public function _class_is_deprecated($method) { |
|
| 473 | 473 | EE_Error::doing_it_wrong( |
| 474 | - 'EE_messages::' . $method, |
|
| 475 | - __( 'EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.' ), |
|
| 474 | + 'EE_messages::'.$method, |
|
| 475 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
| 476 | 476 | '4.9.0', |
| 477 | 477 | '4.10.0.p' |
| 478 | 478 | ); |
| 479 | 479 | // Please use EE_Message_Resource_Manager instead |
| 480 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 480 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
@@ -487,10 +487,10 @@ discard block |
||
| 487 | 487 | * @param string $messenger_name |
| 488 | 488 | * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
| 489 | 489 | */ |
| 490 | - public function ensure_messenger_is_active( $messenger_name ) { |
|
| 490 | + public function ensure_messenger_is_active($messenger_name) { |
|
| 491 | 491 | // EE_messages has been deprecated |
| 492 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 493 | - return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name ); |
|
| 492 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 493 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -502,10 +502,10 @@ discard block |
||
| 502 | 502 | * @return bool true if it got activated (or was active) and false if not. |
| 503 | 503 | * @throws \EE_Error |
| 504 | 504 | */ |
| 505 | - public function ensure_message_type_is_active( $message_type, $messenger ) { |
|
| 505 | + public function ensure_message_type_is_active($message_type, $messenger) { |
|
| 506 | 506 | // EE_messages has been deprecated |
| 507 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 508 | - return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger ); |
|
| 507 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 508 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
@@ -518,10 +518,10 @@ discard block |
||
| 518 | 518 | * they are already setup.) |
| 519 | 519 | * @return boolean an array of generated templates or false if nothing generated/activated. |
| 520 | 520 | */ |
| 521 | - public function activate_messenger( $messenger_name, $mts_to_activate = array() ) { |
|
| 521 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) { |
|
| 522 | 522 | // EE_messages has been deprecated |
| 523 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 524 | - return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate ); |
|
| 523 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 524 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,10 +533,10 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
| 535 | 535 | */ |
| 536 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
| 536 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
| 537 | 537 | // EE_messages has been deprecated |
| 538 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 539 | - return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type ); |
|
| 538 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 539 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | |
@@ -546,10 +546,10 @@ discard block |
||
| 546 | 546 | * @param string $messenger |
| 547 | 547 | * @return EE_messenger | null |
| 548 | 548 | */ |
| 549 | - public function get_messenger_if_active( $messenger ) { |
|
| 549 | + public function get_messenger_if_active($messenger) { |
|
| 550 | 550 | // EE_messages has been deprecated |
| 551 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 552 | - return $this->_message_resource_manager->get_active_messenger( $messenger ); |
|
| 551 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 552 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | |
@@ -570,9 +570,9 @@ discard block |
||
| 570 | 570 | * 'message_type' => null |
| 571 | 571 | * ) |
| 572 | 572 | */ |
| 573 | - public function validate_for_use( EE_Message $message ) { |
|
| 573 | + public function validate_for_use(EE_Message $message) { |
|
| 574 | 574 | // EE_messages has been deprecated |
| 575 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 575 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 576 | 576 | return array( |
| 577 | 577 | 'messenger' => $message->messenger_object(), |
| 578 | 578 | 'message_type' => $message->message_type_object(), |
@@ -600,41 +600,41 @@ discard block |
||
| 600 | 600 | $send = true |
| 601 | 601 | ) { |
| 602 | 602 | // EE_messages has been deprecated |
| 603 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 603 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 604 | 604 | /** @type EE_Messages_Processor $processor */ |
| 605 | - $processor = EE_Registry::instance()->load_lib( 'Messages_Processor' ); |
|
| 605 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 606 | 606 | $error = false; |
| 607 | 607 | //try to intelligently determine what method we'll call based on the incoming data. |
| 608 | 608 | //if generating and sending are different then generate and send immediately. |
| 609 | - if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) { |
|
| 609 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
| 610 | 610 | //in the legacy system, when generating and sending were different, that means all the |
| 611 | 611 | //vars are already in the request object. So let's just use that. |
| 612 | 612 | try { |
| 613 | 613 | /** @type EE_Message_To_Generate_From_Request $mtg */ |
| 614 | - $mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' ); |
|
| 615 | - $processor->generate_and_send_now( $mtg ); |
|
| 616 | - } catch ( EE_Error $e ) { |
|
| 614 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 615 | + $processor->generate_and_send_now($mtg); |
|
| 616 | + } catch (EE_Error $e) { |
|
| 617 | 617 | $error_msg = __( |
| 618 | 618 | 'Please note that a system message failed to send due to a technical issue.', |
| 619 | 619 | 'event_espresso' |
| 620 | 620 | ); |
| 621 | 621 | // add specific message for developers if WP_DEBUG in on |
| 622 | - $error_msg .= '||' . $e->getMessage(); |
|
| 623 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 622 | + $error_msg .= '||'.$e->getMessage(); |
|
| 623 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 624 | 624 | $error = true; |
| 625 | 625 | } |
| 626 | 626 | } else { |
| 627 | - $processor->generate_for_all_active_messengers( $type, $vars, $send ); |
|
| 627 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
| 628 | 628 | //let's find out if there were any errors and how many successfully were queued. |
| 629 | 629 | $count_errors = $processor->get_queue()->count_STS_in_queue( |
| 630 | - array( EEM_Message::status_failed, EEM_Message::status_debug_only ) |
|
| 630 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
| 631 | 631 | ); |
| 632 | - $count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete ); |
|
| 633 | - $count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry ); |
|
| 632 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
| 633 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
| 634 | 634 | $count_errors = $count_errors + $count_retry; |
| 635 | - if ( $count_errors > 0 ) { |
|
| 635 | + if ($count_errors > 0) { |
|
| 636 | 636 | $error = true; |
| 637 | - if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) { |
|
| 637 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
| 638 | 638 | $message = sprintf( |
| 639 | 639 | __( |
| 640 | 640 | 'There were %d errors and %d messages successfully queued for generation and sending', |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | $count_errors, |
| 644 | 644 | $count_queued |
| 645 | 645 | ); |
| 646 | - } elseif ( $count_errors > 1 && $count_queued === 1 ) { |
|
| 646 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
| 647 | 647 | $message = sprintf( |
| 648 | 648 | __( |
| 649 | 649 | 'There were %d errors and %d message successfully queued for generation.', |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | $count_errors, |
| 653 | 653 | $count_queued |
| 654 | 654 | ); |
| 655 | - } elseif ( $count_errors === 1 && $count_queued > 1 ) { |
|
| 655 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
| 656 | 656 | $message = sprintf( |
| 657 | 657 | __( |
| 658 | 658 | 'There was %d error and %d messages successfully queued for generation.', |
@@ -670,9 +670,9 @@ discard block |
||
| 670 | 670 | $count_errors |
| 671 | 671 | ); |
| 672 | 672 | } |
| 673 | - EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 673 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
| 674 | 674 | } else { |
| 675 | - if ( $count_queued === 1 ) { |
|
| 675 | + if ($count_queued === 1) { |
|
| 676 | 676 | $message = sprintf( |
| 677 | 677 | __( |
| 678 | 678 | '%d message successfully queued for generation.', |
@@ -689,18 +689,18 @@ discard block |
||
| 689 | 689 | $count_queued |
| 690 | 690 | ); |
| 691 | 691 | } |
| 692 | - EE_Error::add_success( $message ); |
|
| 692 | + EE_Error::add_success($message); |
|
| 693 | 693 | } |
| 694 | 694 | } |
| 695 | 695 | //if no error then return the generated message(s). |
| 696 | - if ( ! $error && ! $send ) { |
|
| 697 | - $generated_queue = $processor->generate_queue( false ); |
|
| 696 | + if ( ! $error && ! $send) { |
|
| 697 | + $generated_queue = $processor->generate_queue(false); |
|
| 698 | 698 | //get message and return. |
| 699 | 699 | $generated_queue->get_message_repository()->rewind(); |
| 700 | 700 | $messages = array(); |
| 701 | - while ( $generated_queue->get_message_repository()->valid() ) { |
|
| 701 | + while ($generated_queue->get_message_repository()->valid()) { |
|
| 702 | 702 | $message = $generated_queue->get_message_repository()->current(); |
| 703 | - if ( $message instanceof EE_Message ) { |
|
| 703 | + if ($message instanceof EE_Message) { |
|
| 704 | 704 | //set properties that might be expected by add-ons (backward compat) |
| 705 | 705 | $message->content = $message->content(); |
| 706 | 706 | $message->template_pack = $message->get_template_pack(); |
@@ -725,10 +725,10 @@ discard block |
||
| 725 | 725 | * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular preview |
| 726 | 726 | * @return string The body of the message. |
| 727 | 727 | */ |
| 728 | - public function preview_message( $type, $context, $messenger, $send = false ) { |
|
| 728 | + public function preview_message($type, $context, $messenger, $send = false) { |
|
| 729 | 729 | // EE_messages has been deprecated |
| 730 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 731 | - return EED_Messages::preview_message( $type, $context, $messenger, $send ); |
|
| 730 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 731 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | |
@@ -742,14 +742,14 @@ discard block |
||
| 742 | 742 | * |
| 743 | 743 | * @return bool success or fail. |
| 744 | 744 | */ |
| 745 | - public function send_message_with_messenger_only( $messenger, $message_type, $message ) { |
|
| 745 | + public function send_message_with_messenger_only($messenger, $message_type, $message) { |
|
| 746 | 746 | // EE_messages has been deprecated |
| 747 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 747 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 748 | 748 | //setup for sending to new method. |
| 749 | 749 | /** @type EE_Messages_Queue $queue */ |
| 750 | - $queue = EE_Registry::instance()->load_lib( 'Messages_Queue' ); |
|
| 750 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
| 751 | 751 | //make sure we have a proper message object |
| 752 | - if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) { |
|
| 752 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
| 753 | 753 | $msg = EE_Message_Factory::create( |
| 754 | 754 | array( |
| 755 | 755 | 'MSG_messenger' => $messenger, |
@@ -761,15 +761,15 @@ discard block |
||
| 761 | 761 | } else { |
| 762 | 762 | $msg = $message; |
| 763 | 763 | } |
| 764 | - if ( ! $msg instanceof EE_Message ) { |
|
| 764 | + if ( ! $msg instanceof EE_Message) { |
|
| 765 | 765 | return false; |
| 766 | 766 | } |
| 767 | 767 | //make sure any content in a content property (if not empty) is set on the MSG_content. |
| 768 | - if ( ! empty( $msg->content ) ) { |
|
| 769 | - $msg->set( 'MSG_content', $msg->content ); |
|
| 768 | + if ( ! empty($msg->content)) { |
|
| 769 | + $msg->set('MSG_content', $msg->content); |
|
| 770 | 770 | } |
| 771 | - $queue->add( $msg ); |
|
| 772 | - return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue ); |
|
| 771 | + $queue->add($msg); |
|
| 772 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. |
| 784 | 784 | * @throws \EE_Error |
| 785 | 785 | */ |
| 786 | - public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) { |
|
| 786 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { |
|
| 787 | 787 | // EE_messages has been deprecated |
| 788 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 789 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 790 | - return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global ); |
|
| 788 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 789 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 790 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | |
@@ -798,11 +798,11 @@ discard block |
||
| 798 | 798 | * @param string $message_type_name name of EE_message_type |
| 799 | 799 | * @return array |
| 800 | 800 | */ |
| 801 | - public function get_fields( $messenger_name, $message_type_name ) { |
|
| 801 | + public function get_fields($messenger_name, $message_type_name) { |
|
| 802 | 802 | // EE_messages has been deprecated |
| 803 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 804 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 805 | - return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name ); |
|
| 803 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 804 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 805 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -816,13 +816,13 @@ discard block |
||
| 816 | 816 | * @return array multidimensional array of messenger and message_type objects |
| 817 | 817 | * (messengers index, and message_type index); |
| 818 | 818 | */ |
| 819 | - public function get_installed( $type = 'all', $skip_cache = false ) { |
|
| 819 | + public function get_installed($type = 'all', $skip_cache = false) { |
|
| 820 | 820 | // EE_messages has been deprecated |
| 821 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 822 | - if ( $skip_cache ) { |
|
| 821 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 822 | + if ($skip_cache) { |
|
| 823 | 823 | $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
| 824 | 824 | } |
| 825 | - switch ( $type ) { |
|
| 825 | + switch ($type) { |
|
| 826 | 826 | case 'messengers' : |
| 827 | 827 | return array( |
| 828 | 828 | 'messenger' => $this->_message_resource_manager->installed_messengers(), |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | */ |
| 852 | 852 | public function get_active_messengers() { |
| 853 | 853 | // EE_messages has been deprecated |
| 854 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 854 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 855 | 855 | return $this->_message_resource_manager->active_messengers(); |
| 856 | 856 | } |
| 857 | 857 | |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | */ |
| 864 | 864 | public function get_active_message_types() { |
| 865 | 865 | // EE_messages has been deprecated |
| 866 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 866 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 867 | 867 | return $this->_message_resource_manager->list_of_active_message_types(); |
| 868 | 868 | } |
| 869 | 869 | |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | */ |
| 876 | 876 | public function get_active_message_type_objects() { |
| 877 | 877 | // EE_messages has been deprecated |
| 878 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 878 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 879 | 879 | return $this->_message_resource_manager->get_active_message_type_objects(); |
| 880 | 880 | } |
| 881 | 881 | |
@@ -887,10 +887,10 @@ discard block |
||
| 887 | 887 | * @param string $messenger The messenger being checked |
| 888 | 888 | * @return EE_message_type[] (or empty array if none present) |
| 889 | 889 | */ |
| 890 | - public function get_active_message_types_per_messenger( $messenger ) { |
|
| 890 | + public function get_active_message_types_per_messenger($messenger) { |
|
| 891 | 891 | // EE_messages has been deprecated |
| 892 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 893 | - return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger ); |
|
| 892 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 893 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | |
@@ -901,10 +901,10 @@ discard block |
||
| 901 | 901 | * @param string $message_type The string should correspond to a message type. |
| 902 | 902 | * @return EE_message_type|null |
| 903 | 903 | */ |
| 904 | - public function get_active_message_type( $messenger, $message_type ) { |
|
| 904 | + public function get_active_message_type($messenger, $message_type) { |
|
| 905 | 905 | // EE_messages has been deprecated |
| 906 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 907 | - return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type ); |
|
| 906 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 907 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | */ |
| 916 | 916 | public function get_installed_message_types() { |
| 917 | 917 | // EE_messages has been deprecated |
| 918 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 918 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 919 | 919 | return $this->_message_resource_manager->installed_message_types(); |
| 920 | 920 | } |
| 921 | 921 | |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | */ |
| 928 | 928 | public function get_installed_messengers() { |
| 929 | 929 | // EE_messages has been deprecated |
| 930 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 930 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 931 | 931 | return $this->_message_resource_manager->installed_messengers(); |
| 932 | 932 | } |
| 933 | 933 | |
@@ -938,10 +938,10 @@ discard block |
||
| 938 | 938 | * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type. |
| 939 | 939 | * @return array |
| 940 | 940 | */ |
| 941 | - public function get_all_contexts( $slugs_only = true ) { |
|
| 941 | + public function get_all_contexts($slugs_only = true) { |
|
| 942 | 942 | // EE_messages has been deprecated |
| 943 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 944 | - return $this->_message_resource_manager->get_all_contexts( $slugs_only ); |
|
| 943 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 944 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | add_filter( |
| 1001 | 1001 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
| 1002 | 1002 | function($event_list_iframe_css) { |
| 1003 | - if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) { |
|
| 1003 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
| 1004 | 1004 | return $event_list_iframe_css; |
| 1005 | 1005 | } |
| 1006 | 1006 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | add_filter( |
| 1021 | 1021 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
| 1022 | 1022 | function($event_list_iframe_js) { |
| 1023 | - if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) { |
|
| 1023 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
| 1024 | 1024 | return $event_list_iframe_js; |
| 1025 | 1025 | } |
| 1026 | 1026 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | add_action( |
| 1041 | 1041 | 'AHEE__EE_Capabilities__addCaps__complete', |
| 1042 | 1042 | function($capabilities_map) { |
| 1043 | - if ( ! has_action( 'AHEE__EE_Capabilities__init_role_caps__complete' )) { |
|
| 1043 | + if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
| 1044 | 1044 | return; |
| 1045 | 1045 | } |
| 1046 | 1046 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | add_filter( |
| 1061 | 1061 | 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
| 1062 | 1062 | function($existing_attendee, $registration, $attendee_data) { |
| 1063 | - if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) { |
|
| 1063 | + if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
| 1064 | 1064 | return $existing_attendee; |
| 1065 | 1065 | } |
| 1066 | 1066 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1076,7 +1076,7 @@ discard block |
||
| 1076 | 1076 | $existing_attendee, $registration, $attendee_data |
| 1077 | 1077 | ); |
| 1078 | 1078 | }, |
| 1079 | - 10,3 |
|
| 1079 | + 10, 3 |
|
| 1080 | 1080 | ); |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | */ |
| 1141 | 1141 | public function event_list_title($event_list_title = '') |
| 1142 | 1142 | { |
| 1143 | - if (! empty($this->title)) { |
|
| 1143 | + if ( ! empty($this->title)) { |
|
| 1144 | 1144 | return $this->title; |
| 1145 | 1145 | } |
| 1146 | 1146 | return $event_list_title; |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | ); |
| 1053 | 1053 | do_action( |
| 1054 | 1054 | 'AHEE__EE_Capabilities__init_role_caps__complete', |
| 1055 | - $capabilities_map |
|
| 1055 | + $capabilities_map |
|
| 1056 | 1056 | ); |
| 1057 | 1057 | } |
| 1058 | 1058 | ); |
@@ -1072,9 +1072,9 @@ discard block |
||
| 1072 | 1072 | 'filter' |
| 1073 | 1073 | ); |
| 1074 | 1074 | return apply_filters( |
| 1075 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
| 1076 | - $existing_attendee, $registration, $attendee_data |
|
| 1077 | - ); |
|
| 1075 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
| 1076 | + $existing_attendee, $registration, $attendee_data |
|
| 1077 | + ); |
|
| 1078 | 1078 | }, |
| 1079 | 1079 | 10,3 |
| 1080 | 1080 | ); |
@@ -1087,89 +1087,89 @@ discard block |
||
| 1087 | 1087 | class EE_Event_List_Query extends WP_Query |
| 1088 | 1088 | { |
| 1089 | 1089 | |
| 1090 | - private $title; |
|
| 1091 | - |
|
| 1092 | - private $css_class; |
|
| 1093 | - |
|
| 1094 | - private $category_slug; |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * EE_Event_List_Query constructor. |
|
| 1098 | - * |
|
| 1099 | - * @param array $args |
|
| 1100 | - */ |
|
| 1101 | - public function __construct($args = array()) |
|
| 1102 | - { |
|
| 1103 | - \EE_Error::doing_it_wrong( |
|
| 1104 | - __METHOD__, |
|
| 1105 | - __( |
|
| 1106 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
| 1107 | - 'event_espresso' |
|
| 1108 | - ), |
|
| 1109 | - '4.9.27', |
|
| 1110 | - '5.0.0' |
|
| 1111 | - ); |
|
| 1112 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
| 1113 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
| 1114 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
| 1115 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
| 1116 | - // the current "page" we are viewing |
|
| 1117 | - $paged = max(1, get_query_var('paged')); |
|
| 1118 | - // Force these args |
|
| 1119 | - $args = array_merge( |
|
| 1120 | - $args, array( |
|
| 1121 | - 'post_type' => 'espresso_events', |
|
| 1122 | - 'posts_per_page' => $limit, |
|
| 1123 | - 'update_post_term_cache' => false, |
|
| 1124 | - 'update_post_meta_cache' => false, |
|
| 1125 | - 'paged' => $paged, |
|
| 1126 | - 'offset' => ($paged - 1) * $limit |
|
| 1127 | - ) |
|
| 1128 | - ); |
|
| 1129 | - // run the query |
|
| 1130 | - parent::__construct($args); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * event_list_title |
|
| 1137 | - * |
|
| 1138 | - * @param string $event_list_title |
|
| 1139 | - * @return string |
|
| 1140 | - */ |
|
| 1141 | - public function event_list_title($event_list_title = '') |
|
| 1142 | - { |
|
| 1143 | - if (! empty($this->title)) { |
|
| 1144 | - return $this->title; |
|
| 1145 | - } |
|
| 1146 | - return $event_list_title; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * event_list_css |
|
| 1153 | - * |
|
| 1154 | - * @param string $event_list_css |
|
| 1155 | - * @return string |
|
| 1156 | - */ |
|
| 1157 | - public function event_list_css($event_list_css = '') |
|
| 1158 | - { |
|
| 1159 | - $event_list_css .= ! empty($event_list_css) |
|
| 1160 | - ? ' ' |
|
| 1161 | - : ''; |
|
| 1162 | - $event_list_css .= ! empty($this->css_class) |
|
| 1163 | - ? $this->css_class |
|
| 1164 | - : ''; |
|
| 1165 | - $event_list_css .= ! empty($event_list_css) |
|
| 1166 | - ? ' ' |
|
| 1167 | - : ''; |
|
| 1168 | - $event_list_css .= ! empty($this->category_slug) |
|
| 1169 | - ? $this->category_slug |
|
| 1170 | - : ''; |
|
| 1171 | - return $event_list_css; |
|
| 1172 | - } |
|
| 1090 | + private $title; |
|
| 1091 | + |
|
| 1092 | + private $css_class; |
|
| 1093 | + |
|
| 1094 | + private $category_slug; |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * EE_Event_List_Query constructor. |
|
| 1098 | + * |
|
| 1099 | + * @param array $args |
|
| 1100 | + */ |
|
| 1101 | + public function __construct($args = array()) |
|
| 1102 | + { |
|
| 1103 | + \EE_Error::doing_it_wrong( |
|
| 1104 | + __METHOD__, |
|
| 1105 | + __( |
|
| 1106 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
| 1107 | + 'event_espresso' |
|
| 1108 | + ), |
|
| 1109 | + '4.9.27', |
|
| 1110 | + '5.0.0' |
|
| 1111 | + ); |
|
| 1112 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
| 1113 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
| 1114 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
| 1115 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
| 1116 | + // the current "page" we are viewing |
|
| 1117 | + $paged = max(1, get_query_var('paged')); |
|
| 1118 | + // Force these args |
|
| 1119 | + $args = array_merge( |
|
| 1120 | + $args, array( |
|
| 1121 | + 'post_type' => 'espresso_events', |
|
| 1122 | + 'posts_per_page' => $limit, |
|
| 1123 | + 'update_post_term_cache' => false, |
|
| 1124 | + 'update_post_meta_cache' => false, |
|
| 1125 | + 'paged' => $paged, |
|
| 1126 | + 'offset' => ($paged - 1) * $limit |
|
| 1127 | + ) |
|
| 1128 | + ); |
|
| 1129 | + // run the query |
|
| 1130 | + parent::__construct($args); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * event_list_title |
|
| 1137 | + * |
|
| 1138 | + * @param string $event_list_title |
|
| 1139 | + * @return string |
|
| 1140 | + */ |
|
| 1141 | + public function event_list_title($event_list_title = '') |
|
| 1142 | + { |
|
| 1143 | + if (! empty($this->title)) { |
|
| 1144 | + return $this->title; |
|
| 1145 | + } |
|
| 1146 | + return $event_list_title; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * event_list_css |
|
| 1153 | + * |
|
| 1154 | + * @param string $event_list_css |
|
| 1155 | + * @return string |
|
| 1156 | + */ |
|
| 1157 | + public function event_list_css($event_list_css = '') |
|
| 1158 | + { |
|
| 1159 | + $event_list_css .= ! empty($event_list_css) |
|
| 1160 | + ? ' ' |
|
| 1161 | + : ''; |
|
| 1162 | + $event_list_css .= ! empty($this->css_class) |
|
| 1163 | + ? $this->css_class |
|
| 1164 | + : ''; |
|
| 1165 | + $event_list_css .= ! empty($event_list_css) |
|
| 1166 | + ? ' ' |
|
| 1167 | + : ''; |
|
| 1168 | + $event_list_css .= ! empty($this->category_slug) |
|
| 1169 | + ? $this->category_slug |
|
| 1170 | + : ''; |
|
| 1171 | + return $event_list_css; |
|
| 1172 | + } |
|
| 1173 | 1173 | |
| 1174 | 1174 | } |
| 1175 | 1175 | |
@@ -1186,66 +1186,66 @@ discard block |
||
| 1186 | 1186 | { |
| 1187 | 1187 | |
| 1188 | 1188 | |
| 1189 | - /** |
|
| 1190 | - * class constructor |
|
| 1191 | - * |
|
| 1192 | - * @deprecated 4.9.59.p |
|
| 1193 | - */ |
|
| 1194 | - public function __construct() |
|
| 1195 | - { |
|
| 1196 | - EE_Error::doing_it_wrong( |
|
| 1197 | - __METHOD__, |
|
| 1198 | - sprintf( |
|
| 1199 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1200 | - __CLASS__, |
|
| 1201 | - 'EventEspresso\core\services\licensing\LicenseServices' |
|
| 1202 | - ), |
|
| 1203 | - '4.9.59.p' |
|
| 1204 | - ); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * The purpose of this function is to display information about Event Espresso data collection |
|
| 1210 | - * and a optin selection for extra data collecting by users. |
|
| 1211 | - * |
|
| 1212 | - * @param bool $extra |
|
| 1213 | - * @return string html. |
|
| 1214 | - * @deprecated 4.9.59.p |
|
| 1215 | - */ |
|
| 1216 | - public static function espresso_data_collection_optin_text($extra = true) |
|
| 1217 | - { |
|
| 1218 | - EE_Error::doing_it_wrong( |
|
| 1219 | - __METHOD__, |
|
| 1220 | - sprintf( |
|
| 1221 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1222 | - __METHOD__, |
|
| 1223 | - 'EventEspresso\core\domain\services\Stats::optinText' |
|
| 1224 | - ), |
|
| 1225 | - '4.9.59.p' |
|
| 1226 | - ); |
|
| 1227 | - Stats::optinText($extra); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
| 1232 | - * |
|
| 1233 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
| 1234 | - * identify plugins. Defaults to core update |
|
| 1235 | - * @return boolean True if update available, false if not. |
|
| 1236 | - * @deprecated 4.9.59.p |
|
| 1237 | - */ |
|
| 1238 | - public static function is_update_available($basename = '') |
|
| 1239 | - { |
|
| 1240 | - EE_Error::doing_it_wrong( |
|
| 1241 | - __METHOD__, |
|
| 1242 | - sprintf( |
|
| 1243 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1244 | - __METHOD__, |
|
| 1245 | - 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
| 1246 | - ), |
|
| 1247 | - '4.9.59.p' |
|
| 1248 | - ); |
|
| 1249 | - return LicenseService::isUpdateAvailable($basename); |
|
| 1250 | - } |
|
| 1189 | + /** |
|
| 1190 | + * class constructor |
|
| 1191 | + * |
|
| 1192 | + * @deprecated 4.9.59.p |
|
| 1193 | + */ |
|
| 1194 | + public function __construct() |
|
| 1195 | + { |
|
| 1196 | + EE_Error::doing_it_wrong( |
|
| 1197 | + __METHOD__, |
|
| 1198 | + sprintf( |
|
| 1199 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1200 | + __CLASS__, |
|
| 1201 | + 'EventEspresso\core\services\licensing\LicenseServices' |
|
| 1202 | + ), |
|
| 1203 | + '4.9.59.p' |
|
| 1204 | + ); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * The purpose of this function is to display information about Event Espresso data collection |
|
| 1210 | + * and a optin selection for extra data collecting by users. |
|
| 1211 | + * |
|
| 1212 | + * @param bool $extra |
|
| 1213 | + * @return string html. |
|
| 1214 | + * @deprecated 4.9.59.p |
|
| 1215 | + */ |
|
| 1216 | + public static function espresso_data_collection_optin_text($extra = true) |
|
| 1217 | + { |
|
| 1218 | + EE_Error::doing_it_wrong( |
|
| 1219 | + __METHOD__, |
|
| 1220 | + sprintf( |
|
| 1221 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1222 | + __METHOD__, |
|
| 1223 | + 'EventEspresso\core\domain\services\Stats::optinText' |
|
| 1224 | + ), |
|
| 1225 | + '4.9.59.p' |
|
| 1226 | + ); |
|
| 1227 | + Stats::optinText($extra); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
| 1232 | + * |
|
| 1233 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
| 1234 | + * identify plugins. Defaults to core update |
|
| 1235 | + * @return boolean True if update available, false if not. |
|
| 1236 | + * @deprecated 4.9.59.p |
|
| 1237 | + */ |
|
| 1238 | + public static function is_update_available($basename = '') |
|
| 1239 | + { |
|
| 1240 | + EE_Error::doing_it_wrong( |
|
| 1241 | + __METHOD__, |
|
| 1242 | + sprintf( |
|
| 1243 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
| 1244 | + __METHOD__, |
|
| 1245 | + 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
| 1246 | + ), |
|
| 1247 | + '4.9.59.p' |
|
| 1248 | + ); |
|
| 1249 | + return LicenseService::isUpdateAvailable($basename); |
|
| 1250 | + } |
|
| 1251 | 1251 | } |
| 1252 | 1252 | \ No newline at end of file |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | <?php |
| 7 | 7 | //we'll only show site-license keys if this is main_site() (which works for both multi-site and single-site wp installations) |
| 8 | 8 | |
| 9 | - if ( is_main_site() ) { ?> |
|
| 9 | + if ( is_main_site() ) { ?> |
|
| 10 | 10 | <h2 class="ee-admin-settings-hdr" style="width:300px;"> |
| 11 | 11 | <?php _e('Your Event Espresso License Key', 'event_espresso'); ?> |
| 12 | 12 | </h2> |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | <?php |
| 7 | 7 | //we'll only show site-license keys if this is main_site() (which works for both multi-site and single-site wp installations) |
| 8 | 8 | |
| 9 | - if ( is_main_site() ) { ?> |
|
| 9 | + if (is_main_site()) { ?> |
|
| 10 | 10 | <h2 class="ee-admin-settings-hdr" style="width:300px;"> |
| 11 | 11 | <?php _e('Your Event Espresso License Key', 'event_espresso'); ?> |
| 12 | 12 | </h2> |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | <tr <?php echo isset($_REQUEST['license_key']) && $_REQUEST['license_key'] == true ? 'class="yellow_alert"' : '' ?>> |
| 17 | 17 | <th> |
| 18 | 18 | <label for="site_license_key"> |
| 19 | - <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info');?> |
|
| 19 | + <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info'); ?> |
|
| 20 | 20 | </label> |
| 21 | 21 | </th> |
| 22 | 22 | <td> |
| 23 | 23 | <input name="site_license_key" id="site_license_key" size="10" class="regular-text" type="text" value="<?php echo esc_attr($site_license_key); ?>" /><?php echo $site_license_key_verified; ?><br/> |
| 24 | 24 | <p class="description"> |
| 25 | - <?php printf( __('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>' ); ?> |
|
| 25 | + <?php printf(__('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>'); ?> |
|
| 26 | 26 | </p> |
| 27 | 27 | </td> |
| 28 | 28 | </tr> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | <h2 id="contact_info_h4" class="ee-admin-settings-hdr"> |
| 38 | - <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info');?> |
|
| 38 | + <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info'); ?> |
|
| 39 | 39 | </h2> |
| 40 | 40 | |
| 41 | 41 | <table class="form-table"> |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | <input id="organization_city" class="regular-text" type="text" name="organization_city" value="<?php echo esc_textarea($organization_city); ?>" /> |
| 84 | 84 | </td> |
| 85 | 85 | </tr> |
| 86 | - <?php echo EEH_Form_Fields::generate_form_input( $states ); ?> |
|
| 87 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
| 86 | + <?php echo EEH_Form_Fields::generate_form_input($states); ?> |
|
| 87 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
| 88 | 88 | <tr> |
| 89 | 89 | <th> |
| 90 | 90 | <label for="organization_zip"> |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | <td> |
| 105 | 105 | <input class="regular-text" type="text" name="organization_email" value="<?php echo esc_textarea($organization_email); ?>" /> |
| 106 | 106 | <p class="description"> |
| 107 | - <?php echo sprintf( esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>' ); ?> |
|
| 107 | + <?php echo sprintf(esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>'); ?> |
|
| 108 | 108 | </p> |
| 109 | 109 | </td> |
| 110 | 110 | </tr> |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | </table> |
| 139 | 139 | |
| 140 | 140 | <h2 class="ee-admin-settings-hdr"> |
| 141 | - <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info');?> |
|
| 141 | + <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info'); ?> |
|
| 142 | 142 | </h2> |
| 143 | 143 | |
| 144 | 144 | <table class="form-table"> |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | </th> |
| 167 | 167 | <td> |
| 168 | 168 | <?php |
| 169 | - if ( $organization_logo_url ) { |
|
| 169 | + if ($organization_logo_url) { |
|
| 170 | 170 | ?> |
| 171 | 171 | <p id="default-logo-thumb"> |
| 172 | 172 | <img id="current-image-thumb" src="<?php echo esc_url($organization_logo_url) ?>" alt="" /><br /> |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | <br/><br/> |
| 185 | 185 | |
| 186 | 186 | <h2 class="ee-admin-settings-hdr"> |
| 187 | - <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info');?> |
|
| 187 | + <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info'); ?> |
|
| 188 | 188 | </h2> |
| 189 | 189 | <p class="description"><?php _e('Enter any links to social accounts for your organization here', 'event_espresso'); ?></p> |
| 190 | 190 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | <br/><br/> |
| 262 | 262 | |
| 263 | 263 | |
| 264 | - <?php if ( is_main_site() ) : ?> |
|
| 264 | + <?php if (is_main_site()) : ?> |
|
| 265 | 265 | <p> |
| 266 | 266 | <?php Stats::optinText(false); ?> |
| 267 | 267 | </p> |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | </th> |
| 278 | 278 | <td> |
| 279 | 279 | <?php |
| 280 | - $values=array( |
|
| 281 | - array('id'=>'yes','text'=> __('Yes! I want to help improve Event Espresso!','event_espresso')), |
|
| 282 | - array('id'=>'no','text'=> __('Not at this time. Maybe later.','event_espresso')) |
|
| 280 | + $values = array( |
|
| 281 | + array('id'=>'yes', 'text'=> __('Yes! I want to help improve Event Espresso!', 'event_espresso')), |
|
| 282 | + array('id'=>'no', 'text'=> __('Not at this time. Maybe later.', 'event_espresso')) |
|
| 283 | 283 | ); |
| 284 | - echo EEH_Form_Fields::select_input('ueip_optin', $values, !empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
| 284 | + echo EEH_Form_Fields::select_input('ueip_optin', $values, ! empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
| 285 | 285 | ?> |
| 286 | 286 | </td> |
| 287 | 287 | </tr> |
@@ -17,1386 +17,1386 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * _question_group |
|
| 22 | - * holds the specific question group object for the question group details screen |
|
| 23 | - * |
|
| 24 | - * @var object |
|
| 25 | - */ |
|
| 26 | - protected $_question_group; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Initialize basic properties. |
|
| 31 | - */ |
|
| 32 | - protected function _init_page_props() |
|
| 33 | - { |
|
| 34 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | - $this->page_label = GEN_SET_LABEL; |
|
| 36 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Set ajax hooks |
|
| 43 | - */ |
|
| 44 | - protected function _ajax_hooks() |
|
| 45 | - { |
|
| 46 | - add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 47 | - add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 48 | - add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 49 | - add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * More page properties initialization. |
|
| 55 | - */ |
|
| 56 | - protected function _define_page_props() |
|
| 57 | - { |
|
| 58 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | - $this->_labels = array( |
|
| 60 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Set page routes property. |
|
| 67 | - */ |
|
| 68 | - protected function _set_page_routes() |
|
| 69 | - { |
|
| 70 | - $this->_page_routes = array( |
|
| 71 | - |
|
| 72 | - 'critical_pages' => array( |
|
| 73 | - 'func' => '_espresso_page_settings', |
|
| 74 | - 'capability' => 'manage_options', |
|
| 75 | - ), |
|
| 76 | - 'update_espresso_page_settings' => array( |
|
| 77 | - 'func' => '_update_espresso_page_settings', |
|
| 78 | - 'capability' => 'manage_options', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - ), |
|
| 81 | - 'default' => array( |
|
| 82 | - 'func' => '_your_organization_settings', |
|
| 83 | - 'capability' => 'manage_options', |
|
| 84 | - ), |
|
| 85 | - |
|
| 86 | - 'update_your_organization_settings' => array( |
|
| 87 | - 'func' => '_update_your_organization_settings', |
|
| 88 | - 'capability' => 'manage_options', |
|
| 89 | - 'noheader' => true, |
|
| 90 | - ), |
|
| 91 | - |
|
| 92 | - 'admin_option_settings' => array( |
|
| 93 | - 'func' => '_admin_option_settings', |
|
| 94 | - 'capability' => 'manage_options', |
|
| 95 | - ), |
|
| 96 | - |
|
| 97 | - 'update_admin_option_settings' => array( |
|
| 98 | - 'func' => '_update_admin_option_settings', |
|
| 99 | - 'capability' => 'manage_options', |
|
| 100 | - 'noheader' => true, |
|
| 101 | - ), |
|
| 102 | - |
|
| 103 | - 'country_settings' => array( |
|
| 104 | - 'func' => '_country_settings', |
|
| 105 | - 'capability' => 'manage_options', |
|
| 106 | - ), |
|
| 107 | - |
|
| 108 | - 'update_country_settings' => array( |
|
| 109 | - 'func' => '_update_country_settings', |
|
| 110 | - 'capability' => 'manage_options', |
|
| 111 | - 'noheader' => true, |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'display_country_settings' => array( |
|
| 115 | - 'func' => 'display_country_settings', |
|
| 116 | - 'capability' => 'manage_options', |
|
| 117 | - 'noheader' => true, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'add_new_state' => array( |
|
| 121 | - 'func' => 'add_new_state', |
|
| 122 | - 'capability' => 'manage_options', |
|
| 123 | - 'noheader' => true, |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'delete_state' => array( |
|
| 127 | - 'func' => 'delete_state', |
|
| 128 | - 'capability' => 'manage_options', |
|
| 129 | - 'noheader' => true, |
|
| 130 | - ), |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Set page configuration property |
|
| 137 | - */ |
|
| 138 | - protected function _set_page_config() |
|
| 139 | - { |
|
| 140 | - $this->_page_config = array( |
|
| 141 | - 'critical_pages' => array( |
|
| 142 | - 'nav' => array( |
|
| 143 | - 'label' => __('Critical Pages', 'event_espresso'), |
|
| 144 | - 'order' => 50, |
|
| 145 | - ), |
|
| 146 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 147 | - 'help_tabs' => array( |
|
| 148 | - 'general_settings_critical_pages_help_tab' => array( |
|
| 149 | - 'title' => __('Critical Pages', 'event_espresso'), |
|
| 150 | - 'filename' => 'general_settings_critical_pages', |
|
| 151 | - ), |
|
| 152 | - ), |
|
| 153 | - 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 154 | - 'require_nonce' => false, |
|
| 155 | - ), |
|
| 156 | - 'default' => array( |
|
| 157 | - 'nav' => array( |
|
| 158 | - 'label' => __('Your Organization', 'event_espresso'), |
|
| 159 | - 'order' => 20, |
|
| 160 | - ), |
|
| 161 | - 'help_tabs' => array( |
|
| 162 | - 'general_settings_your_organization_help_tab' => array( |
|
| 163 | - 'title' => __('Your Organization', 'event_espresso'), |
|
| 164 | - 'filename' => 'general_settings_your_organization', |
|
| 165 | - ), |
|
| 166 | - ), |
|
| 167 | - 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 168 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 169 | - 'require_nonce' => false, |
|
| 170 | - ), |
|
| 171 | - 'admin_option_settings' => array( |
|
| 172 | - 'nav' => array( |
|
| 173 | - 'label' => __('Admin Options', 'event_espresso'), |
|
| 174 | - 'order' => 60, |
|
| 175 | - ), |
|
| 176 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 177 | - 'help_tabs' => array( |
|
| 178 | - 'general_settings_admin_options_help_tab' => array( |
|
| 179 | - 'title' => __('Admin Options', 'event_espresso'), |
|
| 180 | - 'filename' => 'general_settings_admin_options', |
|
| 181 | - ), |
|
| 182 | - ), |
|
| 183 | - 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 184 | - 'require_nonce' => false, |
|
| 185 | - ), |
|
| 186 | - 'country_settings' => array( |
|
| 187 | - 'nav' => array( |
|
| 188 | - 'label' => __('Countries', 'event_espresso'), |
|
| 189 | - 'order' => 70, |
|
| 190 | - ), |
|
| 191 | - 'help_tabs' => array( |
|
| 192 | - 'general_settings_countries_help_tab' => array( |
|
| 193 | - 'title' => __('Countries', 'event_espresso'), |
|
| 194 | - 'filename' => 'general_settings_countries', |
|
| 195 | - ), |
|
| 196 | - ), |
|
| 197 | - 'help_tour' => array('Countries_Help_Tour'), |
|
| 198 | - 'require_nonce' => false, |
|
| 199 | - ), |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - protected function _add_screen_options() |
|
| 206 | - { |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - protected function _add_feature_pointers() |
|
| 210 | - { |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 216 | - */ |
|
| 217 | - public function load_scripts_styles() |
|
| 218 | - { |
|
| 219 | - //styles |
|
| 220 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 221 | - //scripts |
|
| 222 | - wp_enqueue_script('ee_admin_js'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Execute logic running on `admin_init` |
|
| 228 | - */ |
|
| 229 | - public function admin_init() |
|
| 230 | - { |
|
| 231 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
| 232 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 233 | - 'event_espresso' |
|
| 234 | - ); |
|
| 235 | - EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 236 | - 'An error occurred! Please refresh the page and try again.', |
|
| 237 | - 'event_espresso' |
|
| 238 | - ); |
|
| 239 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 240 | - 'Are you sure you want to delete this State / Province?', |
|
| 241 | - 'event_espresso' |
|
| 242 | - ); |
|
| 243 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 244 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 245 | - 'admin-ajax.php?page=espresso_general_settings', |
|
| 246 | - $protocol |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function admin_notices() |
|
| 251 | - { |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function admin_footer_scripts() |
|
| 255 | - { |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Enqueue scripts and styles for the default route. |
|
| 261 | - */ |
|
| 262 | - public function load_scripts_styles_default() |
|
| 263 | - { |
|
| 264 | - //styles |
|
| 265 | - wp_enqueue_style('thickbox'); |
|
| 266 | - //scripts |
|
| 267 | - wp_enqueue_script('media-upload'); |
|
| 268 | - wp_enqueue_script('thickbox'); |
|
| 269 | - wp_register_script( |
|
| 270 | - 'organization_settings', |
|
| 271 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 272 | - array('jquery', 'media-upload', 'thickbox'), |
|
| 273 | - EVENT_ESPRESSO_VERSION, |
|
| 274 | - true |
|
| 275 | - ); |
|
| 276 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 277 | - wp_enqueue_script('organization_settings'); |
|
| 278 | - wp_enqueue_style('organization-css'); |
|
| 279 | - $confirm_image_delete = array( |
|
| 280 | - 'text' => __( |
|
| 281 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 282 | - 'event_espresso' |
|
| 283 | - ), |
|
| 284 | - ); |
|
| 285 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Enqueue scripts and styles for the country settings route. |
|
| 291 | - */ |
|
| 292 | - public function load_scripts_styles_country_settings() |
|
| 293 | - { |
|
| 294 | - //scripts |
|
| 295 | - wp_register_script( |
|
| 296 | - 'gen_settings_countries', |
|
| 297 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 298 | - array('ee_admin_js'), |
|
| 299 | - EVENT_ESPRESSO_VERSION, |
|
| 300 | - true |
|
| 301 | - ); |
|
| 302 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 303 | - wp_enqueue_script('gen_settings_countries'); |
|
| 304 | - wp_enqueue_style('organization-css'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /************* Espresso Pages *************/ |
|
| 309 | - /** |
|
| 310 | - * _espresso_page_settings |
|
| 311 | - * |
|
| 312 | - * @throws \EE_Error |
|
| 313 | - */ |
|
| 314 | - protected function _espresso_page_settings() |
|
| 315 | - { |
|
| 316 | - // Check to make sure all of the main pages are setup properly, |
|
| 317 | - // if not create the default pages and display an admin notice |
|
| 318 | - EEH_Activation::verify_default_pages_exist(); |
|
| 319 | - $this->_transient_garbage_collection(); |
|
| 320 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 321 | - $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 322 | - ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 323 | - : null; |
|
| 324 | - $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 325 | - ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 326 | - : false; |
|
| 327 | - $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 328 | - ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 329 | - : null; |
|
| 330 | - $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 331 | - ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 332 | - : false; |
|
| 333 | - $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 334 | - ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 335 | - : null; |
|
| 336 | - $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 337 | - ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 338 | - : false; |
|
| 339 | - $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 340 | - ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 341 | - : null; |
|
| 342 | - $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 343 | - ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 344 | - : false; |
|
| 345 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 346 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 347 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 348 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 349 | - $this->_template_args, |
|
| 350 | - true |
|
| 351 | - ); |
|
| 352 | - $this->display_admin_page_with_sidebar(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Handler for updating espresso page settings. |
|
| 358 | - */ |
|
| 359 | - protected function _update_espresso_page_settings() |
|
| 360 | - { |
|
| 361 | - // capture incoming request data && set page IDs |
|
| 362 | - EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 363 | - ? absint($this->_req_data['reg_page_id']) |
|
| 364 | - : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 365 | - EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 366 | - ? absint($this->_req_data['txn_page_id']) |
|
| 367 | - : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 368 | - EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 369 | - ? absint($this->_req_data['thank_you_page_id']) |
|
| 370 | - : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 371 | - EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 372 | - ? absint($this->_req_data['cancel_page_id']) |
|
| 373 | - : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 374 | - |
|
| 375 | - EE_Registry::instance()->CFG->core = apply_filters( |
|
| 376 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 377 | - EE_Registry::instance()->CFG->core, |
|
| 378 | - $this->_req_data |
|
| 379 | - ); |
|
| 380 | - $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 381 | - $this->_redirect_after_action( |
|
| 382 | - $this->_update_espresso_configuration( |
|
| 383 | - $what, |
|
| 384 | - EE_Registry::instance()->CFG->core, |
|
| 385 | - __FILE__, |
|
| 386 | - __FUNCTION__, |
|
| 387 | - __LINE__ |
|
| 388 | - ), |
|
| 389 | - $what, |
|
| 390 | - '', |
|
| 391 | - array( |
|
| 392 | - 'action' => 'critical_pages', |
|
| 393 | - ), |
|
| 394 | - true |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /************* Your Organization *************/ |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Output for the Your Organization settings route. |
|
| 404 | - * @throws DomainException |
|
| 405 | - * @throws EE_Error |
|
| 406 | - */ |
|
| 407 | - protected function _your_organization_settings() |
|
| 408 | - { |
|
| 409 | - |
|
| 410 | - $this->_template_args['site_license_key'] = isset( |
|
| 411 | - EE_Registry::instance()->NET_CFG->core->site_license_key |
|
| 412 | - ) |
|
| 413 | - ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key') |
|
| 414 | - : ''; |
|
| 415 | - $this->_template_args['organization_name'] = isset(EE_Registry::instance()->CFG->organization->name) |
|
| 416 | - ? EE_Registry::instance()->CFG->organization->get_pretty('name') |
|
| 417 | - : ''; |
|
| 418 | - $this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1) |
|
| 419 | - ? EE_Registry::instance()->CFG->organization->get_pretty('address_1') |
|
| 420 | - : ''; |
|
| 421 | - $this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2) |
|
| 422 | - ? EE_Registry::instance()->CFG->organization->get_pretty('address_2') |
|
| 423 | - : ''; |
|
| 424 | - $this->_template_args['organization_city'] = isset(EE_Registry::instance()->CFG->organization->city) |
|
| 425 | - ? EE_Registry::instance()->CFG->organization->get_pretty('city') |
|
| 426 | - : ''; |
|
| 427 | - $this->_template_args['organization_zip'] = isset(EE_Registry::instance()->CFG->organization->zip) |
|
| 428 | - ? EE_Registry::instance()->CFG->organization->get_pretty('zip') |
|
| 429 | - : ''; |
|
| 430 | - $this->_template_args['organization_email'] = isset(EE_Registry::instance()->CFG->organization->email) |
|
| 431 | - ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 432 | - : ''; |
|
| 433 | - $this->_template_args['organization_phone'] = isset(EE_Registry::instance()->CFG->organization->phone) |
|
| 434 | - ? EE_Registry::instance()->CFG->organization->get_pretty('phone') |
|
| 435 | - : ''; |
|
| 436 | - $this->_template_args['organization_vat'] = isset(EE_Registry::instance()->CFG->organization->vat) |
|
| 437 | - ? EE_Registry::instance()->CFG->organization->get_pretty('vat') |
|
| 438 | - : ''; |
|
| 439 | - $this->_template_args['currency_sign'] = isset(EE_Registry::instance()->CFG->currency->sign) |
|
| 440 | - ? EE_Registry::instance()->CFG->currency->get_pretty('sign') |
|
| 441 | - : '$'; |
|
| 442 | - $this->_template_args['organization_logo_url'] = isset(EE_Registry::instance()->CFG->organization->logo_url) |
|
| 443 | - ? EE_Registry::instance()->CFG->organization->get_pretty('logo_url') |
|
| 444 | - : false; |
|
| 445 | - $this->_template_args['organization_facebook'] = isset(EE_Registry::instance()->CFG->organization->facebook) |
|
| 446 | - ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
| 447 | - : ''; |
|
| 448 | - $this->_template_args['organization_twitter'] = isset(EE_Registry::instance()->CFG->organization->twitter) |
|
| 449 | - ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
| 450 | - : ''; |
|
| 451 | - $this->_template_args['organization_linkedin'] = isset(EE_Registry::instance()->CFG->organization->linkedin) |
|
| 452 | - ? EE_Registry::instance()->CFG->organization->get_pretty('linkedin') |
|
| 453 | - : ''; |
|
| 454 | - $this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest) |
|
| 455 | - ? EE_Registry::instance()->CFG->organization->get_pretty('pinterest') |
|
| 456 | - : ''; |
|
| 457 | - $this->_template_args['organization_google'] = isset(EE_Registry::instance()->CFG->organization->google) |
|
| 458 | - ? EE_Registry::instance()->CFG->organization->get_pretty('google') |
|
| 459 | - : ''; |
|
| 460 | - $this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram) |
|
| 461 | - ? EE_Registry::instance()->CFG->organization->get_pretty('instagram') |
|
| 462 | - : ''; |
|
| 463 | - //UXIP settings |
|
| 464 | - $this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin) |
|
| 465 | - ? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin') |
|
| 466 | - : 'yes'; |
|
| 467 | - |
|
| 468 | - $STA_ID = isset(EE_Registry::instance()->CFG->organization->STA_ID) |
|
| 469 | - ? EE_Registry::instance()->CFG->organization->STA_ID |
|
| 470 | - : 4; |
|
| 471 | - $this->_template_args['states'] = new EE_Question_Form_Input( |
|
| 472 | - EE_Question::new_instance(array( |
|
| 473 | - 'QST_ID' => 0, |
|
| 474 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 475 | - 'QST_system' => 'admin-state', |
|
| 476 | - )), |
|
| 477 | - EE_Answer::new_instance(array( |
|
| 478 | - 'ANS_ID' => 0, |
|
| 479 | - 'ANS_value' => $STA_ID, |
|
| 480 | - )), |
|
| 481 | - array( |
|
| 482 | - 'input_id' => 'organization_state', |
|
| 483 | - 'input_name' => 'organization_state', |
|
| 484 | - 'input_prefix' => '', |
|
| 485 | - 'append_qstn_id' => false, |
|
| 486 | - ) |
|
| 487 | - ); |
|
| 488 | - |
|
| 489 | - $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 490 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 491 | - : 'US'; |
|
| 492 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 493 | - EE_Question::new_instance(array( |
|
| 494 | - 'QST_ID' => 0, |
|
| 495 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 496 | - 'QST_system' => 'admin-country', |
|
| 497 | - )), |
|
| 498 | - EE_Answer::new_instance(array( |
|
| 499 | - 'ANS_ID' => 0, |
|
| 500 | - 'ANS_value' => $CNT_ISO, |
|
| 501 | - )), |
|
| 502 | - array( |
|
| 503 | - 'input_id' => 'organization_country', |
|
| 504 | - 'input_name' => 'organization_country', |
|
| 505 | - 'input_prefix' => '', |
|
| 506 | - 'append_qstn_id' => false, |
|
| 507 | - ) |
|
| 508 | - ); |
|
| 509 | - |
|
| 510 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 511 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 512 | - |
|
| 513 | - //PUE verification stuff |
|
| 514 | - $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
| 515 | - $verify_fail = get_option($ver_option_key); |
|
| 516 | - $this->_template_args['site_license_key_verified'] = $verify_fail |
|
| 517 | - || ! empty($verify_fail) |
|
| 518 | - || (empty($this->_template_args['site_license_key']) |
|
| 519 | - && empty($verify_fail) |
|
| 520 | - ) |
|
| 521 | - ? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>' |
|
| 522 | - : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>'; |
|
| 523 | - |
|
| 524 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 525 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 527 | - GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', |
|
| 528 | - $this->_template_args, |
|
| 529 | - true |
|
| 530 | - ); |
|
| 531 | - |
|
| 532 | - $this->display_admin_page_with_sidebar(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Handler for updating organziation settings. |
|
| 538 | - */ |
|
| 539 | - protected function _update_your_organization_settings() |
|
| 540 | - { |
|
| 541 | - if (is_main_site()) { |
|
| 542 | - EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key']) |
|
| 543 | - ? sanitize_text_field($this->_req_data['site_license_key']) |
|
| 544 | - : EE_Registry::instance()->NET_CFG->core->site_license_key; |
|
| 545 | - } |
|
| 546 | - EE_Registry::instance()->CFG->organization->name = isset($this->_req_data['organization_name']) |
|
| 547 | - ? sanitize_text_field($this->_req_data['organization_name']) |
|
| 548 | - : EE_Registry::instance()->CFG->organization->name; |
|
| 549 | - EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1']) |
|
| 550 | - ? sanitize_text_field($this->_req_data['organization_address_1']) |
|
| 551 | - : EE_Registry::instance()->CFG->organization->address_1; |
|
| 552 | - EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2']) |
|
| 553 | - ? sanitize_text_field($this->_req_data['organization_address_2']) |
|
| 554 | - : EE_Registry::instance()->CFG->organization->address_2; |
|
| 555 | - EE_Registry::instance()->CFG->organization->city = isset($this->_req_data['organization_city']) |
|
| 556 | - ? sanitize_text_field($this->_req_data['organization_city']) |
|
| 557 | - : EE_Registry::instance()->CFG->organization->city; |
|
| 558 | - EE_Registry::instance()->CFG->organization->STA_ID = isset($this->_req_data['organization_state']) |
|
| 559 | - ? absint($this->_req_data['organization_state']) |
|
| 560 | - : EE_Registry::instance()->CFG->organization->STA_ID; |
|
| 561 | - EE_Registry::instance()->CFG->organization->CNT_ISO = isset($this->_req_data['organization_country']) |
|
| 562 | - ? sanitize_text_field($this->_req_data['organization_country']) |
|
| 563 | - : EE_Registry::instance()->CFG->organization->CNT_ISO; |
|
| 564 | - EE_Registry::instance()->CFG->organization->zip = isset($this->_req_data['organization_zip']) |
|
| 565 | - ? sanitize_text_field($this->_req_data['organization_zip']) |
|
| 566 | - : EE_Registry::instance()->CFG->organization->zip; |
|
| 567 | - EE_Registry::instance()->CFG->organization->email = isset($this->_req_data['organization_email']) |
|
| 568 | - ? sanitize_email($this->_req_data['organization_email']) |
|
| 569 | - : EE_Registry::instance()->CFG->organization->email; |
|
| 570 | - EE_Registry::instance()->CFG->organization->vat = isset($this->_req_data['organization_vat']) |
|
| 571 | - ? sanitize_text_field($this->_req_data['organization_vat']) |
|
| 572 | - : EE_Registry::instance()->CFG->organization->vat; |
|
| 573 | - EE_Registry::instance()->CFG->organization->phone = isset($this->_req_data['organization_phone']) |
|
| 574 | - ? sanitize_text_field($this->_req_data['organization_phone']) |
|
| 575 | - : EE_Registry::instance()->CFG->organization->phone; |
|
| 576 | - EE_Registry::instance()->CFG->organization->logo_url = isset($this->_req_data['organization_logo_url']) |
|
| 577 | - ? esc_url_raw($this->_req_data['organization_logo_url']) |
|
| 578 | - : EE_Registry::instance()->CFG->organization->logo_url; |
|
| 579 | - EE_Registry::instance()->CFG->organization->facebook = isset($this->_req_data['organization_facebook']) |
|
| 580 | - ? esc_url_raw($this->_req_data['organization_facebook']) |
|
| 581 | - : EE_Registry::instance()->CFG->organization->facebook; |
|
| 582 | - EE_Registry::instance()->CFG->organization->twitter = isset($this->_req_data['organization_twitter']) |
|
| 583 | - ? esc_url_raw($this->_req_data['organization_twitter']) |
|
| 584 | - : EE_Registry::instance()->CFG->organization->twitter; |
|
| 585 | - EE_Registry::instance()->CFG->organization->linkedin = isset($this->_req_data['organization_linkedin']) |
|
| 586 | - ? esc_url_raw($this->_req_data['organization_linkedin']) |
|
| 587 | - : EE_Registry::instance()->CFG->organization->linkedin; |
|
| 588 | - EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest']) |
|
| 589 | - ? esc_url_raw($this->_req_data['organization_pinterest']) |
|
| 590 | - : EE_Registry::instance()->CFG->organization->pinterest; |
|
| 591 | - EE_Registry::instance()->CFG->organization->google = isset($this->_req_data['organization_google']) |
|
| 592 | - ? esc_url_raw($this->_req_data['organization_google']) |
|
| 593 | - : EE_Registry::instance()->CFG->organization->google; |
|
| 594 | - EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram']) |
|
| 595 | - ? esc_url_raw($this->_req_data['organization_instagram']) |
|
| 596 | - : EE_Registry::instance()->CFG->organization->instagram; |
|
| 597 | - EE_Registry::instance()->CFG->core->ee_ueip_optin = isset($this->_req_data['ueip_optin']) |
|
| 598 | - && ! empty($this->_req_data['ueip_optin']) |
|
| 599 | - ? filter_var($this->_req_data['ueip_optin'], FILTER_VALIDATE_BOOLEAN) |
|
| 600 | - : EE_Registry::instance()->CFG->core->ee_ueip_optin; |
|
| 601 | - |
|
| 602 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config( |
|
| 603 | - EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - EE_Registry::instance()->CFG = apply_filters( |
|
| 607 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 608 | - EE_Registry::instance()->CFG |
|
| 609 | - ); |
|
| 610 | - |
|
| 611 | - $what = 'Your Organization Settings'; |
|
| 612 | - $success = $this->_update_espresso_configuration( |
|
| 613 | - $what, |
|
| 614 | - EE_Registry::instance()->CFG, |
|
| 615 | - __FILE__, |
|
| 616 | - __FUNCTION__, |
|
| 617 | - __LINE__ |
|
| 618 | - ); |
|
| 619 | - |
|
| 620 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default')); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - /************* Admin Options *************/ |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * _admin_option_settings |
|
| 630 | - * |
|
| 631 | - * @throws \EE_Error |
|
| 632 | - * @throws \LogicException |
|
| 633 | - */ |
|
| 634 | - protected function _admin_option_settings() |
|
| 635 | - { |
|
| 636 | - $this->_template_args['admin_page_content'] = ''; |
|
| 637 | - try { |
|
| 638 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 639 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 640 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 641 | - // also need to account for the do_action that was in the old template |
|
| 642 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 643 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 644 | - } catch (Exception $e) { |
|
| 645 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | - } |
|
| 647 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 648 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 649 | - $this->display_admin_page_with_sidebar(); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * _update_admin_option_settings |
|
| 655 | - * |
|
| 656 | - * @throws \EE_Error |
|
| 657 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 658 | - * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 659 | - * @throws \InvalidArgumentException |
|
| 660 | - * @throws \LogicException |
|
| 661 | - */ |
|
| 662 | - protected function _update_admin_option_settings() |
|
| 663 | - { |
|
| 664 | - try { |
|
| 665 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 666 | - $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
| 667 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 668 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 669 | - EE_Registry::instance()->CFG->admin |
|
| 670 | - ); |
|
| 671 | - } catch (Exception $e) { |
|
| 672 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 673 | - } |
|
| 674 | - $this->_redirect_after_action( |
|
| 675 | - apply_filters( |
|
| 676 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 677 | - $this->_update_espresso_configuration( |
|
| 678 | - 'Admin Options', |
|
| 679 | - EE_Registry::instance()->CFG->admin, |
|
| 680 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 681 | - ) |
|
| 682 | - ), |
|
| 683 | - 'Admin Options', |
|
| 684 | - 'updated', |
|
| 685 | - array('action' => 'admin_option_settings') |
|
| 686 | - ); |
|
| 687 | - |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /************* Countries *************/ |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Output Country Settings view. |
|
| 696 | - * @throws DomainException |
|
| 697 | - * @throws EE_Error |
|
| 698 | - */ |
|
| 699 | - protected function _country_settings() |
|
| 700 | - { |
|
| 701 | - $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 702 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 703 | - : 'US'; |
|
| 704 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 705 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 706 | - : $CNT_ISO; |
|
| 707 | - |
|
| 708 | - //load field generator helper |
|
| 709 | - |
|
| 710 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 711 | - |
|
| 712 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 713 | - EE_Question::new_instance(array( |
|
| 714 | - 'QST_ID' => 0, |
|
| 715 | - 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
| 716 | - 'QST_system' => 'admin-country', |
|
| 717 | - )), |
|
| 718 | - EE_Answer::new_instance(array( |
|
| 719 | - 'ANS_ID' => 0, |
|
| 720 | - 'ANS_value' => $CNT_ISO, |
|
| 721 | - )), |
|
| 722 | - array( |
|
| 723 | - 'input_id' => 'country', |
|
| 724 | - 'input_name' => 'country', |
|
| 725 | - 'input_prefix' => '', |
|
| 726 | - 'append_qstn_id' => false, |
|
| 727 | - ) |
|
| 728 | - ); |
|
| 729 | - |
|
| 730 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 731 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 732 | - $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
| 733 | - $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
| 734 | - |
|
| 735 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 736 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 737 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 738 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 739 | - $this->_template_args, |
|
| 740 | - true |
|
| 741 | - ); |
|
| 742 | - $this->display_admin_page_with_no_sidebar(); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * display_country_settings |
|
| 748 | - * |
|
| 749 | - * @access public |
|
| 750 | - * @param string $CNT_ISO |
|
| 751 | - * @return mixed string | array |
|
| 752 | - * @throws DomainException |
|
| 753 | - */ |
|
| 754 | - public function display_country_settings($CNT_ISO = '') |
|
| 755 | - { |
|
| 756 | - |
|
| 757 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 758 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 759 | - : $CNT_ISO; |
|
| 760 | - if (! $CNT_ISO) { |
|
| 761 | - return ''; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - // for ajax |
|
| 765 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 766 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 767 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 768 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 769 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 770 | - |
|
| 771 | - $country_input_types = array( |
|
| 772 | - 'CNT_active' => array( |
|
| 773 | - 'type' => 'RADIO_BTN', |
|
| 774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | - 'class' => '', |
|
| 776 | - 'options' => $this->_yes_no_values, |
|
| 777 | - 'use_desc_4_label' => true, |
|
| 778 | - ), |
|
| 779 | - 'CNT_ISO' => array( |
|
| 780 | - 'type' => 'TEXT', |
|
| 781 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 782 | - 'class' => 'small-text', |
|
| 783 | - ), |
|
| 784 | - 'CNT_ISO3' => array( |
|
| 785 | - 'type' => 'TEXT', |
|
| 786 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | - 'class' => 'small-text', |
|
| 788 | - ), |
|
| 789 | - 'RGN_ID' => array( |
|
| 790 | - 'type' => 'TEXT', |
|
| 791 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 792 | - 'class' => 'small-text', |
|
| 793 | - ), |
|
| 794 | - 'CNT_name' => array( |
|
| 795 | - 'type' => 'TEXT', |
|
| 796 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 797 | - 'class' => 'regular-text', |
|
| 798 | - ), |
|
| 799 | - 'CNT_cur_code' => array( |
|
| 800 | - 'type' => 'TEXT', |
|
| 801 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 802 | - 'class' => 'small-text', |
|
| 803 | - ), |
|
| 804 | - 'CNT_cur_single' => array( |
|
| 805 | - 'type' => 'TEXT', |
|
| 806 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 807 | - 'class' => 'medium-text', |
|
| 808 | - ), |
|
| 809 | - 'CNT_cur_plural' => array( |
|
| 810 | - 'type' => 'TEXT', |
|
| 811 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 812 | - 'class' => 'medium-text', |
|
| 813 | - ), |
|
| 814 | - 'CNT_cur_sign' => array( |
|
| 815 | - 'type' => 'TEXT', |
|
| 816 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 817 | - 'class' => 'small-text', |
|
| 818 | - 'htmlentities' => false, |
|
| 819 | - ), |
|
| 820 | - 'CNT_cur_sign_b4' => array( |
|
| 821 | - 'type' => 'RADIO_BTN', |
|
| 822 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 823 | - 'class' => '', |
|
| 824 | - 'options' => $this->_yes_no_values, |
|
| 825 | - 'use_desc_4_label' => true, |
|
| 826 | - ), |
|
| 827 | - 'CNT_cur_dec_plc' => array( |
|
| 828 | - 'type' => 'RADIO_BTN', |
|
| 829 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 830 | - 'class' => '', |
|
| 831 | - 'options' => array( |
|
| 832 | - array('id' => 0, 'text' => ''), |
|
| 833 | - array('id' => 1, 'text' => ''), |
|
| 834 | - array('id' => 2, 'text' => ''), |
|
| 835 | - array('id' => 3, 'text' => ''), |
|
| 836 | - ), |
|
| 837 | - ), |
|
| 838 | - 'CNT_cur_dec_mrk' => array( |
|
| 839 | - 'type' => 'RADIO_BTN', |
|
| 840 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 841 | - 'class' => '', |
|
| 842 | - 'options' => array( |
|
| 843 | - array( |
|
| 844 | - 'id' => ',', |
|
| 845 | - 'text' => __(', (comma)', 'event_espresso'), |
|
| 846 | - ), |
|
| 847 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 848 | - ), |
|
| 849 | - 'use_desc_4_label' => true, |
|
| 850 | - ), |
|
| 851 | - 'CNT_cur_thsnds' => array( |
|
| 852 | - 'type' => 'RADIO_BTN', |
|
| 853 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 854 | - 'class' => '', |
|
| 855 | - 'options' => array( |
|
| 856 | - array( |
|
| 857 | - 'id' => ',', |
|
| 858 | - 'text' => __(', (comma)', 'event_espresso'), |
|
| 859 | - ), |
|
| 860 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 861 | - ), |
|
| 862 | - 'use_desc_4_label' => true, |
|
| 863 | - ), |
|
| 864 | - 'CNT_tel_code' => array( |
|
| 865 | - 'type' => 'TEXT', |
|
| 866 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 867 | - 'class' => 'small-text', |
|
| 868 | - ), |
|
| 869 | - 'CNT_is_EU' => array( |
|
| 870 | - 'type' => 'RADIO_BTN', |
|
| 871 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 872 | - 'class' => '', |
|
| 873 | - 'options' => $this->_yes_no_values, |
|
| 874 | - 'use_desc_4_label' => true, |
|
| 875 | - ), |
|
| 876 | - ); |
|
| 877 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 878 | - $country, |
|
| 879 | - $country_input_types |
|
| 880 | - ); |
|
| 881 | - $country_details_settings = EEH_Template::display_template( |
|
| 882 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 883 | - $this->_template_args, |
|
| 884 | - true |
|
| 885 | - ); |
|
| 886 | - |
|
| 887 | - if (defined('DOING_AJAX')) { |
|
| 888 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 889 | - echo wp_json_encode(array( |
|
| 890 | - 'return_data' => $country_details_settings, |
|
| 891 | - 'success' => $notices['success'], |
|
| 892 | - 'errors' => $notices['errors'], |
|
| 893 | - )); |
|
| 894 | - die(); |
|
| 895 | - } else { |
|
| 896 | - return $country_details_settings; |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * display_country_states |
|
| 903 | - * |
|
| 904 | - * @access public |
|
| 905 | - * @param string $CNT_ISO |
|
| 906 | - * @return string |
|
| 907 | - * @throws DomainException |
|
| 908 | - */ |
|
| 909 | - public function display_country_states($CNT_ISO = '') |
|
| 910 | - { |
|
| 911 | - |
|
| 912 | - $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
| 913 | - |
|
| 914 | - if (! $CNT_ISO) { |
|
| 915 | - return ''; |
|
| 916 | - } |
|
| 917 | - // for ajax |
|
| 918 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 919 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 920 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 921 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 922 | - $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 923 | - |
|
| 924 | - if ($states) { |
|
| 925 | - foreach ($states as $STA_ID => $state) { |
|
| 926 | - if ($state instanceof EE_State) { |
|
| 927 | - //STA_abbrev STA_name STA_active |
|
| 928 | - $state_input_types = array( |
|
| 929 | - 'STA_abbrev' => array( |
|
| 930 | - 'type' => 'TEXT', |
|
| 931 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 932 | - 'class' => 'mid-text', |
|
| 933 | - ), |
|
| 934 | - 'STA_name' => array( |
|
| 935 | - 'type' => 'TEXT', |
|
| 936 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 937 | - 'class' => 'regular-text', |
|
| 938 | - ), |
|
| 939 | - 'STA_active' => array( |
|
| 940 | - 'type' => 'RADIO_BTN', |
|
| 941 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 942 | - 'options' => $this->_yes_no_values, |
|
| 943 | - 'use_desc_4_label' => true, |
|
| 944 | - ), |
|
| 945 | - ); |
|
| 946 | - $this->_template_args['states'][$STA_ID]['inputs'] = |
|
| 947 | - EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 948 | - $state, |
|
| 949 | - $state_input_types |
|
| 950 | - ); |
|
| 951 | - $query_args = array( |
|
| 952 | - 'action' => 'delete_state', |
|
| 953 | - 'STA_ID' => $STA_ID, |
|
| 954 | - 'CNT_ISO' => $CNT_ISO, |
|
| 955 | - 'STA_abbrev' => $state->abbrev(), |
|
| 956 | - ); |
|
| 957 | - $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
| 958 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 959 | - $query_args, |
|
| 960 | - GEN_SET_ADMIN_URL |
|
| 961 | - ); |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - } else { |
|
| 965 | - $this->_template_args['states'] = false; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 969 | - array('action' => 'add_new_state'), |
|
| 970 | - GEN_SET_ADMIN_URL |
|
| 971 | - ); |
|
| 972 | - |
|
| 973 | - $state_details_settings = EEH_Template::display_template( |
|
| 974 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 975 | - $this->_template_args, |
|
| 976 | - true |
|
| 977 | - ); |
|
| 978 | - |
|
| 979 | - if (defined('DOING_AJAX')) { |
|
| 980 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 981 | - echo wp_json_encode(array( |
|
| 982 | - 'return_data' => $state_details_settings, |
|
| 983 | - 'success' => $notices['success'], |
|
| 984 | - 'errors' => $notices['errors'], |
|
| 985 | - )); |
|
| 986 | - die(); |
|
| 987 | - } else { |
|
| 988 | - return $state_details_settings; |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * add_new_state |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @return void |
|
| 998 | - * @throws EE_Error |
|
| 999 | - */ |
|
| 1000 | - public function add_new_state() |
|
| 1001 | - { |
|
| 1002 | - |
|
| 1003 | - $success = true; |
|
| 1004 | - |
|
| 1005 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1006 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1007 | - : false; |
|
| 1008 | - if (! $CNT_ISO) { |
|
| 1009 | - EE_Error::add_error( |
|
| 1010 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1011 | - __FILE__, |
|
| 1012 | - __FUNCTION__, |
|
| 1013 | - __LINE__ |
|
| 1014 | - ); |
|
| 1015 | - $success = false; |
|
| 1016 | - } |
|
| 1017 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1018 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1019 | - : false; |
|
| 1020 | - if (! $STA_abbrev) { |
|
| 1021 | - EE_Error::add_error( |
|
| 1022 | - __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 1023 | - __FILE__, |
|
| 1024 | - __FUNCTION__, |
|
| 1025 | - __LINE__ |
|
| 1026 | - ); |
|
| 1027 | - $success = false; |
|
| 1028 | - } |
|
| 1029 | - $STA_name = isset($this->_req_data['STA_name']) |
|
| 1030 | - ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 1031 | - : false; |
|
| 1032 | - if (! $STA_name) { |
|
| 1033 | - EE_Error::add_error( |
|
| 1034 | - __('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1035 | - __FILE__, |
|
| 1036 | - __FUNCTION__, |
|
| 1037 | - __LINE__ |
|
| 1038 | - ); |
|
| 1039 | - $success = false; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - if ($success) { |
|
| 1043 | - $cols_n_values = array( |
|
| 1044 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1045 | - 'STA_abbrev' => $STA_abbrev, |
|
| 1046 | - 'STA_name' => $STA_name, |
|
| 1047 | - 'STA_active' => true, |
|
| 1048 | - ); |
|
| 1049 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1050 | - EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if (defined('DOING_AJAX')) { |
|
| 1054 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1055 | - echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1056 | - die(); |
|
| 1057 | - } else { |
|
| 1058 | - $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * delete_state |
|
| 1065 | - * |
|
| 1066 | - * @access public |
|
| 1067 | - * @return boolean |
|
| 1068 | - */ |
|
| 1069 | - public function delete_state() |
|
| 1070 | - { |
|
| 1071 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1072 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1073 | - : false; |
|
| 1074 | - $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1075 | - ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1076 | - : false; |
|
| 1077 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1078 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1079 | - : false; |
|
| 1080 | - if (! $STA_ID) { |
|
| 1081 | - EE_Error::add_error( |
|
| 1082 | - __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1083 | - __FILE__, |
|
| 1084 | - __FUNCTION__, |
|
| 1085 | - __LINE__ |
|
| 1086 | - ); |
|
| 1087 | - return false; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1091 | - if ($success !== false) { |
|
| 1092 | - do_action( |
|
| 1093 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1094 | - $CNT_ISO, |
|
| 1095 | - $STA_ID, |
|
| 1096 | - array('STA_abbrev' => $STA_abbrev) |
|
| 1097 | - ); |
|
| 1098 | - EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
| 1099 | - } |
|
| 1100 | - if (defined('DOING_AJAX')) { |
|
| 1101 | - $notices = EE_Error::get_notices(false, false); |
|
| 1102 | - $notices['return_data'] = true; |
|
| 1103 | - echo wp_json_encode($notices); |
|
| 1104 | - die(); |
|
| 1105 | - } else { |
|
| 1106 | - $this->_redirect_after_action( |
|
| 1107 | - $success, |
|
| 1108 | - 'State', |
|
| 1109 | - 'deleted', |
|
| 1110 | - array('action' => 'country_settings') |
|
| 1111 | - ); |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * _update_country_settings |
|
| 1118 | - * |
|
| 1119 | - * @access protected |
|
| 1120 | - * @return void |
|
| 1121 | - * @throws EE_Error |
|
| 1122 | - */ |
|
| 1123 | - protected function _update_country_settings() |
|
| 1124 | - { |
|
| 1125 | - // grab the country ISO code |
|
| 1126 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 1127 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1128 | - : false; |
|
| 1129 | - if (! $CNT_ISO) { |
|
| 1130 | - EE_Error::add_error( |
|
| 1131 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1132 | - __FILE__, |
|
| 1133 | - __FUNCTION__, |
|
| 1134 | - __LINE__ |
|
| 1135 | - ); |
|
| 1136 | - |
|
| 1137 | - return; |
|
| 1138 | - } |
|
| 1139 | - $cols_n_values = array(); |
|
| 1140 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
| 1141 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
| 1142 | - : false; |
|
| 1143 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1144 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1145 | - : null; |
|
| 1146 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1147 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1148 | - : null; |
|
| 1149 | - $cols_n_values['CNT_cur_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
| 1150 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) |
|
| 1151 | - : 'USD'; |
|
| 1152 | - $cols_n_values['CNT_cur_single'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1153 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1154 | - : 'dollar'; |
|
| 1155 | - $cols_n_values['CNT_cur_plural'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1156 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1157 | - : 'dollars'; |
|
| 1158 | - $cols_n_values['CNT_cur_sign'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1159 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1160 | - : '$'; |
|
| 1161 | - $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1162 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1163 | - : true; |
|
| 1164 | - $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1165 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1166 | - : 2; |
|
| 1167 | - $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1168 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1169 | - : '.'; |
|
| 1170 | - $cols_n_values['CNT_cur_thsnds'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1171 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1172 | - : ','; |
|
| 1173 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1174 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1175 | - : null; |
|
| 1176 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1177 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1178 | - : false; |
|
| 1179 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1180 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1181 | - : false; |
|
| 1182 | - // allow filtering of country data |
|
| 1183 | - $cols_n_values = apply_filters( |
|
| 1184 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1185 | - $cols_n_values |
|
| 1186 | - ); |
|
| 1187 | - |
|
| 1188 | - // where values |
|
| 1189 | - $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1190 | - // run the update |
|
| 1191 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1192 | - |
|
| 1193 | - if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1194 | - // allow filtering of states data |
|
| 1195 | - $states = apply_filters( |
|
| 1196 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1197 | - $this->_req_data['states'] |
|
| 1198 | - ); |
|
| 1199 | - |
|
| 1200 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1201 | - foreach ($states as $STA_ID => $state) { |
|
| 1202 | - $cols_n_values = array( |
|
| 1203 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1204 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1205 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1206 | - 'STA_active' => (bool)absint($state['STA_active']), |
|
| 1207 | - ); |
|
| 1208 | - // where values |
|
| 1209 | - $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1210 | - // run the update |
|
| 1211 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1212 | - if ($success !== false) { |
|
| 1213 | - do_action( |
|
| 1214 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1215 | - $CNT_ISO, |
|
| 1216 | - $STA_ID, |
|
| 1217 | - $cols_n_values |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1223 | - if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1224 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1225 | - ) { |
|
| 1226 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1227 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - if ($success !== false) { |
|
| 1231 | - EE_Error::add_success( |
|
| 1232 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1233 | - ); |
|
| 1234 | - } |
|
| 1235 | - $this->_redirect_after_action( |
|
| 1236 | - $success, |
|
| 1237 | - '', |
|
| 1238 | - '', |
|
| 1239 | - array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1240 | - true |
|
| 1241 | - ); |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * form_form_field_label_wrap |
|
| 1247 | - * |
|
| 1248 | - * @access public |
|
| 1249 | - * @param string $label |
|
| 1250 | - * @return string |
|
| 1251 | - */ |
|
| 1252 | - public function country_form_field_label_wrap($label, $required_text) |
|
| 1253 | - { |
|
| 1254 | - return ' |
|
| 20 | + /** |
|
| 21 | + * _question_group |
|
| 22 | + * holds the specific question group object for the question group details screen |
|
| 23 | + * |
|
| 24 | + * @var object |
|
| 25 | + */ |
|
| 26 | + protected $_question_group; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Initialize basic properties. |
|
| 31 | + */ |
|
| 32 | + protected function _init_page_props() |
|
| 33 | + { |
|
| 34 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | + $this->page_label = GEN_SET_LABEL; |
|
| 36 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Set ajax hooks |
|
| 43 | + */ |
|
| 44 | + protected function _ajax_hooks() |
|
| 45 | + { |
|
| 46 | + add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 47 | + add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 48 | + add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 49 | + add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * More page properties initialization. |
|
| 55 | + */ |
|
| 56 | + protected function _define_page_props() |
|
| 57 | + { |
|
| 58 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | + $this->_labels = array( |
|
| 60 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Set page routes property. |
|
| 67 | + */ |
|
| 68 | + protected function _set_page_routes() |
|
| 69 | + { |
|
| 70 | + $this->_page_routes = array( |
|
| 71 | + |
|
| 72 | + 'critical_pages' => array( |
|
| 73 | + 'func' => '_espresso_page_settings', |
|
| 74 | + 'capability' => 'manage_options', |
|
| 75 | + ), |
|
| 76 | + 'update_espresso_page_settings' => array( |
|
| 77 | + 'func' => '_update_espresso_page_settings', |
|
| 78 | + 'capability' => 'manage_options', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + ), |
|
| 81 | + 'default' => array( |
|
| 82 | + 'func' => '_your_organization_settings', |
|
| 83 | + 'capability' => 'manage_options', |
|
| 84 | + ), |
|
| 85 | + |
|
| 86 | + 'update_your_organization_settings' => array( |
|
| 87 | + 'func' => '_update_your_organization_settings', |
|
| 88 | + 'capability' => 'manage_options', |
|
| 89 | + 'noheader' => true, |
|
| 90 | + ), |
|
| 91 | + |
|
| 92 | + 'admin_option_settings' => array( |
|
| 93 | + 'func' => '_admin_option_settings', |
|
| 94 | + 'capability' => 'manage_options', |
|
| 95 | + ), |
|
| 96 | + |
|
| 97 | + 'update_admin_option_settings' => array( |
|
| 98 | + 'func' => '_update_admin_option_settings', |
|
| 99 | + 'capability' => 'manage_options', |
|
| 100 | + 'noheader' => true, |
|
| 101 | + ), |
|
| 102 | + |
|
| 103 | + 'country_settings' => array( |
|
| 104 | + 'func' => '_country_settings', |
|
| 105 | + 'capability' => 'manage_options', |
|
| 106 | + ), |
|
| 107 | + |
|
| 108 | + 'update_country_settings' => array( |
|
| 109 | + 'func' => '_update_country_settings', |
|
| 110 | + 'capability' => 'manage_options', |
|
| 111 | + 'noheader' => true, |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'display_country_settings' => array( |
|
| 115 | + 'func' => 'display_country_settings', |
|
| 116 | + 'capability' => 'manage_options', |
|
| 117 | + 'noheader' => true, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'add_new_state' => array( |
|
| 121 | + 'func' => 'add_new_state', |
|
| 122 | + 'capability' => 'manage_options', |
|
| 123 | + 'noheader' => true, |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'delete_state' => array( |
|
| 127 | + 'func' => 'delete_state', |
|
| 128 | + 'capability' => 'manage_options', |
|
| 129 | + 'noheader' => true, |
|
| 130 | + ), |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Set page configuration property |
|
| 137 | + */ |
|
| 138 | + protected function _set_page_config() |
|
| 139 | + { |
|
| 140 | + $this->_page_config = array( |
|
| 141 | + 'critical_pages' => array( |
|
| 142 | + 'nav' => array( |
|
| 143 | + 'label' => __('Critical Pages', 'event_espresso'), |
|
| 144 | + 'order' => 50, |
|
| 145 | + ), |
|
| 146 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 147 | + 'help_tabs' => array( |
|
| 148 | + 'general_settings_critical_pages_help_tab' => array( |
|
| 149 | + 'title' => __('Critical Pages', 'event_espresso'), |
|
| 150 | + 'filename' => 'general_settings_critical_pages', |
|
| 151 | + ), |
|
| 152 | + ), |
|
| 153 | + 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 154 | + 'require_nonce' => false, |
|
| 155 | + ), |
|
| 156 | + 'default' => array( |
|
| 157 | + 'nav' => array( |
|
| 158 | + 'label' => __('Your Organization', 'event_espresso'), |
|
| 159 | + 'order' => 20, |
|
| 160 | + ), |
|
| 161 | + 'help_tabs' => array( |
|
| 162 | + 'general_settings_your_organization_help_tab' => array( |
|
| 163 | + 'title' => __('Your Organization', 'event_espresso'), |
|
| 164 | + 'filename' => 'general_settings_your_organization', |
|
| 165 | + ), |
|
| 166 | + ), |
|
| 167 | + 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 168 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 169 | + 'require_nonce' => false, |
|
| 170 | + ), |
|
| 171 | + 'admin_option_settings' => array( |
|
| 172 | + 'nav' => array( |
|
| 173 | + 'label' => __('Admin Options', 'event_espresso'), |
|
| 174 | + 'order' => 60, |
|
| 175 | + ), |
|
| 176 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 177 | + 'help_tabs' => array( |
|
| 178 | + 'general_settings_admin_options_help_tab' => array( |
|
| 179 | + 'title' => __('Admin Options', 'event_espresso'), |
|
| 180 | + 'filename' => 'general_settings_admin_options', |
|
| 181 | + ), |
|
| 182 | + ), |
|
| 183 | + 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 184 | + 'require_nonce' => false, |
|
| 185 | + ), |
|
| 186 | + 'country_settings' => array( |
|
| 187 | + 'nav' => array( |
|
| 188 | + 'label' => __('Countries', 'event_espresso'), |
|
| 189 | + 'order' => 70, |
|
| 190 | + ), |
|
| 191 | + 'help_tabs' => array( |
|
| 192 | + 'general_settings_countries_help_tab' => array( |
|
| 193 | + 'title' => __('Countries', 'event_espresso'), |
|
| 194 | + 'filename' => 'general_settings_countries', |
|
| 195 | + ), |
|
| 196 | + ), |
|
| 197 | + 'help_tour' => array('Countries_Help_Tour'), |
|
| 198 | + 'require_nonce' => false, |
|
| 199 | + ), |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + protected function _add_screen_options() |
|
| 206 | + { |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + protected function _add_feature_pointers() |
|
| 210 | + { |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 216 | + */ |
|
| 217 | + public function load_scripts_styles() |
|
| 218 | + { |
|
| 219 | + //styles |
|
| 220 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 221 | + //scripts |
|
| 222 | + wp_enqueue_script('ee_admin_js'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Execute logic running on `admin_init` |
|
| 228 | + */ |
|
| 229 | + public function admin_init() |
|
| 230 | + { |
|
| 231 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
| 232 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 233 | + 'event_espresso' |
|
| 234 | + ); |
|
| 235 | + EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 236 | + 'An error occurred! Please refresh the page and try again.', |
|
| 237 | + 'event_espresso' |
|
| 238 | + ); |
|
| 239 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 240 | + 'Are you sure you want to delete this State / Province?', |
|
| 241 | + 'event_espresso' |
|
| 242 | + ); |
|
| 243 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 244 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 245 | + 'admin-ajax.php?page=espresso_general_settings', |
|
| 246 | + $protocol |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function admin_notices() |
|
| 251 | + { |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function admin_footer_scripts() |
|
| 255 | + { |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Enqueue scripts and styles for the default route. |
|
| 261 | + */ |
|
| 262 | + public function load_scripts_styles_default() |
|
| 263 | + { |
|
| 264 | + //styles |
|
| 265 | + wp_enqueue_style('thickbox'); |
|
| 266 | + //scripts |
|
| 267 | + wp_enqueue_script('media-upload'); |
|
| 268 | + wp_enqueue_script('thickbox'); |
|
| 269 | + wp_register_script( |
|
| 270 | + 'organization_settings', |
|
| 271 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 272 | + array('jquery', 'media-upload', 'thickbox'), |
|
| 273 | + EVENT_ESPRESSO_VERSION, |
|
| 274 | + true |
|
| 275 | + ); |
|
| 276 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 277 | + wp_enqueue_script('organization_settings'); |
|
| 278 | + wp_enqueue_style('organization-css'); |
|
| 279 | + $confirm_image_delete = array( |
|
| 280 | + 'text' => __( |
|
| 281 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 282 | + 'event_espresso' |
|
| 283 | + ), |
|
| 284 | + ); |
|
| 285 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Enqueue scripts and styles for the country settings route. |
|
| 291 | + */ |
|
| 292 | + public function load_scripts_styles_country_settings() |
|
| 293 | + { |
|
| 294 | + //scripts |
|
| 295 | + wp_register_script( |
|
| 296 | + 'gen_settings_countries', |
|
| 297 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 298 | + array('ee_admin_js'), |
|
| 299 | + EVENT_ESPRESSO_VERSION, |
|
| 300 | + true |
|
| 301 | + ); |
|
| 302 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 303 | + wp_enqueue_script('gen_settings_countries'); |
|
| 304 | + wp_enqueue_style('organization-css'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /************* Espresso Pages *************/ |
|
| 309 | + /** |
|
| 310 | + * _espresso_page_settings |
|
| 311 | + * |
|
| 312 | + * @throws \EE_Error |
|
| 313 | + */ |
|
| 314 | + protected function _espresso_page_settings() |
|
| 315 | + { |
|
| 316 | + // Check to make sure all of the main pages are setup properly, |
|
| 317 | + // if not create the default pages and display an admin notice |
|
| 318 | + EEH_Activation::verify_default_pages_exist(); |
|
| 319 | + $this->_transient_garbage_collection(); |
|
| 320 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 321 | + $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 322 | + ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 323 | + : null; |
|
| 324 | + $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 325 | + ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 326 | + : false; |
|
| 327 | + $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 328 | + ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 329 | + : null; |
|
| 330 | + $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 331 | + ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 332 | + : false; |
|
| 333 | + $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 334 | + ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 335 | + : null; |
|
| 336 | + $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 337 | + ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 338 | + : false; |
|
| 339 | + $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 340 | + ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 341 | + : null; |
|
| 342 | + $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 343 | + ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 344 | + : false; |
|
| 345 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 346 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 347 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 348 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 349 | + $this->_template_args, |
|
| 350 | + true |
|
| 351 | + ); |
|
| 352 | + $this->display_admin_page_with_sidebar(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Handler for updating espresso page settings. |
|
| 358 | + */ |
|
| 359 | + protected function _update_espresso_page_settings() |
|
| 360 | + { |
|
| 361 | + // capture incoming request data && set page IDs |
|
| 362 | + EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 363 | + ? absint($this->_req_data['reg_page_id']) |
|
| 364 | + : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 365 | + EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 366 | + ? absint($this->_req_data['txn_page_id']) |
|
| 367 | + : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 368 | + EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 369 | + ? absint($this->_req_data['thank_you_page_id']) |
|
| 370 | + : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 371 | + EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 372 | + ? absint($this->_req_data['cancel_page_id']) |
|
| 373 | + : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 374 | + |
|
| 375 | + EE_Registry::instance()->CFG->core = apply_filters( |
|
| 376 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 377 | + EE_Registry::instance()->CFG->core, |
|
| 378 | + $this->_req_data |
|
| 379 | + ); |
|
| 380 | + $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 381 | + $this->_redirect_after_action( |
|
| 382 | + $this->_update_espresso_configuration( |
|
| 383 | + $what, |
|
| 384 | + EE_Registry::instance()->CFG->core, |
|
| 385 | + __FILE__, |
|
| 386 | + __FUNCTION__, |
|
| 387 | + __LINE__ |
|
| 388 | + ), |
|
| 389 | + $what, |
|
| 390 | + '', |
|
| 391 | + array( |
|
| 392 | + 'action' => 'critical_pages', |
|
| 393 | + ), |
|
| 394 | + true |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /************* Your Organization *************/ |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Output for the Your Organization settings route. |
|
| 404 | + * @throws DomainException |
|
| 405 | + * @throws EE_Error |
|
| 406 | + */ |
|
| 407 | + protected function _your_organization_settings() |
|
| 408 | + { |
|
| 409 | + |
|
| 410 | + $this->_template_args['site_license_key'] = isset( |
|
| 411 | + EE_Registry::instance()->NET_CFG->core->site_license_key |
|
| 412 | + ) |
|
| 413 | + ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key') |
|
| 414 | + : ''; |
|
| 415 | + $this->_template_args['organization_name'] = isset(EE_Registry::instance()->CFG->organization->name) |
|
| 416 | + ? EE_Registry::instance()->CFG->organization->get_pretty('name') |
|
| 417 | + : ''; |
|
| 418 | + $this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1) |
|
| 419 | + ? EE_Registry::instance()->CFG->organization->get_pretty('address_1') |
|
| 420 | + : ''; |
|
| 421 | + $this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2) |
|
| 422 | + ? EE_Registry::instance()->CFG->organization->get_pretty('address_2') |
|
| 423 | + : ''; |
|
| 424 | + $this->_template_args['organization_city'] = isset(EE_Registry::instance()->CFG->organization->city) |
|
| 425 | + ? EE_Registry::instance()->CFG->organization->get_pretty('city') |
|
| 426 | + : ''; |
|
| 427 | + $this->_template_args['organization_zip'] = isset(EE_Registry::instance()->CFG->organization->zip) |
|
| 428 | + ? EE_Registry::instance()->CFG->organization->get_pretty('zip') |
|
| 429 | + : ''; |
|
| 430 | + $this->_template_args['organization_email'] = isset(EE_Registry::instance()->CFG->organization->email) |
|
| 431 | + ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 432 | + : ''; |
|
| 433 | + $this->_template_args['organization_phone'] = isset(EE_Registry::instance()->CFG->organization->phone) |
|
| 434 | + ? EE_Registry::instance()->CFG->organization->get_pretty('phone') |
|
| 435 | + : ''; |
|
| 436 | + $this->_template_args['organization_vat'] = isset(EE_Registry::instance()->CFG->organization->vat) |
|
| 437 | + ? EE_Registry::instance()->CFG->organization->get_pretty('vat') |
|
| 438 | + : ''; |
|
| 439 | + $this->_template_args['currency_sign'] = isset(EE_Registry::instance()->CFG->currency->sign) |
|
| 440 | + ? EE_Registry::instance()->CFG->currency->get_pretty('sign') |
|
| 441 | + : '$'; |
|
| 442 | + $this->_template_args['organization_logo_url'] = isset(EE_Registry::instance()->CFG->organization->logo_url) |
|
| 443 | + ? EE_Registry::instance()->CFG->organization->get_pretty('logo_url') |
|
| 444 | + : false; |
|
| 445 | + $this->_template_args['organization_facebook'] = isset(EE_Registry::instance()->CFG->organization->facebook) |
|
| 446 | + ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
| 447 | + : ''; |
|
| 448 | + $this->_template_args['organization_twitter'] = isset(EE_Registry::instance()->CFG->organization->twitter) |
|
| 449 | + ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
| 450 | + : ''; |
|
| 451 | + $this->_template_args['organization_linkedin'] = isset(EE_Registry::instance()->CFG->organization->linkedin) |
|
| 452 | + ? EE_Registry::instance()->CFG->organization->get_pretty('linkedin') |
|
| 453 | + : ''; |
|
| 454 | + $this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest) |
|
| 455 | + ? EE_Registry::instance()->CFG->organization->get_pretty('pinterest') |
|
| 456 | + : ''; |
|
| 457 | + $this->_template_args['organization_google'] = isset(EE_Registry::instance()->CFG->organization->google) |
|
| 458 | + ? EE_Registry::instance()->CFG->organization->get_pretty('google') |
|
| 459 | + : ''; |
|
| 460 | + $this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram) |
|
| 461 | + ? EE_Registry::instance()->CFG->organization->get_pretty('instagram') |
|
| 462 | + : ''; |
|
| 463 | + //UXIP settings |
|
| 464 | + $this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin) |
|
| 465 | + ? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin') |
|
| 466 | + : 'yes'; |
|
| 467 | + |
|
| 468 | + $STA_ID = isset(EE_Registry::instance()->CFG->organization->STA_ID) |
|
| 469 | + ? EE_Registry::instance()->CFG->organization->STA_ID |
|
| 470 | + : 4; |
|
| 471 | + $this->_template_args['states'] = new EE_Question_Form_Input( |
|
| 472 | + EE_Question::new_instance(array( |
|
| 473 | + 'QST_ID' => 0, |
|
| 474 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 475 | + 'QST_system' => 'admin-state', |
|
| 476 | + )), |
|
| 477 | + EE_Answer::new_instance(array( |
|
| 478 | + 'ANS_ID' => 0, |
|
| 479 | + 'ANS_value' => $STA_ID, |
|
| 480 | + )), |
|
| 481 | + array( |
|
| 482 | + 'input_id' => 'organization_state', |
|
| 483 | + 'input_name' => 'organization_state', |
|
| 484 | + 'input_prefix' => '', |
|
| 485 | + 'append_qstn_id' => false, |
|
| 486 | + ) |
|
| 487 | + ); |
|
| 488 | + |
|
| 489 | + $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 490 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 491 | + : 'US'; |
|
| 492 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 493 | + EE_Question::new_instance(array( |
|
| 494 | + 'QST_ID' => 0, |
|
| 495 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 496 | + 'QST_system' => 'admin-country', |
|
| 497 | + )), |
|
| 498 | + EE_Answer::new_instance(array( |
|
| 499 | + 'ANS_ID' => 0, |
|
| 500 | + 'ANS_value' => $CNT_ISO, |
|
| 501 | + )), |
|
| 502 | + array( |
|
| 503 | + 'input_id' => 'organization_country', |
|
| 504 | + 'input_name' => 'organization_country', |
|
| 505 | + 'input_prefix' => '', |
|
| 506 | + 'append_qstn_id' => false, |
|
| 507 | + ) |
|
| 508 | + ); |
|
| 509 | + |
|
| 510 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 511 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 512 | + |
|
| 513 | + //PUE verification stuff |
|
| 514 | + $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
| 515 | + $verify_fail = get_option($ver_option_key); |
|
| 516 | + $this->_template_args['site_license_key_verified'] = $verify_fail |
|
| 517 | + || ! empty($verify_fail) |
|
| 518 | + || (empty($this->_template_args['site_license_key']) |
|
| 519 | + && empty($verify_fail) |
|
| 520 | + ) |
|
| 521 | + ? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>' |
|
| 522 | + : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>'; |
|
| 523 | + |
|
| 524 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 525 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 527 | + GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', |
|
| 528 | + $this->_template_args, |
|
| 529 | + true |
|
| 530 | + ); |
|
| 531 | + |
|
| 532 | + $this->display_admin_page_with_sidebar(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Handler for updating organziation settings. |
|
| 538 | + */ |
|
| 539 | + protected function _update_your_organization_settings() |
|
| 540 | + { |
|
| 541 | + if (is_main_site()) { |
|
| 542 | + EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key']) |
|
| 543 | + ? sanitize_text_field($this->_req_data['site_license_key']) |
|
| 544 | + : EE_Registry::instance()->NET_CFG->core->site_license_key; |
|
| 545 | + } |
|
| 546 | + EE_Registry::instance()->CFG->organization->name = isset($this->_req_data['organization_name']) |
|
| 547 | + ? sanitize_text_field($this->_req_data['organization_name']) |
|
| 548 | + : EE_Registry::instance()->CFG->organization->name; |
|
| 549 | + EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1']) |
|
| 550 | + ? sanitize_text_field($this->_req_data['organization_address_1']) |
|
| 551 | + : EE_Registry::instance()->CFG->organization->address_1; |
|
| 552 | + EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2']) |
|
| 553 | + ? sanitize_text_field($this->_req_data['organization_address_2']) |
|
| 554 | + : EE_Registry::instance()->CFG->organization->address_2; |
|
| 555 | + EE_Registry::instance()->CFG->organization->city = isset($this->_req_data['organization_city']) |
|
| 556 | + ? sanitize_text_field($this->_req_data['organization_city']) |
|
| 557 | + : EE_Registry::instance()->CFG->organization->city; |
|
| 558 | + EE_Registry::instance()->CFG->organization->STA_ID = isset($this->_req_data['organization_state']) |
|
| 559 | + ? absint($this->_req_data['organization_state']) |
|
| 560 | + : EE_Registry::instance()->CFG->organization->STA_ID; |
|
| 561 | + EE_Registry::instance()->CFG->organization->CNT_ISO = isset($this->_req_data['organization_country']) |
|
| 562 | + ? sanitize_text_field($this->_req_data['organization_country']) |
|
| 563 | + : EE_Registry::instance()->CFG->organization->CNT_ISO; |
|
| 564 | + EE_Registry::instance()->CFG->organization->zip = isset($this->_req_data['organization_zip']) |
|
| 565 | + ? sanitize_text_field($this->_req_data['organization_zip']) |
|
| 566 | + : EE_Registry::instance()->CFG->organization->zip; |
|
| 567 | + EE_Registry::instance()->CFG->organization->email = isset($this->_req_data['organization_email']) |
|
| 568 | + ? sanitize_email($this->_req_data['organization_email']) |
|
| 569 | + : EE_Registry::instance()->CFG->organization->email; |
|
| 570 | + EE_Registry::instance()->CFG->organization->vat = isset($this->_req_data['organization_vat']) |
|
| 571 | + ? sanitize_text_field($this->_req_data['organization_vat']) |
|
| 572 | + : EE_Registry::instance()->CFG->organization->vat; |
|
| 573 | + EE_Registry::instance()->CFG->organization->phone = isset($this->_req_data['organization_phone']) |
|
| 574 | + ? sanitize_text_field($this->_req_data['organization_phone']) |
|
| 575 | + : EE_Registry::instance()->CFG->organization->phone; |
|
| 576 | + EE_Registry::instance()->CFG->organization->logo_url = isset($this->_req_data['organization_logo_url']) |
|
| 577 | + ? esc_url_raw($this->_req_data['organization_logo_url']) |
|
| 578 | + : EE_Registry::instance()->CFG->organization->logo_url; |
|
| 579 | + EE_Registry::instance()->CFG->organization->facebook = isset($this->_req_data['organization_facebook']) |
|
| 580 | + ? esc_url_raw($this->_req_data['organization_facebook']) |
|
| 581 | + : EE_Registry::instance()->CFG->organization->facebook; |
|
| 582 | + EE_Registry::instance()->CFG->organization->twitter = isset($this->_req_data['organization_twitter']) |
|
| 583 | + ? esc_url_raw($this->_req_data['organization_twitter']) |
|
| 584 | + : EE_Registry::instance()->CFG->organization->twitter; |
|
| 585 | + EE_Registry::instance()->CFG->organization->linkedin = isset($this->_req_data['organization_linkedin']) |
|
| 586 | + ? esc_url_raw($this->_req_data['organization_linkedin']) |
|
| 587 | + : EE_Registry::instance()->CFG->organization->linkedin; |
|
| 588 | + EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest']) |
|
| 589 | + ? esc_url_raw($this->_req_data['organization_pinterest']) |
|
| 590 | + : EE_Registry::instance()->CFG->organization->pinterest; |
|
| 591 | + EE_Registry::instance()->CFG->organization->google = isset($this->_req_data['organization_google']) |
|
| 592 | + ? esc_url_raw($this->_req_data['organization_google']) |
|
| 593 | + : EE_Registry::instance()->CFG->organization->google; |
|
| 594 | + EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram']) |
|
| 595 | + ? esc_url_raw($this->_req_data['organization_instagram']) |
|
| 596 | + : EE_Registry::instance()->CFG->organization->instagram; |
|
| 597 | + EE_Registry::instance()->CFG->core->ee_ueip_optin = isset($this->_req_data['ueip_optin']) |
|
| 598 | + && ! empty($this->_req_data['ueip_optin']) |
|
| 599 | + ? filter_var($this->_req_data['ueip_optin'], FILTER_VALIDATE_BOOLEAN) |
|
| 600 | + : EE_Registry::instance()->CFG->core->ee_ueip_optin; |
|
| 601 | + |
|
| 602 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config( |
|
| 603 | + EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + EE_Registry::instance()->CFG = apply_filters( |
|
| 607 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 608 | + EE_Registry::instance()->CFG |
|
| 609 | + ); |
|
| 610 | + |
|
| 611 | + $what = 'Your Organization Settings'; |
|
| 612 | + $success = $this->_update_espresso_configuration( |
|
| 613 | + $what, |
|
| 614 | + EE_Registry::instance()->CFG, |
|
| 615 | + __FILE__, |
|
| 616 | + __FUNCTION__, |
|
| 617 | + __LINE__ |
|
| 618 | + ); |
|
| 619 | + |
|
| 620 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default')); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + /************* Admin Options *************/ |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * _admin_option_settings |
|
| 630 | + * |
|
| 631 | + * @throws \EE_Error |
|
| 632 | + * @throws \LogicException |
|
| 633 | + */ |
|
| 634 | + protected function _admin_option_settings() |
|
| 635 | + { |
|
| 636 | + $this->_template_args['admin_page_content'] = ''; |
|
| 637 | + try { |
|
| 638 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 639 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 640 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 641 | + // also need to account for the do_action that was in the old template |
|
| 642 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 643 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 644 | + } catch (Exception $e) { |
|
| 645 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | + } |
|
| 647 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 648 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 649 | + $this->display_admin_page_with_sidebar(); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * _update_admin_option_settings |
|
| 655 | + * |
|
| 656 | + * @throws \EE_Error |
|
| 657 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 658 | + * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 659 | + * @throws \InvalidArgumentException |
|
| 660 | + * @throws \LogicException |
|
| 661 | + */ |
|
| 662 | + protected function _update_admin_option_settings() |
|
| 663 | + { |
|
| 664 | + try { |
|
| 665 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 666 | + $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
| 667 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 668 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 669 | + EE_Registry::instance()->CFG->admin |
|
| 670 | + ); |
|
| 671 | + } catch (Exception $e) { |
|
| 672 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 673 | + } |
|
| 674 | + $this->_redirect_after_action( |
|
| 675 | + apply_filters( |
|
| 676 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 677 | + $this->_update_espresso_configuration( |
|
| 678 | + 'Admin Options', |
|
| 679 | + EE_Registry::instance()->CFG->admin, |
|
| 680 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 681 | + ) |
|
| 682 | + ), |
|
| 683 | + 'Admin Options', |
|
| 684 | + 'updated', |
|
| 685 | + array('action' => 'admin_option_settings') |
|
| 686 | + ); |
|
| 687 | + |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /************* Countries *************/ |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Output Country Settings view. |
|
| 696 | + * @throws DomainException |
|
| 697 | + * @throws EE_Error |
|
| 698 | + */ |
|
| 699 | + protected function _country_settings() |
|
| 700 | + { |
|
| 701 | + $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 702 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 703 | + : 'US'; |
|
| 704 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 705 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 706 | + : $CNT_ISO; |
|
| 707 | + |
|
| 708 | + //load field generator helper |
|
| 709 | + |
|
| 710 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 711 | + |
|
| 712 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 713 | + EE_Question::new_instance(array( |
|
| 714 | + 'QST_ID' => 0, |
|
| 715 | + 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
| 716 | + 'QST_system' => 'admin-country', |
|
| 717 | + )), |
|
| 718 | + EE_Answer::new_instance(array( |
|
| 719 | + 'ANS_ID' => 0, |
|
| 720 | + 'ANS_value' => $CNT_ISO, |
|
| 721 | + )), |
|
| 722 | + array( |
|
| 723 | + 'input_id' => 'country', |
|
| 724 | + 'input_name' => 'country', |
|
| 725 | + 'input_prefix' => '', |
|
| 726 | + 'append_qstn_id' => false, |
|
| 727 | + ) |
|
| 728 | + ); |
|
| 729 | + |
|
| 730 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 731 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 732 | + $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
| 733 | + $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
| 734 | + |
|
| 735 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 736 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 737 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 738 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 739 | + $this->_template_args, |
|
| 740 | + true |
|
| 741 | + ); |
|
| 742 | + $this->display_admin_page_with_no_sidebar(); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * display_country_settings |
|
| 748 | + * |
|
| 749 | + * @access public |
|
| 750 | + * @param string $CNT_ISO |
|
| 751 | + * @return mixed string | array |
|
| 752 | + * @throws DomainException |
|
| 753 | + */ |
|
| 754 | + public function display_country_settings($CNT_ISO = '') |
|
| 755 | + { |
|
| 756 | + |
|
| 757 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 758 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 759 | + : $CNT_ISO; |
|
| 760 | + if (! $CNT_ISO) { |
|
| 761 | + return ''; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + // for ajax |
|
| 765 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 766 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 767 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 768 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 769 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 770 | + |
|
| 771 | + $country_input_types = array( |
|
| 772 | + 'CNT_active' => array( |
|
| 773 | + 'type' => 'RADIO_BTN', |
|
| 774 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | + 'class' => '', |
|
| 776 | + 'options' => $this->_yes_no_values, |
|
| 777 | + 'use_desc_4_label' => true, |
|
| 778 | + ), |
|
| 779 | + 'CNT_ISO' => array( |
|
| 780 | + 'type' => 'TEXT', |
|
| 781 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 782 | + 'class' => 'small-text', |
|
| 783 | + ), |
|
| 784 | + 'CNT_ISO3' => array( |
|
| 785 | + 'type' => 'TEXT', |
|
| 786 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | + 'class' => 'small-text', |
|
| 788 | + ), |
|
| 789 | + 'RGN_ID' => array( |
|
| 790 | + 'type' => 'TEXT', |
|
| 791 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 792 | + 'class' => 'small-text', |
|
| 793 | + ), |
|
| 794 | + 'CNT_name' => array( |
|
| 795 | + 'type' => 'TEXT', |
|
| 796 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 797 | + 'class' => 'regular-text', |
|
| 798 | + ), |
|
| 799 | + 'CNT_cur_code' => array( |
|
| 800 | + 'type' => 'TEXT', |
|
| 801 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 802 | + 'class' => 'small-text', |
|
| 803 | + ), |
|
| 804 | + 'CNT_cur_single' => array( |
|
| 805 | + 'type' => 'TEXT', |
|
| 806 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 807 | + 'class' => 'medium-text', |
|
| 808 | + ), |
|
| 809 | + 'CNT_cur_plural' => array( |
|
| 810 | + 'type' => 'TEXT', |
|
| 811 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 812 | + 'class' => 'medium-text', |
|
| 813 | + ), |
|
| 814 | + 'CNT_cur_sign' => array( |
|
| 815 | + 'type' => 'TEXT', |
|
| 816 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 817 | + 'class' => 'small-text', |
|
| 818 | + 'htmlentities' => false, |
|
| 819 | + ), |
|
| 820 | + 'CNT_cur_sign_b4' => array( |
|
| 821 | + 'type' => 'RADIO_BTN', |
|
| 822 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 823 | + 'class' => '', |
|
| 824 | + 'options' => $this->_yes_no_values, |
|
| 825 | + 'use_desc_4_label' => true, |
|
| 826 | + ), |
|
| 827 | + 'CNT_cur_dec_plc' => array( |
|
| 828 | + 'type' => 'RADIO_BTN', |
|
| 829 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 830 | + 'class' => '', |
|
| 831 | + 'options' => array( |
|
| 832 | + array('id' => 0, 'text' => ''), |
|
| 833 | + array('id' => 1, 'text' => ''), |
|
| 834 | + array('id' => 2, 'text' => ''), |
|
| 835 | + array('id' => 3, 'text' => ''), |
|
| 836 | + ), |
|
| 837 | + ), |
|
| 838 | + 'CNT_cur_dec_mrk' => array( |
|
| 839 | + 'type' => 'RADIO_BTN', |
|
| 840 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 841 | + 'class' => '', |
|
| 842 | + 'options' => array( |
|
| 843 | + array( |
|
| 844 | + 'id' => ',', |
|
| 845 | + 'text' => __(', (comma)', 'event_espresso'), |
|
| 846 | + ), |
|
| 847 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 848 | + ), |
|
| 849 | + 'use_desc_4_label' => true, |
|
| 850 | + ), |
|
| 851 | + 'CNT_cur_thsnds' => array( |
|
| 852 | + 'type' => 'RADIO_BTN', |
|
| 853 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 854 | + 'class' => '', |
|
| 855 | + 'options' => array( |
|
| 856 | + array( |
|
| 857 | + 'id' => ',', |
|
| 858 | + 'text' => __(', (comma)', 'event_espresso'), |
|
| 859 | + ), |
|
| 860 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 861 | + ), |
|
| 862 | + 'use_desc_4_label' => true, |
|
| 863 | + ), |
|
| 864 | + 'CNT_tel_code' => array( |
|
| 865 | + 'type' => 'TEXT', |
|
| 866 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 867 | + 'class' => 'small-text', |
|
| 868 | + ), |
|
| 869 | + 'CNT_is_EU' => array( |
|
| 870 | + 'type' => 'RADIO_BTN', |
|
| 871 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 872 | + 'class' => '', |
|
| 873 | + 'options' => $this->_yes_no_values, |
|
| 874 | + 'use_desc_4_label' => true, |
|
| 875 | + ), |
|
| 876 | + ); |
|
| 877 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 878 | + $country, |
|
| 879 | + $country_input_types |
|
| 880 | + ); |
|
| 881 | + $country_details_settings = EEH_Template::display_template( |
|
| 882 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 883 | + $this->_template_args, |
|
| 884 | + true |
|
| 885 | + ); |
|
| 886 | + |
|
| 887 | + if (defined('DOING_AJAX')) { |
|
| 888 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 889 | + echo wp_json_encode(array( |
|
| 890 | + 'return_data' => $country_details_settings, |
|
| 891 | + 'success' => $notices['success'], |
|
| 892 | + 'errors' => $notices['errors'], |
|
| 893 | + )); |
|
| 894 | + die(); |
|
| 895 | + } else { |
|
| 896 | + return $country_details_settings; |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * display_country_states |
|
| 903 | + * |
|
| 904 | + * @access public |
|
| 905 | + * @param string $CNT_ISO |
|
| 906 | + * @return string |
|
| 907 | + * @throws DomainException |
|
| 908 | + */ |
|
| 909 | + public function display_country_states($CNT_ISO = '') |
|
| 910 | + { |
|
| 911 | + |
|
| 912 | + $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
| 913 | + |
|
| 914 | + if (! $CNT_ISO) { |
|
| 915 | + return ''; |
|
| 916 | + } |
|
| 917 | + // for ajax |
|
| 918 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 919 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 920 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 921 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 922 | + $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 923 | + |
|
| 924 | + if ($states) { |
|
| 925 | + foreach ($states as $STA_ID => $state) { |
|
| 926 | + if ($state instanceof EE_State) { |
|
| 927 | + //STA_abbrev STA_name STA_active |
|
| 928 | + $state_input_types = array( |
|
| 929 | + 'STA_abbrev' => array( |
|
| 930 | + 'type' => 'TEXT', |
|
| 931 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 932 | + 'class' => 'mid-text', |
|
| 933 | + ), |
|
| 934 | + 'STA_name' => array( |
|
| 935 | + 'type' => 'TEXT', |
|
| 936 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 937 | + 'class' => 'regular-text', |
|
| 938 | + ), |
|
| 939 | + 'STA_active' => array( |
|
| 940 | + 'type' => 'RADIO_BTN', |
|
| 941 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 942 | + 'options' => $this->_yes_no_values, |
|
| 943 | + 'use_desc_4_label' => true, |
|
| 944 | + ), |
|
| 945 | + ); |
|
| 946 | + $this->_template_args['states'][$STA_ID]['inputs'] = |
|
| 947 | + EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 948 | + $state, |
|
| 949 | + $state_input_types |
|
| 950 | + ); |
|
| 951 | + $query_args = array( |
|
| 952 | + 'action' => 'delete_state', |
|
| 953 | + 'STA_ID' => $STA_ID, |
|
| 954 | + 'CNT_ISO' => $CNT_ISO, |
|
| 955 | + 'STA_abbrev' => $state->abbrev(), |
|
| 956 | + ); |
|
| 957 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
| 958 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 959 | + $query_args, |
|
| 960 | + GEN_SET_ADMIN_URL |
|
| 961 | + ); |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + } else { |
|
| 965 | + $this->_template_args['states'] = false; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 969 | + array('action' => 'add_new_state'), |
|
| 970 | + GEN_SET_ADMIN_URL |
|
| 971 | + ); |
|
| 972 | + |
|
| 973 | + $state_details_settings = EEH_Template::display_template( |
|
| 974 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 975 | + $this->_template_args, |
|
| 976 | + true |
|
| 977 | + ); |
|
| 978 | + |
|
| 979 | + if (defined('DOING_AJAX')) { |
|
| 980 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 981 | + echo wp_json_encode(array( |
|
| 982 | + 'return_data' => $state_details_settings, |
|
| 983 | + 'success' => $notices['success'], |
|
| 984 | + 'errors' => $notices['errors'], |
|
| 985 | + )); |
|
| 986 | + die(); |
|
| 987 | + } else { |
|
| 988 | + return $state_details_settings; |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * add_new_state |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @return void |
|
| 998 | + * @throws EE_Error |
|
| 999 | + */ |
|
| 1000 | + public function add_new_state() |
|
| 1001 | + { |
|
| 1002 | + |
|
| 1003 | + $success = true; |
|
| 1004 | + |
|
| 1005 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1006 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1007 | + : false; |
|
| 1008 | + if (! $CNT_ISO) { |
|
| 1009 | + EE_Error::add_error( |
|
| 1010 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1011 | + __FILE__, |
|
| 1012 | + __FUNCTION__, |
|
| 1013 | + __LINE__ |
|
| 1014 | + ); |
|
| 1015 | + $success = false; |
|
| 1016 | + } |
|
| 1017 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1018 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1019 | + : false; |
|
| 1020 | + if (! $STA_abbrev) { |
|
| 1021 | + EE_Error::add_error( |
|
| 1022 | + __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 1023 | + __FILE__, |
|
| 1024 | + __FUNCTION__, |
|
| 1025 | + __LINE__ |
|
| 1026 | + ); |
|
| 1027 | + $success = false; |
|
| 1028 | + } |
|
| 1029 | + $STA_name = isset($this->_req_data['STA_name']) |
|
| 1030 | + ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 1031 | + : false; |
|
| 1032 | + if (! $STA_name) { |
|
| 1033 | + EE_Error::add_error( |
|
| 1034 | + __('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1035 | + __FILE__, |
|
| 1036 | + __FUNCTION__, |
|
| 1037 | + __LINE__ |
|
| 1038 | + ); |
|
| 1039 | + $success = false; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + if ($success) { |
|
| 1043 | + $cols_n_values = array( |
|
| 1044 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1045 | + 'STA_abbrev' => $STA_abbrev, |
|
| 1046 | + 'STA_name' => $STA_name, |
|
| 1047 | + 'STA_active' => true, |
|
| 1048 | + ); |
|
| 1049 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1050 | + EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if (defined('DOING_AJAX')) { |
|
| 1054 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1055 | + echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1056 | + die(); |
|
| 1057 | + } else { |
|
| 1058 | + $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * delete_state |
|
| 1065 | + * |
|
| 1066 | + * @access public |
|
| 1067 | + * @return boolean |
|
| 1068 | + */ |
|
| 1069 | + public function delete_state() |
|
| 1070 | + { |
|
| 1071 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1072 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1073 | + : false; |
|
| 1074 | + $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1075 | + ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1076 | + : false; |
|
| 1077 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1078 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1079 | + : false; |
|
| 1080 | + if (! $STA_ID) { |
|
| 1081 | + EE_Error::add_error( |
|
| 1082 | + __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1083 | + __FILE__, |
|
| 1084 | + __FUNCTION__, |
|
| 1085 | + __LINE__ |
|
| 1086 | + ); |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1091 | + if ($success !== false) { |
|
| 1092 | + do_action( |
|
| 1093 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1094 | + $CNT_ISO, |
|
| 1095 | + $STA_ID, |
|
| 1096 | + array('STA_abbrev' => $STA_abbrev) |
|
| 1097 | + ); |
|
| 1098 | + EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
| 1099 | + } |
|
| 1100 | + if (defined('DOING_AJAX')) { |
|
| 1101 | + $notices = EE_Error::get_notices(false, false); |
|
| 1102 | + $notices['return_data'] = true; |
|
| 1103 | + echo wp_json_encode($notices); |
|
| 1104 | + die(); |
|
| 1105 | + } else { |
|
| 1106 | + $this->_redirect_after_action( |
|
| 1107 | + $success, |
|
| 1108 | + 'State', |
|
| 1109 | + 'deleted', |
|
| 1110 | + array('action' => 'country_settings') |
|
| 1111 | + ); |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * _update_country_settings |
|
| 1118 | + * |
|
| 1119 | + * @access protected |
|
| 1120 | + * @return void |
|
| 1121 | + * @throws EE_Error |
|
| 1122 | + */ |
|
| 1123 | + protected function _update_country_settings() |
|
| 1124 | + { |
|
| 1125 | + // grab the country ISO code |
|
| 1126 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 1127 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1128 | + : false; |
|
| 1129 | + if (! $CNT_ISO) { |
|
| 1130 | + EE_Error::add_error( |
|
| 1131 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1132 | + __FILE__, |
|
| 1133 | + __FUNCTION__, |
|
| 1134 | + __LINE__ |
|
| 1135 | + ); |
|
| 1136 | + |
|
| 1137 | + return; |
|
| 1138 | + } |
|
| 1139 | + $cols_n_values = array(); |
|
| 1140 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
| 1141 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
| 1142 | + : false; |
|
| 1143 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1144 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1145 | + : null; |
|
| 1146 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1147 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1148 | + : null; |
|
| 1149 | + $cols_n_values['CNT_cur_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
| 1150 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) |
|
| 1151 | + : 'USD'; |
|
| 1152 | + $cols_n_values['CNT_cur_single'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1153 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1154 | + : 'dollar'; |
|
| 1155 | + $cols_n_values['CNT_cur_plural'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1156 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1157 | + : 'dollars'; |
|
| 1158 | + $cols_n_values['CNT_cur_sign'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1159 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1160 | + : '$'; |
|
| 1161 | + $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1162 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1163 | + : true; |
|
| 1164 | + $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1165 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1166 | + : 2; |
|
| 1167 | + $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1168 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1169 | + : '.'; |
|
| 1170 | + $cols_n_values['CNT_cur_thsnds'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1171 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1172 | + : ','; |
|
| 1173 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1174 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1175 | + : null; |
|
| 1176 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1177 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1178 | + : false; |
|
| 1179 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1180 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1181 | + : false; |
|
| 1182 | + // allow filtering of country data |
|
| 1183 | + $cols_n_values = apply_filters( |
|
| 1184 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1185 | + $cols_n_values |
|
| 1186 | + ); |
|
| 1187 | + |
|
| 1188 | + // where values |
|
| 1189 | + $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1190 | + // run the update |
|
| 1191 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1192 | + |
|
| 1193 | + if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1194 | + // allow filtering of states data |
|
| 1195 | + $states = apply_filters( |
|
| 1196 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1197 | + $this->_req_data['states'] |
|
| 1198 | + ); |
|
| 1199 | + |
|
| 1200 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1201 | + foreach ($states as $STA_ID => $state) { |
|
| 1202 | + $cols_n_values = array( |
|
| 1203 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1204 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1205 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1206 | + 'STA_active' => (bool)absint($state['STA_active']), |
|
| 1207 | + ); |
|
| 1208 | + // where values |
|
| 1209 | + $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1210 | + // run the update |
|
| 1211 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1212 | + if ($success !== false) { |
|
| 1213 | + do_action( |
|
| 1214 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1215 | + $CNT_ISO, |
|
| 1216 | + $STA_ID, |
|
| 1217 | + $cols_n_values |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1223 | + if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1224 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1225 | + ) { |
|
| 1226 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1227 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + if ($success !== false) { |
|
| 1231 | + EE_Error::add_success( |
|
| 1232 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1233 | + ); |
|
| 1234 | + } |
|
| 1235 | + $this->_redirect_after_action( |
|
| 1236 | + $success, |
|
| 1237 | + '', |
|
| 1238 | + '', |
|
| 1239 | + array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1240 | + true |
|
| 1241 | + ); |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * form_form_field_label_wrap |
|
| 1247 | + * |
|
| 1248 | + * @access public |
|
| 1249 | + * @param string $label |
|
| 1250 | + * @return string |
|
| 1251 | + */ |
|
| 1252 | + public function country_form_field_label_wrap($label, $required_text) |
|
| 1253 | + { |
|
| 1254 | + return ' |
|
| 1255 | 1255 | <tr> |
| 1256 | 1256 | <th> |
| 1257 | 1257 | ' . $label . ' |
| 1258 | 1258 | </th>'; |
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * form_form_field_input__wrap |
|
| 1264 | - * |
|
| 1265 | - * @access public |
|
| 1266 | - * @param string $label |
|
| 1267 | - * @return string |
|
| 1268 | - */ |
|
| 1269 | - public function country_form_field_input__wrap($input, $label) |
|
| 1270 | - { |
|
| 1271 | - return ' |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * form_form_field_input__wrap |
|
| 1264 | + * |
|
| 1265 | + * @access public |
|
| 1266 | + * @param string $label |
|
| 1267 | + * @return string |
|
| 1268 | + */ |
|
| 1269 | + public function country_form_field_input__wrap($input, $label) |
|
| 1270 | + { |
|
| 1271 | + return ' |
|
| 1272 | 1272 | <td class="general-settings-country-input-td"> |
| 1273 | 1273 | ' . $input . ' |
| 1274 | 1274 | </td> |
| 1275 | 1275 | </tr>'; |
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * form_form_field_label_wrap |
|
| 1281 | - * |
|
| 1282 | - * @access public |
|
| 1283 | - * @param string $label |
|
| 1284 | - * @param string $required_text |
|
| 1285 | - * @return string |
|
| 1286 | - */ |
|
| 1287 | - public function state_form_field_label_wrap($label, $required_text) |
|
| 1288 | - { |
|
| 1289 | - return $required_text; |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * form_form_field_input__wrap |
|
| 1295 | - * |
|
| 1296 | - * @access public |
|
| 1297 | - * @param string $label |
|
| 1298 | - * @return string |
|
| 1299 | - */ |
|
| 1300 | - public function state_form_field_input__wrap($input, $label) |
|
| 1301 | - { |
|
| 1302 | - return ' |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * form_form_field_label_wrap |
|
| 1281 | + * |
|
| 1282 | + * @access public |
|
| 1283 | + * @param string $label |
|
| 1284 | + * @param string $required_text |
|
| 1285 | + * @return string |
|
| 1286 | + */ |
|
| 1287 | + public function state_form_field_label_wrap($label, $required_text) |
|
| 1288 | + { |
|
| 1289 | + return $required_text; |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * form_form_field_input__wrap |
|
| 1295 | + * |
|
| 1296 | + * @access public |
|
| 1297 | + * @param string $label |
|
| 1298 | + * @return string |
|
| 1299 | + */ |
|
| 1300 | + public function state_form_field_input__wrap($input, $label) |
|
| 1301 | + { |
|
| 1302 | + return ' |
|
| 1303 | 1303 | <td class="general-settings-country-state-input-td"> |
| 1304 | 1304 | ' . $input . ' |
| 1305 | 1305 | </td>'; |
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /***********/ |
|
| 1310 | - |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * displays edit and view links for critical EE pages |
|
| 1314 | - * |
|
| 1315 | - * @access public |
|
| 1316 | - * @param int $ee_page_id |
|
| 1317 | - * @return string |
|
| 1318 | - */ |
|
| 1319 | - public static function edit_view_links($ee_page_id) |
|
| 1320 | - { |
|
| 1321 | - $links = '<a href="' |
|
| 1322 | - . add_query_arg( |
|
| 1323 | - array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1324 | - admin_url('post.php') |
|
| 1325 | - ) |
|
| 1326 | - . '" >' |
|
| 1327 | - . __('Edit', 'event_espresso') |
|
| 1328 | - . '</a>'; |
|
| 1329 | - $links .= ' | '; |
|
| 1330 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
| 1331 | - |
|
| 1332 | - return $links; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * displays page and shortcode status for critical EE pages |
|
| 1338 | - * |
|
| 1339 | - * @param WP page object $ee_page |
|
| 1340 | - * @return string |
|
| 1341 | - */ |
|
| 1342 | - public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1343 | - { |
|
| 1344 | - |
|
| 1345 | - // page status |
|
| 1346 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1347 | - $pg_colour = 'green'; |
|
| 1348 | - $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1349 | - } else { |
|
| 1350 | - $pg_colour = 'red'; |
|
| 1351 | - $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - // shortcode status |
|
| 1355 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1356 | - $sc_colour = 'green'; |
|
| 1357 | - $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1358 | - } else { |
|
| 1359 | - $sc_colour = 'red'; |
|
| 1360 | - $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1364 | - . $pg_status |
|
| 1365 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * generates a dropdown of all parent pages - copied from WP core |
|
| 1371 | - * |
|
| 1372 | - * @param int $default |
|
| 1373 | - * @param int $parent |
|
| 1374 | - * @param int $level |
|
| 1375 | - */ |
|
| 1376 | - public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1377 | - { |
|
| 1378 | - global $wpdb; |
|
| 1379 | - $items = $wpdb->get_results( |
|
| 1380 | - $wpdb->prepare( |
|
| 1381 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1382 | - $parent |
|
| 1383 | - ) |
|
| 1384 | - ); |
|
| 1385 | - |
|
| 1386 | - if ($items) { |
|
| 1387 | - foreach ($items as $item) { |
|
| 1388 | - $pad = str_repeat(' ', $level * 3); |
|
| 1389 | - if ($item->ID == $default) { |
|
| 1390 | - $current = ' selected="selected"'; |
|
| 1391 | - } else { |
|
| 1392 | - $current = ''; |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1396 | - . esc_html($item->post_title) |
|
| 1397 | - . "</option>"; |
|
| 1398 | - parent_dropdown($default, $item->ID, $level + 1); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /***********/ |
|
| 1310 | + |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * displays edit and view links for critical EE pages |
|
| 1314 | + * |
|
| 1315 | + * @access public |
|
| 1316 | + * @param int $ee_page_id |
|
| 1317 | + * @return string |
|
| 1318 | + */ |
|
| 1319 | + public static function edit_view_links($ee_page_id) |
|
| 1320 | + { |
|
| 1321 | + $links = '<a href="' |
|
| 1322 | + . add_query_arg( |
|
| 1323 | + array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1324 | + admin_url('post.php') |
|
| 1325 | + ) |
|
| 1326 | + . '" >' |
|
| 1327 | + . __('Edit', 'event_espresso') |
|
| 1328 | + . '</a>'; |
|
| 1329 | + $links .= ' | '; |
|
| 1330 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
| 1331 | + |
|
| 1332 | + return $links; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * displays page and shortcode status for critical EE pages |
|
| 1338 | + * |
|
| 1339 | + * @param WP page object $ee_page |
|
| 1340 | + * @return string |
|
| 1341 | + */ |
|
| 1342 | + public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1343 | + { |
|
| 1344 | + |
|
| 1345 | + // page status |
|
| 1346 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1347 | + $pg_colour = 'green'; |
|
| 1348 | + $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1349 | + } else { |
|
| 1350 | + $pg_colour = 'red'; |
|
| 1351 | + $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + // shortcode status |
|
| 1355 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1356 | + $sc_colour = 'green'; |
|
| 1357 | + $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1358 | + } else { |
|
| 1359 | + $sc_colour = 'red'; |
|
| 1360 | + $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1364 | + . $pg_status |
|
| 1365 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * generates a dropdown of all parent pages - copied from WP core |
|
| 1371 | + * |
|
| 1372 | + * @param int $default |
|
| 1373 | + * @param int $parent |
|
| 1374 | + * @param int $level |
|
| 1375 | + */ |
|
| 1376 | + public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1377 | + { |
|
| 1378 | + global $wpdb; |
|
| 1379 | + $items = $wpdb->get_results( |
|
| 1380 | + $wpdb->prepare( |
|
| 1381 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1382 | + $parent |
|
| 1383 | + ) |
|
| 1384 | + ); |
|
| 1385 | + |
|
| 1386 | + if ($items) { |
|
| 1387 | + foreach ($items as $item) { |
|
| 1388 | + $pad = str_repeat(' ', $level * 3); |
|
| 1389 | + if ($item->ID == $default) { |
|
| 1390 | + $current = ' selected="selected"'; |
|
| 1391 | + } else { |
|
| 1392 | + $current = ''; |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1396 | + . esc_html($item->post_title) |
|
| 1397 | + . "</option>"; |
|
| 1398 | + parent_dropdown($default, $item->ID, $level + 1); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + } |
|
| 1402 | 1402 | } |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | /** |
| 543 | 543 | * @initiate session |
| 544 | 544 | * @access private |
| 545 | - * @return TRUE on success, FALSE on fail |
|
| 545 | + * @return boolean on success, FALSE on fail |
|
| 546 | 546 | * @throws EE_Error |
| 547 | 547 | * @throws InvalidArgumentException |
| 548 | 548 | * @throws InvalidDataTypeException |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * @update session data prior to saving to the db |
| 779 | 779 | * @access public |
| 780 | 780 | * @param bool $new_session |
| 781 | - * @return TRUE on success, FALSE on fail |
|
| 781 | + * @return boolean on success, FALSE on fail |
|
| 782 | 782 | * @throws EE_Error |
| 783 | 783 | * @throws InvalidArgumentException |
| 784 | 784 | * @throws InvalidDataTypeException |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | * _save_session_to_db |
| 880 | 880 | * |
| 881 | 881 | * @param bool $clear_session |
| 882 | - * @return string |
|
| 882 | + * @return boolean |
|
| 883 | 883 | * @throws EE_Error |
| 884 | 884 | * @throws InvalidArgumentException |
| 885 | 885 | * @throws InvalidDataTypeException |
@@ -22,1229 +22,1229 @@ discard block |
||
| 22 | 22 | class EE_Session implements SessionIdentifierInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - const session_id_prefix = 'ee_ssn_'; |
|
| 26 | - |
|
| 27 | - const hash_check_prefix = 'ee_shc_'; |
|
| 28 | - |
|
| 29 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 30 | - |
|
| 31 | - const STATUS_CLOSED = 0; |
|
| 32 | - |
|
| 33 | - const STATUS_OPEN = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * instance of the EE_Session object |
|
| 37 | - * |
|
| 38 | - * @var EE_Session |
|
| 39 | - */ |
|
| 40 | - private static $_instance; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var CacheStorageInterface $cache_storage |
|
| 44 | - */ |
|
| 45 | - protected $cache_storage; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * EE_Encryption object |
|
| 49 | - * |
|
| 50 | - * @var EE_Encryption |
|
| 51 | - */ |
|
| 52 | - protected $encryption; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * the session id |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - private $_sid; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * session id salt |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - private $_sid_salt; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * session data |
|
| 70 | - * |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - private $_session_data = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * how long an EE session lasts |
|
| 77 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 78 | - * |
|
| 79 | - * @var SessionLifespan $session_lifespan |
|
| 80 | - */ |
|
| 81 | - private $session_lifespan; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * session expiration time as Unix timestamp in GMT |
|
| 85 | - * |
|
| 86 | - * @var int |
|
| 87 | - */ |
|
| 88 | - private $_expiration; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * whether or not session has expired at some point |
|
| 92 | - * |
|
| 93 | - * @var boolean |
|
| 94 | - */ |
|
| 95 | - private $_expired = false; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * current time as Unix timestamp in GMT |
|
| 99 | - * |
|
| 100 | - * @var int |
|
| 101 | - */ |
|
| 102 | - private $_time; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * whether to encrypt session data |
|
| 106 | - * |
|
| 107 | - * @var bool |
|
| 108 | - */ |
|
| 109 | - private $_use_encryption; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * well... according to the server... |
|
| 113 | - * |
|
| 114 | - * @var null |
|
| 115 | - */ |
|
| 116 | - private $_user_agent; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * do you really trust the server ? |
|
| 120 | - * |
|
| 121 | - * @var null |
|
| 122 | - */ |
|
| 123 | - private $_ip_address; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * current WP user_id |
|
| 127 | - * |
|
| 128 | - * @var null |
|
| 129 | - */ |
|
| 130 | - private $_wp_user_id; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * array for defining default session vars |
|
| 134 | - * |
|
| 135 | - * @var array |
|
| 136 | - */ |
|
| 137 | - private $_default_session_vars = array( |
|
| 138 | - 'id' => null, |
|
| 139 | - 'user_id' => null, |
|
| 140 | - 'ip_address' => null, |
|
| 141 | - 'user_agent' => null, |
|
| 142 | - 'init_access' => null, |
|
| 143 | - 'last_access' => null, |
|
| 144 | - 'expiration' => null, |
|
| 145 | - 'pages_visited' => array(), |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * timestamp for when last garbage collection cycle was performed |
|
| 150 | - * |
|
| 151 | - * @var int $_last_gc |
|
| 152 | - */ |
|
| 153 | - private $_last_gc; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @var RequestInterface $request |
|
| 157 | - */ |
|
| 158 | - protected $request; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * whether session is active or not |
|
| 162 | - * |
|
| 163 | - * @var int $status |
|
| 164 | - */ |
|
| 165 | - private $status = EE_Session::STATUS_CLOSED; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @singleton method used to instantiate class object |
|
| 171 | - * @param CacheStorageInterface $cache_storage |
|
| 172 | - * @param SessionLifespan|null $lifespan |
|
| 173 | - * @param RequestInterface $request |
|
| 174 | - * @param EE_Encryption $encryption |
|
| 175 | - * @return EE_Session |
|
| 176 | - * @throws InvalidArgumentException |
|
| 177 | - * @throws InvalidDataTypeException |
|
| 178 | - * @throws InvalidInterfaceException |
|
| 179 | - */ |
|
| 180 | - public static function instance( |
|
| 181 | - CacheStorageInterface $cache_storage = null, |
|
| 182 | - SessionLifespan $lifespan = null, |
|
| 183 | - RequestInterface $request = null, |
|
| 184 | - EE_Encryption $encryption = null |
|
| 185 | - ) { |
|
| 186 | - // check if class object is instantiated |
|
| 187 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 188 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | - self::$_instance = new self( |
|
| 191 | - $cache_storage, |
|
| 192 | - $lifespan, |
|
| 193 | - $request, |
|
| 194 | - $encryption |
|
| 195 | - ); |
|
| 196 | - } |
|
| 197 | - return self::$_instance; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * protected constructor to prevent direct creation |
|
| 203 | - * |
|
| 204 | - * @param CacheStorageInterface $cache_storage |
|
| 205 | - * @param SessionLifespan $lifespan |
|
| 206 | - * @param RequestInterface $request |
|
| 207 | - * @param EE_Encryption $encryption |
|
| 208 | - * @throws InvalidArgumentException |
|
| 209 | - * @throws InvalidDataTypeException |
|
| 210 | - * @throws InvalidInterfaceException |
|
| 211 | - */ |
|
| 212 | - protected function __construct( |
|
| 213 | - CacheStorageInterface $cache_storage, |
|
| 214 | - SessionLifespan $lifespan, |
|
| 215 | - RequestInterface $request, |
|
| 216 | - EE_Encryption $encryption = null |
|
| 217 | - ) { |
|
| 218 | - // session loading is turned ON by default, |
|
| 219 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 220 | - // (which currently fires on the init hook at priority 9), |
|
| 221 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - $this->session_lifespan = $lifespan; |
|
| 226 | - $this->request = $request; |
|
| 227 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 228 | - define('ESPRESSO_SESSION', true); |
|
| 229 | - } |
|
| 230 | - // retrieve session options from db |
|
| 231 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 232 | - if (! empty($session_settings)) { |
|
| 233 | - // cycle though existing session options |
|
| 234 | - foreach ($session_settings as $var_name => $session_setting) { |
|
| 235 | - // set values for class properties |
|
| 236 | - $var_name = '_' . $var_name; |
|
| 237 | - $this->{$var_name} = $session_setting; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - $this->cache_storage = $cache_storage; |
|
| 241 | - // are we using encryption? |
|
| 242 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 243 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 244 | - // encrypt data via: $this->encryption->encrypt(); |
|
| 245 | - $this->encryption = $encryption; |
|
| 246 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 247 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 248 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 249 | - // apply default session vars |
|
| 250 | - $this->_set_defaults(); |
|
| 251 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 252 | - // check request for 'clear_session' param |
|
| 253 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 254 | - // once everything is all said and done, |
|
| 255 | - add_action('shutdown', array($this, 'update'), 100); |
|
| 256 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 257 | - $this->configure_garbage_collection_filters(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return bool |
|
| 263 | - * @throws InvalidArgumentException |
|
| 264 | - * @throws InvalidDataTypeException |
|
| 265 | - * @throws InvalidInterfaceException |
|
| 266 | - */ |
|
| 267 | - public static function isLoadedAndActive() |
|
| 268 | - { |
|
| 269 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 270 | - && EE_Session::instance() instanceof EE_Session |
|
| 271 | - && EE_Session::instance()->isActive(); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return bool |
|
| 277 | - */ |
|
| 278 | - public function isActive() |
|
| 279 | - { |
|
| 280 | - return $this->status === EE_Session::STATUS_OPEN; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @return void |
|
| 287 | - * @throws EE_Error |
|
| 288 | - * @throws InvalidArgumentException |
|
| 289 | - * @throws InvalidDataTypeException |
|
| 290 | - * @throws InvalidInterfaceException |
|
| 291 | - * @throws InvalidSessionDataException |
|
| 292 | - */ |
|
| 293 | - public function open_session() |
|
| 294 | - { |
|
| 295 | - // check for existing session and retrieve it from db |
|
| 296 | - if (! $this->_espresso_session()) { |
|
| 297 | - // or just start a new one |
|
| 298 | - $this->_create_espresso_session(); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @return bool |
|
| 306 | - */ |
|
| 307 | - public function expired() |
|
| 308 | - { |
|
| 309 | - return $this->_expired; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @return void |
|
| 316 | - */ |
|
| 317 | - public function reset_expired() |
|
| 318 | - { |
|
| 319 | - $this->_expired = false; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return int |
|
| 325 | - */ |
|
| 326 | - public function expiration() |
|
| 327 | - { |
|
| 328 | - return $this->_expiration; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @return int |
|
| 335 | - */ |
|
| 336 | - public function extension() |
|
| 337 | - { |
|
| 338 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param int $time number of seconds to add to session expiration |
|
| 345 | - */ |
|
| 346 | - public function extend_expiration($time = 0) |
|
| 347 | - { |
|
| 348 | - $time = $time ? $time : $this->extension(); |
|
| 349 | - $this->_expiration += absint($time); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @return int |
|
| 356 | - */ |
|
| 357 | - public function lifespan() |
|
| 358 | - { |
|
| 359 | - return $this->session_lifespan->inSeconds(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * This just sets some defaults for the _session data property |
|
| 366 | - * |
|
| 367 | - * @access private |
|
| 368 | - * @return void |
|
| 369 | - */ |
|
| 370 | - private function _set_defaults() |
|
| 371 | - { |
|
| 372 | - // set some defaults |
|
| 373 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 374 | - if (is_array($default_var)) { |
|
| 375 | - $this->_session_data[ $key ] = array(); |
|
| 376 | - } else { |
|
| 377 | - $this->_session_data[ $key ] = ''; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 25 | + const session_id_prefix = 'ee_ssn_'; |
|
| 26 | + |
|
| 27 | + const hash_check_prefix = 'ee_shc_'; |
|
| 28 | + |
|
| 29 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 30 | + |
|
| 31 | + const STATUS_CLOSED = 0; |
|
| 32 | + |
|
| 33 | + const STATUS_OPEN = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * instance of the EE_Session object |
|
| 37 | + * |
|
| 38 | + * @var EE_Session |
|
| 39 | + */ |
|
| 40 | + private static $_instance; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var CacheStorageInterface $cache_storage |
|
| 44 | + */ |
|
| 45 | + protected $cache_storage; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * EE_Encryption object |
|
| 49 | + * |
|
| 50 | + * @var EE_Encryption |
|
| 51 | + */ |
|
| 52 | + protected $encryption; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * the session id |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + private $_sid; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * session id salt |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + private $_sid_salt; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * session data |
|
| 70 | + * |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + private $_session_data = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * how long an EE session lasts |
|
| 77 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 78 | + * |
|
| 79 | + * @var SessionLifespan $session_lifespan |
|
| 80 | + */ |
|
| 81 | + private $session_lifespan; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * session expiration time as Unix timestamp in GMT |
|
| 85 | + * |
|
| 86 | + * @var int |
|
| 87 | + */ |
|
| 88 | + private $_expiration; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * whether or not session has expired at some point |
|
| 92 | + * |
|
| 93 | + * @var boolean |
|
| 94 | + */ |
|
| 95 | + private $_expired = false; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * current time as Unix timestamp in GMT |
|
| 99 | + * |
|
| 100 | + * @var int |
|
| 101 | + */ |
|
| 102 | + private $_time; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * whether to encrypt session data |
|
| 106 | + * |
|
| 107 | + * @var bool |
|
| 108 | + */ |
|
| 109 | + private $_use_encryption; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * well... according to the server... |
|
| 113 | + * |
|
| 114 | + * @var null |
|
| 115 | + */ |
|
| 116 | + private $_user_agent; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * do you really trust the server ? |
|
| 120 | + * |
|
| 121 | + * @var null |
|
| 122 | + */ |
|
| 123 | + private $_ip_address; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * current WP user_id |
|
| 127 | + * |
|
| 128 | + * @var null |
|
| 129 | + */ |
|
| 130 | + private $_wp_user_id; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * array for defining default session vars |
|
| 134 | + * |
|
| 135 | + * @var array |
|
| 136 | + */ |
|
| 137 | + private $_default_session_vars = array( |
|
| 138 | + 'id' => null, |
|
| 139 | + 'user_id' => null, |
|
| 140 | + 'ip_address' => null, |
|
| 141 | + 'user_agent' => null, |
|
| 142 | + 'init_access' => null, |
|
| 143 | + 'last_access' => null, |
|
| 144 | + 'expiration' => null, |
|
| 145 | + 'pages_visited' => array(), |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * timestamp for when last garbage collection cycle was performed |
|
| 150 | + * |
|
| 151 | + * @var int $_last_gc |
|
| 152 | + */ |
|
| 153 | + private $_last_gc; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @var RequestInterface $request |
|
| 157 | + */ |
|
| 158 | + protected $request; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * whether session is active or not |
|
| 162 | + * |
|
| 163 | + * @var int $status |
|
| 164 | + */ |
|
| 165 | + private $status = EE_Session::STATUS_CLOSED; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @singleton method used to instantiate class object |
|
| 171 | + * @param CacheStorageInterface $cache_storage |
|
| 172 | + * @param SessionLifespan|null $lifespan |
|
| 173 | + * @param RequestInterface $request |
|
| 174 | + * @param EE_Encryption $encryption |
|
| 175 | + * @return EE_Session |
|
| 176 | + * @throws InvalidArgumentException |
|
| 177 | + * @throws InvalidDataTypeException |
|
| 178 | + * @throws InvalidInterfaceException |
|
| 179 | + */ |
|
| 180 | + public static function instance( |
|
| 181 | + CacheStorageInterface $cache_storage = null, |
|
| 182 | + SessionLifespan $lifespan = null, |
|
| 183 | + RequestInterface $request = null, |
|
| 184 | + EE_Encryption $encryption = null |
|
| 185 | + ) { |
|
| 186 | + // check if class object is instantiated |
|
| 187 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 188 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 189 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | + self::$_instance = new self( |
|
| 191 | + $cache_storage, |
|
| 192 | + $lifespan, |
|
| 193 | + $request, |
|
| 194 | + $encryption |
|
| 195 | + ); |
|
| 196 | + } |
|
| 197 | + return self::$_instance; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * protected constructor to prevent direct creation |
|
| 203 | + * |
|
| 204 | + * @param CacheStorageInterface $cache_storage |
|
| 205 | + * @param SessionLifespan $lifespan |
|
| 206 | + * @param RequestInterface $request |
|
| 207 | + * @param EE_Encryption $encryption |
|
| 208 | + * @throws InvalidArgumentException |
|
| 209 | + * @throws InvalidDataTypeException |
|
| 210 | + * @throws InvalidInterfaceException |
|
| 211 | + */ |
|
| 212 | + protected function __construct( |
|
| 213 | + CacheStorageInterface $cache_storage, |
|
| 214 | + SessionLifespan $lifespan, |
|
| 215 | + RequestInterface $request, |
|
| 216 | + EE_Encryption $encryption = null |
|
| 217 | + ) { |
|
| 218 | + // session loading is turned ON by default, |
|
| 219 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 220 | + // (which currently fires on the init hook at priority 9), |
|
| 221 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 222 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + $this->session_lifespan = $lifespan; |
|
| 226 | + $this->request = $request; |
|
| 227 | + if (! defined('ESPRESSO_SESSION')) { |
|
| 228 | + define('ESPRESSO_SESSION', true); |
|
| 229 | + } |
|
| 230 | + // retrieve session options from db |
|
| 231 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 232 | + if (! empty($session_settings)) { |
|
| 233 | + // cycle though existing session options |
|
| 234 | + foreach ($session_settings as $var_name => $session_setting) { |
|
| 235 | + // set values for class properties |
|
| 236 | + $var_name = '_' . $var_name; |
|
| 237 | + $this->{$var_name} = $session_setting; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + $this->cache_storage = $cache_storage; |
|
| 241 | + // are we using encryption? |
|
| 242 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 243 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 244 | + // encrypt data via: $this->encryption->encrypt(); |
|
| 245 | + $this->encryption = $encryption; |
|
| 246 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 247 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 248 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 249 | + // apply default session vars |
|
| 250 | + $this->_set_defaults(); |
|
| 251 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 252 | + // check request for 'clear_session' param |
|
| 253 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 254 | + // once everything is all said and done, |
|
| 255 | + add_action('shutdown', array($this, 'update'), 100); |
|
| 256 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 257 | + $this->configure_garbage_collection_filters(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return bool |
|
| 263 | + * @throws InvalidArgumentException |
|
| 264 | + * @throws InvalidDataTypeException |
|
| 265 | + * @throws InvalidInterfaceException |
|
| 266 | + */ |
|
| 267 | + public static function isLoadedAndActive() |
|
| 268 | + { |
|
| 269 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 270 | + && EE_Session::instance() instanceof EE_Session |
|
| 271 | + && EE_Session::instance()->isActive(); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return bool |
|
| 277 | + */ |
|
| 278 | + public function isActive() |
|
| 279 | + { |
|
| 280 | + return $this->status === EE_Session::STATUS_OPEN; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @return void |
|
| 287 | + * @throws EE_Error |
|
| 288 | + * @throws InvalidArgumentException |
|
| 289 | + * @throws InvalidDataTypeException |
|
| 290 | + * @throws InvalidInterfaceException |
|
| 291 | + * @throws InvalidSessionDataException |
|
| 292 | + */ |
|
| 293 | + public function open_session() |
|
| 294 | + { |
|
| 295 | + // check for existing session and retrieve it from db |
|
| 296 | + if (! $this->_espresso_session()) { |
|
| 297 | + // or just start a new one |
|
| 298 | + $this->_create_espresso_session(); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @return bool |
|
| 306 | + */ |
|
| 307 | + public function expired() |
|
| 308 | + { |
|
| 309 | + return $this->_expired; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @return void |
|
| 316 | + */ |
|
| 317 | + public function reset_expired() |
|
| 318 | + { |
|
| 319 | + $this->_expired = false; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return int |
|
| 325 | + */ |
|
| 326 | + public function expiration() |
|
| 327 | + { |
|
| 328 | + return $this->_expiration; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @return int |
|
| 335 | + */ |
|
| 336 | + public function extension() |
|
| 337 | + { |
|
| 338 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param int $time number of seconds to add to session expiration |
|
| 345 | + */ |
|
| 346 | + public function extend_expiration($time = 0) |
|
| 347 | + { |
|
| 348 | + $time = $time ? $time : $this->extension(); |
|
| 349 | + $this->_expiration += absint($time); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @return int |
|
| 356 | + */ |
|
| 357 | + public function lifespan() |
|
| 358 | + { |
|
| 359 | + return $this->session_lifespan->inSeconds(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * This just sets some defaults for the _session data property |
|
| 366 | + * |
|
| 367 | + * @access private |
|
| 368 | + * @return void |
|
| 369 | + */ |
|
| 370 | + private function _set_defaults() |
|
| 371 | + { |
|
| 372 | + // set some defaults |
|
| 373 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 374 | + if (is_array($default_var)) { |
|
| 375 | + $this->_session_data[ $key ] = array(); |
|
| 376 | + } else { |
|
| 377 | + $this->_session_data[ $key ] = ''; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | |
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @retrieve session data |
|
| 386 | - * @access public |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function id() |
|
| 390 | - { |
|
| 391 | - return $this->_sid; |
|
| 392 | - } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @retrieve session data |
|
| 386 | + * @access public |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function id() |
|
| 390 | + { |
|
| 391 | + return $this->_sid; |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | 394 | |
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * @param \EE_Cart $cart |
|
| 398 | - * @return bool |
|
| 399 | - */ |
|
| 400 | - public function set_cart(EE_Cart $cart) |
|
| 401 | - { |
|
| 402 | - $this->_session_data['cart'] = $cart; |
|
| 403 | - return true; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * reset_cart |
|
| 410 | - */ |
|
| 411 | - public function reset_cart() |
|
| 412 | - { |
|
| 413 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 414 | - $this->_session_data['cart'] = null; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * @return \EE_Cart |
|
| 421 | - */ |
|
| 422 | - public function cart() |
|
| 423 | - { |
|
| 424 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 425 | - ? $this->_session_data['cart'] |
|
| 426 | - : null; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @param \EE_Checkout $checkout |
|
| 433 | - * @return bool |
|
| 434 | - */ |
|
| 435 | - public function set_checkout(EE_Checkout $checkout) |
|
| 436 | - { |
|
| 437 | - $this->_session_data['checkout'] = $checkout; |
|
| 438 | - return true; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * reset_checkout |
|
| 445 | - */ |
|
| 446 | - public function reset_checkout() |
|
| 447 | - { |
|
| 448 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 449 | - $this->_session_data['checkout'] = null; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @return \EE_Checkout |
|
| 456 | - */ |
|
| 457 | - public function checkout() |
|
| 458 | - { |
|
| 459 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 460 | - ? $this->_session_data['checkout'] |
|
| 461 | - : null; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @param \EE_Transaction $transaction |
|
| 468 | - * @return bool |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public function set_transaction(EE_Transaction $transaction) |
|
| 472 | - { |
|
| 473 | - // first remove the session from the transaction before we save the transaction in the session |
|
| 474 | - $transaction->set_txn_session_data(null); |
|
| 475 | - $this->_session_data['transaction'] = $transaction; |
|
| 476 | - return true; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * reset_transaction |
|
| 483 | - */ |
|
| 484 | - public function reset_transaction() |
|
| 485 | - { |
|
| 486 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 487 | - $this->_session_data['transaction'] = null; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @return \EE_Transaction |
|
| 494 | - */ |
|
| 495 | - public function transaction() |
|
| 496 | - { |
|
| 497 | - return isset($this->_session_data['transaction']) |
|
| 498 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 499 | - ? $this->_session_data['transaction'] |
|
| 500 | - : null; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * retrieve session data |
|
| 506 | - * |
|
| 507 | - * @param null $key |
|
| 508 | - * @param bool $reset_cache |
|
| 509 | - * @return array |
|
| 510 | - */ |
|
| 511 | - public function get_session_data($key = null, $reset_cache = false) |
|
| 512 | - { |
|
| 513 | - if ($reset_cache) { |
|
| 514 | - $this->reset_cart(); |
|
| 515 | - $this->reset_checkout(); |
|
| 516 | - $this->reset_transaction(); |
|
| 517 | - } |
|
| 518 | - if (! empty($key)) { |
|
| 519 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 520 | - } |
|
| 521 | - return $this->_session_data; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Returns TRUE on success, FALSE on fail |
|
| 527 | - * |
|
| 528 | - * @param array $data |
|
| 529 | - * @return bool |
|
| 530 | - */ |
|
| 531 | - public function set_session_data($data) |
|
| 532 | - { |
|
| 533 | - // nothing ??? bad data ??? go home! |
|
| 534 | - if (empty($data) || ! is_array($data)) { |
|
| 535 | - EE_Error::add_error( |
|
| 536 | - esc_html__( |
|
| 537 | - 'No session data or invalid session data was provided.', |
|
| 538 | - 'event_espresso' |
|
| 539 | - ), |
|
| 540 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 541 | - ); |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - foreach ($data as $key => $value) { |
|
| 545 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 546 | - EE_Error::add_error( |
|
| 547 | - sprintf( |
|
| 548 | - esc_html__( |
|
| 549 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
| 550 | - 'event_espresso' |
|
| 551 | - ), |
|
| 552 | - $key |
|
| 553 | - ), |
|
| 554 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 555 | - ); |
|
| 556 | - return false; |
|
| 557 | - } |
|
| 558 | - $this->_session_data[ $key ] = $value; |
|
| 559 | - } |
|
| 560 | - return true; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @initiate session |
|
| 567 | - * @access private |
|
| 568 | - * @return TRUE on success, FALSE on fail |
|
| 569 | - * @throws EE_Error |
|
| 570 | - * @throws InvalidArgumentException |
|
| 571 | - * @throws InvalidDataTypeException |
|
| 572 | - * @throws InvalidInterfaceException |
|
| 573 | - * @throws InvalidSessionDataException |
|
| 574 | - */ |
|
| 575 | - private function _espresso_session() |
|
| 576 | - { |
|
| 577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 578 | - // check that session has started |
|
| 579 | - if (session_id() === '') { |
|
| 580 | - //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 581 | - session_start(); |
|
| 582 | - } |
|
| 583 | - $this->status = EE_Session::STATUS_OPEN; |
|
| 584 | - // get our modified session ID |
|
| 585 | - $this->_sid = $this->_generate_session_id(); |
|
| 586 | - // and the visitors IP |
|
| 587 | - $this->_ip_address = $this->request->ipAddress(); |
|
| 588 | - // set the "user agent" |
|
| 589 | - $this->_user_agent = $this->request->userAgent(); |
|
| 590 | - // now let's retrieve what's in the db |
|
| 591 | - $session_data = $this->_retrieve_session_data(); |
|
| 592 | - if (! empty($session_data)) { |
|
| 593 | - // get the current time in UTC |
|
| 594 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 595 | - // and reset the session expiration |
|
| 596 | - $this->_expiration = isset($session_data['expiration']) |
|
| 597 | - ? $session_data['expiration'] |
|
| 598 | - : $this->_time + $this->session_lifespan->inSeconds(); |
|
| 599 | - } else { |
|
| 600 | - // set initial site access time and the session expiration |
|
| 601 | - $this->_set_init_access_and_expiration(); |
|
| 602 | - // set referer |
|
| 603 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 604 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 605 | - : ''; |
|
| 606 | - // no previous session = go back and create one (on top of the data above) |
|
| 607 | - return false; |
|
| 608 | - } |
|
| 609 | - // now the user agent |
|
| 610 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 611 | - return false; |
|
| 612 | - } |
|
| 613 | - // wait a minute... how old are you? |
|
| 614 | - if ($this->_time > $this->_expiration) { |
|
| 615 | - // yer too old fer me! |
|
| 616 | - $this->_expired = true; |
|
| 617 | - // wipe out everything that isn't a default session datum |
|
| 618 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 619 | - } |
|
| 620 | - // make event espresso session data available to plugin |
|
| 621 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 622 | - return true; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * _get_session_data |
|
| 629 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 630 | - * databases |
|
| 631 | - * |
|
| 632 | - * @return array |
|
| 633 | - * @throws EE_Error |
|
| 634 | - * @throws InvalidArgumentException |
|
| 635 | - * @throws InvalidSessionDataException |
|
| 636 | - * @throws InvalidDataTypeException |
|
| 637 | - * @throws InvalidInterfaceException |
|
| 638 | - */ |
|
| 639 | - protected function _retrieve_session_data() |
|
| 640 | - { |
|
| 641 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 642 | - try { |
|
| 643 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 644 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 645 | - if (empty($session_data)) { |
|
| 646 | - return array(); |
|
| 647 | - } |
|
| 648 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 649 | - $hash_check = $this->cache_storage->get( |
|
| 650 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 651 | - false |
|
| 652 | - ); |
|
| 653 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 654 | - EE_Error::add_error( |
|
| 655 | - sprintf( |
|
| 656 | - __( |
|
| 657 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 658 | - 'event_espresso' |
|
| 659 | - ), |
|
| 660 | - EE_Session::session_id_prefix . $this->_sid |
|
| 661 | - ), |
|
| 662 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 663 | - ); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } catch (Exception $e) { |
|
| 667 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
| 668 | - global $wpdb; |
|
| 669 | - $row = $wpdb->get_row( |
|
| 670 | - $wpdb->prepare( |
|
| 671 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 672 | - '_transient_' . $ssn_key |
|
| 673 | - ) |
|
| 674 | - ); |
|
| 675 | - $session_data = is_object($row) ? $row->option_value : null; |
|
| 676 | - if ($session_data) { |
|
| 677 | - $session_data = preg_replace_callback( |
|
| 678 | - '!s:(d+):"(.*?)";!', |
|
| 679 | - function ($match) |
|
| 680 | - { |
|
| 681 | - return $match[1] === strlen($match[2]) |
|
| 682 | - ? $match[0] |
|
| 683 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 684 | - }, |
|
| 685 | - $session_data |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - $session_data = maybe_unserialize($session_data); |
|
| 689 | - } |
|
| 690 | - // in case the data is encoded... try to decode it |
|
| 691 | - $session_data = $this->encryption instanceof EE_Encryption |
|
| 692 | - ? $this->encryption->base64_string_decode($session_data) |
|
| 693 | - : $session_data; |
|
| 694 | - if (! is_array($session_data)) { |
|
| 695 | - try { |
|
| 696 | - $session_data = maybe_unserialize($session_data); |
|
| 697 | - } catch (Exception $e) { |
|
| 698 | - $msg = esc_html__( |
|
| 699 | - 'An error occurred while attempting to unserialize the session data.', |
|
| 700 | - 'event_espresso' |
|
| 701 | - ); |
|
| 702 | - $msg .= WP_DEBUG |
|
| 703 | - ? '<br><pre>' |
|
| 704 | - . print_r($session_data, true) |
|
| 705 | - . '</pre><br>' |
|
| 706 | - . $this->find_serialize_error($session_data) |
|
| 707 | - : ''; |
|
| 708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 709 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
| 710 | - } |
|
| 711 | - } |
|
| 712 | - // just a check to make sure the session array is indeed an array |
|
| 713 | - if (! is_array($session_data)) { |
|
| 714 | - // no?!?! then something is wrong |
|
| 715 | - $msg = esc_html__( |
|
| 716 | - 'The session data is missing, invalid, or corrupted.', |
|
| 717 | - 'event_espresso' |
|
| 718 | - ); |
|
| 719 | - $msg .= WP_DEBUG |
|
| 720 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 721 | - : ''; |
|
| 722 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 723 | - throw new InvalidSessionDataException($msg); |
|
| 724 | - } |
|
| 725 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 726 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 727 | - $session_data['transaction'] |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - return $session_data; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * _generate_session_id |
|
| 737 | - * Retrieves the PHP session id either directly from the PHP session, |
|
| 738 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 739 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
| 740 | - * so that it can be safely used as a $_REQUEST param |
|
| 741 | - * |
|
| 742 | - * @return string |
|
| 743 | - */ |
|
| 744 | - protected function _generate_session_id() |
|
| 745 | - { |
|
| 746 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 747 | - if (isset($_REQUEST['EESID'])) { |
|
| 748 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 749 | - } else { |
|
| 750 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 751 | - } |
|
| 752 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * _get_sid_salt |
|
| 759 | - * |
|
| 760 | - * @return string |
|
| 761 | - */ |
|
| 762 | - protected function _get_sid_salt() |
|
| 763 | - { |
|
| 764 | - // was session id salt already saved to db ? |
|
| 765 | - if (empty($this->_sid_salt)) { |
|
| 766 | - // no? then maybe use WP defined constant |
|
| 767 | - if (defined('AUTH_SALT')) { |
|
| 768 | - $this->_sid_salt = AUTH_SALT; |
|
| 769 | - } |
|
| 770 | - // if salt doesn't exist or is too short |
|
| 771 | - if (strlen($this->_sid_salt) < 32) { |
|
| 772 | - // create a new one |
|
| 773 | - $this->_sid_salt = wp_generate_password(64); |
|
| 774 | - } |
|
| 775 | - // and save it as a permanent session setting |
|
| 776 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 777 | - } |
|
| 778 | - return $this->_sid_salt; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * _set_init_access_and_expiration |
|
| 785 | - * |
|
| 786 | - * @return void |
|
| 787 | - */ |
|
| 788 | - protected function _set_init_access_and_expiration() |
|
| 789 | - { |
|
| 790 | - $this->_time = time(); |
|
| 791 | - $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
| 792 | - // set initial site access time |
|
| 793 | - $this->_session_data['init_access'] = $this->_time; |
|
| 794 | - // and the session expiration |
|
| 795 | - $this->_session_data['expiration'] = $this->_expiration; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * @update session data prior to saving to the db |
|
| 802 | - * @access public |
|
| 803 | - * @param bool $new_session |
|
| 804 | - * @return TRUE on success, FALSE on fail |
|
| 805 | - * @throws EE_Error |
|
| 806 | - * @throws InvalidArgumentException |
|
| 807 | - * @throws InvalidDataTypeException |
|
| 808 | - * @throws InvalidInterfaceException |
|
| 809 | - */ |
|
| 810 | - public function update($new_session = false) |
|
| 811 | - { |
|
| 812 | - $this->_session_data = $this->_session_data !== null |
|
| 813 | - && is_array($this->_session_data) |
|
| 814 | - && isset($this->_session_data['id']) |
|
| 815 | - ? $this->_session_data |
|
| 816 | - : array(); |
|
| 817 | - if (empty($this->_session_data)) { |
|
| 818 | - $this->_set_defaults(); |
|
| 819 | - } |
|
| 820 | - $session_data = array(); |
|
| 821 | - foreach ($this->_session_data as $key => $value) { |
|
| 822 | - |
|
| 823 | - switch ($key) { |
|
| 824 | - |
|
| 825 | - case 'id' : |
|
| 826 | - // session ID |
|
| 827 | - $session_data['id'] = $this->_sid; |
|
| 828 | - break; |
|
| 829 | - case 'ip_address' : |
|
| 830 | - // visitor ip address |
|
| 831 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 832 | - break; |
|
| 833 | - case 'user_agent' : |
|
| 834 | - // visitor user_agent |
|
| 835 | - $session_data['user_agent'] = $this->_user_agent; |
|
| 836 | - break; |
|
| 837 | - case 'init_access' : |
|
| 838 | - $session_data['init_access'] = absint($value); |
|
| 839 | - break; |
|
| 840 | - case 'last_access' : |
|
| 841 | - // current access time |
|
| 842 | - $session_data['last_access'] = $this->_time; |
|
| 843 | - break; |
|
| 844 | - case 'expiration' : |
|
| 845 | - // when the session expires |
|
| 846 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
| 847 | - ? $this->_expiration |
|
| 848 | - : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
| 849 | - break; |
|
| 850 | - case 'user_id' : |
|
| 851 | - // current user if logged in |
|
| 852 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
| 853 | - break; |
|
| 854 | - case 'pages_visited' : |
|
| 855 | - $page_visit = $this->_get_page_visit(); |
|
| 856 | - if ($page_visit) { |
|
| 857 | - // set pages visited where the first will be the http referrer |
|
| 858 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 859 | - // we'll only save the last 10 page visits. |
|
| 860 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 861 | - } |
|
| 862 | - break; |
|
| 863 | - default : |
|
| 864 | - // carry any other data over |
|
| 865 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - $this->_session_data = $session_data; |
|
| 869 | - // creating a new session does not require saving to the db just yet |
|
| 870 | - if (! $new_session) { |
|
| 871 | - // ready? let's save |
|
| 872 | - if ($this->_save_session_to_db()) { |
|
| 873 | - return true; |
|
| 874 | - } |
|
| 875 | - return false; |
|
| 876 | - } |
|
| 877 | - // meh, why not? |
|
| 878 | - return true; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * @create session data array |
|
| 885 | - * @access public |
|
| 886 | - * @return bool |
|
| 887 | - * @throws EE_Error |
|
| 888 | - * @throws InvalidArgumentException |
|
| 889 | - * @throws InvalidDataTypeException |
|
| 890 | - * @throws InvalidInterfaceException |
|
| 891 | - */ |
|
| 892 | - private function _create_espresso_session() |
|
| 893 | - { |
|
| 894 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 895 | - // use the update function for now with $new_session arg set to TRUE |
|
| 896 | - return $this->update(true) ? true : false; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * _save_session_to_db |
|
| 903 | - * |
|
| 904 | - * @param bool $clear_session |
|
| 905 | - * @return string |
|
| 906 | - * @throws EE_Error |
|
| 907 | - * @throws InvalidArgumentException |
|
| 908 | - * @throws InvalidDataTypeException |
|
| 909 | - * @throws InvalidInterfaceException |
|
| 910 | - */ |
|
| 911 | - private function _save_session_to_db($clear_session = false) |
|
| 912 | - { |
|
| 913 | - // don't save sessions for crawlers |
|
| 914 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 915 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 916 | - return false; |
|
| 917 | - } |
|
| 918 | - $transaction = $this->transaction(); |
|
| 919 | - if ($transaction instanceof EE_Transaction) { |
|
| 920 | - if (! $transaction->ID()) { |
|
| 921 | - $transaction->save(); |
|
| 922 | - } |
|
| 923 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
| 924 | - } |
|
| 925 | - // then serialize all of our session data |
|
| 926 | - $session_data = serialize($this->_session_data); |
|
| 927 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 928 | - $session_data = $this->_use_encryption |
|
| 929 | - ? $this->encryption->base64_string_encode($session_data) |
|
| 930 | - : $session_data; |
|
| 931 | - // maybe save hash check |
|
| 932 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 933 | - $this->cache_storage->add( |
|
| 934 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 935 | - md5($session_data), |
|
| 936 | - $this->session_lifespan->inSeconds() |
|
| 937 | - ); |
|
| 938 | - } |
|
| 939 | - // we're using the Transient API for storing session data, |
|
| 940 | - return $this->cache_storage->add( |
|
| 941 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 942 | - $session_data, |
|
| 943 | - $this->session_lifespan->inSeconds() |
|
| 944 | - ); |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * @get the full page request the visitor is accessing |
|
| 950 | - * @access public |
|
| 951 | - * @return string |
|
| 952 | - */ |
|
| 953 | - public function _get_page_visit() |
|
| 954 | - { |
|
| 955 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 956 | - // check for request url |
|
| 957 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 958 | - $http_host = ''; |
|
| 959 | - $page_id = '?'; |
|
| 960 | - $e_reg = ''; |
|
| 961 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 962 | - $ru_bits = explode('?', $request_uri); |
|
| 963 | - $request_uri = $ru_bits[0]; |
|
| 964 | - // check for and grab host as well |
|
| 965 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
| 966 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 967 | - } |
|
| 968 | - // check for page_id in SERVER REQUEST |
|
| 969 | - if (isset($_REQUEST['page_id'])) { |
|
| 970 | - // rebuild $e_reg without any of the extra parameters |
|
| 971 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 972 | - } |
|
| 973 | - // check for $e_reg in SERVER REQUEST |
|
| 974 | - if (isset($_REQUEST['ee'])) { |
|
| 975 | - // rebuild $e_reg without any of the extra parameters |
|
| 976 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 977 | - } |
|
| 978 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 979 | - } |
|
| 980 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * @the current wp user id |
|
| 987 | - * @access public |
|
| 988 | - * @return int |
|
| 989 | - */ |
|
| 990 | - public function _wp_user_id() |
|
| 991 | - { |
|
| 992 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 993 | - $this->_wp_user_id = get_current_user_id(); |
|
| 994 | - return $this->_wp_user_id; |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * Clear EE_Session data |
|
| 1001 | - * |
|
| 1002 | - * @access public |
|
| 1003 | - * @param string $class |
|
| 1004 | - * @param string $function |
|
| 1005 | - * @return void |
|
| 1006 | - * @throws EE_Error |
|
| 1007 | - * @throws InvalidArgumentException |
|
| 1008 | - * @throws InvalidDataTypeException |
|
| 1009 | - * @throws InvalidInterfaceException |
|
| 1010 | - */ |
|
| 1011 | - public function clear_session($class = '', $function = '') |
|
| 1012 | - { |
|
| 396 | + /** |
|
| 397 | + * @param \EE_Cart $cart |
|
| 398 | + * @return bool |
|
| 399 | + */ |
|
| 400 | + public function set_cart(EE_Cart $cart) |
|
| 401 | + { |
|
| 402 | + $this->_session_data['cart'] = $cart; |
|
| 403 | + return true; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * reset_cart |
|
| 410 | + */ |
|
| 411 | + public function reset_cart() |
|
| 412 | + { |
|
| 413 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 414 | + $this->_session_data['cart'] = null; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * @return \EE_Cart |
|
| 421 | + */ |
|
| 422 | + public function cart() |
|
| 423 | + { |
|
| 424 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 425 | + ? $this->_session_data['cart'] |
|
| 426 | + : null; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @param \EE_Checkout $checkout |
|
| 433 | + * @return bool |
|
| 434 | + */ |
|
| 435 | + public function set_checkout(EE_Checkout $checkout) |
|
| 436 | + { |
|
| 437 | + $this->_session_data['checkout'] = $checkout; |
|
| 438 | + return true; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * reset_checkout |
|
| 445 | + */ |
|
| 446 | + public function reset_checkout() |
|
| 447 | + { |
|
| 448 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 449 | + $this->_session_data['checkout'] = null; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @return \EE_Checkout |
|
| 456 | + */ |
|
| 457 | + public function checkout() |
|
| 458 | + { |
|
| 459 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 460 | + ? $this->_session_data['checkout'] |
|
| 461 | + : null; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @param \EE_Transaction $transaction |
|
| 468 | + * @return bool |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public function set_transaction(EE_Transaction $transaction) |
|
| 472 | + { |
|
| 473 | + // first remove the session from the transaction before we save the transaction in the session |
|
| 474 | + $transaction->set_txn_session_data(null); |
|
| 475 | + $this->_session_data['transaction'] = $transaction; |
|
| 476 | + return true; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * reset_transaction |
|
| 483 | + */ |
|
| 484 | + public function reset_transaction() |
|
| 485 | + { |
|
| 486 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 487 | + $this->_session_data['transaction'] = null; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @return \EE_Transaction |
|
| 494 | + */ |
|
| 495 | + public function transaction() |
|
| 496 | + { |
|
| 497 | + return isset($this->_session_data['transaction']) |
|
| 498 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 499 | + ? $this->_session_data['transaction'] |
|
| 500 | + : null; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * retrieve session data |
|
| 506 | + * |
|
| 507 | + * @param null $key |
|
| 508 | + * @param bool $reset_cache |
|
| 509 | + * @return array |
|
| 510 | + */ |
|
| 511 | + public function get_session_data($key = null, $reset_cache = false) |
|
| 512 | + { |
|
| 513 | + if ($reset_cache) { |
|
| 514 | + $this->reset_cart(); |
|
| 515 | + $this->reset_checkout(); |
|
| 516 | + $this->reset_transaction(); |
|
| 517 | + } |
|
| 518 | + if (! empty($key)) { |
|
| 519 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 520 | + } |
|
| 521 | + return $this->_session_data; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Returns TRUE on success, FALSE on fail |
|
| 527 | + * |
|
| 528 | + * @param array $data |
|
| 529 | + * @return bool |
|
| 530 | + */ |
|
| 531 | + public function set_session_data($data) |
|
| 532 | + { |
|
| 533 | + // nothing ??? bad data ??? go home! |
|
| 534 | + if (empty($data) || ! is_array($data)) { |
|
| 535 | + EE_Error::add_error( |
|
| 536 | + esc_html__( |
|
| 537 | + 'No session data or invalid session data was provided.', |
|
| 538 | + 'event_espresso' |
|
| 539 | + ), |
|
| 540 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 541 | + ); |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 544 | + foreach ($data as $key => $value) { |
|
| 545 | + if (isset($this->_default_session_vars[ $key ])) { |
|
| 546 | + EE_Error::add_error( |
|
| 547 | + sprintf( |
|
| 548 | + esc_html__( |
|
| 549 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
| 550 | + 'event_espresso' |
|
| 551 | + ), |
|
| 552 | + $key |
|
| 553 | + ), |
|
| 554 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 555 | + ); |
|
| 556 | + return false; |
|
| 557 | + } |
|
| 558 | + $this->_session_data[ $key ] = $value; |
|
| 559 | + } |
|
| 560 | + return true; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @initiate session |
|
| 567 | + * @access private |
|
| 568 | + * @return TRUE on success, FALSE on fail |
|
| 569 | + * @throws EE_Error |
|
| 570 | + * @throws InvalidArgumentException |
|
| 571 | + * @throws InvalidDataTypeException |
|
| 572 | + * @throws InvalidInterfaceException |
|
| 573 | + * @throws InvalidSessionDataException |
|
| 574 | + */ |
|
| 575 | + private function _espresso_session() |
|
| 576 | + { |
|
| 577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 578 | + // check that session has started |
|
| 579 | + if (session_id() === '') { |
|
| 580 | + //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 581 | + session_start(); |
|
| 582 | + } |
|
| 583 | + $this->status = EE_Session::STATUS_OPEN; |
|
| 584 | + // get our modified session ID |
|
| 585 | + $this->_sid = $this->_generate_session_id(); |
|
| 586 | + // and the visitors IP |
|
| 587 | + $this->_ip_address = $this->request->ipAddress(); |
|
| 588 | + // set the "user agent" |
|
| 589 | + $this->_user_agent = $this->request->userAgent(); |
|
| 590 | + // now let's retrieve what's in the db |
|
| 591 | + $session_data = $this->_retrieve_session_data(); |
|
| 592 | + if (! empty($session_data)) { |
|
| 593 | + // get the current time in UTC |
|
| 594 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 595 | + // and reset the session expiration |
|
| 596 | + $this->_expiration = isset($session_data['expiration']) |
|
| 597 | + ? $session_data['expiration'] |
|
| 598 | + : $this->_time + $this->session_lifespan->inSeconds(); |
|
| 599 | + } else { |
|
| 600 | + // set initial site access time and the session expiration |
|
| 601 | + $this->_set_init_access_and_expiration(); |
|
| 602 | + // set referer |
|
| 603 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 604 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 605 | + : ''; |
|
| 606 | + // no previous session = go back and create one (on top of the data above) |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + // now the user agent |
|
| 610 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 611 | + return false; |
|
| 612 | + } |
|
| 613 | + // wait a minute... how old are you? |
|
| 614 | + if ($this->_time > $this->_expiration) { |
|
| 615 | + // yer too old fer me! |
|
| 616 | + $this->_expired = true; |
|
| 617 | + // wipe out everything that isn't a default session datum |
|
| 618 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 619 | + } |
|
| 620 | + // make event espresso session data available to plugin |
|
| 621 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * _get_session_data |
|
| 629 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 630 | + * databases |
|
| 631 | + * |
|
| 632 | + * @return array |
|
| 633 | + * @throws EE_Error |
|
| 634 | + * @throws InvalidArgumentException |
|
| 635 | + * @throws InvalidSessionDataException |
|
| 636 | + * @throws InvalidDataTypeException |
|
| 637 | + * @throws InvalidInterfaceException |
|
| 638 | + */ |
|
| 639 | + protected function _retrieve_session_data() |
|
| 640 | + { |
|
| 641 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 642 | + try { |
|
| 643 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 644 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 645 | + if (empty($session_data)) { |
|
| 646 | + return array(); |
|
| 647 | + } |
|
| 648 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 649 | + $hash_check = $this->cache_storage->get( |
|
| 650 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 651 | + false |
|
| 652 | + ); |
|
| 653 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 654 | + EE_Error::add_error( |
|
| 655 | + sprintf( |
|
| 656 | + __( |
|
| 657 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 658 | + 'event_espresso' |
|
| 659 | + ), |
|
| 660 | + EE_Session::session_id_prefix . $this->_sid |
|
| 661 | + ), |
|
| 662 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } catch (Exception $e) { |
|
| 667 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
| 668 | + global $wpdb; |
|
| 669 | + $row = $wpdb->get_row( |
|
| 670 | + $wpdb->prepare( |
|
| 671 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 672 | + '_transient_' . $ssn_key |
|
| 673 | + ) |
|
| 674 | + ); |
|
| 675 | + $session_data = is_object($row) ? $row->option_value : null; |
|
| 676 | + if ($session_data) { |
|
| 677 | + $session_data = preg_replace_callback( |
|
| 678 | + '!s:(d+):"(.*?)";!', |
|
| 679 | + function ($match) |
|
| 680 | + { |
|
| 681 | + return $match[1] === strlen($match[2]) |
|
| 682 | + ? $match[0] |
|
| 683 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 684 | + }, |
|
| 685 | + $session_data |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + $session_data = maybe_unserialize($session_data); |
|
| 689 | + } |
|
| 690 | + // in case the data is encoded... try to decode it |
|
| 691 | + $session_data = $this->encryption instanceof EE_Encryption |
|
| 692 | + ? $this->encryption->base64_string_decode($session_data) |
|
| 693 | + : $session_data; |
|
| 694 | + if (! is_array($session_data)) { |
|
| 695 | + try { |
|
| 696 | + $session_data = maybe_unserialize($session_data); |
|
| 697 | + } catch (Exception $e) { |
|
| 698 | + $msg = esc_html__( |
|
| 699 | + 'An error occurred while attempting to unserialize the session data.', |
|
| 700 | + 'event_espresso' |
|
| 701 | + ); |
|
| 702 | + $msg .= WP_DEBUG |
|
| 703 | + ? '<br><pre>' |
|
| 704 | + . print_r($session_data, true) |
|
| 705 | + . '</pre><br>' |
|
| 706 | + . $this->find_serialize_error($session_data) |
|
| 707 | + : ''; |
|
| 708 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 709 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | + // just a check to make sure the session array is indeed an array |
|
| 713 | + if (! is_array($session_data)) { |
|
| 714 | + // no?!?! then something is wrong |
|
| 715 | + $msg = esc_html__( |
|
| 716 | + 'The session data is missing, invalid, or corrupted.', |
|
| 717 | + 'event_espresso' |
|
| 718 | + ); |
|
| 719 | + $msg .= WP_DEBUG |
|
| 720 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 721 | + : ''; |
|
| 722 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 723 | + throw new InvalidSessionDataException($msg); |
|
| 724 | + } |
|
| 725 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 726 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 727 | + $session_data['transaction'] |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + return $session_data; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * _generate_session_id |
|
| 737 | + * Retrieves the PHP session id either directly from the PHP session, |
|
| 738 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 739 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
| 740 | + * so that it can be safely used as a $_REQUEST param |
|
| 741 | + * |
|
| 742 | + * @return string |
|
| 743 | + */ |
|
| 744 | + protected function _generate_session_id() |
|
| 745 | + { |
|
| 746 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 747 | + if (isset($_REQUEST['EESID'])) { |
|
| 748 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 749 | + } else { |
|
| 750 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 751 | + } |
|
| 752 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * _get_sid_salt |
|
| 759 | + * |
|
| 760 | + * @return string |
|
| 761 | + */ |
|
| 762 | + protected function _get_sid_salt() |
|
| 763 | + { |
|
| 764 | + // was session id salt already saved to db ? |
|
| 765 | + if (empty($this->_sid_salt)) { |
|
| 766 | + // no? then maybe use WP defined constant |
|
| 767 | + if (defined('AUTH_SALT')) { |
|
| 768 | + $this->_sid_salt = AUTH_SALT; |
|
| 769 | + } |
|
| 770 | + // if salt doesn't exist or is too short |
|
| 771 | + if (strlen($this->_sid_salt) < 32) { |
|
| 772 | + // create a new one |
|
| 773 | + $this->_sid_salt = wp_generate_password(64); |
|
| 774 | + } |
|
| 775 | + // and save it as a permanent session setting |
|
| 776 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 777 | + } |
|
| 778 | + return $this->_sid_salt; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * _set_init_access_and_expiration |
|
| 785 | + * |
|
| 786 | + * @return void |
|
| 787 | + */ |
|
| 788 | + protected function _set_init_access_and_expiration() |
|
| 789 | + { |
|
| 790 | + $this->_time = time(); |
|
| 791 | + $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
| 792 | + // set initial site access time |
|
| 793 | + $this->_session_data['init_access'] = $this->_time; |
|
| 794 | + // and the session expiration |
|
| 795 | + $this->_session_data['expiration'] = $this->_expiration; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * @update session data prior to saving to the db |
|
| 802 | + * @access public |
|
| 803 | + * @param bool $new_session |
|
| 804 | + * @return TRUE on success, FALSE on fail |
|
| 805 | + * @throws EE_Error |
|
| 806 | + * @throws InvalidArgumentException |
|
| 807 | + * @throws InvalidDataTypeException |
|
| 808 | + * @throws InvalidInterfaceException |
|
| 809 | + */ |
|
| 810 | + public function update($new_session = false) |
|
| 811 | + { |
|
| 812 | + $this->_session_data = $this->_session_data !== null |
|
| 813 | + && is_array($this->_session_data) |
|
| 814 | + && isset($this->_session_data['id']) |
|
| 815 | + ? $this->_session_data |
|
| 816 | + : array(); |
|
| 817 | + if (empty($this->_session_data)) { |
|
| 818 | + $this->_set_defaults(); |
|
| 819 | + } |
|
| 820 | + $session_data = array(); |
|
| 821 | + foreach ($this->_session_data as $key => $value) { |
|
| 822 | + |
|
| 823 | + switch ($key) { |
|
| 824 | + |
|
| 825 | + case 'id' : |
|
| 826 | + // session ID |
|
| 827 | + $session_data['id'] = $this->_sid; |
|
| 828 | + break; |
|
| 829 | + case 'ip_address' : |
|
| 830 | + // visitor ip address |
|
| 831 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 832 | + break; |
|
| 833 | + case 'user_agent' : |
|
| 834 | + // visitor user_agent |
|
| 835 | + $session_data['user_agent'] = $this->_user_agent; |
|
| 836 | + break; |
|
| 837 | + case 'init_access' : |
|
| 838 | + $session_data['init_access'] = absint($value); |
|
| 839 | + break; |
|
| 840 | + case 'last_access' : |
|
| 841 | + // current access time |
|
| 842 | + $session_data['last_access'] = $this->_time; |
|
| 843 | + break; |
|
| 844 | + case 'expiration' : |
|
| 845 | + // when the session expires |
|
| 846 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
| 847 | + ? $this->_expiration |
|
| 848 | + : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
| 849 | + break; |
|
| 850 | + case 'user_id' : |
|
| 851 | + // current user if logged in |
|
| 852 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
| 853 | + break; |
|
| 854 | + case 'pages_visited' : |
|
| 855 | + $page_visit = $this->_get_page_visit(); |
|
| 856 | + if ($page_visit) { |
|
| 857 | + // set pages visited where the first will be the http referrer |
|
| 858 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 859 | + // we'll only save the last 10 page visits. |
|
| 860 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 861 | + } |
|
| 862 | + break; |
|
| 863 | + default : |
|
| 864 | + // carry any other data over |
|
| 865 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + $this->_session_data = $session_data; |
|
| 869 | + // creating a new session does not require saving to the db just yet |
|
| 870 | + if (! $new_session) { |
|
| 871 | + // ready? let's save |
|
| 872 | + if ($this->_save_session_to_db()) { |
|
| 873 | + return true; |
|
| 874 | + } |
|
| 875 | + return false; |
|
| 876 | + } |
|
| 877 | + // meh, why not? |
|
| 878 | + return true; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * @create session data array |
|
| 885 | + * @access public |
|
| 886 | + * @return bool |
|
| 887 | + * @throws EE_Error |
|
| 888 | + * @throws InvalidArgumentException |
|
| 889 | + * @throws InvalidDataTypeException |
|
| 890 | + * @throws InvalidInterfaceException |
|
| 891 | + */ |
|
| 892 | + private function _create_espresso_session() |
|
| 893 | + { |
|
| 894 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 895 | + // use the update function for now with $new_session arg set to TRUE |
|
| 896 | + return $this->update(true) ? true : false; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * _save_session_to_db |
|
| 903 | + * |
|
| 904 | + * @param bool $clear_session |
|
| 905 | + * @return string |
|
| 906 | + * @throws EE_Error |
|
| 907 | + * @throws InvalidArgumentException |
|
| 908 | + * @throws InvalidDataTypeException |
|
| 909 | + * @throws InvalidInterfaceException |
|
| 910 | + */ |
|
| 911 | + private function _save_session_to_db($clear_session = false) |
|
| 912 | + { |
|
| 913 | + // don't save sessions for crawlers |
|
| 914 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 915 | + if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 916 | + return false; |
|
| 917 | + } |
|
| 918 | + $transaction = $this->transaction(); |
|
| 919 | + if ($transaction instanceof EE_Transaction) { |
|
| 920 | + if (! $transaction->ID()) { |
|
| 921 | + $transaction->save(); |
|
| 922 | + } |
|
| 923 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
| 924 | + } |
|
| 925 | + // then serialize all of our session data |
|
| 926 | + $session_data = serialize($this->_session_data); |
|
| 927 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 928 | + $session_data = $this->_use_encryption |
|
| 929 | + ? $this->encryption->base64_string_encode($session_data) |
|
| 930 | + : $session_data; |
|
| 931 | + // maybe save hash check |
|
| 932 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 933 | + $this->cache_storage->add( |
|
| 934 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 935 | + md5($session_data), |
|
| 936 | + $this->session_lifespan->inSeconds() |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | + // we're using the Transient API for storing session data, |
|
| 940 | + return $this->cache_storage->add( |
|
| 941 | + EE_Session::session_id_prefix . $this->_sid, |
|
| 942 | + $session_data, |
|
| 943 | + $this->session_lifespan->inSeconds() |
|
| 944 | + ); |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * @get the full page request the visitor is accessing |
|
| 950 | + * @access public |
|
| 951 | + * @return string |
|
| 952 | + */ |
|
| 953 | + public function _get_page_visit() |
|
| 954 | + { |
|
| 955 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 956 | + // check for request url |
|
| 957 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 958 | + $http_host = ''; |
|
| 959 | + $page_id = '?'; |
|
| 960 | + $e_reg = ''; |
|
| 961 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 962 | + $ru_bits = explode('?', $request_uri); |
|
| 963 | + $request_uri = $ru_bits[0]; |
|
| 964 | + // check for and grab host as well |
|
| 965 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
| 966 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 967 | + } |
|
| 968 | + // check for page_id in SERVER REQUEST |
|
| 969 | + if (isset($_REQUEST['page_id'])) { |
|
| 970 | + // rebuild $e_reg without any of the extra parameters |
|
| 971 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 972 | + } |
|
| 973 | + // check for $e_reg in SERVER REQUEST |
|
| 974 | + if (isset($_REQUEST['ee'])) { |
|
| 975 | + // rebuild $e_reg without any of the extra parameters |
|
| 976 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 977 | + } |
|
| 978 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 979 | + } |
|
| 980 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * @the current wp user id |
|
| 987 | + * @access public |
|
| 988 | + * @return int |
|
| 989 | + */ |
|
| 990 | + public function _wp_user_id() |
|
| 991 | + { |
|
| 992 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 993 | + $this->_wp_user_id = get_current_user_id(); |
|
| 994 | + return $this->_wp_user_id; |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * Clear EE_Session data |
|
| 1001 | + * |
|
| 1002 | + * @access public |
|
| 1003 | + * @param string $class |
|
| 1004 | + * @param string $function |
|
| 1005 | + * @return void |
|
| 1006 | + * @throws EE_Error |
|
| 1007 | + * @throws InvalidArgumentException |
|
| 1008 | + * @throws InvalidDataTypeException |
|
| 1009 | + * @throws InvalidInterfaceException |
|
| 1010 | + */ |
|
| 1011 | + public function clear_session($class = '', $function = '') |
|
| 1012 | + { |
|
| 1013 | 1013 | // echo ' |
| 1014 | 1014 | // <h3 style="color:#999;line-height:.9em;"> |
| 1015 | 1015 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
| 1016 | 1016 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
| 1017 | 1017 | // </h3>'; |
| 1018 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1019 | - $this->reset_cart(); |
|
| 1020 | - $this->reset_checkout(); |
|
| 1021 | - $this->reset_transaction(); |
|
| 1022 | - // wipe out everything that isn't a default session datum |
|
| 1023 | - $this->reset_data(array_keys($this->_session_data)); |
|
| 1024 | - // reset initial site access time and the session expiration |
|
| 1025 | - $this->_set_init_access_and_expiration(); |
|
| 1026 | - $this->_save_session_to_db(true); |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1032 | - * |
|
| 1033 | - * @param array|mixed $data_to_reset |
|
| 1034 | - * @param bool $show_all_notices |
|
| 1035 | - * @return bool |
|
| 1036 | - */ |
|
| 1037 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1038 | - { |
|
| 1039 | - // if $data_to_reset is not in an array, then put it in one |
|
| 1040 | - if (! is_array($data_to_reset)) { |
|
| 1041 | - $data_to_reset = array($data_to_reset); |
|
| 1042 | - } |
|
| 1043 | - // nothing ??? go home! |
|
| 1044 | - if (empty($data_to_reset)) { |
|
| 1045 | - EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1046 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1047 | - return false; |
|
| 1048 | - } |
|
| 1049 | - $return_value = true; |
|
| 1050 | - // since $data_to_reset is an array, cycle through the values |
|
| 1051 | - foreach ($data_to_reset as $reset) { |
|
| 1052 | - |
|
| 1053 | - // first check to make sure it is a valid session var |
|
| 1054 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1055 | - // then check to make sure it is not a default var |
|
| 1056 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1057 | - // remove session var |
|
| 1058 | - unset($this->_session_data[ $reset ]); |
|
| 1059 | - if ($show_all_notices) { |
|
| 1060 | - EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1061 | - $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1062 | - } |
|
| 1063 | - } else { |
|
| 1064 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1065 | - if ($show_all_notices) { |
|
| 1066 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1067 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1068 | - } |
|
| 1069 | - $return_value = false; |
|
| 1070 | - } |
|
| 1071 | - } elseif ($show_all_notices) { |
|
| 1072 | - // oops! that session var does not exist! |
|
| 1073 | - EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1074 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1075 | - $return_value = false; |
|
| 1076 | - } |
|
| 1077 | - } // end of foreach |
|
| 1078 | - return $return_value; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * wp_loaded |
|
| 1085 | - * |
|
| 1086 | - * @access public |
|
| 1087 | - * @throws EE_Error |
|
| 1088 | - * @throws InvalidDataTypeException |
|
| 1089 | - * @throws InvalidInterfaceException |
|
| 1090 | - * @throws InvalidArgumentException |
|
| 1091 | - */ |
|
| 1092 | - public function wp_loaded() |
|
| 1093 | - { |
|
| 1094 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1095 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1096 | - } |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * Used to reset the entire object (for tests). |
|
| 1103 | - * |
|
| 1104 | - * @since 4.3.0 |
|
| 1105 | - * @throws EE_Error |
|
| 1106 | - * @throws InvalidDataTypeException |
|
| 1107 | - * @throws InvalidInterfaceException |
|
| 1108 | - * @throws InvalidArgumentException |
|
| 1109 | - */ |
|
| 1110 | - public function reset_instance() |
|
| 1111 | - { |
|
| 1112 | - $this->clear_session(); |
|
| 1113 | - self::$_instance = null; |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - public function configure_garbage_collection_filters() |
|
| 1119 | - { |
|
| 1120 | - // run old filter we had for controlling session cleanup |
|
| 1121 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1122 | - apply_filters( |
|
| 1123 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1124 | - 50 |
|
| 1125 | - ) |
|
| 1126 | - ); |
|
| 1127 | - // is there a value? or one that is different than the default 50 records? |
|
| 1128 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1129 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1130 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1131 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1132 | - // or use that for the new transient cleanup query limit |
|
| 1133 | - add_filter( |
|
| 1134 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1135 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1136 | - { |
|
| 1137 | - return $expired_session_transient_delete_query_limit; |
|
| 1138 | - } |
|
| 1139 | - ); |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - /** |
|
| 1146 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1147 | - * @param $data1 |
|
| 1148 | - * @return string |
|
| 1149 | - */ |
|
| 1150 | - private function find_serialize_error($data1) |
|
| 1151 | - { |
|
| 1152 | - $error = '<pre>'; |
|
| 1153 | - $data2 = preg_replace_callback( |
|
| 1154 | - '!s:(\d+):"(.*?)";!', |
|
| 1155 | - function ($match) |
|
| 1156 | - { |
|
| 1157 | - return ($match[1] === strlen($match[2])) |
|
| 1158 | - ? $match[0] |
|
| 1159 | - : 's:' |
|
| 1160 | - . strlen($match[2]) |
|
| 1161 | - . ':"' |
|
| 1162 | - . $match[2] |
|
| 1163 | - . '";'; |
|
| 1164 | - }, |
|
| 1165 | - $data1 |
|
| 1166 | - ); |
|
| 1167 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1168 | - $error .= $data1 . PHP_EOL; |
|
| 1169 | - $error .= $data2 . PHP_EOL; |
|
| 1170 | - for ($i = 0; $i < $max; $i++) { |
|
| 1171 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1172 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1173 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1174 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1175 | - $start = ($i - 20); |
|
| 1176 | - $start = ($start < 0) ? 0 : $start; |
|
| 1177 | - $length = 40; |
|
| 1178 | - $point = $max - $i; |
|
| 1179 | - if ($point < 20) { |
|
| 1180 | - $rlength = 1; |
|
| 1181 | - $rpoint = -$point; |
|
| 1182 | - } else { |
|
| 1183 | - $rpoint = $length - 20; |
|
| 1184 | - $rlength = 1; |
|
| 1185 | - } |
|
| 1186 | - $error .= "\t-> Section Data1 = "; |
|
| 1187 | - $error .= substr_replace( |
|
| 1188 | - substr($data1, $start, $length), |
|
| 1189 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1190 | - $rpoint, |
|
| 1191 | - $rlength |
|
| 1192 | - ); |
|
| 1193 | - $error .= PHP_EOL; |
|
| 1194 | - $error .= "\t-> Section Data2 = "; |
|
| 1195 | - $error .= substr_replace( |
|
| 1196 | - substr($data2, $start, $length), |
|
| 1197 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1198 | - $rpoint, |
|
| 1199 | - $rlength |
|
| 1200 | - ); |
|
| 1201 | - $error .= PHP_EOL; |
|
| 1202 | - } |
|
| 1203 | - } |
|
| 1204 | - $error .= '</pre>'; |
|
| 1205 | - return $error; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - |
|
| 1209 | - /** |
|
| 1210 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1211 | - * |
|
| 1212 | - * @param array $updated_settings |
|
| 1213 | - */ |
|
| 1214 | - private function updateSessionSettings(array $updated_settings = array()) |
|
| 1215 | - { |
|
| 1216 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1217 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1218 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * garbage_collection |
|
| 1224 | - */ |
|
| 1225 | - public function garbageCollection() |
|
| 1226 | - { |
|
| 1227 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1228 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1229 | - $this->_last_gc = time(); |
|
| 1230 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1231 | - /** @type WPDB $wpdb */ |
|
| 1232 | - global $wpdb; |
|
| 1233 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1234 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1235 | - apply_filters( |
|
| 1236 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1237 | - 50 |
|
| 1238 | - ) |
|
| 1239 | - ); |
|
| 1240 | - // non-zero LIMIT means take out the trash |
|
| 1241 | - if ($expired_session_transient_delete_query_limit) { |
|
| 1242 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1243 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1244 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1245 | - // but we only want to pick up any trash that's been around for more than a day |
|
| 1246 | - $expiration = time() - DAY_IN_SECONDS; |
|
| 1247 | - $SQL = " |
|
| 1018 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1019 | + $this->reset_cart(); |
|
| 1020 | + $this->reset_checkout(); |
|
| 1021 | + $this->reset_transaction(); |
|
| 1022 | + // wipe out everything that isn't a default session datum |
|
| 1023 | + $this->reset_data(array_keys($this->_session_data)); |
|
| 1024 | + // reset initial site access time and the session expiration |
|
| 1025 | + $this->_set_init_access_and_expiration(); |
|
| 1026 | + $this->_save_session_to_db(true); |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1032 | + * |
|
| 1033 | + * @param array|mixed $data_to_reset |
|
| 1034 | + * @param bool $show_all_notices |
|
| 1035 | + * @return bool |
|
| 1036 | + */ |
|
| 1037 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1038 | + { |
|
| 1039 | + // if $data_to_reset is not in an array, then put it in one |
|
| 1040 | + if (! is_array($data_to_reset)) { |
|
| 1041 | + $data_to_reset = array($data_to_reset); |
|
| 1042 | + } |
|
| 1043 | + // nothing ??? go home! |
|
| 1044 | + if (empty($data_to_reset)) { |
|
| 1045 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1046 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1047 | + return false; |
|
| 1048 | + } |
|
| 1049 | + $return_value = true; |
|
| 1050 | + // since $data_to_reset is an array, cycle through the values |
|
| 1051 | + foreach ($data_to_reset as $reset) { |
|
| 1052 | + |
|
| 1053 | + // first check to make sure it is a valid session var |
|
| 1054 | + if (isset($this->_session_data[ $reset ])) { |
|
| 1055 | + // then check to make sure it is not a default var |
|
| 1056 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1057 | + // remove session var |
|
| 1058 | + unset($this->_session_data[ $reset ]); |
|
| 1059 | + if ($show_all_notices) { |
|
| 1060 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1061 | + $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1062 | + } |
|
| 1063 | + } else { |
|
| 1064 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1065 | + if ($show_all_notices) { |
|
| 1066 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1067 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1068 | + } |
|
| 1069 | + $return_value = false; |
|
| 1070 | + } |
|
| 1071 | + } elseif ($show_all_notices) { |
|
| 1072 | + // oops! that session var does not exist! |
|
| 1073 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1074 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1075 | + $return_value = false; |
|
| 1076 | + } |
|
| 1077 | + } // end of foreach |
|
| 1078 | + return $return_value; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * wp_loaded |
|
| 1085 | + * |
|
| 1086 | + * @access public |
|
| 1087 | + * @throws EE_Error |
|
| 1088 | + * @throws InvalidDataTypeException |
|
| 1089 | + * @throws InvalidInterfaceException |
|
| 1090 | + * @throws InvalidArgumentException |
|
| 1091 | + */ |
|
| 1092 | + public function wp_loaded() |
|
| 1093 | + { |
|
| 1094 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1095 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1096 | + } |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * Used to reset the entire object (for tests). |
|
| 1103 | + * |
|
| 1104 | + * @since 4.3.0 |
|
| 1105 | + * @throws EE_Error |
|
| 1106 | + * @throws InvalidDataTypeException |
|
| 1107 | + * @throws InvalidInterfaceException |
|
| 1108 | + * @throws InvalidArgumentException |
|
| 1109 | + */ |
|
| 1110 | + public function reset_instance() |
|
| 1111 | + { |
|
| 1112 | + $this->clear_session(); |
|
| 1113 | + self::$_instance = null; |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + public function configure_garbage_collection_filters() |
|
| 1119 | + { |
|
| 1120 | + // run old filter we had for controlling session cleanup |
|
| 1121 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1122 | + apply_filters( |
|
| 1123 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1124 | + 50 |
|
| 1125 | + ) |
|
| 1126 | + ); |
|
| 1127 | + // is there a value? or one that is different than the default 50 records? |
|
| 1128 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1129 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1130 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1131 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1132 | + // or use that for the new transient cleanup query limit |
|
| 1133 | + add_filter( |
|
| 1134 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1135 | + function () use ($expired_session_transient_delete_query_limit) |
|
| 1136 | + { |
|
| 1137 | + return $expired_session_transient_delete_query_limit; |
|
| 1138 | + } |
|
| 1139 | + ); |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + /** |
|
| 1146 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1147 | + * @param $data1 |
|
| 1148 | + * @return string |
|
| 1149 | + */ |
|
| 1150 | + private function find_serialize_error($data1) |
|
| 1151 | + { |
|
| 1152 | + $error = '<pre>'; |
|
| 1153 | + $data2 = preg_replace_callback( |
|
| 1154 | + '!s:(\d+):"(.*?)";!', |
|
| 1155 | + function ($match) |
|
| 1156 | + { |
|
| 1157 | + return ($match[1] === strlen($match[2])) |
|
| 1158 | + ? $match[0] |
|
| 1159 | + : 's:' |
|
| 1160 | + . strlen($match[2]) |
|
| 1161 | + . ':"' |
|
| 1162 | + . $match[2] |
|
| 1163 | + . '";'; |
|
| 1164 | + }, |
|
| 1165 | + $data1 |
|
| 1166 | + ); |
|
| 1167 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1168 | + $error .= $data1 . PHP_EOL; |
|
| 1169 | + $error .= $data2 . PHP_EOL; |
|
| 1170 | + for ($i = 0; $i < $max; $i++) { |
|
| 1171 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1172 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1173 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1174 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1175 | + $start = ($i - 20); |
|
| 1176 | + $start = ($start < 0) ? 0 : $start; |
|
| 1177 | + $length = 40; |
|
| 1178 | + $point = $max - $i; |
|
| 1179 | + if ($point < 20) { |
|
| 1180 | + $rlength = 1; |
|
| 1181 | + $rpoint = -$point; |
|
| 1182 | + } else { |
|
| 1183 | + $rpoint = $length - 20; |
|
| 1184 | + $rlength = 1; |
|
| 1185 | + } |
|
| 1186 | + $error .= "\t-> Section Data1 = "; |
|
| 1187 | + $error .= substr_replace( |
|
| 1188 | + substr($data1, $start, $length), |
|
| 1189 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1190 | + $rpoint, |
|
| 1191 | + $rlength |
|
| 1192 | + ); |
|
| 1193 | + $error .= PHP_EOL; |
|
| 1194 | + $error .= "\t-> Section Data2 = "; |
|
| 1195 | + $error .= substr_replace( |
|
| 1196 | + substr($data2, $start, $length), |
|
| 1197 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1198 | + $rpoint, |
|
| 1199 | + $rlength |
|
| 1200 | + ); |
|
| 1201 | + $error .= PHP_EOL; |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + $error .= '</pre>'; |
|
| 1205 | + return $error; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1211 | + * |
|
| 1212 | + * @param array $updated_settings |
|
| 1213 | + */ |
|
| 1214 | + private function updateSessionSettings(array $updated_settings = array()) |
|
| 1215 | + { |
|
| 1216 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1217 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1218 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * garbage_collection |
|
| 1224 | + */ |
|
| 1225 | + public function garbageCollection() |
|
| 1226 | + { |
|
| 1227 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1228 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1229 | + $this->_last_gc = time(); |
|
| 1230 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1231 | + /** @type WPDB $wpdb */ |
|
| 1232 | + global $wpdb; |
|
| 1233 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1234 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1235 | + apply_filters( |
|
| 1236 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1237 | + 50 |
|
| 1238 | + ) |
|
| 1239 | + ); |
|
| 1240 | + // non-zero LIMIT means take out the trash |
|
| 1241 | + if ($expired_session_transient_delete_query_limit) { |
|
| 1242 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1243 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1244 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1245 | + // but we only want to pick up any trash that's been around for more than a day |
|
| 1246 | + $expiration = time() - DAY_IN_SECONDS; |
|
| 1247 | + $SQL = " |
|
| 1248 | 1248 | SELECT option_name |
| 1249 | 1249 | FROM {$wpdb->options} |
| 1250 | 1250 | WHERE |
@@ -1253,19 +1253,19 @@ discard block |
||
| 1253 | 1253 | AND option_value < {$expiration} |
| 1254 | 1254 | LIMIT {$expired_session_transient_delete_query_limit} |
| 1255 | 1255 | "; |
| 1256 | - // produces something like: |
|
| 1257 | - // SELECT option_name FROM wp_options |
|
| 1258 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1259 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1260 | - // AND option_value < 1508368198 LIMIT 50 |
|
| 1261 | - $expired_sessions = $wpdb->get_col($SQL); |
|
| 1262 | - // valid results? |
|
| 1263 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1264 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1256 | + // produces something like: |
|
| 1257 | + // SELECT option_name FROM wp_options |
|
| 1258 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1259 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1260 | + // AND option_value < 1508368198 LIMIT 50 |
|
| 1261 | + $expired_sessions = $wpdb->get_col($SQL); |
|
| 1262 | + // valid results? |
|
| 1263 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1264 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | 1269 | |
| 1270 | 1270 | |
| 1271 | 1271 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | // check if class object is instantiated |
| 187 | 187 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
| 188 | 188 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 189 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 190 | 190 | self::$_instance = new self( |
| 191 | 191 | $cache_storage, |
| 192 | 192 | $lifespan, |
@@ -219,21 +219,21 @@ discard block |
||
| 219 | 219 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
| 220 | 220 | // (which currently fires on the init hook at priority 9), |
| 221 | 221 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 222 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 223 | 223 | return; |
| 224 | 224 | } |
| 225 | 225 | $this->session_lifespan = $lifespan; |
| 226 | 226 | $this->request = $request; |
| 227 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 227 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
| 228 | 228 | define('ESPRESSO_SESSION', true); |
| 229 | 229 | } |
| 230 | 230 | // retrieve session options from db |
| 231 | 231 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
| 232 | - if (! empty($session_settings)) { |
|
| 232 | + if ( ! empty($session_settings)) { |
|
| 233 | 233 | // cycle though existing session options |
| 234 | 234 | foreach ($session_settings as $var_name => $session_setting) { |
| 235 | 235 | // set values for class properties |
| 236 | - $var_name = '_' . $var_name; |
|
| 236 | + $var_name = '_'.$var_name; |
|
| 237 | 237 | $this->{$var_name} = $session_setting; |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | public function open_session() |
| 294 | 294 | { |
| 295 | 295 | // check for existing session and retrieve it from db |
| 296 | - if (! $this->_espresso_session()) { |
|
| 296 | + if ( ! $this->_espresso_session()) { |
|
| 297 | 297 | // or just start a new one |
| 298 | 298 | $this->_create_espresso_session(); |
| 299 | 299 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function extend_expiration($time = 0) |
| 347 | 347 | { |
| 348 | - $time = $time ? $time : $this->extension(); |
|
| 348 | + $time = $time ? $time : $this->extension(); |
|
| 349 | 349 | $this->_expiration += absint($time); |
| 350 | 350 | } |
| 351 | 351 | |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | // set some defaults |
| 373 | 373 | foreach ($this->_default_session_vars as $key => $default_var) { |
| 374 | 374 | if (is_array($default_var)) { |
| 375 | - $this->_session_data[ $key ] = array(); |
|
| 375 | + $this->_session_data[$key] = array(); |
|
| 376 | 376 | } else { |
| 377 | - $this->_session_data[ $key ] = ''; |
|
| 377 | + $this->_session_data[$key] = ''; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
@@ -515,8 +515,8 @@ discard block |
||
| 515 | 515 | $this->reset_checkout(); |
| 516 | 516 | $this->reset_transaction(); |
| 517 | 517 | } |
| 518 | - if (! empty($key)) { |
|
| 519 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 518 | + if ( ! empty($key)) { |
|
| 519 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
| 520 | 520 | } |
| 521 | 521 | return $this->_session_data; |
| 522 | 522 | } |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | return false; |
| 543 | 543 | } |
| 544 | 544 | foreach ($data as $key => $value) { |
| 545 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 545 | + if (isset($this->_default_session_vars[$key])) { |
|
| 546 | 546 | EE_Error::add_error( |
| 547 | 547 | sprintf( |
| 548 | 548 | esc_html__( |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | ); |
| 556 | 556 | return false; |
| 557 | 557 | } |
| 558 | - $this->_session_data[ $key ] = $value; |
|
| 558 | + $this->_session_data[$key] = $value; |
|
| 559 | 559 | } |
| 560 | 560 | return true; |
| 561 | 561 | } |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | $this->_user_agent = $this->request->userAgent(); |
| 590 | 590 | // now let's retrieve what's in the db |
| 591 | 591 | $session_data = $this->_retrieve_session_data(); |
| 592 | - if (! empty($session_data)) { |
|
| 592 | + if ( ! empty($session_data)) { |
|
| 593 | 593 | // get the current time in UTC |
| 594 | 594 | $this->_time = $this->_time !== null ? $this->_time : time(); |
| 595 | 595 | // and reset the session expiration |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | // set initial site access time and the session expiration |
| 601 | 601 | $this->_set_init_access_and_expiration(); |
| 602 | 602 | // set referer |
| 603 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 603 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
| 604 | 604 | ? esc_attr($_SERVER['HTTP_REFERER']) |
| 605 | 605 | : ''; |
| 606 | 606 | // no previous session = go back and create one (on top of the data above) |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | */ |
| 639 | 639 | protected function _retrieve_session_data() |
| 640 | 640 | { |
| 641 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 641 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
| 642 | 642 | try { |
| 643 | 643 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
| 644 | 644 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | } |
| 648 | 648 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 649 | 649 | $hash_check = $this->cache_storage->get( |
| 650 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 650 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 651 | 651 | false |
| 652 | 652 | ); |
| 653 | 653 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
| 658 | 658 | 'event_espresso' |
| 659 | 659 | ), |
| 660 | - EE_Session::session_id_prefix . $this->_sid |
|
| 660 | + EE_Session::session_id_prefix.$this->_sid |
|
| 661 | 661 | ), |
| 662 | 662 | __FILE__, __FUNCTION__, __LINE__ |
| 663 | 663 | ); |
@@ -666,21 +666,21 @@ discard block |
||
| 666 | 666 | } catch (Exception $e) { |
| 667 | 667 | // let's just eat that error for now and attempt to correct any corrupted data |
| 668 | 668 | global $wpdb; |
| 669 | - $row = $wpdb->get_row( |
|
| 669 | + $row = $wpdb->get_row( |
|
| 670 | 670 | $wpdb->prepare( |
| 671 | 671 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
| 672 | - '_transient_' . $ssn_key |
|
| 672 | + '_transient_'.$ssn_key |
|
| 673 | 673 | ) |
| 674 | 674 | ); |
| 675 | 675 | $session_data = is_object($row) ? $row->option_value : null; |
| 676 | 676 | if ($session_data) { |
| 677 | 677 | $session_data = preg_replace_callback( |
| 678 | 678 | '!s:(d+):"(.*?)";!', |
| 679 | - function ($match) |
|
| 679 | + function($match) |
|
| 680 | 680 | { |
| 681 | 681 | return $match[1] === strlen($match[2]) |
| 682 | 682 | ? $match[0] |
| 683 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 683 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
| 684 | 684 | }, |
| 685 | 685 | $session_data |
| 686 | 686 | ); |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | $session_data = $this->encryption instanceof EE_Encryption |
| 692 | 692 | ? $this->encryption->base64_string_decode($session_data) |
| 693 | 693 | : $session_data; |
| 694 | - if (! is_array($session_data)) { |
|
| 694 | + if ( ! is_array($session_data)) { |
|
| 695 | 695 | try { |
| 696 | 696 | $session_data = maybe_unserialize($session_data); |
| 697 | 697 | } catch (Exception $e) { |
@@ -705,21 +705,21 @@ discard block |
||
| 705 | 705 | . '</pre><br>' |
| 706 | 706 | . $this->find_serialize_error($session_data) |
| 707 | 707 | : ''; |
| 708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 708 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 709 | 709 | throw new InvalidSessionDataException($msg, 0, $e); |
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | // just a check to make sure the session array is indeed an array |
| 713 | - if (! is_array($session_data)) { |
|
| 713 | + if ( ! is_array($session_data)) { |
|
| 714 | 714 | // no?!?! then something is wrong |
| 715 | 715 | $msg = esc_html__( |
| 716 | 716 | 'The session data is missing, invalid, or corrupted.', |
| 717 | 717 | 'event_espresso' |
| 718 | 718 | ); |
| 719 | 719 | $msg .= WP_DEBUG |
| 720 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 720 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
| 721 | 721 | : ''; |
| 722 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 722 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 723 | 723 | throw new InvalidSessionDataException($msg); |
| 724 | 724 | } |
| 725 | 725 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | if (isset($_REQUEST['EESID'])) { |
| 748 | 748 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
| 749 | 749 | } else { |
| 750 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 750 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
| 751 | 751 | } |
| 752 | 752 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
| 753 | 753 | } |
@@ -855,19 +855,19 @@ discard block |
||
| 855 | 855 | $page_visit = $this->_get_page_visit(); |
| 856 | 856 | if ($page_visit) { |
| 857 | 857 | // set pages visited where the first will be the http referrer |
| 858 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 858 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
| 859 | 859 | // we'll only save the last 10 page visits. |
| 860 | 860 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
| 861 | 861 | } |
| 862 | 862 | break; |
| 863 | 863 | default : |
| 864 | 864 | // carry any other data over |
| 865 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 865 | + $session_data[$key] = $this->_session_data[$key]; |
|
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | $this->_session_data = $session_data; |
| 869 | 869 | // creating a new session does not require saving to the db just yet |
| 870 | - if (! $new_session) { |
|
| 870 | + if ( ! $new_session) { |
|
| 871 | 871 | // ready? let's save |
| 872 | 872 | if ($this->_save_session_to_db()) { |
| 873 | 873 | return true; |
@@ -912,12 +912,12 @@ discard block |
||
| 912 | 912 | { |
| 913 | 913 | // don't save sessions for crawlers |
| 914 | 914 | // and unless we're deleting the session data, don't save anything if there isn't a cart |
| 915 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 915 | + if ($this->request->isBot() || ( ! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 916 | 916 | return false; |
| 917 | 917 | } |
| 918 | 918 | $transaction = $this->transaction(); |
| 919 | 919 | if ($transaction instanceof EE_Transaction) { |
| 920 | - if (! $transaction->ID()) { |
|
| 920 | + if ( ! $transaction->ID()) { |
|
| 921 | 921 | $transaction->save(); |
| 922 | 922 | } |
| 923 | 923 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -931,14 +931,14 @@ discard block |
||
| 931 | 931 | // maybe save hash check |
| 932 | 932 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 933 | 933 | $this->cache_storage->add( |
| 934 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 934 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 935 | 935 | md5($session_data), |
| 936 | 936 | $this->session_lifespan->inSeconds() |
| 937 | 937 | ); |
| 938 | 938 | } |
| 939 | 939 | // we're using the Transient API for storing session data, |
| 940 | 940 | return $this->cache_storage->add( |
| 941 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 941 | + EE_Session::session_id_prefix.$this->_sid, |
|
| 942 | 942 | $session_data, |
| 943 | 943 | $this->session_lifespan->inSeconds() |
| 944 | 944 | ); |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | */ |
| 953 | 953 | public function _get_page_visit() |
| 954 | 954 | { |
| 955 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 955 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
| 956 | 956 | // check for request url |
| 957 | 957 | if (isset($_SERVER['REQUEST_URI'])) { |
| 958 | 958 | $http_host = ''; |
@@ -968,14 +968,14 @@ discard block |
||
| 968 | 968 | // check for page_id in SERVER REQUEST |
| 969 | 969 | if (isset($_REQUEST['page_id'])) { |
| 970 | 970 | // rebuild $e_reg without any of the extra parameters |
| 971 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 971 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
| 972 | 972 | } |
| 973 | 973 | // check for $e_reg in SERVER REQUEST |
| 974 | 974 | if (isset($_REQUEST['ee'])) { |
| 975 | 975 | // rebuild $e_reg without any of the extra parameters |
| 976 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 976 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
| 977 | 977 | } |
| 978 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 978 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
| 979 | 979 | } |
| 980 | 980 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
| 981 | 981 | } |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
| 1016 | 1016 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
| 1017 | 1017 | // </h3>'; |
| 1018 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1018 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
| 1019 | 1019 | $this->reset_cart(); |
| 1020 | 1020 | $this->reset_checkout(); |
| 1021 | 1021 | $this->reset_transaction(); |
@@ -1037,7 +1037,7 @@ discard block |
||
| 1037 | 1037 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
| 1038 | 1038 | { |
| 1039 | 1039 | // if $data_to_reset is not in an array, then put it in one |
| 1040 | - if (! is_array($data_to_reset)) { |
|
| 1040 | + if ( ! is_array($data_to_reset)) { |
|
| 1041 | 1041 | $data_to_reset = array($data_to_reset); |
| 1042 | 1042 | } |
| 1043 | 1043 | // nothing ??? go home! |
@@ -1051,11 +1051,11 @@ discard block |
||
| 1051 | 1051 | foreach ($data_to_reset as $reset) { |
| 1052 | 1052 | |
| 1053 | 1053 | // first check to make sure it is a valid session var |
| 1054 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1054 | + if (isset($this->_session_data[$reset])) { |
|
| 1055 | 1055 | // then check to make sure it is not a default var |
| 1056 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1056 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1057 | 1057 | // remove session var |
| 1058 | - unset($this->_session_data[ $reset ]); |
|
| 1058 | + unset($this->_session_data[$reset]); |
|
| 1059 | 1059 | if ($show_all_notices) { |
| 1060 | 1060 | EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
| 1061 | 1061 | $reset), __FILE__, __FUNCTION__, __LINE__); |
@@ -1132,7 +1132,7 @@ discard block |
||
| 1132 | 1132 | // or use that for the new transient cleanup query limit |
| 1133 | 1133 | add_filter( |
| 1134 | 1134 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
| 1135 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1135 | + function() use ($expired_session_transient_delete_query_limit) |
|
| 1136 | 1136 | { |
| 1137 | 1137 | return $expired_session_transient_delete_query_limit; |
| 1138 | 1138 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
| 1152 | 1152 | $error = '<pre>'; |
| 1153 | 1153 | $data2 = preg_replace_callback( |
| 1154 | 1154 | '!s:(\d+):"(.*?)";!', |
| 1155 | - function ($match) |
|
| 1155 | + function($match) |
|
| 1156 | 1156 | { |
| 1157 | 1157 | return ($match[1] === strlen($match[2])) |
| 1158 | 1158 | ? $match[0] |
@@ -1164,14 +1164,14 @@ discard block |
||
| 1164 | 1164 | }, |
| 1165 | 1165 | $data1 |
| 1166 | 1166 | ); |
| 1167 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1168 | - $error .= $data1 . PHP_EOL; |
|
| 1169 | - $error .= $data2 . PHP_EOL; |
|
| 1167 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1168 | + $error .= $data1.PHP_EOL; |
|
| 1169 | + $error .= $data2.PHP_EOL; |
|
| 1170 | 1170 | for ($i = 0; $i < $max; $i++) { |
| 1171 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1172 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1173 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1174 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1171 | + if (@$data1[$i] !== @$data2[$i]) { |
|
| 1172 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
| 1173 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
| 1174 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
| 1175 | 1175 | $start = ($i - 20); |
| 1176 | 1176 | $start = ($start < 0) ? 0 : $start; |
| 1177 | 1177 | $length = 40; |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | $error .= "\t-> Section Data1 = "; |
| 1187 | 1187 | $error .= substr_replace( |
| 1188 | 1188 | substr($data1, $start, $length), |
| 1189 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1189 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
| 1190 | 1190 | $rpoint, |
| 1191 | 1191 | $rlength |
| 1192 | 1192 | ); |
@@ -1194,7 +1194,7 @@ discard block |
||
| 1194 | 1194 | $error .= "\t-> Section Data2 = "; |
| 1195 | 1195 | $error .= substr_replace( |
| 1196 | 1196 | substr($data2, $start, $length), |
| 1197 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1197 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
| 1198 | 1198 | $rpoint, |
| 1199 | 1199 | $rlength |
| 1200 | 1200 | ); |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | public function garbageCollection() |
| 1226 | 1226 | { |
| 1227 | 1227 | // only perform during regular requests if last garbage collection was over an hour ago |
| 1228 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1228 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1229 | 1229 | $this->_last_gc = time(); |
| 1230 | 1230 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
| 1231 | 1231 | /** @type WPDB $wpdb */ |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | // AND option_value < 1508368198 LIMIT 50 |
| 1261 | 1261 | $expired_sessions = $wpdb->get_col($SQL); |
| 1262 | 1262 | // valid results? |
| 1263 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1263 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1264 | 1264 | $this->cache_storage->deleteMany($expired_sessions, true); |
| 1265 | 1265 | } |
| 1266 | 1266 | } |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class EE_SPCO_JSON_Response |
|
| 5 | - * |
|
| 6 | - * Description |
|
| 7 | - * |
|
| 8 | - * @package Event Espresso |
|
| 9 | - * @subpackage core |
|
| 10 | - * @author Brent Christensen |
|
| 11 | - * |
|
| 12 | - * |
|
| 13 | - */ |
|
| 3 | + * |
|
| 4 | + * Class EE_SPCO_JSON_Response |
|
| 5 | + * |
|
| 6 | + * Description |
|
| 7 | + * |
|
| 8 | + * @package Event Espresso |
|
| 9 | + * @subpackage core |
|
| 10 | + * @author Brent Christensen |
|
| 11 | + * |
|
| 12 | + * |
|
| 13 | + */ |
|
| 14 | 14 | class EE_SPCO_JSON_Response { |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * class constructor |
| 87 | - */ |
|
| 87 | + */ |
|
| 88 | 88 | public function __construct( ) { |
| 89 | 89 | } |
| 90 | 90 | |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * @param float $payment_amount |
|
| 276 | - * @throws EE_Error |
|
| 277 | - */ |
|
| 274 | + /** |
|
| 275 | + * @param float $payment_amount |
|
| 276 | + * @throws EE_Error |
|
| 277 | + */ |
|
| 278 | 278 | public function set_payment_amount( $payment_amount ) { |
| 279 | 279 | $this->_payment_amount = (float)$payment_amount; |
| 280 | 280 | } |
@@ -408,11 +408,11 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - public function echoAndExit() |
|
| 412 | - { |
|
| 413 | - echo $this; |
|
| 414 | - exit(); |
|
| 415 | - } |
|
| 411 | + public function echoAndExit() |
|
| 412 | + { |
|
| 413 | + echo $this; |
|
| 414 | + exit(); |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | 417 | } |
| 418 | 418 | // End of file EE_SPCO_JSON_Response.php |
@@ -104,71 +104,71 @@ discard block |
||
| 104 | 104 | public function __toString() { |
| 105 | 105 | $JSON_response = array(); |
| 106 | 106 | // grab notices |
| 107 | - $notices = EE_Error::get_notices( FALSE ); |
|
| 108 | - $this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' ); |
|
| 109 | - $this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' ); |
|
| 110 | - $this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' ); |
|
| 107 | + $notices = EE_Error::get_notices(FALSE); |
|
| 108 | + $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
| 109 | + $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
| 110 | + $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
| 111 | 111 | // add notices to JSON response, but only if they exist |
| 112 | - if ( $this->attention() ) { |
|
| 112 | + if ($this->attention()) { |
|
| 113 | 113 | $JSON_response['attention'] = $this->attention(); |
| 114 | 114 | } |
| 115 | - if ( $this->errors() ) { |
|
| 115 | + if ($this->errors()) { |
|
| 116 | 116 | $JSON_response['errors'] = $this->errors(); |
| 117 | 117 | } |
| 118 | - if ( $this->unexpected_errors() ) { |
|
| 118 | + if ($this->unexpected_errors()) { |
|
| 119 | 119 | $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
| 120 | 120 | } |
| 121 | - if ( $this->success() ) { |
|
| 121 | + if ($this->success()) { |
|
| 122 | 122 | $JSON_response['success'] = $this->success(); |
| 123 | 123 | } |
| 124 | 124 | // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
| 125 | - if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) { |
|
| 125 | + if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
| 126 | 126 | $JSON_response['success'] = null; |
| 127 | 127 | } |
| 128 | 128 | // set redirect_url, IF it exists |
| 129 | - if ( $this->redirect_url() ) { |
|
| 129 | + if ($this->redirect_url()) { |
|
| 130 | 130 | $JSON_response['redirect_url'] = $this->redirect_url(); |
| 131 | 131 | } |
| 132 | 132 | // set registration_time_limit, IF it exists |
| 133 | - if ( $this->registration_time_limit() ) { |
|
| 133 | + if ($this->registration_time_limit()) { |
|
| 134 | 134 | $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
| 135 | 135 | } |
| 136 | 136 | // set payment_amount, IF it exists |
| 137 | - if ( $this->payment_amount() !== null ) { |
|
| 138 | - $JSON_response[ 'payment_amount' ] = $this->payment_amount(); |
|
| 137 | + if ($this->payment_amount() !== null) { |
|
| 138 | + $JSON_response['payment_amount'] = $this->payment_amount(); |
|
| 139 | 139 | } |
| 140 | 140 | // grab generic return data |
| 141 | 141 | $return_data = $this->return_data(); |
| 142 | 142 | // add billing form validation rules |
| 143 | - if ( $this->validation_rules() ) { |
|
| 143 | + if ($this->validation_rules()) { |
|
| 144 | 144 | $return_data['validation_rules'] = $this->validation_rules(); |
| 145 | 145 | } |
| 146 | 146 | // set reg_step_html, IF it exists |
| 147 | - if ( $this->reg_step_html() ) { |
|
| 147 | + if ($this->reg_step_html()) { |
|
| 148 | 148 | $return_data['reg_step_html'] = $this->reg_step_html(); |
| 149 | 149 | } |
| 150 | 150 | // set method of payment, IF it exists |
| 151 | - if ( $this->method_of_payment() ) { |
|
| 151 | + if ($this->method_of_payment()) { |
|
| 152 | 152 | $return_data['method_of_payment'] = $this->method_of_payment(); |
| 153 | 153 | } |
| 154 | 154 | // set "plz_select_method_of_payment" message, IF it exists |
| 155 | - if ( $this->plz_select_method_of_payment() ) { |
|
| 155 | + if ($this->plz_select_method_of_payment()) { |
|
| 156 | 156 | $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
| 157 | 157 | } |
| 158 | 158 | // set redirect_form, IF it exists |
| 159 | - if ( $this->redirect_form() ) { |
|
| 159 | + if ($this->redirect_form()) { |
|
| 160 | 160 | $return_data['redirect_form'] = $this->redirect_form(); |
| 161 | 161 | } |
| 162 | 162 | // and finally, add return_data array to main JSON response array, IF it contains anything |
| 163 | 163 | // why did we add some of the above properties to the return data array? |
| 164 | 164 | // because it is easier and cleaner in the Javascript to deal with this way |
| 165 | - if ( ! empty( $return_data )) { |
|
| 165 | + if ( ! empty($return_data)) { |
|
| 166 | 166 | $JSON_response['return_data'] = $return_data; |
| 167 | 167 | } |
| 168 | 168 | // filter final array |
| 169 | - $JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response ); |
|
| 169 | + $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
| 170 | 170 | // return encoded array |
| 171 | - return (string) wp_json_encode( $JSON_response ); |
|
| 171 | + return (string) wp_json_encode($JSON_response); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | /** |
| 177 | 177 | * @param string $attention |
| 178 | 178 | */ |
| 179 | - public function set_attention( $attention ) { |
|
| 179 | + public function set_attention($attention) { |
|
| 180 | 180 | $this->_attention = $attention; |
| 181 | 181 | } |
| 182 | 182 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | /** |
| 195 | 195 | * @param string $errors |
| 196 | 196 | */ |
| 197 | - public function set_errors( $errors ) { |
|
| 197 | + public function set_errors($errors) { |
|
| 198 | 198 | $this->_errors = $errors; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | /** |
| 222 | 222 | * @param string $unexpected_errors |
| 223 | 223 | */ |
| 224 | - public function set_unexpected_errors( $unexpected_errors ) { |
|
| 224 | + public function set_unexpected_errors($unexpected_errors) { |
|
| 225 | 225 | $this->_unexpected_errors = $unexpected_errors; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | /** |
| 231 | 231 | * @param string $success |
| 232 | 232 | */ |
| 233 | - public function set_success( $success ) { |
|
| 233 | + public function set_success($success) { |
|
| 234 | 234 | $this->_success = $success; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | /** |
| 249 | 249 | * @param string $method_of_payment |
| 250 | 250 | */ |
| 251 | - public function set_method_of_payment( $method_of_payment ) { |
|
| 251 | + public function set_method_of_payment($method_of_payment) { |
|
| 252 | 252 | $this->_method_of_payment = $method_of_payment; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | * @param float $payment_amount |
| 276 | 276 | * @throws EE_Error |
| 277 | 277 | */ |
| 278 | - public function set_payment_amount( $payment_amount ) { |
|
| 279 | - $this->_payment_amount = (float)$payment_amount; |
|
| 278 | + public function set_payment_amount($payment_amount) { |
|
| 279 | + $this->_payment_amount = (float) $payment_amount; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | /** |
| 285 | 285 | * @param string $next_step_html |
| 286 | 286 | */ |
| 287 | - public function set_reg_step_html( $next_step_html ) { |
|
| 287 | + public function set_reg_step_html($next_step_html) { |
|
| 288 | 288 | $this->_reg_step_html = $next_step_html; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | /** |
| 303 | 303 | * @param string $redirect_form |
| 304 | 304 | */ |
| 305 | - public function set_redirect_form( $redirect_form ) { |
|
| 305 | + public function set_redirect_form($redirect_form) { |
|
| 306 | 306 | $this->_redirect_form = $redirect_form; |
| 307 | 307 | } |
| 308 | 308 | |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @return string |
| 313 | 313 | */ |
| 314 | 314 | public function redirect_form() { |
| 315 | - return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE; |
|
| 315 | + return ! empty($this->_redirect_form) ? $this->_redirect_form : FALSE; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | /** |
| 321 | 321 | * @param string $plz_select_method_of_payment |
| 322 | 322 | */ |
| 323 | - public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) { |
|
| 323 | + public function set_plz_select_method_of_payment($plz_select_method_of_payment) { |
|
| 324 | 324 | $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | /** |
| 339 | 339 | * @param string $redirect_url |
| 340 | 340 | */ |
| 341 | - public function set_redirect_url( $redirect_url ) { |
|
| 341 | + public function set_redirect_url($redirect_url) { |
|
| 342 | 342 | $this->_redirect_url = $redirect_url; |
| 343 | 343 | } |
| 344 | 344 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | /** |
| 366 | 366 | * @param string $registration_time_limit |
| 367 | 367 | */ |
| 368 | - public function set_registration_time_limit( $registration_time_limit ) { |
|
| 368 | + public function set_registration_time_limit($registration_time_limit) { |
|
| 369 | 369 | $this->_registration_time_limit = $registration_time_limit; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | /** |
| 375 | 375 | * @param array $return_data |
| 376 | 376 | */ |
| 377 | - public function set_return_data( $return_data ) { |
|
| 378 | - $this->_return_data = array_merge( $this->_return_data, $return_data ); |
|
| 377 | + public function set_return_data($return_data) { |
|
| 378 | + $this->_return_data = array_merge($this->_return_data, $return_data); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | * @param array $validation_rules |
| 394 | 394 | */ |
| 395 | 395 | public function add_validation_rules(array $validation_rules = array()) { |
| 396 | - if ( is_array( $validation_rules ) && ! empty( $validation_rules )) { |
|
| 397 | - $this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules ); |
|
| 396 | + if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
| 397 | + $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | * @return array | bool |
| 405 | 405 | */ |
| 406 | 406 | public function validation_rules() { |
| 407 | - return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE; |
|
| 407 | + return ! empty($this->_validation_rules) ? $this->_validation_rules : FALSE; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | //AND we are going to make sure they're in that specified order |
| 112 | 112 | $reordered_subsections = array(); |
| 113 | 113 | foreach ($options_array['include'] as $input_name) { |
| 114 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 114 | + if (isset($this->_subsections[$input_name])) { |
|
| 115 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | $this->_subsections = $reordered_subsections; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if (isset($options_array['layout_strategy'])) { |
| 125 | 125 | $this->_layout_strategy = $options_array['layout_strategy']; |
| 126 | 126 | } |
| 127 | - if (! $this->_layout_strategy) { |
|
| 127 | + if ( ! $this->_layout_strategy) { |
|
| 128 | 128 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
| 129 | 129 | } |
| 130 | 130 | $this->_layout_strategy->_construct_finalize($this); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | $req_data, |
| 278 | 278 | $this |
| 279 | 279 | ); |
| 280 | - $this->cached_request_data = (array)$req_data; |
|
| 280 | + $this->cached_request_data = (array) $req_data; |
|
| 281 | 281 | } |
| 282 | 282 | return $this->cached_request_data; |
| 283 | 283 | } |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | if ($validate) { |
| 314 | 314 | $this->_validate(); |
| 315 | 315 | //if it's invalid, we're going to want to re-display so remember what they submitted |
| 316 | - if (! $this->is_valid()) { |
|
| 316 | + if ( ! $this->is_valid()) { |
|
| 317 | 317 | $this->store_submitted_form_data_in_session(); |
| 318 | 318 | } |
| 319 | 319 | } |
@@ -426,11 +426,11 @@ discard block |
||
| 426 | 426 | public function populate_defaults($default_data) |
| 427 | 427 | { |
| 428 | 428 | foreach ($this->subsections(false) as $subsection_name => $subsection) { |
| 429 | - if (isset($default_data[ $subsection_name ])) { |
|
| 429 | + if (isset($default_data[$subsection_name])) { |
|
| 430 | 430 | if ($subsection instanceof EE_Form_Input_Base) { |
| 431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 431 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 432 | 432 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 433 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | public function subsection_exists($name) |
| 447 | 447 | { |
| 448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 448 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | if ($require_construction_to_be_finalized) { |
| 468 | 468 | $this->ensure_construct_finalized_called(); |
| 469 | 469 | } |
| 470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 470 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $validatable_subsections = array(); |
| 483 | 483 | foreach ($this->subsections() as $name => $obj) { |
| 484 | 484 | if ($obj instanceof EE_Form_Section_Validatable) { |
| 485 | - $validatable_subsections[ $name ] = $obj; |
|
| 485 | + $validatable_subsections[$name] = $obj; |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | return $validatable_subsections; |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | $name, |
| 510 | 510 | $require_construction_to_be_finalized |
| 511 | 511 | ); |
| 512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 512 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 513 | 513 | throw new EE_Error( |
| 514 | 514 | sprintf( |
| 515 | 515 | esc_html__( |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | $name, |
| 547 | 547 | $require_construction_to_be_finalized |
| 548 | 548 | ); |
| 549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 549 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 550 | 550 | throw new EE_Error( |
| 551 | 551 | sprintf( |
| 552 | 552 | esc_html__( |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | */ |
| 586 | 586 | public function is_valid() |
| 587 | 587 | { |
| 588 | - if($this->is_valid === null) { |
|
| 589 | - if (! $this->has_received_submission()) { |
|
| 588 | + if ($this->is_valid === null) { |
|
| 589 | + if ( ! $this->has_received_submission()) { |
|
| 590 | 590 | throw new EE_Error( |
| 591 | 591 | sprintf( |
| 592 | 592 | esc_html__( |
@@ -596,14 +596,14 @@ discard block |
||
| 596 | 596 | ) |
| 597 | 597 | ); |
| 598 | 598 | } |
| 599 | - if (! parent::is_valid()) { |
|
| 599 | + if ( ! parent::is_valid()) { |
|
| 600 | 600 | $this->is_valid = false; |
| 601 | 601 | } else { |
| 602 | 602 | // ok so no general errors to this entire form section. |
| 603 | 603 | // so let's check the subsections, but only set errors if that hasn't been done yet |
| 604 | 604 | $this->is_valid = true; |
| 605 | 605 | foreach ($this->get_validatable_subsections() as $subsection) { |
| 606 | - if (! $subsection->is_valid()) { |
|
| 606 | + if ( ! $subsection->is_valid()) { |
|
| 607 | 607 | $this->is_valid = false; |
| 608 | 608 | } |
| 609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | */ |
| 621 | 621 | protected function _set_default_name_if_empty() |
| 622 | 622 | { |
| 623 | - if (! $this->_name) { |
|
| 623 | + if ( ! $this->_name) { |
|
| 624 | 624 | $classname = get_class($this); |
| 625 | 625 | $default_name = str_replace('EE_', '', $classname); |
| 626 | 626 | $this->_name = $default_name; |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | { |
| 711 | 711 | wp_register_script( |
| 712 | 712 | 'ee_form_section_validation', |
| 713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 713 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
| 714 | 714 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
| 715 | 715 | EVENT_ESPRESSO_VERSION, |
| 716 | 716 | true |
@@ -754,13 +754,13 @@ discard block |
||
| 754 | 754 | // we only want to localize vars ONCE for the entire form, |
| 755 | 755 | // so if the form section doesn't have a parent, then it must be the top dog |
| 756 | 756 | if ($return_for_subsection || ! $this->parent_section()) { |
| 757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 757 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 758 | 758 | 'form_section_id' => $this->html_id(true), |
| 759 | 759 | 'validation_rules' => $this->get_jquery_validation_rules(), |
| 760 | 760 | 'other_data' => $this->get_other_js_data(), |
| 761 | 761 | 'errors' => $this->subsection_validation_errors_by_html_name(), |
| 762 | 762 | ); |
| 763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | $inputs = array(); |
| 796 | 796 | foreach ($this->subsections() as $subsection) { |
| 797 | 797 | if ($subsection instanceof EE_Form_Input_Base) { |
| 798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 798 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 799 | 799 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 800 | 800 | $inputs += $subsection->inputs_in_subsections(); |
| 801 | 801 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | $errors = array(); |
| 819 | 819 | foreach ($inputs as $form_input) { |
| 820 | 820 | if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
| 821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 821 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | return $errors; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
| 842 | 842 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
| 843 | 843 | : 'wp_default'; |
| 844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 845 | 845 | wp_enqueue_script('ee_form_section_validation'); |
| 846 | 846 | wp_localize_script( |
| 847 | 847 | 'ee_form_section_validation', |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | public function ensure_scripts_localized() |
| 860 | 860 | { |
| 861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 861 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 862 | 862 | $this->_enqueue_and_localize_form_js(); |
| 863 | 863 | } |
| 864 | 864 | } |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | //reset the cache of whether this form is valid or not- we're re-validating it now |
| 955 | 955 | $this->is_valid = null; |
| 956 | 956 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 957 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 958 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 959 | 959 | } |
| 960 | 960 | $subsection->_validate(); |
| 961 | 961 | } |
@@ -973,9 +973,9 @@ discard block |
||
| 973 | 973 | $inputs = array(); |
| 974 | 974 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 975 | 975 | if ($subsection instanceof EE_Form_Section_Proper) { |
| 976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 976 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 977 | 977 | } elseif ($subsection instanceof EE_Form_Input_Base) { |
| 978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 978 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | return $inputs; |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | $inputs = array(); |
| 994 | 994 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 995 | 995 | if ($subsection instanceof EE_Form_Input_Base) { |
| 996 | - $inputs[ $subsection_name ] = $subsection; |
|
| 996 | + $inputs[$subsection_name] = $subsection; |
|
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | 999 | return $inputs; |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | $form_sections = array(); |
| 1012 | 1012 | foreach ($this->subsections() as $name => $obj) { |
| 1013 | 1013 | if ($obj instanceof EE_Form_Section_Proper) { |
| 1014 | - $form_sections[ $name ] = $obj; |
|
| 1014 | + $form_sections[$name] = $obj; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | return $form_sections; |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | $input_values = array(); |
| 1119 | 1119 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 1120 | 1120 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1121 | - $input_values[ $subsection_name ] = $pretty |
|
| 1121 | + $input_values[$subsection_name] = $pretty |
|
| 1122 | 1122 | ? $subsection->pretty_value() |
| 1123 | 1123 | : $subsection->normalized_value(); |
| 1124 | 1124 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | if ($flatten) { |
| 1131 | 1131 | $input_values = array_merge($input_values, $subform_input_values); |
| 1132 | 1132 | } else { |
| 1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1133 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | 1136 | } |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1159 | 1159 | // is this input part of an array of inputs? |
| 1160 | 1160 | if (strpos($subsection->html_name(), '[') !== false) { |
| 1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1162 | 1162 | explode( |
| 1163 | 1163 | '[', |
| 1164 | 1164 | str_replace(']', '', $subsection->html_name()) |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 1167 | ); |
| 1168 | 1168 | $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
| 1169 | 1169 | } else { |
| 1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1170 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
| 1173 | 1173 | $subform_input_values = $subsection->submitted_values($include_subforms); |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | public function exclude(array $inputs_to_exclude = array()) |
| 1203 | 1203 | { |
| 1204 | 1204 | foreach ($inputs_to_exclude as $input_to_exclude_name) { |
| 1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1205 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | } |
| 1208 | 1208 | |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
| 1245 | 1245 | { |
| 1246 | 1246 | foreach ($new_subsections as $subsection_name => $subsection) { |
| 1247 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1247 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1248 | 1248 | EE_Error::add_error( |
| 1249 | 1249 | sprintf( |
| 1250 | 1250 | esc_html__( |
@@ -1256,7 +1256,7 @@ discard block |
||
| 1256 | 1256 | $this->name() |
| 1257 | 1257 | ) |
| 1258 | 1258 | ); |
| 1259 | - unset($new_subsections[ $subsection_name ]); |
|
| 1259 | + unset($new_subsections[$subsection_name]); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | } |
| 1262 | 1262 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1280,7 +1280,7 @@ discard block |
||
| 1280 | 1280 | */ |
| 1281 | 1281 | public function has_subsection($subsection_name, $recursive = false) |
| 1282 | 1282 | { |
| 1283 | - foreach ($this->_subsections as $name => $subsection) {if( |
|
| 1283 | + foreach ($this->_subsections as $name => $subsection) {if ( |
|
| 1284 | 1284 | $name === $subsection_name |
| 1285 | 1285 | || ( |
| 1286 | 1286 | $recursive |
@@ -1371,7 +1371,7 @@ discard block |
||
| 1371 | 1371 | public function html_name_prefix() |
| 1372 | 1372 | { |
| 1373 | 1373 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
| 1374 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1374 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
| 1375 | 1375 | } |
| 1376 | 1376 | return $this->name(); |
| 1377 | 1377 | } |
@@ -1411,7 +1411,7 @@ discard block |
||
| 1411 | 1411 | */ |
| 1412 | 1412 | public function ensure_construct_finalized_called() |
| 1413 | 1413 | { |
| 1414 | - if (! $this->_construction_finalized) { |
|
| 1414 | + if ( ! $this->_construction_finalized) { |
|
| 1415 | 1415 | $this->_construct_finalize($this->_parent_section, $this->_name); |
| 1416 | 1416 | } |
| 1417 | 1417 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | $form_section = $validation_error->get_form_section(); |
| 1485 | 1485 | if ($form_section instanceof EE_Form_Input_Base) { |
| 1486 | 1486 | $label = $validation_error->get_form_section()->html_label_text(); |
| 1487 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1487 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1488 | 1488 | $label = $validation_error->get_form_section()->name(); |
| 1489 | 1489 | } else { |
| 1490 | 1490 | $label = esc_html__('Unknown', 'event_espresso'); |
@@ -14,1529 +14,1529 @@ |
||
| 14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Subsections |
|
| 21 | - * |
|
| 22 | - * @var EE_Form_Section_Validatable[] |
|
| 23 | - */ |
|
| 24 | - protected $_subsections = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Strategy for laying out the form |
|
| 28 | - * |
|
| 29 | - * @var EE_Form_Section_Layout_Base |
|
| 30 | - */ |
|
| 31 | - protected $_layout_strategy; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Whether or not this form has received and validated a form submission yet |
|
| 35 | - * |
|
| 36 | - * @var boolean |
|
| 37 | - */ |
|
| 38 | - protected $_received_submission = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * message displayed to users upon successful form submission |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $_form_submission_success_message = ''; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * message displayed to users upon unsuccessful form submission |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - protected $_form_submission_error_message = ''; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var array like $_REQUEST |
|
| 56 | - */ |
|
| 57 | - protected $cached_request_data; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 61 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
| 62 | - * @var boolean|null |
|
| 63 | - */ |
|
| 64 | - protected $is_valid; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Stores all the data that will localized for form validation |
|
| 68 | - * |
|
| 69 | - * @var array |
|
| 70 | - */ |
|
| 71 | - static protected $_js_localization = array(); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * whether or not the form's localized validation JS vars have been set |
|
| 75 | - * |
|
| 76 | - * @type boolean |
|
| 77 | - */ |
|
| 78 | - static protected $_scripts_localized = false; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 83 | - * so that they know who their parent is, and what name they've been given. |
|
| 84 | - * |
|
| 85 | - * @param array[] $options_array { |
|
| 86 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 87 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 88 | - * and in that order. This is handy if you want |
|
| 89 | - * the subsections to be ordered differently than the default, and if you override |
|
| 90 | - * which fields are shown |
|
| 91 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 92 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 93 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 94 | - * items from that list of inclusions) |
|
| 95 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 96 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function __construct($options_array = array()) |
|
| 100 | - { |
|
| 101 | - $options_array = (array) apply_filters( |
|
| 102 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 103 | - $options_array, |
|
| 104 | - $this |
|
| 105 | - ); |
|
| 106 | - //call parent first, as it may be setting the name |
|
| 107 | - parent::__construct($options_array); |
|
| 108 | - //if they've included subsections in the constructor, add them now |
|
| 109 | - if (isset($options_array['include'])) { |
|
| 110 | - //we are going to make sure we ONLY have those subsections to include |
|
| 111 | - //AND we are going to make sure they're in that specified order |
|
| 112 | - $reordered_subsections = array(); |
|
| 113 | - foreach ($options_array['include'] as $input_name) { |
|
| 114 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $this->_subsections = $reordered_subsections; |
|
| 119 | - } |
|
| 120 | - if (isset($options_array['exclude'])) { |
|
| 121 | - $exclude = $options_array['exclude']; |
|
| 122 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 123 | - } |
|
| 124 | - if (isset($options_array['layout_strategy'])) { |
|
| 125 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 126 | - } |
|
| 127 | - if (! $this->_layout_strategy) { |
|
| 128 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 129 | - } |
|
| 130 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 131 | - //ok so we are definitely going to want the forms JS, |
|
| 132 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 133 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 134 | - //ok so they've constructed this object after when they should have. |
|
| 135 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 136 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 137 | - } else { |
|
| 138 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 139 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | - } |
|
| 141 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 142 | - /** |
|
| 143 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 144 | - * The form probably doesn't yet have a parent form section. |
|
| 145 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 146 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 147 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 148 | - * |
|
| 149 | - * @since 4.9.32 |
|
| 150 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 151 | - * except maybe calling _construct_finalize has been done |
|
| 152 | - * @param array $options_array options passed into the constructor |
|
| 153 | - */ |
|
| 154 | - do_action( |
|
| 155 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 156 | - $this, |
|
| 157 | - $options_array |
|
| 158 | - ); |
|
| 159 | - if (isset($options_array['name'])) { |
|
| 160 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Finishes construction given the parent form section and this form section's name |
|
| 167 | - * |
|
| 168 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 169 | - * @param string $name |
|
| 170 | - * @throws EE_Error |
|
| 171 | - */ |
|
| 172 | - public function _construct_finalize($parent_form_section, $name) |
|
| 173 | - { |
|
| 174 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 175 | - $this->_set_default_name_if_empty(); |
|
| 176 | - $this->_set_default_html_id_if_empty(); |
|
| 177 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 178 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 179 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 180 | - } else { |
|
| 181 | - throw new EE_Error( |
|
| 182 | - sprintf( |
|
| 183 | - esc_html__( |
|
| 184 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 185 | - 'event_espresso' |
|
| 186 | - ), |
|
| 187 | - $subsection_name, |
|
| 188 | - get_class($this), |
|
| 189 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - /** |
|
| 195 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 196 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 197 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 198 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 199 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 200 | - * ensured it has a name, HTML IDs, etc |
|
| 201 | - * |
|
| 202 | - * @param EE_Form_Section_Proper $this |
|
| 203 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 204 | - * @param string $name |
|
| 205 | - */ |
|
| 206 | - do_action( |
|
| 207 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 208 | - $this, |
|
| 209 | - $parent_form_section, |
|
| 210 | - $name |
|
| 211 | - ); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Gets the layout strategy for this form section |
|
| 217 | - * |
|
| 218 | - * @return EE_Form_Section_Layout_Base |
|
| 219 | - */ |
|
| 220 | - public function get_layout_strategy() |
|
| 221 | - { |
|
| 222 | - return $this->_layout_strategy; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Gets the HTML for a single input for this form section according |
|
| 228 | - * to the layout strategy |
|
| 229 | - * |
|
| 230 | - * @param EE_Form_Input_Base $input |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - public function get_html_for_input($input) |
|
| 234 | - { |
|
| 235 | - return $this->_layout_strategy->layout_input($input); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * was_submitted - checks if form inputs are present in request data |
|
| 241 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 242 | - * proper form sections and form inputs) |
|
| 243 | - * |
|
| 244 | - * @param null $form_data |
|
| 245 | - * @return boolean |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - public function was_submitted($form_data = null) |
|
| 249 | - { |
|
| 250 | - return $this->form_data_present_in($form_data); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 255 | - * something different, refresh the cache, and then return it |
|
| 256 | - * @param null $req_data |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - protected function getCachedRequest($req_data = null) |
|
| 260 | - { |
|
| 261 | - if ($this->cached_request_data === null |
|
| 262 | - || ( |
|
| 263 | - $req_data !== null && |
|
| 264 | - $req_data !== $this->cached_request_data |
|
| 265 | - ) |
|
| 266 | - ) { |
|
| 267 | - $req_data = apply_filters( |
|
| 268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 269 | - $req_data, |
|
| 270 | - $this |
|
| 271 | - ); |
|
| 272 | - if ($req_data === null) { |
|
| 273 | - $req_data = array_merge($_GET, $_POST); |
|
| 274 | - } |
|
| 275 | - $req_data = apply_filters( |
|
| 276 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 277 | - $req_data, |
|
| 278 | - $this |
|
| 279 | - ); |
|
| 280 | - $this->cached_request_data = (array)$req_data; |
|
| 281 | - } |
|
| 282 | - return $this->cached_request_data; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 288 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 289 | - * |
|
| 290 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 291 | - * However, you CAN supply a different array. |
|
| 292 | - * Consider using set_defaults() instead however. |
|
| 293 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 294 | - * the inputs will have the correct name in the request data for this function |
|
| 295 | - * to find them and populate the form with them. |
|
| 296 | - * If you have a flat form (with only input subsections), |
|
| 297 | - * you can supply a flat array where keys |
|
| 298 | - * are the form input names and values are their values) |
|
| 299 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 300 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 301 | - * But if the data has already been validated |
|
| 302 | - * (eg you validated the data then stored it in the DB) |
|
| 303 | - * you may want to skip this step. |
|
| 304 | - * @throws InvalidArgumentException |
|
| 305 | - * @throws InvalidInterfaceException |
|
| 306 | - * @throws InvalidDataTypeException |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 310 | - { |
|
| 311 | - $req_data = $this->getCachedRequest($req_data); |
|
| 312 | - $this->_normalize($req_data); |
|
| 313 | - if ($validate) { |
|
| 314 | - $this->_validate(); |
|
| 315 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 316 | - if (! $this->is_valid()) { |
|
| 317 | - $this->store_submitted_form_data_in_session(); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 321 | - $this->set_submission_error_message(); |
|
| 322 | - } |
|
| 323 | - do_action( |
|
| 324 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 325 | - $req_data, |
|
| 326 | - $this, |
|
| 327 | - $validate |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * caches the originally submitted input values in the session |
|
| 334 | - * so that they can be used to repopulate the form if it failed validation |
|
| 335 | - * |
|
| 336 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 337 | - * @throws InvalidArgumentException |
|
| 338 | - * @throws InvalidInterfaceException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws EE_Error |
|
| 341 | - */ |
|
| 342 | - protected function store_submitted_form_data_in_session() |
|
| 343 | - { |
|
| 344 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 345 | - array( |
|
| 346 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 347 | - ) |
|
| 348 | - ); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * retrieves the originally submitted input values in the session |
|
| 354 | - * so that they can be used to repopulate the form if it failed validation |
|
| 355 | - * |
|
| 356 | - * @return array |
|
| 357 | - * @throws InvalidArgumentException |
|
| 358 | - * @throws InvalidInterfaceException |
|
| 359 | - * @throws InvalidDataTypeException |
|
| 360 | - */ |
|
| 361 | - protected function get_submitted_form_data_from_session() |
|
| 362 | - { |
|
| 363 | - $session = EE_Registry::instance()->SSN; |
|
| 364 | - if ($session instanceof EE_Session) { |
|
| 365 | - return $session->get_session_data( |
|
| 366 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 367 | - ); |
|
| 368 | - } |
|
| 369 | - return array(); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * flushed the originally submitted input values from the session |
|
| 375 | - * |
|
| 376 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 377 | - * @throws InvalidArgumentException |
|
| 378 | - * @throws InvalidInterfaceException |
|
| 379 | - * @throws InvalidDataTypeException |
|
| 380 | - */ |
|
| 381 | - protected function flush_submitted_form_data_from_session() |
|
| 382 | - { |
|
| 383 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 384 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 385 | - ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Populates this form and its subsections with data from the session. |
|
| 391 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 392 | - * validation errors when displaying too) |
|
| 393 | - * Returns true if the form was populated from the session, false otherwise |
|
| 394 | - * |
|
| 395 | - * @return boolean |
|
| 396 | - * @throws InvalidArgumentException |
|
| 397 | - * @throws InvalidInterfaceException |
|
| 398 | - * @throws InvalidDataTypeException |
|
| 399 | - * @throws EE_Error |
|
| 400 | - */ |
|
| 401 | - public function populate_from_session() |
|
| 402 | - { |
|
| 403 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 404 | - if (empty($form_data_in_session)) { |
|
| 405 | - return false; |
|
| 406 | - } |
|
| 407 | - $this->receive_form_submission($form_data_in_session); |
|
| 408 | - $this->flush_submitted_form_data_from_session(); |
|
| 409 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 410 | - return true; |
|
| 411 | - } |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Populates the default data for the form, given an array where keys are |
|
| 418 | - * the input names, and values are their values (preferably normalized to be their |
|
| 419 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 420 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 421 | - * the value being an array formatted in teh same way |
|
| 422 | - * |
|
| 423 | - * @param array $default_data |
|
| 424 | - * @throws EE_Error |
|
| 425 | - */ |
|
| 426 | - public function populate_defaults($default_data) |
|
| 427 | - { |
|
| 428 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 429 | - if (isset($default_data[ $subsection_name ])) { |
|
| 430 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 432 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * returns true if subsection exists |
|
| 442 | - * |
|
| 443 | - * @param string $name |
|
| 444 | - * @return boolean |
|
| 445 | - */ |
|
| 446 | - public function subsection_exists($name) |
|
| 447 | - { |
|
| 448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Gets the subsection specified by its name |
|
| 454 | - * |
|
| 455 | - * @param string $name |
|
| 456 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 457 | - * so that the inputs will be properly configured. |
|
| 458 | - * However, some client code may be ok |
|
| 459 | - * with construction finalize being called later |
|
| 460 | - * (realizing that the subsections' html names |
|
| 461 | - * might not be set yet, etc.) |
|
| 462 | - * @return EE_Form_Section_Base |
|
| 463 | - * @throws EE_Error |
|
| 464 | - */ |
|
| 465 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 466 | - { |
|
| 467 | - if ($require_construction_to_be_finalized) { |
|
| 468 | - $this->ensure_construct_finalized_called(); |
|
| 469 | - } |
|
| 470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Gets all the validatable subsections of this form section |
|
| 476 | - * |
|
| 477 | - * @return EE_Form_Section_Validatable[] |
|
| 478 | - * @throws EE_Error |
|
| 479 | - */ |
|
| 480 | - public function get_validatable_subsections() |
|
| 481 | - { |
|
| 482 | - $validatable_subsections = array(); |
|
| 483 | - foreach ($this->subsections() as $name => $obj) { |
|
| 484 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 485 | - $validatable_subsections[ $name ] = $obj; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - return $validatable_subsections; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 494 | - * throw an EE_Error. |
|
| 495 | - * |
|
| 496 | - * @param string $name |
|
| 497 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 498 | - * leave this as TRUE so that the inputs will be properly |
|
| 499 | - * configured. However, some client code may be ok with |
|
| 500 | - * construction finalize being called later |
|
| 501 | - * (realizing that the subsections' html names might not be |
|
| 502 | - * set yet, etc.) |
|
| 503 | - * @return EE_Form_Input_Base |
|
| 504 | - * @throws EE_Error |
|
| 505 | - */ |
|
| 506 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 507 | - { |
|
| 508 | - $subsection = $this->get_subsection( |
|
| 509 | - $name, |
|
| 510 | - $require_construction_to_be_finalized |
|
| 511 | - ); |
|
| 512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 513 | - throw new EE_Error( |
|
| 514 | - sprintf( |
|
| 515 | - esc_html__( |
|
| 516 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 517 | - 'event_espresso' |
|
| 518 | - ), |
|
| 519 | - $name, |
|
| 520 | - get_class($this), |
|
| 521 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 522 | - ) |
|
| 523 | - ); |
|
| 524 | - } |
|
| 525 | - return $subsection; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 531 | - * otherwise throws an EE_Error |
|
| 532 | - * |
|
| 533 | - * @param string $name |
|
| 534 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 535 | - * leave this as TRUE so that the inputs will be properly |
|
| 536 | - * configured. However, some client code may be ok with |
|
| 537 | - * construction finalize being called later |
|
| 538 | - * (realizing that the subsections' html names might not be |
|
| 539 | - * set yet, etc.) |
|
| 540 | - * @return EE_Form_Section_Proper |
|
| 541 | - * @throws EE_Error |
|
| 542 | - */ |
|
| 543 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 544 | - { |
|
| 545 | - $subsection = $this->get_subsection( |
|
| 546 | - $name, |
|
| 547 | - $require_construction_to_be_finalized |
|
| 548 | - ); |
|
| 549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 550 | - throw new EE_Error( |
|
| 551 | - sprintf( |
|
| 552 | - esc_html__( |
|
| 553 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 554 | - 'event_espresso' |
|
| 555 | - ), |
|
| 556 | - $name, |
|
| 557 | - get_class($this) |
|
| 558 | - ) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - return $subsection; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 567 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 568 | - * |
|
| 569 | - * @param string $name |
|
| 570 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 571 | - * @throws EE_Error |
|
| 572 | - */ |
|
| 573 | - public function get_input_value($name) |
|
| 574 | - { |
|
| 575 | - $input = $this->get_input($name); |
|
| 576 | - return $input->normalized_value(); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 582 | - * |
|
| 583 | - * @throws EE_Error |
|
| 584 | - * @return boolean |
|
| 585 | - */ |
|
| 586 | - public function is_valid() |
|
| 587 | - { |
|
| 588 | - if($this->is_valid === null) { |
|
| 589 | - if (! $this->has_received_submission()) { |
|
| 590 | - throw new EE_Error( |
|
| 591 | - sprintf( |
|
| 592 | - esc_html__( |
|
| 593 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 594 | - 'event_espresso' |
|
| 595 | - ) |
|
| 596 | - ) |
|
| 597 | - ); |
|
| 598 | - } |
|
| 599 | - if (! parent::is_valid()) { |
|
| 600 | - $this->is_valid = false; |
|
| 601 | - } else { |
|
| 602 | - // ok so no general errors to this entire form section. |
|
| 603 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 604 | - $this->is_valid = true; |
|
| 605 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 606 | - if (! $subsection->is_valid()) { |
|
| 607 | - $this->is_valid = false; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - return $this->is_valid; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * gets the default name of this form section if none is specified |
|
| 618 | - * |
|
| 619 | - * @return void |
|
| 620 | - */ |
|
| 621 | - protected function _set_default_name_if_empty() |
|
| 622 | - { |
|
| 623 | - if (! $this->_name) { |
|
| 624 | - $classname = get_class($this); |
|
| 625 | - $default_name = str_replace('EE_', '', $classname); |
|
| 626 | - $this->_name = $default_name; |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 633 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 634 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 635 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 636 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 637 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 638 | - * any CSS. |
|
| 639 | - * |
|
| 640 | - * @throws InvalidArgumentException |
|
| 641 | - * @throws InvalidInterfaceException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws EE_Error |
|
| 644 | - */ |
|
| 645 | - public function get_html_and_js() |
|
| 646 | - { |
|
| 647 | - $this->enqueue_js(); |
|
| 648 | - return $this->get_html(); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 654 | - * |
|
| 655 | - * @param bool $display_previously_submitted_data |
|
| 656 | - * @return string |
|
| 657 | - * @throws InvalidArgumentException |
|
| 658 | - * @throws InvalidInterfaceException |
|
| 659 | - * @throws InvalidDataTypeException |
|
| 660 | - * @throws EE_Error |
|
| 661 | - * @throws EE_Error |
|
| 662 | - * @throws EE_Error |
|
| 663 | - */ |
|
| 664 | - public function get_html($display_previously_submitted_data = true) |
|
| 665 | - { |
|
| 666 | - $this->ensure_construct_finalized_called(); |
|
| 667 | - if ($display_previously_submitted_data) { |
|
| 668 | - $this->populate_from_session(); |
|
| 669 | - } |
|
| 670 | - return $this->_form_html_filter |
|
| 671 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 672 | - : $this->_layout_strategy->layout_form(); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * enqueues JS and CSS for the form. |
|
| 678 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 679 | - * scripts and styles can be put in the header, but if called later |
|
| 680 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 681 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 682 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 683 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 684 | - * |
|
| 685 | - * @return void |
|
| 686 | - * @throws EE_Error |
|
| 687 | - */ |
|
| 688 | - public function enqueue_js() |
|
| 689 | - { |
|
| 690 | - $this->_enqueue_and_localize_form_js(); |
|
| 691 | - foreach ($this->subsections() as $subsection) { |
|
| 692 | - $subsection->enqueue_js(); |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 699 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 700 | - * the wp_enqueue_scripts hook. |
|
| 701 | - * However, registering the form js and localizing it can happen when we |
|
| 702 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 703 | - * could change until it's actually outputted) |
|
| 704 | - * |
|
| 705 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 706 | - * to be triggered automatically or not |
|
| 707 | - * @return void |
|
| 708 | - */ |
|
| 709 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 710 | - { |
|
| 711 | - wp_register_script( |
|
| 712 | - 'ee_form_section_validation', |
|
| 713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 714 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 715 | - EVENT_ESPRESSO_VERSION, |
|
| 716 | - true |
|
| 717 | - ); |
|
| 718 | - wp_localize_script( |
|
| 719 | - 'ee_form_section_validation', |
|
| 720 | - 'ee_form_section_validation_init', |
|
| 721 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 722 | - ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * gets the variables used by form_section_validation.js. |
|
| 728 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 729 | - * but before the wordpress hook wp_loaded |
|
| 730 | - * |
|
| 731 | - * @throws EE_Error |
|
| 732 | - */ |
|
| 733 | - public function _enqueue_and_localize_form_js() |
|
| 734 | - { |
|
| 735 | - $this->ensure_construct_finalized_called(); |
|
| 736 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 737 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 738 | - //and localize it just before the footer |
|
| 739 | - $this->localize_validation_rules(); |
|
| 740 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 741 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * add our form section data to a static variable accessible by all form sections |
|
| 747 | - * |
|
| 748 | - * @param bool $return_for_subsection |
|
| 749 | - * @return void |
|
| 750 | - * @throws EE_Error |
|
| 751 | - */ |
|
| 752 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 753 | - { |
|
| 754 | - // we only want to localize vars ONCE for the entire form, |
|
| 755 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 756 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 758 | - 'form_section_id' => $this->html_id(true), |
|
| 759 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 760 | - 'other_data' => $this->get_other_js_data(), |
|
| 761 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 762 | - ); |
|
| 763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 770 | - * This is primarily data added by inputs and forms in addition to any |
|
| 771 | - * scripts they might enqueue |
|
| 772 | - * |
|
| 773 | - * @param array $form_other_js_data |
|
| 774 | - * @return array |
|
| 775 | - * @throws EE_Error |
|
| 776 | - */ |
|
| 777 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 778 | - { |
|
| 779 | - foreach ($this->subsections() as $subsection) { |
|
| 780 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 781 | - } |
|
| 782 | - return $form_other_js_data; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 788 | - * Keys are their form names, and values are the inputs themselves |
|
| 789 | - * |
|
| 790 | - * @return EE_Form_Input_Base |
|
| 791 | - * @throws EE_Error |
|
| 792 | - */ |
|
| 793 | - public function inputs_in_subsections() |
|
| 794 | - { |
|
| 795 | - $inputs = array(); |
|
| 796 | - foreach ($this->subsections() as $subsection) { |
|
| 797 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 799 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 800 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - return $inputs; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Gets a flat array of all the validation errors. |
|
| 809 | - * Keys are html names (because those should be unique) |
|
| 810 | - * and values are a string of all their validation errors |
|
| 811 | - * |
|
| 812 | - * @return string[] |
|
| 813 | - * @throws EE_Error |
|
| 814 | - */ |
|
| 815 | - public function subsection_validation_errors_by_html_name() |
|
| 816 | - { |
|
| 817 | - $inputs = $this->inputs(); |
|
| 818 | - $errors = array(); |
|
| 819 | - foreach ($inputs as $form_input) { |
|
| 820 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - return $errors; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 830 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 831 | - * |
|
| 832 | - * @throws InvalidArgumentException |
|
| 833 | - * @throws InvalidInterfaceException |
|
| 834 | - * @throws InvalidDataTypeException |
|
| 835 | - */ |
|
| 836 | - public static function localize_script_for_all_forms() |
|
| 837 | - { |
|
| 838 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 839 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 840 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 841 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 842 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 843 | - : 'wp_default'; |
|
| 844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 845 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 846 | - wp_localize_script( |
|
| 847 | - 'ee_form_section_validation', |
|
| 848 | - 'ee_form_section_vars', |
|
| 849 | - EE_Form_Section_Proper::$_js_localization |
|
| 850 | - ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * ensure_scripts_localized |
|
| 856 | - * |
|
| 857 | - * @throws EE_Error |
|
| 858 | - */ |
|
| 859 | - public function ensure_scripts_localized() |
|
| 860 | - { |
|
| 861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 862 | - $this->_enqueue_and_localize_form_js(); |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 869 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 870 | - * |
|
| 871 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 872 | - */ |
|
| 873 | - private static function _get_localized_error_messages() |
|
| 874 | - { |
|
| 875 | - return array( |
|
| 876 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
| 877 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
| 878 | - ); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * @return array |
|
| 884 | - */ |
|
| 885 | - public static function js_localization() |
|
| 886 | - { |
|
| 887 | - return self::$_js_localization; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * @return void |
|
| 893 | - */ |
|
| 894 | - public static function reset_js_localization() |
|
| 895 | - { |
|
| 896 | - self::$_js_localization = array(); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 902 | - * See parent function for more... |
|
| 903 | - * |
|
| 904 | - * @return array |
|
| 905 | - * @throws EE_Error |
|
| 906 | - */ |
|
| 907 | - public function get_jquery_validation_rules() |
|
| 908 | - { |
|
| 909 | - $jquery_validation_rules = array(); |
|
| 910 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 911 | - $jquery_validation_rules = array_merge( |
|
| 912 | - $jquery_validation_rules, |
|
| 913 | - $subsection->get_jquery_validation_rules() |
|
| 914 | - ); |
|
| 915 | - } |
|
| 916 | - return $jquery_validation_rules; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 922 | - * |
|
| 923 | - * @param array $req_data like $_POST |
|
| 924 | - * @return void |
|
| 925 | - * @throws EE_Error |
|
| 926 | - */ |
|
| 927 | - protected function _normalize($req_data) |
|
| 928 | - { |
|
| 929 | - $this->_received_submission = true; |
|
| 930 | - $this->_validation_errors = array(); |
|
| 931 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 932 | - try { |
|
| 933 | - $subsection->_normalize($req_data); |
|
| 934 | - } catch (EE_Validation_Error $e) { |
|
| 935 | - $subsection->add_validation_error($e); |
|
| 936 | - } |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - /** |
|
| 942 | - * Performs validation on this form section and its subsections. |
|
| 943 | - * For each subsection, |
|
| 944 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 945 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 946 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 947 | - * you would be best to override this _validate method, |
|
| 948 | - * calling parent::_validate() first. |
|
| 949 | - * |
|
| 950 | - * @throws EE_Error |
|
| 951 | - */ |
|
| 952 | - protected function _validate() |
|
| 953 | - { |
|
| 954 | - //reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 955 | - $this->is_valid = null; |
|
| 956 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 959 | - } |
|
| 960 | - $subsection->_validate(); |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Gets all the validated inputs for the form section |
|
| 967 | - * |
|
| 968 | - * @return array |
|
| 969 | - * @throws EE_Error |
|
| 970 | - */ |
|
| 971 | - public function valid_data() |
|
| 972 | - { |
|
| 973 | - $inputs = array(); |
|
| 974 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 975 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 977 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - return $inputs; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * Gets all the inputs on this form section |
|
| 987 | - * |
|
| 988 | - * @return EE_Form_Input_Base[] |
|
| 989 | - * @throws EE_Error |
|
| 990 | - */ |
|
| 991 | - public function inputs() |
|
| 992 | - { |
|
| 993 | - $inputs = array(); |
|
| 994 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 995 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 996 | - $inputs[ $subsection_name ] = $subsection; |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - return $inputs; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - |
|
| 1003 | - /** |
|
| 1004 | - * Gets all the subsections which are a proper form |
|
| 1005 | - * |
|
| 1006 | - * @return EE_Form_Section_Proper[] |
|
| 1007 | - * @throws EE_Error |
|
| 1008 | - */ |
|
| 1009 | - public function subforms() |
|
| 1010 | - { |
|
| 1011 | - $form_sections = array(); |
|
| 1012 | - foreach ($this->subsections() as $name => $obj) { |
|
| 1013 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1014 | - $form_sections[ $name ] = $obj; |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - return $form_sections; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1023 | - * Consider using inputs() or subforms() |
|
| 1024 | - * if you only want form inputs or proper form sections. |
|
| 1025 | - * |
|
| 1026 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1027 | - * leave this as TRUE so that the inputs will be properly |
|
| 1028 | - * configured. However, some client code may be ok with |
|
| 1029 | - * construction finalize being called later |
|
| 1030 | - * (realizing that the subsections' html names might not be |
|
| 1031 | - * set yet, etc.) |
|
| 1032 | - * @return EE_Form_Section_Proper[] |
|
| 1033 | - * @throws EE_Error |
|
| 1034 | - */ |
|
| 1035 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 1036 | - { |
|
| 1037 | - if ($require_construction_to_be_finalized) { |
|
| 1038 | - $this->ensure_construct_finalized_called(); |
|
| 1039 | - } |
|
| 1040 | - return $this->_subsections; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Returns whether this form has any subforms or inputs |
|
| 1046 | - * @return bool |
|
| 1047 | - */ |
|
| 1048 | - public function hasSubsections() |
|
| 1049 | - { |
|
| 1050 | - return ! empty($this->_subsections); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 1056 | - * values. (Similar to calling get_input_value on inputs) |
|
| 1057 | - * |
|
| 1058 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1059 | - * or just this forms' direct children inputs |
|
| 1060 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1061 | - * or allow multidimensional array |
|
| 1062 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1063 | - * with array keys being input names |
|
| 1064 | - * (regardless of whether they are from a subsection or not), |
|
| 1065 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1066 | - * where keys are always subsection names and values are either |
|
| 1067 | - * the input's normalized value, or an array like the top-level array |
|
| 1068 | - * @throws EE_Error |
|
| 1069 | - */ |
|
| 1070 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1071 | - { |
|
| 1072 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1078 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1079 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 1080 | - * where keys are the input names, and values are their display values |
|
| 1081 | - * |
|
| 1082 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1083 | - * or just this forms' direct children inputs |
|
| 1084 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1085 | - * or allow multidimensional array |
|
| 1086 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1087 | - * with array keys being input names |
|
| 1088 | - * (regardless of whether they are from a subsection or not), |
|
| 1089 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1090 | - * where keys are always subsection names and values are either |
|
| 1091 | - * the input's normalized value, or an array like the top-level array |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - */ |
|
| 1094 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1095 | - { |
|
| 1096 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - /** |
|
| 1101 | - * Gets the input values from the form |
|
| 1102 | - * |
|
| 1103 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1104 | - * or just the normalized value |
|
| 1105 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1106 | - * or just this forms' direct children inputs |
|
| 1107 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1108 | - * or allow multidimensional array |
|
| 1109 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1110 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1111 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1112 | - * where keys are always subsection names and values are either |
|
| 1113 | - * the input's normalized value, or an array like the top-level array |
|
| 1114 | - * @throws EE_Error |
|
| 1115 | - */ |
|
| 1116 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1117 | - { |
|
| 1118 | - $input_values = array(); |
|
| 1119 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1120 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1121 | - $input_values[ $subsection_name ] = $pretty |
|
| 1122 | - ? $subsection->pretty_value() |
|
| 1123 | - : $subsection->normalized_value(); |
|
| 1124 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1125 | - $subform_input_values = $subsection->_input_values( |
|
| 1126 | - $pretty, |
|
| 1127 | - $include_subform_inputs, |
|
| 1128 | - $flatten |
|
| 1129 | - ); |
|
| 1130 | - if ($flatten) { |
|
| 1131 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1132 | - } else { |
|
| 1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - return $input_values; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - |
|
| 1141 | - /** |
|
| 1142 | - * Gets the originally submitted input values from the form |
|
| 1143 | - * |
|
| 1144 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1145 | - * or just this forms' direct children inputs |
|
| 1146 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1147 | - * with array keys being input names |
|
| 1148 | - * (regardless of whether they are from a subsection or not), |
|
| 1149 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1150 | - * where keys are always subsection names and values are either |
|
| 1151 | - * the input's normalized value, or an array like the top-level array |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - */ |
|
| 1154 | - public function submitted_values($include_subforms = false) |
|
| 1155 | - { |
|
| 1156 | - $submitted_values = array(); |
|
| 1157 | - foreach ($this->subsections() as $subsection) { |
|
| 1158 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1159 | - // is this input part of an array of inputs? |
|
| 1160 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1162 | - explode( |
|
| 1163 | - '[', |
|
| 1164 | - str_replace(']', '', $subsection->html_name()) |
|
| 1165 | - ), |
|
| 1166 | - $subsection->raw_value() |
|
| 1167 | - ); |
|
| 1168 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1169 | - } else { |
|
| 1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1171 | - } |
|
| 1172 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1173 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1174 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - return $submitted_values; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * Indicates whether or not this form has received a submission yet |
|
| 1183 | - * (ie, had receive_form_submission called on it yet) |
|
| 1184 | - * |
|
| 1185 | - * @return boolean |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - */ |
|
| 1188 | - public function has_received_submission() |
|
| 1189 | - { |
|
| 1190 | - $this->ensure_construct_finalized_called(); |
|
| 1191 | - return $this->_received_submission; |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - /** |
|
| 1196 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1197 | - * Removes the listed inputs from the form |
|
| 1198 | - * |
|
| 1199 | - * @param array $inputs_to_exclude values are the input names |
|
| 1200 | - * @return void |
|
| 1201 | - */ |
|
| 1202 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1203 | - { |
|
| 1204 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1212 | - * @param array $inputs_to_hide |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - */ |
|
| 1215 | - public function hide(array $inputs_to_hide = array()) |
|
| 1216 | - { |
|
| 1217 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1218 | - $input = $this->get_input($input_to_hide); |
|
| 1219 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * add_subsections |
|
| 1226 | - * Adds the listed subsections to the form section. |
|
| 1227 | - * If $subsection_name_to_target is provided, |
|
| 1228 | - * then new subsections are added before or after that subsection, |
|
| 1229 | - * otherwise to the start or end of the entire subsections array. |
|
| 1230 | - * |
|
| 1231 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1232 | - * where keys are their names |
|
| 1233 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1234 | - * should be added before or after |
|
| 1235 | - * IF $subsection_name_to_target is null, |
|
| 1236 | - * then $new_subsections will be added to |
|
| 1237 | - * the beginning or end of the entire subsections array |
|
| 1238 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1239 | - * $subsection_name_to_target, |
|
| 1240 | - * or if $subsection_name_to_target is null, |
|
| 1241 | - * before or after entire subsections array |
|
| 1242 | - * @return void |
|
| 1243 | - * @throws EE_Error |
|
| 1244 | - */ |
|
| 1245 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1246 | - { |
|
| 1247 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1249 | - EE_Error::add_error( |
|
| 1250 | - sprintf( |
|
| 1251 | - esc_html__( |
|
| 1252 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1253 | - 'event_espresso' |
|
| 1254 | - ), |
|
| 1255 | - get_class($subsection), |
|
| 1256 | - $subsection_name, |
|
| 1257 | - $this->name() |
|
| 1258 | - ) |
|
| 1259 | - ); |
|
| 1260 | - unset($new_subsections[ $subsection_name ]); |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1263 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1264 | - $this->_subsections, |
|
| 1265 | - $new_subsections, |
|
| 1266 | - $subsection_name_to_target, |
|
| 1267 | - $add_before |
|
| 1268 | - ); |
|
| 1269 | - if ($this->_construction_finalized) { |
|
| 1270 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1271 | - $subsection->_construct_finalize($this, $name); |
|
| 1272 | - } |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * @param string $subsection_name |
|
| 1279 | - * @param bool $recursive |
|
| 1280 | - * @return bool |
|
| 1281 | - */ |
|
| 1282 | - public function has_subsection($subsection_name, $recursive = false) |
|
| 1283 | - { |
|
| 1284 | - foreach ($this->_subsections as $name => $subsection) {if( |
|
| 1285 | - $name === $subsection_name |
|
| 1286 | - || ( |
|
| 1287 | - $recursive |
|
| 1288 | - && $subsection instanceof EE_Form_Section_Proper |
|
| 1289 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1290 | - ) |
|
| 1291 | - ) { |
|
| 1292 | - return true; |
|
| 1293 | - } |
|
| 1294 | - } |
|
| 1295 | - return false; |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - |
|
| 1299 | - |
|
| 1300 | - /** |
|
| 1301 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1302 | - * |
|
| 1303 | - * @throws EE_Error |
|
| 1304 | - */ |
|
| 1305 | - public function clean_sensitive_data() |
|
| 1306 | - { |
|
| 1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | - $subsection->clean_sensitive_data(); |
|
| 1309 | - } |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1315 | - * @param string $form_submission_error_message |
|
| 1316 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 1317 | - * @throws EE_Error |
|
| 1318 | - */ |
|
| 1319 | - public function set_submission_error_message( |
|
| 1320 | - $form_submission_error_message = '' |
|
| 1321 | - ) { |
|
| 1322 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1323 | - ? $form_submission_error_message |
|
| 1324 | - : $this->getAllValidationErrorsString(); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1330 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 1331 | - * set_submission_error_message |
|
| 1332 | - * |
|
| 1333 | - * @return string |
|
| 1334 | - */ |
|
| 1335 | - public function submission_error_message() |
|
| 1336 | - { |
|
| 1337 | - return $this->_form_submission_error_message; |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 1343 | - * @param string $form_submission_success_message |
|
| 1344 | - */ |
|
| 1345 | - public function set_submission_success_message($form_submission_success_message = '') |
|
| 1346 | - { |
|
| 1347 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1348 | - ? $form_submission_success_message |
|
| 1349 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 1355 | - * @return string |
|
| 1356 | - */ |
|
| 1357 | - public function submission_success_message() |
|
| 1358 | - { |
|
| 1359 | - return $this->_form_submission_success_message; |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * Returns the prefix that should be used on child of this form section for |
|
| 1365 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1366 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1367 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1368 | - * |
|
| 1369 | - * @return string |
|
| 1370 | - * @throws EE_Error |
|
| 1371 | - */ |
|
| 1372 | - public function html_name_prefix() |
|
| 1373 | - { |
|
| 1374 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1376 | - } |
|
| 1377 | - return $this->name(); |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1383 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1384 | - * was set, which is probably nothing, or the classname) |
|
| 1385 | - * |
|
| 1386 | - * @return string |
|
| 1387 | - * @throws EE_Error |
|
| 1388 | - */ |
|
| 1389 | - public function name() |
|
| 1390 | - { |
|
| 1391 | - $this->ensure_construct_finalized_called(); |
|
| 1392 | - return parent::name(); |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * @return EE_Form_Section_Proper |
|
| 1398 | - * @throws EE_Error |
|
| 1399 | - */ |
|
| 1400 | - public function parent_section() |
|
| 1401 | - { |
|
| 1402 | - $this->ensure_construct_finalized_called(); |
|
| 1403 | - return parent::parent_section(); |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - |
|
| 1407 | - /** |
|
| 1408 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1409 | - * |
|
| 1410 | - * @return void |
|
| 1411 | - * @throws EE_Error |
|
| 1412 | - */ |
|
| 1413 | - public function ensure_construct_finalized_called() |
|
| 1414 | - { |
|
| 1415 | - if (! $this->_construction_finalized) { |
|
| 1416 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1423 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1424 | - * |
|
| 1425 | - * @param array $req_data |
|
| 1426 | - * @return boolean |
|
| 1427 | - * @throws EE_Error |
|
| 1428 | - */ |
|
| 1429 | - public function form_data_present_in($req_data = null) |
|
| 1430 | - { |
|
| 1431 | - $req_data = $this->getCachedRequest($req_data); |
|
| 1432 | - foreach ($this->subsections() as $subsection) { |
|
| 1433 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1434 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1435 | - return true; |
|
| 1436 | - } |
|
| 1437 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1438 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1439 | - return true; |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - |
|
| 1447 | - /** |
|
| 1448 | - * Gets validation errors for this form section and subsections |
|
| 1449 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1450 | - * gets the validation errors for ALL subsection |
|
| 1451 | - * |
|
| 1452 | - * @return EE_Validation_Error[] |
|
| 1453 | - * @throws EE_Error |
|
| 1454 | - */ |
|
| 1455 | - public function get_validation_errors_accumulated() |
|
| 1456 | - { |
|
| 1457 | - $validation_errors = $this->get_validation_errors(); |
|
| 1458 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1459 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1460 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1461 | - } else { |
|
| 1462 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1463 | - } |
|
| 1464 | - if ($validation_errors_on_this_subsection) { |
|
| 1465 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1466 | - } |
|
| 1467 | - } |
|
| 1468 | - return $validation_errors; |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1473 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1474 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1475 | - * |
|
| 1476 | - * @return string |
|
| 1477 | - * @since 4.9.59.p |
|
| 1478 | - */ |
|
| 1479 | - protected function getAllValidationErrorsString() |
|
| 1480 | - { |
|
| 1481 | - $submission_error_messages = array(); |
|
| 1482 | - // bad, bad, bad registrant |
|
| 1483 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1484 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1485 | - $form_section = $validation_error->get_form_section(); |
|
| 1486 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1487 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1488 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1489 | - $label = $validation_error->get_form_section()->name(); |
|
| 1490 | - } else { |
|
| 1491 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1492 | - } |
|
| 1493 | - $submission_error_messages[] = sprintf( |
|
| 1494 | - __('%s : %s', 'event_espresso'), |
|
| 1495 | - $label, |
|
| 1496 | - $validation_error->getMessage() |
|
| 1497 | - ); |
|
| 1498 | - } |
|
| 1499 | - } |
|
| 1500 | - return implode('<br', $submission_error_messages); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - /** |
|
| 1505 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1506 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1507 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1508 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1509 | - * which will be returned. |
|
| 1510 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1511 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1512 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1513 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1514 | - * Etc |
|
| 1515 | - * |
|
| 1516 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1517 | - * @return EE_Form_Section_Base |
|
| 1518 | - * @throws EE_Error |
|
| 1519 | - */ |
|
| 1520 | - public function find_section_from_path($form_section_path) |
|
| 1521 | - { |
|
| 1522 | - //check if we can find the input from purely going straight up the tree |
|
| 1523 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1524 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1525 | - return $input; |
|
| 1526 | - } |
|
| 1527 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1528 | - if ($next_slash_pos !== false) { |
|
| 1529 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1530 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1531 | - } else { |
|
| 1532 | - $child_section_name = $form_section_path; |
|
| 1533 | - $subpath = ''; |
|
| 1534 | - } |
|
| 1535 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1536 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1537 | - return $child_section->find_section_from_path($subpath); |
|
| 1538 | - } |
|
| 1539 | - return null; |
|
| 1540 | - } |
|
| 17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Subsections |
|
| 21 | + * |
|
| 22 | + * @var EE_Form_Section_Validatable[] |
|
| 23 | + */ |
|
| 24 | + protected $_subsections = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Strategy for laying out the form |
|
| 28 | + * |
|
| 29 | + * @var EE_Form_Section_Layout_Base |
|
| 30 | + */ |
|
| 31 | + protected $_layout_strategy; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Whether or not this form has received and validated a form submission yet |
|
| 35 | + * |
|
| 36 | + * @var boolean |
|
| 37 | + */ |
|
| 38 | + protected $_received_submission = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * message displayed to users upon successful form submission |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $_form_submission_success_message = ''; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * message displayed to users upon unsuccessful form submission |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + protected $_form_submission_error_message = ''; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var array like $_REQUEST |
|
| 56 | + */ |
|
| 57 | + protected $cached_request_data; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 61 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
| 62 | + * @var boolean|null |
|
| 63 | + */ |
|
| 64 | + protected $is_valid; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Stores all the data that will localized for form validation |
|
| 68 | + * |
|
| 69 | + * @var array |
|
| 70 | + */ |
|
| 71 | + static protected $_js_localization = array(); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * whether or not the form's localized validation JS vars have been set |
|
| 75 | + * |
|
| 76 | + * @type boolean |
|
| 77 | + */ |
|
| 78 | + static protected $_scripts_localized = false; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 83 | + * so that they know who their parent is, and what name they've been given. |
|
| 84 | + * |
|
| 85 | + * @param array[] $options_array { |
|
| 86 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 87 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 88 | + * and in that order. This is handy if you want |
|
| 89 | + * the subsections to be ordered differently than the default, and if you override |
|
| 90 | + * which fields are shown |
|
| 91 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 92 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 93 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 94 | + * items from that list of inclusions) |
|
| 95 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 96 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function __construct($options_array = array()) |
|
| 100 | + { |
|
| 101 | + $options_array = (array) apply_filters( |
|
| 102 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 103 | + $options_array, |
|
| 104 | + $this |
|
| 105 | + ); |
|
| 106 | + //call parent first, as it may be setting the name |
|
| 107 | + parent::__construct($options_array); |
|
| 108 | + //if they've included subsections in the constructor, add them now |
|
| 109 | + if (isset($options_array['include'])) { |
|
| 110 | + //we are going to make sure we ONLY have those subsections to include |
|
| 111 | + //AND we are going to make sure they're in that specified order |
|
| 112 | + $reordered_subsections = array(); |
|
| 113 | + foreach ($options_array['include'] as $input_name) { |
|
| 114 | + if (isset($this->_subsections[ $input_name ])) { |
|
| 115 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $this->_subsections = $reordered_subsections; |
|
| 119 | + } |
|
| 120 | + if (isset($options_array['exclude'])) { |
|
| 121 | + $exclude = $options_array['exclude']; |
|
| 122 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 123 | + } |
|
| 124 | + if (isset($options_array['layout_strategy'])) { |
|
| 125 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 126 | + } |
|
| 127 | + if (! $this->_layout_strategy) { |
|
| 128 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 129 | + } |
|
| 130 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 131 | + //ok so we are definitely going to want the forms JS, |
|
| 132 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 133 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 134 | + //ok so they've constructed this object after when they should have. |
|
| 135 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 136 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 137 | + } else { |
|
| 138 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 139 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | + } |
|
| 141 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 142 | + /** |
|
| 143 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 144 | + * The form probably doesn't yet have a parent form section. |
|
| 145 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 146 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 147 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 148 | + * |
|
| 149 | + * @since 4.9.32 |
|
| 150 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 151 | + * except maybe calling _construct_finalize has been done |
|
| 152 | + * @param array $options_array options passed into the constructor |
|
| 153 | + */ |
|
| 154 | + do_action( |
|
| 155 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 156 | + $this, |
|
| 157 | + $options_array |
|
| 158 | + ); |
|
| 159 | + if (isset($options_array['name'])) { |
|
| 160 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Finishes construction given the parent form section and this form section's name |
|
| 167 | + * |
|
| 168 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 169 | + * @param string $name |
|
| 170 | + * @throws EE_Error |
|
| 171 | + */ |
|
| 172 | + public function _construct_finalize($parent_form_section, $name) |
|
| 173 | + { |
|
| 174 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 175 | + $this->_set_default_name_if_empty(); |
|
| 176 | + $this->_set_default_html_id_if_empty(); |
|
| 177 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 178 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 179 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 180 | + } else { |
|
| 181 | + throw new EE_Error( |
|
| 182 | + sprintf( |
|
| 183 | + esc_html__( |
|
| 184 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 185 | + 'event_espresso' |
|
| 186 | + ), |
|
| 187 | + $subsection_name, |
|
| 188 | + get_class($this), |
|
| 189 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + /** |
|
| 195 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 196 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 197 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 198 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 199 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 200 | + * ensured it has a name, HTML IDs, etc |
|
| 201 | + * |
|
| 202 | + * @param EE_Form_Section_Proper $this |
|
| 203 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 204 | + * @param string $name |
|
| 205 | + */ |
|
| 206 | + do_action( |
|
| 207 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 208 | + $this, |
|
| 209 | + $parent_form_section, |
|
| 210 | + $name |
|
| 211 | + ); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Gets the layout strategy for this form section |
|
| 217 | + * |
|
| 218 | + * @return EE_Form_Section_Layout_Base |
|
| 219 | + */ |
|
| 220 | + public function get_layout_strategy() |
|
| 221 | + { |
|
| 222 | + return $this->_layout_strategy; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Gets the HTML for a single input for this form section according |
|
| 228 | + * to the layout strategy |
|
| 229 | + * |
|
| 230 | + * @param EE_Form_Input_Base $input |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + public function get_html_for_input($input) |
|
| 234 | + { |
|
| 235 | + return $this->_layout_strategy->layout_input($input); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * was_submitted - checks if form inputs are present in request data |
|
| 241 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 242 | + * proper form sections and form inputs) |
|
| 243 | + * |
|
| 244 | + * @param null $form_data |
|
| 245 | + * @return boolean |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + public function was_submitted($form_data = null) |
|
| 249 | + { |
|
| 250 | + return $this->form_data_present_in($form_data); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 255 | + * something different, refresh the cache, and then return it |
|
| 256 | + * @param null $req_data |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + protected function getCachedRequest($req_data = null) |
|
| 260 | + { |
|
| 261 | + if ($this->cached_request_data === null |
|
| 262 | + || ( |
|
| 263 | + $req_data !== null && |
|
| 264 | + $req_data !== $this->cached_request_data |
|
| 265 | + ) |
|
| 266 | + ) { |
|
| 267 | + $req_data = apply_filters( |
|
| 268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 269 | + $req_data, |
|
| 270 | + $this |
|
| 271 | + ); |
|
| 272 | + if ($req_data === null) { |
|
| 273 | + $req_data = array_merge($_GET, $_POST); |
|
| 274 | + } |
|
| 275 | + $req_data = apply_filters( |
|
| 276 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 277 | + $req_data, |
|
| 278 | + $this |
|
| 279 | + ); |
|
| 280 | + $this->cached_request_data = (array)$req_data; |
|
| 281 | + } |
|
| 282 | + return $this->cached_request_data; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 288 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 289 | + * |
|
| 290 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 291 | + * However, you CAN supply a different array. |
|
| 292 | + * Consider using set_defaults() instead however. |
|
| 293 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 294 | + * the inputs will have the correct name in the request data for this function |
|
| 295 | + * to find them and populate the form with them. |
|
| 296 | + * If you have a flat form (with only input subsections), |
|
| 297 | + * you can supply a flat array where keys |
|
| 298 | + * are the form input names and values are their values) |
|
| 299 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 300 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 301 | + * But if the data has already been validated |
|
| 302 | + * (eg you validated the data then stored it in the DB) |
|
| 303 | + * you may want to skip this step. |
|
| 304 | + * @throws InvalidArgumentException |
|
| 305 | + * @throws InvalidInterfaceException |
|
| 306 | + * @throws InvalidDataTypeException |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 310 | + { |
|
| 311 | + $req_data = $this->getCachedRequest($req_data); |
|
| 312 | + $this->_normalize($req_data); |
|
| 313 | + if ($validate) { |
|
| 314 | + $this->_validate(); |
|
| 315 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 316 | + if (! $this->is_valid()) { |
|
| 317 | + $this->store_submitted_form_data_in_session(); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 321 | + $this->set_submission_error_message(); |
|
| 322 | + } |
|
| 323 | + do_action( |
|
| 324 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 325 | + $req_data, |
|
| 326 | + $this, |
|
| 327 | + $validate |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * caches the originally submitted input values in the session |
|
| 334 | + * so that they can be used to repopulate the form if it failed validation |
|
| 335 | + * |
|
| 336 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 337 | + * @throws InvalidArgumentException |
|
| 338 | + * @throws InvalidInterfaceException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws EE_Error |
|
| 341 | + */ |
|
| 342 | + protected function store_submitted_form_data_in_session() |
|
| 343 | + { |
|
| 344 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 345 | + array( |
|
| 346 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 347 | + ) |
|
| 348 | + ); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * retrieves the originally submitted input values in the session |
|
| 354 | + * so that they can be used to repopulate the form if it failed validation |
|
| 355 | + * |
|
| 356 | + * @return array |
|
| 357 | + * @throws InvalidArgumentException |
|
| 358 | + * @throws InvalidInterfaceException |
|
| 359 | + * @throws InvalidDataTypeException |
|
| 360 | + */ |
|
| 361 | + protected function get_submitted_form_data_from_session() |
|
| 362 | + { |
|
| 363 | + $session = EE_Registry::instance()->SSN; |
|
| 364 | + if ($session instanceof EE_Session) { |
|
| 365 | + return $session->get_session_data( |
|
| 366 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 367 | + ); |
|
| 368 | + } |
|
| 369 | + return array(); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * flushed the originally submitted input values from the session |
|
| 375 | + * |
|
| 376 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 377 | + * @throws InvalidArgumentException |
|
| 378 | + * @throws InvalidInterfaceException |
|
| 379 | + * @throws InvalidDataTypeException |
|
| 380 | + */ |
|
| 381 | + protected function flush_submitted_form_data_from_session() |
|
| 382 | + { |
|
| 383 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 384 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 385 | + ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Populates this form and its subsections with data from the session. |
|
| 391 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 392 | + * validation errors when displaying too) |
|
| 393 | + * Returns true if the form was populated from the session, false otherwise |
|
| 394 | + * |
|
| 395 | + * @return boolean |
|
| 396 | + * @throws InvalidArgumentException |
|
| 397 | + * @throws InvalidInterfaceException |
|
| 398 | + * @throws InvalidDataTypeException |
|
| 399 | + * @throws EE_Error |
|
| 400 | + */ |
|
| 401 | + public function populate_from_session() |
|
| 402 | + { |
|
| 403 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 404 | + if (empty($form_data_in_session)) { |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | + $this->receive_form_submission($form_data_in_session); |
|
| 408 | + $this->flush_submitted_form_data_from_session(); |
|
| 409 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 410 | + return true; |
|
| 411 | + } |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Populates the default data for the form, given an array where keys are |
|
| 418 | + * the input names, and values are their values (preferably normalized to be their |
|
| 419 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 420 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 421 | + * the value being an array formatted in teh same way |
|
| 422 | + * |
|
| 423 | + * @param array $default_data |
|
| 424 | + * @throws EE_Error |
|
| 425 | + */ |
|
| 426 | + public function populate_defaults($default_data) |
|
| 427 | + { |
|
| 428 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 429 | + if (isset($default_data[ $subsection_name ])) { |
|
| 430 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 431 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
| 432 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 433 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * returns true if subsection exists |
|
| 442 | + * |
|
| 443 | + * @param string $name |
|
| 444 | + * @return boolean |
|
| 445 | + */ |
|
| 446 | + public function subsection_exists($name) |
|
| 447 | + { |
|
| 448 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Gets the subsection specified by its name |
|
| 454 | + * |
|
| 455 | + * @param string $name |
|
| 456 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 457 | + * so that the inputs will be properly configured. |
|
| 458 | + * However, some client code may be ok |
|
| 459 | + * with construction finalize being called later |
|
| 460 | + * (realizing that the subsections' html names |
|
| 461 | + * might not be set yet, etc.) |
|
| 462 | + * @return EE_Form_Section_Base |
|
| 463 | + * @throws EE_Error |
|
| 464 | + */ |
|
| 465 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 466 | + { |
|
| 467 | + if ($require_construction_to_be_finalized) { |
|
| 468 | + $this->ensure_construct_finalized_called(); |
|
| 469 | + } |
|
| 470 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Gets all the validatable subsections of this form section |
|
| 476 | + * |
|
| 477 | + * @return EE_Form_Section_Validatable[] |
|
| 478 | + * @throws EE_Error |
|
| 479 | + */ |
|
| 480 | + public function get_validatable_subsections() |
|
| 481 | + { |
|
| 482 | + $validatable_subsections = array(); |
|
| 483 | + foreach ($this->subsections() as $name => $obj) { |
|
| 484 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 485 | + $validatable_subsections[ $name ] = $obj; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + return $validatable_subsections; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 494 | + * throw an EE_Error. |
|
| 495 | + * |
|
| 496 | + * @param string $name |
|
| 497 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 498 | + * leave this as TRUE so that the inputs will be properly |
|
| 499 | + * configured. However, some client code may be ok with |
|
| 500 | + * construction finalize being called later |
|
| 501 | + * (realizing that the subsections' html names might not be |
|
| 502 | + * set yet, etc.) |
|
| 503 | + * @return EE_Form_Input_Base |
|
| 504 | + * @throws EE_Error |
|
| 505 | + */ |
|
| 506 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 507 | + { |
|
| 508 | + $subsection = $this->get_subsection( |
|
| 509 | + $name, |
|
| 510 | + $require_construction_to_be_finalized |
|
| 511 | + ); |
|
| 512 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 513 | + throw new EE_Error( |
|
| 514 | + sprintf( |
|
| 515 | + esc_html__( |
|
| 516 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 517 | + 'event_espresso' |
|
| 518 | + ), |
|
| 519 | + $name, |
|
| 520 | + get_class($this), |
|
| 521 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 522 | + ) |
|
| 523 | + ); |
|
| 524 | + } |
|
| 525 | + return $subsection; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 531 | + * otherwise throws an EE_Error |
|
| 532 | + * |
|
| 533 | + * @param string $name |
|
| 534 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 535 | + * leave this as TRUE so that the inputs will be properly |
|
| 536 | + * configured. However, some client code may be ok with |
|
| 537 | + * construction finalize being called later |
|
| 538 | + * (realizing that the subsections' html names might not be |
|
| 539 | + * set yet, etc.) |
|
| 540 | + * @return EE_Form_Section_Proper |
|
| 541 | + * @throws EE_Error |
|
| 542 | + */ |
|
| 543 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 544 | + { |
|
| 545 | + $subsection = $this->get_subsection( |
|
| 546 | + $name, |
|
| 547 | + $require_construction_to_be_finalized |
|
| 548 | + ); |
|
| 549 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 550 | + throw new EE_Error( |
|
| 551 | + sprintf( |
|
| 552 | + esc_html__( |
|
| 553 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 554 | + 'event_espresso' |
|
| 555 | + ), |
|
| 556 | + $name, |
|
| 557 | + get_class($this) |
|
| 558 | + ) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + return $subsection; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 567 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 568 | + * |
|
| 569 | + * @param string $name |
|
| 570 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 571 | + * @throws EE_Error |
|
| 572 | + */ |
|
| 573 | + public function get_input_value($name) |
|
| 574 | + { |
|
| 575 | + $input = $this->get_input($name); |
|
| 576 | + return $input->normalized_value(); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 582 | + * |
|
| 583 | + * @throws EE_Error |
|
| 584 | + * @return boolean |
|
| 585 | + */ |
|
| 586 | + public function is_valid() |
|
| 587 | + { |
|
| 588 | + if($this->is_valid === null) { |
|
| 589 | + if (! $this->has_received_submission()) { |
|
| 590 | + throw new EE_Error( |
|
| 591 | + sprintf( |
|
| 592 | + esc_html__( |
|
| 593 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 594 | + 'event_espresso' |
|
| 595 | + ) |
|
| 596 | + ) |
|
| 597 | + ); |
|
| 598 | + } |
|
| 599 | + if (! parent::is_valid()) { |
|
| 600 | + $this->is_valid = false; |
|
| 601 | + } else { |
|
| 602 | + // ok so no general errors to this entire form section. |
|
| 603 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 604 | + $this->is_valid = true; |
|
| 605 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 606 | + if (! $subsection->is_valid()) { |
|
| 607 | + $this->is_valid = false; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + return $this->is_valid; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * gets the default name of this form section if none is specified |
|
| 618 | + * |
|
| 619 | + * @return void |
|
| 620 | + */ |
|
| 621 | + protected function _set_default_name_if_empty() |
|
| 622 | + { |
|
| 623 | + if (! $this->_name) { |
|
| 624 | + $classname = get_class($this); |
|
| 625 | + $default_name = str_replace('EE_', '', $classname); |
|
| 626 | + $this->_name = $default_name; |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 633 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 634 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 635 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 636 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 637 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 638 | + * any CSS. |
|
| 639 | + * |
|
| 640 | + * @throws InvalidArgumentException |
|
| 641 | + * @throws InvalidInterfaceException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws EE_Error |
|
| 644 | + */ |
|
| 645 | + public function get_html_and_js() |
|
| 646 | + { |
|
| 647 | + $this->enqueue_js(); |
|
| 648 | + return $this->get_html(); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 654 | + * |
|
| 655 | + * @param bool $display_previously_submitted_data |
|
| 656 | + * @return string |
|
| 657 | + * @throws InvalidArgumentException |
|
| 658 | + * @throws InvalidInterfaceException |
|
| 659 | + * @throws InvalidDataTypeException |
|
| 660 | + * @throws EE_Error |
|
| 661 | + * @throws EE_Error |
|
| 662 | + * @throws EE_Error |
|
| 663 | + */ |
|
| 664 | + public function get_html($display_previously_submitted_data = true) |
|
| 665 | + { |
|
| 666 | + $this->ensure_construct_finalized_called(); |
|
| 667 | + if ($display_previously_submitted_data) { |
|
| 668 | + $this->populate_from_session(); |
|
| 669 | + } |
|
| 670 | + return $this->_form_html_filter |
|
| 671 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 672 | + : $this->_layout_strategy->layout_form(); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * enqueues JS and CSS for the form. |
|
| 678 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 679 | + * scripts and styles can be put in the header, but if called later |
|
| 680 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 681 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 682 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 683 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 684 | + * |
|
| 685 | + * @return void |
|
| 686 | + * @throws EE_Error |
|
| 687 | + */ |
|
| 688 | + public function enqueue_js() |
|
| 689 | + { |
|
| 690 | + $this->_enqueue_and_localize_form_js(); |
|
| 691 | + foreach ($this->subsections() as $subsection) { |
|
| 692 | + $subsection->enqueue_js(); |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 699 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 700 | + * the wp_enqueue_scripts hook. |
|
| 701 | + * However, registering the form js and localizing it can happen when we |
|
| 702 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 703 | + * could change until it's actually outputted) |
|
| 704 | + * |
|
| 705 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 706 | + * to be triggered automatically or not |
|
| 707 | + * @return void |
|
| 708 | + */ |
|
| 709 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 710 | + { |
|
| 711 | + wp_register_script( |
|
| 712 | + 'ee_form_section_validation', |
|
| 713 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 714 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 715 | + EVENT_ESPRESSO_VERSION, |
|
| 716 | + true |
|
| 717 | + ); |
|
| 718 | + wp_localize_script( |
|
| 719 | + 'ee_form_section_validation', |
|
| 720 | + 'ee_form_section_validation_init', |
|
| 721 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 722 | + ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * gets the variables used by form_section_validation.js. |
|
| 728 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 729 | + * but before the wordpress hook wp_loaded |
|
| 730 | + * |
|
| 731 | + * @throws EE_Error |
|
| 732 | + */ |
|
| 733 | + public function _enqueue_and_localize_form_js() |
|
| 734 | + { |
|
| 735 | + $this->ensure_construct_finalized_called(); |
|
| 736 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 737 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 738 | + //and localize it just before the footer |
|
| 739 | + $this->localize_validation_rules(); |
|
| 740 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 741 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * add our form section data to a static variable accessible by all form sections |
|
| 747 | + * |
|
| 748 | + * @param bool $return_for_subsection |
|
| 749 | + * @return void |
|
| 750 | + * @throws EE_Error |
|
| 751 | + */ |
|
| 752 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 753 | + { |
|
| 754 | + // we only want to localize vars ONCE for the entire form, |
|
| 755 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 756 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 757 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 758 | + 'form_section_id' => $this->html_id(true), |
|
| 759 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 760 | + 'other_data' => $this->get_other_js_data(), |
|
| 761 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 762 | + ); |
|
| 763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 770 | + * This is primarily data added by inputs and forms in addition to any |
|
| 771 | + * scripts they might enqueue |
|
| 772 | + * |
|
| 773 | + * @param array $form_other_js_data |
|
| 774 | + * @return array |
|
| 775 | + * @throws EE_Error |
|
| 776 | + */ |
|
| 777 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 778 | + { |
|
| 779 | + foreach ($this->subsections() as $subsection) { |
|
| 780 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 781 | + } |
|
| 782 | + return $form_other_js_data; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 788 | + * Keys are their form names, and values are the inputs themselves |
|
| 789 | + * |
|
| 790 | + * @return EE_Form_Input_Base |
|
| 791 | + * @throws EE_Error |
|
| 792 | + */ |
|
| 793 | + public function inputs_in_subsections() |
|
| 794 | + { |
|
| 795 | + $inputs = array(); |
|
| 796 | + foreach ($this->subsections() as $subsection) { |
|
| 797 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 798 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
| 799 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 800 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + return $inputs; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Gets a flat array of all the validation errors. |
|
| 809 | + * Keys are html names (because those should be unique) |
|
| 810 | + * and values are a string of all their validation errors |
|
| 811 | + * |
|
| 812 | + * @return string[] |
|
| 813 | + * @throws EE_Error |
|
| 814 | + */ |
|
| 815 | + public function subsection_validation_errors_by_html_name() |
|
| 816 | + { |
|
| 817 | + $inputs = $this->inputs(); |
|
| 818 | + $errors = array(); |
|
| 819 | + foreach ($inputs as $form_input) { |
|
| 820 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 821 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + return $errors; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 830 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 831 | + * |
|
| 832 | + * @throws InvalidArgumentException |
|
| 833 | + * @throws InvalidInterfaceException |
|
| 834 | + * @throws InvalidDataTypeException |
|
| 835 | + */ |
|
| 836 | + public static function localize_script_for_all_forms() |
|
| 837 | + { |
|
| 838 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 839 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 840 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 841 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 842 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 843 | + : 'wp_default'; |
|
| 844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 845 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 846 | + wp_localize_script( |
|
| 847 | + 'ee_form_section_validation', |
|
| 848 | + 'ee_form_section_vars', |
|
| 849 | + EE_Form_Section_Proper::$_js_localization |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * ensure_scripts_localized |
|
| 856 | + * |
|
| 857 | + * @throws EE_Error |
|
| 858 | + */ |
|
| 859 | + public function ensure_scripts_localized() |
|
| 860 | + { |
|
| 861 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 862 | + $this->_enqueue_and_localize_form_js(); |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 869 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 870 | + * |
|
| 871 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 872 | + */ |
|
| 873 | + private static function _get_localized_error_messages() |
|
| 874 | + { |
|
| 875 | + return array( |
|
| 876 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
| 877 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
| 878 | + ); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * @return array |
|
| 884 | + */ |
|
| 885 | + public static function js_localization() |
|
| 886 | + { |
|
| 887 | + return self::$_js_localization; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * @return void |
|
| 893 | + */ |
|
| 894 | + public static function reset_js_localization() |
|
| 895 | + { |
|
| 896 | + self::$_js_localization = array(); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 902 | + * See parent function for more... |
|
| 903 | + * |
|
| 904 | + * @return array |
|
| 905 | + * @throws EE_Error |
|
| 906 | + */ |
|
| 907 | + public function get_jquery_validation_rules() |
|
| 908 | + { |
|
| 909 | + $jquery_validation_rules = array(); |
|
| 910 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 911 | + $jquery_validation_rules = array_merge( |
|
| 912 | + $jquery_validation_rules, |
|
| 913 | + $subsection->get_jquery_validation_rules() |
|
| 914 | + ); |
|
| 915 | + } |
|
| 916 | + return $jquery_validation_rules; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 922 | + * |
|
| 923 | + * @param array $req_data like $_POST |
|
| 924 | + * @return void |
|
| 925 | + * @throws EE_Error |
|
| 926 | + */ |
|
| 927 | + protected function _normalize($req_data) |
|
| 928 | + { |
|
| 929 | + $this->_received_submission = true; |
|
| 930 | + $this->_validation_errors = array(); |
|
| 931 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 932 | + try { |
|
| 933 | + $subsection->_normalize($req_data); |
|
| 934 | + } catch (EE_Validation_Error $e) { |
|
| 935 | + $subsection->add_validation_error($e); |
|
| 936 | + } |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + /** |
|
| 942 | + * Performs validation on this form section and its subsections. |
|
| 943 | + * For each subsection, |
|
| 944 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 945 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 946 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 947 | + * you would be best to override this _validate method, |
|
| 948 | + * calling parent::_validate() first. |
|
| 949 | + * |
|
| 950 | + * @throws EE_Error |
|
| 951 | + */ |
|
| 952 | + protected function _validate() |
|
| 953 | + { |
|
| 954 | + //reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 955 | + $this->is_valid = null; |
|
| 956 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 957 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 958 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 959 | + } |
|
| 960 | + $subsection->_validate(); |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Gets all the validated inputs for the form section |
|
| 967 | + * |
|
| 968 | + * @return array |
|
| 969 | + * @throws EE_Error |
|
| 970 | + */ |
|
| 971 | + public function valid_data() |
|
| 972 | + { |
|
| 973 | + $inputs = array(); |
|
| 974 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 975 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 976 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 977 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 978 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + return $inputs; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * Gets all the inputs on this form section |
|
| 987 | + * |
|
| 988 | + * @return EE_Form_Input_Base[] |
|
| 989 | + * @throws EE_Error |
|
| 990 | + */ |
|
| 991 | + public function inputs() |
|
| 992 | + { |
|
| 993 | + $inputs = array(); |
|
| 994 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 995 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 996 | + $inputs[ $subsection_name ] = $subsection; |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + return $inputs; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + |
|
| 1003 | + /** |
|
| 1004 | + * Gets all the subsections which are a proper form |
|
| 1005 | + * |
|
| 1006 | + * @return EE_Form_Section_Proper[] |
|
| 1007 | + * @throws EE_Error |
|
| 1008 | + */ |
|
| 1009 | + public function subforms() |
|
| 1010 | + { |
|
| 1011 | + $form_sections = array(); |
|
| 1012 | + foreach ($this->subsections() as $name => $obj) { |
|
| 1013 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1014 | + $form_sections[ $name ] = $obj; |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + return $form_sections; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1023 | + * Consider using inputs() or subforms() |
|
| 1024 | + * if you only want form inputs or proper form sections. |
|
| 1025 | + * |
|
| 1026 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1027 | + * leave this as TRUE so that the inputs will be properly |
|
| 1028 | + * configured. However, some client code may be ok with |
|
| 1029 | + * construction finalize being called later |
|
| 1030 | + * (realizing that the subsections' html names might not be |
|
| 1031 | + * set yet, etc.) |
|
| 1032 | + * @return EE_Form_Section_Proper[] |
|
| 1033 | + * @throws EE_Error |
|
| 1034 | + */ |
|
| 1035 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 1036 | + { |
|
| 1037 | + if ($require_construction_to_be_finalized) { |
|
| 1038 | + $this->ensure_construct_finalized_called(); |
|
| 1039 | + } |
|
| 1040 | + return $this->_subsections; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Returns whether this form has any subforms or inputs |
|
| 1046 | + * @return bool |
|
| 1047 | + */ |
|
| 1048 | + public function hasSubsections() |
|
| 1049 | + { |
|
| 1050 | + return ! empty($this->_subsections); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 1056 | + * values. (Similar to calling get_input_value on inputs) |
|
| 1057 | + * |
|
| 1058 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1059 | + * or just this forms' direct children inputs |
|
| 1060 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1061 | + * or allow multidimensional array |
|
| 1062 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1063 | + * with array keys being input names |
|
| 1064 | + * (regardless of whether they are from a subsection or not), |
|
| 1065 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1066 | + * where keys are always subsection names and values are either |
|
| 1067 | + * the input's normalized value, or an array like the top-level array |
|
| 1068 | + * @throws EE_Error |
|
| 1069 | + */ |
|
| 1070 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1071 | + { |
|
| 1072 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1078 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1079 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 1080 | + * where keys are the input names, and values are their display values |
|
| 1081 | + * |
|
| 1082 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1083 | + * or just this forms' direct children inputs |
|
| 1084 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1085 | + * or allow multidimensional array |
|
| 1086 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1087 | + * with array keys being input names |
|
| 1088 | + * (regardless of whether they are from a subsection or not), |
|
| 1089 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1090 | + * where keys are always subsection names and values are either |
|
| 1091 | + * the input's normalized value, or an array like the top-level array |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + */ |
|
| 1094 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1095 | + { |
|
| 1096 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + /** |
|
| 1101 | + * Gets the input values from the form |
|
| 1102 | + * |
|
| 1103 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1104 | + * or just the normalized value |
|
| 1105 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1106 | + * or just this forms' direct children inputs |
|
| 1107 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1108 | + * or allow multidimensional array |
|
| 1109 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1110 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1111 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1112 | + * where keys are always subsection names and values are either |
|
| 1113 | + * the input's normalized value, or an array like the top-level array |
|
| 1114 | + * @throws EE_Error |
|
| 1115 | + */ |
|
| 1116 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1117 | + { |
|
| 1118 | + $input_values = array(); |
|
| 1119 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1120 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1121 | + $input_values[ $subsection_name ] = $pretty |
|
| 1122 | + ? $subsection->pretty_value() |
|
| 1123 | + : $subsection->normalized_value(); |
|
| 1124 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1125 | + $subform_input_values = $subsection->_input_values( |
|
| 1126 | + $pretty, |
|
| 1127 | + $include_subform_inputs, |
|
| 1128 | + $flatten |
|
| 1129 | + ); |
|
| 1130 | + if ($flatten) { |
|
| 1131 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1132 | + } else { |
|
| 1133 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + return $input_values; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * Gets the originally submitted input values from the form |
|
| 1143 | + * |
|
| 1144 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1145 | + * or just this forms' direct children inputs |
|
| 1146 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1147 | + * with array keys being input names |
|
| 1148 | + * (regardless of whether they are from a subsection or not), |
|
| 1149 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1150 | + * where keys are always subsection names and values are either |
|
| 1151 | + * the input's normalized value, or an array like the top-level array |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + */ |
|
| 1154 | + public function submitted_values($include_subforms = false) |
|
| 1155 | + { |
|
| 1156 | + $submitted_values = array(); |
|
| 1157 | + foreach ($this->subsections() as $subsection) { |
|
| 1158 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1159 | + // is this input part of an array of inputs? |
|
| 1160 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1162 | + explode( |
|
| 1163 | + '[', |
|
| 1164 | + str_replace(']', '', $subsection->html_name()) |
|
| 1165 | + ), |
|
| 1166 | + $subsection->raw_value() |
|
| 1167 | + ); |
|
| 1168 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1169 | + } else { |
|
| 1170 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1171 | + } |
|
| 1172 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1173 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1174 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + return $submitted_values; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * Indicates whether or not this form has received a submission yet |
|
| 1183 | + * (ie, had receive_form_submission called on it yet) |
|
| 1184 | + * |
|
| 1185 | + * @return boolean |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + */ |
|
| 1188 | + public function has_received_submission() |
|
| 1189 | + { |
|
| 1190 | + $this->ensure_construct_finalized_called(); |
|
| 1191 | + return $this->_received_submission; |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + /** |
|
| 1196 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1197 | + * Removes the listed inputs from the form |
|
| 1198 | + * |
|
| 1199 | + * @param array $inputs_to_exclude values are the input names |
|
| 1200 | + * @return void |
|
| 1201 | + */ |
|
| 1202 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1203 | + { |
|
| 1204 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1205 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1212 | + * @param array $inputs_to_hide |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + */ |
|
| 1215 | + public function hide(array $inputs_to_hide = array()) |
|
| 1216 | + { |
|
| 1217 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1218 | + $input = $this->get_input($input_to_hide); |
|
| 1219 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * add_subsections |
|
| 1226 | + * Adds the listed subsections to the form section. |
|
| 1227 | + * If $subsection_name_to_target is provided, |
|
| 1228 | + * then new subsections are added before or after that subsection, |
|
| 1229 | + * otherwise to the start or end of the entire subsections array. |
|
| 1230 | + * |
|
| 1231 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1232 | + * where keys are their names |
|
| 1233 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1234 | + * should be added before or after |
|
| 1235 | + * IF $subsection_name_to_target is null, |
|
| 1236 | + * then $new_subsections will be added to |
|
| 1237 | + * the beginning or end of the entire subsections array |
|
| 1238 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1239 | + * $subsection_name_to_target, |
|
| 1240 | + * or if $subsection_name_to_target is null, |
|
| 1241 | + * before or after entire subsections array |
|
| 1242 | + * @return void |
|
| 1243 | + * @throws EE_Error |
|
| 1244 | + */ |
|
| 1245 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1246 | + { |
|
| 1247 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1248 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1249 | + EE_Error::add_error( |
|
| 1250 | + sprintf( |
|
| 1251 | + esc_html__( |
|
| 1252 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1253 | + 'event_espresso' |
|
| 1254 | + ), |
|
| 1255 | + get_class($subsection), |
|
| 1256 | + $subsection_name, |
|
| 1257 | + $this->name() |
|
| 1258 | + ) |
|
| 1259 | + ); |
|
| 1260 | + unset($new_subsections[ $subsection_name ]); |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1264 | + $this->_subsections, |
|
| 1265 | + $new_subsections, |
|
| 1266 | + $subsection_name_to_target, |
|
| 1267 | + $add_before |
|
| 1268 | + ); |
|
| 1269 | + if ($this->_construction_finalized) { |
|
| 1270 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1271 | + $subsection->_construct_finalize($this, $name); |
|
| 1272 | + } |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * @param string $subsection_name |
|
| 1279 | + * @param bool $recursive |
|
| 1280 | + * @return bool |
|
| 1281 | + */ |
|
| 1282 | + public function has_subsection($subsection_name, $recursive = false) |
|
| 1283 | + { |
|
| 1284 | + foreach ($this->_subsections as $name => $subsection) {if( |
|
| 1285 | + $name === $subsection_name |
|
| 1286 | + || ( |
|
| 1287 | + $recursive |
|
| 1288 | + && $subsection instanceof EE_Form_Section_Proper |
|
| 1289 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1290 | + ) |
|
| 1291 | + ) { |
|
| 1292 | + return true; |
|
| 1293 | + } |
|
| 1294 | + } |
|
| 1295 | + return false; |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + |
|
| 1299 | + |
|
| 1300 | + /** |
|
| 1301 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1302 | + * |
|
| 1303 | + * @throws EE_Error |
|
| 1304 | + */ |
|
| 1305 | + public function clean_sensitive_data() |
|
| 1306 | + { |
|
| 1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | + $subsection->clean_sensitive_data(); |
|
| 1309 | + } |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1315 | + * @param string $form_submission_error_message |
|
| 1316 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 1317 | + * @throws EE_Error |
|
| 1318 | + */ |
|
| 1319 | + public function set_submission_error_message( |
|
| 1320 | + $form_submission_error_message = '' |
|
| 1321 | + ) { |
|
| 1322 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1323 | + ? $form_submission_error_message |
|
| 1324 | + : $this->getAllValidationErrorsString(); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1330 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 1331 | + * set_submission_error_message |
|
| 1332 | + * |
|
| 1333 | + * @return string |
|
| 1334 | + */ |
|
| 1335 | + public function submission_error_message() |
|
| 1336 | + { |
|
| 1337 | + return $this->_form_submission_error_message; |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 1343 | + * @param string $form_submission_success_message |
|
| 1344 | + */ |
|
| 1345 | + public function set_submission_success_message($form_submission_success_message = '') |
|
| 1346 | + { |
|
| 1347 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1348 | + ? $form_submission_success_message |
|
| 1349 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 1355 | + * @return string |
|
| 1356 | + */ |
|
| 1357 | + public function submission_success_message() |
|
| 1358 | + { |
|
| 1359 | + return $this->_form_submission_success_message; |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * Returns the prefix that should be used on child of this form section for |
|
| 1365 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1366 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1367 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1368 | + * |
|
| 1369 | + * @return string |
|
| 1370 | + * @throws EE_Error |
|
| 1371 | + */ |
|
| 1372 | + public function html_name_prefix() |
|
| 1373 | + { |
|
| 1374 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1375 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1376 | + } |
|
| 1377 | + return $this->name(); |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + |
|
| 1381 | + /** |
|
| 1382 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1383 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1384 | + * was set, which is probably nothing, or the classname) |
|
| 1385 | + * |
|
| 1386 | + * @return string |
|
| 1387 | + * @throws EE_Error |
|
| 1388 | + */ |
|
| 1389 | + public function name() |
|
| 1390 | + { |
|
| 1391 | + $this->ensure_construct_finalized_called(); |
|
| 1392 | + return parent::name(); |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * @return EE_Form_Section_Proper |
|
| 1398 | + * @throws EE_Error |
|
| 1399 | + */ |
|
| 1400 | + public function parent_section() |
|
| 1401 | + { |
|
| 1402 | + $this->ensure_construct_finalized_called(); |
|
| 1403 | + return parent::parent_section(); |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + |
|
| 1407 | + /** |
|
| 1408 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1409 | + * |
|
| 1410 | + * @return void |
|
| 1411 | + * @throws EE_Error |
|
| 1412 | + */ |
|
| 1413 | + public function ensure_construct_finalized_called() |
|
| 1414 | + { |
|
| 1415 | + if (! $this->_construction_finalized) { |
|
| 1416 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1423 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1424 | + * |
|
| 1425 | + * @param array $req_data |
|
| 1426 | + * @return boolean |
|
| 1427 | + * @throws EE_Error |
|
| 1428 | + */ |
|
| 1429 | + public function form_data_present_in($req_data = null) |
|
| 1430 | + { |
|
| 1431 | + $req_data = $this->getCachedRequest($req_data); |
|
| 1432 | + foreach ($this->subsections() as $subsection) { |
|
| 1433 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1434 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1435 | + return true; |
|
| 1436 | + } |
|
| 1437 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1438 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1439 | + return true; |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + |
|
| 1447 | + /** |
|
| 1448 | + * Gets validation errors for this form section and subsections |
|
| 1449 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1450 | + * gets the validation errors for ALL subsection |
|
| 1451 | + * |
|
| 1452 | + * @return EE_Validation_Error[] |
|
| 1453 | + * @throws EE_Error |
|
| 1454 | + */ |
|
| 1455 | + public function get_validation_errors_accumulated() |
|
| 1456 | + { |
|
| 1457 | + $validation_errors = $this->get_validation_errors(); |
|
| 1458 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1459 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1460 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1461 | + } else { |
|
| 1462 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1463 | + } |
|
| 1464 | + if ($validation_errors_on_this_subsection) { |
|
| 1465 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1466 | + } |
|
| 1467 | + } |
|
| 1468 | + return $validation_errors; |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1473 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1474 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1475 | + * |
|
| 1476 | + * @return string |
|
| 1477 | + * @since 4.9.59.p |
|
| 1478 | + */ |
|
| 1479 | + protected function getAllValidationErrorsString() |
|
| 1480 | + { |
|
| 1481 | + $submission_error_messages = array(); |
|
| 1482 | + // bad, bad, bad registrant |
|
| 1483 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1484 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1485 | + $form_section = $validation_error->get_form_section(); |
|
| 1486 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1487 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1488 | + } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1489 | + $label = $validation_error->get_form_section()->name(); |
|
| 1490 | + } else { |
|
| 1491 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1492 | + } |
|
| 1493 | + $submission_error_messages[] = sprintf( |
|
| 1494 | + __('%s : %s', 'event_espresso'), |
|
| 1495 | + $label, |
|
| 1496 | + $validation_error->getMessage() |
|
| 1497 | + ); |
|
| 1498 | + } |
|
| 1499 | + } |
|
| 1500 | + return implode('<br', $submission_error_messages); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + /** |
|
| 1505 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1506 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1507 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1508 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1509 | + * which will be returned. |
|
| 1510 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1511 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1512 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1513 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1514 | + * Etc |
|
| 1515 | + * |
|
| 1516 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1517 | + * @return EE_Form_Section_Base |
|
| 1518 | + * @throws EE_Error |
|
| 1519 | + */ |
|
| 1520 | + public function find_section_from_path($form_section_path) |
|
| 1521 | + { |
|
| 1522 | + //check if we can find the input from purely going straight up the tree |
|
| 1523 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1524 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1525 | + return $input; |
|
| 1526 | + } |
|
| 1527 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1528 | + if ($next_slash_pos !== false) { |
|
| 1529 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1530 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1531 | + } else { |
|
| 1532 | + $child_section_name = $form_section_path; |
|
| 1533 | + $subpath = ''; |
|
| 1534 | + } |
|
| 1535 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1536 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1537 | + return $child_section->find_section_from_path($subpath); |
|
| 1538 | + } |
|
| 1539 | + return null; |
|
| 1540 | + } |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
@@ -20,590 +20,590 @@ |
||
| 20 | 20 | class Request implements InterminableInterface, RequestInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * $_GET parameters |
|
| 25 | - * |
|
| 26 | - * @var array $get |
|
| 27 | - */ |
|
| 28 | - private $get; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * $_POST parameters |
|
| 32 | - * |
|
| 33 | - * @var array $post |
|
| 34 | - */ |
|
| 35 | - private $post; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * $_COOKIE parameters |
|
| 39 | - * |
|
| 40 | - * @var array $cookie |
|
| 41 | - */ |
|
| 42 | - private $cookie; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * $_SERVER parameters |
|
| 46 | - * |
|
| 47 | - * @var array $server |
|
| 48 | - */ |
|
| 49 | - private $server; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * $_REQUEST parameters |
|
| 53 | - * |
|
| 54 | - * @var array $request |
|
| 55 | - */ |
|
| 56 | - private $request; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var RequestTypeContextCheckerInterface |
|
| 60 | - */ |
|
| 61 | - private $request_type; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * IP address for request |
|
| 65 | - * |
|
| 66 | - * @var string $ip_address |
|
| 67 | - */ |
|
| 68 | - private $ip_address; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string $user_agent |
|
| 72 | - */ |
|
| 73 | - private $user_agent; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * true if current user appears to be some kind of bot |
|
| 77 | - * |
|
| 78 | - * @var bool $is_bot |
|
| 79 | - */ |
|
| 80 | - private $is_bot; |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param array $get |
|
| 86 | - * @param array $post |
|
| 87 | - * @param array $cookie |
|
| 88 | - * @param array $server |
|
| 89 | - */ |
|
| 90 | - public function __construct(array $get, array $post, array $cookie, array $server) |
|
| 91 | - { |
|
| 92 | - // grab request vars |
|
| 93 | - $this->get = $get; |
|
| 94 | - $this->post = $post; |
|
| 95 | - $this->cookie = $cookie; |
|
| 96 | - $this->server = $server; |
|
| 97 | - $this->request = array_merge($this->get, $this->post); |
|
| 98 | - $this->ip_address = $this->visitorIp(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param RequestTypeContextCheckerInterface $type |
|
| 104 | - */ |
|
| 105 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 106 | - { |
|
| 107 | - $this->request_type = $type; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - public function getParams() |
|
| 116 | - { |
|
| 117 | - return $this->get; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function postParams() |
|
| 126 | - { |
|
| 127 | - return $this->post; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function cookieParams() |
|
| 136 | - { |
|
| 137 | - return $this->cookie; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return array |
|
| 143 | - */ |
|
| 144 | - public function serverParams() |
|
| 145 | - { |
|
| 146 | - return $this->server; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * returns contents of $_REQUEST |
|
| 153 | - * |
|
| 154 | - * @return array |
|
| 155 | - */ |
|
| 156 | - public function requestParams() |
|
| 157 | - { |
|
| 158 | - return $this->request; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param $key |
|
| 165 | - * @param $value |
|
| 166 | - * @param bool $override_ee |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - public function setRequestParam($key, $value, $override_ee = false) |
|
| 170 | - { |
|
| 171 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 172 | - if ( |
|
| 173 | - $key !== 'ee' |
|
| 174 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
| 175 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
| 176 | - ) { |
|
| 177 | - $this->request[ $key ] = $value; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * returns the value for a request param if the given key exists |
|
| 185 | - * |
|
| 186 | - * @param $key |
|
| 187 | - * @param null $default |
|
| 188 | - * @return mixed |
|
| 189 | - */ |
|
| 190 | - public function getRequestParam($key, $default = null) |
|
| 191 | - { |
|
| 192 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * check if param exists |
|
| 199 | - * |
|
| 200 | - * @param $key |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - public function requestParamIsSet($key) |
|
| 204 | - { |
|
| 205 | - return $this->requestParameterDrillDown($key); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 211 | - * and return the value for the first match found |
|
| 212 | - * wildcards can be either of the following: |
|
| 213 | - * ? to represent a single character of any type |
|
| 214 | - * * to represent one or more characters of any type |
|
| 215 | - * |
|
| 216 | - * @param string $pattern |
|
| 217 | - * @param null|mixed $default |
|
| 218 | - * @return false|int |
|
| 219 | - */ |
|
| 220 | - public function getMatch($pattern, $default = null) |
|
| 221 | - { |
|
| 222 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 228 | - * wildcards can be either of the following: |
|
| 229 | - * ? to represent a single character of any type |
|
| 230 | - * * to represent one or more characters of any type |
|
| 231 | - * returns true if a match is found or false if not |
|
| 232 | - * |
|
| 233 | - * @param string $pattern |
|
| 234 | - * @return false|int |
|
| 235 | - */ |
|
| 236 | - public function matches($pattern) |
|
| 237 | - { |
|
| 238 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 244 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 245 | - * and used to search through the current request's parameter keys |
|
| 246 | - * @param array $request_params The array of request parameters to search through |
|
| 247 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 248 | - * Default is null |
|
| 249 | - * @param string $return [optional] Controls what kind of value is returned. |
|
| 250 | - * Options are: |
|
| 251 | - * 'bool' will return true or false if match is found or not |
|
| 252 | - * 'key' will return the first key found that matches the supplied pattern |
|
| 253 | - * 'value' will return the value for the first request parameter |
|
| 254 | - * whose key matches the supplied pattern |
|
| 255 | - * Default is 'value' |
|
| 256 | - * @return boolean|string |
|
| 257 | - */ |
|
| 258 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 259 | - { |
|
| 260 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 261 | - ? $return |
|
| 262 | - : 'is_set'; |
|
| 263 | - // replace wildcard chars with regex chars |
|
| 264 | - $pattern = str_replace( |
|
| 265 | - array("\*", "\?"), |
|
| 266 | - array('.*', '.'), |
|
| 267 | - preg_quote($pattern, '/') |
|
| 268 | - ); |
|
| 269 | - foreach ($request_params as $key => $request_param) { |
|
| 270 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 271 | - // return value for request param |
|
| 272 | - if ($return === 'value') { |
|
| 273 | - return $request_params[ $key ]; |
|
| 274 | - } |
|
| 275 | - // or actual key or true just to indicate it was found |
|
| 276 | - return $return === 'key' ? $key : true; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - // match not found so return default value or false |
|
| 280 | - return $return === 'value' ? $default : false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 286 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 287 | - * by using square brackets to surround keys for deeper array elements. |
|
| 288 | - * For example : |
|
| 289 | - * if the supplied $key was: "first[second][third]" |
|
| 290 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
| 291 | - * Given the following request parameters: |
|
| 292 | - * array( |
|
| 293 | - * 'first' => array( |
|
| 294 | - * 'second' => array( |
|
| 295 | - * 'third' => 'has a value' |
|
| 296 | - * ) |
|
| 297 | - * ) |
|
| 298 | - * ) |
|
| 299 | - * would return true if default parameters were set |
|
| 300 | - * |
|
| 301 | - * @param string $callback |
|
| 302 | - * @param $key |
|
| 303 | - * @param null $default |
|
| 304 | - * @param array $request_params |
|
| 305 | - * @return bool|mixed|null |
|
| 306 | - */ |
|
| 307 | - private function requestParameterDrillDown( |
|
| 308 | - $key, |
|
| 309 | - $default = null, |
|
| 310 | - $callback = 'is_set', |
|
| 311 | - array $request_params = array() |
|
| 312 | - ) { |
|
| 313 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 314 | - ? $callback |
|
| 315 | - : 'is_set'; |
|
| 316 | - $request_params = ! empty($request_params) |
|
| 317 | - ? $request_params |
|
| 318 | - : $this->request; |
|
| 319 | - // does incoming key represent an array like 'first[second][third]' ? |
|
| 320 | - if (strpos($key, '[') !== false) { |
|
| 321 | - // turn it into an actual array |
|
| 322 | - $key = str_replace(']', '', $key); |
|
| 323 | - $keys = explode('[', $key); |
|
| 324 | - $key = array_shift($keys); |
|
| 325 | - if ($callback === 'match') { |
|
| 326 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 327 | - $key = $real_key ? $real_key : $key; |
|
| 328 | - } |
|
| 329 | - // check if top level key exists |
|
| 330 | - if (isset($request_params[ $key ])) { |
|
| 331 | - // build a new key to pass along like: 'second[third]' |
|
| 332 | - // or just 'second' depending on depth of keys |
|
| 333 | - $key_string = array_shift($keys); |
|
| 334 | - if (! empty($keys)) { |
|
| 335 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 336 | - } |
|
| 337 | - return $this->requestParameterDrillDown( |
|
| 338 | - $key_string, |
|
| 339 | - $default, |
|
| 340 | - $callback, |
|
| 341 | - $request_params[ $key ] |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - if ($callback === 'is_set') { |
|
| 346 | - return isset($request_params[ $key ]); |
|
| 347 | - } |
|
| 348 | - if ($callback === 'match') { |
|
| 349 | - return $this->match($key, $request_params, $default); |
|
| 350 | - } |
|
| 351 | - return isset($request_params[ $key ]) |
|
| 352 | - ? $request_params[ $key ] |
|
| 353 | - : $default; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * remove param |
|
| 359 | - * |
|
| 360 | - * @param $key |
|
| 361 | - * @param bool $unset_from_global_too |
|
| 362 | - */ |
|
| 363 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 364 | - { |
|
| 365 | - unset($this->request[ $key ]); |
|
| 366 | - if ($unset_from_global_too) { |
|
| 367 | - unset($_REQUEST[ $key ]); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @return string |
|
| 375 | - */ |
|
| 376 | - public function ipAddress() |
|
| 377 | - { |
|
| 378 | - return $this->ip_address; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * attempt to get IP address of current visitor from server |
|
| 384 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 385 | - * |
|
| 386 | - * @access public |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - private function visitorIp() |
|
| 390 | - { |
|
| 391 | - $visitor_ip = '0.0.0.0'; |
|
| 392 | - $server_keys = array( |
|
| 393 | - 'HTTP_CLIENT_IP', |
|
| 394 | - 'HTTP_X_FORWARDED_FOR', |
|
| 395 | - 'HTTP_X_FORWARDED', |
|
| 396 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 397 | - 'HTTP_FORWARDED_FOR', |
|
| 398 | - 'HTTP_FORWARDED', |
|
| 399 | - 'REMOTE_ADDR', |
|
| 400 | - ); |
|
| 401 | - foreach ($server_keys as $key) { |
|
| 402 | - if (isset($this->server[ $key ])) { |
|
| 403 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 404 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 405 | - $visitor_ip = $ip; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - return $visitor_ip; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @return string |
|
| 416 | - */ |
|
| 417 | - public function requestUri() |
|
| 418 | - { |
|
| 419 | - $request_uri = filter_input( |
|
| 420 | - INPUT_SERVER, |
|
| 421 | - 'REQUEST_URI', |
|
| 422 | - FILTER_SANITIZE_URL, |
|
| 423 | - FILTER_NULL_ON_FAILURE |
|
| 424 | - ); |
|
| 425 | - if (empty($request_uri)) { |
|
| 426 | - // fallback sanitization if the above fails |
|
| 427 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 428 | - } |
|
| 429 | - return $request_uri; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @return string |
|
| 435 | - */ |
|
| 436 | - public function userAgent() |
|
| 437 | - { |
|
| 438 | - return $this->user_agent; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param string $user_agent |
|
| 444 | - */ |
|
| 445 | - public function setUserAgent($user_agent = '') |
|
| 446 | - { |
|
| 447 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 448 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 449 | - } |
|
| 450 | - $this->user_agent = $user_agent; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @return bool |
|
| 456 | - */ |
|
| 457 | - public function isBot() |
|
| 458 | - { |
|
| 459 | - return $this->is_bot; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param bool $is_bot |
|
| 465 | - */ |
|
| 466 | - public function setIsBot($is_bot) |
|
| 467 | - { |
|
| 468 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @return bool |
|
| 474 | - */ |
|
| 475 | - public function isActivation() |
|
| 476 | - { |
|
| 477 | - return $this->request_type->isActivation(); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param $is_activation |
|
| 483 | - * @return bool |
|
| 484 | - */ |
|
| 485 | - public function setIsActivation($is_activation) |
|
| 486 | - { |
|
| 487 | - return $this->request_type->setIsActivation($is_activation); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @return bool |
|
| 493 | - */ |
|
| 494 | - public function isAdmin() |
|
| 495 | - { |
|
| 496 | - return $this->request_type->isAdmin(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @return bool |
|
| 502 | - */ |
|
| 503 | - public function isAdminAjax() |
|
| 504 | - { |
|
| 505 | - return $this->request_type->isAdminAjax(); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * @return bool |
|
| 511 | - */ |
|
| 512 | - public function isAjax() |
|
| 513 | - { |
|
| 514 | - return $this->request_type->isAjax(); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * @return bool |
|
| 520 | - */ |
|
| 521 | - public function isEeAjax() |
|
| 522 | - { |
|
| 523 | - return $this->request_type->isEeAjax(); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @return bool |
|
| 529 | - */ |
|
| 530 | - public function isOtherAjax() |
|
| 531 | - { |
|
| 532 | - return $this->request_type->isOtherAjax(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * @return bool |
|
| 538 | - */ |
|
| 539 | - public function isApi() |
|
| 540 | - { |
|
| 541 | - return $this->request_type->isApi(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * @return bool |
|
| 547 | - */ |
|
| 548 | - public function isCli() |
|
| 549 | - { |
|
| 550 | - return $this->request_type->isCli(); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * @return bool |
|
| 556 | - */ |
|
| 557 | - public function isCron() |
|
| 558 | - { |
|
| 559 | - return $this->request_type->isCron(); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * @return bool |
|
| 565 | - */ |
|
| 566 | - public function isFeed() |
|
| 567 | - { |
|
| 568 | - return $this->request_type->isFeed(); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @return bool |
|
| 574 | - */ |
|
| 575 | - public function isFrontend() |
|
| 576 | - { |
|
| 577 | - return $this->request_type->isFrontend(); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @return bool |
|
| 583 | - */ |
|
| 584 | - public function isFrontAjax() |
|
| 585 | - { |
|
| 586 | - return $this->request_type->isFrontAjax(); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @return bool |
|
| 593 | - */ |
|
| 594 | - public function isIframe() |
|
| 595 | - { |
|
| 596 | - return $this->request_type->isIframe(); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * @return string |
|
| 602 | - */ |
|
| 603 | - public function slug() |
|
| 604 | - { |
|
| 605 | - return $this->request_type->slug(); |
|
| 606 | - } |
|
| 23 | + /** |
|
| 24 | + * $_GET parameters |
|
| 25 | + * |
|
| 26 | + * @var array $get |
|
| 27 | + */ |
|
| 28 | + private $get; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * $_POST parameters |
|
| 32 | + * |
|
| 33 | + * @var array $post |
|
| 34 | + */ |
|
| 35 | + private $post; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * $_COOKIE parameters |
|
| 39 | + * |
|
| 40 | + * @var array $cookie |
|
| 41 | + */ |
|
| 42 | + private $cookie; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * $_SERVER parameters |
|
| 46 | + * |
|
| 47 | + * @var array $server |
|
| 48 | + */ |
|
| 49 | + private $server; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * $_REQUEST parameters |
|
| 53 | + * |
|
| 54 | + * @var array $request |
|
| 55 | + */ |
|
| 56 | + private $request; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var RequestTypeContextCheckerInterface |
|
| 60 | + */ |
|
| 61 | + private $request_type; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * IP address for request |
|
| 65 | + * |
|
| 66 | + * @var string $ip_address |
|
| 67 | + */ |
|
| 68 | + private $ip_address; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string $user_agent |
|
| 72 | + */ |
|
| 73 | + private $user_agent; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * true if current user appears to be some kind of bot |
|
| 77 | + * |
|
| 78 | + * @var bool $is_bot |
|
| 79 | + */ |
|
| 80 | + private $is_bot; |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param array $get |
|
| 86 | + * @param array $post |
|
| 87 | + * @param array $cookie |
|
| 88 | + * @param array $server |
|
| 89 | + */ |
|
| 90 | + public function __construct(array $get, array $post, array $cookie, array $server) |
|
| 91 | + { |
|
| 92 | + // grab request vars |
|
| 93 | + $this->get = $get; |
|
| 94 | + $this->post = $post; |
|
| 95 | + $this->cookie = $cookie; |
|
| 96 | + $this->server = $server; |
|
| 97 | + $this->request = array_merge($this->get, $this->post); |
|
| 98 | + $this->ip_address = $this->visitorIp(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param RequestTypeContextCheckerInterface $type |
|
| 104 | + */ |
|
| 105 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 106 | + { |
|
| 107 | + $this->request_type = $type; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + public function getParams() |
|
| 116 | + { |
|
| 117 | + return $this->get; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function postParams() |
|
| 126 | + { |
|
| 127 | + return $this->post; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function cookieParams() |
|
| 136 | + { |
|
| 137 | + return $this->cookie; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return array |
|
| 143 | + */ |
|
| 144 | + public function serverParams() |
|
| 145 | + { |
|
| 146 | + return $this->server; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * returns contents of $_REQUEST |
|
| 153 | + * |
|
| 154 | + * @return array |
|
| 155 | + */ |
|
| 156 | + public function requestParams() |
|
| 157 | + { |
|
| 158 | + return $this->request; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param $key |
|
| 165 | + * @param $value |
|
| 166 | + * @param bool $override_ee |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + public function setRequestParam($key, $value, $override_ee = false) |
|
| 170 | + { |
|
| 171 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 172 | + if ( |
|
| 173 | + $key !== 'ee' |
|
| 174 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
| 175 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
| 176 | + ) { |
|
| 177 | + $this->request[ $key ] = $value; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * returns the value for a request param if the given key exists |
|
| 185 | + * |
|
| 186 | + * @param $key |
|
| 187 | + * @param null $default |
|
| 188 | + * @return mixed |
|
| 189 | + */ |
|
| 190 | + public function getRequestParam($key, $default = null) |
|
| 191 | + { |
|
| 192 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * check if param exists |
|
| 199 | + * |
|
| 200 | + * @param $key |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + public function requestParamIsSet($key) |
|
| 204 | + { |
|
| 205 | + return $this->requestParameterDrillDown($key); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 211 | + * and return the value for the first match found |
|
| 212 | + * wildcards can be either of the following: |
|
| 213 | + * ? to represent a single character of any type |
|
| 214 | + * * to represent one or more characters of any type |
|
| 215 | + * |
|
| 216 | + * @param string $pattern |
|
| 217 | + * @param null|mixed $default |
|
| 218 | + * @return false|int |
|
| 219 | + */ |
|
| 220 | + public function getMatch($pattern, $default = null) |
|
| 221 | + { |
|
| 222 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 228 | + * wildcards can be either of the following: |
|
| 229 | + * ? to represent a single character of any type |
|
| 230 | + * * to represent one or more characters of any type |
|
| 231 | + * returns true if a match is found or false if not |
|
| 232 | + * |
|
| 233 | + * @param string $pattern |
|
| 234 | + * @return false|int |
|
| 235 | + */ |
|
| 236 | + public function matches($pattern) |
|
| 237 | + { |
|
| 238 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 244 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 245 | + * and used to search through the current request's parameter keys |
|
| 246 | + * @param array $request_params The array of request parameters to search through |
|
| 247 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 248 | + * Default is null |
|
| 249 | + * @param string $return [optional] Controls what kind of value is returned. |
|
| 250 | + * Options are: |
|
| 251 | + * 'bool' will return true or false if match is found or not |
|
| 252 | + * 'key' will return the first key found that matches the supplied pattern |
|
| 253 | + * 'value' will return the value for the first request parameter |
|
| 254 | + * whose key matches the supplied pattern |
|
| 255 | + * Default is 'value' |
|
| 256 | + * @return boolean|string |
|
| 257 | + */ |
|
| 258 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 259 | + { |
|
| 260 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 261 | + ? $return |
|
| 262 | + : 'is_set'; |
|
| 263 | + // replace wildcard chars with regex chars |
|
| 264 | + $pattern = str_replace( |
|
| 265 | + array("\*", "\?"), |
|
| 266 | + array('.*', '.'), |
|
| 267 | + preg_quote($pattern, '/') |
|
| 268 | + ); |
|
| 269 | + foreach ($request_params as $key => $request_param) { |
|
| 270 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 271 | + // return value for request param |
|
| 272 | + if ($return === 'value') { |
|
| 273 | + return $request_params[ $key ]; |
|
| 274 | + } |
|
| 275 | + // or actual key or true just to indicate it was found |
|
| 276 | + return $return === 'key' ? $key : true; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + // match not found so return default value or false |
|
| 280 | + return $return === 'value' ? $default : false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 286 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 287 | + * by using square brackets to surround keys for deeper array elements. |
|
| 288 | + * For example : |
|
| 289 | + * if the supplied $key was: "first[second][third]" |
|
| 290 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
| 291 | + * Given the following request parameters: |
|
| 292 | + * array( |
|
| 293 | + * 'first' => array( |
|
| 294 | + * 'second' => array( |
|
| 295 | + * 'third' => 'has a value' |
|
| 296 | + * ) |
|
| 297 | + * ) |
|
| 298 | + * ) |
|
| 299 | + * would return true if default parameters were set |
|
| 300 | + * |
|
| 301 | + * @param string $callback |
|
| 302 | + * @param $key |
|
| 303 | + * @param null $default |
|
| 304 | + * @param array $request_params |
|
| 305 | + * @return bool|mixed|null |
|
| 306 | + */ |
|
| 307 | + private function requestParameterDrillDown( |
|
| 308 | + $key, |
|
| 309 | + $default = null, |
|
| 310 | + $callback = 'is_set', |
|
| 311 | + array $request_params = array() |
|
| 312 | + ) { |
|
| 313 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 314 | + ? $callback |
|
| 315 | + : 'is_set'; |
|
| 316 | + $request_params = ! empty($request_params) |
|
| 317 | + ? $request_params |
|
| 318 | + : $this->request; |
|
| 319 | + // does incoming key represent an array like 'first[second][third]' ? |
|
| 320 | + if (strpos($key, '[') !== false) { |
|
| 321 | + // turn it into an actual array |
|
| 322 | + $key = str_replace(']', '', $key); |
|
| 323 | + $keys = explode('[', $key); |
|
| 324 | + $key = array_shift($keys); |
|
| 325 | + if ($callback === 'match') { |
|
| 326 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 327 | + $key = $real_key ? $real_key : $key; |
|
| 328 | + } |
|
| 329 | + // check if top level key exists |
|
| 330 | + if (isset($request_params[ $key ])) { |
|
| 331 | + // build a new key to pass along like: 'second[third]' |
|
| 332 | + // or just 'second' depending on depth of keys |
|
| 333 | + $key_string = array_shift($keys); |
|
| 334 | + if (! empty($keys)) { |
|
| 335 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 336 | + } |
|
| 337 | + return $this->requestParameterDrillDown( |
|
| 338 | + $key_string, |
|
| 339 | + $default, |
|
| 340 | + $callback, |
|
| 341 | + $request_params[ $key ] |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + if ($callback === 'is_set') { |
|
| 346 | + return isset($request_params[ $key ]); |
|
| 347 | + } |
|
| 348 | + if ($callback === 'match') { |
|
| 349 | + return $this->match($key, $request_params, $default); |
|
| 350 | + } |
|
| 351 | + return isset($request_params[ $key ]) |
|
| 352 | + ? $request_params[ $key ] |
|
| 353 | + : $default; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * remove param |
|
| 359 | + * |
|
| 360 | + * @param $key |
|
| 361 | + * @param bool $unset_from_global_too |
|
| 362 | + */ |
|
| 363 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 364 | + { |
|
| 365 | + unset($this->request[ $key ]); |
|
| 366 | + if ($unset_from_global_too) { |
|
| 367 | + unset($_REQUEST[ $key ]); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @return string |
|
| 375 | + */ |
|
| 376 | + public function ipAddress() |
|
| 377 | + { |
|
| 378 | + return $this->ip_address; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * attempt to get IP address of current visitor from server |
|
| 384 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 385 | + * |
|
| 386 | + * @access public |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + private function visitorIp() |
|
| 390 | + { |
|
| 391 | + $visitor_ip = '0.0.0.0'; |
|
| 392 | + $server_keys = array( |
|
| 393 | + 'HTTP_CLIENT_IP', |
|
| 394 | + 'HTTP_X_FORWARDED_FOR', |
|
| 395 | + 'HTTP_X_FORWARDED', |
|
| 396 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 397 | + 'HTTP_FORWARDED_FOR', |
|
| 398 | + 'HTTP_FORWARDED', |
|
| 399 | + 'REMOTE_ADDR', |
|
| 400 | + ); |
|
| 401 | + foreach ($server_keys as $key) { |
|
| 402 | + if (isset($this->server[ $key ])) { |
|
| 403 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 404 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 405 | + $visitor_ip = $ip; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + return $visitor_ip; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @return string |
|
| 416 | + */ |
|
| 417 | + public function requestUri() |
|
| 418 | + { |
|
| 419 | + $request_uri = filter_input( |
|
| 420 | + INPUT_SERVER, |
|
| 421 | + 'REQUEST_URI', |
|
| 422 | + FILTER_SANITIZE_URL, |
|
| 423 | + FILTER_NULL_ON_FAILURE |
|
| 424 | + ); |
|
| 425 | + if (empty($request_uri)) { |
|
| 426 | + // fallback sanitization if the above fails |
|
| 427 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 428 | + } |
|
| 429 | + return $request_uri; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @return string |
|
| 435 | + */ |
|
| 436 | + public function userAgent() |
|
| 437 | + { |
|
| 438 | + return $this->user_agent; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param string $user_agent |
|
| 444 | + */ |
|
| 445 | + public function setUserAgent($user_agent = '') |
|
| 446 | + { |
|
| 447 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 448 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 449 | + } |
|
| 450 | + $this->user_agent = $user_agent; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @return bool |
|
| 456 | + */ |
|
| 457 | + public function isBot() |
|
| 458 | + { |
|
| 459 | + return $this->is_bot; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param bool $is_bot |
|
| 465 | + */ |
|
| 466 | + public function setIsBot($is_bot) |
|
| 467 | + { |
|
| 468 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @return bool |
|
| 474 | + */ |
|
| 475 | + public function isActivation() |
|
| 476 | + { |
|
| 477 | + return $this->request_type->isActivation(); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param $is_activation |
|
| 483 | + * @return bool |
|
| 484 | + */ |
|
| 485 | + public function setIsActivation($is_activation) |
|
| 486 | + { |
|
| 487 | + return $this->request_type->setIsActivation($is_activation); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @return bool |
|
| 493 | + */ |
|
| 494 | + public function isAdmin() |
|
| 495 | + { |
|
| 496 | + return $this->request_type->isAdmin(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @return bool |
|
| 502 | + */ |
|
| 503 | + public function isAdminAjax() |
|
| 504 | + { |
|
| 505 | + return $this->request_type->isAdminAjax(); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * @return bool |
|
| 511 | + */ |
|
| 512 | + public function isAjax() |
|
| 513 | + { |
|
| 514 | + return $this->request_type->isAjax(); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * @return bool |
|
| 520 | + */ |
|
| 521 | + public function isEeAjax() |
|
| 522 | + { |
|
| 523 | + return $this->request_type->isEeAjax(); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @return bool |
|
| 529 | + */ |
|
| 530 | + public function isOtherAjax() |
|
| 531 | + { |
|
| 532 | + return $this->request_type->isOtherAjax(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * @return bool |
|
| 538 | + */ |
|
| 539 | + public function isApi() |
|
| 540 | + { |
|
| 541 | + return $this->request_type->isApi(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * @return bool |
|
| 547 | + */ |
|
| 548 | + public function isCli() |
|
| 549 | + { |
|
| 550 | + return $this->request_type->isCli(); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * @return bool |
|
| 556 | + */ |
|
| 557 | + public function isCron() |
|
| 558 | + { |
|
| 559 | + return $this->request_type->isCron(); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * @return bool |
|
| 565 | + */ |
|
| 566 | + public function isFeed() |
|
| 567 | + { |
|
| 568 | + return $this->request_type->isFeed(); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @return bool |
|
| 574 | + */ |
|
| 575 | + public function isFrontend() |
|
| 576 | + { |
|
| 577 | + return $this->request_type->isFrontend(); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @return bool |
|
| 583 | + */ |
|
| 584 | + public function isFrontAjax() |
|
| 585 | + { |
|
| 586 | + return $this->request_type->isFrontAjax(); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @return bool |
|
| 593 | + */ |
|
| 594 | + public function isIframe() |
|
| 595 | + { |
|
| 596 | + return $this->request_type->isIframe(); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * @return string |
|
| 602 | + */ |
|
| 603 | + public function slug() |
|
| 604 | + { |
|
| 605 | + return $this->request_type->slug(); |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | 608 | |
| 609 | 609 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | || ($key === 'ee' && empty($this->request['ee'])) |
| 175 | 175 | || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
| 176 | 176 | ) { |
| 177 | - $this->request[ $key ] = $value; |
|
| 177 | + $this->request[$key] = $value; |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -267,10 +267,10 @@ discard block |
||
| 267 | 267 | preg_quote($pattern, '/') |
| 268 | 268 | ); |
| 269 | 269 | foreach ($request_params as $key => $request_param) { |
| 270 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 270 | + if (preg_match('/^'.$pattern.'$/is', $key)) { |
|
| 271 | 271 | // return value for request param |
| 272 | 272 | if ($return === 'value') { |
| 273 | - return $request_params[ $key ]; |
|
| 273 | + return $request_params[$key]; |
|
| 274 | 274 | } |
| 275 | 275 | // or actual key or true just to indicate it was found |
| 276 | 276 | return $return === 'key' ? $key : true; |
@@ -327,29 +327,29 @@ discard block |
||
| 327 | 327 | $key = $real_key ? $real_key : $key; |
| 328 | 328 | } |
| 329 | 329 | // check if top level key exists |
| 330 | - if (isset($request_params[ $key ])) { |
|
| 330 | + if (isset($request_params[$key])) { |
|
| 331 | 331 | // build a new key to pass along like: 'second[third]' |
| 332 | 332 | // or just 'second' depending on depth of keys |
| 333 | 333 | $key_string = array_shift($keys); |
| 334 | - if (! empty($keys)) { |
|
| 335 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 334 | + if ( ! empty($keys)) { |
|
| 335 | + $key_string .= '['.implode('][', $keys).']'; |
|
| 336 | 336 | } |
| 337 | 337 | return $this->requestParameterDrillDown( |
| 338 | 338 | $key_string, |
| 339 | 339 | $default, |
| 340 | 340 | $callback, |
| 341 | - $request_params[ $key ] |
|
| 341 | + $request_params[$key] |
|
| 342 | 342 | ); |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | if ($callback === 'is_set') { |
| 346 | - return isset($request_params[ $key ]); |
|
| 346 | + return isset($request_params[$key]); |
|
| 347 | 347 | } |
| 348 | 348 | if ($callback === 'match') { |
| 349 | 349 | return $this->match($key, $request_params, $default); |
| 350 | 350 | } |
| 351 | - return isset($request_params[ $key ]) |
|
| 352 | - ? $request_params[ $key ] |
|
| 351 | + return isset($request_params[$key]) |
|
| 352 | + ? $request_params[$key] |
|
| 353 | 353 | : $default; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | public function unSetRequestParam($key, $unset_from_global_too = false) |
| 364 | 364 | { |
| 365 | - unset($this->request[ $key ]); |
|
| 365 | + unset($this->request[$key]); |
|
| 366 | 366 | if ($unset_from_global_too) { |
| 367 | - unset($_REQUEST[ $key ]); |
|
| 367 | + unset($_REQUEST[$key]); |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | 'REMOTE_ADDR', |
| 400 | 400 | ); |
| 401 | 401 | foreach ($server_keys as $key) { |
| 402 | - if (isset($this->server[ $key ])) { |
|
| 403 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 402 | + if (isset($this->server[$key])) { |
|
| 403 | + foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) { |
|
| 404 | 404 | if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
| 405 | 405 | $visitor_ip = $ip; |
| 406 | 406 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @param $key |
| 187 | 187 | * @param null $default |
| 188 | - * @return mixed |
|
| 188 | + * @return integer |
|
| 189 | 189 | */ |
| 190 | 190 | public function getRequestParam($key, $default = null) |
| 191 | 191 | { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * returns true if a match is found or false if not |
| 232 | 232 | * |
| 233 | 233 | * @param string $pattern |
| 234 | - * @return false|int |
|
| 234 | + * @return boolean |
|
| 235 | 235 | */ |
| 236 | 236 | public function matches($pattern) |
| 237 | 237 | { |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * would return true if default parameters were set |
| 300 | 300 | * |
| 301 | 301 | * @param string $callback |
| 302 | - * @param $key |
|
| 302 | + * @param string $key |
|
| 303 | 303 | * @param null $default |
| 304 | 304 | * @param array $request_params |
| 305 | 305 | * @return bool|mixed|null |
@@ -20,139 +20,139 @@ |
||
| 20 | 20 | interface RequestInterface extends RequestTypeContextCheckerInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param RequestTypeContextCheckerInterface $type |
|
| 25 | - */ |
|
| 26 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function getParams(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return array |
|
| 36 | - */ |
|
| 37 | - public function postParams(); |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - public function cookieParams(); |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @return array |
|
| 48 | - */ |
|
| 49 | - public function serverParams(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * returns contents of $_REQUEST |
|
| 54 | - * |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function requestParams(); |
|
| 23 | + /** |
|
| 24 | + * @param RequestTypeContextCheckerInterface $type |
|
| 25 | + */ |
|
| 26 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function getParams(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return array |
|
| 36 | + */ |
|
| 37 | + public function postParams(); |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + public function cookieParams(); |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @return array |
|
| 48 | + */ |
|
| 49 | + public function serverParams(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * returns contents of $_REQUEST |
|
| 54 | + * |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function requestParams(); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $key |
|
| 62 | - * @param string $value |
|
| 63 | - * @param bool $override_ee |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function setRequestParam($key, $value, $override_ee = false); |
|
| 60 | + /** |
|
| 61 | + * @param string $key |
|
| 62 | + * @param string $value |
|
| 63 | + * @param bool $override_ee |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function setRequestParam($key, $value, $override_ee = false); |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * returns the value for a request param if the given key exists |
|
| 71 | - * |
|
| 72 | - * @param string $key |
|
| 73 | - * @param null $default |
|
| 74 | - * @return mixed |
|
| 75 | - */ |
|
| 76 | - public function getRequestParam($key, $default = null); |
|
| 69 | + /** |
|
| 70 | + * returns the value for a request param if the given key exists |
|
| 71 | + * |
|
| 72 | + * @param string $key |
|
| 73 | + * @param null $default |
|
| 74 | + * @return mixed |
|
| 75 | + */ |
|
| 76 | + public function getRequestParam($key, $default = null); |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * check if param exists |
|
| 81 | - * |
|
| 82 | - * @param string $key |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function requestParamIsSet($key); |
|
| 79 | + /** |
|
| 80 | + * check if param exists |
|
| 81 | + * |
|
| 82 | + * @param string $key |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function requestParamIsSet($key); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 90 | - * and return the value for the first match found |
|
| 91 | - * wildcards can be either of the following: |
|
| 92 | - * ? to represent a single character of any type |
|
| 93 | - * * to represent one or more characters of any type |
|
| 94 | - * |
|
| 95 | - * @param string $pattern |
|
| 96 | - * @param null|mixed $default |
|
| 97 | - * @return false|int |
|
| 98 | - */ |
|
| 99 | - public function getMatch($pattern, $default = null); |
|
| 88 | + /** |
|
| 89 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 90 | + * and return the value for the first match found |
|
| 91 | + * wildcards can be either of the following: |
|
| 92 | + * ? to represent a single character of any type |
|
| 93 | + * * to represent one or more characters of any type |
|
| 94 | + * |
|
| 95 | + * @param string $pattern |
|
| 96 | + * @param null|mixed $default |
|
| 97 | + * @return false|int |
|
| 98 | + */ |
|
| 99 | + public function getMatch($pattern, $default = null); |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 104 | - * wildcards can be either of the following: |
|
| 105 | - * ? to represent a single character of any type |
|
| 106 | - * * to represent one or more characters of any type |
|
| 107 | - * returns true if a match is found or false if not |
|
| 108 | - * |
|
| 109 | - * @param string $pattern |
|
| 110 | - * @return false|int |
|
| 111 | - */ |
|
| 112 | - public function matches($pattern); |
|
| 102 | + /** |
|
| 103 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 104 | + * wildcards can be either of the following: |
|
| 105 | + * ? to represent a single character of any type |
|
| 106 | + * * to represent one or more characters of any type |
|
| 107 | + * returns true if a match is found or false if not |
|
| 108 | + * |
|
| 109 | + * @param string $pattern |
|
| 110 | + * @return false|int |
|
| 111 | + */ |
|
| 112 | + public function matches($pattern); |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * remove param |
|
| 117 | - * |
|
| 118 | - * @param string $key |
|
| 119 | - * @param bool $unset_from_global_too |
|
| 120 | - */ |
|
| 121 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 115 | + /** |
|
| 116 | + * remove param |
|
| 117 | + * |
|
| 118 | + * @param string $key |
|
| 119 | + * @param bool $unset_from_global_too |
|
| 120 | + */ |
|
| 121 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function ipAddress(); |
|
| 124 | + /** |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function ipAddress(); |
|
| 128 | 128 | |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function requestUri(); |
|
| 134 | - |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function requestUri(); |
|
| 134 | + |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function userAgent(); |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param string $user_agent |
|
| 144 | - */ |
|
| 145 | - public function setUserAgent($user_agent = ''); |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function isBot(); |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param bool $is_bot |
|
| 156 | - */ |
|
| 157 | - public function setIsBot($is_bot); |
|
| 136 | + /** |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function userAgent(); |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param string $user_agent |
|
| 144 | + */ |
|
| 145 | + public function setUserAgent($user_agent = ''); |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function isBot(); |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param bool $is_bot |
|
| 156 | + */ |
|
| 157 | + public function setIsBot($is_bot); |
|
| 158 | 158 | } |
@@ -8,649 +8,649 @@ |
||
| 8 | 8 | class EE_Email_messenger extends EE_messenger |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * To field for email |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $_to = ''; |
|
| 16 | - |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * CC field for email. |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $_cc = ''; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * From field for email |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $_from = ''; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Subject field for email |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_subject = ''; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Content field for email |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_content = ''; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * constructor |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - */ |
|
| 50 | - public function __construct() |
|
| 51 | - { |
|
| 52 | - //set name and description properties |
|
| 53 | - $this->name = 'email'; |
|
| 54 | - $this->description = sprintf( |
|
| 55 | - esc_html__( |
|
| 56 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
| 57 | - 'event_espresso' |
|
| 58 | - ), |
|
| 59 | - '<code>wp_mail</code>' |
|
| 60 | - ); |
|
| 61 | - $this->label = array( |
|
| 62 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
| 63 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
| 64 | - ); |
|
| 65 | - $this->activate_on_install = true; |
|
| 66 | - |
|
| 67 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
| 68 | - // properties |
|
| 69 | - parent::__construct(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * see abstract declaration in parent class for details. |
|
| 75 | - */ |
|
| 76 | - protected function _set_admin_pages() |
|
| 77 | - { |
|
| 78 | - $this->admin_registered_pages = array( |
|
| 79 | - 'events_edit' => true, |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * see abstract declaration in parent class for details |
|
| 86 | - */ |
|
| 87 | - protected function _set_valid_shortcodes() |
|
| 88 | - { |
|
| 89 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
| 90 | - // message type. |
|
| 91 | - $this->_valid_shortcodes = array( |
|
| 92 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 93 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 94 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * see abstract declaration in parent class for details |
|
| 101 | - * |
|
| 102 | - * @access protected |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - protected function _set_validator_config() |
|
| 106 | - { |
|
| 107 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
| 108 | - |
|
| 109 | - $this->_validator_config = array( |
|
| 110 | - 'to' => array( |
|
| 111 | - 'shortcodes' => $valid_shortcodes['to'], |
|
| 112 | - 'type' => 'email', |
|
| 113 | - ), |
|
| 114 | - 'cc' => array( |
|
| 115 | - 'shortcodes' => $valid_shortcodes['to'], |
|
| 116 | - 'type' => 'email', |
|
| 117 | - ), |
|
| 118 | - 'from' => array( |
|
| 119 | - 'shortcodes' => $valid_shortcodes['from'], |
|
| 120 | - 'type' => 'email', |
|
| 121 | - ), |
|
| 122 | - 'subject' => array( |
|
| 123 | - 'shortcodes' => array( |
|
| 124 | - 'organization', |
|
| 125 | - 'primary_registration_details', |
|
| 126 | - 'event_author', |
|
| 127 | - 'primary_registration_details', |
|
| 128 | - 'recipient_details', |
|
| 129 | - ), |
|
| 130 | - ), |
|
| 131 | - 'content' => array( |
|
| 132 | - 'shortcodes' => array( |
|
| 133 | - 'event_list', |
|
| 134 | - 'attendee_list', |
|
| 135 | - 'ticket_list', |
|
| 136 | - 'organization', |
|
| 137 | - 'primary_registration_details', |
|
| 138 | - 'primary_registration_list', |
|
| 139 | - 'event_author', |
|
| 140 | - 'recipient_details', |
|
| 141 | - 'recipient_list', |
|
| 142 | - 'transaction', |
|
| 143 | - 'messenger', |
|
| 144 | - ), |
|
| 145 | - ), |
|
| 146 | - 'attendee_list' => array( |
|
| 147 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
| 148 | - 'required' => array('[ATTENDEE_LIST]'), |
|
| 149 | - ), |
|
| 150 | - 'event_list' => array( |
|
| 151 | - 'shortcodes' => array( |
|
| 152 | - 'event', |
|
| 153 | - 'attendee_list', |
|
| 154 | - 'ticket_list', |
|
| 155 | - 'venue', |
|
| 156 | - 'datetime_list', |
|
| 157 | - 'attendee', |
|
| 158 | - 'primary_registration_details', |
|
| 159 | - 'primary_registration_list', |
|
| 160 | - 'event_author', |
|
| 161 | - 'recipient_details', |
|
| 162 | - 'recipient_list', |
|
| 163 | - ), |
|
| 164 | - 'required' => array('[EVENT_LIST]'), |
|
| 165 | - ), |
|
| 166 | - 'ticket_list' => array( |
|
| 167 | - 'shortcodes' => array( |
|
| 168 | - 'event_list', |
|
| 169 | - 'attendee_list', |
|
| 170 | - 'ticket', |
|
| 171 | - 'datetime_list', |
|
| 172 | - 'primary_registration_details', |
|
| 173 | - 'recipient_details', |
|
| 174 | - ), |
|
| 175 | - 'required' => array('[TICKET_LIST]'), |
|
| 176 | - ), |
|
| 177 | - 'datetime_list' => array( |
|
| 178 | - 'shortcodes' => array('datetime'), |
|
| 179 | - 'required' => array('[DATETIME_LIST]'), |
|
| 180 | - ), |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @see parent EE_messenger class for docs |
|
| 187 | - * @since 4.5.0 |
|
| 188 | - */ |
|
| 189 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 190 | - { |
|
| 191 | - if ($sending_messenger_name = 'html') { |
|
| 192 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - public function add_email_css( |
|
| 198 | - $variation_path, |
|
| 199 | - $messenger, |
|
| 200 | - $message_type, |
|
| 201 | - $type, |
|
| 202 | - $variation, |
|
| 203 | - $file_extension, |
|
| 204 | - $url, |
|
| 205 | - EE_Messages_Template_Pack $template_pack |
|
| 206 | - ) { |
|
| 207 | - //prevent recursion on this callback. |
|
| 208 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
| 209 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
| 210 | - |
|
| 211 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 212 | - return $variation; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * See parent for details |
|
| 218 | - * |
|
| 219 | - * @access protected |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - protected function _set_test_settings_fields() |
|
| 223 | - { |
|
| 224 | - $this->_test_settings_fields = array( |
|
| 225 | - 'to' => array( |
|
| 226 | - 'input' => 'text', |
|
| 227 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
| 228 | - 'type' => 'email', |
|
| 229 | - 'required' => true, |
|
| 230 | - 'validation' => true, |
|
| 231 | - 'css_class' => 'large-text', |
|
| 232 | - 'format' => '%s', |
|
| 233 | - 'default' => get_bloginfo('admin_email'), |
|
| 234 | - ), |
|
| 235 | - 'subject' => array( |
|
| 236 | - 'input' => 'hidden', |
|
| 237 | - 'label' => '', |
|
| 238 | - 'type' => 'string', |
|
| 239 | - 'required' => false, |
|
| 240 | - 'validation' => false, |
|
| 241 | - 'format' => '%s', |
|
| 242 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
| 243 | - 'default' => '', |
|
| 244 | - 'css_class' => '', |
|
| 245 | - ), |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * _set_template_fields |
|
| 252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | - * |
|
| 254 | - * @access protected |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - protected function _set_template_fields() |
|
| 258 | - { |
|
| 259 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
| 260 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
| 261 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
| 262 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
| 263 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
| 264 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
| 265 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
| 266 | - // will not be displayed/parsed. |
|
| 267 | - $this->_template_fields = array( |
|
| 268 | - 'to' => array( |
|
| 269 | - 'input' => 'text', |
|
| 270 | - 'label' => esc_html_x( |
|
| 271 | - 'To', |
|
| 272 | - 'Label for the "To" field for email addresses', |
|
| 273 | - 'event_espresso' |
|
| 274 | - ), |
|
| 275 | - 'type' => 'string', |
|
| 276 | - 'required' => true, |
|
| 277 | - 'validation' => true, |
|
| 278 | - 'css_class' => 'large-text', |
|
| 279 | - 'format' => '%s', |
|
| 280 | - ), |
|
| 281 | - 'cc' => array( |
|
| 282 | - 'input' => 'text', |
|
| 283 | - 'label' => esc_html_x( |
|
| 284 | - 'CC', |
|
| 285 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
| 286 | - 'event_espresso' |
|
| 287 | - ), |
|
| 288 | - 'type' => 'string', |
|
| 289 | - 'required' => false, |
|
| 290 | - 'validation' => true, |
|
| 291 | - 'css_class' => 'large-text', |
|
| 292 | - 'format' => '%s', |
|
| 293 | - ), |
|
| 294 | - 'from' => array( |
|
| 295 | - 'input' => 'text', |
|
| 296 | - 'label' => esc_html_x( |
|
| 297 | - 'From', |
|
| 298 | - 'Label for the "From" field for email addresses.', |
|
| 299 | - 'event_espresso' |
|
| 300 | - ), |
|
| 301 | - 'type' => 'string', |
|
| 302 | - 'required' => true, |
|
| 303 | - 'validation' => true, |
|
| 304 | - 'css_class' => 'large-text', |
|
| 305 | - 'format' => '%s', |
|
| 306 | - ), |
|
| 307 | - 'subject' => array( |
|
| 308 | - 'input' => 'text', |
|
| 309 | - 'label' => esc_html_x( |
|
| 310 | - 'Subject', |
|
| 311 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
| 312 | - 'event_espresso' |
|
| 313 | - ), |
|
| 314 | - 'type' => 'string', |
|
| 315 | - 'required' => true, |
|
| 316 | - 'validation' => true, |
|
| 317 | - 'css_class' => 'large-text', |
|
| 318 | - 'format' => '%s', |
|
| 319 | - ), |
|
| 320 | - 'content' => '', |
|
| 321 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 322 | - 'extra' => array( |
|
| 323 | - 'content' => array( |
|
| 324 | - 'main' => array( |
|
| 325 | - 'input' => 'wp_editor', |
|
| 326 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 327 | - 'type' => 'string', |
|
| 328 | - 'required' => true, |
|
| 329 | - 'validation' => true, |
|
| 330 | - 'format' => '%s', |
|
| 331 | - 'rows' => '15', |
|
| 332 | - ), |
|
| 333 | - 'event_list' => array( |
|
| 334 | - 'input' => 'wp_editor', |
|
| 335 | - 'label' => '[EVENT_LIST]', |
|
| 336 | - 'type' => 'string', |
|
| 337 | - 'required' => true, |
|
| 338 | - 'validation' => true, |
|
| 339 | - 'format' => '%s', |
|
| 340 | - 'rows' => '15', |
|
| 341 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
| 342 | - ), |
|
| 343 | - 'attendee_list' => array( |
|
| 344 | - 'input' => 'textarea', |
|
| 345 | - 'label' => '[ATTENDEE_LIST]', |
|
| 346 | - 'type' => 'string', |
|
| 347 | - 'required' => true, |
|
| 348 | - 'validation' => true, |
|
| 349 | - 'format' => '%s', |
|
| 350 | - 'css_class' => 'large-text', |
|
| 351 | - 'rows' => '5', |
|
| 352 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
| 353 | - ), |
|
| 354 | - 'ticket_list' => array( |
|
| 355 | - 'input' => 'textarea', |
|
| 356 | - 'label' => '[TICKET_LIST]', |
|
| 357 | - 'type' => 'string', |
|
| 358 | - 'required' => true, |
|
| 359 | - 'validation' => true, |
|
| 360 | - 'format' => '%s', |
|
| 361 | - 'css_class' => 'large-text', |
|
| 362 | - 'rows' => '10', |
|
| 363 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
| 364 | - ), |
|
| 365 | - 'datetime_list' => array( |
|
| 366 | - 'input' => 'textarea', |
|
| 367 | - 'label' => '[DATETIME_LIST]', |
|
| 368 | - 'type' => 'string', |
|
| 369 | - 'required' => true, |
|
| 370 | - 'validation' => true, |
|
| 371 | - 'format' => '%s', |
|
| 372 | - 'css_class' => 'large-text', |
|
| 373 | - 'rows' => '10', |
|
| 374 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
| 375 | - ), |
|
| 376 | - ), |
|
| 377 | - ), |
|
| 378 | - ); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * See definition of this class in parent |
|
| 384 | - */ |
|
| 385 | - protected function _set_default_message_types() |
|
| 386 | - { |
|
| 387 | - $this->_default_message_types = array( |
|
| 388 | - 'payment', |
|
| 389 | - 'payment_refund', |
|
| 390 | - 'registration', |
|
| 391 | - 'not_approved_registration', |
|
| 392 | - 'pending_approval', |
|
| 393 | - ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @see definition of this class in parent |
|
| 399 | - * @since 4.5.0 |
|
| 400 | - */ |
|
| 401 | - protected function _set_valid_message_types() |
|
| 402 | - { |
|
| 403 | - $this->_valid_message_types = array( |
|
| 404 | - 'payment', |
|
| 405 | - 'registration', |
|
| 406 | - 'not_approved_registration', |
|
| 407 | - 'declined_registration', |
|
| 408 | - 'cancelled_registration', |
|
| 409 | - 'pending_approval', |
|
| 410 | - 'registration_summary', |
|
| 411 | - 'payment_reminder', |
|
| 412 | - 'payment_declined', |
|
| 413 | - 'payment_refund', |
|
| 414 | - ); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * setting up admin_settings_fields for messenger. |
|
| 420 | - */ |
|
| 421 | - protected function _set_admin_settings_fields() |
|
| 422 | - { |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * We just deliver the messages don't kill us!! |
|
| 427 | - * |
|
| 428 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
| 429 | - * present. |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 432 | - */ |
|
| 433 | - protected function _send_message() |
|
| 434 | - { |
|
| 435 | - $success = wp_mail( |
|
| 436 | - $this->_to, |
|
| 437 | - //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
| 438 | - //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
| 439 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
| 440 | - $this->_body(), |
|
| 441 | - $this->_headers() |
|
| 442 | - ); |
|
| 443 | - if (! $success) { |
|
| 444 | - EE_Error::add_error( |
|
| 445 | - sprintf( |
|
| 446 | - esc_html__( |
|
| 447 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
| 448 | - 'event_espresso' |
|
| 449 | - ), |
|
| 450 | - $this->_to, |
|
| 451 | - $this->_from, |
|
| 452 | - '<br />' |
|
| 453 | - ), |
|
| 454 | - __FILE__, |
|
| 455 | - __FUNCTION__, |
|
| 456 | - __LINE__ |
|
| 457 | - ); |
|
| 458 | - } |
|
| 459 | - return $success; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * see parent for definition |
|
| 465 | - * |
|
| 466 | - * @return string html body of the message content and the related css. |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 469 | - */ |
|
| 470 | - protected function _preview() |
|
| 471 | - { |
|
| 472 | - return $this->_body(true); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Setup headers for email |
|
| 478 | - * |
|
| 479 | - * @access protected |
|
| 480 | - * @return string formatted header for email |
|
| 481 | - */ |
|
| 482 | - protected function _headers() |
|
| 483 | - { |
|
| 484 | - $this->_ensure_has_from_email_address(); |
|
| 485 | - $from = $this->_from; |
|
| 486 | - $headers = array( |
|
| 487 | - 'From:' . $from, |
|
| 488 | - 'Reply-To:' . $from, |
|
| 489 | - 'Content-Type:text/html; charset=utf-8', |
|
| 490 | - ); |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
| 494 | - * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
| 495 | - * type which they are no longer able to change. |
|
| 496 | - */ |
|
| 497 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
| 498 | - $headers[] = 'cc: ' . $this->_cc; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
| 502 | - // header. |
|
| 503 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
| 504 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
| 505 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
| 511 | - * address for the from address to avoid problems with sending emails. |
|
| 512 | - */ |
|
| 513 | - protected function _ensure_has_from_email_address() |
|
| 514 | - { |
|
| 515 | - if (empty($this->_from)) { |
|
| 516 | - $this->_from = get_bloginfo('admin_email'); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
| 523 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
| 524 | - * be empty |
|
| 525 | - * |
|
| 526 | - * @since 4.3.1 |
|
| 527 | - * @return array |
|
| 528 | - */ |
|
| 529 | - private function _parse_from() |
|
| 530 | - { |
|
| 531 | - if (strpos($this->_from, '<') !== false) { |
|
| 532 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
| 533 | - $from_name = str_replace('"', '', $from_name); |
|
| 534 | - $from_name = trim($from_name); |
|
| 535 | - |
|
| 536 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
| 537 | - $from_email = str_replace('>', '', $from_email); |
|
| 538 | - $from_email = trim($from_email); |
|
| 539 | - } elseif (trim($this->_from) !== '') { |
|
| 540 | - $from_name = ''; |
|
| 541 | - $from_email = trim($this->_from); |
|
| 542 | - } else { |
|
| 543 | - $from_name = $from_email = ''; |
|
| 544 | - } |
|
| 545 | - return array($from_name, $from_email); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Callback for the wp_mail_from filter. |
|
| 551 | - * |
|
| 552 | - * @since 4.3.1 |
|
| 553 | - * @param string $from_email What the original from_email is. |
|
| 554 | - * @return string |
|
| 555 | - */ |
|
| 556 | - public function set_from_address($from_email) |
|
| 557 | - { |
|
| 558 | - $parsed_from = $this->_parse_from(); |
|
| 559 | - //includes fallback if the parsing failed. |
|
| 560 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
| 561 | - ? $parsed_from[1] |
|
| 562 | - : get_bloginfo('admin_email'); |
|
| 563 | - return $from_email; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Callback fro the wp_mail_from_name filter. |
|
| 569 | - * |
|
| 570 | - * @since 4.3.1 |
|
| 571 | - * @param string $from_name The original from_name. |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 574 | - public function set_from_name($from_name) |
|
| 575 | - { |
|
| 576 | - $parsed_from = $this->_parse_from(); |
|
| 577 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
| 578 | - $from_name = $parsed_from[0]; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
| 582 | - //but realize the default name is HTML entity-encoded |
|
| 583 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
| 584 | - |
|
| 585 | - return $from_name; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * setup body for email |
|
| 591 | - * |
|
| 592 | - * @param bool $preview will determine whether this is preview template or not. |
|
| 593 | - * @return string formatted body for email. |
|
| 594 | - * @throws EE_Error |
|
| 595 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 596 | - */ |
|
| 597 | - protected function _body($preview = false) |
|
| 598 | - { |
|
| 599 | - //setup template args! |
|
| 600 | - $this->_template_args = array( |
|
| 601 | - 'subject' => $this->_subject, |
|
| 602 | - 'from' => $this->_from, |
|
| 603 | - 'main_body' => wpautop($this->_content), |
|
| 604 | - ); |
|
| 605 | - $body = $this->_get_main_template($preview); |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
| 609 | - * |
|
| 610 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
| 611 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
| 612 | - */ |
|
| 613 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
| 614 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
| 615 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
| 616 | - |
|
| 617 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
| 618 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 619 | - $style = file_get_contents( |
|
| 620 | - $this->get_variation( |
|
| 621 | - $this->_tmp_pack, |
|
| 622 | - $this->_incoming_message_type->name, |
|
| 623 | - false, |
|
| 624 | - 'main', |
|
| 625 | - $this->_variation |
|
| 626 | - ), |
|
| 627 | - true |
|
| 628 | - ); |
|
| 629 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
| 630 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
| 631 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
| 632 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
| 633 | - $body = ltrim($body, "<?"); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - } |
|
| 637 | - return $body; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * This just returns any existing test settings that might be saved in the database |
|
| 643 | - * |
|
| 644 | - * @access public |
|
| 645 | - * @return array |
|
| 646 | - */ |
|
| 647 | - public function get_existing_test_settings() |
|
| 648 | - { |
|
| 649 | - $settings = parent::get_existing_test_settings(); |
|
| 650 | - //override subject if present because we always want it to be fresh. |
|
| 651 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
| 652 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
| 653 | - } |
|
| 654 | - return $settings; |
|
| 655 | - } |
|
| 11 | + /** |
|
| 12 | + * To field for email |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $_to = ''; |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * CC field for email. |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $_cc = ''; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * From field for email |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $_from = ''; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Subject field for email |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_subject = ''; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Content field for email |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_content = ''; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * constructor |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + */ |
|
| 50 | + public function __construct() |
|
| 51 | + { |
|
| 52 | + //set name and description properties |
|
| 53 | + $this->name = 'email'; |
|
| 54 | + $this->description = sprintf( |
|
| 55 | + esc_html__( |
|
| 56 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
| 57 | + 'event_espresso' |
|
| 58 | + ), |
|
| 59 | + '<code>wp_mail</code>' |
|
| 60 | + ); |
|
| 61 | + $this->label = array( |
|
| 62 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
| 63 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
| 64 | + ); |
|
| 65 | + $this->activate_on_install = true; |
|
| 66 | + |
|
| 67 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
| 68 | + // properties |
|
| 69 | + parent::__construct(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * see abstract declaration in parent class for details. |
|
| 75 | + */ |
|
| 76 | + protected function _set_admin_pages() |
|
| 77 | + { |
|
| 78 | + $this->admin_registered_pages = array( |
|
| 79 | + 'events_edit' => true, |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * see abstract declaration in parent class for details |
|
| 86 | + */ |
|
| 87 | + protected function _set_valid_shortcodes() |
|
| 88 | + { |
|
| 89 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
| 90 | + // message type. |
|
| 91 | + $this->_valid_shortcodes = array( |
|
| 92 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 93 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 94 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * see abstract declaration in parent class for details |
|
| 101 | + * |
|
| 102 | + * @access protected |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + protected function _set_validator_config() |
|
| 106 | + { |
|
| 107 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
| 108 | + |
|
| 109 | + $this->_validator_config = array( |
|
| 110 | + 'to' => array( |
|
| 111 | + 'shortcodes' => $valid_shortcodes['to'], |
|
| 112 | + 'type' => 'email', |
|
| 113 | + ), |
|
| 114 | + 'cc' => array( |
|
| 115 | + 'shortcodes' => $valid_shortcodes['to'], |
|
| 116 | + 'type' => 'email', |
|
| 117 | + ), |
|
| 118 | + 'from' => array( |
|
| 119 | + 'shortcodes' => $valid_shortcodes['from'], |
|
| 120 | + 'type' => 'email', |
|
| 121 | + ), |
|
| 122 | + 'subject' => array( |
|
| 123 | + 'shortcodes' => array( |
|
| 124 | + 'organization', |
|
| 125 | + 'primary_registration_details', |
|
| 126 | + 'event_author', |
|
| 127 | + 'primary_registration_details', |
|
| 128 | + 'recipient_details', |
|
| 129 | + ), |
|
| 130 | + ), |
|
| 131 | + 'content' => array( |
|
| 132 | + 'shortcodes' => array( |
|
| 133 | + 'event_list', |
|
| 134 | + 'attendee_list', |
|
| 135 | + 'ticket_list', |
|
| 136 | + 'organization', |
|
| 137 | + 'primary_registration_details', |
|
| 138 | + 'primary_registration_list', |
|
| 139 | + 'event_author', |
|
| 140 | + 'recipient_details', |
|
| 141 | + 'recipient_list', |
|
| 142 | + 'transaction', |
|
| 143 | + 'messenger', |
|
| 144 | + ), |
|
| 145 | + ), |
|
| 146 | + 'attendee_list' => array( |
|
| 147 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
| 148 | + 'required' => array('[ATTENDEE_LIST]'), |
|
| 149 | + ), |
|
| 150 | + 'event_list' => array( |
|
| 151 | + 'shortcodes' => array( |
|
| 152 | + 'event', |
|
| 153 | + 'attendee_list', |
|
| 154 | + 'ticket_list', |
|
| 155 | + 'venue', |
|
| 156 | + 'datetime_list', |
|
| 157 | + 'attendee', |
|
| 158 | + 'primary_registration_details', |
|
| 159 | + 'primary_registration_list', |
|
| 160 | + 'event_author', |
|
| 161 | + 'recipient_details', |
|
| 162 | + 'recipient_list', |
|
| 163 | + ), |
|
| 164 | + 'required' => array('[EVENT_LIST]'), |
|
| 165 | + ), |
|
| 166 | + 'ticket_list' => array( |
|
| 167 | + 'shortcodes' => array( |
|
| 168 | + 'event_list', |
|
| 169 | + 'attendee_list', |
|
| 170 | + 'ticket', |
|
| 171 | + 'datetime_list', |
|
| 172 | + 'primary_registration_details', |
|
| 173 | + 'recipient_details', |
|
| 174 | + ), |
|
| 175 | + 'required' => array('[TICKET_LIST]'), |
|
| 176 | + ), |
|
| 177 | + 'datetime_list' => array( |
|
| 178 | + 'shortcodes' => array('datetime'), |
|
| 179 | + 'required' => array('[DATETIME_LIST]'), |
|
| 180 | + ), |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @see parent EE_messenger class for docs |
|
| 187 | + * @since 4.5.0 |
|
| 188 | + */ |
|
| 189 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 190 | + { |
|
| 191 | + if ($sending_messenger_name = 'html') { |
|
| 192 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + public function add_email_css( |
|
| 198 | + $variation_path, |
|
| 199 | + $messenger, |
|
| 200 | + $message_type, |
|
| 201 | + $type, |
|
| 202 | + $variation, |
|
| 203 | + $file_extension, |
|
| 204 | + $url, |
|
| 205 | + EE_Messages_Template_Pack $template_pack |
|
| 206 | + ) { |
|
| 207 | + //prevent recursion on this callback. |
|
| 208 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
| 209 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
| 210 | + |
|
| 211 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
| 212 | + return $variation; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * See parent for details |
|
| 218 | + * |
|
| 219 | + * @access protected |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + protected function _set_test_settings_fields() |
|
| 223 | + { |
|
| 224 | + $this->_test_settings_fields = array( |
|
| 225 | + 'to' => array( |
|
| 226 | + 'input' => 'text', |
|
| 227 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
| 228 | + 'type' => 'email', |
|
| 229 | + 'required' => true, |
|
| 230 | + 'validation' => true, |
|
| 231 | + 'css_class' => 'large-text', |
|
| 232 | + 'format' => '%s', |
|
| 233 | + 'default' => get_bloginfo('admin_email'), |
|
| 234 | + ), |
|
| 235 | + 'subject' => array( |
|
| 236 | + 'input' => 'hidden', |
|
| 237 | + 'label' => '', |
|
| 238 | + 'type' => 'string', |
|
| 239 | + 'required' => false, |
|
| 240 | + 'validation' => false, |
|
| 241 | + 'format' => '%s', |
|
| 242 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
| 243 | + 'default' => '', |
|
| 244 | + 'css_class' => '', |
|
| 245 | + ), |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * _set_template_fields |
|
| 252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | + * |
|
| 254 | + * @access protected |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + protected function _set_template_fields() |
|
| 258 | + { |
|
| 259 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
| 260 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
| 261 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
| 262 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
| 263 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
| 264 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
| 265 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
| 266 | + // will not be displayed/parsed. |
|
| 267 | + $this->_template_fields = array( |
|
| 268 | + 'to' => array( |
|
| 269 | + 'input' => 'text', |
|
| 270 | + 'label' => esc_html_x( |
|
| 271 | + 'To', |
|
| 272 | + 'Label for the "To" field for email addresses', |
|
| 273 | + 'event_espresso' |
|
| 274 | + ), |
|
| 275 | + 'type' => 'string', |
|
| 276 | + 'required' => true, |
|
| 277 | + 'validation' => true, |
|
| 278 | + 'css_class' => 'large-text', |
|
| 279 | + 'format' => '%s', |
|
| 280 | + ), |
|
| 281 | + 'cc' => array( |
|
| 282 | + 'input' => 'text', |
|
| 283 | + 'label' => esc_html_x( |
|
| 284 | + 'CC', |
|
| 285 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
| 286 | + 'event_espresso' |
|
| 287 | + ), |
|
| 288 | + 'type' => 'string', |
|
| 289 | + 'required' => false, |
|
| 290 | + 'validation' => true, |
|
| 291 | + 'css_class' => 'large-text', |
|
| 292 | + 'format' => '%s', |
|
| 293 | + ), |
|
| 294 | + 'from' => array( |
|
| 295 | + 'input' => 'text', |
|
| 296 | + 'label' => esc_html_x( |
|
| 297 | + 'From', |
|
| 298 | + 'Label for the "From" field for email addresses.', |
|
| 299 | + 'event_espresso' |
|
| 300 | + ), |
|
| 301 | + 'type' => 'string', |
|
| 302 | + 'required' => true, |
|
| 303 | + 'validation' => true, |
|
| 304 | + 'css_class' => 'large-text', |
|
| 305 | + 'format' => '%s', |
|
| 306 | + ), |
|
| 307 | + 'subject' => array( |
|
| 308 | + 'input' => 'text', |
|
| 309 | + 'label' => esc_html_x( |
|
| 310 | + 'Subject', |
|
| 311 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
| 312 | + 'event_espresso' |
|
| 313 | + ), |
|
| 314 | + 'type' => 'string', |
|
| 315 | + 'required' => true, |
|
| 316 | + 'validation' => true, |
|
| 317 | + 'css_class' => 'large-text', |
|
| 318 | + 'format' => '%s', |
|
| 319 | + ), |
|
| 320 | + 'content' => '', |
|
| 321 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 322 | + 'extra' => array( |
|
| 323 | + 'content' => array( |
|
| 324 | + 'main' => array( |
|
| 325 | + 'input' => 'wp_editor', |
|
| 326 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 327 | + 'type' => 'string', |
|
| 328 | + 'required' => true, |
|
| 329 | + 'validation' => true, |
|
| 330 | + 'format' => '%s', |
|
| 331 | + 'rows' => '15', |
|
| 332 | + ), |
|
| 333 | + 'event_list' => array( |
|
| 334 | + 'input' => 'wp_editor', |
|
| 335 | + 'label' => '[EVENT_LIST]', |
|
| 336 | + 'type' => 'string', |
|
| 337 | + 'required' => true, |
|
| 338 | + 'validation' => true, |
|
| 339 | + 'format' => '%s', |
|
| 340 | + 'rows' => '15', |
|
| 341 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
| 342 | + ), |
|
| 343 | + 'attendee_list' => array( |
|
| 344 | + 'input' => 'textarea', |
|
| 345 | + 'label' => '[ATTENDEE_LIST]', |
|
| 346 | + 'type' => 'string', |
|
| 347 | + 'required' => true, |
|
| 348 | + 'validation' => true, |
|
| 349 | + 'format' => '%s', |
|
| 350 | + 'css_class' => 'large-text', |
|
| 351 | + 'rows' => '5', |
|
| 352 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
| 353 | + ), |
|
| 354 | + 'ticket_list' => array( |
|
| 355 | + 'input' => 'textarea', |
|
| 356 | + 'label' => '[TICKET_LIST]', |
|
| 357 | + 'type' => 'string', |
|
| 358 | + 'required' => true, |
|
| 359 | + 'validation' => true, |
|
| 360 | + 'format' => '%s', |
|
| 361 | + 'css_class' => 'large-text', |
|
| 362 | + 'rows' => '10', |
|
| 363 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
| 364 | + ), |
|
| 365 | + 'datetime_list' => array( |
|
| 366 | + 'input' => 'textarea', |
|
| 367 | + 'label' => '[DATETIME_LIST]', |
|
| 368 | + 'type' => 'string', |
|
| 369 | + 'required' => true, |
|
| 370 | + 'validation' => true, |
|
| 371 | + 'format' => '%s', |
|
| 372 | + 'css_class' => 'large-text', |
|
| 373 | + 'rows' => '10', |
|
| 374 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
| 375 | + ), |
|
| 376 | + ), |
|
| 377 | + ), |
|
| 378 | + ); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * See definition of this class in parent |
|
| 384 | + */ |
|
| 385 | + protected function _set_default_message_types() |
|
| 386 | + { |
|
| 387 | + $this->_default_message_types = array( |
|
| 388 | + 'payment', |
|
| 389 | + 'payment_refund', |
|
| 390 | + 'registration', |
|
| 391 | + 'not_approved_registration', |
|
| 392 | + 'pending_approval', |
|
| 393 | + ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @see definition of this class in parent |
|
| 399 | + * @since 4.5.0 |
|
| 400 | + */ |
|
| 401 | + protected function _set_valid_message_types() |
|
| 402 | + { |
|
| 403 | + $this->_valid_message_types = array( |
|
| 404 | + 'payment', |
|
| 405 | + 'registration', |
|
| 406 | + 'not_approved_registration', |
|
| 407 | + 'declined_registration', |
|
| 408 | + 'cancelled_registration', |
|
| 409 | + 'pending_approval', |
|
| 410 | + 'registration_summary', |
|
| 411 | + 'payment_reminder', |
|
| 412 | + 'payment_declined', |
|
| 413 | + 'payment_refund', |
|
| 414 | + ); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * setting up admin_settings_fields for messenger. |
|
| 420 | + */ |
|
| 421 | + protected function _set_admin_settings_fields() |
|
| 422 | + { |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * We just deliver the messages don't kill us!! |
|
| 427 | + * |
|
| 428 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
| 429 | + * present. |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 432 | + */ |
|
| 433 | + protected function _send_message() |
|
| 434 | + { |
|
| 435 | + $success = wp_mail( |
|
| 436 | + $this->_to, |
|
| 437 | + //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
| 438 | + //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
| 439 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
| 440 | + $this->_body(), |
|
| 441 | + $this->_headers() |
|
| 442 | + ); |
|
| 443 | + if (! $success) { |
|
| 444 | + EE_Error::add_error( |
|
| 445 | + sprintf( |
|
| 446 | + esc_html__( |
|
| 447 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
| 448 | + 'event_espresso' |
|
| 449 | + ), |
|
| 450 | + $this->_to, |
|
| 451 | + $this->_from, |
|
| 452 | + '<br />' |
|
| 453 | + ), |
|
| 454 | + __FILE__, |
|
| 455 | + __FUNCTION__, |
|
| 456 | + __LINE__ |
|
| 457 | + ); |
|
| 458 | + } |
|
| 459 | + return $success; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * see parent for definition |
|
| 465 | + * |
|
| 466 | + * @return string html body of the message content and the related css. |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 469 | + */ |
|
| 470 | + protected function _preview() |
|
| 471 | + { |
|
| 472 | + return $this->_body(true); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Setup headers for email |
|
| 478 | + * |
|
| 479 | + * @access protected |
|
| 480 | + * @return string formatted header for email |
|
| 481 | + */ |
|
| 482 | + protected function _headers() |
|
| 483 | + { |
|
| 484 | + $this->_ensure_has_from_email_address(); |
|
| 485 | + $from = $this->_from; |
|
| 486 | + $headers = array( |
|
| 487 | + 'From:' . $from, |
|
| 488 | + 'Reply-To:' . $from, |
|
| 489 | + 'Content-Type:text/html; charset=utf-8', |
|
| 490 | + ); |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
| 494 | + * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
| 495 | + * type which they are no longer able to change. |
|
| 496 | + */ |
|
| 497 | + if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
| 498 | + $headers[] = 'cc: ' . $this->_cc; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
| 502 | + // header. |
|
| 503 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
| 504 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
| 505 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
| 511 | + * address for the from address to avoid problems with sending emails. |
|
| 512 | + */ |
|
| 513 | + protected function _ensure_has_from_email_address() |
|
| 514 | + { |
|
| 515 | + if (empty($this->_from)) { |
|
| 516 | + $this->_from = get_bloginfo('admin_email'); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
| 523 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
| 524 | + * be empty |
|
| 525 | + * |
|
| 526 | + * @since 4.3.1 |
|
| 527 | + * @return array |
|
| 528 | + */ |
|
| 529 | + private function _parse_from() |
|
| 530 | + { |
|
| 531 | + if (strpos($this->_from, '<') !== false) { |
|
| 532 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
| 533 | + $from_name = str_replace('"', '', $from_name); |
|
| 534 | + $from_name = trim($from_name); |
|
| 535 | + |
|
| 536 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
| 537 | + $from_email = str_replace('>', '', $from_email); |
|
| 538 | + $from_email = trim($from_email); |
|
| 539 | + } elseif (trim($this->_from) !== '') { |
|
| 540 | + $from_name = ''; |
|
| 541 | + $from_email = trim($this->_from); |
|
| 542 | + } else { |
|
| 543 | + $from_name = $from_email = ''; |
|
| 544 | + } |
|
| 545 | + return array($from_name, $from_email); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Callback for the wp_mail_from filter. |
|
| 551 | + * |
|
| 552 | + * @since 4.3.1 |
|
| 553 | + * @param string $from_email What the original from_email is. |
|
| 554 | + * @return string |
|
| 555 | + */ |
|
| 556 | + public function set_from_address($from_email) |
|
| 557 | + { |
|
| 558 | + $parsed_from = $this->_parse_from(); |
|
| 559 | + //includes fallback if the parsing failed. |
|
| 560 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
| 561 | + ? $parsed_from[1] |
|
| 562 | + : get_bloginfo('admin_email'); |
|
| 563 | + return $from_email; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Callback fro the wp_mail_from_name filter. |
|
| 569 | + * |
|
| 570 | + * @since 4.3.1 |
|
| 571 | + * @param string $from_name The original from_name. |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | + public function set_from_name($from_name) |
|
| 575 | + { |
|
| 576 | + $parsed_from = $this->_parse_from(); |
|
| 577 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
| 578 | + $from_name = $parsed_from[0]; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
| 582 | + //but realize the default name is HTML entity-encoded |
|
| 583 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
| 584 | + |
|
| 585 | + return $from_name; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * setup body for email |
|
| 591 | + * |
|
| 592 | + * @param bool $preview will determine whether this is preview template or not. |
|
| 593 | + * @return string formatted body for email. |
|
| 594 | + * @throws EE_Error |
|
| 595 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
| 596 | + */ |
|
| 597 | + protected function _body($preview = false) |
|
| 598 | + { |
|
| 599 | + //setup template args! |
|
| 600 | + $this->_template_args = array( |
|
| 601 | + 'subject' => $this->_subject, |
|
| 602 | + 'from' => $this->_from, |
|
| 603 | + 'main_body' => wpautop($this->_content), |
|
| 604 | + ); |
|
| 605 | + $body = $this->_get_main_template($preview); |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
| 609 | + * |
|
| 610 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
| 611 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
| 612 | + */ |
|
| 613 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
| 614 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
| 615 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
| 616 | + |
|
| 617 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
| 618 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 619 | + $style = file_get_contents( |
|
| 620 | + $this->get_variation( |
|
| 621 | + $this->_tmp_pack, |
|
| 622 | + $this->_incoming_message_type->name, |
|
| 623 | + false, |
|
| 624 | + 'main', |
|
| 625 | + $this->_variation |
|
| 626 | + ), |
|
| 627 | + true |
|
| 628 | + ); |
|
| 629 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
| 630 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
| 631 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
| 632 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
| 633 | + $body = ltrim($body, "<?"); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + } |
|
| 637 | + return $body; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * This just returns any existing test settings that might be saved in the database |
|
| 643 | + * |
|
| 644 | + * @access public |
|
| 645 | + * @return array |
|
| 646 | + */ |
|
| 647 | + public function get_existing_test_settings() |
|
| 648 | + { |
|
| 649 | + $settings = parent::get_existing_test_settings(); |
|
| 650 | + //override subject if present because we always want it to be fresh. |
|
| 651 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
| 652 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
| 653 | + } |
|
| 654 | + return $settings; |
|
| 655 | + } |
|
| 656 | 656 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ), |
| 59 | 59 | '<code>wp_mail</code>' |
| 60 | 60 | ); |
| 61 | - $this->label = array( |
|
| 61 | + $this->label = array( |
|
| 62 | 62 | 'singular' => esc_html__('email', 'event_espresso'), |
| 63 | 63 | 'plural' => esc_html__('emails', 'event_espresso'), |
| 64 | 64 | ); |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $this->_body(), |
| 441 | 441 | $this->_headers() |
| 442 | 442 | ); |
| 443 | - if (! $success) { |
|
| 443 | + if ( ! $success) { |
|
| 444 | 444 | EE_Error::add_error( |
| 445 | 445 | sprintf( |
| 446 | 446 | esc_html__( |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | $this->_ensure_has_from_email_address(); |
| 485 | 485 | $from = $this->_from; |
| 486 | 486 | $headers = array( |
| 487 | - 'From:' . $from, |
|
| 488 | - 'Reply-To:' . $from, |
|
| 487 | + 'From:'.$from, |
|
| 488 | + 'Reply-To:'.$from, |
|
| 489 | 489 | 'Content-Type:text/html; charset=utf-8', |
| 490 | 490 | ); |
| 491 | 491 | |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
| 495 | 495 | * type which they are no longer able to change. |
| 496 | 496 | */ |
| 497 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
| 498 | - $headers[] = 'cc: ' . $this->_cc; |
|
| 497 | + if ( ! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
| 498 | + $headers[] = 'cc: '.$this->_cc; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | 'from' => $this->_from, |
| 603 | 603 | 'main_body' => wpautop($this->_content), |
| 604 | 604 | ); |
| 605 | - $body = $this->_get_main_template($preview); |
|
| 605 | + $body = $this->_get_main_template($preview); |
|
| 606 | 606 | |
| 607 | 607 | /** |
| 608 | 608 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
@@ -612,10 +612,10 @@ discard block |
||
| 612 | 612 | */ |
| 613 | 613 | if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
| 614 | 614 | //require CssToInlineStyles library and its dependencies via composer autoloader |
| 615 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
| 615 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php'; |
|
| 616 | 616 | |
| 617 | 617 | //now if this isn't a preview, let's setup the body so it has inline styles |
| 618 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 618 | + if ( ! $preview || ($preview && defined('DOING_AJAX'))) { |
|
| 619 | 619 | $style = file_get_contents( |
| 620 | 620 | $this->get_variation( |
| 621 | 621 | $this->_tmp_pack, |