@@ -24,15 +24,15 @@ |
||
| 24 | 24 | |
| 25 | 25 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 26 | 26 | |
| 27 | - if (! defined('EE_MSG_PG_SLUG')) { |
|
| 27 | + if ( ! defined('EE_MSG_PG_SLUG')) { |
|
| 28 | 28 | define('EE_MSG_PG_SLUG', 'espresso_messages'); |
| 29 | 29 | define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
| 30 | - define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
| 31 | - define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
| 32 | - define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
| 33 | - define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
| 34 | - define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
| 35 | - define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
| 30 | + define('EE_MSG_ADMIN', EE_ADMIN_PAGES.'messages/'); |
|
| 31 | + define('EE_MSG_ADMIN_URL', admin_url('admin.php?page='.EE_MSG_PG_SLUG)); |
|
| 32 | + define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN.'assets/'); |
|
| 33 | + define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL.'messages/assets/'); |
|
| 34 | + define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN.'templates/'); |
|
| 35 | + define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL.'messages/templates/'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | parent::__construct(); |
@@ -13,52 +13,52 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Messages_Admin_Page_Init extends EE_Admin_Page_Init |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - *constructor |
|
| 18 | - * |
|
| 19 | - * @Constructor |
|
| 20 | - * @access public |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function __construct() |
|
| 24 | - { |
|
| 16 | + /** |
|
| 17 | + *constructor |
|
| 18 | + * |
|
| 19 | + * @Constructor |
|
| 20 | + * @access public |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function __construct() |
|
| 24 | + { |
|
| 25 | 25 | |
| 26 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 26 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 27 | 27 | |
| 28 | - if (! defined('EE_MSG_PG_SLUG')) { |
|
| 29 | - define('EE_MSG_PG_SLUG', 'espresso_messages'); |
|
| 30 | - define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
|
| 31 | - define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
| 32 | - define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
| 33 | - define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
| 34 | - define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
| 35 | - define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
| 36 | - define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
| 37 | - } |
|
| 28 | + if (! defined('EE_MSG_PG_SLUG')) { |
|
| 29 | + define('EE_MSG_PG_SLUG', 'espresso_messages'); |
|
| 30 | + define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
|
| 31 | + define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
| 32 | + define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
| 33 | + define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
| 34 | + define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
| 35 | + define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
| 36 | + define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - parent::__construct(); |
|
| 40 | - } |
|
| 39 | + parent::__construct(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - protected function _set_init_properties() |
|
| 44 | - { |
|
| 45 | - $this->label = esc_html__('Messages System', 'event_espresso'); |
|
| 46 | - } |
|
| 43 | + protected function _set_init_properties() |
|
| 44 | + { |
|
| 45 | + $this->label = esc_html__('Messages System', 'event_espresso'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - protected function _set_menu_map() |
|
| 50 | - { |
|
| 51 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
| 52 | - array( |
|
| 53 | - 'menu_group' => 'management', |
|
| 54 | - 'menu_order' => 10, |
|
| 55 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 56 | - 'parent_slug' => 'espresso_events', |
|
| 57 | - 'menu_slug' => EE_MSG_PG_SLUG, |
|
| 58 | - 'menu_label' => esc_html__('Messages', 'event_espresso'), |
|
| 59 | - 'capability' => 'ee_read_global_messages', |
|
| 60 | - 'admin_init_page' => $this, |
|
| 61 | - ) |
|
| 62 | - ); |
|
| 63 | - } |
|
| 49 | + protected function _set_menu_map() |
|
| 50 | + { |
|
| 51 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
| 52 | + array( |
|
| 53 | + 'menu_group' => 'management', |
|
| 54 | + 'menu_order' => 10, |
|
| 55 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 56 | + 'parent_slug' => 'espresso_events', |
|
| 57 | + 'menu_slug' => EE_MSG_PG_SLUG, |
|
| 58 | + 'menu_label' => esc_html__('Messages', 'event_espresso'), |
|
| 59 | + 'capability' => 'ee_read_global_messages', |
|
| 60 | + 'admin_init_page' => $this, |
|
| 61 | + ) |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -23,15 +23,15 @@ |
||
| 23 | 23 | public function __construct() |
| 24 | 24 | { |
| 25 | 25 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 26 | - if (! defined('REG_PG_SLUG')) { |
|
| 26 | + if ( ! defined('REG_PG_SLUG')) { |
|
| 27 | 27 | define('REG_PG_SLUG', 'espresso_registrations'); |
| 28 | 28 | define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
| 29 | - define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
| 30 | - define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
| 31 | - define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
| 32 | - define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
| 33 | - define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
| 34 | - define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
| 29 | + define('REG_ADMIN', EE_ADMIN_PAGES.'registrations/'); |
|
| 30 | + define('REG_ADMIN_URL', admin_url('admin.php?page='.REG_PG_SLUG)); |
|
| 31 | + define('REG_ASSETS_PATH', REG_ADMIN.'assets/'); |
|
| 32 | + define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL.'registrations/assets/'); |
|
| 33 | + define('REG_TEMPLATE_PATH', REG_ADMIN.'templates/'); |
|
| 34 | + define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL.'registrations/templates/'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | parent::__construct(); |
@@ -11,50 +11,50 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Registrations_Admin_Page_Init extends EE_Admin_Page_CPT_Init |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * constructor |
|
| 16 | - * |
|
| 17 | - * @Constructor |
|
| 18 | - * @access public |
|
| 19 | - * @return void |
|
| 20 | - */ |
|
| 21 | - public function __construct() |
|
| 22 | - { |
|
| 23 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 24 | - if (! defined('REG_PG_SLUG')) { |
|
| 25 | - define('REG_PG_SLUG', 'espresso_registrations'); |
|
| 26 | - define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
|
| 27 | - define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
| 28 | - define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
| 29 | - define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
| 30 | - define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
| 31 | - define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
| 32 | - define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
| 33 | - } |
|
| 14 | + /** |
|
| 15 | + * constructor |
|
| 16 | + * |
|
| 17 | + * @Constructor |
|
| 18 | + * @access public |
|
| 19 | + * @return void |
|
| 20 | + */ |
|
| 21 | + public function __construct() |
|
| 22 | + { |
|
| 23 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 24 | + if (! defined('REG_PG_SLUG')) { |
|
| 25 | + define('REG_PG_SLUG', 'espresso_registrations'); |
|
| 26 | + define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
|
| 27 | + define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
| 28 | + define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
| 29 | + define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
| 30 | + define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
| 31 | + define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
| 32 | + define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - parent::__construct(); |
|
| 36 | - } |
|
| 35 | + parent::__construct(); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - protected function _set_init_properties() |
|
| 40 | - { |
|
| 41 | - $this->label = esc_html__('Registrations Overview', 'event_espresso'); |
|
| 42 | - } |
|
| 39 | + protected function _set_init_properties() |
|
| 40 | + { |
|
| 41 | + $this->label = esc_html__('Registrations Overview', 'event_espresso'); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - protected function _set_menu_map() |
|
| 46 | - { |
|
| 47 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
| 48 | - array( |
|
| 49 | - 'menu_group' => 'main', |
|
| 50 | - 'menu_order' => 40, |
|
| 51 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 52 | - 'parent_slug' => 'espresso_events', |
|
| 53 | - 'menu_slug' => REG_PG_SLUG, |
|
| 54 | - 'menu_label' => esc_html__('Registrations', 'event_espresso'), |
|
| 55 | - 'capability' => 'ee_read_registrations', |
|
| 56 | - 'admin_init_page' => $this, |
|
| 57 | - ) |
|
| 58 | - ); |
|
| 59 | - } |
|
| 45 | + protected function _set_menu_map() |
|
| 46 | + { |
|
| 47 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
| 48 | + array( |
|
| 49 | + 'menu_group' => 'main', |
|
| 50 | + 'menu_order' => 40, |
|
| 51 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 52 | + 'parent_slug' => 'espresso_events', |
|
| 53 | + 'menu_slug' => REG_PG_SLUG, |
|
| 54 | + 'menu_label' => esc_html__('Registrations', 'event_espresso'), |
|
| 55 | + 'capability' => 'ee_read_registrations', |
|
| 56 | + 'admin_init_page' => $this, |
|
| 57 | + ) |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -20,18 +20,18 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | public function __construct($pm_instance = null) |
| 22 | 22 | { |
| 23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
| 23 | + require_once($this->file_folder().'EEG_Paypal_Express.gateway.php'); |
|
| 24 | 24 | $this->_gateway = new EEG_Paypal_Express(); |
| 25 | 25 | |
| 26 | 26 | $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
| 27 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
| 27 | + $this->_template_path = $this->file_folder().'templates/'; |
|
| 28 | 28 | $this->_default_description = esc_html__( |
| 29 | 29 | // @codingStandardsIgnoreStart |
| 30 | 30 | 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
| 31 | 31 | // @codingStandardsIgnoreEnd |
| 32 | 32 | 'event_espresso' |
| 33 | 33 | ); |
| 34 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
| 34 | + $this->_default_button_url = $this->file_url().'lib/paypal-express-checkout-logo-gold-160.png'; |
|
| 35 | 35 | |
| 36 | 36 | parent::__construct($pm_instance); |
| 37 | 37 | } |
@@ -14,89 +14,89 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_PMT_Paypal_Express extends EE_PMT_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * EE_PMT_Paypal_Express constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct($pm_instance = null) |
|
| 21 | - { |
|
| 22 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
| 23 | - $this->_gateway = new EEG_Paypal_Express(); |
|
| 17 | + /** |
|
| 18 | + * EE_PMT_Paypal_Express constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct($pm_instance = null) |
|
| 21 | + { |
|
| 22 | + require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
| 23 | + $this->_gateway = new EEG_Paypal_Express(); |
|
| 24 | 24 | |
| 25 | - $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
| 26 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
| 27 | - $this->_default_description = esc_html__( |
|
| 28 | - // @codingStandardsIgnoreStart |
|
| 29 | - 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
| 30 | - // @codingStandardsIgnoreEnd |
|
| 31 | - 'event_espresso' |
|
| 32 | - ); |
|
| 33 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
| 25 | + $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
| 26 | + $this->_template_path = $this->file_folder() . 'templates/'; |
|
| 27 | + $this->_default_description = esc_html__( |
|
| 28 | + // @codingStandardsIgnoreStart |
|
| 29 | + 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
| 30 | + // @codingStandardsIgnoreEnd |
|
| 31 | + 'event_espresso' |
|
| 32 | + ); |
|
| 33 | + $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
| 34 | 34 | |
| 35 | - parent::__construct($pm_instance); |
|
| 36 | - } |
|
| 35 | + parent::__construct($pm_instance); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Adds the help tab. |
|
| 41 | - * |
|
| 42 | - * @see EE_PMT_Base::help_tabs_config() |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function help_tabs_config() |
|
| 46 | - { |
|
| 47 | - return array( |
|
| 48 | - $this->get_help_tab_name() => array( |
|
| 49 | - 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
| 50 | - 'filename' => 'payment_methods_overview_paypal_express' |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - } |
|
| 39 | + /** |
|
| 40 | + * Adds the help tab. |
|
| 41 | + * |
|
| 42 | + * @see EE_PMT_Base::help_tabs_config() |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function help_tabs_config() |
|
| 46 | + { |
|
| 47 | + return array( |
|
| 48 | + $this->get_help_tab_name() => array( |
|
| 49 | + 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
| 50 | + 'filename' => 'payment_methods_overview_paypal_express' |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Gets the form for all the settings related to this payment method type. |
|
| 58 | - * |
|
| 59 | - * @return EE_Payment_Method_Form |
|
| 60 | - */ |
|
| 61 | - public function generate_new_settings_form() |
|
| 62 | - { |
|
| 63 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Gets the form for all the settings related to this payment method type. |
|
| 58 | + * |
|
| 59 | + * @return EE_Payment_Method_Form |
|
| 60 | + */ |
|
| 61 | + public function generate_new_settings_form() |
|
| 62 | + { |
|
| 63 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Creates a billing form for this payment method type. |
|
| 69 | - * |
|
| 70 | - * @param \EE_Transaction $transaction |
|
| 71 | - * @return \EE_Billing_Info_Form |
|
| 72 | - */ |
|
| 73 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
| 74 | - { |
|
| 75 | - if ($this->_pm_instance->debug_mode()) { |
|
| 76 | - $form = new EE_Billing_Info_Form( |
|
| 77 | - $this->_pm_instance, |
|
| 78 | - array( |
|
| 79 | - 'name' => 'paypal_express_Info_Form', |
|
| 80 | - 'subsections' => array( |
|
| 81 | - 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
| 82 | - array( |
|
| 83 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 84 | - array( |
|
| 85 | - 'layout_template_file' => $this->_template_path |
|
| 86 | - . 'paypal_express_debug_info.template.php', |
|
| 87 | - 'template_args' => array( |
|
| 88 | - 'debug_mode' => $this->_pm_instance->debug_mode() |
|
| 89 | - ) |
|
| 90 | - ) |
|
| 91 | - ) |
|
| 92 | - ) |
|
| 93 | - ) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ); |
|
| 97 | - return $form; |
|
| 98 | - } |
|
| 67 | + /** |
|
| 68 | + * Creates a billing form for this payment method type. |
|
| 69 | + * |
|
| 70 | + * @param \EE_Transaction $transaction |
|
| 71 | + * @return \EE_Billing_Info_Form |
|
| 72 | + */ |
|
| 73 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
| 74 | + { |
|
| 75 | + if ($this->_pm_instance->debug_mode()) { |
|
| 76 | + $form = new EE_Billing_Info_Form( |
|
| 77 | + $this->_pm_instance, |
|
| 78 | + array( |
|
| 79 | + 'name' => 'paypal_express_Info_Form', |
|
| 80 | + 'subsections' => array( |
|
| 81 | + 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
| 82 | + array( |
|
| 83 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 84 | + array( |
|
| 85 | + 'layout_template_file' => $this->_template_path |
|
| 86 | + . 'paypal_express_debug_info.template.php', |
|
| 87 | + 'template_args' => array( |
|
| 88 | + 'debug_mode' => $this->_pm_instance->debug_mode() |
|
| 89 | + ) |
|
| 90 | + ) |
|
| 91 | + ) |
|
| 92 | + ) |
|
| 93 | + ) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ); |
|
| 97 | + return $form; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return false; |
|
| 101 | - } |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | { |
| 91 | 91 | espresso_load_required( |
| 92 | 92 | 'EE_Request', |
| 93 | - EE_CORE . 'request_stack/EE_Request.core.php' |
|
| 93 | + EE_CORE.'request_stack/EE_Request.core.php' |
|
| 94 | 94 | ); |
| 95 | 95 | $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
| 96 | 96 | $this->legacy_request->setRequest($this->request); |
@@ -28,84 +28,84 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class BootstrapRequestResponseObjects |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @type LegacyRequestInterface $legacy_request |
|
| 33 | - */ |
|
| 34 | - protected $legacy_request; |
|
| 31 | + /** |
|
| 32 | + * @type LegacyRequestInterface $legacy_request |
|
| 33 | + */ |
|
| 34 | + protected $legacy_request; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @type LoaderInterface $loader |
|
| 38 | - */ |
|
| 39 | - protected $loader; |
|
| 36 | + /** |
|
| 37 | + * @type LoaderInterface $loader |
|
| 38 | + */ |
|
| 39 | + protected $loader; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var RequestInterface $request |
|
| 43 | - */ |
|
| 44 | - protected $request; |
|
| 41 | + /** |
|
| 42 | + * @var RequestInterface $request |
|
| 43 | + */ |
|
| 44 | + protected $request; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var ResponseInterface $response |
|
| 48 | - */ |
|
| 49 | - protected $response; |
|
| 46 | + /** |
|
| 47 | + * @var ResponseInterface $response |
|
| 48 | + */ |
|
| 49 | + protected $response; |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * BootstrapRequestResponseObjects constructor. |
|
| 54 | - * |
|
| 55 | - * @param LoaderInterface $loader |
|
| 56 | - */ |
|
| 57 | - public function __construct(LoaderInterface $loader) |
|
| 58 | - { |
|
| 59 | - $this->loader = $loader; |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * BootstrapRequestResponseObjects constructor. |
|
| 54 | + * |
|
| 55 | + * @param LoaderInterface $loader |
|
| 56 | + */ |
|
| 57 | + public function __construct(LoaderInterface $loader) |
|
| 58 | + { |
|
| 59 | + $this->loader = $loader; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function buildRequestResponse() |
|
| 67 | - { |
|
| 68 | - $request_params = new RequestParams(new RequestSanitizer()); |
|
| 69 | - $server_params = new ServerParams(new ServerSanitizer()); |
|
| 70 | - // load our Request and Response objects |
|
| 71 | - $this->request = new Request($request_params, $server_params); |
|
| 72 | - $this->response = new Response(); |
|
| 73 | - $this->loader->share(RequestParams::class, $request_params); |
|
| 74 | - $this->loader->share(ServerParams::class, $server_params); |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function buildRequestResponse() |
|
| 67 | + { |
|
| 68 | + $request_params = new RequestParams(new RequestSanitizer()); |
|
| 69 | + $server_params = new ServerParams(new ServerSanitizer()); |
|
| 70 | + // load our Request and Response objects |
|
| 71 | + $this->request = new Request($request_params, $server_params); |
|
| 72 | + $this->response = new Response(); |
|
| 73 | + $this->loader->share(RequestParams::class, $request_params); |
|
| 74 | + $this->loader->share(ServerParams::class, $server_params); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return void |
|
| 80 | - * @throws InvalidArgumentException |
|
| 81 | - */ |
|
| 82 | - public function shareRequestResponse() |
|
| 83 | - { |
|
| 84 | - $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
| 85 | - $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
| 86 | - EE_Dependency_Map::instance()->setRequest($this->request); |
|
| 87 | - EE_Dependency_Map::instance()->setResponse($this->response); |
|
| 88 | - } |
|
| 78 | + /** |
|
| 79 | + * @return void |
|
| 80 | + * @throws InvalidArgumentException |
|
| 81 | + */ |
|
| 82 | + public function shareRequestResponse() |
|
| 83 | + { |
|
| 84 | + $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
| 85 | + $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
| 86 | + EE_Dependency_Map::instance()->setRequest($this->request); |
|
| 87 | + EE_Dependency_Map::instance()->setResponse($this->response); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - public function setupLegacyRequest() |
|
| 97 | - { |
|
| 98 | - espresso_load_required( |
|
| 99 | - 'EE_Request', |
|
| 100 | - EE_CORE . 'request_stack/EE_Request.core.php' |
|
| 101 | - ); |
|
| 102 | - $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
| 103 | - $this->legacy_request->setRequest($this->request); |
|
| 104 | - $this->legacy_request->admin = $this->request->isAdmin(); |
|
| 105 | - $this->legacy_request->ajax = $this->request->isAjax(); |
|
| 106 | - $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
| 107 | - EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
| 108 | - $this->loader->share('EE_Request', $this->legacy_request); |
|
| 109 | - $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
| 110 | - } |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + public function setupLegacyRequest() |
|
| 97 | + { |
|
| 98 | + espresso_load_required( |
|
| 99 | + 'EE_Request', |
|
| 100 | + EE_CORE . 'request_stack/EE_Request.core.php' |
|
| 101 | + ); |
|
| 102 | + $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
| 103 | + $this->legacy_request->setRequest($this->request); |
|
| 104 | + $this->legacy_request->admin = $this->request->isAdmin(); |
|
| 105 | + $this->legacy_request->ajax = $this->request->isAjax(); |
|
| 106 | + $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
| 107 | + EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
| 108 | + $this->loader->share('EE_Request', $this->legacy_request); |
|
| 109 | + $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | // load interfaces |
| 200 | 200 | espresso_load_required( |
| 201 | 201 | 'EEH_Autoloader', |
| 202 | - EE_CORE . 'helpers/EEH_Autoloader.helper.php' |
|
| 202 | + EE_CORE.'helpers/EEH_Autoloader.helper.php' |
|
| 203 | 203 | ); |
| 204 | 204 | EEH_Autoloader::instance(); |
| 205 | 205 | } |
@@ -213,13 +213,13 @@ discard block |
||
| 213 | 213 | protected function setAutoloadersForRequiredFiles() |
| 214 | 214 | { |
| 215 | 215 | // load interfaces |
| 216 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
| 216 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces', true); |
|
| 217 | 217 | // load helpers |
| 218 | 218 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
| 219 | 219 | // register legacy request stack classes just in case |
| 220 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack/'); |
|
| 220 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack/'); |
|
| 221 | 221 | // register legacy middleware classes just in case |
| 222 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware/'); |
|
| 222 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware/'); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -46,225 +46,225 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | class BootstrapCore |
| 48 | 48 | { |
| 49 | - /** |
|
| 50 | - * @type LoaderInterface $loader |
|
| 51 | - */ |
|
| 52 | - private $loader; |
|
| 49 | + /** |
|
| 50 | + * @type LoaderInterface $loader |
|
| 51 | + */ |
|
| 52 | + private $loader; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var RequestInterface $request |
|
| 56 | - */ |
|
| 57 | - protected $request; |
|
| 54 | + /** |
|
| 55 | + * @var RequestInterface $request |
|
| 56 | + */ |
|
| 57 | + protected $request; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var ResponseInterface $response |
|
| 61 | - */ |
|
| 62 | - protected $response; |
|
| 59 | + /** |
|
| 60 | + * @var ResponseInterface $response |
|
| 61 | + */ |
|
| 62 | + protected $response; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var RequestStackBuilder $request_stack_builder |
|
| 66 | - */ |
|
| 67 | - protected $request_stack_builder; |
|
| 64 | + /** |
|
| 65 | + * @var RequestStackBuilder $request_stack_builder |
|
| 66 | + */ |
|
| 67 | + protected $request_stack_builder; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var RequestStack $request_stack |
|
| 71 | - */ |
|
| 72 | - protected $request_stack; |
|
| 69 | + /** |
|
| 70 | + * @var RequestStack $request_stack |
|
| 71 | + */ |
|
| 72 | + protected $request_stack; |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * BootstrapCore constructor. |
|
| 77 | - */ |
|
| 78 | - public function __construct() |
|
| 79 | - { |
|
| 80 | - do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
| 81 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
| 82 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * BootstrapCore constructor. |
|
| 77 | + */ |
|
| 78 | + public function __construct() |
|
| 79 | + { |
|
| 80 | + do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
| 81 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
| 82 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @throws DomainException |
|
| 88 | - * @throws EE_Error |
|
| 89 | - * @throws Exception |
|
| 90 | - * @throws InvalidArgumentException |
|
| 91 | - * @throws InvalidClassException |
|
| 92 | - * @throws InvalidDataTypeException |
|
| 93 | - * @throws InvalidFilePathException |
|
| 94 | - * @throws InvalidInterfaceException |
|
| 95 | - * @throws InvalidRequestStackMiddlewareException |
|
| 96 | - * @throws OutOfBoundsException |
|
| 97 | - * @throws ReflectionException |
|
| 98 | - */ |
|
| 99 | - public function initialize() |
|
| 100 | - { |
|
| 101 | - $this->bootstrapDependencyInjectionContainer(); |
|
| 102 | - $this->bootstrapDomain(); |
|
| 103 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
| 104 | - add_action( |
|
| 105 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
| 106 | - array($bootstrap_request, 'setupLegacyRequest') |
|
| 107 | - ); |
|
| 108 | - $this->runRequestStack(); |
|
| 109 | - } |
|
| 86 | + /** |
|
| 87 | + * @throws DomainException |
|
| 88 | + * @throws EE_Error |
|
| 89 | + * @throws Exception |
|
| 90 | + * @throws InvalidArgumentException |
|
| 91 | + * @throws InvalidClassException |
|
| 92 | + * @throws InvalidDataTypeException |
|
| 93 | + * @throws InvalidFilePathException |
|
| 94 | + * @throws InvalidInterfaceException |
|
| 95 | + * @throws InvalidRequestStackMiddlewareException |
|
| 96 | + * @throws OutOfBoundsException |
|
| 97 | + * @throws ReflectionException |
|
| 98 | + */ |
|
| 99 | + public function initialize() |
|
| 100 | + { |
|
| 101 | + $this->bootstrapDependencyInjectionContainer(); |
|
| 102 | + $this->bootstrapDomain(); |
|
| 103 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
| 104 | + add_action( |
|
| 105 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
| 106 | + array($bootstrap_request, 'setupLegacyRequest') |
|
| 107 | + ); |
|
| 108 | + $this->runRequestStack(); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * @throws ReflectionException |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidDataTypeException |
|
| 117 | - * @throws InvalidInterfaceException |
|
| 118 | - * @throws OutOfBoundsException |
|
| 119 | - */ |
|
| 120 | - private function bootstrapDependencyInjectionContainer() |
|
| 121 | - { |
|
| 122 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
| 123 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
| 124 | - $bootstrap_di->buildLoader(); |
|
| 125 | - $registry = $bootstrap_di->getRegistry(); |
|
| 126 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
| 127 | - $dependency_map->initialize(); |
|
| 128 | - $registry->initialize(); |
|
| 129 | - $this->loader = $bootstrap_di->getLoader(); |
|
| 130 | - } |
|
| 112 | + /** |
|
| 113 | + * @throws ReflectionException |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidDataTypeException |
|
| 117 | + * @throws InvalidInterfaceException |
|
| 118 | + * @throws OutOfBoundsException |
|
| 119 | + */ |
|
| 120 | + private function bootstrapDependencyInjectionContainer() |
|
| 121 | + { |
|
| 122 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
| 123 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
| 124 | + $bootstrap_di->buildLoader(); |
|
| 125 | + $registry = $bootstrap_di->getRegistry(); |
|
| 126 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
| 127 | + $dependency_map->initialize(); |
|
| 128 | + $registry->initialize(); |
|
| 129 | + $this->loader = $bootstrap_di->getLoader(); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * configures the Domain object for core |
|
| 135 | - * |
|
| 136 | - * @return void |
|
| 137 | - * @throws DomainException |
|
| 138 | - * @throws InvalidArgumentException |
|
| 139 | - * @throws InvalidDataTypeException |
|
| 140 | - * @throws InvalidClassException |
|
| 141 | - * @throws InvalidFilePathException |
|
| 142 | - * @throws InvalidInterfaceException |
|
| 143 | - */ |
|
| 144 | - private function bootstrapDomain() |
|
| 145 | - { |
|
| 146 | - DomainFactory::getEventEspressoCoreDomain(); |
|
| 147 | - } |
|
| 133 | + /** |
|
| 134 | + * configures the Domain object for core |
|
| 135 | + * |
|
| 136 | + * @return void |
|
| 137 | + * @throws DomainException |
|
| 138 | + * @throws InvalidArgumentException |
|
| 139 | + * @throws InvalidDataTypeException |
|
| 140 | + * @throws InvalidClassException |
|
| 141 | + * @throws InvalidFilePathException |
|
| 142 | + * @throws InvalidInterfaceException |
|
| 143 | + */ |
|
| 144 | + private function bootstrapDomain() |
|
| 145 | + { |
|
| 146 | + DomainFactory::getEventEspressoCoreDomain(); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * sets up the request and response objects |
|
| 152 | - * |
|
| 153 | - * @return BootstrapRequestResponseObjects |
|
| 154 | - * @throws InvalidArgumentException |
|
| 155 | - */ |
|
| 156 | - private function bootstrapRequestResponseObjects() |
|
| 157 | - { |
|
| 158 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
| 159 | - $bootstrap_request = $this->loader->getShared( |
|
| 160 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
| 161 | - array($this->loader) |
|
| 162 | - ); |
|
| 163 | - $bootstrap_request->buildRequestResponse(); |
|
| 164 | - $bootstrap_request->shareRequestResponse(); |
|
| 165 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 166 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
| 167 | - return $bootstrap_request; |
|
| 168 | - } |
|
| 150 | + /** |
|
| 151 | + * sets up the request and response objects |
|
| 152 | + * |
|
| 153 | + * @return BootstrapRequestResponseObjects |
|
| 154 | + * @throws InvalidArgumentException |
|
| 155 | + */ |
|
| 156 | + private function bootstrapRequestResponseObjects() |
|
| 157 | + { |
|
| 158 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
| 159 | + $bootstrap_request = $this->loader->getShared( |
|
| 160 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
| 161 | + array($this->loader) |
|
| 162 | + ); |
|
| 163 | + $bootstrap_request->buildRequestResponse(); |
|
| 164 | + $bootstrap_request->shareRequestResponse(); |
|
| 165 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 166 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
| 167 | + return $bootstrap_request; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * run_request_stack |
|
| 173 | - * construct request stack and run middleware apps |
|
| 174 | - * |
|
| 175 | - * @throws EE_Error |
|
| 176 | - * @throws Exception |
|
| 177 | - */ |
|
| 178 | - public function runRequestStack() |
|
| 179 | - { |
|
| 180 | - $this->loadAutoloader(); |
|
| 181 | - $this->setAutoloadersForRequiredFiles(); |
|
| 182 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
| 183 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
| 184 | - new RequestStackCoreApp() |
|
| 185 | - ); |
|
| 186 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
| 187 | - $this->request_stack->handleResponse(); |
|
| 188 | - } |
|
| 171 | + /** |
|
| 172 | + * run_request_stack |
|
| 173 | + * construct request stack and run middleware apps |
|
| 174 | + * |
|
| 175 | + * @throws EE_Error |
|
| 176 | + * @throws Exception |
|
| 177 | + */ |
|
| 178 | + public function runRequestStack() |
|
| 179 | + { |
|
| 180 | + $this->loadAutoloader(); |
|
| 181 | + $this->setAutoloadersForRequiredFiles(); |
|
| 182 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
| 183 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
| 184 | + new RequestStackCoreApp() |
|
| 185 | + ); |
|
| 186 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
| 187 | + $this->request_stack->handleResponse(); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * load_autoloader |
|
| 193 | - * |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - protected function loadAutoloader() |
|
| 197 | - { |
|
| 198 | - // load interfaces |
|
| 199 | - espresso_load_required( |
|
| 200 | - 'EEH_Autoloader', |
|
| 201 | - EE_CORE . 'helpers/EEH_Autoloader.helper.php' |
|
| 202 | - ); |
|
| 203 | - EEH_Autoloader::instance(); |
|
| 204 | - } |
|
| 191 | + /** |
|
| 192 | + * load_autoloader |
|
| 193 | + * |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + protected function loadAutoloader() |
|
| 197 | + { |
|
| 198 | + // load interfaces |
|
| 199 | + espresso_load_required( |
|
| 200 | + 'EEH_Autoloader', |
|
| 201 | + EE_CORE . 'helpers/EEH_Autoloader.helper.php' |
|
| 202 | + ); |
|
| 203 | + EEH_Autoloader::instance(); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * load_required_files |
|
| 209 | - * |
|
| 210 | - * @throws EE_Error |
|
| 211 | - */ |
|
| 212 | - protected function setAutoloadersForRequiredFiles() |
|
| 213 | - { |
|
| 214 | - // load interfaces |
|
| 215 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
| 216 | - // load helpers |
|
| 217 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 218 | - // register legacy request stack classes just in case |
|
| 219 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack/'); |
|
| 220 | - // register legacy middleware classes just in case |
|
| 221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware/'); |
|
| 222 | - } |
|
| 207 | + /** |
|
| 208 | + * load_required_files |
|
| 209 | + * |
|
| 210 | + * @throws EE_Error |
|
| 211 | + */ |
|
| 212 | + protected function setAutoloadersForRequiredFiles() |
|
| 213 | + { |
|
| 214 | + // load interfaces |
|
| 215 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
| 216 | + // load helpers |
|
| 217 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 218 | + // register legacy request stack classes just in case |
|
| 219 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack/'); |
|
| 220 | + // register legacy middleware classes just in case |
|
| 221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware/'); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * build_request_stack |
|
| 227 | - * |
|
| 228 | - * @return RequestStackBuilder |
|
| 229 | - */ |
|
| 230 | - public function buildRequestStack() |
|
| 231 | - { |
|
| 232 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
| 233 | - /** |
|
| 234 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
| 235 | - * so items at the beginning of the final middleware stack will run last. |
|
| 236 | - * First parameter is the middleware classname, second is an array of arguments |
|
| 237 | - */ |
|
| 238 | - $stack_apps = apply_filters( |
|
| 239 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
| 240 | - array( |
|
| 241 | - // first in last out |
|
| 242 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
| 243 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
| 244 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
| 245 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
| 246 | - // last in first out |
|
| 247 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - // legacy filter for backwards compatibility |
|
| 251 | - $stack_apps = apply_filters( |
|
| 252 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
| 253 | - $stack_apps |
|
| 254 | - ); |
|
| 255 | - // load middleware onto stack : FILO (First In Last Out) |
|
| 256 | - // items at the beginning of the $stack_apps array will run last |
|
| 257 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
| 258 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
| 259 | - } |
|
| 260 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
| 261 | - // and we also need it to always run first because the rest of the system relies on it |
|
| 262 | - $request_stack_builder->push( |
|
| 263 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
| 264 | - ); |
|
| 265 | - return apply_filters( |
|
| 266 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
| 267 | - $request_stack_builder |
|
| 268 | - ); |
|
| 269 | - } |
|
| 225 | + /** |
|
| 226 | + * build_request_stack |
|
| 227 | + * |
|
| 228 | + * @return RequestStackBuilder |
|
| 229 | + */ |
|
| 230 | + public function buildRequestStack() |
|
| 231 | + { |
|
| 232 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
| 233 | + /** |
|
| 234 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
| 235 | + * so items at the beginning of the final middleware stack will run last. |
|
| 236 | + * First parameter is the middleware classname, second is an array of arguments |
|
| 237 | + */ |
|
| 238 | + $stack_apps = apply_filters( |
|
| 239 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
| 240 | + array( |
|
| 241 | + // first in last out |
|
| 242 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
| 243 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
| 244 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
| 245 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
| 246 | + // last in first out |
|
| 247 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + // legacy filter for backwards compatibility |
|
| 251 | + $stack_apps = apply_filters( |
|
| 252 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
| 253 | + $stack_apps |
|
| 254 | + ); |
|
| 255 | + // load middleware onto stack : FILO (First In Last Out) |
|
| 256 | + // items at the beginning of the $stack_apps array will run last |
|
| 257 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
| 258 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
| 259 | + } |
|
| 260 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
| 261 | + // and we also need it to always run first because the rest of the system relies on it |
|
| 262 | + $request_stack_builder->push( |
|
| 263 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
| 264 | + ); |
|
| 265 | + return apply_filters( |
|
| 266 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
| 267 | + $request_stack_builder |
|
| 268 | + ); |
|
| 269 | + } |
|
| 270 | 270 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | array(), |
| 130 | 130 | CoffeeMaker::BREW_LOAD_ONLY, |
| 131 | 131 | array( |
| 132 | - EE_INTERFACES . '*.php', |
|
| 133 | - EE_INTERFACES . '*.interfaces.php', |
|
| 132 | + EE_INTERFACES.'*.php', |
|
| 133 | + EE_INTERFACES.'*.interfaces.php', |
|
| 134 | 134 | ) |
| 135 | 135 | ) |
| 136 | 136 | ); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | array(), |
| 143 | 143 | array(), |
| 144 | 144 | CoffeeMaker::BREW_SHARED, |
| 145 | - EE_MODELS . '*.model.php' |
|
| 145 | + EE_MODELS.'*.model.php' |
|
| 146 | 146 | ) |
| 147 | 147 | ); |
| 148 | 148 | // add a wildcard recipe for loading core classes |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | array(), |
| 155 | 155 | CoffeeMaker::BREW_SHARED, |
| 156 | 156 | array( |
| 157 | - EE_CORE . '*.core.php', |
|
| 158 | - EE_ADMIN . '*.core.php', |
|
| 159 | - EE_CPTS . '*.core.php', |
|
| 160 | - EE_CORE . 'data_migration_scripts/*.core.php', |
|
| 157 | + EE_CORE.'*.core.php', |
|
| 158 | + EE_ADMIN.'*.core.php', |
|
| 159 | + EE_CPTS.'*.core.php', |
|
| 160 | + EE_CORE.'data_migration_scripts/*.core.php', |
|
| 161 | 161 | ) |
| 162 | 162 | ) |
| 163 | 163 | ); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | array(), |
| 170 | 170 | array(), |
| 171 | 171 | CoffeeMaker::BREW_LOAD_ONLY, |
| 172 | - array(EE_ADMIN . '*.core.php') |
|
| 172 | + array(EE_ADMIN.'*.core.php') |
|
| 173 | 173 | ) |
| 174 | 174 | ); |
| 175 | 175 | // add a wildcard recipe for loading core classes |
@@ -19,192 +19,192 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class OpenCoffeeShop |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var CoffeeShop $CoffeeShop |
|
| 24 | - */ |
|
| 25 | - private $CoffeeShop; |
|
| 22 | + /** |
|
| 23 | + * @var CoffeeShop $CoffeeShop |
|
| 24 | + */ |
|
| 25 | + private $CoffeeShop; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * OpenCoffeeShop constructor |
|
| 30 | - * |
|
| 31 | - * @throws InvalidInterfaceException |
|
| 32 | - */ |
|
| 33 | - public function __construct() |
|
| 34 | - { |
|
| 35 | - // instantiate the DI container |
|
| 36 | - $this->CoffeeShop = new CoffeeShop(); |
|
| 37 | - } |
|
| 28 | + /** |
|
| 29 | + * OpenCoffeeShop constructor |
|
| 30 | + * |
|
| 31 | + * @throws InvalidInterfaceException |
|
| 32 | + */ |
|
| 33 | + public function __construct() |
|
| 34 | + { |
|
| 35 | + // instantiate the DI container |
|
| 36 | + $this->CoffeeShop = new CoffeeShop(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 41 | - /** |
|
| 42 | - * @return CoffeeShop |
|
| 43 | - */ |
|
| 44 | - public function CoffeeShop() |
|
| 45 | - { |
|
| 46 | - return $this->CoffeeShop; |
|
| 47 | - } |
|
| 40 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 41 | + /** |
|
| 42 | + * @return CoffeeShop |
|
| 43 | + */ |
|
| 44 | + public function CoffeeShop() |
|
| 45 | + { |
|
| 46 | + return $this->CoffeeShop; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * configure coffee makers which control the different kinds of brews |
|
| 52 | - * ( shared services, new factory objects, etc ) |
|
| 53 | - * |
|
| 54 | - * @throws InvalidEntityException |
|
| 55 | - */ |
|
| 56 | - public function setupCoffeeMakers() |
|
| 57 | - { |
|
| 58 | - // create a dependency injector class for resolving class constructor arguments |
|
| 59 | - $DependencyInjector = new DependencyInjector( |
|
| 60 | - $this->CoffeeShop, |
|
| 61 | - new \EEH_Array() |
|
| 62 | - ); |
|
| 63 | - // and some coffeemakers, one for creating new instances |
|
| 64 | - $this->CoffeeShop->addCoffeeMaker( |
|
| 65 | - new NewCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 66 | - CoffeeMaker::BREW_NEW |
|
| 67 | - ); |
|
| 68 | - // one for shared services |
|
| 69 | - $this->CoffeeShop->addCoffeeMaker( |
|
| 70 | - new SharedCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 71 | - CoffeeMaker::BREW_SHARED |
|
| 72 | - ); |
|
| 73 | - // and one for classes that only get loaded |
|
| 74 | - $this->CoffeeShop->addCoffeeMaker( |
|
| 75 | - new LoadOnlyCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 76 | - CoffeeMaker::BREW_LOAD_ONLY |
|
| 77 | - ); |
|
| 78 | - } |
|
| 50 | + /** |
|
| 51 | + * configure coffee makers which control the different kinds of brews |
|
| 52 | + * ( shared services, new factory objects, etc ) |
|
| 53 | + * |
|
| 54 | + * @throws InvalidEntityException |
|
| 55 | + */ |
|
| 56 | + public function setupCoffeeMakers() |
|
| 57 | + { |
|
| 58 | + // create a dependency injector class for resolving class constructor arguments |
|
| 59 | + $DependencyInjector = new DependencyInjector( |
|
| 60 | + $this->CoffeeShop, |
|
| 61 | + new \EEH_Array() |
|
| 62 | + ); |
|
| 63 | + // and some coffeemakers, one for creating new instances |
|
| 64 | + $this->CoffeeShop->addCoffeeMaker( |
|
| 65 | + new NewCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 66 | + CoffeeMaker::BREW_NEW |
|
| 67 | + ); |
|
| 68 | + // one for shared services |
|
| 69 | + $this->CoffeeShop->addCoffeeMaker( |
|
| 70 | + new SharedCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 71 | + CoffeeMaker::BREW_SHARED |
|
| 72 | + ); |
|
| 73 | + // and one for classes that only get loaded |
|
| 74 | + $this->CoffeeShop->addCoffeeMaker( |
|
| 75 | + new LoadOnlyCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
| 76 | + CoffeeMaker::BREW_LOAD_ONLY |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Recipes define how to load legacy classes |
|
| 83 | - * |
|
| 84 | - * @throws InvalidIdentifierException |
|
| 85 | - */ |
|
| 86 | - public function addRecipes() |
|
| 87 | - { |
|
| 88 | - // add default recipe, which should handle loading for most PSR-4 compatible classes |
|
| 89 | - // as long as they are not type hinting for interfaces |
|
| 90 | - $this->CoffeeShop->addRecipe( |
|
| 91 | - new Recipe( |
|
| 92 | - Recipe::DEFAULT_ID |
|
| 93 | - ) |
|
| 94 | - ); |
|
| 95 | - // PSR-4 compatible class with aliases |
|
| 96 | - $this->CoffeeShop->addRecipe( |
|
| 97 | - new Recipe( |
|
| 98 | - 'CommandHandlerManager', |
|
| 99 | - 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 100 | - array( |
|
| 101 | - 'CommandHandlerManagerInterface', |
|
| 102 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 103 | - ), |
|
| 104 | - array(), |
|
| 105 | - CoffeeMaker::BREW_SHARED |
|
| 106 | - ) |
|
| 107 | - ); |
|
| 108 | - // PSR-4 compatible class with aliases, which dependency on CommandHandlerManager |
|
| 109 | - $this->CoffeeShop->addRecipe( |
|
| 110 | - new Recipe( |
|
| 111 | - 'CommandBus', |
|
| 112 | - 'EventEspresso\core\services\commands\CommandBus', |
|
| 113 | - array( |
|
| 114 | - 'CommandBusInterface', |
|
| 115 | - 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 116 | - ), |
|
| 117 | - array(), |
|
| 118 | - CoffeeMaker::BREW_SHARED |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - // LEGACY classes that are NOT compatible with PSR-4 autoloading, and so must specify a filepath |
|
| 122 | - // add a wildcard recipe for loading legacy core interfaces |
|
| 123 | - $this->CoffeeShop->addRecipe( |
|
| 124 | - new Recipe( |
|
| 125 | - 'EEI_*', |
|
| 126 | - '', |
|
| 127 | - array(), |
|
| 128 | - array(), |
|
| 129 | - CoffeeMaker::BREW_LOAD_ONLY, |
|
| 130 | - array( |
|
| 131 | - EE_INTERFACES . '*.php', |
|
| 132 | - EE_INTERFACES . '*.interfaces.php', |
|
| 133 | - ) |
|
| 134 | - ) |
|
| 135 | - ); |
|
| 136 | - // add a wildcard recipe for loading models |
|
| 137 | - $this->CoffeeShop->addRecipe( |
|
| 138 | - new Recipe( |
|
| 139 | - 'EEM_*', |
|
| 140 | - '', |
|
| 141 | - array(), |
|
| 142 | - array(), |
|
| 143 | - CoffeeMaker::BREW_SHARED, |
|
| 144 | - EE_MODELS . '*.model.php' |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - // add a wildcard recipe for loading core classes |
|
| 148 | - $this->CoffeeShop->addRecipe( |
|
| 149 | - new Recipe( |
|
| 150 | - 'EE_*', |
|
| 151 | - '', |
|
| 152 | - array(), |
|
| 153 | - array(), |
|
| 154 | - CoffeeMaker::BREW_SHARED, |
|
| 155 | - array( |
|
| 156 | - EE_CORE . '*.core.php', |
|
| 157 | - EE_ADMIN . '*.core.php', |
|
| 158 | - EE_CPTS . '*.core.php', |
|
| 159 | - EE_CORE . 'data_migration_scripts/*.core.php', |
|
| 160 | - ) |
|
| 161 | - ) |
|
| 162 | - ); |
|
| 163 | - // load admin page parent class |
|
| 164 | - $this->CoffeeShop->addRecipe( |
|
| 165 | - new Recipe( |
|
| 166 | - 'EE_Admin_Page*', |
|
| 167 | - '', |
|
| 168 | - array(), |
|
| 169 | - array(), |
|
| 170 | - CoffeeMaker::BREW_LOAD_ONLY, |
|
| 171 | - array(EE_ADMIN . '*.core.php') |
|
| 172 | - ) |
|
| 173 | - ); |
|
| 174 | - // add a wildcard recipe for loading core classes |
|
| 175 | - // $this->CoffeeShop->addRecipe( |
|
| 176 | - // new Recipe( |
|
| 177 | - // '*_Admin_Page', |
|
| 178 | - // '', |
|
| 179 | - // array(), |
|
| 180 | - // array(), |
|
| 181 | - // CoffeeMaker::BREW_SHARED, |
|
| 182 | - // array( |
|
| 183 | - // EE_ADMIN_PAGES . 'transactions/*.core.php', |
|
| 184 | - // ) |
|
| 185 | - // ) |
|
| 186 | - // ); |
|
| 187 | - } |
|
| 81 | + /** |
|
| 82 | + * Recipes define how to load legacy classes |
|
| 83 | + * |
|
| 84 | + * @throws InvalidIdentifierException |
|
| 85 | + */ |
|
| 86 | + public function addRecipes() |
|
| 87 | + { |
|
| 88 | + // add default recipe, which should handle loading for most PSR-4 compatible classes |
|
| 89 | + // as long as they are not type hinting for interfaces |
|
| 90 | + $this->CoffeeShop->addRecipe( |
|
| 91 | + new Recipe( |
|
| 92 | + Recipe::DEFAULT_ID |
|
| 93 | + ) |
|
| 94 | + ); |
|
| 95 | + // PSR-4 compatible class with aliases |
|
| 96 | + $this->CoffeeShop->addRecipe( |
|
| 97 | + new Recipe( |
|
| 98 | + 'CommandHandlerManager', |
|
| 99 | + 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 100 | + array( |
|
| 101 | + 'CommandHandlerManagerInterface', |
|
| 102 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 103 | + ), |
|
| 104 | + array(), |
|
| 105 | + CoffeeMaker::BREW_SHARED |
|
| 106 | + ) |
|
| 107 | + ); |
|
| 108 | + // PSR-4 compatible class with aliases, which dependency on CommandHandlerManager |
|
| 109 | + $this->CoffeeShop->addRecipe( |
|
| 110 | + new Recipe( |
|
| 111 | + 'CommandBus', |
|
| 112 | + 'EventEspresso\core\services\commands\CommandBus', |
|
| 113 | + array( |
|
| 114 | + 'CommandBusInterface', |
|
| 115 | + 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 116 | + ), |
|
| 117 | + array(), |
|
| 118 | + CoffeeMaker::BREW_SHARED |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + // LEGACY classes that are NOT compatible with PSR-4 autoloading, and so must specify a filepath |
|
| 122 | + // add a wildcard recipe for loading legacy core interfaces |
|
| 123 | + $this->CoffeeShop->addRecipe( |
|
| 124 | + new Recipe( |
|
| 125 | + 'EEI_*', |
|
| 126 | + '', |
|
| 127 | + array(), |
|
| 128 | + array(), |
|
| 129 | + CoffeeMaker::BREW_LOAD_ONLY, |
|
| 130 | + array( |
|
| 131 | + EE_INTERFACES . '*.php', |
|
| 132 | + EE_INTERFACES . '*.interfaces.php', |
|
| 133 | + ) |
|
| 134 | + ) |
|
| 135 | + ); |
|
| 136 | + // add a wildcard recipe for loading models |
|
| 137 | + $this->CoffeeShop->addRecipe( |
|
| 138 | + new Recipe( |
|
| 139 | + 'EEM_*', |
|
| 140 | + '', |
|
| 141 | + array(), |
|
| 142 | + array(), |
|
| 143 | + CoffeeMaker::BREW_SHARED, |
|
| 144 | + EE_MODELS . '*.model.php' |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + // add a wildcard recipe for loading core classes |
|
| 148 | + $this->CoffeeShop->addRecipe( |
|
| 149 | + new Recipe( |
|
| 150 | + 'EE_*', |
|
| 151 | + '', |
|
| 152 | + array(), |
|
| 153 | + array(), |
|
| 154 | + CoffeeMaker::BREW_SHARED, |
|
| 155 | + array( |
|
| 156 | + EE_CORE . '*.core.php', |
|
| 157 | + EE_ADMIN . '*.core.php', |
|
| 158 | + EE_CPTS . '*.core.php', |
|
| 159 | + EE_CORE . 'data_migration_scripts/*.core.php', |
|
| 160 | + ) |
|
| 161 | + ) |
|
| 162 | + ); |
|
| 163 | + // load admin page parent class |
|
| 164 | + $this->CoffeeShop->addRecipe( |
|
| 165 | + new Recipe( |
|
| 166 | + 'EE_Admin_Page*', |
|
| 167 | + '', |
|
| 168 | + array(), |
|
| 169 | + array(), |
|
| 170 | + CoffeeMaker::BREW_LOAD_ONLY, |
|
| 171 | + array(EE_ADMIN . '*.core.php') |
|
| 172 | + ) |
|
| 173 | + ); |
|
| 174 | + // add a wildcard recipe for loading core classes |
|
| 175 | + // $this->CoffeeShop->addRecipe( |
|
| 176 | + // new Recipe( |
|
| 177 | + // '*_Admin_Page', |
|
| 178 | + // '', |
|
| 179 | + // array(), |
|
| 180 | + // array(), |
|
| 181 | + // CoffeeMaker::BREW_SHARED, |
|
| 182 | + // array( |
|
| 183 | + // EE_ADMIN_PAGES . 'transactions/*.core.php', |
|
| 184 | + // ) |
|
| 185 | + // ) |
|
| 186 | + // ); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * bootstrap EE and the request stack |
|
| 192 | - * |
|
| 193 | - * @throws ServiceNotFoundException |
|
| 194 | - * @throws InvalidClassException |
|
| 195 | - * @throws InvalidDataTypeException |
|
| 196 | - * @throws InvalidIdentifierException |
|
| 197 | - * @throws exceptions\ServiceExistsException |
|
| 198 | - * @throws OutOfBoundsException |
|
| 199 | - * @throws exceptions\InstantiationException |
|
| 200 | - */ |
|
| 201 | - public function firstBrew() |
|
| 202 | - { |
|
| 203 | - $this->CoffeeShop->brew( |
|
| 204 | - 'EventEspresso\core\services\request\Request', |
|
| 205 | - array($_GET, $_POST, $_COOKIE, $_SERVER) |
|
| 206 | - ); |
|
| 207 | - $this->CoffeeShop->brew('EventEspresso\core\services\request\Response'); |
|
| 208 | - $this->CoffeeShop->brew('EE_Bootstrap'); |
|
| 209 | - } |
|
| 190 | + /** |
|
| 191 | + * bootstrap EE and the request stack |
|
| 192 | + * |
|
| 193 | + * @throws ServiceNotFoundException |
|
| 194 | + * @throws InvalidClassException |
|
| 195 | + * @throws InvalidDataTypeException |
|
| 196 | + * @throws InvalidIdentifierException |
|
| 197 | + * @throws exceptions\ServiceExistsException |
|
| 198 | + * @throws OutOfBoundsException |
|
| 199 | + * @throws exceptions\InstantiationException |
|
| 200 | + */ |
|
| 201 | + public function firstBrew() |
|
| 202 | + { |
|
| 203 | + $this->CoffeeShop->brew( |
|
| 204 | + 'EventEspresso\core\services\request\Request', |
|
| 205 | + array($_GET, $_POST, $_COOKIE, $_SERVER) |
|
| 206 | + ); |
|
| 207 | + $this->CoffeeShop->brew('EventEspresso\core\services\request\Response'); |
|
| 208 | + $this->CoffeeShop->brew('EE_Bootstrap'); |
|
| 209 | + } |
|
| 210 | 210 | } |
@@ -15,94 +15,94 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class LicenseService |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var Config |
|
| 20 | - */ |
|
| 21 | - private $config; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var Stats |
|
| 26 | - */ |
|
| 27 | - private $stats_collection; |
|
| 28 | - |
|
| 29 | - public function __construct(Stats $stats_collection, Config $config) |
|
| 30 | - { |
|
| 31 | - $this->config = $config; |
|
| 32 | - $this->stats_collection = $stats_collection; |
|
| 33 | - $this->loadPueClient(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - private function loadPueClient() |
|
| 37 | - { |
|
| 38 | - // PUE Auto Upgrades stuff |
|
| 39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
| 40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
| 41 | - |
|
| 42 | - // $options needs to be an array with the included keys as listed. |
|
| 43 | - $options = array( |
|
| 44 | - // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
| 45 | - // clients options table. Will be automatically set if left blank. |
|
| 46 | - 'apikey' => $this->config->siteLicenseKey(), |
|
| 47 | - // (required), you will need to obtain the apikey that the client gets from your site and |
|
| 48 | - // then saves in their sites options table (see 'getting an api-key' below) |
|
| 49 | - 'lang_domain' => $this->config->i18nDomain(), |
|
| 50 | - // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
| 51 | - // localized). That way strings in this file will be included in the translation for your plugin. |
|
| 52 | - 'checkPeriod' => $this->config->checkPeriod(), |
|
| 53 | - // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
| 54 | - // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
| 55 | - // default to 12 hours. |
|
| 56 | - 'option_key' => $this->config->optionKey(), |
|
| 57 | - // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
| 58 | - // updating your information message whenever this option_key is modified. |
|
| 59 | - 'options_page_slug' => $this->config->optionsPageSlug(), |
|
| 60 | - 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
| 61 | - 'use_wp_update' => true, |
|
| 62 | - // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
| 63 | - 'extra_stats' => $this->stats_collection->statsCallback(), |
|
| 64 | - 'turn_on_notices_saved' => true, |
|
| 65 | - ); |
|
| 66 | - // initiate the class and start the plugin update engine! |
|
| 67 | - new PluginUpdateEngineChecker( |
|
| 68 | - $this->config->hostServerUrl(), |
|
| 69 | - $this->config->pluginSlug(), |
|
| 70 | - $options |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
| 78 | - * |
|
| 79 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
| 80 | - * identify plugins. Defaults to core update |
|
| 81 | - * @return boolean True if update available, false if not. |
|
| 82 | - */ |
|
| 83 | - public static function isUpdateAvailable($basename = '') |
|
| 84 | - { |
|
| 85 | - $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
| 86 | - |
|
| 87 | - $update = false; |
|
| 88 | - |
|
| 89 | - // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
| 90 | - $folder = '/' . dirname($basename); |
|
| 91 | - |
|
| 92 | - $plugins = get_plugins($folder); |
|
| 93 | - $current = get_site_transient('update_plugins'); |
|
| 94 | - |
|
| 95 | - foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
| 96 | - if (isset($current->response['plugin_file'])) { |
|
| 97 | - $update = true; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // it's possible that there is an update but an invalid site-license-key is in use |
|
| 102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
| 103 | - $update = true; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $update; |
|
| 107 | - } |
|
| 18 | + /** |
|
| 19 | + * @var Config |
|
| 20 | + */ |
|
| 21 | + private $config; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var Stats |
|
| 26 | + */ |
|
| 27 | + private $stats_collection; |
|
| 28 | + |
|
| 29 | + public function __construct(Stats $stats_collection, Config $config) |
|
| 30 | + { |
|
| 31 | + $this->config = $config; |
|
| 32 | + $this->stats_collection = $stats_collection; |
|
| 33 | + $this->loadPueClient(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + private function loadPueClient() |
|
| 37 | + { |
|
| 38 | + // PUE Auto Upgrades stuff |
|
| 39 | + if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
| 40 | + require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
| 41 | + |
|
| 42 | + // $options needs to be an array with the included keys as listed. |
|
| 43 | + $options = array( |
|
| 44 | + // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
| 45 | + // clients options table. Will be automatically set if left blank. |
|
| 46 | + 'apikey' => $this->config->siteLicenseKey(), |
|
| 47 | + // (required), you will need to obtain the apikey that the client gets from your site and |
|
| 48 | + // then saves in their sites options table (see 'getting an api-key' below) |
|
| 49 | + 'lang_domain' => $this->config->i18nDomain(), |
|
| 50 | + // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
| 51 | + // localized). That way strings in this file will be included in the translation for your plugin. |
|
| 52 | + 'checkPeriod' => $this->config->checkPeriod(), |
|
| 53 | + // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
| 54 | + // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
| 55 | + // default to 12 hours. |
|
| 56 | + 'option_key' => $this->config->optionKey(), |
|
| 57 | + // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
| 58 | + // updating your information message whenever this option_key is modified. |
|
| 59 | + 'options_page_slug' => $this->config->optionsPageSlug(), |
|
| 60 | + 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
| 61 | + 'use_wp_update' => true, |
|
| 62 | + // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
| 63 | + 'extra_stats' => $this->stats_collection->statsCallback(), |
|
| 64 | + 'turn_on_notices_saved' => true, |
|
| 65 | + ); |
|
| 66 | + // initiate the class and start the plugin update engine! |
|
| 67 | + new PluginUpdateEngineChecker( |
|
| 68 | + $this->config->hostServerUrl(), |
|
| 69 | + $this->config->pluginSlug(), |
|
| 70 | + $options |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
| 78 | + * |
|
| 79 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
| 80 | + * identify plugins. Defaults to core update |
|
| 81 | + * @return boolean True if update available, false if not. |
|
| 82 | + */ |
|
| 83 | + public static function isUpdateAvailable($basename = '') |
|
| 84 | + { |
|
| 85 | + $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
| 86 | + |
|
| 87 | + $update = false; |
|
| 88 | + |
|
| 89 | + // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
| 90 | + $folder = '/' . dirname($basename); |
|
| 91 | + |
|
| 92 | + $plugins = get_plugins($folder); |
|
| 93 | + $current = get_site_transient('update_plugins'); |
|
| 94 | + |
|
| 95 | + foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
| 96 | + if (isset($current->response['plugin_file'])) { |
|
| 97 | + $update = true; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // it's possible that there is an update but an invalid site-license-key is in use |
|
| 102 | + if (get_site_option('pue_json_error_' . $basename)) { |
|
| 103 | + $update = true; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $update; |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | private function loadPueClient() |
| 37 | 37 | { |
| 38 | 38 | // PUE Auto Upgrades stuff |
| 39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
| 40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
| 39 | + if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { // include the file |
|
| 40 | + require_once(EE_THIRD_PARTY.'pue/pue-client.php'); |
|
| 41 | 41 | |
| 42 | 42 | // $options needs to be an array with the included keys as listed. |
| 43 | 43 | $options = array( |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $update = false; |
| 88 | 88 | |
| 89 | 89 | // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
| 90 | - $folder = '/' . dirname($basename); |
|
| 90 | + $folder = '/'.dirname($basename); |
|
| 91 | 91 | |
| 92 | 92 | $plugins = get_plugins($folder); |
| 93 | 93 | $current = get_site_transient('update_plugins'); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // it's possible that there is an update but an invalid site-license-key is in use |
| 102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
| 102 | + if (get_site_option('pue_json_error_'.$basename)) { |
|
| 103 | 103 | $update = true; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
| 27 | 27 | wp_enqueue_style( |
| 28 | 28 | 'ee_progress_steps_display_number_bubbles', |
| 29 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
| 29 | + plugin_dir_url(__FILE__).'number_bubbles.css' |
|
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -39,6 +39,6 @@ discard block |
||
| 39 | 39 | public function getTemplate() |
| 40 | 40 | { |
| 41 | 41 | // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
| 42 | - return __DIR__ . '/number_bubbles.template.php'; |
|
| 42 | + return __DIR__.'/number_bubbles.template.php'; |
|
| 43 | 43 | } |
| 44 | 44 | } |
@@ -14,29 +14,29 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class NumberBubblesProgressStepsDisplay implements ProgressStepsDisplayInterface |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * used for setting up css and js required for the display strategy |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - public function enqueueStylesAndScripts() |
|
| 23 | - { |
|
| 24 | - // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
| 25 | - wp_enqueue_style( |
|
| 26 | - 'ee_progress_steps_display_number_bubbles', |
|
| 27 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
| 28 | - ); |
|
| 29 | - } |
|
| 17 | + /** |
|
| 18 | + * used for setting up css and js required for the display strategy |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + public function enqueueStylesAndScripts() |
|
| 23 | + { |
|
| 24 | + // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
| 25 | + wp_enqueue_style( |
|
| 26 | + 'ee_progress_steps_display_number_bubbles', |
|
| 27 | + plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * loads and returns a full server path to the template used for the display strategy |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getTemplate() |
|
| 38 | - { |
|
| 39 | - // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
| 40 | - return __DIR__ . '/number_bubbles.template.php'; |
|
| 41 | - } |
|
| 32 | + /** |
|
| 33 | + * loads and returns a full server path to the template used for the display strategy |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getTemplate() |
|
| 38 | + { |
|
| 39 | + // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
| 40 | + return __DIR__ . '/number_bubbles.template.php'; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | // AND we are going to make sure they're in that specified order |
| 112 | 112 | $reordered_subsections = array(); |
| 113 | 113 | foreach ($options_array['include'] as $input_name) { |
| 114 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 114 | + if (isset($this->_subsections[$input_name])) { |
|
| 115 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | $this->_subsections = $reordered_subsections; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if (isset($options_array['layout_strategy'])) { |
| 125 | 125 | $this->_layout_strategy = $options_array['layout_strategy']; |
| 126 | 126 | } |
| 127 | - if (! $this->_layout_strategy) { |
|
| 127 | + if ( ! $this->_layout_strategy) { |
|
| 128 | 128 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
| 129 | 129 | } |
| 130 | 130 | $this->_layout_strategy->_construct_finalize($this); |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | if ($validate) { |
| 314 | 314 | $this->_validate(); |
| 315 | 315 | // if it's invalid, we're going to want to re-display so remember what they submitted |
| 316 | - if (! $this->is_valid()) { |
|
| 316 | + if ( ! $this->is_valid()) { |
|
| 317 | 317 | $this->store_submitted_form_data_in_session(); |
| 318 | 318 | } |
| 319 | 319 | } |
@@ -426,11 +426,11 @@ discard block |
||
| 426 | 426 | public function populate_defaults($default_data) |
| 427 | 427 | { |
| 428 | 428 | foreach ($this->subsections(false) as $subsection_name => $subsection) { |
| 429 | - if (isset($default_data[ $subsection_name ])) { |
|
| 429 | + if (isset($default_data[$subsection_name])) { |
|
| 430 | 430 | if ($subsection instanceof EE_Form_Input_Base) { |
| 431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 431 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 432 | 432 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 433 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | public function subsection_exists($name) |
| 447 | 447 | { |
| 448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 448 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | if ($require_construction_to_be_finalized) { |
| 468 | 468 | $this->ensure_construct_finalized_called(); |
| 469 | 469 | } |
| 470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 470 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $validatable_subsections = array(); |
| 483 | 483 | foreach ($this->subsections() as $name => $obj) { |
| 484 | 484 | if ($obj instanceof EE_Form_Section_Validatable) { |
| 485 | - $validatable_subsections[ $name ] = $obj; |
|
| 485 | + $validatable_subsections[$name] = $obj; |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | return $validatable_subsections; |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | $name, |
| 510 | 510 | $require_construction_to_be_finalized |
| 511 | 511 | ); |
| 512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 512 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 513 | 513 | throw new EE_Error( |
| 514 | 514 | sprintf( |
| 515 | 515 | esc_html__( |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | $name, |
| 547 | 547 | $require_construction_to_be_finalized |
| 548 | 548 | ); |
| 549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 549 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 550 | 550 | throw new EE_Error( |
| 551 | 551 | sprintf( |
| 552 | 552 | esc_html__( |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | public function is_valid() |
| 587 | 587 | { |
| 588 | 588 | if ($this->is_valid === null) { |
| 589 | - if (! $this->has_received_submission()) { |
|
| 589 | + if ( ! $this->has_received_submission()) { |
|
| 590 | 590 | throw new EE_Error( |
| 591 | 591 | sprintf( |
| 592 | 592 | esc_html__( |
@@ -596,14 +596,14 @@ discard block |
||
| 596 | 596 | ) |
| 597 | 597 | ); |
| 598 | 598 | } |
| 599 | - if (! parent::is_valid()) { |
|
| 599 | + if ( ! parent::is_valid()) { |
|
| 600 | 600 | $this->is_valid = false; |
| 601 | 601 | } else { |
| 602 | 602 | // ok so no general errors to this entire form section. |
| 603 | 603 | // so let's check the subsections, but only set errors if that hasn't been done yet |
| 604 | 604 | $this->is_valid = true; |
| 605 | 605 | foreach ($this->get_validatable_subsections() as $subsection) { |
| 606 | - if (! $subsection->is_valid()) { |
|
| 606 | + if ( ! $subsection->is_valid()) { |
|
| 607 | 607 | $this->is_valid = false; |
| 608 | 608 | } |
| 609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | */ |
| 621 | 621 | protected function _set_default_name_if_empty() |
| 622 | 622 | { |
| 623 | - if (! $this->_name) { |
|
| 623 | + if ( ! $this->_name) { |
|
| 624 | 624 | $classname = get_class($this); |
| 625 | 625 | $default_name = str_replace('EE_', '', $classname); |
| 626 | 626 | $this->_name = $default_name; |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | { |
| 711 | 711 | wp_register_script( |
| 712 | 712 | 'ee_form_section_validation', |
| 713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 713 | + EE_GLOBAL_ASSETS_URL.'scripts'.'/form_section_validation.js', |
|
| 714 | 714 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
| 715 | 715 | EVENT_ESPRESSO_VERSION, |
| 716 | 716 | true |
@@ -754,13 +754,13 @@ discard block |
||
| 754 | 754 | // we only want to localize vars ONCE for the entire form, |
| 755 | 755 | // so if the form section doesn't have a parent, then it must be the top dog |
| 756 | 756 | if ($return_for_subsection || ! $this->parent_section()) { |
| 757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 757 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 758 | 758 | 'form_section_id' => $this->html_id(true), |
| 759 | 759 | 'validation_rules' => $this->get_jquery_validation_rules(), |
| 760 | 760 | 'other_data' => $this->get_other_js_data(), |
| 761 | 761 | 'errors' => $this->subsection_validation_errors_by_html_name(), |
| 762 | 762 | ); |
| 763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | $inputs = array(); |
| 796 | 796 | foreach ($this->subsections() as $subsection) { |
| 797 | 797 | if ($subsection instanceof EE_Form_Input_Base) { |
| 798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 798 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 799 | 799 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 800 | 800 | $inputs += $subsection->inputs_in_subsections(); |
| 801 | 801 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | $errors = array(); |
| 819 | 819 | foreach ($inputs as $form_input) { |
| 820 | 820 | if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
| 821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 821 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | return $errors; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
| 842 | 842 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
| 843 | 843 | : 'wp_default'; |
| 844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 845 | 845 | wp_enqueue_script('ee_form_section_validation'); |
| 846 | 846 | wp_localize_script( |
| 847 | 847 | 'ee_form_section_validation', |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | public function ensure_scripts_localized() |
| 860 | 860 | { |
| 861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 861 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 862 | 862 | $this->_enqueue_and_localize_form_js(); |
| 863 | 863 | } |
| 864 | 864 | } |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | // reset the cache of whether this form is valid or not- we're re-validating it now |
| 955 | 955 | $this->is_valid = null; |
| 956 | 956 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 957 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 958 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 959 | 959 | } |
| 960 | 960 | $subsection->_validate(); |
| 961 | 961 | } |
@@ -973,9 +973,9 @@ discard block |
||
| 973 | 973 | $inputs = array(); |
| 974 | 974 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 975 | 975 | if ($subsection instanceof EE_Form_Section_Proper) { |
| 976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 976 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 977 | 977 | } elseif ($subsection instanceof EE_Form_Input_Base) { |
| 978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 978 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | return $inputs; |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | $inputs = array(); |
| 994 | 994 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 995 | 995 | if ($subsection instanceof EE_Form_Input_Base) { |
| 996 | - $inputs[ $subsection_name ] = $subsection; |
|
| 996 | + $inputs[$subsection_name] = $subsection; |
|
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | 999 | return $inputs; |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | $form_sections = array(); |
| 1012 | 1012 | foreach ($this->subsections() as $name => $obj) { |
| 1013 | 1013 | if ($obj instanceof EE_Form_Section_Proper) { |
| 1014 | - $form_sections[ $name ] = $obj; |
|
| 1014 | + $form_sections[$name] = $obj; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | return $form_sections; |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | $input_values = array(); |
| 1119 | 1119 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 1120 | 1120 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1121 | - $input_values[ $subsection_name ] = $pretty |
|
| 1121 | + $input_values[$subsection_name] = $pretty |
|
| 1122 | 1122 | ? $subsection->pretty_value() |
| 1123 | 1123 | : $subsection->normalized_value(); |
| 1124 | 1124 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | if ($flatten) { |
| 1131 | 1131 | $input_values = array_merge($input_values, $subform_input_values); |
| 1132 | 1132 | } else { |
| 1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1133 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | 1136 | } |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1159 | 1159 | // is this input part of an array of inputs? |
| 1160 | 1160 | if (strpos($subsection->html_name(), '[') !== false) { |
| 1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1162 | 1162 | explode( |
| 1163 | 1163 | '[', |
| 1164 | 1164 | str_replace(']', '', $subsection->html_name()) |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 1167 | ); |
| 1168 | 1168 | $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
| 1169 | 1169 | } else { |
| 1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1170 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
| 1173 | 1173 | $subform_input_values = $subsection->submitted_values($include_subforms); |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | public function exclude(array $inputs_to_exclude = array()) |
| 1203 | 1203 | { |
| 1204 | 1204 | foreach ($inputs_to_exclude as $input_to_exclude_name) { |
| 1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1205 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | } |
| 1208 | 1208 | |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
| 1246 | 1246 | { |
| 1247 | 1247 | foreach ($new_subsections as $subsection_name => $subsection) { |
| 1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1248 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1249 | 1249 | EE_Error::add_error( |
| 1250 | 1250 | sprintf( |
| 1251 | 1251 | esc_html__( |
@@ -1257,7 +1257,7 @@ discard block |
||
| 1257 | 1257 | $this->name() |
| 1258 | 1258 | ) |
| 1259 | 1259 | ); |
| 1260 | - unset($new_subsections[ $subsection_name ]); |
|
| 1260 | + unset($new_subsections[$subsection_name]); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | public function html_name_prefix() |
| 1373 | 1373 | { |
| 1374 | 1374 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
| 1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1375 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
| 1376 | 1376 | } |
| 1377 | 1377 | return $this->name(); |
| 1378 | 1378 | } |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | */ |
| 1413 | 1413 | public function ensure_construct_finalized_called() |
| 1414 | 1414 | { |
| 1415 | - if (! $this->_construction_finalized) { |
|
| 1415 | + if ( ! $this->_construction_finalized) { |
|
| 1416 | 1416 | $this->_construct_finalize($this->_parent_section, $this->_name); |
| 1417 | 1417 | } |
| 1418 | 1418 | } |
@@ -15,1532 +15,1532 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 17 | 17 | { |
| 18 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Subsections |
|
| 22 | - * |
|
| 23 | - * @var EE_Form_Section_Validatable[] |
|
| 24 | - */ |
|
| 25 | - protected $_subsections = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Strategy for laying out the form |
|
| 29 | - * |
|
| 30 | - * @var EE_Form_Section_Layout_Base |
|
| 31 | - */ |
|
| 32 | - protected $_layout_strategy; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Whether or not this form has received and validated a form submission yet |
|
| 36 | - * |
|
| 37 | - * @var boolean |
|
| 38 | - */ |
|
| 39 | - protected $_received_submission = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * message displayed to users upon successful form submission |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $_form_submission_success_message = ''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * message displayed to users upon unsuccessful form submission |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $_form_submission_error_message = ''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var array like post / request |
|
| 57 | - */ |
|
| 58 | - protected $cached_request_data; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | - * @var boolean|null |
|
| 64 | - */ |
|
| 65 | - protected $is_valid; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Stores all the data that will localized for form validation |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected static $_js_localization = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * whether or not the form's localized validation JS vars have been set |
|
| 76 | - * |
|
| 77 | - * @type boolean |
|
| 78 | - */ |
|
| 79 | - protected static $_scripts_localized = false; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | - * so that they know who their parent is, and what name they've been given. |
|
| 85 | - * |
|
| 86 | - * @param array[] $options_array { |
|
| 87 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | - * and in that order. This is handy if you want |
|
| 90 | - * the subsections to be ordered differently than the default, and if you override |
|
| 91 | - * which fields are shown |
|
| 92 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | - * items from that list of inclusions) |
|
| 96 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | - * @throws EE_Error |
|
| 99 | - */ |
|
| 100 | - public function __construct($options_array = array()) |
|
| 101 | - { |
|
| 102 | - $options_array = (array) apply_filters( |
|
| 103 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | - $options_array, |
|
| 105 | - $this |
|
| 106 | - ); |
|
| 107 | - // call parent first, as it may be setting the name |
|
| 108 | - parent::__construct($options_array); |
|
| 109 | - // if they've included subsections in the constructor, add them now |
|
| 110 | - if (isset($options_array['include'])) { |
|
| 111 | - // we are going to make sure we ONLY have those subsections to include |
|
| 112 | - // AND we are going to make sure they're in that specified order |
|
| 113 | - $reordered_subsections = array(); |
|
| 114 | - foreach ($options_array['include'] as $input_name) { |
|
| 115 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $this->_subsections = $reordered_subsections; |
|
| 120 | - } |
|
| 121 | - if (isset($options_array['exclude'])) { |
|
| 122 | - $exclude = $options_array['exclude']; |
|
| 123 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | - } |
|
| 125 | - if (isset($options_array['layout_strategy'])) { |
|
| 126 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | - } |
|
| 128 | - if (! $this->_layout_strategy) { |
|
| 129 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | - } |
|
| 131 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | - // ok so we are definitely going to want the forms JS, |
|
| 133 | - // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | - // ok so they've constructed this object after when they should have. |
|
| 136 | - // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | - } else { |
|
| 139 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | - } |
|
| 142 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | - /** |
|
| 144 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | - * The form probably doesn't yet have a parent form section. |
|
| 146 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | - * |
|
| 150 | - * @since 4.9.32 |
|
| 151 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | - * except maybe calling _construct_finalize has been done |
|
| 153 | - * @param array $options_array options passed into the constructor |
|
| 154 | - */ |
|
| 155 | - do_action( |
|
| 156 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | - $this, |
|
| 158 | - $options_array |
|
| 159 | - ); |
|
| 160 | - if (isset($options_array['name'])) { |
|
| 161 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Finishes construction given the parent form section and this form section's name |
|
| 168 | - * |
|
| 169 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 170 | - * @param string $name |
|
| 171 | - * @throws EE_Error |
|
| 172 | - */ |
|
| 173 | - public function _construct_finalize($parent_form_section, $name) |
|
| 174 | - { |
|
| 175 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | - $this->_set_default_name_if_empty(); |
|
| 177 | - $this->_set_default_html_id_if_empty(); |
|
| 178 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | - } else { |
|
| 182 | - throw new EE_Error( |
|
| 183 | - sprintf( |
|
| 184 | - esc_html__( |
|
| 185 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - $subsection_name, |
|
| 189 | - get_class($this), |
|
| 190 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - /** |
|
| 196 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | - * ensured it has a name, HTML IDs, etc |
|
| 202 | - * |
|
| 203 | - * @param EE_Form_Section_Proper $this |
|
| 204 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | - * @param string $name |
|
| 206 | - */ |
|
| 207 | - do_action( |
|
| 208 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | - $this, |
|
| 210 | - $parent_form_section, |
|
| 211 | - $name |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Gets the layout strategy for this form section |
|
| 218 | - * |
|
| 219 | - * @return EE_Form_Section_Layout_Base |
|
| 220 | - */ |
|
| 221 | - public function get_layout_strategy() |
|
| 222 | - { |
|
| 223 | - return $this->_layout_strategy; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Gets the HTML for a single input for this form section according |
|
| 229 | - * to the layout strategy |
|
| 230 | - * |
|
| 231 | - * @param EE_Form_Input_Base $input |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - public function get_html_for_input($input) |
|
| 235 | - { |
|
| 236 | - return $this->_layout_strategy->layout_input($input); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * was_submitted - checks if form inputs are present in request data |
|
| 242 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | - * proper form sections and form inputs) |
|
| 244 | - * |
|
| 245 | - * @param null $form_data |
|
| 246 | - * @return boolean |
|
| 247 | - * @throws EE_Error |
|
| 248 | - */ |
|
| 249 | - public function was_submitted($form_data = null) |
|
| 250 | - { |
|
| 251 | - return $this->form_data_present_in($form_data); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | - * something different, refresh the cache, and then return it |
|
| 257 | - * @param null $req_data |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - protected function getCachedRequest($req_data = null) |
|
| 261 | - { |
|
| 262 | - if ( |
|
| 263 | - $this->cached_request_data === null |
|
| 264 | - || ( |
|
| 265 | - $req_data !== null |
|
| 266 | - && $req_data !== $this->cached_request_data |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - $req_data = apply_filters( |
|
| 270 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | - $req_data, |
|
| 272 | - $this |
|
| 273 | - ); |
|
| 274 | - if ($req_data === null) { |
|
| 275 | - /** @var RequestInterface $request */ |
|
| 276 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | - $req_data = $request->requestParams(); |
|
| 278 | - } |
|
| 279 | - $req_data = apply_filters( |
|
| 280 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | - $req_data, |
|
| 282 | - $this |
|
| 283 | - ); |
|
| 284 | - $this->cached_request_data = (array) $req_data; |
|
| 285 | - } |
|
| 286 | - return $this->cached_request_data; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | - * |
|
| 294 | - * @param array|null $req_data should usually be post data (the default). |
|
| 295 | - * However, you CAN supply a different array. |
|
| 296 | - * Consider using set_defaults() instead however. |
|
| 297 | - * (If you rendered the form in the page using $form_x->get_html() |
|
| 298 | - * the inputs will have the correct name in the request data for this function |
|
| 299 | - * to find them and populate the form with them. |
|
| 300 | - * If you have a flat form (with only input subsections), |
|
| 301 | - * you can supply a flat array where keys |
|
| 302 | - * are the form input names and values are their values) |
|
| 303 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | - * But if the data has already been validated |
|
| 306 | - * (eg you validated the data then stored it in the DB) |
|
| 307 | - * you may want to skip this step. |
|
| 308 | - * @throws InvalidArgumentException |
|
| 309 | - * @throws InvalidInterfaceException |
|
| 310 | - * @throws InvalidDataTypeException |
|
| 311 | - * @throws EE_Error |
|
| 312 | - */ |
|
| 313 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | - { |
|
| 315 | - $req_data = $this->getCachedRequest($req_data); |
|
| 316 | - $this->_normalize($req_data); |
|
| 317 | - if ($validate) { |
|
| 318 | - $this->_validate(); |
|
| 319 | - // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | - if (! $this->is_valid()) { |
|
| 321 | - $this->store_submitted_form_data_in_session(); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | - $this->set_submission_error_message(); |
|
| 326 | - } |
|
| 327 | - do_action( |
|
| 328 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | - $req_data, |
|
| 330 | - $this, |
|
| 331 | - $validate |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * caches the originally submitted input values in the session |
|
| 338 | - * so that they can be used to repopulate the form if it failed validation |
|
| 339 | - * |
|
| 340 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidInterfaceException |
|
| 343 | - * @throws InvalidDataTypeException |
|
| 344 | - * @throws EE_Error |
|
| 345 | - */ |
|
| 346 | - protected function store_submitted_form_data_in_session() |
|
| 347 | - { |
|
| 348 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 349 | - array( |
|
| 350 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * retrieves the originally submitted input values in the session |
|
| 358 | - * so that they can be used to repopulate the form if it failed validation |
|
| 359 | - * |
|
| 360 | - * @return array |
|
| 361 | - * @throws InvalidArgumentException |
|
| 362 | - * @throws InvalidInterfaceException |
|
| 363 | - * @throws InvalidDataTypeException |
|
| 364 | - */ |
|
| 365 | - protected function get_submitted_form_data_from_session() |
|
| 366 | - { |
|
| 367 | - $session = EE_Registry::instance()->SSN; |
|
| 368 | - if ($session instanceof EE_Session) { |
|
| 369 | - return $session->get_session_data( |
|
| 370 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 371 | - ); |
|
| 372 | - } |
|
| 373 | - return array(); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * flushed the originally submitted input values from the session |
|
| 379 | - * |
|
| 380 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 381 | - * @throws InvalidArgumentException |
|
| 382 | - * @throws InvalidInterfaceException |
|
| 383 | - * @throws InvalidDataTypeException |
|
| 384 | - */ |
|
| 385 | - public static function flush_submitted_form_data_from_session() |
|
| 386 | - { |
|
| 387 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 388 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Populates this form and its subsections with data from the session. |
|
| 395 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 396 | - * validation errors when displaying too) |
|
| 397 | - * Returns true if the form was populated from the session, false otherwise |
|
| 398 | - * |
|
| 399 | - * @return boolean |
|
| 400 | - * @throws InvalidArgumentException |
|
| 401 | - * @throws InvalidInterfaceException |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws EE_Error |
|
| 404 | - */ |
|
| 405 | - public function populate_from_session() |
|
| 406 | - { |
|
| 407 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 408 | - if (empty($form_data_in_session)) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - $this->receive_form_submission($form_data_in_session); |
|
| 412 | - add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 413 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 414 | - return true; |
|
| 415 | - } |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Populates the default data for the form, given an array where keys are |
|
| 422 | - * the input names, and values are their values (preferably normalized to be their |
|
| 423 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 424 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 425 | - * the value being an array formatted in teh same way |
|
| 426 | - * |
|
| 427 | - * @param array $default_data |
|
| 428 | - * @throws EE_Error |
|
| 429 | - */ |
|
| 430 | - public function populate_defaults($default_data) |
|
| 431 | - { |
|
| 432 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 433 | - if (isset($default_data[ $subsection_name ])) { |
|
| 434 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 435 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 436 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 437 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * returns true if subsection exists |
|
| 446 | - * |
|
| 447 | - * @param string $name |
|
| 448 | - * @return boolean |
|
| 449 | - */ |
|
| 450 | - public function subsection_exists($name) |
|
| 451 | - { |
|
| 452 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Gets the subsection specified by its name |
|
| 458 | - * |
|
| 459 | - * @param string $name |
|
| 460 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 461 | - * so that the inputs will be properly configured. |
|
| 462 | - * However, some client code may be ok |
|
| 463 | - * with construction finalize being called later |
|
| 464 | - * (realizing that the subsections' html names |
|
| 465 | - * might not be set yet, etc.) |
|
| 466 | - * @return EE_Form_Section_Base |
|
| 467 | - * @throws EE_Error |
|
| 468 | - */ |
|
| 469 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 470 | - { |
|
| 471 | - if ($require_construction_to_be_finalized) { |
|
| 472 | - $this->ensure_construct_finalized_called(); |
|
| 473 | - } |
|
| 474 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Gets all the validatable subsections of this form section |
|
| 480 | - * |
|
| 481 | - * @return EE_Form_Section_Validatable[] |
|
| 482 | - * @throws EE_Error |
|
| 483 | - */ |
|
| 484 | - public function get_validatable_subsections() |
|
| 485 | - { |
|
| 486 | - $validatable_subsections = array(); |
|
| 487 | - foreach ($this->subsections() as $name => $obj) { |
|
| 488 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 489 | - $validatable_subsections[ $name ] = $obj; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - return $validatable_subsections; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 498 | - * throw an EE_Error. |
|
| 499 | - * |
|
| 500 | - * @param string $name |
|
| 501 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 502 | - * leave this as TRUE so that the inputs will be properly |
|
| 503 | - * configured. However, some client code may be ok with |
|
| 504 | - * construction finalize being called later |
|
| 505 | - * (realizing that the subsections' html names might not be |
|
| 506 | - * set yet, etc.) |
|
| 507 | - * @return EE_Form_Input_Base |
|
| 508 | - * @throws EE_Error |
|
| 509 | - */ |
|
| 510 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 511 | - { |
|
| 512 | - $subsection = $this->get_subsection( |
|
| 513 | - $name, |
|
| 514 | - $require_construction_to_be_finalized |
|
| 515 | - ); |
|
| 516 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 517 | - throw new EE_Error( |
|
| 518 | - sprintf( |
|
| 519 | - esc_html__( |
|
| 520 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 521 | - 'event_espresso' |
|
| 522 | - ), |
|
| 523 | - $name, |
|
| 524 | - get_class($this), |
|
| 525 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 526 | - ) |
|
| 527 | - ); |
|
| 528 | - } |
|
| 529 | - return $subsection; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 535 | - * otherwise throws an EE_Error |
|
| 536 | - * |
|
| 537 | - * @param string $name |
|
| 538 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 539 | - * leave this as TRUE so that the inputs will be properly |
|
| 540 | - * configured. However, some client code may be ok with |
|
| 541 | - * construction finalize being called later |
|
| 542 | - * (realizing that the subsections' html names might not be |
|
| 543 | - * set yet, etc.) |
|
| 544 | - * @return EE_Form_Section_Proper |
|
| 545 | - * @throws EE_Error |
|
| 546 | - */ |
|
| 547 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 548 | - { |
|
| 549 | - $subsection = $this->get_subsection( |
|
| 550 | - $name, |
|
| 551 | - $require_construction_to_be_finalized |
|
| 552 | - ); |
|
| 553 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 554 | - throw new EE_Error( |
|
| 555 | - sprintf( |
|
| 556 | - esc_html__( |
|
| 557 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 558 | - 'event_espresso' |
|
| 559 | - ), |
|
| 560 | - $name, |
|
| 561 | - get_class($this) |
|
| 562 | - ) |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - return $subsection; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 571 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 572 | - * |
|
| 573 | - * @param string $name |
|
| 574 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 575 | - * @throws EE_Error |
|
| 576 | - */ |
|
| 577 | - public function get_input_value($name) |
|
| 578 | - { |
|
| 579 | - $input = $this->get_input($name); |
|
| 580 | - return $input->normalized_value(); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 586 | - * |
|
| 587 | - * @throws EE_Error |
|
| 588 | - * @return boolean |
|
| 589 | - */ |
|
| 590 | - public function is_valid() |
|
| 591 | - { |
|
| 592 | - if ($this->is_valid === null) { |
|
| 593 | - if (! $this->has_received_submission()) { |
|
| 594 | - throw new EE_Error( |
|
| 595 | - sprintf( |
|
| 596 | - esc_html__( |
|
| 597 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 598 | - 'event_espresso' |
|
| 599 | - ) |
|
| 600 | - ) |
|
| 601 | - ); |
|
| 602 | - } |
|
| 603 | - if (! parent::is_valid()) { |
|
| 604 | - $this->is_valid = false; |
|
| 605 | - } else { |
|
| 606 | - // ok so no general errors to this entire form section. |
|
| 607 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 608 | - $this->is_valid = true; |
|
| 609 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 610 | - if (! $subsection->is_valid()) { |
|
| 611 | - $this->is_valid = false; |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - return $this->is_valid; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * gets the default name of this form section if none is specified |
|
| 622 | - * |
|
| 623 | - * @return void |
|
| 624 | - */ |
|
| 625 | - protected function _set_default_name_if_empty() |
|
| 626 | - { |
|
| 627 | - if (! $this->_name) { |
|
| 628 | - $classname = get_class($this); |
|
| 629 | - $default_name = str_replace('EE_', '', $classname); |
|
| 630 | - $this->_name = $default_name; |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 637 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 638 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 639 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 640 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 641 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 642 | - * any CSS. |
|
| 643 | - * |
|
| 644 | - * @throws InvalidArgumentException |
|
| 645 | - * @throws InvalidInterfaceException |
|
| 646 | - * @throws InvalidDataTypeException |
|
| 647 | - * @throws EE_Error |
|
| 648 | - */ |
|
| 649 | - public function get_html_and_js() |
|
| 650 | - { |
|
| 651 | - $this->enqueue_js(); |
|
| 652 | - return $this->get_html(); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 658 | - * |
|
| 659 | - * @param bool $display_previously_submitted_data |
|
| 660 | - * @return string |
|
| 661 | - * @throws InvalidArgumentException |
|
| 662 | - * @throws InvalidInterfaceException |
|
| 663 | - * @throws InvalidDataTypeException |
|
| 664 | - * @throws EE_Error |
|
| 665 | - * @throws EE_Error |
|
| 666 | - * @throws EE_Error |
|
| 667 | - */ |
|
| 668 | - public function get_html($display_previously_submitted_data = true) |
|
| 669 | - { |
|
| 670 | - $this->ensure_construct_finalized_called(); |
|
| 671 | - if ($display_previously_submitted_data) { |
|
| 672 | - $this->populate_from_session(); |
|
| 673 | - } |
|
| 674 | - return $this->_form_html_filter |
|
| 675 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 676 | - : $this->_layout_strategy->layout_form(); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * enqueues JS and CSS for the form. |
|
| 682 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 683 | - * scripts and styles can be put in the header, but if called later |
|
| 684 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 685 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 686 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 687 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 688 | - * |
|
| 689 | - * @return void |
|
| 690 | - * @throws EE_Error |
|
| 691 | - */ |
|
| 692 | - public function enqueue_js() |
|
| 693 | - { |
|
| 694 | - $this->_enqueue_and_localize_form_js(); |
|
| 695 | - foreach ($this->subsections() as $subsection) { |
|
| 696 | - $subsection->enqueue_js(); |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 703 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 704 | - * the wp_enqueue_scripts hook. |
|
| 705 | - * However, registering the form js and localizing it can happen when we |
|
| 706 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 707 | - * could change until it's actually outputted) |
|
| 708 | - * |
|
| 709 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 710 | - * to be triggered automatically or not |
|
| 711 | - * @return void |
|
| 712 | - */ |
|
| 713 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 714 | - { |
|
| 715 | - wp_register_script( |
|
| 716 | - 'ee_form_section_validation', |
|
| 717 | - EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 718 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 719 | - EVENT_ESPRESSO_VERSION, |
|
| 720 | - true |
|
| 721 | - ); |
|
| 722 | - wp_localize_script( |
|
| 723 | - 'ee_form_section_validation', |
|
| 724 | - 'ee_form_section_validation_init', |
|
| 725 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 726 | - ); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * gets the variables used by form_section_validation.js. |
|
| 732 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 733 | - * but before the wordpress hook wp_loaded |
|
| 734 | - * |
|
| 735 | - * @throws EE_Error |
|
| 736 | - */ |
|
| 737 | - public function _enqueue_and_localize_form_js() |
|
| 738 | - { |
|
| 739 | - $this->ensure_construct_finalized_called(); |
|
| 740 | - // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 741 | - // so we need to add our form section data to a static variable accessible by all form sections |
|
| 742 | - // and localize it just before the footer |
|
| 743 | - $this->localize_validation_rules(); |
|
| 744 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 745 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * add our form section data to a static variable accessible by all form sections |
|
| 751 | - * |
|
| 752 | - * @param bool $return_for_subsection |
|
| 753 | - * @return void |
|
| 754 | - * @throws EE_Error |
|
| 755 | - */ |
|
| 756 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 757 | - { |
|
| 758 | - // we only want to localize vars ONCE for the entire form, |
|
| 759 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 760 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 761 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 762 | - 'form_section_id' => $this->html_id(true), |
|
| 763 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 764 | - 'other_data' => $this->get_other_js_data(), |
|
| 765 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 766 | - ); |
|
| 767 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 774 | - * This is primarily data added by inputs and forms in addition to any |
|
| 775 | - * scripts they might enqueue |
|
| 776 | - * |
|
| 777 | - * @param array $form_other_js_data |
|
| 778 | - * @return array |
|
| 779 | - * @throws EE_Error |
|
| 780 | - */ |
|
| 781 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 782 | - { |
|
| 783 | - foreach ($this->subsections() as $subsection) { |
|
| 784 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 785 | - } |
|
| 786 | - return $form_other_js_data; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 792 | - * Keys are their form names, and values are the inputs themselves |
|
| 793 | - * |
|
| 794 | - * @return EE_Form_Input_Base |
|
| 795 | - * @throws EE_Error |
|
| 796 | - */ |
|
| 797 | - public function inputs_in_subsections() |
|
| 798 | - { |
|
| 799 | - $inputs = array(); |
|
| 800 | - foreach ($this->subsections() as $subsection) { |
|
| 801 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 802 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 803 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 804 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - return $inputs; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Gets a flat array of all the validation errors. |
|
| 813 | - * Keys are html names (because those should be unique) |
|
| 814 | - * and values are a string of all their validation errors |
|
| 815 | - * |
|
| 816 | - * @return string[] |
|
| 817 | - * @throws EE_Error |
|
| 818 | - */ |
|
| 819 | - public function subsection_validation_errors_by_html_name() |
|
| 820 | - { |
|
| 821 | - $inputs = $this->inputs(); |
|
| 822 | - $errors = array(); |
|
| 823 | - foreach ($inputs as $form_input) { |
|
| 824 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 825 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - return $errors; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 834 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 835 | - * |
|
| 836 | - * @throws InvalidArgumentException |
|
| 837 | - * @throws InvalidInterfaceException |
|
| 838 | - * @throws InvalidDataTypeException |
|
| 839 | - */ |
|
| 840 | - public static function localize_script_for_all_forms() |
|
| 841 | - { |
|
| 842 | - // allow inputs and stuff to hook in their JS and stuff here |
|
| 843 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 844 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 845 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 846 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 847 | - : 'wp_default'; |
|
| 848 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 849 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 850 | - wp_localize_script( |
|
| 851 | - 'ee_form_section_validation', |
|
| 852 | - 'ee_form_section_vars', |
|
| 853 | - EE_Form_Section_Proper::$_js_localization |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * ensure_scripts_localized |
|
| 860 | - * |
|
| 861 | - * @throws EE_Error |
|
| 862 | - */ |
|
| 863 | - public function ensure_scripts_localized() |
|
| 864 | - { |
|
| 865 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 866 | - $this->_enqueue_and_localize_form_js(); |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 873 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 874 | - * |
|
| 875 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 876 | - */ |
|
| 877 | - private static function _get_localized_error_messages() |
|
| 878 | - { |
|
| 879 | - return array( |
|
| 880 | - 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 881 | - 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * @return array |
|
| 888 | - */ |
|
| 889 | - public static function js_localization() |
|
| 890 | - { |
|
| 891 | - return self::$_js_localization; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public static function reset_js_localization() |
|
| 899 | - { |
|
| 900 | - self::$_js_localization = array(); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 906 | - * See parent function for more... |
|
| 907 | - * |
|
| 908 | - * @return array |
|
| 909 | - * @throws EE_Error |
|
| 910 | - */ |
|
| 911 | - public function get_jquery_validation_rules() |
|
| 912 | - { |
|
| 913 | - $jquery_validation_rules = array(); |
|
| 914 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 915 | - $jquery_validation_rules = array_merge( |
|
| 916 | - $jquery_validation_rules, |
|
| 917 | - $subsection->get_jquery_validation_rules() |
|
| 918 | - ); |
|
| 919 | - } |
|
| 920 | - return $jquery_validation_rules; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - |
|
| 924 | - /** |
|
| 925 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 926 | - * |
|
| 927 | - * @param array $req_data |
|
| 928 | - * @return void |
|
| 929 | - * @throws EE_Error |
|
| 930 | - */ |
|
| 931 | - protected function _normalize($req_data) |
|
| 932 | - { |
|
| 933 | - $this->_received_submission = true; |
|
| 934 | - $this->_validation_errors = array(); |
|
| 935 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 936 | - try { |
|
| 937 | - $subsection->_normalize($req_data); |
|
| 938 | - } catch (EE_Validation_Error $e) { |
|
| 939 | - $subsection->add_validation_error($e); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * Performs validation on this form section and its subsections. |
|
| 947 | - * For each subsection, |
|
| 948 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 949 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 950 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 951 | - * you would be best to override this _validate method, |
|
| 952 | - * calling parent::_validate() first. |
|
| 953 | - * |
|
| 954 | - * @throws EE_Error |
|
| 955 | - */ |
|
| 956 | - protected function _validate() |
|
| 957 | - { |
|
| 958 | - // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 959 | - $this->is_valid = null; |
|
| 960 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 961 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 962 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 963 | - } |
|
| 964 | - $subsection->_validate(); |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * Gets all the validated inputs for the form section |
|
| 971 | - * |
|
| 972 | - * @return array |
|
| 973 | - * @throws EE_Error |
|
| 974 | - */ |
|
| 975 | - public function valid_data() |
|
| 976 | - { |
|
| 977 | - $inputs = array(); |
|
| 978 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 979 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 980 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 981 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 982 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - return $inputs; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Gets all the inputs on this form section |
|
| 991 | - * |
|
| 992 | - * @return EE_Form_Input_Base[] |
|
| 993 | - * @throws EE_Error |
|
| 994 | - */ |
|
| 995 | - public function inputs() |
|
| 996 | - { |
|
| 997 | - $inputs = array(); |
|
| 998 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 999 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1000 | - $inputs[ $subsection_name ] = $subsection; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - return $inputs; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * Gets all the subsections which are a proper form |
|
| 1009 | - * |
|
| 1010 | - * @return EE_Form_Section_Proper[] |
|
| 1011 | - * @throws EE_Error |
|
| 1012 | - */ |
|
| 1013 | - public function subforms() |
|
| 1014 | - { |
|
| 1015 | - $form_sections = array(); |
|
| 1016 | - foreach ($this->subsections() as $name => $obj) { |
|
| 1017 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1018 | - $form_sections[ $name ] = $obj; |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - return $form_sections; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1027 | - * Consider using inputs() or subforms() |
|
| 1028 | - * if you only want form inputs or proper form sections. |
|
| 1029 | - * |
|
| 1030 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1031 | - * leave this as TRUE so that the inputs will be properly |
|
| 1032 | - * configured. However, some client code may be ok with |
|
| 1033 | - * construction finalize being called later |
|
| 1034 | - * (realizing that the subsections' html names might not be |
|
| 1035 | - * set yet, etc.) |
|
| 1036 | - * @return EE_Form_Section_Proper[] |
|
| 1037 | - * @throws EE_Error |
|
| 1038 | - */ |
|
| 1039 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 1040 | - { |
|
| 1041 | - if ($require_construction_to_be_finalized) { |
|
| 1042 | - $this->ensure_construct_finalized_called(); |
|
| 1043 | - } |
|
| 1044 | - return $this->_subsections; |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * Returns whether this form has any subforms or inputs |
|
| 1050 | - * @return bool |
|
| 1051 | - */ |
|
| 1052 | - public function hasSubsections() |
|
| 1053 | - { |
|
| 1054 | - return ! empty($this->_subsections); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 1060 | - * values. (Similar to calling get_input_value on inputs) |
|
| 1061 | - * |
|
| 1062 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1063 | - * or just this forms' direct children inputs |
|
| 1064 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1065 | - * or allow multidimensional array |
|
| 1066 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1067 | - * with array keys being input names |
|
| 1068 | - * (regardless of whether they are from a subsection or not), |
|
| 1069 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1070 | - * where keys are always subsection names and values are either |
|
| 1071 | - * the input's normalized value, or an array like the top-level array |
|
| 1072 | - * @throws EE_Error |
|
| 1073 | - */ |
|
| 1074 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1075 | - { |
|
| 1076 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1082 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1083 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 1084 | - * where keys are the input names, and values are their display values |
|
| 1085 | - * |
|
| 1086 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1087 | - * or just this forms' direct children inputs |
|
| 1088 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1089 | - * or allow multidimensional array |
|
| 1090 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1091 | - * with array keys being input names |
|
| 1092 | - * (regardless of whether they are from a subsection or not), |
|
| 1093 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1094 | - * where keys are always subsection names and values are either |
|
| 1095 | - * the input's normalized value, or an array like the top-level array |
|
| 1096 | - * @throws EE_Error |
|
| 1097 | - */ |
|
| 1098 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1099 | - { |
|
| 1100 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Gets the input values from the form |
|
| 1106 | - * |
|
| 1107 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1108 | - * or just the normalized value |
|
| 1109 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1110 | - * or just this forms' direct children inputs |
|
| 1111 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1112 | - * or allow multidimensional array |
|
| 1113 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1114 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1115 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1116 | - * where keys are always subsection names and values are either |
|
| 1117 | - * the input's normalized value, or an array like the top-level array |
|
| 1118 | - * @throws EE_Error |
|
| 1119 | - */ |
|
| 1120 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1121 | - { |
|
| 1122 | - $input_values = array(); |
|
| 1123 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1124 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1125 | - $input_values[ $subsection_name ] = $pretty |
|
| 1126 | - ? $subsection->pretty_value() |
|
| 1127 | - : $subsection->normalized_value(); |
|
| 1128 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1129 | - $subform_input_values = $subsection->_input_values( |
|
| 1130 | - $pretty, |
|
| 1131 | - $include_subform_inputs, |
|
| 1132 | - $flatten |
|
| 1133 | - ); |
|
| 1134 | - if ($flatten) { |
|
| 1135 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1136 | - } else { |
|
| 1137 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - return $input_values; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - /** |
|
| 1146 | - * Gets the originally submitted input values from the form |
|
| 1147 | - * |
|
| 1148 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1149 | - * or just this forms' direct children inputs |
|
| 1150 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1151 | - * with array keys being input names |
|
| 1152 | - * (regardless of whether they are from a subsection or not), |
|
| 1153 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1154 | - * where keys are always subsection names and values are either |
|
| 1155 | - * the input's normalized value, or an array like the top-level array |
|
| 1156 | - * @throws EE_Error |
|
| 1157 | - */ |
|
| 1158 | - public function submitted_values($include_subforms = false) |
|
| 1159 | - { |
|
| 1160 | - $submitted_values = array(); |
|
| 1161 | - foreach ($this->subsections() as $subsection) { |
|
| 1162 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1163 | - // is this input part of an array of inputs? |
|
| 1164 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1165 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1166 | - explode( |
|
| 1167 | - '[', |
|
| 1168 | - str_replace(']', '', $subsection->html_name()) |
|
| 1169 | - ), |
|
| 1170 | - $subsection->raw_value() |
|
| 1171 | - ); |
|
| 1172 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1173 | - } else { |
|
| 1174 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1175 | - } |
|
| 1176 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1177 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1178 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1179 | - } |
|
| 1180 | - } |
|
| 1181 | - return $submitted_values; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * Indicates whether or not this form has received a submission yet |
|
| 1187 | - * (ie, had receive_form_submission called on it yet) |
|
| 1188 | - * |
|
| 1189 | - * @return boolean |
|
| 1190 | - * @throws EE_Error |
|
| 1191 | - */ |
|
| 1192 | - public function has_received_submission() |
|
| 1193 | - { |
|
| 1194 | - $this->ensure_construct_finalized_called(); |
|
| 1195 | - return $this->_received_submission; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - |
|
| 1199 | - /** |
|
| 1200 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1201 | - * Removes the listed inputs from the form |
|
| 1202 | - * |
|
| 1203 | - * @param array $inputs_to_exclude values are the input names |
|
| 1204 | - * @return void |
|
| 1205 | - */ |
|
| 1206 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1207 | - { |
|
| 1208 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1209 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1216 | - * @param array $inputs_to_hide |
|
| 1217 | - * @throws EE_Error |
|
| 1218 | - */ |
|
| 1219 | - public function hide(array $inputs_to_hide = array()) |
|
| 1220 | - { |
|
| 1221 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1222 | - $input = $this->get_input($input_to_hide); |
|
| 1223 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - /** |
|
| 1229 | - * add_subsections |
|
| 1230 | - * Adds the listed subsections to the form section. |
|
| 1231 | - * If $subsection_name_to_target is provided, |
|
| 1232 | - * then new subsections are added before or after that subsection, |
|
| 1233 | - * otherwise to the start or end of the entire subsections array. |
|
| 1234 | - * |
|
| 1235 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1236 | - * where keys are their names |
|
| 1237 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1238 | - * should be added before or after |
|
| 1239 | - * IF $subsection_name_to_target is null, |
|
| 1240 | - * then $new_subsections will be added to |
|
| 1241 | - * the beginning or end of the entire subsections array |
|
| 1242 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1243 | - * $subsection_name_to_target, |
|
| 1244 | - * or if $subsection_name_to_target is null, |
|
| 1245 | - * before or after entire subsections array |
|
| 1246 | - * @return void |
|
| 1247 | - * @throws EE_Error |
|
| 1248 | - */ |
|
| 1249 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1250 | - { |
|
| 1251 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1252 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1253 | - EE_Error::add_error( |
|
| 1254 | - sprintf( |
|
| 1255 | - esc_html__( |
|
| 1256 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1257 | - 'event_espresso' |
|
| 1258 | - ), |
|
| 1259 | - get_class($subsection), |
|
| 1260 | - $subsection_name, |
|
| 1261 | - $this->name() |
|
| 1262 | - ) |
|
| 1263 | - ); |
|
| 1264 | - unset($new_subsections[ $subsection_name ]); |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1268 | - $this->_subsections, |
|
| 1269 | - $new_subsections, |
|
| 1270 | - $subsection_name_to_target, |
|
| 1271 | - $add_before |
|
| 1272 | - ); |
|
| 1273 | - if ($this->_construction_finalized) { |
|
| 1274 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1275 | - $subsection->_construct_finalize($this, $name); |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * @param string $subsection_name |
|
| 1283 | - * @param bool $recursive |
|
| 1284 | - * @return bool |
|
| 1285 | - */ |
|
| 1286 | - public function has_subsection($subsection_name, $recursive = false) |
|
| 1287 | - { |
|
| 1288 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1289 | - if ( |
|
| 1290 | - $name === $subsection_name |
|
| 1291 | - || ( |
|
| 1292 | - $recursive |
|
| 1293 | - && $subsection instanceof EE_Form_Section_Proper |
|
| 1294 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1295 | - ) |
|
| 1296 | - ) { |
|
| 1297 | - return true; |
|
| 1298 | - } |
|
| 1299 | - } |
|
| 1300 | - return false; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1307 | - * |
|
| 1308 | - * @throws EE_Error |
|
| 1309 | - */ |
|
| 1310 | - public function clean_sensitive_data() |
|
| 1311 | - { |
|
| 1312 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1313 | - $subsection->clean_sensitive_data(); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1320 | - * @param string $form_submission_error_message |
|
| 1321 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 1322 | - * @throws EE_Error |
|
| 1323 | - */ |
|
| 1324 | - public function set_submission_error_message( |
|
| 1325 | - $form_submission_error_message = '' |
|
| 1326 | - ) { |
|
| 1327 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1328 | - ? $form_submission_error_message |
|
| 1329 | - : $this->getAllValidationErrorsString(); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - |
|
| 1333 | - /** |
|
| 1334 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1335 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 1336 | - * set_submission_error_message |
|
| 1337 | - * |
|
| 1338 | - * @return string |
|
| 1339 | - */ |
|
| 1340 | - public function submission_error_message() |
|
| 1341 | - { |
|
| 1342 | - return $this->_form_submission_error_message; |
|
| 1343 | - } |
|
| 1344 | - |
|
| 1345 | - |
|
| 1346 | - /** |
|
| 1347 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 1348 | - * @param string $form_submission_success_message |
|
| 1349 | - */ |
|
| 1350 | - public function set_submission_success_message($form_submission_success_message = '') |
|
| 1351 | - { |
|
| 1352 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1353 | - ? $form_submission_success_message |
|
| 1354 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - /** |
|
| 1359 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 1360 | - * @return string |
|
| 1361 | - */ |
|
| 1362 | - public function submission_success_message() |
|
| 1363 | - { |
|
| 1364 | - return $this->_form_submission_success_message; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Returns the prefix that should be used on child of this form section for |
|
| 1370 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1371 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1372 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1373 | - * |
|
| 1374 | - * @return string |
|
| 1375 | - * @throws EE_Error |
|
| 1376 | - */ |
|
| 1377 | - public function html_name_prefix() |
|
| 1378 | - { |
|
| 1379 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1380 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1381 | - } |
|
| 1382 | - return $this->name(); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - |
|
| 1386 | - /** |
|
| 1387 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1388 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1389 | - * was set, which is probably nothing, or the classname) |
|
| 1390 | - * |
|
| 1391 | - * @return string |
|
| 1392 | - * @throws EE_Error |
|
| 1393 | - */ |
|
| 1394 | - public function name() |
|
| 1395 | - { |
|
| 1396 | - $this->ensure_construct_finalized_called(); |
|
| 1397 | - return parent::name(); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * @return EE_Form_Section_Proper |
|
| 1403 | - * @throws EE_Error |
|
| 1404 | - */ |
|
| 1405 | - public function parent_section() |
|
| 1406 | - { |
|
| 1407 | - $this->ensure_construct_finalized_called(); |
|
| 1408 | - return parent::parent_section(); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1414 | - * |
|
| 1415 | - * @return void |
|
| 1416 | - * @throws EE_Error |
|
| 1417 | - */ |
|
| 1418 | - public function ensure_construct_finalized_called() |
|
| 1419 | - { |
|
| 1420 | - if (! $this->_construction_finalized) { |
|
| 1421 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1428 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1429 | - * |
|
| 1430 | - * @param array $req_data |
|
| 1431 | - * @return boolean |
|
| 1432 | - * @throws EE_Error |
|
| 1433 | - */ |
|
| 1434 | - public function form_data_present_in($req_data = null) |
|
| 1435 | - { |
|
| 1436 | - $req_data = $this->getCachedRequest($req_data); |
|
| 1437 | - foreach ($this->subsections() as $subsection) { |
|
| 1438 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1439 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1440 | - return true; |
|
| 1441 | - } |
|
| 1442 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1443 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1444 | - return true; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - return false; |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - |
|
| 1452 | - /** |
|
| 1453 | - * Gets validation errors for this form section and subsections |
|
| 1454 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1455 | - * gets the validation errors for ALL subsection |
|
| 1456 | - * |
|
| 1457 | - * @return EE_Validation_Error[] |
|
| 1458 | - * @throws EE_Error |
|
| 1459 | - */ |
|
| 1460 | - public function get_validation_errors_accumulated() |
|
| 1461 | - { |
|
| 1462 | - $validation_errors = $this->get_validation_errors(); |
|
| 1463 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1464 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1465 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1466 | - } else { |
|
| 1467 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1468 | - } |
|
| 1469 | - if ($validation_errors_on_this_subsection) { |
|
| 1470 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - return $validation_errors; |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1478 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1479 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1480 | - * |
|
| 1481 | - * @return string |
|
| 1482 | - * @since 4.9.59.p |
|
| 1483 | - */ |
|
| 1484 | - protected function getAllValidationErrorsString() |
|
| 1485 | - { |
|
| 1486 | - $submission_error_messages = array(); |
|
| 1487 | - // bad, bad, bad registrant |
|
| 1488 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1489 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1490 | - $form_section = $validation_error->get_form_section(); |
|
| 1491 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1492 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1493 | - } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1494 | - $label = $validation_error->get_form_section()->name(); |
|
| 1495 | - } else { |
|
| 1496 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1497 | - } |
|
| 1498 | - $submission_error_messages[] = sprintf( |
|
| 1499 | - esc_html__('%s : %s', 'event_espresso'), |
|
| 1500 | - $label, |
|
| 1501 | - $validation_error->getMessage() |
|
| 1502 | - ); |
|
| 1503 | - } |
|
| 1504 | - } |
|
| 1505 | - return implode('<br>', $submission_error_messages); |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - |
|
| 1509 | - /** |
|
| 1510 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1511 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1512 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1513 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1514 | - * which will be returned. |
|
| 1515 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1516 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1517 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1518 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1519 | - * Etc |
|
| 1520 | - * |
|
| 1521 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1522 | - * @return EE_Form_Section_Base |
|
| 1523 | - * @throws EE_Error |
|
| 1524 | - */ |
|
| 1525 | - public function find_section_from_path($form_section_path) |
|
| 1526 | - { |
|
| 1527 | - // check if we can find the input from purely going straight up the tree |
|
| 1528 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1529 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1530 | - return $input; |
|
| 1531 | - } |
|
| 1532 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1533 | - if ($next_slash_pos !== false) { |
|
| 1534 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1535 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1536 | - } else { |
|
| 1537 | - $child_section_name = $form_section_path; |
|
| 1538 | - $subpath = ''; |
|
| 1539 | - } |
|
| 1540 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1541 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1542 | - return $child_section->find_section_from_path($subpath); |
|
| 1543 | - } |
|
| 1544 | - return null; |
|
| 1545 | - } |
|
| 18 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Subsections |
|
| 22 | + * |
|
| 23 | + * @var EE_Form_Section_Validatable[] |
|
| 24 | + */ |
|
| 25 | + protected $_subsections = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Strategy for laying out the form |
|
| 29 | + * |
|
| 30 | + * @var EE_Form_Section_Layout_Base |
|
| 31 | + */ |
|
| 32 | + protected $_layout_strategy; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Whether or not this form has received and validated a form submission yet |
|
| 36 | + * |
|
| 37 | + * @var boolean |
|
| 38 | + */ |
|
| 39 | + protected $_received_submission = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * message displayed to users upon successful form submission |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $_form_submission_success_message = ''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * message displayed to users upon unsuccessful form submission |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $_form_submission_error_message = ''; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var array like post / request |
|
| 57 | + */ |
|
| 58 | + protected $cached_request_data; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | + * @var boolean|null |
|
| 64 | + */ |
|
| 65 | + protected $is_valid; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Stores all the data that will localized for form validation |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected static $_js_localization = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * whether or not the form's localized validation JS vars have been set |
|
| 76 | + * |
|
| 77 | + * @type boolean |
|
| 78 | + */ |
|
| 79 | + protected static $_scripts_localized = false; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | + * so that they know who their parent is, and what name they've been given. |
|
| 85 | + * |
|
| 86 | + * @param array[] $options_array { |
|
| 87 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | + * and in that order. This is handy if you want |
|
| 90 | + * the subsections to be ordered differently than the default, and if you override |
|
| 91 | + * which fields are shown |
|
| 92 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | + * items from that list of inclusions) |
|
| 96 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | + * @throws EE_Error |
|
| 99 | + */ |
|
| 100 | + public function __construct($options_array = array()) |
|
| 101 | + { |
|
| 102 | + $options_array = (array) apply_filters( |
|
| 103 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | + $options_array, |
|
| 105 | + $this |
|
| 106 | + ); |
|
| 107 | + // call parent first, as it may be setting the name |
|
| 108 | + parent::__construct($options_array); |
|
| 109 | + // if they've included subsections in the constructor, add them now |
|
| 110 | + if (isset($options_array['include'])) { |
|
| 111 | + // we are going to make sure we ONLY have those subsections to include |
|
| 112 | + // AND we are going to make sure they're in that specified order |
|
| 113 | + $reordered_subsections = array(); |
|
| 114 | + foreach ($options_array['include'] as $input_name) { |
|
| 115 | + if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $this->_subsections = $reordered_subsections; |
|
| 120 | + } |
|
| 121 | + if (isset($options_array['exclude'])) { |
|
| 122 | + $exclude = $options_array['exclude']; |
|
| 123 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | + } |
|
| 125 | + if (isset($options_array['layout_strategy'])) { |
|
| 126 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | + } |
|
| 128 | + if (! $this->_layout_strategy) { |
|
| 129 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | + } |
|
| 131 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | + // ok so we are definitely going to want the forms JS, |
|
| 133 | + // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | + // ok so they've constructed this object after when they should have. |
|
| 136 | + // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | + } else { |
|
| 139 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | + } |
|
| 142 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | + /** |
|
| 144 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | + * The form probably doesn't yet have a parent form section. |
|
| 146 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | + * |
|
| 150 | + * @since 4.9.32 |
|
| 151 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | + * except maybe calling _construct_finalize has been done |
|
| 153 | + * @param array $options_array options passed into the constructor |
|
| 154 | + */ |
|
| 155 | + do_action( |
|
| 156 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | + $this, |
|
| 158 | + $options_array |
|
| 159 | + ); |
|
| 160 | + if (isset($options_array['name'])) { |
|
| 161 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Finishes construction given the parent form section and this form section's name |
|
| 168 | + * |
|
| 169 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 170 | + * @param string $name |
|
| 171 | + * @throws EE_Error |
|
| 172 | + */ |
|
| 173 | + public function _construct_finalize($parent_form_section, $name) |
|
| 174 | + { |
|
| 175 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | + $this->_set_default_name_if_empty(); |
|
| 177 | + $this->_set_default_html_id_if_empty(); |
|
| 178 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | + } else { |
|
| 182 | + throw new EE_Error( |
|
| 183 | + sprintf( |
|
| 184 | + esc_html__( |
|
| 185 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + $subsection_name, |
|
| 189 | + get_class($this), |
|
| 190 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + /** |
|
| 196 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | + * ensured it has a name, HTML IDs, etc |
|
| 202 | + * |
|
| 203 | + * @param EE_Form_Section_Proper $this |
|
| 204 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | + * @param string $name |
|
| 206 | + */ |
|
| 207 | + do_action( |
|
| 208 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | + $this, |
|
| 210 | + $parent_form_section, |
|
| 211 | + $name |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Gets the layout strategy for this form section |
|
| 218 | + * |
|
| 219 | + * @return EE_Form_Section_Layout_Base |
|
| 220 | + */ |
|
| 221 | + public function get_layout_strategy() |
|
| 222 | + { |
|
| 223 | + return $this->_layout_strategy; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Gets the HTML for a single input for this form section according |
|
| 229 | + * to the layout strategy |
|
| 230 | + * |
|
| 231 | + * @param EE_Form_Input_Base $input |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public function get_html_for_input($input) |
|
| 235 | + { |
|
| 236 | + return $this->_layout_strategy->layout_input($input); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * was_submitted - checks if form inputs are present in request data |
|
| 242 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | + * proper form sections and form inputs) |
|
| 244 | + * |
|
| 245 | + * @param null $form_data |
|
| 246 | + * @return boolean |
|
| 247 | + * @throws EE_Error |
|
| 248 | + */ |
|
| 249 | + public function was_submitted($form_data = null) |
|
| 250 | + { |
|
| 251 | + return $this->form_data_present_in($form_data); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | + * something different, refresh the cache, and then return it |
|
| 257 | + * @param null $req_data |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + protected function getCachedRequest($req_data = null) |
|
| 261 | + { |
|
| 262 | + if ( |
|
| 263 | + $this->cached_request_data === null |
|
| 264 | + || ( |
|
| 265 | + $req_data !== null |
|
| 266 | + && $req_data !== $this->cached_request_data |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + $req_data = apply_filters( |
|
| 270 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | + $req_data, |
|
| 272 | + $this |
|
| 273 | + ); |
|
| 274 | + if ($req_data === null) { |
|
| 275 | + /** @var RequestInterface $request */ |
|
| 276 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | + $req_data = $request->requestParams(); |
|
| 278 | + } |
|
| 279 | + $req_data = apply_filters( |
|
| 280 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | + $req_data, |
|
| 282 | + $this |
|
| 283 | + ); |
|
| 284 | + $this->cached_request_data = (array) $req_data; |
|
| 285 | + } |
|
| 286 | + return $this->cached_request_data; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | + * |
|
| 294 | + * @param array|null $req_data should usually be post data (the default). |
|
| 295 | + * However, you CAN supply a different array. |
|
| 296 | + * Consider using set_defaults() instead however. |
|
| 297 | + * (If you rendered the form in the page using $form_x->get_html() |
|
| 298 | + * the inputs will have the correct name in the request data for this function |
|
| 299 | + * to find them and populate the form with them. |
|
| 300 | + * If you have a flat form (with only input subsections), |
|
| 301 | + * you can supply a flat array where keys |
|
| 302 | + * are the form input names and values are their values) |
|
| 303 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | + * But if the data has already been validated |
|
| 306 | + * (eg you validated the data then stored it in the DB) |
|
| 307 | + * you may want to skip this step. |
|
| 308 | + * @throws InvalidArgumentException |
|
| 309 | + * @throws InvalidInterfaceException |
|
| 310 | + * @throws InvalidDataTypeException |
|
| 311 | + * @throws EE_Error |
|
| 312 | + */ |
|
| 313 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | + { |
|
| 315 | + $req_data = $this->getCachedRequest($req_data); |
|
| 316 | + $this->_normalize($req_data); |
|
| 317 | + if ($validate) { |
|
| 318 | + $this->_validate(); |
|
| 319 | + // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | + if (! $this->is_valid()) { |
|
| 321 | + $this->store_submitted_form_data_in_session(); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | + $this->set_submission_error_message(); |
|
| 326 | + } |
|
| 327 | + do_action( |
|
| 328 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | + $req_data, |
|
| 330 | + $this, |
|
| 331 | + $validate |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * caches the originally submitted input values in the session |
|
| 338 | + * so that they can be used to repopulate the form if it failed validation |
|
| 339 | + * |
|
| 340 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidInterfaceException |
|
| 343 | + * @throws InvalidDataTypeException |
|
| 344 | + * @throws EE_Error |
|
| 345 | + */ |
|
| 346 | + protected function store_submitted_form_data_in_session() |
|
| 347 | + { |
|
| 348 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 349 | + array( |
|
| 350 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * retrieves the originally submitted input values in the session |
|
| 358 | + * so that they can be used to repopulate the form if it failed validation |
|
| 359 | + * |
|
| 360 | + * @return array |
|
| 361 | + * @throws InvalidArgumentException |
|
| 362 | + * @throws InvalidInterfaceException |
|
| 363 | + * @throws InvalidDataTypeException |
|
| 364 | + */ |
|
| 365 | + protected function get_submitted_form_data_from_session() |
|
| 366 | + { |
|
| 367 | + $session = EE_Registry::instance()->SSN; |
|
| 368 | + if ($session instanceof EE_Session) { |
|
| 369 | + return $session->get_session_data( |
|
| 370 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 371 | + ); |
|
| 372 | + } |
|
| 373 | + return array(); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * flushed the originally submitted input values from the session |
|
| 379 | + * |
|
| 380 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 381 | + * @throws InvalidArgumentException |
|
| 382 | + * @throws InvalidInterfaceException |
|
| 383 | + * @throws InvalidDataTypeException |
|
| 384 | + */ |
|
| 385 | + public static function flush_submitted_form_data_from_session() |
|
| 386 | + { |
|
| 387 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 388 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Populates this form and its subsections with data from the session. |
|
| 395 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 396 | + * validation errors when displaying too) |
|
| 397 | + * Returns true if the form was populated from the session, false otherwise |
|
| 398 | + * |
|
| 399 | + * @return boolean |
|
| 400 | + * @throws InvalidArgumentException |
|
| 401 | + * @throws InvalidInterfaceException |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws EE_Error |
|
| 404 | + */ |
|
| 405 | + public function populate_from_session() |
|
| 406 | + { |
|
| 407 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 408 | + if (empty($form_data_in_session)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + $this->receive_form_submission($form_data_in_session); |
|
| 412 | + add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 413 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 414 | + return true; |
|
| 415 | + } |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Populates the default data for the form, given an array where keys are |
|
| 422 | + * the input names, and values are their values (preferably normalized to be their |
|
| 423 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 424 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 425 | + * the value being an array formatted in teh same way |
|
| 426 | + * |
|
| 427 | + * @param array $default_data |
|
| 428 | + * @throws EE_Error |
|
| 429 | + */ |
|
| 430 | + public function populate_defaults($default_data) |
|
| 431 | + { |
|
| 432 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 433 | + if (isset($default_data[ $subsection_name ])) { |
|
| 434 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 435 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
| 436 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 437 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * returns true if subsection exists |
|
| 446 | + * |
|
| 447 | + * @param string $name |
|
| 448 | + * @return boolean |
|
| 449 | + */ |
|
| 450 | + public function subsection_exists($name) |
|
| 451 | + { |
|
| 452 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Gets the subsection specified by its name |
|
| 458 | + * |
|
| 459 | + * @param string $name |
|
| 460 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 461 | + * so that the inputs will be properly configured. |
|
| 462 | + * However, some client code may be ok |
|
| 463 | + * with construction finalize being called later |
|
| 464 | + * (realizing that the subsections' html names |
|
| 465 | + * might not be set yet, etc.) |
|
| 466 | + * @return EE_Form_Section_Base |
|
| 467 | + * @throws EE_Error |
|
| 468 | + */ |
|
| 469 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 470 | + { |
|
| 471 | + if ($require_construction_to_be_finalized) { |
|
| 472 | + $this->ensure_construct_finalized_called(); |
|
| 473 | + } |
|
| 474 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Gets all the validatable subsections of this form section |
|
| 480 | + * |
|
| 481 | + * @return EE_Form_Section_Validatable[] |
|
| 482 | + * @throws EE_Error |
|
| 483 | + */ |
|
| 484 | + public function get_validatable_subsections() |
|
| 485 | + { |
|
| 486 | + $validatable_subsections = array(); |
|
| 487 | + foreach ($this->subsections() as $name => $obj) { |
|
| 488 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 489 | + $validatable_subsections[ $name ] = $obj; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + return $validatable_subsections; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 498 | + * throw an EE_Error. |
|
| 499 | + * |
|
| 500 | + * @param string $name |
|
| 501 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 502 | + * leave this as TRUE so that the inputs will be properly |
|
| 503 | + * configured. However, some client code may be ok with |
|
| 504 | + * construction finalize being called later |
|
| 505 | + * (realizing that the subsections' html names might not be |
|
| 506 | + * set yet, etc.) |
|
| 507 | + * @return EE_Form_Input_Base |
|
| 508 | + * @throws EE_Error |
|
| 509 | + */ |
|
| 510 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 511 | + { |
|
| 512 | + $subsection = $this->get_subsection( |
|
| 513 | + $name, |
|
| 514 | + $require_construction_to_be_finalized |
|
| 515 | + ); |
|
| 516 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 517 | + throw new EE_Error( |
|
| 518 | + sprintf( |
|
| 519 | + esc_html__( |
|
| 520 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 521 | + 'event_espresso' |
|
| 522 | + ), |
|
| 523 | + $name, |
|
| 524 | + get_class($this), |
|
| 525 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 526 | + ) |
|
| 527 | + ); |
|
| 528 | + } |
|
| 529 | + return $subsection; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 535 | + * otherwise throws an EE_Error |
|
| 536 | + * |
|
| 537 | + * @param string $name |
|
| 538 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 539 | + * leave this as TRUE so that the inputs will be properly |
|
| 540 | + * configured. However, some client code may be ok with |
|
| 541 | + * construction finalize being called later |
|
| 542 | + * (realizing that the subsections' html names might not be |
|
| 543 | + * set yet, etc.) |
|
| 544 | + * @return EE_Form_Section_Proper |
|
| 545 | + * @throws EE_Error |
|
| 546 | + */ |
|
| 547 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 548 | + { |
|
| 549 | + $subsection = $this->get_subsection( |
|
| 550 | + $name, |
|
| 551 | + $require_construction_to_be_finalized |
|
| 552 | + ); |
|
| 553 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 554 | + throw new EE_Error( |
|
| 555 | + sprintf( |
|
| 556 | + esc_html__( |
|
| 557 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 558 | + 'event_espresso' |
|
| 559 | + ), |
|
| 560 | + $name, |
|
| 561 | + get_class($this) |
|
| 562 | + ) |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + return $subsection; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 571 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 572 | + * |
|
| 573 | + * @param string $name |
|
| 574 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 575 | + * @throws EE_Error |
|
| 576 | + */ |
|
| 577 | + public function get_input_value($name) |
|
| 578 | + { |
|
| 579 | + $input = $this->get_input($name); |
|
| 580 | + return $input->normalized_value(); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 586 | + * |
|
| 587 | + * @throws EE_Error |
|
| 588 | + * @return boolean |
|
| 589 | + */ |
|
| 590 | + public function is_valid() |
|
| 591 | + { |
|
| 592 | + if ($this->is_valid === null) { |
|
| 593 | + if (! $this->has_received_submission()) { |
|
| 594 | + throw new EE_Error( |
|
| 595 | + sprintf( |
|
| 596 | + esc_html__( |
|
| 597 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 598 | + 'event_espresso' |
|
| 599 | + ) |
|
| 600 | + ) |
|
| 601 | + ); |
|
| 602 | + } |
|
| 603 | + if (! parent::is_valid()) { |
|
| 604 | + $this->is_valid = false; |
|
| 605 | + } else { |
|
| 606 | + // ok so no general errors to this entire form section. |
|
| 607 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 608 | + $this->is_valid = true; |
|
| 609 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 610 | + if (! $subsection->is_valid()) { |
|
| 611 | + $this->is_valid = false; |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + return $this->is_valid; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * gets the default name of this form section if none is specified |
|
| 622 | + * |
|
| 623 | + * @return void |
|
| 624 | + */ |
|
| 625 | + protected function _set_default_name_if_empty() |
|
| 626 | + { |
|
| 627 | + if (! $this->_name) { |
|
| 628 | + $classname = get_class($this); |
|
| 629 | + $default_name = str_replace('EE_', '', $classname); |
|
| 630 | + $this->_name = $default_name; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 637 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 638 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 639 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 640 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 641 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 642 | + * any CSS. |
|
| 643 | + * |
|
| 644 | + * @throws InvalidArgumentException |
|
| 645 | + * @throws InvalidInterfaceException |
|
| 646 | + * @throws InvalidDataTypeException |
|
| 647 | + * @throws EE_Error |
|
| 648 | + */ |
|
| 649 | + public function get_html_and_js() |
|
| 650 | + { |
|
| 651 | + $this->enqueue_js(); |
|
| 652 | + return $this->get_html(); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 658 | + * |
|
| 659 | + * @param bool $display_previously_submitted_data |
|
| 660 | + * @return string |
|
| 661 | + * @throws InvalidArgumentException |
|
| 662 | + * @throws InvalidInterfaceException |
|
| 663 | + * @throws InvalidDataTypeException |
|
| 664 | + * @throws EE_Error |
|
| 665 | + * @throws EE_Error |
|
| 666 | + * @throws EE_Error |
|
| 667 | + */ |
|
| 668 | + public function get_html($display_previously_submitted_data = true) |
|
| 669 | + { |
|
| 670 | + $this->ensure_construct_finalized_called(); |
|
| 671 | + if ($display_previously_submitted_data) { |
|
| 672 | + $this->populate_from_session(); |
|
| 673 | + } |
|
| 674 | + return $this->_form_html_filter |
|
| 675 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 676 | + : $this->_layout_strategy->layout_form(); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * enqueues JS and CSS for the form. |
|
| 682 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 683 | + * scripts and styles can be put in the header, but if called later |
|
| 684 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 685 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 686 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 687 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 688 | + * |
|
| 689 | + * @return void |
|
| 690 | + * @throws EE_Error |
|
| 691 | + */ |
|
| 692 | + public function enqueue_js() |
|
| 693 | + { |
|
| 694 | + $this->_enqueue_and_localize_form_js(); |
|
| 695 | + foreach ($this->subsections() as $subsection) { |
|
| 696 | + $subsection->enqueue_js(); |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 703 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 704 | + * the wp_enqueue_scripts hook. |
|
| 705 | + * However, registering the form js and localizing it can happen when we |
|
| 706 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 707 | + * could change until it's actually outputted) |
|
| 708 | + * |
|
| 709 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 710 | + * to be triggered automatically or not |
|
| 711 | + * @return void |
|
| 712 | + */ |
|
| 713 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 714 | + { |
|
| 715 | + wp_register_script( |
|
| 716 | + 'ee_form_section_validation', |
|
| 717 | + EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 718 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 719 | + EVENT_ESPRESSO_VERSION, |
|
| 720 | + true |
|
| 721 | + ); |
|
| 722 | + wp_localize_script( |
|
| 723 | + 'ee_form_section_validation', |
|
| 724 | + 'ee_form_section_validation_init', |
|
| 725 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 726 | + ); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * gets the variables used by form_section_validation.js. |
|
| 732 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 733 | + * but before the wordpress hook wp_loaded |
|
| 734 | + * |
|
| 735 | + * @throws EE_Error |
|
| 736 | + */ |
|
| 737 | + public function _enqueue_and_localize_form_js() |
|
| 738 | + { |
|
| 739 | + $this->ensure_construct_finalized_called(); |
|
| 740 | + // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 741 | + // so we need to add our form section data to a static variable accessible by all form sections |
|
| 742 | + // and localize it just before the footer |
|
| 743 | + $this->localize_validation_rules(); |
|
| 744 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 745 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * add our form section data to a static variable accessible by all form sections |
|
| 751 | + * |
|
| 752 | + * @param bool $return_for_subsection |
|
| 753 | + * @return void |
|
| 754 | + * @throws EE_Error |
|
| 755 | + */ |
|
| 756 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 757 | + { |
|
| 758 | + // we only want to localize vars ONCE for the entire form, |
|
| 759 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 760 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 761 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 762 | + 'form_section_id' => $this->html_id(true), |
|
| 763 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 764 | + 'other_data' => $this->get_other_js_data(), |
|
| 765 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 766 | + ); |
|
| 767 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 774 | + * This is primarily data added by inputs and forms in addition to any |
|
| 775 | + * scripts they might enqueue |
|
| 776 | + * |
|
| 777 | + * @param array $form_other_js_data |
|
| 778 | + * @return array |
|
| 779 | + * @throws EE_Error |
|
| 780 | + */ |
|
| 781 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 782 | + { |
|
| 783 | + foreach ($this->subsections() as $subsection) { |
|
| 784 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 785 | + } |
|
| 786 | + return $form_other_js_data; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 792 | + * Keys are their form names, and values are the inputs themselves |
|
| 793 | + * |
|
| 794 | + * @return EE_Form_Input_Base |
|
| 795 | + * @throws EE_Error |
|
| 796 | + */ |
|
| 797 | + public function inputs_in_subsections() |
|
| 798 | + { |
|
| 799 | + $inputs = array(); |
|
| 800 | + foreach ($this->subsections() as $subsection) { |
|
| 801 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 802 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
| 803 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 804 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + return $inputs; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * Gets a flat array of all the validation errors. |
|
| 813 | + * Keys are html names (because those should be unique) |
|
| 814 | + * and values are a string of all their validation errors |
|
| 815 | + * |
|
| 816 | + * @return string[] |
|
| 817 | + * @throws EE_Error |
|
| 818 | + */ |
|
| 819 | + public function subsection_validation_errors_by_html_name() |
|
| 820 | + { |
|
| 821 | + $inputs = $this->inputs(); |
|
| 822 | + $errors = array(); |
|
| 823 | + foreach ($inputs as $form_input) { |
|
| 824 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 825 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + return $errors; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 834 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 835 | + * |
|
| 836 | + * @throws InvalidArgumentException |
|
| 837 | + * @throws InvalidInterfaceException |
|
| 838 | + * @throws InvalidDataTypeException |
|
| 839 | + */ |
|
| 840 | + public static function localize_script_for_all_forms() |
|
| 841 | + { |
|
| 842 | + // allow inputs and stuff to hook in their JS and stuff here |
|
| 843 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 844 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 845 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 846 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 847 | + : 'wp_default'; |
|
| 848 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 849 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 850 | + wp_localize_script( |
|
| 851 | + 'ee_form_section_validation', |
|
| 852 | + 'ee_form_section_vars', |
|
| 853 | + EE_Form_Section_Proper::$_js_localization |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * ensure_scripts_localized |
|
| 860 | + * |
|
| 861 | + * @throws EE_Error |
|
| 862 | + */ |
|
| 863 | + public function ensure_scripts_localized() |
|
| 864 | + { |
|
| 865 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 866 | + $this->_enqueue_and_localize_form_js(); |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 873 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 874 | + * |
|
| 875 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 876 | + */ |
|
| 877 | + private static function _get_localized_error_messages() |
|
| 878 | + { |
|
| 879 | + return array( |
|
| 880 | + 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 881 | + 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * @return array |
|
| 888 | + */ |
|
| 889 | + public static function js_localization() |
|
| 890 | + { |
|
| 891 | + return self::$_js_localization; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public static function reset_js_localization() |
|
| 899 | + { |
|
| 900 | + self::$_js_localization = array(); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 906 | + * See parent function for more... |
|
| 907 | + * |
|
| 908 | + * @return array |
|
| 909 | + * @throws EE_Error |
|
| 910 | + */ |
|
| 911 | + public function get_jquery_validation_rules() |
|
| 912 | + { |
|
| 913 | + $jquery_validation_rules = array(); |
|
| 914 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 915 | + $jquery_validation_rules = array_merge( |
|
| 916 | + $jquery_validation_rules, |
|
| 917 | + $subsection->get_jquery_validation_rules() |
|
| 918 | + ); |
|
| 919 | + } |
|
| 920 | + return $jquery_validation_rules; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + |
|
| 924 | + /** |
|
| 925 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 926 | + * |
|
| 927 | + * @param array $req_data |
|
| 928 | + * @return void |
|
| 929 | + * @throws EE_Error |
|
| 930 | + */ |
|
| 931 | + protected function _normalize($req_data) |
|
| 932 | + { |
|
| 933 | + $this->_received_submission = true; |
|
| 934 | + $this->_validation_errors = array(); |
|
| 935 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 936 | + try { |
|
| 937 | + $subsection->_normalize($req_data); |
|
| 938 | + } catch (EE_Validation_Error $e) { |
|
| 939 | + $subsection->add_validation_error($e); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * Performs validation on this form section and its subsections. |
|
| 947 | + * For each subsection, |
|
| 948 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 949 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 950 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 951 | + * you would be best to override this _validate method, |
|
| 952 | + * calling parent::_validate() first. |
|
| 953 | + * |
|
| 954 | + * @throws EE_Error |
|
| 955 | + */ |
|
| 956 | + protected function _validate() |
|
| 957 | + { |
|
| 958 | + // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 959 | + $this->is_valid = null; |
|
| 960 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 961 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 962 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 963 | + } |
|
| 964 | + $subsection->_validate(); |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * Gets all the validated inputs for the form section |
|
| 971 | + * |
|
| 972 | + * @return array |
|
| 973 | + * @throws EE_Error |
|
| 974 | + */ |
|
| 975 | + public function valid_data() |
|
| 976 | + { |
|
| 977 | + $inputs = array(); |
|
| 978 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 979 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 980 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 981 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 982 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + return $inputs; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Gets all the inputs on this form section |
|
| 991 | + * |
|
| 992 | + * @return EE_Form_Input_Base[] |
|
| 993 | + * @throws EE_Error |
|
| 994 | + */ |
|
| 995 | + public function inputs() |
|
| 996 | + { |
|
| 997 | + $inputs = array(); |
|
| 998 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 999 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1000 | + $inputs[ $subsection_name ] = $subsection; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + return $inputs; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Gets all the subsections which are a proper form |
|
| 1009 | + * |
|
| 1010 | + * @return EE_Form_Section_Proper[] |
|
| 1011 | + * @throws EE_Error |
|
| 1012 | + */ |
|
| 1013 | + public function subforms() |
|
| 1014 | + { |
|
| 1015 | + $form_sections = array(); |
|
| 1016 | + foreach ($this->subsections() as $name => $obj) { |
|
| 1017 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1018 | + $form_sections[ $name ] = $obj; |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + return $form_sections; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1027 | + * Consider using inputs() or subforms() |
|
| 1028 | + * if you only want form inputs or proper form sections. |
|
| 1029 | + * |
|
| 1030 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1031 | + * leave this as TRUE so that the inputs will be properly |
|
| 1032 | + * configured. However, some client code may be ok with |
|
| 1033 | + * construction finalize being called later |
|
| 1034 | + * (realizing that the subsections' html names might not be |
|
| 1035 | + * set yet, etc.) |
|
| 1036 | + * @return EE_Form_Section_Proper[] |
|
| 1037 | + * @throws EE_Error |
|
| 1038 | + */ |
|
| 1039 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 1040 | + { |
|
| 1041 | + if ($require_construction_to_be_finalized) { |
|
| 1042 | + $this->ensure_construct_finalized_called(); |
|
| 1043 | + } |
|
| 1044 | + return $this->_subsections; |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * Returns whether this form has any subforms or inputs |
|
| 1050 | + * @return bool |
|
| 1051 | + */ |
|
| 1052 | + public function hasSubsections() |
|
| 1053 | + { |
|
| 1054 | + return ! empty($this->_subsections); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 1060 | + * values. (Similar to calling get_input_value on inputs) |
|
| 1061 | + * |
|
| 1062 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1063 | + * or just this forms' direct children inputs |
|
| 1064 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1065 | + * or allow multidimensional array |
|
| 1066 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1067 | + * with array keys being input names |
|
| 1068 | + * (regardless of whether they are from a subsection or not), |
|
| 1069 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1070 | + * where keys are always subsection names and values are either |
|
| 1071 | + * the input's normalized value, or an array like the top-level array |
|
| 1072 | + * @throws EE_Error |
|
| 1073 | + */ |
|
| 1074 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1075 | + { |
|
| 1076 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1082 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1083 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 1084 | + * where keys are the input names, and values are their display values |
|
| 1085 | + * |
|
| 1086 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1087 | + * or just this forms' direct children inputs |
|
| 1088 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1089 | + * or allow multidimensional array |
|
| 1090 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1091 | + * with array keys being input names |
|
| 1092 | + * (regardless of whether they are from a subsection or not), |
|
| 1093 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1094 | + * where keys are always subsection names and values are either |
|
| 1095 | + * the input's normalized value, or an array like the top-level array |
|
| 1096 | + * @throws EE_Error |
|
| 1097 | + */ |
|
| 1098 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1099 | + { |
|
| 1100 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Gets the input values from the form |
|
| 1106 | + * |
|
| 1107 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1108 | + * or just the normalized value |
|
| 1109 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1110 | + * or just this forms' direct children inputs |
|
| 1111 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1112 | + * or allow multidimensional array |
|
| 1113 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1114 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1115 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1116 | + * where keys are always subsection names and values are either |
|
| 1117 | + * the input's normalized value, or an array like the top-level array |
|
| 1118 | + * @throws EE_Error |
|
| 1119 | + */ |
|
| 1120 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1121 | + { |
|
| 1122 | + $input_values = array(); |
|
| 1123 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1124 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1125 | + $input_values[ $subsection_name ] = $pretty |
|
| 1126 | + ? $subsection->pretty_value() |
|
| 1127 | + : $subsection->normalized_value(); |
|
| 1128 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1129 | + $subform_input_values = $subsection->_input_values( |
|
| 1130 | + $pretty, |
|
| 1131 | + $include_subform_inputs, |
|
| 1132 | + $flatten |
|
| 1133 | + ); |
|
| 1134 | + if ($flatten) { |
|
| 1135 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1136 | + } else { |
|
| 1137 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + return $input_values; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + /** |
|
| 1146 | + * Gets the originally submitted input values from the form |
|
| 1147 | + * |
|
| 1148 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1149 | + * or just this forms' direct children inputs |
|
| 1150 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1151 | + * with array keys being input names |
|
| 1152 | + * (regardless of whether they are from a subsection or not), |
|
| 1153 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1154 | + * where keys are always subsection names and values are either |
|
| 1155 | + * the input's normalized value, or an array like the top-level array |
|
| 1156 | + * @throws EE_Error |
|
| 1157 | + */ |
|
| 1158 | + public function submitted_values($include_subforms = false) |
|
| 1159 | + { |
|
| 1160 | + $submitted_values = array(); |
|
| 1161 | + foreach ($this->subsections() as $subsection) { |
|
| 1162 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1163 | + // is this input part of an array of inputs? |
|
| 1164 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1165 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1166 | + explode( |
|
| 1167 | + '[', |
|
| 1168 | + str_replace(']', '', $subsection->html_name()) |
|
| 1169 | + ), |
|
| 1170 | + $subsection->raw_value() |
|
| 1171 | + ); |
|
| 1172 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1173 | + } else { |
|
| 1174 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1175 | + } |
|
| 1176 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1177 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1178 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1179 | + } |
|
| 1180 | + } |
|
| 1181 | + return $submitted_values; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Indicates whether or not this form has received a submission yet |
|
| 1187 | + * (ie, had receive_form_submission called on it yet) |
|
| 1188 | + * |
|
| 1189 | + * @return boolean |
|
| 1190 | + * @throws EE_Error |
|
| 1191 | + */ |
|
| 1192 | + public function has_received_submission() |
|
| 1193 | + { |
|
| 1194 | + $this->ensure_construct_finalized_called(); |
|
| 1195 | + return $this->_received_submission; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + |
|
| 1199 | + /** |
|
| 1200 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1201 | + * Removes the listed inputs from the form |
|
| 1202 | + * |
|
| 1203 | + * @param array $inputs_to_exclude values are the input names |
|
| 1204 | + * @return void |
|
| 1205 | + */ |
|
| 1206 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1207 | + { |
|
| 1208 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1209 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1216 | + * @param array $inputs_to_hide |
|
| 1217 | + * @throws EE_Error |
|
| 1218 | + */ |
|
| 1219 | + public function hide(array $inputs_to_hide = array()) |
|
| 1220 | + { |
|
| 1221 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1222 | + $input = $this->get_input($input_to_hide); |
|
| 1223 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * add_subsections |
|
| 1230 | + * Adds the listed subsections to the form section. |
|
| 1231 | + * If $subsection_name_to_target is provided, |
|
| 1232 | + * then new subsections are added before or after that subsection, |
|
| 1233 | + * otherwise to the start or end of the entire subsections array. |
|
| 1234 | + * |
|
| 1235 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1236 | + * where keys are their names |
|
| 1237 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1238 | + * should be added before or after |
|
| 1239 | + * IF $subsection_name_to_target is null, |
|
| 1240 | + * then $new_subsections will be added to |
|
| 1241 | + * the beginning or end of the entire subsections array |
|
| 1242 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1243 | + * $subsection_name_to_target, |
|
| 1244 | + * or if $subsection_name_to_target is null, |
|
| 1245 | + * before or after entire subsections array |
|
| 1246 | + * @return void |
|
| 1247 | + * @throws EE_Error |
|
| 1248 | + */ |
|
| 1249 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1250 | + { |
|
| 1251 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1252 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1253 | + EE_Error::add_error( |
|
| 1254 | + sprintf( |
|
| 1255 | + esc_html__( |
|
| 1256 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1257 | + 'event_espresso' |
|
| 1258 | + ), |
|
| 1259 | + get_class($subsection), |
|
| 1260 | + $subsection_name, |
|
| 1261 | + $this->name() |
|
| 1262 | + ) |
|
| 1263 | + ); |
|
| 1264 | + unset($new_subsections[ $subsection_name ]); |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1268 | + $this->_subsections, |
|
| 1269 | + $new_subsections, |
|
| 1270 | + $subsection_name_to_target, |
|
| 1271 | + $add_before |
|
| 1272 | + ); |
|
| 1273 | + if ($this->_construction_finalized) { |
|
| 1274 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1275 | + $subsection->_construct_finalize($this, $name); |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * @param string $subsection_name |
|
| 1283 | + * @param bool $recursive |
|
| 1284 | + * @return bool |
|
| 1285 | + */ |
|
| 1286 | + public function has_subsection($subsection_name, $recursive = false) |
|
| 1287 | + { |
|
| 1288 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1289 | + if ( |
|
| 1290 | + $name === $subsection_name |
|
| 1291 | + || ( |
|
| 1292 | + $recursive |
|
| 1293 | + && $subsection instanceof EE_Form_Section_Proper |
|
| 1294 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1295 | + ) |
|
| 1296 | + ) { |
|
| 1297 | + return true; |
|
| 1298 | + } |
|
| 1299 | + } |
|
| 1300 | + return false; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1307 | + * |
|
| 1308 | + * @throws EE_Error |
|
| 1309 | + */ |
|
| 1310 | + public function clean_sensitive_data() |
|
| 1311 | + { |
|
| 1312 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1313 | + $subsection->clean_sensitive_data(); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1320 | + * @param string $form_submission_error_message |
|
| 1321 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 1322 | + * @throws EE_Error |
|
| 1323 | + */ |
|
| 1324 | + public function set_submission_error_message( |
|
| 1325 | + $form_submission_error_message = '' |
|
| 1326 | + ) { |
|
| 1327 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1328 | + ? $form_submission_error_message |
|
| 1329 | + : $this->getAllValidationErrorsString(); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + |
|
| 1333 | + /** |
|
| 1334 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1335 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 1336 | + * set_submission_error_message |
|
| 1337 | + * |
|
| 1338 | + * @return string |
|
| 1339 | + */ |
|
| 1340 | + public function submission_error_message() |
|
| 1341 | + { |
|
| 1342 | + return $this->_form_submission_error_message; |
|
| 1343 | + } |
|
| 1344 | + |
|
| 1345 | + |
|
| 1346 | + /** |
|
| 1347 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 1348 | + * @param string $form_submission_success_message |
|
| 1349 | + */ |
|
| 1350 | + public function set_submission_success_message($form_submission_success_message = '') |
|
| 1351 | + { |
|
| 1352 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1353 | + ? $form_submission_success_message |
|
| 1354 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 1360 | + * @return string |
|
| 1361 | + */ |
|
| 1362 | + public function submission_success_message() |
|
| 1363 | + { |
|
| 1364 | + return $this->_form_submission_success_message; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Returns the prefix that should be used on child of this form section for |
|
| 1370 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1371 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1372 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1373 | + * |
|
| 1374 | + * @return string |
|
| 1375 | + * @throws EE_Error |
|
| 1376 | + */ |
|
| 1377 | + public function html_name_prefix() |
|
| 1378 | + { |
|
| 1379 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1380 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1381 | + } |
|
| 1382 | + return $this->name(); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + |
|
| 1386 | + /** |
|
| 1387 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1388 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1389 | + * was set, which is probably nothing, or the classname) |
|
| 1390 | + * |
|
| 1391 | + * @return string |
|
| 1392 | + * @throws EE_Error |
|
| 1393 | + */ |
|
| 1394 | + public function name() |
|
| 1395 | + { |
|
| 1396 | + $this->ensure_construct_finalized_called(); |
|
| 1397 | + return parent::name(); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * @return EE_Form_Section_Proper |
|
| 1403 | + * @throws EE_Error |
|
| 1404 | + */ |
|
| 1405 | + public function parent_section() |
|
| 1406 | + { |
|
| 1407 | + $this->ensure_construct_finalized_called(); |
|
| 1408 | + return parent::parent_section(); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1414 | + * |
|
| 1415 | + * @return void |
|
| 1416 | + * @throws EE_Error |
|
| 1417 | + */ |
|
| 1418 | + public function ensure_construct_finalized_called() |
|
| 1419 | + { |
|
| 1420 | + if (! $this->_construction_finalized) { |
|
| 1421 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1428 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1429 | + * |
|
| 1430 | + * @param array $req_data |
|
| 1431 | + * @return boolean |
|
| 1432 | + * @throws EE_Error |
|
| 1433 | + */ |
|
| 1434 | + public function form_data_present_in($req_data = null) |
|
| 1435 | + { |
|
| 1436 | + $req_data = $this->getCachedRequest($req_data); |
|
| 1437 | + foreach ($this->subsections() as $subsection) { |
|
| 1438 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1439 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1440 | + return true; |
|
| 1441 | + } |
|
| 1442 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1443 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1444 | + return true; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + return false; |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + |
|
| 1452 | + /** |
|
| 1453 | + * Gets validation errors for this form section and subsections |
|
| 1454 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1455 | + * gets the validation errors for ALL subsection |
|
| 1456 | + * |
|
| 1457 | + * @return EE_Validation_Error[] |
|
| 1458 | + * @throws EE_Error |
|
| 1459 | + */ |
|
| 1460 | + public function get_validation_errors_accumulated() |
|
| 1461 | + { |
|
| 1462 | + $validation_errors = $this->get_validation_errors(); |
|
| 1463 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1464 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1465 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1466 | + } else { |
|
| 1467 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1468 | + } |
|
| 1469 | + if ($validation_errors_on_this_subsection) { |
|
| 1470 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + return $validation_errors; |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + /** |
|
| 1477 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1478 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1479 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1480 | + * |
|
| 1481 | + * @return string |
|
| 1482 | + * @since 4.9.59.p |
|
| 1483 | + */ |
|
| 1484 | + protected function getAllValidationErrorsString() |
|
| 1485 | + { |
|
| 1486 | + $submission_error_messages = array(); |
|
| 1487 | + // bad, bad, bad registrant |
|
| 1488 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1489 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1490 | + $form_section = $validation_error->get_form_section(); |
|
| 1491 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1492 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1493 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1494 | + $label = $validation_error->get_form_section()->name(); |
|
| 1495 | + } else { |
|
| 1496 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1497 | + } |
|
| 1498 | + $submission_error_messages[] = sprintf( |
|
| 1499 | + esc_html__('%s : %s', 'event_espresso'), |
|
| 1500 | + $label, |
|
| 1501 | + $validation_error->getMessage() |
|
| 1502 | + ); |
|
| 1503 | + } |
|
| 1504 | + } |
|
| 1505 | + return implode('<br>', $submission_error_messages); |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + |
|
| 1509 | + /** |
|
| 1510 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1511 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1512 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1513 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1514 | + * which will be returned. |
|
| 1515 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1516 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1517 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1518 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1519 | + * Etc |
|
| 1520 | + * |
|
| 1521 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1522 | + * @return EE_Form_Section_Base |
|
| 1523 | + * @throws EE_Error |
|
| 1524 | + */ |
|
| 1525 | + public function find_section_from_path($form_section_path) |
|
| 1526 | + { |
|
| 1527 | + // check if we can find the input from purely going straight up the tree |
|
| 1528 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1529 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1530 | + return $input; |
|
| 1531 | + } |
|
| 1532 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1533 | + if ($next_slash_pos !== false) { |
|
| 1534 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1535 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1536 | + } else { |
|
| 1537 | + $child_section_name = $form_section_path; |
|
| 1538 | + $subpath = ''; |
|
| 1539 | + } |
|
| 1540 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1541 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1542 | + return $child_section->find_section_from_path($subpath); |
|
| 1543 | + } |
|
| 1544 | + return null; |
|
| 1545 | + } |
|
| 1546 | 1546 | } |