@@ -22,744 +22,744 @@ |
||
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return EED_Module|EED_Add_New_State |
|
| 27 | - */ |
|
| 28 | - public static function instance() |
|
| 29 | - { |
|
| 30 | - return parent::get_instance(__CLASS__); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public static function set_hooks() |
|
| 41 | - { |
|
| 42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks_admin() |
|
| 69 | - { |
|
| 70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public static function set_definitions() |
|
| 101 | - { |
|
| 102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | - '\\', |
|
| 105 | - DS, |
|
| 106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param WP $WP |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function run($WP) |
|
| 117 | - { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public static function translate_js_strings() |
|
| 126 | - { |
|
| 127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | - 'event_espresso' |
|
| 130 | - ); |
|
| 131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ); |
|
| 135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | - 'event_espresso' |
|
| 138 | - ); |
|
| 139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | - 'The new state was successfully saved to the database.', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ); |
|
| 143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - public static function wp_enqueue_scripts() |
|
| 155 | - { |
|
| 156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | - wp_enqueue_script('add_new_state'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * display_add_new_state_micro_form |
|
| 167 | - * |
|
| 168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | - * @return string |
|
| 170 | - * @throws EE_Error |
|
| 171 | - * @throws InvalidArgumentException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - */ |
|
| 175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | - { |
|
| 178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | - // is the "state" question in this form section? |
|
| 182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | - if ($input instanceof EE_State_Select_Input) { |
|
| 187 | - $input->html_name(); |
|
| 188 | - } |
|
| 189 | - return $question_group_reg_form; |
|
| 190 | - } |
|
| 191 | - // we're only doing this for state select inputs |
|
| 192 | - if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | - // grab any set values from the request |
|
| 194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | - $country_options = array(); |
|
| 199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | - if (! empty($countries)) { |
|
| 201 | - foreach ($countries as $country) { |
|
| 202 | - if ($country instanceof EE_Country) { |
|
| 203 | - $country_options[$country->ID()] = $country->name(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | - array( |
|
| 209 | - 'name' => 'new_state_micro_form', |
|
| 210 | - 'html_id' => 'new_state_micro_form', |
|
| 211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | - 'subsections' => array( |
|
| 213 | - // add hidden input to indicate that a new state is being added |
|
| 214 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | - array( |
|
| 216 | - 'html_name' => str_replace( |
|
| 217 | - 'state', |
|
| 218 | - 'nsmf_add_new_state', |
|
| 219 | - $input->html_name() |
|
| 220 | - ), |
|
| 221 | - 'html_id' => str_replace( |
|
| 222 | - 'state', |
|
| 223 | - 'nsmf_add_new_state', |
|
| 224 | - $input->html_id() |
|
| 225 | - ), |
|
| 226 | - 'default' => 0, |
|
| 227 | - ) |
|
| 228 | - ), |
|
| 229 | - // add link for displaying hidden container |
|
| 230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | - apply_filters( |
|
| 232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | - EEH_HTML::link( |
|
| 234 | - '', |
|
| 235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | - '', |
|
| 237 | - 'display-' . $input->html_id(), |
|
| 238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | - '', |
|
| 240 | - 'data-target="' . $input->html_id() . '"' |
|
| 241 | - ) |
|
| 242 | - ) |
|
| 243 | - ), |
|
| 244 | - // add initial html for hidden container |
|
| 245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | - apply_filters( |
|
| 247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | - 'display: none;') . |
|
| 250 | - EEH_HTML::h6( |
|
| 251 | - esc_html__( |
|
| 252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ) |
|
| 255 | - ) . |
|
| 256 | - EEH_HTML::ul() . |
|
| 257 | - EEH_HTML::li( |
|
| 258 | - esc_html__( |
|
| 259 | - 'first select the Country that your State/Province belongs to', |
|
| 260 | - 'event_espresso' |
|
| 261 | - ) |
|
| 262 | - ) . |
|
| 263 | - EEH_HTML::li( |
|
| 264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | - ) . |
|
| 266 | - EEH_HTML::li( |
|
| 267 | - esc_html__( |
|
| 268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ) |
|
| 271 | - ) . |
|
| 272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | - EEH_HTML::ulx() |
|
| 274 | - ) |
|
| 275 | - ), |
|
| 276 | - // NEW STATE COUNTRY |
|
| 277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | - $country_options, |
|
| 279 | - array( |
|
| 280 | - 'html_name' => $country_name, |
|
| 281 | - 'html_id' => str_replace( |
|
| 282 | - 'state', |
|
| 283 | - 'nsmf_new_state_country', $input->html_id() |
|
| 284 | - ), |
|
| 285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | - 'required' => false, |
|
| 289 | - ) |
|
| 290 | - ), |
|
| 291 | - // NEW STATE NAME |
|
| 292 | - 'new_state_name' => new EE_Text_Input( |
|
| 293 | - array( |
|
| 294 | - 'html_name' => $state_name, |
|
| 295 | - 'html_id' => str_replace( |
|
| 296 | - 'state', |
|
| 297 | - 'nsmf_new_state_name', $input->html_id() |
|
| 298 | - ), |
|
| 299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | - 'event_espresso'), |
|
| 302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | - 'required' => false, |
|
| 304 | - ) |
|
| 305 | - ), |
|
| 306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | - // NEW STATE NAME |
|
| 308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | - array( |
|
| 310 | - 'html_name' => $abbrv_name, |
|
| 311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | - $input->html_id()), |
|
| 313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | - 'html_label_text' => esc_html__( |
|
| 315 | - 'New State/Province Abbreviation', |
|
| 316 | - 'event_espresso' |
|
| 317 | - ) . ' *', |
|
| 318 | - 'html_other_attributes' => 'size="24"', |
|
| 319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | - 'required' => false, |
|
| 321 | - ) |
|
| 322 | - ), |
|
| 323 | - // "submit" button |
|
| 324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | - apply_filters( |
|
| 326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | - EEH_HTML::nbsp(3) . |
|
| 328 | - EEH_HTML::link( |
|
| 329 | - '', |
|
| 330 | - esc_html__('ADD', 'event_espresso'), |
|
| 331 | - '', |
|
| 332 | - 'submit-' . $new_state_submit_id, |
|
| 333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | - '', |
|
| 335 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | - ) |
|
| 337 | - ) |
|
| 338 | - ), |
|
| 339 | - // extra info |
|
| 340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | - apply_filters( |
|
| 342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | - EEH_HTML::br(2) |
|
| 344 | - . |
|
| 345 | - EEH_HTML::div('', '', 'small-text') |
|
| 346 | - . |
|
| 347 | - EEH_HTML::strong( |
|
| 348 | - '* ' . |
|
| 349 | - esc_html__( |
|
| 350 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | - 'event_espresso' |
|
| 352 | - ) |
|
| 353 | - ) |
|
| 354 | - . |
|
| 355 | - EEH_HTML::br() |
|
| 356 | - . |
|
| 357 | - sprintf( |
|
| 358 | - esc_html__( |
|
| 359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | - 'event_espresso' |
|
| 361 | - ), |
|
| 362 | - EEH_HTML::link( |
|
| 363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | - '', |
|
| 366 | - '', |
|
| 367 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | - '', |
|
| 369 | - 'target="_blank"' |
|
| 370 | - ) |
|
| 371 | - ) |
|
| 372 | - . |
|
| 373 | - EEH_HTML::divx() |
|
| 374 | - . |
|
| 375 | - EEH_HTML::br() |
|
| 376 | - . |
|
| 377 | - EEH_HTML::link( |
|
| 378 | - '', |
|
| 379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | - '', |
|
| 381 | - 'hide-' . $input->html_id(), |
|
| 382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | - '', |
|
| 384 | - 'data-target="' . $input->html_id() . '"' |
|
| 385 | - ) |
|
| 386 | - . |
|
| 387 | - EEH_HTML::divx() |
|
| 388 | - . |
|
| 389 | - EEH_HTML::br() |
|
| 390 | - ) |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - $question_group_reg_form->add_subsections( |
|
| 396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | - 'state', |
|
| 398 | - false |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - return $question_group_reg_form; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * set_new_state_input_width |
|
| 408 | - * |
|
| 409 | - * @return int|string |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws InvalidDataTypeException |
|
| 413 | - * @throws InvalidInterfaceException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - */ |
|
| 416 | - public static function add_new_state() |
|
| 417 | - { |
|
| 418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | - EE_Registry::instance()->load_model('State'); |
|
| 421 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | - : false; |
|
| 425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | - : false; |
|
| 428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | - : false; |
|
| 431 | - if ($state_country && $state_name && $state_abbr) { |
|
| 432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | - 'STA_name' => ucwords($state_name), |
|
| 436 | - 'STA_active' => false, |
|
| 437 | - )); |
|
| 438 | - if ($new_state instanceof EE_State) { |
|
| 439 | - // clean house |
|
| 440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | - // get any existing new states |
|
| 445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | - 'nsmf_new_states' |
|
| 447 | - ); |
|
| 448 | - $new_states[$new_state->ID()] = $new_state; |
|
| 449 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | - array('nsmf_new_states' => $new_states) |
|
| 451 | - ); |
|
| 452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | - echo wp_json_encode(array( |
|
| 454 | - 'success' => true, |
|
| 455 | - 'id' => $new_state->ID(), |
|
| 456 | - 'name' => $new_state->name(), |
|
| 457 | - 'abbrev' => $new_state->abbrev(), |
|
| 458 | - 'country_iso' => $new_state->country_iso(), |
|
| 459 | - 'country_name' => $new_state->country()->name(), |
|
| 460 | - )); |
|
| 461 | - exit(); |
|
| 462 | - } |
|
| 463 | - return $new_state->ID(); |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - $error = esc_html__( |
|
| 467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | - 'event_espresso' |
|
| 469 | - ); |
|
| 470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | - echo wp_json_encode(array('error' => $error)); |
|
| 472 | - exit(); |
|
| 473 | - } |
|
| 474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * recursively drills down through request params to remove any that were added by this module |
|
| 484 | - * |
|
| 485 | - * @param array $request_params |
|
| 486 | - * @return array |
|
| 487 | - */ |
|
| 488 | - public static function filter_checkout_request_params($request_params) |
|
| 489 | - { |
|
| 490 | - foreach ($request_params as $form_section) { |
|
| 491 | - if (is_array($form_section)) { |
|
| 492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $request_params; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param array $request_params |
|
| 503 | - * @return array |
|
| 504 | - */ |
|
| 505 | - public static function unset_new_state_request_params($request_params) |
|
| 506 | - { |
|
| 507 | - unset( |
|
| 508 | - $request_params['new_state_micro_form'], |
|
| 509 | - $request_params['new_state_micro_add_new_state'], |
|
| 510 | - $request_params['new_state_micro_new_state_country'], |
|
| 511 | - $request_params['new_state_micro_new_state_name'], |
|
| 512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | - ); |
|
| 514 | - return $request_params; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * @param array $props_n_values |
|
| 521 | - * @return bool |
|
| 522 | - * @throws EE_Error |
|
| 523 | - * @throws InvalidArgumentException |
|
| 524 | - * @throws InvalidDataTypeException |
|
| 525 | - * @throws InvalidInterfaceException |
|
| 526 | - */ |
|
| 527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | - { |
|
| 529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | - if (! empty($existing_state)) { |
|
| 531 | - return array_pop($existing_state); |
|
| 532 | - } |
|
| 533 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | - if ($new_state instanceof EE_State) { |
|
| 535 | - $country_settings_url = add_query_arg( |
|
| 536 | - array( |
|
| 537 | - 'page' => 'espresso_general_settings', |
|
| 538 | - 'action' => 'country_settings', |
|
| 539 | - 'country' => $new_state->country_iso(), |
|
| 540 | - ), |
|
| 541 | - admin_url('admin.php') |
|
| 542 | - ); |
|
| 543 | - // if not non-ajax admin |
|
| 544 | - new PersistentAdminNotice( |
|
| 545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | - sprintf( |
|
| 547 | - esc_html__( |
|
| 548 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 549 | - 'event_espresso' |
|
| 550 | - ), |
|
| 551 | - '<b>' . $new_state->name() . '</b>', |
|
| 552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | - '<a href="' |
|
| 555 | - . $country_settings_url |
|
| 556 | - . '">' |
|
| 557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | - 'event_espresso') |
|
| 559 | - . '</a>', |
|
| 560 | - '<br />' |
|
| 561 | - ) |
|
| 562 | - ); |
|
| 563 | - $new_state->save(); |
|
| 564 | - EEM_State::instance()->reset_cached_states(); |
|
| 565 | - return $new_state; |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @param string $CNT_ISO |
|
| 574 | - * @param string $STA_ID |
|
| 575 | - * @param array $cols_n_values |
|
| 576 | - * @return void |
|
| 577 | - * @throws DomainException |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidArgumentException |
|
| 580 | - * @throws InvalidDataTypeException |
|
| 581 | - * @throws InvalidInterfaceException |
|
| 582 | - */ |
|
| 583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | - { |
|
| 585 | - if (! $CNT_ISO) { |
|
| 586 | - EE_Error::add_error( |
|
| 587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | - __FILE__, |
|
| 589 | - __FUNCTION__, |
|
| 590 | - __LINE__ |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | - : false; |
|
| 595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | - if ($state instanceof EE_State) { |
|
| 598 | - $STA_abbrev = $state->abbrev(); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (! $STA_abbrev) { |
|
| 602 | - EE_Error::add_error( |
|
| 603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | - __FILE__, |
|
| 605 | - __FUNCTION__, |
|
| 606 | - __LINE__ |
|
| 607 | - ); |
|
| 608 | - } |
|
| 609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | - ); |
|
| 613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param EE_State[] $state_options |
|
| 620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | - * @param EE_Registration $registration |
|
| 622 | - * @param EE_Question $question |
|
| 623 | - * @param $answer |
|
| 624 | - * @return array |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws InvalidInterfaceException |
|
| 629 | - */ |
|
| 630 | - public static function inject_new_reg_state_into_options( |
|
| 631 | - $state_options = array(), |
|
| 632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | - EE_Registration $registration, |
|
| 634 | - EE_Question $question, |
|
| 635 | - $answer |
|
| 636 | - ) { |
|
| 637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | - && $question->type() === EEM_Question::QST_type_state |
|
| 639 | - ) { |
|
| 640 | - $STA_ID = $answer->value(); |
|
| 641 | - if (! empty($STA_ID)) { |
|
| 642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | - if ($state instanceof EE_State) { |
|
| 644 | - $country = $state->country(); |
|
| 645 | - if ($country instanceof EE_Country) { |
|
| 646 | - if (! isset($state_options[$country->name()])) { |
|
| 647 | - $state_options[$country->name()] = array(); |
|
| 648 | - } |
|
| 649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - return $state_options; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param EE_Country[] $country_options |
|
| 663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | - * @param EE_Registration $registration |
|
| 665 | - * @param EE_Question $question |
|
| 666 | - * @param $answer |
|
| 667 | - * @return array |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws InvalidDataTypeException |
|
| 671 | - * @throws InvalidInterfaceException |
|
| 672 | - */ |
|
| 673 | - public static function inject_new_reg_country_into_options( |
|
| 674 | - $country_options = array(), |
|
| 675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | - EE_Registration $registration, |
|
| 677 | - EE_Question $question, |
|
| 678 | - $answer |
|
| 679 | - ) { |
|
| 680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | - && $question->type() |
|
| 682 | - === EEM_Question::QST_type_country |
|
| 683 | - ) { |
|
| 684 | - $CNT_ISO = $answer->value(); |
|
| 685 | - if (! empty($CNT_ISO)) { |
|
| 686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | - if ($country instanceof EE_Country) { |
|
| 688 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - return $country_options; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param EE_State[] $state_options |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws InvalidArgumentException |
|
| 704 | - * @throws InvalidDataTypeException |
|
| 705 | - * @throws InvalidInterfaceException |
|
| 706 | - */ |
|
| 707 | - public static function state_options($state_options = array()) |
|
| 708 | - { |
|
| 709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | - foreach ($new_states as $new_state) { |
|
| 711 | - if ( |
|
| 712 | - $new_state instanceof EE_State |
|
| 713 | - && $new_state->country() instanceof EE_Country |
|
| 714 | - ) { |
|
| 715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - return $state_options; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @return array |
|
| 725 | - * @throws InvalidArgumentException |
|
| 726 | - * @throws InvalidDataTypeException |
|
| 727 | - * @throws InvalidInterfaceException |
|
| 728 | - */ |
|
| 729 | - protected static function _get_new_states() |
|
| 730 | - { |
|
| 731 | - $new_states = array(); |
|
| 732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | - 'nsmf_new_states' |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - return is_array($new_states) ? $new_states : array(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * @param EE_Country[] $country_options |
|
| 744 | - * @return array |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @throws InvalidArgumentException |
|
| 747 | - * @throws InvalidDataTypeException |
|
| 748 | - * @throws InvalidInterfaceException |
|
| 749 | - */ |
|
| 750 | - public static function country_options($country_options = array()) |
|
| 751 | - { |
|
| 752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | - foreach ($new_states as $new_state) { |
|
| 754 | - if ( |
|
| 755 | - $new_state instanceof EE_State |
|
| 756 | - && $new_state->country() instanceof EE_Country |
|
| 757 | - ) { |
|
| 758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $country_options; |
|
| 762 | - } |
|
| 25 | + /** |
|
| 26 | + * @return EED_Module|EED_Add_New_State |
|
| 27 | + */ |
|
| 28 | + public static function instance() |
|
| 29 | + { |
|
| 30 | + return parent::get_instance(__CLASS__); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public static function set_hooks() |
|
| 41 | + { |
|
| 42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks_admin() |
|
| 69 | + { |
|
| 70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public static function set_definitions() |
|
| 101 | + { |
|
| 102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | + '\\', |
|
| 105 | + DS, |
|
| 106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param WP $WP |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function run($WP) |
|
| 117 | + { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public static function translate_js_strings() |
|
| 126 | + { |
|
| 127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | + 'event_espresso' |
|
| 130 | + ); |
|
| 131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ); |
|
| 135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | + 'event_espresso' |
|
| 138 | + ); |
|
| 139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | + 'The new state was successfully saved to the database.', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ); |
|
| 143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + public static function wp_enqueue_scripts() |
|
| 155 | + { |
|
| 156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | + wp_enqueue_script('add_new_state'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * display_add_new_state_micro_form |
|
| 167 | + * |
|
| 168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | + * @return string |
|
| 170 | + * @throws EE_Error |
|
| 171 | + * @throws InvalidArgumentException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + */ |
|
| 175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | + { |
|
| 178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | + // is the "state" question in this form section? |
|
| 182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | + if ($input instanceof EE_State_Select_Input) { |
|
| 187 | + $input->html_name(); |
|
| 188 | + } |
|
| 189 | + return $question_group_reg_form; |
|
| 190 | + } |
|
| 191 | + // we're only doing this for state select inputs |
|
| 192 | + if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | + // grab any set values from the request |
|
| 194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | + $country_options = array(); |
|
| 199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | + if (! empty($countries)) { |
|
| 201 | + foreach ($countries as $country) { |
|
| 202 | + if ($country instanceof EE_Country) { |
|
| 203 | + $country_options[$country->ID()] = $country->name(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | + array( |
|
| 209 | + 'name' => 'new_state_micro_form', |
|
| 210 | + 'html_id' => 'new_state_micro_form', |
|
| 211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | + 'subsections' => array( |
|
| 213 | + // add hidden input to indicate that a new state is being added |
|
| 214 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | + array( |
|
| 216 | + 'html_name' => str_replace( |
|
| 217 | + 'state', |
|
| 218 | + 'nsmf_add_new_state', |
|
| 219 | + $input->html_name() |
|
| 220 | + ), |
|
| 221 | + 'html_id' => str_replace( |
|
| 222 | + 'state', |
|
| 223 | + 'nsmf_add_new_state', |
|
| 224 | + $input->html_id() |
|
| 225 | + ), |
|
| 226 | + 'default' => 0, |
|
| 227 | + ) |
|
| 228 | + ), |
|
| 229 | + // add link for displaying hidden container |
|
| 230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | + apply_filters( |
|
| 232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | + EEH_HTML::link( |
|
| 234 | + '', |
|
| 235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | + '', |
|
| 237 | + 'display-' . $input->html_id(), |
|
| 238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | + '', |
|
| 240 | + 'data-target="' . $input->html_id() . '"' |
|
| 241 | + ) |
|
| 242 | + ) |
|
| 243 | + ), |
|
| 244 | + // add initial html for hidden container |
|
| 245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | + apply_filters( |
|
| 247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | + 'display: none;') . |
|
| 250 | + EEH_HTML::h6( |
|
| 251 | + esc_html__( |
|
| 252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ) |
|
| 255 | + ) . |
|
| 256 | + EEH_HTML::ul() . |
|
| 257 | + EEH_HTML::li( |
|
| 258 | + esc_html__( |
|
| 259 | + 'first select the Country that your State/Province belongs to', |
|
| 260 | + 'event_espresso' |
|
| 261 | + ) |
|
| 262 | + ) . |
|
| 263 | + EEH_HTML::li( |
|
| 264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | + ) . |
|
| 266 | + EEH_HTML::li( |
|
| 267 | + esc_html__( |
|
| 268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ) |
|
| 271 | + ) . |
|
| 272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | + EEH_HTML::ulx() |
|
| 274 | + ) |
|
| 275 | + ), |
|
| 276 | + // NEW STATE COUNTRY |
|
| 277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | + $country_options, |
|
| 279 | + array( |
|
| 280 | + 'html_name' => $country_name, |
|
| 281 | + 'html_id' => str_replace( |
|
| 282 | + 'state', |
|
| 283 | + 'nsmf_new_state_country', $input->html_id() |
|
| 284 | + ), |
|
| 285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | + 'required' => false, |
|
| 289 | + ) |
|
| 290 | + ), |
|
| 291 | + // NEW STATE NAME |
|
| 292 | + 'new_state_name' => new EE_Text_Input( |
|
| 293 | + array( |
|
| 294 | + 'html_name' => $state_name, |
|
| 295 | + 'html_id' => str_replace( |
|
| 296 | + 'state', |
|
| 297 | + 'nsmf_new_state_name', $input->html_id() |
|
| 298 | + ), |
|
| 299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | + 'event_espresso'), |
|
| 302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | + 'required' => false, |
|
| 304 | + ) |
|
| 305 | + ), |
|
| 306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | + // NEW STATE NAME |
|
| 308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | + array( |
|
| 310 | + 'html_name' => $abbrv_name, |
|
| 311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | + $input->html_id()), |
|
| 313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | + 'html_label_text' => esc_html__( |
|
| 315 | + 'New State/Province Abbreviation', |
|
| 316 | + 'event_espresso' |
|
| 317 | + ) . ' *', |
|
| 318 | + 'html_other_attributes' => 'size="24"', |
|
| 319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | + 'required' => false, |
|
| 321 | + ) |
|
| 322 | + ), |
|
| 323 | + // "submit" button |
|
| 324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | + apply_filters( |
|
| 326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | + EEH_HTML::nbsp(3) . |
|
| 328 | + EEH_HTML::link( |
|
| 329 | + '', |
|
| 330 | + esc_html__('ADD', 'event_espresso'), |
|
| 331 | + '', |
|
| 332 | + 'submit-' . $new_state_submit_id, |
|
| 333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | + '', |
|
| 335 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | + ) |
|
| 337 | + ) |
|
| 338 | + ), |
|
| 339 | + // extra info |
|
| 340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | + apply_filters( |
|
| 342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | + EEH_HTML::br(2) |
|
| 344 | + . |
|
| 345 | + EEH_HTML::div('', '', 'small-text') |
|
| 346 | + . |
|
| 347 | + EEH_HTML::strong( |
|
| 348 | + '* ' . |
|
| 349 | + esc_html__( |
|
| 350 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | + 'event_espresso' |
|
| 352 | + ) |
|
| 353 | + ) |
|
| 354 | + . |
|
| 355 | + EEH_HTML::br() |
|
| 356 | + . |
|
| 357 | + sprintf( |
|
| 358 | + esc_html__( |
|
| 359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | + 'event_espresso' |
|
| 361 | + ), |
|
| 362 | + EEH_HTML::link( |
|
| 363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | + '', |
|
| 366 | + '', |
|
| 367 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | + '', |
|
| 369 | + 'target="_blank"' |
|
| 370 | + ) |
|
| 371 | + ) |
|
| 372 | + . |
|
| 373 | + EEH_HTML::divx() |
|
| 374 | + . |
|
| 375 | + EEH_HTML::br() |
|
| 376 | + . |
|
| 377 | + EEH_HTML::link( |
|
| 378 | + '', |
|
| 379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | + '', |
|
| 381 | + 'hide-' . $input->html_id(), |
|
| 382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | + '', |
|
| 384 | + 'data-target="' . $input->html_id() . '"' |
|
| 385 | + ) |
|
| 386 | + . |
|
| 387 | + EEH_HTML::divx() |
|
| 388 | + . |
|
| 389 | + EEH_HTML::br() |
|
| 390 | + ) |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + $question_group_reg_form->add_subsections( |
|
| 396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | + 'state', |
|
| 398 | + false |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + return $question_group_reg_form; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * set_new_state_input_width |
|
| 408 | + * |
|
| 409 | + * @return int|string |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws InvalidDataTypeException |
|
| 413 | + * @throws InvalidInterfaceException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + */ |
|
| 416 | + public static function add_new_state() |
|
| 417 | + { |
|
| 418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | + EE_Registry::instance()->load_model('State'); |
|
| 421 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | + : false; |
|
| 425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | + : false; |
|
| 428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | + : false; |
|
| 431 | + if ($state_country && $state_name && $state_abbr) { |
|
| 432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | + 'STA_name' => ucwords($state_name), |
|
| 436 | + 'STA_active' => false, |
|
| 437 | + )); |
|
| 438 | + if ($new_state instanceof EE_State) { |
|
| 439 | + // clean house |
|
| 440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | + // get any existing new states |
|
| 445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | + 'nsmf_new_states' |
|
| 447 | + ); |
|
| 448 | + $new_states[$new_state->ID()] = $new_state; |
|
| 449 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | + array('nsmf_new_states' => $new_states) |
|
| 451 | + ); |
|
| 452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | + echo wp_json_encode(array( |
|
| 454 | + 'success' => true, |
|
| 455 | + 'id' => $new_state->ID(), |
|
| 456 | + 'name' => $new_state->name(), |
|
| 457 | + 'abbrev' => $new_state->abbrev(), |
|
| 458 | + 'country_iso' => $new_state->country_iso(), |
|
| 459 | + 'country_name' => $new_state->country()->name(), |
|
| 460 | + )); |
|
| 461 | + exit(); |
|
| 462 | + } |
|
| 463 | + return $new_state->ID(); |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + $error = esc_html__( |
|
| 467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | + 'event_espresso' |
|
| 469 | + ); |
|
| 470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | + echo wp_json_encode(array('error' => $error)); |
|
| 472 | + exit(); |
|
| 473 | + } |
|
| 474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * recursively drills down through request params to remove any that were added by this module |
|
| 484 | + * |
|
| 485 | + * @param array $request_params |
|
| 486 | + * @return array |
|
| 487 | + */ |
|
| 488 | + public static function filter_checkout_request_params($request_params) |
|
| 489 | + { |
|
| 490 | + foreach ($request_params as $form_section) { |
|
| 491 | + if (is_array($form_section)) { |
|
| 492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $request_params; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param array $request_params |
|
| 503 | + * @return array |
|
| 504 | + */ |
|
| 505 | + public static function unset_new_state_request_params($request_params) |
|
| 506 | + { |
|
| 507 | + unset( |
|
| 508 | + $request_params['new_state_micro_form'], |
|
| 509 | + $request_params['new_state_micro_add_new_state'], |
|
| 510 | + $request_params['new_state_micro_new_state_country'], |
|
| 511 | + $request_params['new_state_micro_new_state_name'], |
|
| 512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | + ); |
|
| 514 | + return $request_params; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * @param array $props_n_values |
|
| 521 | + * @return bool |
|
| 522 | + * @throws EE_Error |
|
| 523 | + * @throws InvalidArgumentException |
|
| 524 | + * @throws InvalidDataTypeException |
|
| 525 | + * @throws InvalidInterfaceException |
|
| 526 | + */ |
|
| 527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | + { |
|
| 529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | + if (! empty($existing_state)) { |
|
| 531 | + return array_pop($existing_state); |
|
| 532 | + } |
|
| 533 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | + if ($new_state instanceof EE_State) { |
|
| 535 | + $country_settings_url = add_query_arg( |
|
| 536 | + array( |
|
| 537 | + 'page' => 'espresso_general_settings', |
|
| 538 | + 'action' => 'country_settings', |
|
| 539 | + 'country' => $new_state->country_iso(), |
|
| 540 | + ), |
|
| 541 | + admin_url('admin.php') |
|
| 542 | + ); |
|
| 543 | + // if not non-ajax admin |
|
| 544 | + new PersistentAdminNotice( |
|
| 545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | + sprintf( |
|
| 547 | + esc_html__( |
|
| 548 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 549 | + 'event_espresso' |
|
| 550 | + ), |
|
| 551 | + '<b>' . $new_state->name() . '</b>', |
|
| 552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | + '<a href="' |
|
| 555 | + . $country_settings_url |
|
| 556 | + . '">' |
|
| 557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | + 'event_espresso') |
|
| 559 | + . '</a>', |
|
| 560 | + '<br />' |
|
| 561 | + ) |
|
| 562 | + ); |
|
| 563 | + $new_state->save(); |
|
| 564 | + EEM_State::instance()->reset_cached_states(); |
|
| 565 | + return $new_state; |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @param string $CNT_ISO |
|
| 574 | + * @param string $STA_ID |
|
| 575 | + * @param array $cols_n_values |
|
| 576 | + * @return void |
|
| 577 | + * @throws DomainException |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidArgumentException |
|
| 580 | + * @throws InvalidDataTypeException |
|
| 581 | + * @throws InvalidInterfaceException |
|
| 582 | + */ |
|
| 583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | + { |
|
| 585 | + if (! $CNT_ISO) { |
|
| 586 | + EE_Error::add_error( |
|
| 587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | + __FILE__, |
|
| 589 | + __FUNCTION__, |
|
| 590 | + __LINE__ |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | + : false; |
|
| 595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | + if ($state instanceof EE_State) { |
|
| 598 | + $STA_abbrev = $state->abbrev(); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (! $STA_abbrev) { |
|
| 602 | + EE_Error::add_error( |
|
| 603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | + __FILE__, |
|
| 605 | + __FUNCTION__, |
|
| 606 | + __LINE__ |
|
| 607 | + ); |
|
| 608 | + } |
|
| 609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | + ); |
|
| 613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param EE_State[] $state_options |
|
| 620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | + * @param EE_Registration $registration |
|
| 622 | + * @param EE_Question $question |
|
| 623 | + * @param $answer |
|
| 624 | + * @return array |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws InvalidInterfaceException |
|
| 629 | + */ |
|
| 630 | + public static function inject_new_reg_state_into_options( |
|
| 631 | + $state_options = array(), |
|
| 632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | + EE_Registration $registration, |
|
| 634 | + EE_Question $question, |
|
| 635 | + $answer |
|
| 636 | + ) { |
|
| 637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | + && $question->type() === EEM_Question::QST_type_state |
|
| 639 | + ) { |
|
| 640 | + $STA_ID = $answer->value(); |
|
| 641 | + if (! empty($STA_ID)) { |
|
| 642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | + if ($state instanceof EE_State) { |
|
| 644 | + $country = $state->country(); |
|
| 645 | + if ($country instanceof EE_Country) { |
|
| 646 | + if (! isset($state_options[$country->name()])) { |
|
| 647 | + $state_options[$country->name()] = array(); |
|
| 648 | + } |
|
| 649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + return $state_options; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param EE_Country[] $country_options |
|
| 663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | + * @param EE_Registration $registration |
|
| 665 | + * @param EE_Question $question |
|
| 666 | + * @param $answer |
|
| 667 | + * @return array |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws InvalidDataTypeException |
|
| 671 | + * @throws InvalidInterfaceException |
|
| 672 | + */ |
|
| 673 | + public static function inject_new_reg_country_into_options( |
|
| 674 | + $country_options = array(), |
|
| 675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | + EE_Registration $registration, |
|
| 677 | + EE_Question $question, |
|
| 678 | + $answer |
|
| 679 | + ) { |
|
| 680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | + && $question->type() |
|
| 682 | + === EEM_Question::QST_type_country |
|
| 683 | + ) { |
|
| 684 | + $CNT_ISO = $answer->value(); |
|
| 685 | + if (! empty($CNT_ISO)) { |
|
| 686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | + if ($country instanceof EE_Country) { |
|
| 688 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + return $country_options; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param EE_State[] $state_options |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws InvalidArgumentException |
|
| 704 | + * @throws InvalidDataTypeException |
|
| 705 | + * @throws InvalidInterfaceException |
|
| 706 | + */ |
|
| 707 | + public static function state_options($state_options = array()) |
|
| 708 | + { |
|
| 709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | + foreach ($new_states as $new_state) { |
|
| 711 | + if ( |
|
| 712 | + $new_state instanceof EE_State |
|
| 713 | + && $new_state->country() instanceof EE_Country |
|
| 714 | + ) { |
|
| 715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + return $state_options; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @return array |
|
| 725 | + * @throws InvalidArgumentException |
|
| 726 | + * @throws InvalidDataTypeException |
|
| 727 | + * @throws InvalidInterfaceException |
|
| 728 | + */ |
|
| 729 | + protected static function _get_new_states() |
|
| 730 | + { |
|
| 731 | + $new_states = array(); |
|
| 732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | + 'nsmf_new_states' |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + return is_array($new_states) ? $new_states : array(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * @param EE_Country[] $country_options |
|
| 744 | + * @return array |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @throws InvalidArgumentException |
|
| 747 | + * @throws InvalidDataTypeException |
|
| 748 | + * @throws InvalidInterfaceException |
|
| 749 | + */ |
|
| 750 | + public static function country_options($country_options = array()) |
|
| 751 | + { |
|
| 752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | + foreach ($new_states as $new_state) { |
|
| 754 | + if ( |
|
| 755 | + $new_state instanceof EE_State |
|
| 756 | + && $new_state->country() instanceof EE_Country |
|
| 757 | + ) { |
|
| 758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $country_options; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | |
@@ -27,746 +27,746 @@ |
||
| 27 | 27 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Sets some dynamic defaults |
|
| 32 | - * |
|
| 33 | - * @param array $fieldValues |
|
| 34 | - * @param bool $bydb |
|
| 35 | - * @param string $timezone |
|
| 36 | - * @param array $date_formats |
|
| 37 | - * @throws EE_Error |
|
| 38 | - */ |
|
| 39 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | - { |
|
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | - } |
|
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | - } |
|
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | - } |
|
| 53 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values |
|
| 59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | - * used.) |
|
| 61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | - * date_format and the second value is the time format |
|
| 63 | - * @return EE_Attendee |
|
| 64 | - * @throws EE_Error |
|
| 65 | - */ |
|
| 66 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | - { |
|
| 68 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param array $props_n_values incoming values from the database |
|
| 75 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | - * the website will be used. |
|
| 77 | - * @return EE_Attendee |
|
| 78 | - */ |
|
| 79 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | - { |
|
| 81 | - return new self($props_n_values, true, $timezone); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set Attendee First Name |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @param string $fname |
|
| 90 | - * @throws EE_Error |
|
| 91 | - */ |
|
| 92 | - public function set_fname($fname = '') |
|
| 93 | - { |
|
| 94 | - $this->set('ATT_fname', $fname); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Set Attendee Last Name |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @param string $lname |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function set_lname($lname = '') |
|
| 106 | - { |
|
| 107 | - $this->set('ATT_lname', $lname); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Set Attendee Address |
|
| 113 | - * |
|
| 114 | - * @access public |
|
| 115 | - * @param string $address |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_address($address = '') |
|
| 119 | - { |
|
| 120 | - $this->set('ATT_address', $address); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set Attendee Address2 |
|
| 126 | - * |
|
| 127 | - * @access public |
|
| 128 | - * @param string $address2 |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public function set_address2($address2 = '') |
|
| 132 | - { |
|
| 133 | - $this->set('ATT_address2', $address2); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set Attendee City |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @param string $city |
|
| 142 | - * @throws EE_Error |
|
| 143 | - */ |
|
| 144 | - public function set_city($city = '') |
|
| 145 | - { |
|
| 146 | - $this->set('ATT_city', $city); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set Attendee State ID |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @param int $STA_ID |
|
| 155 | - * @throws EE_Error |
|
| 156 | - */ |
|
| 157 | - public function set_state($STA_ID = 0) |
|
| 158 | - { |
|
| 159 | - $this->set('STA_ID', $STA_ID); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Country ISO Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $CNT_ISO |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function set_country($CNT_ISO = '') |
|
| 171 | - { |
|
| 172 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Set Attendee Zip/Postal Code |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @param string $zip |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public function set_zip($zip = '') |
|
| 184 | - { |
|
| 185 | - $this->set('ATT_zip', $zip); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set Attendee Email Address |
|
| 191 | - * |
|
| 192 | - * @access public |
|
| 193 | - * @param string $email |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function set_email($email = '') |
|
| 197 | - { |
|
| 198 | - $this->set('ATT_email', $email); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Set Attendee Phone |
|
| 204 | - * |
|
| 205 | - * @access public |
|
| 206 | - * @param string $phone |
|
| 207 | - * @throws EE_Error |
|
| 208 | - */ |
|
| 209 | - public function set_phone($phone = '') |
|
| 210 | - { |
|
| 211 | - $this->set('ATT_phone', $phone); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * set deleted |
|
| 217 | - * |
|
| 218 | - * @access public |
|
| 219 | - * @param bool $ATT_deleted |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function set_deleted($ATT_deleted = false) |
|
| 223 | - { |
|
| 224 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Returns the value for the post_author id saved with the cpt |
|
| 230 | - * |
|
| 231 | - * @since 4.5.0 |
|
| 232 | - * @return int |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function wp_user() |
|
| 236 | - { |
|
| 237 | - return $this->get('ATT_author'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * get Attendee First Name |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return string |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - public function fname() |
|
| 249 | - { |
|
| 250 | - return $this->get('ATT_fname'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * echoes out the attendee's first name |
|
| 256 | - * |
|
| 257 | - * @return void |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - public function e_full_name() |
|
| 261 | - { |
|
| 262 | - echo $this->full_name(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns the first and last name concatenated together with a space. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function full_name($apply_html_entities = false) |
|
| 274 | - { |
|
| 275 | - $full_name = array( |
|
| 276 | - $this->fname(), |
|
| 277 | - $this->lname(), |
|
| 278 | - ); |
|
| 279 | - $full_name = array_filter($full_name); |
|
| 280 | - $full_name = implode(' ', $full_name); |
|
| 281 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | - * attendee. |
|
| 289 | - * |
|
| 290 | - * @param bool $apply_html_entities |
|
| 291 | - * @return string |
|
| 292 | - * @throws EE_Error |
|
| 293 | - */ |
|
| 294 | - public function ATT_full_name($apply_html_entities = false) |
|
| 295 | - { |
|
| 296 | - return $apply_html_entities |
|
| 297 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | - : $this->get('ATT_full_name'); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * get Attendee Last Name |
|
| 304 | - * |
|
| 305 | - * @access public |
|
| 306 | - * @return string |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function lname() |
|
| 310 | - { |
|
| 311 | - return $this->get('ATT_lname'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | - * |
|
| 318 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | - * Eg, if the user only responded to state and country, |
|
| 320 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | - * @return array |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function full_address_as_array() |
|
| 325 | - { |
|
| 326 | - $full_address_array = array(); |
|
| 327 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | - $address_fields_value = $this->get($address_field_name); |
|
| 330 | - if (! empty($address_fields_value)) { |
|
| 331 | - $full_address_array[] = $address_fields_value; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - //now handle state and country |
|
| 335 | - $state_obj = $this->state_obj(); |
|
| 336 | - if ($state_obj instanceof EE_State) { |
|
| 337 | - $full_address_array[] = $state_obj->name(); |
|
| 338 | - } |
|
| 339 | - $country_obj = $this->country_obj(); |
|
| 340 | - if ($country_obj instanceof EE_Country) { |
|
| 341 | - $full_address_array[] = $country_obj->name(); |
|
| 342 | - } |
|
| 343 | - //lastly get the xip |
|
| 344 | - $zip_value = $this->zip(); |
|
| 345 | - if (! empty($zip_value)) { |
|
| 346 | - $full_address_array[] = $zip_value; |
|
| 347 | - } |
|
| 348 | - return $full_address_array; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Attendee Address |
|
| 354 | - * |
|
| 355 | - * @return string |
|
| 356 | - * @throws EE_Error |
|
| 357 | - */ |
|
| 358 | - public function address() |
|
| 359 | - { |
|
| 360 | - return $this->get('ATT_address'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get Attendee Address2 |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - public function address2() |
|
| 371 | - { |
|
| 372 | - return $this->get('ATT_address2'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * get Attendee City |
|
| 378 | - * |
|
| 379 | - * @return string |
|
| 380 | - * @throws EE_Error |
|
| 381 | - */ |
|
| 382 | - public function city() |
|
| 383 | - { |
|
| 384 | - return $this->get('ATT_city'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * get Attendee State ID |
|
| 390 | - * |
|
| 391 | - * @return string |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function state_ID() |
|
| 395 | - { |
|
| 396 | - return $this->get('STA_ID'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return string |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function state_abbrev() |
|
| 405 | - { |
|
| 406 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Gets the state set to this attendee |
|
| 412 | - * |
|
| 413 | - * @return EE_State |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function state_obj() |
|
| 417 | - { |
|
| 418 | - return $this->get_first_related('State'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns the state's name, otherwise 'Unknown' |
|
| 424 | - * |
|
| 425 | - * @return string |
|
| 426 | - * @throws EE_Error |
|
| 427 | - */ |
|
| 428 | - public function state_name() |
|
| 429 | - { |
|
| 430 | - if ($this->state_obj()) { |
|
| 431 | - return $this->state_obj()->name(); |
|
| 432 | - } else { |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * either displays the state abbreviation or the state name, as determined |
|
| 440 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | - * defaults to abbreviation |
|
| 442 | - * |
|
| 443 | - * @return string |
|
| 444 | - * @throws EE_Error |
|
| 445 | - */ |
|
| 446 | - public function state() |
|
| 447 | - { |
|
| 448 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | - return $this->state_abbrev(); |
|
| 450 | - } |
|
| 451 | - return $this->state_name(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get Attendee Country ISO Code |
|
| 457 | - * |
|
| 458 | - * @return string |
|
| 459 | - * @throws EE_Error |
|
| 460 | - */ |
|
| 461 | - public function country_ID() |
|
| 462 | - { |
|
| 463 | - return $this->get('CNT_ISO'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets country set for this attendee |
|
| 469 | - * |
|
| 470 | - * @return EE_Country |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function country_obj() |
|
| 474 | - { |
|
| 475 | - return $this->get_first_related('Country'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | - * |
|
| 482 | - * @return string |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function country_name() |
|
| 486 | - { |
|
| 487 | - if ($this->country_obj()) { |
|
| 488 | - return $this->country_obj()->name(); |
|
| 489 | - } |
|
| 490 | - return ''; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * either displays the country ISO2 code or the country name, as determined |
|
| 496 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | - * defaults to abbreviation |
|
| 498 | - * |
|
| 499 | - * @return string |
|
| 500 | - * @throws EE_Error |
|
| 501 | - */ |
|
| 502 | - public function country() |
|
| 503 | - { |
|
| 504 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | - return $this->country_ID(); |
|
| 506 | - } |
|
| 507 | - return $this->country_name(); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get Attendee Zip/Postal Code |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - * @throws EE_Error |
|
| 516 | - */ |
|
| 517 | - public function zip() |
|
| 518 | - { |
|
| 519 | - return $this->get('ATT_zip'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * get Attendee Email Address |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function email() |
|
| 530 | - { |
|
| 531 | - return $this->get('ATT_email'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * get Attendee Phone # |
|
| 537 | - * |
|
| 538 | - * @return string |
|
| 539 | - * @throws EE_Error |
|
| 540 | - */ |
|
| 541 | - public function phone() |
|
| 542 | - { |
|
| 543 | - return $this->get('ATT_phone'); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * get deleted |
|
| 549 | - * |
|
| 550 | - * @return bool |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function deleted() |
|
| 554 | - { |
|
| 555 | - return $this->get('ATT_deleted'); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Gets registrations of this attendee |
|
| 561 | - * |
|
| 562 | - * @param array $query_params |
|
| 563 | - * @return EE_Registration[] |
|
| 564 | - * @throws EE_Error |
|
| 565 | - */ |
|
| 566 | - public function get_registrations($query_params = array()) |
|
| 567 | - { |
|
| 568 | - return $this->get_many_related('Registration', $query_params); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Gets the most recent registration of this attendee |
|
| 574 | - * |
|
| 575 | - * @return EE_Registration |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function get_most_recent_registration() |
|
| 579 | - { |
|
| 580 | - return $this->get_first_related( |
|
| 581 | - 'Registration', |
|
| 582 | - array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | - ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Gets the most recent registration for this attend at this event |
|
| 589 | - * |
|
| 590 | - * @param int $event_id |
|
| 591 | - * @return EE_Registration |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function get_most_recent_registration_for_event($event_id) |
|
| 595 | - { |
|
| 596 | - return $this->get_first_related( |
|
| 597 | - 'Registration', |
|
| 598 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * returns any events attached to this attendee ($_Event property); |
|
| 605 | - * |
|
| 606 | - * @return array |
|
| 607 | - * @throws EE_Error |
|
| 608 | - */ |
|
| 609 | - public function events() |
|
| 610 | - { |
|
| 611 | - return $this->get_many_related('Event'); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | - * used to save the billing info |
|
| 619 | - * |
|
| 620 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | - * @return EE_Form_Section_Proper|null |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - public function billing_info_for_payment_method($payment_method) |
|
| 625 | - { |
|
| 626 | - $pm_type = $payment_method->type_obj(); |
|
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | - return null; |
|
| 629 | - } |
|
| 630 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | - if (! $billing_info) { |
|
| 632 | - return null; |
|
| 633 | - } |
|
| 634 | - $billing_form = $pm_type->billing_form(); |
|
| 635 | - //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | - $form_totally_hidden = true; |
|
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | - $form_totally_hidden = false; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if($form_totally_hidden) { |
|
| 644 | - return null; |
|
| 645 | - } |
|
| 646 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $billing_form; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | - * specified payment method |
|
| 657 | - * |
|
| 658 | - * @param EE_Payment_Method $payment_method |
|
| 659 | - * @return string |
|
| 660 | - * @throws EE_Error |
|
| 661 | - */ |
|
| 662 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | - { |
|
| 664 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | - } |
|
| 667 | - return null; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | - * retrieve it |
|
| 674 | - * |
|
| 675 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | - * @param EE_Payment_Method $payment_method |
|
| 677 | - * @return boolean |
|
| 678 | - * @throws EE_Error |
|
| 679 | - */ |
|
| 680 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | - { |
|
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - $billing_form->clean_sensitive_data(); |
|
| 687 | - return update_post_meta( |
|
| 688 | - $this->ID(), |
|
| 689 | - $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | - $billing_form->input_values(true) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Return the link to the admin details for the object. |
|
| 697 | - * |
|
| 698 | - * @return string |
|
| 699 | - * @throws EE_Error |
|
| 700 | - * @throws InvalidArgumentException |
|
| 701 | - * @throws InvalidDataTypeException |
|
| 702 | - * @throws InvalidInterfaceException |
|
| 703 | - * @throws ReflectionException |
|
| 704 | - */ |
|
| 705 | - public function get_admin_details_link() |
|
| 706 | - { |
|
| 707 | - return $this->get_admin_edit_link(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | - * |
|
| 714 | - * @return string |
|
| 715 | - * @throws EE_Error |
|
| 716 | - * @throws InvalidArgumentException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - * @throws InvalidDataTypeException |
|
| 719 | - * @throws InvalidInterfaceException |
|
| 720 | - */ |
|
| 721 | - public function get_admin_edit_link() |
|
| 722 | - { |
|
| 723 | - EE_Registry::instance()->load_helper('URL'); |
|
| 724 | - return EEH_URL::add_query_args_and_nonce( |
|
| 725 | - array( |
|
| 726 | - 'page' => 'espresso_registrations', |
|
| 727 | - 'action' => 'edit_attendee', |
|
| 728 | - 'post' => $this->ID(), |
|
| 729 | - ), |
|
| 730 | - admin_url('admin.php') |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Returns the link to a settings page for the object. |
|
| 737 | - * |
|
| 738 | - * @return string |
|
| 739 | - * @throws EE_Error |
|
| 740 | - * @throws InvalidArgumentException |
|
| 741 | - * @throws InvalidDataTypeException |
|
| 742 | - * @throws InvalidInterfaceException |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public function get_admin_settings_link() |
|
| 746 | - { |
|
| 747 | - return $this->get_admin_edit_link(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | - * |
|
| 754 | - * @return string |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws ReflectionException |
|
| 758 | - * @throws InvalidDataTypeException |
|
| 759 | - * @throws InvalidInterfaceException |
|
| 760 | - */ |
|
| 761 | - public function get_admin_overview_link() |
|
| 762 | - { |
|
| 763 | - EE_Registry::instance()->load_helper('URL'); |
|
| 764 | - return EEH_URL::add_query_args_and_nonce( |
|
| 765 | - array( |
|
| 766 | - 'page' => 'espresso_registrations', |
|
| 767 | - 'action' => 'contact_list', |
|
| 768 | - ), |
|
| 769 | - admin_url('admin.php') |
|
| 770 | - ); |
|
| 771 | - } |
|
| 30 | + /** |
|
| 31 | + * Sets some dynamic defaults |
|
| 32 | + * |
|
| 33 | + * @param array $fieldValues |
|
| 34 | + * @param bool $bydb |
|
| 35 | + * @param string $timezone |
|
| 36 | + * @param array $date_formats |
|
| 37 | + * @throws EE_Error |
|
| 38 | + */ |
|
| 39 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | + { |
|
| 41 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | + } |
|
| 46 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | + } |
|
| 50 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | + } |
|
| 53 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values |
|
| 59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | + * used.) |
|
| 61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | + * date_format and the second value is the time format |
|
| 63 | + * @return EE_Attendee |
|
| 64 | + * @throws EE_Error |
|
| 65 | + */ |
|
| 66 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | + { |
|
| 68 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param array $props_n_values incoming values from the database |
|
| 75 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | + * the website will be used. |
|
| 77 | + * @return EE_Attendee |
|
| 78 | + */ |
|
| 79 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | + { |
|
| 81 | + return new self($props_n_values, true, $timezone); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set Attendee First Name |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @param string $fname |
|
| 90 | + * @throws EE_Error |
|
| 91 | + */ |
|
| 92 | + public function set_fname($fname = '') |
|
| 93 | + { |
|
| 94 | + $this->set('ATT_fname', $fname); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Set Attendee Last Name |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @param string $lname |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function set_lname($lname = '') |
|
| 106 | + { |
|
| 107 | + $this->set('ATT_lname', $lname); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Set Attendee Address |
|
| 113 | + * |
|
| 114 | + * @access public |
|
| 115 | + * @param string $address |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_address($address = '') |
|
| 119 | + { |
|
| 120 | + $this->set('ATT_address', $address); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set Attendee Address2 |
|
| 126 | + * |
|
| 127 | + * @access public |
|
| 128 | + * @param string $address2 |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public function set_address2($address2 = '') |
|
| 132 | + { |
|
| 133 | + $this->set('ATT_address2', $address2); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set Attendee City |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @param string $city |
|
| 142 | + * @throws EE_Error |
|
| 143 | + */ |
|
| 144 | + public function set_city($city = '') |
|
| 145 | + { |
|
| 146 | + $this->set('ATT_city', $city); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set Attendee State ID |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @param int $STA_ID |
|
| 155 | + * @throws EE_Error |
|
| 156 | + */ |
|
| 157 | + public function set_state($STA_ID = 0) |
|
| 158 | + { |
|
| 159 | + $this->set('STA_ID', $STA_ID); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Country ISO Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $CNT_ISO |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function set_country($CNT_ISO = '') |
|
| 171 | + { |
|
| 172 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set Attendee Zip/Postal Code |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @param string $zip |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public function set_zip($zip = '') |
|
| 184 | + { |
|
| 185 | + $this->set('ATT_zip', $zip); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set Attendee Email Address |
|
| 191 | + * |
|
| 192 | + * @access public |
|
| 193 | + * @param string $email |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function set_email($email = '') |
|
| 197 | + { |
|
| 198 | + $this->set('ATT_email', $email); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Set Attendee Phone |
|
| 204 | + * |
|
| 205 | + * @access public |
|
| 206 | + * @param string $phone |
|
| 207 | + * @throws EE_Error |
|
| 208 | + */ |
|
| 209 | + public function set_phone($phone = '') |
|
| 210 | + { |
|
| 211 | + $this->set('ATT_phone', $phone); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * set deleted |
|
| 217 | + * |
|
| 218 | + * @access public |
|
| 219 | + * @param bool $ATT_deleted |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function set_deleted($ATT_deleted = false) |
|
| 223 | + { |
|
| 224 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Returns the value for the post_author id saved with the cpt |
|
| 230 | + * |
|
| 231 | + * @since 4.5.0 |
|
| 232 | + * @return int |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function wp_user() |
|
| 236 | + { |
|
| 237 | + return $this->get('ATT_author'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * get Attendee First Name |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return string |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + public function fname() |
|
| 249 | + { |
|
| 250 | + return $this->get('ATT_fname'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * echoes out the attendee's first name |
|
| 256 | + * |
|
| 257 | + * @return void |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + public function e_full_name() |
|
| 261 | + { |
|
| 262 | + echo $this->full_name(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns the first and last name concatenated together with a space. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function full_name($apply_html_entities = false) |
|
| 274 | + { |
|
| 275 | + $full_name = array( |
|
| 276 | + $this->fname(), |
|
| 277 | + $this->lname(), |
|
| 278 | + ); |
|
| 279 | + $full_name = array_filter($full_name); |
|
| 280 | + $full_name = implode(' ', $full_name); |
|
| 281 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | + * attendee. |
|
| 289 | + * |
|
| 290 | + * @param bool $apply_html_entities |
|
| 291 | + * @return string |
|
| 292 | + * @throws EE_Error |
|
| 293 | + */ |
|
| 294 | + public function ATT_full_name($apply_html_entities = false) |
|
| 295 | + { |
|
| 296 | + return $apply_html_entities |
|
| 297 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | + : $this->get('ATT_full_name'); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * get Attendee Last Name |
|
| 304 | + * |
|
| 305 | + * @access public |
|
| 306 | + * @return string |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function lname() |
|
| 310 | + { |
|
| 311 | + return $this->get('ATT_lname'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | + * |
|
| 318 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | + * Eg, if the user only responded to state and country, |
|
| 320 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | + * @return array |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function full_address_as_array() |
|
| 325 | + { |
|
| 326 | + $full_address_array = array(); |
|
| 327 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | + $address_fields_value = $this->get($address_field_name); |
|
| 330 | + if (! empty($address_fields_value)) { |
|
| 331 | + $full_address_array[] = $address_fields_value; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + //now handle state and country |
|
| 335 | + $state_obj = $this->state_obj(); |
|
| 336 | + if ($state_obj instanceof EE_State) { |
|
| 337 | + $full_address_array[] = $state_obj->name(); |
|
| 338 | + } |
|
| 339 | + $country_obj = $this->country_obj(); |
|
| 340 | + if ($country_obj instanceof EE_Country) { |
|
| 341 | + $full_address_array[] = $country_obj->name(); |
|
| 342 | + } |
|
| 343 | + //lastly get the xip |
|
| 344 | + $zip_value = $this->zip(); |
|
| 345 | + if (! empty($zip_value)) { |
|
| 346 | + $full_address_array[] = $zip_value; |
|
| 347 | + } |
|
| 348 | + return $full_address_array; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Attendee Address |
|
| 354 | + * |
|
| 355 | + * @return string |
|
| 356 | + * @throws EE_Error |
|
| 357 | + */ |
|
| 358 | + public function address() |
|
| 359 | + { |
|
| 360 | + return $this->get('ATT_address'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get Attendee Address2 |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + public function address2() |
|
| 371 | + { |
|
| 372 | + return $this->get('ATT_address2'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * get Attendee City |
|
| 378 | + * |
|
| 379 | + * @return string |
|
| 380 | + * @throws EE_Error |
|
| 381 | + */ |
|
| 382 | + public function city() |
|
| 383 | + { |
|
| 384 | + return $this->get('ATT_city'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * get Attendee State ID |
|
| 390 | + * |
|
| 391 | + * @return string |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function state_ID() |
|
| 395 | + { |
|
| 396 | + return $this->get('STA_ID'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return string |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function state_abbrev() |
|
| 405 | + { |
|
| 406 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Gets the state set to this attendee |
|
| 412 | + * |
|
| 413 | + * @return EE_State |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function state_obj() |
|
| 417 | + { |
|
| 418 | + return $this->get_first_related('State'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns the state's name, otherwise 'Unknown' |
|
| 424 | + * |
|
| 425 | + * @return string |
|
| 426 | + * @throws EE_Error |
|
| 427 | + */ |
|
| 428 | + public function state_name() |
|
| 429 | + { |
|
| 430 | + if ($this->state_obj()) { |
|
| 431 | + return $this->state_obj()->name(); |
|
| 432 | + } else { |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * either displays the state abbreviation or the state name, as determined |
|
| 440 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | + * defaults to abbreviation |
|
| 442 | + * |
|
| 443 | + * @return string |
|
| 444 | + * @throws EE_Error |
|
| 445 | + */ |
|
| 446 | + public function state() |
|
| 447 | + { |
|
| 448 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | + return $this->state_abbrev(); |
|
| 450 | + } |
|
| 451 | + return $this->state_name(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get Attendee Country ISO Code |
|
| 457 | + * |
|
| 458 | + * @return string |
|
| 459 | + * @throws EE_Error |
|
| 460 | + */ |
|
| 461 | + public function country_ID() |
|
| 462 | + { |
|
| 463 | + return $this->get('CNT_ISO'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets country set for this attendee |
|
| 469 | + * |
|
| 470 | + * @return EE_Country |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function country_obj() |
|
| 474 | + { |
|
| 475 | + return $this->get_first_related('Country'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | + * |
|
| 482 | + * @return string |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function country_name() |
|
| 486 | + { |
|
| 487 | + if ($this->country_obj()) { |
|
| 488 | + return $this->country_obj()->name(); |
|
| 489 | + } |
|
| 490 | + return ''; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * either displays the country ISO2 code or the country name, as determined |
|
| 496 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | + * defaults to abbreviation |
|
| 498 | + * |
|
| 499 | + * @return string |
|
| 500 | + * @throws EE_Error |
|
| 501 | + */ |
|
| 502 | + public function country() |
|
| 503 | + { |
|
| 504 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | + return $this->country_ID(); |
|
| 506 | + } |
|
| 507 | + return $this->country_name(); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get Attendee Zip/Postal Code |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + * @throws EE_Error |
|
| 516 | + */ |
|
| 517 | + public function zip() |
|
| 518 | + { |
|
| 519 | + return $this->get('ATT_zip'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * get Attendee Email Address |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function email() |
|
| 530 | + { |
|
| 531 | + return $this->get('ATT_email'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * get Attendee Phone # |
|
| 537 | + * |
|
| 538 | + * @return string |
|
| 539 | + * @throws EE_Error |
|
| 540 | + */ |
|
| 541 | + public function phone() |
|
| 542 | + { |
|
| 543 | + return $this->get('ATT_phone'); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * get deleted |
|
| 549 | + * |
|
| 550 | + * @return bool |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function deleted() |
|
| 554 | + { |
|
| 555 | + return $this->get('ATT_deleted'); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Gets registrations of this attendee |
|
| 561 | + * |
|
| 562 | + * @param array $query_params |
|
| 563 | + * @return EE_Registration[] |
|
| 564 | + * @throws EE_Error |
|
| 565 | + */ |
|
| 566 | + public function get_registrations($query_params = array()) |
|
| 567 | + { |
|
| 568 | + return $this->get_many_related('Registration', $query_params); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Gets the most recent registration of this attendee |
|
| 574 | + * |
|
| 575 | + * @return EE_Registration |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function get_most_recent_registration() |
|
| 579 | + { |
|
| 580 | + return $this->get_first_related( |
|
| 581 | + 'Registration', |
|
| 582 | + array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | + ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Gets the most recent registration for this attend at this event |
|
| 589 | + * |
|
| 590 | + * @param int $event_id |
|
| 591 | + * @return EE_Registration |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function get_most_recent_registration_for_event($event_id) |
|
| 595 | + { |
|
| 596 | + return $this->get_first_related( |
|
| 597 | + 'Registration', |
|
| 598 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * returns any events attached to this attendee ($_Event property); |
|
| 605 | + * |
|
| 606 | + * @return array |
|
| 607 | + * @throws EE_Error |
|
| 608 | + */ |
|
| 609 | + public function events() |
|
| 610 | + { |
|
| 611 | + return $this->get_many_related('Event'); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | + * used to save the billing info |
|
| 619 | + * |
|
| 620 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | + * @return EE_Form_Section_Proper|null |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + public function billing_info_for_payment_method($payment_method) |
|
| 625 | + { |
|
| 626 | + $pm_type = $payment_method->type_obj(); |
|
| 627 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | + return null; |
|
| 629 | + } |
|
| 630 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | + if (! $billing_info) { |
|
| 632 | + return null; |
|
| 633 | + } |
|
| 634 | + $billing_form = $pm_type->billing_form(); |
|
| 635 | + //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | + $form_totally_hidden = true; |
|
| 637 | + foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | + if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | + $form_totally_hidden = false; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if($form_totally_hidden) { |
|
| 644 | + return null; |
|
| 645 | + } |
|
| 646 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $billing_form; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | + * specified payment method |
|
| 657 | + * |
|
| 658 | + * @param EE_Payment_Method $payment_method |
|
| 659 | + * @return string |
|
| 660 | + * @throws EE_Error |
|
| 661 | + */ |
|
| 662 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | + { |
|
| 664 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | + } |
|
| 667 | + return null; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | + * retrieve it |
|
| 674 | + * |
|
| 675 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | + * @param EE_Payment_Method $payment_method |
|
| 677 | + * @return boolean |
|
| 678 | + * @throws EE_Error |
|
| 679 | + */ |
|
| 680 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | + { |
|
| 682 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + $billing_form->clean_sensitive_data(); |
|
| 687 | + return update_post_meta( |
|
| 688 | + $this->ID(), |
|
| 689 | + $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | + $billing_form->input_values(true) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Return the link to the admin details for the object. |
|
| 697 | + * |
|
| 698 | + * @return string |
|
| 699 | + * @throws EE_Error |
|
| 700 | + * @throws InvalidArgumentException |
|
| 701 | + * @throws InvalidDataTypeException |
|
| 702 | + * @throws InvalidInterfaceException |
|
| 703 | + * @throws ReflectionException |
|
| 704 | + */ |
|
| 705 | + public function get_admin_details_link() |
|
| 706 | + { |
|
| 707 | + return $this->get_admin_edit_link(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | + * |
|
| 714 | + * @return string |
|
| 715 | + * @throws EE_Error |
|
| 716 | + * @throws InvalidArgumentException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + * @throws InvalidDataTypeException |
|
| 719 | + * @throws InvalidInterfaceException |
|
| 720 | + */ |
|
| 721 | + public function get_admin_edit_link() |
|
| 722 | + { |
|
| 723 | + EE_Registry::instance()->load_helper('URL'); |
|
| 724 | + return EEH_URL::add_query_args_and_nonce( |
|
| 725 | + array( |
|
| 726 | + 'page' => 'espresso_registrations', |
|
| 727 | + 'action' => 'edit_attendee', |
|
| 728 | + 'post' => $this->ID(), |
|
| 729 | + ), |
|
| 730 | + admin_url('admin.php') |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Returns the link to a settings page for the object. |
|
| 737 | + * |
|
| 738 | + * @return string |
|
| 739 | + * @throws EE_Error |
|
| 740 | + * @throws InvalidArgumentException |
|
| 741 | + * @throws InvalidDataTypeException |
|
| 742 | + * @throws InvalidInterfaceException |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public function get_admin_settings_link() |
|
| 746 | + { |
|
| 747 | + return $this->get_admin_edit_link(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | + * |
|
| 754 | + * @return string |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws ReflectionException |
|
| 758 | + * @throws InvalidDataTypeException |
|
| 759 | + * @throws InvalidInterfaceException |
|
| 760 | + */ |
|
| 761 | + public function get_admin_overview_link() |
|
| 762 | + { |
|
| 763 | + EE_Registry::instance()->load_helper('URL'); |
|
| 764 | + return EEH_URL::add_query_args_and_nonce( |
|
| 765 | + array( |
|
| 766 | + 'page' => 'espresso_registrations', |
|
| 767 | + 'action' => 'contact_list', |
|
| 768 | + ), |
|
| 769 | + admin_url('admin.php') |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | 772 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
| 40 | 40 | { |
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 41 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 43 | 43 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 45 | 45 | } |
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 46 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 47 | 47 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 48 | 48 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 49 | 49 | } |
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 50 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | 51 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 52 | 52 | } |
| 53 | 53 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
| 328 | 328 | foreach ($initial_address_fields as $address_field_name) { |
| 329 | 329 | $address_fields_value = $this->get($address_field_name); |
| 330 | - if (! empty($address_fields_value)) { |
|
| 330 | + if ( ! empty($address_fields_value)) { |
|
| 331 | 331 | $full_address_array[] = $address_fields_value; |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | //lastly get the xip |
| 344 | 344 | $zip_value = $this->zip(); |
| 345 | - if (! empty($zip_value)) { |
|
| 345 | + if ( ! empty($zip_value)) { |
|
| 346 | 346 | $full_address_array[] = $zip_value; |
| 347 | 347 | } |
| 348 | 348 | return $full_address_array; |
@@ -624,23 +624,23 @@ discard block |
||
| 624 | 624 | public function billing_info_for_payment_method($payment_method) |
| 625 | 625 | { |
| 626 | 626 | $pm_type = $payment_method->type_obj(); |
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 627 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | 628 | return null; |
| 629 | 629 | } |
| 630 | 630 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 631 | - if (! $billing_info) { |
|
| 631 | + if ( ! $billing_info) { |
|
| 632 | 632 | return null; |
| 633 | 633 | } |
| 634 | 634 | $billing_form = $pm_type->billing_form(); |
| 635 | 635 | //double-check the form isn't totally hidden, in which case pretend there is no form |
| 636 | 636 | $form_totally_hidden = true; |
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 637 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 638 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | 639 | $form_totally_hidden = false; |
| 640 | 640 | break; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - if($form_totally_hidden) { |
|
| 643 | + if ($form_totally_hidden) { |
|
| 644 | 644 | return null; |
| 645 | 645 | } |
| 646 | 646 | if ($billing_form instanceof EE_Form_Section_Proper) { |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | public function get_billing_info_postmeta_name($payment_method) |
| 663 | 663 | { |
| 664 | 664 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 665 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 666 | 666 | } |
| 667 | 667 | return null; |
| 668 | 668 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 681 | 681 | { |
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 682 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | 683 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
| 684 | 684 | return false; |
| 685 | 685 | } |
@@ -15,288 +15,288 @@ |
||
| 15 | 15 | abstract class EE_Form_Section_Layout_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Form form section to lay out |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Proper |
|
| 22 | - */ |
|
| 23 | - protected $_form_section; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * __construct |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The form section on which this strategy is to perform |
|
| 38 | - * |
|
| 39 | - * @param EE_Form_Section_Proper $form |
|
| 40 | - */ |
|
| 41 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | - { |
|
| 43 | - $this->_form_section = $form; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return EE_Form_Section_Proper |
|
| 50 | - */ |
|
| 51 | - public function form_section() |
|
| 52 | - { |
|
| 53 | - return $this->_form_section; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | - * this form. |
|
| 61 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | - * proper subsections. |
|
| 63 | - * Returns the HTML |
|
| 64 | - * |
|
| 65 | - * @return string HTML for displaying |
|
| 66 | - * @throws EE_Error |
|
| 67 | - */ |
|
| 68 | - public function layout_form() |
|
| 69 | - { |
|
| 70 | - $html = ''; |
|
| 71 | - // layout_form_begin |
|
| 72 | - $html .= apply_filters( |
|
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | - $this->layout_form_begin(), |
|
| 75 | - $this->_form_section |
|
| 76 | - ); |
|
| 77 | - // layout_form_loop |
|
| 78 | - $html .= apply_filters( |
|
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | - $this->layout_form_loop(), |
|
| 81 | - $this->_form_section |
|
| 82 | - ); |
|
| 83 | - // layout_form_end |
|
| 84 | - $html .= apply_filters( |
|
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | - $this->layout_form_end(), |
|
| 87 | - $this->_form_section |
|
| 88 | - ); |
|
| 89 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | - return $html; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function layout_form_loop() |
|
| 100 | - { |
|
| 101 | - $html = ''; |
|
| 102 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | - $html .= apply_filters( |
|
| 105 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | - $this->layout_input($subsection), |
|
| 108 | - $this->_form_section, |
|
| 109 | - $subsection |
|
| 110 | - ); |
|
| 111 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | - $html .= apply_filters( |
|
| 113 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | - $this->layout_subsection($subsection), |
|
| 116 | - $this->_form_section, |
|
| 117 | - $subsection |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - return $html; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - abstract public function layout_form_begin(); |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - abstract public function layout_form_end(); |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | - * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | - * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | - * 'easy-to-layout' inputs |
|
| 151 | - * |
|
| 152 | - * @param EE_Form_Input_Base $input |
|
| 153 | - * @return string html |
|
| 154 | - */ |
|
| 155 | - abstract public function layout_input($input); |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | - * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | - * |
|
| 164 | - * @param EE_Form_Section_Base $subsection |
|
| 165 | - * @return string html |
|
| 166 | - */ |
|
| 167 | - abstract public function layout_subsection($subsection); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Gets the HTML for the label tag and its contents for the input |
|
| 173 | - * |
|
| 174 | - * @param EE_Form_Input_Base $input |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function display_label($input) |
|
| 178 | - { |
|
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | - return ''; |
|
| 181 | - } |
|
| 182 | - $class = $input->required() |
|
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | - : $input->html_label_class(); |
|
| 185 | - $label_text = $input->required() |
|
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | - : $input->html_label_text(); |
|
| 188 | - return '<label id="' |
|
| 189 | - . $input->html_label_id() |
|
| 190 | - . '" class="' |
|
| 191 | - . $class |
|
| 192 | - . '" style="' |
|
| 193 | - . $input->html_label_style() |
|
| 194 | - . '" for="' . $input->html_name() |
|
| 195 | - . '">' |
|
| 196 | - . $label_text |
|
| 197 | - . '</label>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | - * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function display_form_wide_errors() |
|
| 209 | - { |
|
| 210 | - $html = ''; |
|
| 211 | - if ($this->_form_section->get_validation_errors()) { |
|
| 212 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | - //get all the errors on THIS form section (errors which aren't |
|
| 214 | - //for specific inputs, but instead for the entire form section) |
|
| 215 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 217 | - } |
|
| 218 | - $html .= '</div>'; |
|
| 219 | - } |
|
| 220 | - return apply_filters( |
|
| 221 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | - $html, |
|
| 223 | - $this |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | - * Note that if JS is enabled, it should remove these and instead |
|
| 232 | - * populate the form's errors in the jquery validate fashion |
|
| 233 | - * using the localized data provided to the JS |
|
| 234 | - * |
|
| 235 | - * @param EE_Form_Input_Base $input |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function display_errors($input) |
|
| 239 | - { |
|
| 240 | - if ($input->get_validation_errors()) { |
|
| 241 | - return "<label id='" |
|
| 242 | - . $input->html_id() |
|
| 243 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | - . $input->get_validation_error_string() |
|
| 245 | - . '</label>'; |
|
| 246 | - } |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Displays the help span for the specified input |
|
| 254 | - * |
|
| 255 | - * @param EE_Form_Input_Base $input |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function display_help_text($input) |
|
| 259 | - { |
|
| 260 | - $help_text = $input->html_help_text(); |
|
| 261 | - if ($help_text !== '' && $help_text !== null) { |
|
| 262 | - $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | - return '<' |
|
| 264 | - . $tag |
|
| 265 | - . ' id="' |
|
| 266 | - . $input->html_id() |
|
| 267 | - . '-help" class="' |
|
| 268 | - . $input->html_help_class() |
|
| 269 | - . '" style="' |
|
| 270 | - . $input->html_help_style() |
|
| 271 | - . '">' |
|
| 272 | - . $help_text |
|
| 273 | - . '</' |
|
| 274 | - . $tag |
|
| 275 | - . '>'; |
|
| 276 | - } |
|
| 277 | - return ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Does an action and hook onto the end of teh form |
|
| 284 | - * |
|
| 285 | - * @param string $html |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function add_form_section_hooks_and_filters($html) |
|
| 289 | - { |
|
| 290 | - // replace dashes and spaces with underscores |
|
| 291 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | - $html = (string) apply_filters( |
|
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | - $html, |
|
| 296 | - $this->_form_section |
|
| 297 | - ); |
|
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | - return $html; |
|
| 301 | - } |
|
| 18 | + /** |
|
| 19 | + * Form form section to lay out |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Proper |
|
| 22 | + */ |
|
| 23 | + protected $_form_section; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * __construct |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The form section on which this strategy is to perform |
|
| 38 | + * |
|
| 39 | + * @param EE_Form_Section_Proper $form |
|
| 40 | + */ |
|
| 41 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | + { |
|
| 43 | + $this->_form_section = $form; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return EE_Form_Section_Proper |
|
| 50 | + */ |
|
| 51 | + public function form_section() |
|
| 52 | + { |
|
| 53 | + return $this->_form_section; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | + * this form. |
|
| 61 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | + * proper subsections. |
|
| 63 | + * Returns the HTML |
|
| 64 | + * |
|
| 65 | + * @return string HTML for displaying |
|
| 66 | + * @throws EE_Error |
|
| 67 | + */ |
|
| 68 | + public function layout_form() |
|
| 69 | + { |
|
| 70 | + $html = ''; |
|
| 71 | + // layout_form_begin |
|
| 72 | + $html .= apply_filters( |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | + $this->layout_form_begin(), |
|
| 75 | + $this->_form_section |
|
| 76 | + ); |
|
| 77 | + // layout_form_loop |
|
| 78 | + $html .= apply_filters( |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | + $this->layout_form_loop(), |
|
| 81 | + $this->_form_section |
|
| 82 | + ); |
|
| 83 | + // layout_form_end |
|
| 84 | + $html .= apply_filters( |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | + $this->layout_form_end(), |
|
| 87 | + $this->_form_section |
|
| 88 | + ); |
|
| 89 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | + return $html; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function layout_form_loop() |
|
| 100 | + { |
|
| 101 | + $html = ''; |
|
| 102 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | + $html .= apply_filters( |
|
| 105 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | + $this->layout_input($subsection), |
|
| 108 | + $this->_form_section, |
|
| 109 | + $subsection |
|
| 110 | + ); |
|
| 111 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | + $html .= apply_filters( |
|
| 113 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | + $this->layout_subsection($subsection), |
|
| 116 | + $this->_form_section, |
|
| 117 | + $subsection |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + return $html; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + abstract public function layout_form_begin(); |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + abstract public function layout_form_end(); |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | + * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | + * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | + * 'easy-to-layout' inputs |
|
| 151 | + * |
|
| 152 | + * @param EE_Form_Input_Base $input |
|
| 153 | + * @return string html |
|
| 154 | + */ |
|
| 155 | + abstract public function layout_input($input); |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | + * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | + * |
|
| 164 | + * @param EE_Form_Section_Base $subsection |
|
| 165 | + * @return string html |
|
| 166 | + */ |
|
| 167 | + abstract public function layout_subsection($subsection); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Gets the HTML for the label tag and its contents for the input |
|
| 173 | + * |
|
| 174 | + * @param EE_Form_Input_Base $input |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function display_label($input) |
|
| 178 | + { |
|
| 179 | + if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 182 | + $class = $input->required() |
|
| 183 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | + : $input->html_label_class(); |
|
| 185 | + $label_text = $input->required() |
|
| 186 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | + : $input->html_label_text(); |
|
| 188 | + return '<label id="' |
|
| 189 | + . $input->html_label_id() |
|
| 190 | + . '" class="' |
|
| 191 | + . $class |
|
| 192 | + . '" style="' |
|
| 193 | + . $input->html_label_style() |
|
| 194 | + . '" for="' . $input->html_name() |
|
| 195 | + . '">' |
|
| 196 | + . $label_text |
|
| 197 | + . '</label>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | + * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function display_form_wide_errors() |
|
| 209 | + { |
|
| 210 | + $html = ''; |
|
| 211 | + if ($this->_form_section->get_validation_errors()) { |
|
| 212 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | + //get all the errors on THIS form section (errors which aren't |
|
| 214 | + //for specific inputs, but instead for the entire form section) |
|
| 215 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | + $html .= $error->getMessage() . '<br>'; |
|
| 217 | + } |
|
| 218 | + $html .= '</div>'; |
|
| 219 | + } |
|
| 220 | + return apply_filters( |
|
| 221 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | + $html, |
|
| 223 | + $this |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | + * Note that if JS is enabled, it should remove these and instead |
|
| 232 | + * populate the form's errors in the jquery validate fashion |
|
| 233 | + * using the localized data provided to the JS |
|
| 234 | + * |
|
| 235 | + * @param EE_Form_Input_Base $input |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function display_errors($input) |
|
| 239 | + { |
|
| 240 | + if ($input->get_validation_errors()) { |
|
| 241 | + return "<label id='" |
|
| 242 | + . $input->html_id() |
|
| 243 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | + . $input->get_validation_error_string() |
|
| 245 | + . '</label>'; |
|
| 246 | + } |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Displays the help span for the specified input |
|
| 254 | + * |
|
| 255 | + * @param EE_Form_Input_Base $input |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function display_help_text($input) |
|
| 259 | + { |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | + if ($help_text !== '' && $help_text !== null) { |
|
| 262 | + $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | + return '<' |
|
| 264 | + . $tag |
|
| 265 | + . ' id="' |
|
| 266 | + . $input->html_id() |
|
| 267 | + . '-help" class="' |
|
| 268 | + . $input->html_help_class() |
|
| 269 | + . '" style="' |
|
| 270 | + . $input->html_help_style() |
|
| 271 | + . '">' |
|
| 272 | + . $help_text |
|
| 273 | + . '</' |
|
| 274 | + . $tag |
|
| 275 | + . '>'; |
|
| 276 | + } |
|
| 277 | + return ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Does an action and hook onto the end of teh form |
|
| 284 | + * |
|
| 285 | + * @param string $html |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function add_form_section_hooks_and_filters($html) |
|
| 289 | + { |
|
| 290 | + // replace dashes and spaces with underscores |
|
| 291 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | + $html = (string) apply_filters( |
|
| 294 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | + $html, |
|
| 296 | + $this->_form_section |
|
| 297 | + ); |
|
| 298 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | + return $html; |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | $html = ''; |
| 71 | 71 | // layout_form_begin |
| 72 | 72 | $html .= apply_filters( |
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
| 74 | 74 | $this->layout_form_begin(), |
| 75 | 75 | $this->_form_section |
| 76 | 76 | ); |
| 77 | 77 | // layout_form_loop |
| 78 | 78 | $html .= apply_filters( |
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
| 80 | 80 | $this->layout_form_loop(), |
| 81 | 81 | $this->_form_section |
| 82 | 82 | ); |
| 83 | 83 | // layout_form_end |
| 84 | 84 | $html .= apply_filters( |
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
| 86 | 86 | $this->layout_form_end(), |
| 87 | 87 | $this->_form_section |
| 88 | 88 | ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if ($subsection instanceof EE_Form_Input_Base) { |
| 104 | 104 | $html .= apply_filters( |
| 105 | 105 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 106 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 107 | 107 | $this->layout_input($subsection), |
| 108 | 108 | $this->_form_section, |
| 109 | 109 | $subsection |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
| 112 | 112 | $html .= apply_filters( |
| 113 | 113 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 114 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 115 | 115 | $this->layout_subsection($subsection), |
| 116 | 116 | $this->_form_section, |
| 117 | 117 | $subsection |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function display_label($input) |
| 178 | 178 | { |
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 179 | + if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 180 | 180 | return ''; |
| 181 | 181 | } |
| 182 | 182 | $class = $input->required() |
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 183 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 184 | 184 | : $input->html_label_class(); |
| 185 | 185 | $label_text = $input->required() |
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 186 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
| 187 | 187 | : $input->html_label_text(); |
| 188 | 188 | return '<label id="' |
| 189 | 189 | . $input->html_label_id() |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | . $class |
| 192 | 192 | . '" style="' |
| 193 | 193 | . $input->html_label_style() |
| 194 | - . '" for="' . $input->html_name() |
|
| 194 | + . '" for="'.$input->html_name() |
|
| 195 | 195 | . '">' |
| 196 | 196 | . $label_text |
| 197 | 197 | . '</label>'; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | //get all the errors on THIS form section (errors which aren't |
| 214 | 214 | //for specific inputs, but instead for the entire form section) |
| 215 | 215 | foreach ($this->_form_section->get_validation_errors() as $error) { |
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 216 | + $html .= $error->getMessage().'<br>'; |
|
| 217 | 217 | } |
| 218 | 218 | $html .= '</div>'; |
| 219 | 219 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function display_help_text($input) |
| 259 | 259 | { |
| 260 | - $help_text = $input->html_help_text(); |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | 261 | if ($help_text !== '' && $help_text !== null) { |
| 262 | 262 | $tag = is_admin() ? 'p' : 'span'; |
| 263 | 263 | return '<' |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | // replace dashes and spaces with underscores |
| 291 | 291 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
| 293 | 293 | $html = (string) apply_filters( |
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 294 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
| 295 | 295 | $html, |
| 296 | 296 | $this->_form_section |
| 297 | 297 | ); |
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 298 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
| 300 | 300 | return $html; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function instance() { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) { |
|
| 35 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function __construct() { |
| 50 | 50 | //let's just make sure this is instantiated in the right place. |
| 51 | - if ( did_action( 'wp_print_styles' ) || did_action( 'admin_head' )) { |
|
| 52 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso' ), '4.1' ); |
|
| 51 | + if (did_action('wp_print_styles') || did_action('admin_head')) { |
|
| 52 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1'); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -61,25 +61,25 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | public function register_and_enqueue() { |
| 64 | - $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js'; |
|
| 65 | - $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map'; |
|
| 66 | - $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css'; |
|
| 64 | + $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js'; |
|
| 65 | + $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map'; |
|
| 66 | + $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css'; |
|
| 67 | 67 | |
| 68 | - wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE ); |
|
| 69 | - wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE ); |
|
| 70 | - wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 68 | + wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE); |
|
| 69 | + wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE); |
|
| 70 | + wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 71 | 71 | |
| 72 | - wp_register_style('qtip-css', $qtipcss, array(), '2.2' ); |
|
| 72 | + wp_register_style('qtip-css', $qtipcss, array(), '2.2'); |
|
| 73 | 73 | |
| 74 | 74 | //k now let's see if there are any registered qtips. If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!) |
| 75 | - if ( !empty( $this->_qtips ) ) { |
|
| 75 | + if ( ! empty($this->_qtips)) { |
|
| 76 | 76 | wp_enqueue_script('ee-qtip-helper'); |
| 77 | 77 | wp_enqueue_style('qtip-css'); |
| 78 | 78 | $qtips = array(); |
| 79 | - foreach ( $this->_qtips as $qtip ) { |
|
| 79 | + foreach ($this->_qtips as $qtip) { |
|
| 80 | 80 | $qts = $qtip->get_tips(); |
| 81 | - foreach ( $qts as $qt ) { |
|
| 82 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 81 | + foreach ($qts as $qt) { |
|
| 82 | + if ( ! $qt instanceof EE_Qtip) |
|
| 83 | 83 | continue; |
| 84 | 84 | $qtips[] = array( |
| 85 | 85 | 'content_id' => $qt->content_id, |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | - if ( !empty($qtips) ) |
|
| 92 | - wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 91 | + if ( ! empty($qtips)) |
|
| 92 | + wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips)); |
|
| 93 | 93 | |
| 94 | 94 | } else { |
| 95 | 95 | //qtips has been requested without any registration (so assuming its just directly used in the admin). |
@@ -111,24 +111,24 @@ discard block |
||
| 111 | 111 | * @param string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips] |
| 112 | 112 | * @return void |
| 113 | 113 | */ |
| 114 | - public function register( $configname, $paths = array() ) { |
|
| 114 | + public function register($configname, $paths = array()) { |
|
| 115 | 115 | |
| 116 | 116 | //let's just make sure this is instantiated in the right place. |
| 117 | - if ( did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts') ) { |
|
| 118 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso' ), '4.1' ); |
|
| 117 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 118 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $configname = (array) $configname; //typecast to array |
| 122 | - foreach ( $configname as $config ) { |
|
| 123 | - $this->_register( $config, $paths ); |
|
| 122 | + foreach ($configname as $config) { |
|
| 123 | + $this->_register($config, $paths); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | //hook into appropriate footer |
| 127 | 127 | $footer_action = is_admin() ? 'admin_footer' : 'wp_footer'; |
| 128 | - add_action($footer_action, array($this, 'setup_qtip'), 10 ); |
|
| 128 | + add_action($footer_action, array($this, 'setup_qtip'), 10); |
|
| 129 | 129 | |
| 130 | 130 | //make sure we "turn on" qtip js. |
| 131 | - add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 131 | + add_filter('FHEE_load_qtip', '__return_true'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | * @throws EE_Error |
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | - private function _register( $config, $paths ) { |
|
| 145 | + private function _register($config, $paths) { |
|
| 146 | 146 | //before doing anything we have to make sure that EE_Qtip_Config parent is required. |
| 147 | - EE_Registry::instance()->load_lib( 'Qtip_Config', array(), TRUE ); |
|
| 147 | + EE_Registry::instance()->load_lib('Qtip_Config', array(), TRUE); |
|
| 148 | 148 | |
| 149 | - if ( !empty( $paths ) ) { |
|
| 149 | + if ( ! empty($paths)) { |
|
| 150 | 150 | $paths = (array) $paths; |
| 151 | - foreach ( $paths as $path ) { |
|
| 152 | - $path = $path . $config . '.lib.php'; |
|
| 153 | - if ( !is_readable($path ) ) { |
|
| 151 | + foreach ($paths as $path) { |
|
| 152 | + $path = $path.$config.'.lib.php'; |
|
| 153 | + if ( ! is_readable($path)) { |
|
| 154 | 154 | continue; |
| 155 | 155 | } else { |
| 156 | 156 | require_once $path; |
@@ -159,26 +159,26 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | //does class exist at this point? If it does then let's instantiate. If it doesn't then let's continue with other paths. |
| 162 | - if ( !class_exists($config) ) { |
|
| 163 | - $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php'; |
|
| 164 | - if ( !is_readable($path ) ) { |
|
| 165 | - throw new EE_Error( sprintf( __('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config ) ); |
|
| 162 | + if ( ! class_exists($config)) { |
|
| 163 | + $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php'; |
|
| 164 | + if ( ! is_readable($path)) { |
|
| 165 | + throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config)); |
|
| 166 | 166 | } else { |
| 167 | 167 | require_once $path; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | //now we attempt a class_exists one more time. |
| 172 | - if ( !class_exists( $config ) ) |
|
| 173 | - throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 172 | + if ( ! class_exists($config)) |
|
| 173 | + throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config)); |
|
| 174 | 174 | |
| 175 | 175 | //made it HERE? FINALLY, let's get things setup. |
| 176 | 176 | $a = new ReflectionClass($config); |
| 177 | 177 | $qtip = $a->newInstance(); |
| 178 | 178 | |
| 179 | 179 | //verify that $qtip is a valid object |
| 180 | - if ( ! $qtip instanceof EE_Qtip_Config ) |
|
| 181 | - throw new EE_Error( sprintf( esc_html__( 'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>' ) ); |
|
| 180 | + if ( ! $qtip instanceof EE_Qtip_Config) |
|
| 181 | + throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>')); |
|
| 182 | 182 | |
| 183 | 183 | $this->_qtips[] = $a->newInstance(); |
| 184 | 184 | |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | * @return void |
| 195 | 195 | */ |
| 196 | 196 | public function setup_qtip() { |
| 197 | - if ( empty( $this->_qtips ) ) |
|
| 197 | + if (empty($this->_qtips)) |
|
| 198 | 198 | return; //no qtips! |
| 199 | 199 | |
| 200 | 200 | $content = array(); |
| 201 | 201 | |
| 202 | - foreach ( $this->_qtips as $qtip ) { |
|
| 202 | + foreach ($this->_qtips as $qtip) { |
|
| 203 | 203 | $content[] = $this->_generate_content_container($qtip); |
| 204 | 204 | } |
| 205 | 205 | |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | private function _generate_content_container($qtip) { |
| 217 | 217 | $qts = $qtip->get_tips(); |
| 218 | 218 | $content = array(); |
| 219 | - foreach ( $qts as $qt ) { |
|
| 220 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 219 | + foreach ($qts as $qt) { |
|
| 220 | + if ( ! $qt instanceof EE_Qtip) |
|
| 221 | 221 | continue; |
| 222 | - $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>'; |
|
| 222 | + $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | return implode('<br />', $content); |
@@ -19,126 +19,126 @@ |
||
| 19 | 19 | abstract class DomainBase implements DomainInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | - * |
|
| 25 | - * @var FilePath |
|
| 26 | - */ |
|
| 27 | - private $plugin_file; |
|
| 22 | + /** |
|
| 23 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | + * |
|
| 25 | + * @var FilePath |
|
| 26 | + */ |
|
| 27 | + private $plugin_file; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * String indicating version for plugin |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private $version; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $plugin_basename |
|
| 38 | - */ |
|
| 39 | - private $plugin_basename; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string $plugin_path |
|
| 43 | - */ |
|
| 44 | - private $plugin_path; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $plugin_url |
|
| 48 | - */ |
|
| 49 | - private $plugin_url; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Initializes internal properties. |
|
| 55 | - * |
|
| 56 | - * @param FilePath $plugin_file |
|
| 57 | - * @param Version $version |
|
| 58 | - */ |
|
| 59 | - public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | - { |
|
| 61 | - $this->plugin_file = $plugin_file; |
|
| 62 | - $this->version = $version; |
|
| 63 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function pluginFile() |
|
| 73 | - { |
|
| 74 | - return (string) $this->plugin_file; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function pluginBasename() |
|
| 83 | - { |
|
| 84 | - return $this->plugin_basename; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function pluginPath() |
|
| 93 | - { |
|
| 94 | - return $this->plugin_path; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function pluginUrl() |
|
| 103 | - { |
|
| 104 | - return $this->plugin_url; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function version() |
|
| 113 | - { |
|
| 114 | - return (string) $this->version; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return Version |
|
| 121 | - */ |
|
| 122 | - public function versionValueObject() |
|
| 123 | - { |
|
| 124 | - return $this->version; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function distributionAssetsPath() |
|
| 132 | - { |
|
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | - } |
|
| 29 | + /** |
|
| 30 | + * String indicating version for plugin |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private $version; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $plugin_basename |
|
| 38 | + */ |
|
| 39 | + private $plugin_basename; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string $plugin_path |
|
| 43 | + */ |
|
| 44 | + private $plugin_path; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $plugin_url |
|
| 48 | + */ |
|
| 49 | + private $plugin_url; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Initializes internal properties. |
|
| 55 | + * |
|
| 56 | + * @param FilePath $plugin_file |
|
| 57 | + * @param Version $version |
|
| 58 | + */ |
|
| 59 | + public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | + { |
|
| 61 | + $this->plugin_file = $plugin_file; |
|
| 62 | + $this->version = $version; |
|
| 63 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function pluginFile() |
|
| 73 | + { |
|
| 74 | + return (string) $this->plugin_file; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function pluginBasename() |
|
| 83 | + { |
|
| 84 | + return $this->plugin_basename; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function pluginPath() |
|
| 93 | + { |
|
| 94 | + return $this->plugin_path; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function pluginUrl() |
|
| 103 | + { |
|
| 104 | + return $this->plugin_url; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function version() |
|
| 113 | + { |
|
| 114 | + return (string) $this->version; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return Version |
|
| 121 | + */ |
|
| 122 | + public function versionValueObject() |
|
| 123 | + { |
|
| 124 | + return $this->version; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function distributionAssetsPath() |
|
| 132 | + { |
|
| 133 | + return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function distributionAssetsUrl() |
|
| 141 | - { |
|
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | - } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function distributionAssetsUrl() |
|
| 141 | + { |
|
| 142 | + return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function distributionAssetsPath() |
| 132 | 132 | { |
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 133 | + return $this->pluginPath().'assets/dist/'; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function distributionAssetsUrl() |
| 141 | 141 | { |
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 142 | + return $this->pluginUrl().'assets/dist/'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
@@ -19,33 +19,33 @@ |
||
| 19 | 19 | class InvalidRequestStackMiddlewareException extends InvalidDataTypeException |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param mixed $middleware_app_class |
|
| 24 | - * @param string $message |
|
| 25 | - * @param int $code |
|
| 26 | - * @param Exception $previous |
|
| 27 | - */ |
|
| 28 | - public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | - { |
|
| 30 | - if(is_array($middleware_app_class)) { |
|
| 31 | - $middleware_app_class = reset($middleware_app_class); |
|
| 32 | - } |
|
| 33 | - if (empty($message)) { |
|
| 34 | - $message = sprintf( |
|
| 35 | - esc_html__( |
|
| 36 | - 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 37 | - 'event_espresso' |
|
| 38 | - ), |
|
| 39 | - $middleware_app_class |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - parent::__construct( |
|
| 43 | - '$middleware_app_class', |
|
| 44 | - $middleware_app_class, |
|
| 45 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 46 | - $message, |
|
| 47 | - $code, |
|
| 48 | - $previous |
|
| 49 | - ); |
|
| 50 | - } |
|
| 22 | + /** |
|
| 23 | + * @param mixed $middleware_app_class |
|
| 24 | + * @param string $message |
|
| 25 | + * @param int $code |
|
| 26 | + * @param Exception $previous |
|
| 27 | + */ |
|
| 28 | + public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | + { |
|
| 30 | + if(is_array($middleware_app_class)) { |
|
| 31 | + $middleware_app_class = reset($middleware_app_class); |
|
| 32 | + } |
|
| 33 | + if (empty($message)) { |
|
| 34 | + $message = sprintf( |
|
| 35 | + esc_html__( |
|
| 36 | + 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 37 | + 'event_espresso' |
|
| 38 | + ), |
|
| 39 | + $middleware_app_class |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + parent::__construct( |
|
| 43 | + '$middleware_app_class', |
|
| 44 | + $middleware_app_class, |
|
| 45 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 46 | + $message, |
|
| 47 | + $code, |
|
| 48 | + $previous |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
| 29 | 29 | { |
| 30 | - if(is_array($middleware_app_class)) { |
|
| 30 | + if (is_array($middleware_app_class)) { |
|
| 31 | 31 | $middleware_app_class = reset($middleware_app_class); |
| 32 | 32 | } |
| 33 | 33 | if (empty($message)) { |
@@ -24,97 +24,97 @@ |
||
| 24 | 24 | class RequestStackBuilder extends SplDoublyLinkedList |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @type LoaderInterface $loader |
|
| 29 | - */ |
|
| 30 | - private $loader; |
|
| 27 | + /** |
|
| 28 | + * @type LoaderInterface $loader |
|
| 29 | + */ |
|
| 30 | + private $loader; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * RequestStackBuilder constructor. |
|
| 35 | - * |
|
| 36 | - * @param LoaderInterface $loader |
|
| 37 | - */ |
|
| 38 | - public function __construct(LoaderInterface $loader) |
|
| 39 | - { |
|
| 40 | - $this->loader = $loader; |
|
| 41 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * RequestStackBuilder constructor. |
|
| 35 | + * |
|
| 36 | + * @param LoaderInterface $loader |
|
| 37 | + */ |
|
| 38 | + public function __construct(LoaderInterface $loader) |
|
| 39 | + { |
|
| 40 | + $this->loader = $loader; |
|
| 41 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * builds decorated middleware stack |
|
| 47 | - * by continuously injecting previous middleware app into the next |
|
| 48 | - * |
|
| 49 | - * @param RequestStackCoreAppInterface $application |
|
| 50 | - * @return RequestStack |
|
| 51 | - * @throws Exception |
|
| 52 | - */ |
|
| 53 | - public function resolve(RequestStackCoreAppInterface $application) |
|
| 54 | - { |
|
| 55 | - $core_app = $application; |
|
| 56 | - // NOW... because the RequestStack is following the decorator pattern, |
|
| 57 | - // the first stack app we add will end up at the center of the stack, |
|
| 58 | - // and will end up being the last item to actually run, but we don't want that! |
|
| 59 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 60 | - // BUT... we want the final stack to be in the same order as the first. |
|
| 61 | - // So we need to reverse the iterator mode when transferring items, |
|
| 62 | - // because if we don't, the second stack will end up in the incorrect order. |
|
| 63 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 64 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 65 | - try { |
|
| 66 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 67 | - $middleware_app_class = array_shift($middleware_app); |
|
| 68 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 69 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 70 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 71 | - } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 72 | - if(WP_DEBUG) { |
|
| 73 | - new ExceptionStackTraceDisplay($exception); |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 76 | - error_log($exception->getMessage()); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - return new RequestStack($application, $core_app); |
|
| 80 | - } |
|
| 45 | + /** |
|
| 46 | + * builds decorated middleware stack |
|
| 47 | + * by continuously injecting previous middleware app into the next |
|
| 48 | + * |
|
| 49 | + * @param RequestStackCoreAppInterface $application |
|
| 50 | + * @return RequestStack |
|
| 51 | + * @throws Exception |
|
| 52 | + */ |
|
| 53 | + public function resolve(RequestStackCoreAppInterface $application) |
|
| 54 | + { |
|
| 55 | + $core_app = $application; |
|
| 56 | + // NOW... because the RequestStack is following the decorator pattern, |
|
| 57 | + // the first stack app we add will end up at the center of the stack, |
|
| 58 | + // and will end up being the last item to actually run, but we don't want that! |
|
| 59 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 60 | + // BUT... we want the final stack to be in the same order as the first. |
|
| 61 | + // So we need to reverse the iterator mode when transferring items, |
|
| 62 | + // because if we don't, the second stack will end up in the incorrect order. |
|
| 63 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 64 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 65 | + try { |
|
| 66 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 67 | + $middleware_app_class = array_shift($middleware_app); |
|
| 68 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 69 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 70 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 71 | + } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 72 | + if(WP_DEBUG) { |
|
| 73 | + new ExceptionStackTraceDisplay($exception); |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | + error_log($exception->getMessage()); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + return new RequestStack($application, $core_app); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 85 | - * are all ordered correctly so that the middleware can be properly constructed |
|
| 86 | - * |
|
| 87 | - * @param array $middleware_app |
|
| 88 | - * @param bool $recurse |
|
| 89 | - * @return array |
|
| 90 | - * @throws InvalidRequestStackMiddlewareException |
|
| 91 | - */ |
|
| 92 | - protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 93 | - { |
|
| 94 | - $middleware_app_class = reset($middleware_app); |
|
| 95 | - // is array empty ? |
|
| 96 | - if($middleware_app_class === false) { |
|
| 97 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 98 | - } |
|
| 99 | - // are the class and arguments in the wrong order ? |
|
| 100 | - if(is_array($middleware_app_class)) { |
|
| 101 | - if ($recurse === true) { |
|
| 102 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 103 | - } |
|
| 104 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 105 | - } |
|
| 106 | - // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 107 | - if(is_int($middleware_app_class)) { |
|
| 108 | - if ($recurse === true) { |
|
| 109 | - $middleware_app = array_reverse($middleware_app); |
|
| 110 | - return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 111 | - } |
|
| 112 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | - } |
|
| 114 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 115 | - if(! class_exists($middleware_app_class)) { |
|
| 116 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 117 | - } |
|
| 118 | - return $middleware_app; |
|
| 119 | - } |
|
| 83 | + /** |
|
| 84 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 85 | + * are all ordered correctly so that the middleware can be properly constructed |
|
| 86 | + * |
|
| 87 | + * @param array $middleware_app |
|
| 88 | + * @param bool $recurse |
|
| 89 | + * @return array |
|
| 90 | + * @throws InvalidRequestStackMiddlewareException |
|
| 91 | + */ |
|
| 92 | + protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 93 | + { |
|
| 94 | + $middleware_app_class = reset($middleware_app); |
|
| 95 | + // is array empty ? |
|
| 96 | + if($middleware_app_class === false) { |
|
| 97 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 98 | + } |
|
| 99 | + // are the class and arguments in the wrong order ? |
|
| 100 | + if(is_array($middleware_app_class)) { |
|
| 101 | + if ($recurse === true) { |
|
| 102 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 103 | + } |
|
| 104 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 105 | + } |
|
| 106 | + // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 107 | + if(is_int($middleware_app_class)) { |
|
| 108 | + if ($recurse === true) { |
|
| 109 | + $middleware_app = array_reverse($middleware_app); |
|
| 110 | + return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 111 | + } |
|
| 112 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | + } |
|
| 114 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 115 | + if(! class_exists($middleware_app_class)) { |
|
| 116 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 117 | + } |
|
| 118 | + return $middleware_app; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
| 70 | 70 | $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
| 71 | 71 | } catch (InvalidRequestStackMiddlewareException $exception) { |
| 72 | - if(WP_DEBUG) { |
|
| 72 | + if (WP_DEBUG) { |
|
| 73 | 73 | new ExceptionStackTraceDisplay($exception); |
| 74 | 74 | continue; |
| 75 | 75 | } |
@@ -93,18 +93,18 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $middleware_app_class = reset($middleware_app); |
| 95 | 95 | // is array empty ? |
| 96 | - if($middleware_app_class === false) { |
|
| 96 | + if ($middleware_app_class === false) { |
|
| 97 | 97 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 98 | 98 | } |
| 99 | 99 | // are the class and arguments in the wrong order ? |
| 100 | - if(is_array($middleware_app_class)) { |
|
| 100 | + if (is_array($middleware_app_class)) { |
|
| 101 | 101 | if ($recurse === true) { |
| 102 | 102 | return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
| 103 | 103 | } |
| 104 | 104 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 105 | 105 | } |
| 106 | 106 | // is filter callback working like legacy middleware and sending a numerically indexed array ? |
| 107 | - if(is_int($middleware_app_class)) { |
|
| 107 | + if (is_int($middleware_app_class)) { |
|
| 108 | 108 | if ($recurse === true) { |
| 109 | 109 | $middleware_app = array_reverse($middleware_app); |
| 110 | 110 | return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 113 | 113 | } |
| 114 | 114 | // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
| 115 | - if(! class_exists($middleware_app_class)) { |
|
| 115 | + if ( ! class_exists($middleware_app_class)) { |
|
| 116 | 116 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 117 | 117 | } |
| 118 | 118 | return $middleware_app; |
@@ -16,49 +16,49 @@ |
||
| 16 | 16 | interface DomainInterface extends InterminableInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return string |
|
| 21 | - * @throws DomainException |
|
| 22 | - */ |
|
| 23 | - public function pluginFile(); |
|
| 19 | + /** |
|
| 20 | + * @return string |
|
| 21 | + * @throws DomainException |
|
| 22 | + */ |
|
| 23 | + public function pluginFile(); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - * @throws DomainException |
|
| 29 | - */ |
|
| 30 | - public function pluginBasename(); |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + * @throws DomainException |
|
| 29 | + */ |
|
| 30 | + public function pluginBasename(); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function pluginPath(); |
|
| 33 | + /** |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function pluginPath(); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - * @throws DomainException |
|
| 42 | - */ |
|
| 43 | - public function pluginUrl(); |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + * @throws DomainException |
|
| 42 | + */ |
|
| 43 | + public function pluginUrl(); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - * @throws DomainException |
|
| 49 | - */ |
|
| 50 | - public function version(); |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + * @throws DomainException |
|
| 49 | + */ |
|
| 50 | + public function version(); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function distributionAssetsPath(); |
|
| 53 | + /** |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function distributionAssetsPath(); |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function distributionAssetsUrl(); |
|
| 59 | + /** |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function distributionAssetsUrl(); |
|
| 63 | 63 | |
| 64 | 64 | } |
@@ -14,1506 +14,1506 @@ |
||
| 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 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1279 | - * |
|
| 1280 | - * @throws EE_Error |
|
| 1281 | - */ |
|
| 1282 | - public function clean_sensitive_data() |
|
| 1283 | - { |
|
| 1284 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1285 | - $subsection->clean_sensitive_data(); |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1292 | - * @param string $form_submission_error_message |
|
| 1293 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 1294 | - * @throws EE_Error |
|
| 1295 | - */ |
|
| 1296 | - public function set_submission_error_message( |
|
| 1297 | - $form_submission_error_message = '' |
|
| 1298 | - ) { |
|
| 1299 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1300 | - ? $form_submission_error_message |
|
| 1301 | - : $this->getAllValidationErrorsString(); |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1307 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 1308 | - * set_submission_error_message |
|
| 1309 | - * |
|
| 1310 | - * @return string |
|
| 1311 | - */ |
|
| 1312 | - public function submission_error_message() |
|
| 1313 | - { |
|
| 1314 | - return $this->_form_submission_error_message; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 1320 | - * @param string $form_submission_success_message |
|
| 1321 | - */ |
|
| 1322 | - public function set_submission_success_message($form_submission_success_message = '') |
|
| 1323 | - { |
|
| 1324 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1325 | - ? $form_submission_success_message |
|
| 1326 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - /** |
|
| 1331 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 1332 | - * @return string |
|
| 1333 | - */ |
|
| 1334 | - public function submission_success_message() |
|
| 1335 | - { |
|
| 1336 | - return $this->_form_submission_success_message; |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * Returns the prefix that should be used on child of this form section for |
|
| 1342 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1343 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1344 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1345 | - * |
|
| 1346 | - * @return string |
|
| 1347 | - * @throws EE_Error |
|
| 1348 | - */ |
|
| 1349 | - public function html_name_prefix() |
|
| 1350 | - { |
|
| 1351 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1352 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1353 | - } |
|
| 1354 | - return $this->name(); |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - /** |
|
| 1359 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1360 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1361 | - * was set, which is probably nothing, or the classname) |
|
| 1362 | - * |
|
| 1363 | - * @return string |
|
| 1364 | - * @throws EE_Error |
|
| 1365 | - */ |
|
| 1366 | - public function name() |
|
| 1367 | - { |
|
| 1368 | - $this->ensure_construct_finalized_called(); |
|
| 1369 | - return parent::name(); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * @return EE_Form_Section_Proper |
|
| 1375 | - * @throws EE_Error |
|
| 1376 | - */ |
|
| 1377 | - public function parent_section() |
|
| 1378 | - { |
|
| 1379 | - $this->ensure_construct_finalized_called(); |
|
| 1380 | - return parent::parent_section(); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - |
|
| 1384 | - /** |
|
| 1385 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1386 | - * |
|
| 1387 | - * @return void |
|
| 1388 | - * @throws EE_Error |
|
| 1389 | - */ |
|
| 1390 | - public function ensure_construct_finalized_called() |
|
| 1391 | - { |
|
| 1392 | - if (! $this->_construction_finalized) { |
|
| 1393 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - |
|
| 1398 | - /** |
|
| 1399 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1400 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1401 | - * |
|
| 1402 | - * @param array $req_data |
|
| 1403 | - * @return boolean |
|
| 1404 | - * @throws EE_Error |
|
| 1405 | - */ |
|
| 1406 | - public function form_data_present_in($req_data = null) |
|
| 1407 | - { |
|
| 1408 | - $req_data = $this->getCachedRequest($req_data); |
|
| 1409 | - foreach ($this->subsections() as $subsection) { |
|
| 1410 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1411 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1412 | - return true; |
|
| 1413 | - } |
|
| 1414 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1415 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1416 | - return true; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - return false; |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * Gets validation errors for this form section and subsections |
|
| 1426 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1427 | - * gets the validation errors for ALL subsection |
|
| 1428 | - * |
|
| 1429 | - * @return EE_Validation_Error[] |
|
| 1430 | - * @throws EE_Error |
|
| 1431 | - */ |
|
| 1432 | - public function get_validation_errors_accumulated() |
|
| 1433 | - { |
|
| 1434 | - $validation_errors = $this->get_validation_errors(); |
|
| 1435 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1436 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1437 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1438 | - } else { |
|
| 1439 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1440 | - } |
|
| 1441 | - if ($validation_errors_on_this_subsection) { |
|
| 1442 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - return $validation_errors; |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - /** |
|
| 1449 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1450 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1451 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1452 | - * |
|
| 1453 | - * @return string |
|
| 1454 | - * @since $VID:$ |
|
| 1455 | - */ |
|
| 1456 | - protected function getAllValidationErrorsString() |
|
| 1457 | - { |
|
| 1458 | - $submission_error_messages = array(); |
|
| 1459 | - // bad, bad, bad registrant |
|
| 1460 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1461 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1462 | - $form_section = $validation_error->get_form_section(); |
|
| 1463 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1464 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1465 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1466 | - $label = $validation_error->get_form_section()->name(); |
|
| 1467 | - } else { |
|
| 1468 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1469 | - } |
|
| 1470 | - $submission_error_messages[] = sprintf( |
|
| 1471 | - __('%s : %s', 'event_espresso'), |
|
| 1472 | - $label, |
|
| 1473 | - $validation_error->getMessage() |
|
| 1474 | - ); |
|
| 1475 | - } |
|
| 1476 | - } |
|
| 1477 | - return implode('<br', $submission_error_messages); |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1483 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1484 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1485 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1486 | - * which will be returned. |
|
| 1487 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1488 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1489 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1490 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1491 | - * Etc |
|
| 1492 | - * |
|
| 1493 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1494 | - * @return EE_Form_Section_Base |
|
| 1495 | - * @throws EE_Error |
|
| 1496 | - */ |
|
| 1497 | - public function find_section_from_path($form_section_path) |
|
| 1498 | - { |
|
| 1499 | - //check if we can find the input from purely going straight up the tree |
|
| 1500 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1501 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1502 | - return $input; |
|
| 1503 | - } |
|
| 1504 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1505 | - if ($next_slash_pos !== false) { |
|
| 1506 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1507 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1508 | - } else { |
|
| 1509 | - $child_section_name = $form_section_path; |
|
| 1510 | - $subpath = ''; |
|
| 1511 | - } |
|
| 1512 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1513 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1514 | - return $child_section->find_section_from_path($subpath); |
|
| 1515 | - } |
|
| 1516 | - return null; |
|
| 1517 | - } |
|
| 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 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1279 | + * |
|
| 1280 | + * @throws EE_Error |
|
| 1281 | + */ |
|
| 1282 | + public function clean_sensitive_data() |
|
| 1283 | + { |
|
| 1284 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1285 | + $subsection->clean_sensitive_data(); |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1292 | + * @param string $form_submission_error_message |
|
| 1293 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 1294 | + * @throws EE_Error |
|
| 1295 | + */ |
|
| 1296 | + public function set_submission_error_message( |
|
| 1297 | + $form_submission_error_message = '' |
|
| 1298 | + ) { |
|
| 1299 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1300 | + ? $form_submission_error_message |
|
| 1301 | + : $this->getAllValidationErrorsString(); |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1307 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 1308 | + * set_submission_error_message |
|
| 1309 | + * |
|
| 1310 | + * @return string |
|
| 1311 | + */ |
|
| 1312 | + public function submission_error_message() |
|
| 1313 | + { |
|
| 1314 | + return $this->_form_submission_error_message; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 1320 | + * @param string $form_submission_success_message |
|
| 1321 | + */ |
|
| 1322 | + public function set_submission_success_message($form_submission_success_message = '') |
|
| 1323 | + { |
|
| 1324 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1325 | + ? $form_submission_success_message |
|
| 1326 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + /** |
|
| 1331 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 1332 | + * @return string |
|
| 1333 | + */ |
|
| 1334 | + public function submission_success_message() |
|
| 1335 | + { |
|
| 1336 | + return $this->_form_submission_success_message; |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * Returns the prefix that should be used on child of this form section for |
|
| 1342 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1343 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1344 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1345 | + * |
|
| 1346 | + * @return string |
|
| 1347 | + * @throws EE_Error |
|
| 1348 | + */ |
|
| 1349 | + public function html_name_prefix() |
|
| 1350 | + { |
|
| 1351 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1352 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1353 | + } |
|
| 1354 | + return $this->name(); |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1360 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1361 | + * was set, which is probably nothing, or the classname) |
|
| 1362 | + * |
|
| 1363 | + * @return string |
|
| 1364 | + * @throws EE_Error |
|
| 1365 | + */ |
|
| 1366 | + public function name() |
|
| 1367 | + { |
|
| 1368 | + $this->ensure_construct_finalized_called(); |
|
| 1369 | + return parent::name(); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * @return EE_Form_Section_Proper |
|
| 1375 | + * @throws EE_Error |
|
| 1376 | + */ |
|
| 1377 | + public function parent_section() |
|
| 1378 | + { |
|
| 1379 | + $this->ensure_construct_finalized_called(); |
|
| 1380 | + return parent::parent_section(); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + |
|
| 1384 | + /** |
|
| 1385 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1386 | + * |
|
| 1387 | + * @return void |
|
| 1388 | + * @throws EE_Error |
|
| 1389 | + */ |
|
| 1390 | + public function ensure_construct_finalized_called() |
|
| 1391 | + { |
|
| 1392 | + if (! $this->_construction_finalized) { |
|
| 1393 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + |
|
| 1398 | + /** |
|
| 1399 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1400 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1401 | + * |
|
| 1402 | + * @param array $req_data |
|
| 1403 | + * @return boolean |
|
| 1404 | + * @throws EE_Error |
|
| 1405 | + */ |
|
| 1406 | + public function form_data_present_in($req_data = null) |
|
| 1407 | + { |
|
| 1408 | + $req_data = $this->getCachedRequest($req_data); |
|
| 1409 | + foreach ($this->subsections() as $subsection) { |
|
| 1410 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1411 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1412 | + return true; |
|
| 1413 | + } |
|
| 1414 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1415 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1416 | + return true; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + return false; |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * Gets validation errors for this form section and subsections |
|
| 1426 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1427 | + * gets the validation errors for ALL subsection |
|
| 1428 | + * |
|
| 1429 | + * @return EE_Validation_Error[] |
|
| 1430 | + * @throws EE_Error |
|
| 1431 | + */ |
|
| 1432 | + public function get_validation_errors_accumulated() |
|
| 1433 | + { |
|
| 1434 | + $validation_errors = $this->get_validation_errors(); |
|
| 1435 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1436 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1437 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1438 | + } else { |
|
| 1439 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1440 | + } |
|
| 1441 | + if ($validation_errors_on_this_subsection) { |
|
| 1442 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + return $validation_errors; |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + /** |
|
| 1449 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1450 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1451 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1452 | + * |
|
| 1453 | + * @return string |
|
| 1454 | + * @since $VID:$ |
|
| 1455 | + */ |
|
| 1456 | + protected function getAllValidationErrorsString() |
|
| 1457 | + { |
|
| 1458 | + $submission_error_messages = array(); |
|
| 1459 | + // bad, bad, bad registrant |
|
| 1460 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1461 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1462 | + $form_section = $validation_error->get_form_section(); |
|
| 1463 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1464 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1465 | + } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1466 | + $label = $validation_error->get_form_section()->name(); |
|
| 1467 | + } else { |
|
| 1468 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1469 | + } |
|
| 1470 | + $submission_error_messages[] = sprintf( |
|
| 1471 | + __('%s : %s', 'event_espresso'), |
|
| 1472 | + $label, |
|
| 1473 | + $validation_error->getMessage() |
|
| 1474 | + ); |
|
| 1475 | + } |
|
| 1476 | + } |
|
| 1477 | + return implode('<br', $submission_error_messages); |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1483 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1484 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1485 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1486 | + * which will be returned. |
|
| 1487 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1488 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1489 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1490 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1491 | + * Etc |
|
| 1492 | + * |
|
| 1493 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1494 | + * @return EE_Form_Section_Base |
|
| 1495 | + * @throws EE_Error |
|
| 1496 | + */ |
|
| 1497 | + public function find_section_from_path($form_section_path) |
|
| 1498 | + { |
|
| 1499 | + //check if we can find the input from purely going straight up the tree |
|
| 1500 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1501 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1502 | + return $input; |
|
| 1503 | + } |
|
| 1504 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1505 | + if ($next_slash_pos !== false) { |
|
| 1506 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1507 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1508 | + } else { |
|
| 1509 | + $child_section_name = $form_section_path; |
|
| 1510 | + $subpath = ''; |
|
| 1511 | + } |
|
| 1512 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1513 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1514 | + return $child_section->find_section_from_path($subpath); |
|
| 1515 | + } |
|
| 1516 | + return null; |
|
| 1517 | + } |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |