@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.3.0 |
8 | 8 | */ |
9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -23,152 +23,152 @@ discard block |
||
23 | 23 | class EE_Newsletter_message_type extends EE_message_type |
24 | 24 | { |
25 | 25 | |
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->name = 'newsletter'; |
|
29 | - $this->description = __('Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', |
|
30 | - 'event_espresso'); |
|
31 | - $this->label = array( |
|
32 | - 'singular' => __('batch', 'event_espresso'), |
|
33 | - 'plural' => __('batches', 'event_espresso'), |
|
34 | - ); |
|
35 | - $this->_master_templates = array( |
|
36 | - 'email' => 'registration', |
|
37 | - ); |
|
38 | - |
|
39 | - parent::__construct(); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - protected function _set_admin_pages() |
|
44 | - { |
|
45 | - $this->admin_registered_pages = array(); //no admin pages to register this with. |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - protected function _set_data_handler() |
|
50 | - { |
|
51 | - $this->_data_handler = 'Registrations'; |
|
52 | - $this->_single_message = $this->_data instanceof EE_Registration; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
57 | - { |
|
58 | - //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
|
59 | - return array($registration); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - protected function _set_admin_settings_fields() |
|
64 | - { |
|
65 | - $this->_admin_settings_fields = array(); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - protected function _set_contexts() |
|
70 | - { |
|
71 | - $this->_context_label = array( |
|
72 | - 'label' => __('recipient', 'event_espresso'), |
|
73 | - 'plural' => __('recipients', 'event_espresso'), |
|
74 | - 'description' => __('Recipient\'s are who will receive the message.', 'event_espresso'), |
|
75 | - ); |
|
76 | - |
|
77 | - $this->_contexts = array( |
|
78 | - 'attendee' => array( |
|
79 | - 'label' => __('Registrant', 'event_espresso'), |
|
80 | - 'description' => __('This template goes to selected registrants.', 'event_espresso'), |
|
81 | - ), |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * used to set the valid shortcodes. |
|
88 | - * For the newsletter message type we only have two valid shortcode libraries in use, recipient details and |
|
89 | - * organization. That's it! |
|
90 | - * |
|
91 | - * @since 4.3.0 |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - protected function _set_valid_shortcodes() |
|
95 | - { |
|
96 | - parent::_set_valid_shortcodes(); |
|
97 | - |
|
98 | - $included_shortcodes = array( |
|
99 | - 'recipient_details', |
|
100 | - 'organization', |
|
101 | - 'newsletter', |
|
102 | - ); |
|
103 | - |
|
104 | - foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
105 | - foreach ($shortcodes as $key => $shortcode) { |
|
106 | - if (! in_array($shortcode, $included_shortcodes)) { |
|
107 | - unset($this->_valid_shortcodes[$context][$key]); |
|
108 | - } |
|
109 | - } |
|
110 | - $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
111 | - } |
|
112 | - |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Override default _attendee_addressees in EE_message_type because we want to loop through the registrations |
|
118 | - * for EE_message_type. |
|
119 | - */ |
|
120 | - protected function _attendee_addressees() |
|
121 | - { |
|
122 | - $addressee = array(); |
|
123 | - |
|
124 | - //looping through registrations |
|
125 | - foreach ($this->_data->registrations as $reg_id => $details) { |
|
126 | - //set $attendee array to blank on each loop |
|
127 | - $aee = array(); |
|
128 | - |
|
129 | - //need to get the attendee from this registration. |
|
130 | - $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
131 | - ? $details['att_obj'] |
|
132 | - : null; |
|
133 | - |
|
134 | - if (! $attendee instanceof EE_Attendee) { |
|
135 | - continue; |
|
136 | - } |
|
137 | - |
|
138 | - //set $aee from attendee object |
|
139 | - $aee['att_obj'] = $attendee; |
|
140 | - $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
141 | - ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
142 | - : array(); |
|
143 | - $aee['attendee_email'] = $attendee->email(); |
|
144 | - $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
145 | - ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
146 | - : array(); |
|
147 | - |
|
148 | - if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
149 | - $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
150 | - $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
151 | - } else { |
|
152 | - $aee['evt_objs'] = $aee['events'] = array(); |
|
153 | - } |
|
154 | - |
|
155 | - $aee['reg_obj'] = isset($details['reg_obj']) |
|
156 | - ? $details['reg_obj'] |
|
157 | - : null; |
|
158 | - $aee['attendees'] = $this->_data->attendees; |
|
159 | - |
|
160 | - //merge in the primary attendee data |
|
161 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
162 | - |
|
163 | - //make sure txn is set |
|
164 | - if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
165 | - $aee['txn'] = $aee['reg_obj']->transaction(); |
|
166 | - } |
|
167 | - |
|
168 | - $addressee[] = new EE_Messages_Addressee($aee); |
|
169 | - } |
|
170 | - return $addressee; |
|
171 | - } |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->name = 'newsletter'; |
|
29 | + $this->description = __('Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', |
|
30 | + 'event_espresso'); |
|
31 | + $this->label = array( |
|
32 | + 'singular' => __('batch', 'event_espresso'), |
|
33 | + 'plural' => __('batches', 'event_espresso'), |
|
34 | + ); |
|
35 | + $this->_master_templates = array( |
|
36 | + 'email' => 'registration', |
|
37 | + ); |
|
38 | + |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + protected function _set_admin_pages() |
|
44 | + { |
|
45 | + $this->admin_registered_pages = array(); //no admin pages to register this with. |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + protected function _set_data_handler() |
|
50 | + { |
|
51 | + $this->_data_handler = 'Registrations'; |
|
52 | + $this->_single_message = $this->_data instanceof EE_Registration; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
57 | + { |
|
58 | + //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
|
59 | + return array($registration); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + protected function _set_admin_settings_fields() |
|
64 | + { |
|
65 | + $this->_admin_settings_fields = array(); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + protected function _set_contexts() |
|
70 | + { |
|
71 | + $this->_context_label = array( |
|
72 | + 'label' => __('recipient', 'event_espresso'), |
|
73 | + 'plural' => __('recipients', 'event_espresso'), |
|
74 | + 'description' => __('Recipient\'s are who will receive the message.', 'event_espresso'), |
|
75 | + ); |
|
76 | + |
|
77 | + $this->_contexts = array( |
|
78 | + 'attendee' => array( |
|
79 | + 'label' => __('Registrant', 'event_espresso'), |
|
80 | + 'description' => __('This template goes to selected registrants.', 'event_espresso'), |
|
81 | + ), |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * used to set the valid shortcodes. |
|
88 | + * For the newsletter message type we only have two valid shortcode libraries in use, recipient details and |
|
89 | + * organization. That's it! |
|
90 | + * |
|
91 | + * @since 4.3.0 |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + protected function _set_valid_shortcodes() |
|
95 | + { |
|
96 | + parent::_set_valid_shortcodes(); |
|
97 | + |
|
98 | + $included_shortcodes = array( |
|
99 | + 'recipient_details', |
|
100 | + 'organization', |
|
101 | + 'newsletter', |
|
102 | + ); |
|
103 | + |
|
104 | + foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
105 | + foreach ($shortcodes as $key => $shortcode) { |
|
106 | + if (! in_array($shortcode, $included_shortcodes)) { |
|
107 | + unset($this->_valid_shortcodes[$context][$key]); |
|
108 | + } |
|
109 | + } |
|
110 | + $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
111 | + } |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Override default _attendee_addressees in EE_message_type because we want to loop through the registrations |
|
118 | + * for EE_message_type. |
|
119 | + */ |
|
120 | + protected function _attendee_addressees() |
|
121 | + { |
|
122 | + $addressee = array(); |
|
123 | + |
|
124 | + //looping through registrations |
|
125 | + foreach ($this->_data->registrations as $reg_id => $details) { |
|
126 | + //set $attendee array to blank on each loop |
|
127 | + $aee = array(); |
|
128 | + |
|
129 | + //need to get the attendee from this registration. |
|
130 | + $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
131 | + ? $details['att_obj'] |
|
132 | + : null; |
|
133 | + |
|
134 | + if (! $attendee instanceof EE_Attendee) { |
|
135 | + continue; |
|
136 | + } |
|
137 | + |
|
138 | + //set $aee from attendee object |
|
139 | + $aee['att_obj'] = $attendee; |
|
140 | + $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
141 | + ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
142 | + : array(); |
|
143 | + $aee['attendee_email'] = $attendee->email(); |
|
144 | + $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
145 | + ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
146 | + : array(); |
|
147 | + |
|
148 | + if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
149 | + $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
150 | + $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
151 | + } else { |
|
152 | + $aee['evt_objs'] = $aee['events'] = array(); |
|
153 | + } |
|
154 | + |
|
155 | + $aee['reg_obj'] = isset($details['reg_obj']) |
|
156 | + ? $details['reg_obj'] |
|
157 | + : null; |
|
158 | + $aee['attendees'] = $this->_data->attendees; |
|
159 | + |
|
160 | + //merge in the primary attendee data |
|
161 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
162 | + |
|
163 | + //make sure txn is set |
|
164 | + if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
165 | + $aee['txn'] = $aee['reg_obj']->transaction(); |
|
166 | + } |
|
167 | + |
|
168 | + $addressee[] = new EE_Messages_Addressee($aee); |
|
169 | + } |
|
170 | + return $addressee; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | 174 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @subpackage helpers |
7 | 7 | * @since 4.3.0 |
8 | 8 | */ |
9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | 10 | exit('No direct script access allowed'); |
11 | 11 | } |
12 | 12 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
105 | 105 | foreach ($shortcodes as $key => $shortcode) { |
106 | - if (! in_array($shortcode, $included_shortcodes)) { |
|
106 | + if ( ! in_array($shortcode, $included_shortcodes)) { |
|
107 | 107 | unset($this->_valid_shortcodes[$context][$key]); |
108 | 108 | } |
109 | 109 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ? $details['att_obj'] |
132 | 132 | : null; |
133 | 133 | |
134 | - if (! $attendee instanceof EE_Attendee) { |
|
134 | + if ( ! $attendee instanceof EE_Attendee) { |
|
135 | 135 | continue; |
136 | 136 | } |
137 | 137 |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.032'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.032'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -21,326 +21,326 @@ |
||
21 | 21 | class EED_Recaptcha_Invisible extends EED_Module |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Registration_Config $config |
|
26 | - */ |
|
27 | - private static $config; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @return EED_Module|EED_Recaptcha |
|
32 | - */ |
|
33 | - public static function instance() |
|
34 | - { |
|
35 | - return parent::get_instance(__CLASS__); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @return void |
|
41 | - * @throws InvalidInterfaceException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws InvalidArgumentException |
|
44 | - */ |
|
45 | - public static function set_hooks() |
|
46 | - { |
|
47 | - EED_Recaptcha_Invisible::setProperties(); |
|
48 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
49 | - if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
50 | - // ticket selection |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
53 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
54 | - 10, 3 |
|
55 | - ); |
|
56 | - add_action( |
|
57 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
58 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
59 | - ); |
|
60 | - } |
|
61 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
62 | - // checkout |
|
63 | - add_action( |
|
64 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
65 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
66 | - ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
69 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
70 | - 10, 2 |
|
71 | - ); |
|
72 | - } |
|
73 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @return void |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - * @throws InvalidArgumentException |
|
83 | - */ |
|
84 | - public static function set_hooks_admin() |
|
85 | - { |
|
86 | - EED_Recaptcha_Invisible::setProperties(); |
|
87 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
88 | - add_action( |
|
89 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
90 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
91 | - ); |
|
92 | - } |
|
93 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
96 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
97 | - 10, 2 |
|
98 | - ); |
|
99 | - } |
|
100 | - // admin settings |
|
101 | - add_action( |
|
102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | - ); |
|
105 | - add_filter( |
|
106 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidArgumentException |
|
117 | - */ |
|
118 | - public static function setProperties() |
|
119 | - { |
|
120 | - |
|
121 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public static function useInvisibleRecaptcha() |
|
130 | - { |
|
131 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
132 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $form |
|
138 | - * @return boolean |
|
139 | - */ |
|
140 | - public static function protectForm($form) |
|
141 | - { |
|
142 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
143 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return void |
|
151 | - * @throws InvalidInterfaceException |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidArgumentException |
|
154 | - */ |
|
155 | - public static function localizeScriptVars() |
|
156 | - { |
|
157 | - wp_localize_script( |
|
158 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
159 | - 'eeRecaptcha', |
|
160 | - RecaptchaFactory::create()->getLocalizedVars() |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public static function assetsUrl() |
|
169 | - { |
|
170 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param \WP $WP |
|
176 | - */ |
|
177 | - public function run($WP) |
|
178 | - { |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param EE_Request $request |
|
185 | - * @return bool |
|
186 | - * @throws InvalidArgumentException |
|
187 | - * @throws InvalidDataTypeException |
|
188 | - * @throws InvalidInterfaceException |
|
189 | - * @throws RuntimeException |
|
190 | - */ |
|
191 | - public static function verifyToken(EE_Request $request) |
|
192 | - { |
|
193 | - return RecaptchaFactory::create()->verifyToken($request); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param EE_Form_Section_Proper $reg_form |
|
199 | - * @return void |
|
200 | - * @throws EE_Error |
|
201 | - * @throws InvalidArgumentException |
|
202 | - * @throws InvalidDataTypeException |
|
203 | - * @throws InvalidInterfaceException |
|
204 | - * @throws DomainException |
|
205 | - */ |
|
206 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
207 | - { |
|
208 | - // do nothing if form isn't for a reg step or test has already been passed |
|
209 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | - return; |
|
211 | - } |
|
212 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
213 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
214 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
215 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param EE_Form_Section_Proper $reg_form |
|
222 | - * @return bool |
|
223 | - * @throws InvalidDataTypeException |
|
224 | - * @throws InvalidInterfaceException |
|
225 | - * @throws EE_Error |
|
226 | - * @throws InvalidArgumentException |
|
227 | - */ |
|
228 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
229 | - { |
|
230 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
231 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param array|null $req_data |
|
237 | - * @param EE_Form_Section_Proper $reg_form |
|
238 | - * @return array |
|
239 | - * @throws EE_Error |
|
240 | - * @throws InvalidArgumentException |
|
241 | - * @throws InvalidDataTypeException |
|
242 | - * @throws InvalidInterfaceException |
|
243 | - * @throws RuntimeException |
|
244 | - */ |
|
245 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
246 | - { |
|
247 | - // do nothing if form isn't for a reg step or test has already been passed |
|
248 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | - return $req_data; |
|
250 | - } |
|
251 | - /** @var EE_Request $request */ |
|
252 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
253 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | - if ($request->isAjax()) { |
|
255 | - $json_response = new EE_SPCO_JSON_Response(); |
|
256 | - $json_response->echoAndExit(); |
|
257 | - } |
|
258 | - EEH_URL::safeRedirectAndExit( |
|
259 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
260 | - ); |
|
261 | - } |
|
262 | - return $req_data; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @param string $html |
|
268 | - * @param EE_Event $event |
|
269 | - * @param bool $iframe |
|
270 | - * @return string |
|
271 | - * @throws EE_Error |
|
272 | - * @throws InvalidArgumentException |
|
273 | - * @throws InvalidDataTypeException |
|
274 | - * @throws InvalidInterfaceException |
|
275 | - * @throws ReflectionException |
|
276 | - * @throws DomainException |
|
277 | - */ |
|
278 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
279 | - { |
|
280 | - $recaptcha = RecaptchaFactory::create(); |
|
281 | - // do nothing if test has already been passed |
|
282 | - if ($recaptcha->recaptchaPassed()) { |
|
283 | - return $html; |
|
284 | - } |
|
285 | - $html .= $recaptcha->getInputHtml( |
|
286 | - array( |
|
287 | - 'recaptcha_id' => $event->ID(), |
|
288 | - 'iframe' => $iframe, |
|
289 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
290 | - ) |
|
291 | - ); |
|
292 | - return $html; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @return void |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidInterfaceException |
|
300 | - * @throws InvalidDataTypeException |
|
301 | - * @throws RuntimeException |
|
302 | - */ |
|
303 | - public static function processTicketSelectorForm() |
|
304 | - { |
|
305 | - // do nothing if test has already been passed |
|
306 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
307 | - return; |
|
308 | - } |
|
309 | - /** @var EE_Request $request */ |
|
310 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
311 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | - $event_id = $request->get('tkt-slctr-event-id'); |
|
313 | - $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
314 | - ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
315 | - : get_permalink($event_id); |
|
316 | - EEH_URL::safeRedirectAndExit($return_url); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @throws EE_Error |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws InvalidDataTypeException |
|
325 | - * @throws InvalidInterfaceException |
|
326 | - */ |
|
327 | - public static function adminSettings() |
|
328 | - { |
|
329 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @param EE_Registration_Config $EE_Registration_Config |
|
335 | - * @return EE_Registration_Config |
|
336 | - * @throws EE_Error |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidDataTypeException |
|
339 | - * @throws InvalidInterfaceException |
|
340 | - * @throws ReflectionException |
|
341 | - */ |
|
342 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
343 | - { |
|
344 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
345 | - } |
|
24 | + /** |
|
25 | + * @var EE_Registration_Config $config |
|
26 | + */ |
|
27 | + private static $config; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @return EED_Module|EED_Recaptcha |
|
32 | + */ |
|
33 | + public static function instance() |
|
34 | + { |
|
35 | + return parent::get_instance(__CLASS__); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + * @throws InvalidInterfaceException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws InvalidArgumentException |
|
44 | + */ |
|
45 | + public static function set_hooks() |
|
46 | + { |
|
47 | + EED_Recaptcha_Invisible::setProperties(); |
|
48 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
49 | + if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
50 | + // ticket selection |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
53 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
54 | + 10, 3 |
|
55 | + ); |
|
56 | + add_action( |
|
57 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
58 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
59 | + ); |
|
60 | + } |
|
61 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
62 | + // checkout |
|
63 | + add_action( |
|
64 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
65 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
66 | + ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
69 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
70 | + 10, 2 |
|
71 | + ); |
|
72 | + } |
|
73 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + * @throws InvalidArgumentException |
|
83 | + */ |
|
84 | + public static function set_hooks_admin() |
|
85 | + { |
|
86 | + EED_Recaptcha_Invisible::setProperties(); |
|
87 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
88 | + add_action( |
|
89 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
90 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
91 | + ); |
|
92 | + } |
|
93 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
96 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
97 | + 10, 2 |
|
98 | + ); |
|
99 | + } |
|
100 | + // admin settings |
|
101 | + add_action( |
|
102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | + ); |
|
105 | + add_filter( |
|
106 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidArgumentException |
|
117 | + */ |
|
118 | + public static function setProperties() |
|
119 | + { |
|
120 | + |
|
121 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public static function useInvisibleRecaptcha() |
|
130 | + { |
|
131 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
132 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $form |
|
138 | + * @return boolean |
|
139 | + */ |
|
140 | + public static function protectForm($form) |
|
141 | + { |
|
142 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
143 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return void |
|
151 | + * @throws InvalidInterfaceException |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidArgumentException |
|
154 | + */ |
|
155 | + public static function localizeScriptVars() |
|
156 | + { |
|
157 | + wp_localize_script( |
|
158 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
159 | + 'eeRecaptcha', |
|
160 | + RecaptchaFactory::create()->getLocalizedVars() |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public static function assetsUrl() |
|
169 | + { |
|
170 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param \WP $WP |
|
176 | + */ |
|
177 | + public function run($WP) |
|
178 | + { |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param EE_Request $request |
|
185 | + * @return bool |
|
186 | + * @throws InvalidArgumentException |
|
187 | + * @throws InvalidDataTypeException |
|
188 | + * @throws InvalidInterfaceException |
|
189 | + * @throws RuntimeException |
|
190 | + */ |
|
191 | + public static function verifyToken(EE_Request $request) |
|
192 | + { |
|
193 | + return RecaptchaFactory::create()->verifyToken($request); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param EE_Form_Section_Proper $reg_form |
|
199 | + * @return void |
|
200 | + * @throws EE_Error |
|
201 | + * @throws InvalidArgumentException |
|
202 | + * @throws InvalidDataTypeException |
|
203 | + * @throws InvalidInterfaceException |
|
204 | + * @throws DomainException |
|
205 | + */ |
|
206 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
207 | + { |
|
208 | + // do nothing if form isn't for a reg step or test has already been passed |
|
209 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | + return; |
|
211 | + } |
|
212 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
213 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
214 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
215 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param EE_Form_Section_Proper $reg_form |
|
222 | + * @return bool |
|
223 | + * @throws InvalidDataTypeException |
|
224 | + * @throws InvalidInterfaceException |
|
225 | + * @throws EE_Error |
|
226 | + * @throws InvalidArgumentException |
|
227 | + */ |
|
228 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
229 | + { |
|
230 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
231 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param array|null $req_data |
|
237 | + * @param EE_Form_Section_Proper $reg_form |
|
238 | + * @return array |
|
239 | + * @throws EE_Error |
|
240 | + * @throws InvalidArgumentException |
|
241 | + * @throws InvalidDataTypeException |
|
242 | + * @throws InvalidInterfaceException |
|
243 | + * @throws RuntimeException |
|
244 | + */ |
|
245 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
246 | + { |
|
247 | + // do nothing if form isn't for a reg step or test has already been passed |
|
248 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | + return $req_data; |
|
250 | + } |
|
251 | + /** @var EE_Request $request */ |
|
252 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
253 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | + if ($request->isAjax()) { |
|
255 | + $json_response = new EE_SPCO_JSON_Response(); |
|
256 | + $json_response->echoAndExit(); |
|
257 | + } |
|
258 | + EEH_URL::safeRedirectAndExit( |
|
259 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
260 | + ); |
|
261 | + } |
|
262 | + return $req_data; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @param string $html |
|
268 | + * @param EE_Event $event |
|
269 | + * @param bool $iframe |
|
270 | + * @return string |
|
271 | + * @throws EE_Error |
|
272 | + * @throws InvalidArgumentException |
|
273 | + * @throws InvalidDataTypeException |
|
274 | + * @throws InvalidInterfaceException |
|
275 | + * @throws ReflectionException |
|
276 | + * @throws DomainException |
|
277 | + */ |
|
278 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
279 | + { |
|
280 | + $recaptcha = RecaptchaFactory::create(); |
|
281 | + // do nothing if test has already been passed |
|
282 | + if ($recaptcha->recaptchaPassed()) { |
|
283 | + return $html; |
|
284 | + } |
|
285 | + $html .= $recaptcha->getInputHtml( |
|
286 | + array( |
|
287 | + 'recaptcha_id' => $event->ID(), |
|
288 | + 'iframe' => $iframe, |
|
289 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
290 | + ) |
|
291 | + ); |
|
292 | + return $html; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @return void |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidInterfaceException |
|
300 | + * @throws InvalidDataTypeException |
|
301 | + * @throws RuntimeException |
|
302 | + */ |
|
303 | + public static function processTicketSelectorForm() |
|
304 | + { |
|
305 | + // do nothing if test has already been passed |
|
306 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
307 | + return; |
|
308 | + } |
|
309 | + /** @var EE_Request $request */ |
|
310 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
311 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | + $event_id = $request->get('tkt-slctr-event-id'); |
|
313 | + $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
314 | + ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
315 | + : get_permalink($event_id); |
|
316 | + EEH_URL::safeRedirectAndExit($return_url); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @throws EE_Error |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws InvalidDataTypeException |
|
325 | + * @throws InvalidInterfaceException |
|
326 | + */ |
|
327 | + public static function adminSettings() |
|
328 | + { |
|
329 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @param EE_Registration_Config $EE_Registration_Config |
|
335 | + * @return EE_Registration_Config |
|
336 | + * @throws EE_Error |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidDataTypeException |
|
339 | + * @throws InvalidInterfaceException |
|
340 | + * @throws ReflectionException |
|
341 | + */ |
|
342 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
343 | + { |
|
344 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
345 | + } |
|
346 | 346 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | EED_Recaptcha_Invisible::setProperties(); |
48 | 48 | if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
49 | - if(EED_Recaptcha_Invisible::protectForm('ticket_selector')){ |
|
49 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
50 | 50 | // ticket selection |
51 | 51 | add_filter( |
52 | 52 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public static function assetsUrl() |
169 | 169 | { |
170 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
170 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
207 | 207 | { |
208 | 208 | // do nothing if form isn't for a reg step or test has already been passed |
209 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
209 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
246 | 246 | { |
247 | 247 | // do nothing if form isn't for a reg step or test has already been passed |
248 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
248 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
249 | 249 | return $req_data; |
250 | 250 | } |
251 | 251 | /** @var EE_Request $request */ |
252 | 252 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
253 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
253 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
254 | 254 | if ($request->isAjax()) { |
255 | 255 | $json_response = new EE_SPCO_JSON_Response(); |
256 | 256 | $json_response->echoAndExit(); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | } |
309 | 309 | /** @var EE_Request $request */ |
310 | 310 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
311 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
311 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
312 | 312 | $event_id = $request->get('tkt-slctr-event-id'); |
313 | 313 | $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
314 | 314 | ? $request->get("tkt-slctr-return-url-{$event_id}") |
@@ -35,337 +35,337 @@ |
||
35 | 35 | class RecaptchaAdminSettings |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * @var EE_Registration_Config $config |
|
40 | - */ |
|
41 | - private $config; |
|
38 | + /** |
|
39 | + * @var EE_Registration_Config $config |
|
40 | + */ |
|
41 | + private $config; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * RecaptchaAdminSettings constructor. |
|
46 | - * |
|
47 | - * @param EE_Registration_Config $registration_config |
|
48 | - */ |
|
49 | - public function __construct(EE_Registration_Config $registration_config) |
|
50 | - { |
|
51 | - $this->config = $registration_config; |
|
52 | - } |
|
44 | + /** |
|
45 | + * RecaptchaAdminSettings constructor. |
|
46 | + * |
|
47 | + * @param EE_Registration_Config $registration_config |
|
48 | + */ |
|
49 | + public function __construct(EE_Registration_Config $registration_config) |
|
50 | + { |
|
51 | + $this->config = $registration_config; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - * @throws EE_Error |
|
60 | - */ |
|
61 | - public function adminSettings() |
|
62 | - { |
|
63 | - echo $this->settingsForm()->get_html_and_js(); |
|
64 | - } |
|
55 | + /** |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + * @throws EE_Error |
|
60 | + */ |
|
61 | + public function adminSettings() |
|
62 | + { |
|
63 | + echo $this->settingsForm()->get_html_and_js(); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @return EE_Form_Section_Proper |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - protected function settingsForm() |
|
72 | - { |
|
73 | - return new EE_Form_Section_Proper( |
|
74 | - array( |
|
75 | - 'name' => 'recaptcha_settings_form', |
|
76 | - 'html_id' => 'recaptcha_settings_form', |
|
77 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
78 | - 'subsections' => apply_filters( |
|
79 | - 'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections', |
|
80 | - array( |
|
81 | - 'main_settings_hdr' => new EE_Form_Section_HTML( |
|
82 | - EEH_HTML::h2( |
|
83 | - esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso') |
|
84 | - . EEH_Template::get_help_tab_link('recaptcha_info') |
|
85 | - ) |
|
86 | - ), |
|
87 | - 'main_settings' => $this->mainSettings(), |
|
88 | - 'appearance_settings_hdr' => new EE_Form_Section_HTML( |
|
89 | - EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso')) |
|
90 | - ), |
|
91 | - 'appearance_settings' => $this->appearanceSettings(), |
|
92 | - 'required_fields_note' => new EE_Form_Section_HTML( |
|
93 | - EEH_HTML::p( |
|
94 | - esc_html__('All fields marked with a * are required fields', 'event_espresso'), |
|
95 | - '', 'grey-text' |
|
96 | - ) |
|
97 | - ), |
|
98 | - ) |
|
99 | - ), |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
67 | + /** |
|
68 | + * @return EE_Form_Section_Proper |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + protected function settingsForm() |
|
72 | + { |
|
73 | + return new EE_Form_Section_Proper( |
|
74 | + array( |
|
75 | + 'name' => 'recaptcha_settings_form', |
|
76 | + 'html_id' => 'recaptcha_settings_form', |
|
77 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
78 | + 'subsections' => apply_filters( |
|
79 | + 'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections', |
|
80 | + array( |
|
81 | + 'main_settings_hdr' => new EE_Form_Section_HTML( |
|
82 | + EEH_HTML::h2( |
|
83 | + esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso') |
|
84 | + . EEH_Template::get_help_tab_link('recaptcha_info') |
|
85 | + ) |
|
86 | + ), |
|
87 | + 'main_settings' => $this->mainSettings(), |
|
88 | + 'appearance_settings_hdr' => new EE_Form_Section_HTML( |
|
89 | + EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso')) |
|
90 | + ), |
|
91 | + 'appearance_settings' => $this->appearanceSettings(), |
|
92 | + 'required_fields_note' => new EE_Form_Section_HTML( |
|
93 | + EEH_HTML::p( |
|
94 | + esc_html__('All fields marked with a * are required fields', 'event_espresso'), |
|
95 | + '', 'grey-text' |
|
96 | + ) |
|
97 | + ), |
|
98 | + ) |
|
99 | + ), |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * @return EE_Form_Section_Proper |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - protected function mainSettings() |
|
110 | - { |
|
111 | - return new EE_Form_Section_Proper( |
|
112 | - array( |
|
113 | - 'name' => 'recaptcha_settings_tbl', |
|
114 | - 'html_id' => 'recaptcha_settings_tbl', |
|
115 | - 'html_class' => 'form-table', |
|
116 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
117 | - 'subsections' => apply_filters( |
|
118 | - 'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections', |
|
119 | - array( |
|
120 | - 'use_captcha' => new EE_Yes_No_Input( |
|
121 | - array( |
|
122 | - 'html_label_text' => esc_html__('Use reCAPTCHA', 'event_espresso'), |
|
123 | - 'html_help_text' => sprintf( |
|
124 | - esc_html__('reCAPTCHA is a free service that protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', |
|
125 | - 'event_espresso'), |
|
126 | - '<a href="https://www.google.com/recaptcha/intro/index.html">', |
|
127 | - '</a>' |
|
128 | - ), |
|
129 | - 'default' => $this->config->use_captcha !== null |
|
130 | - ? $this->config->use_captcha : false, |
|
131 | - 'display_html_label_text' => false, |
|
132 | - ) |
|
133 | - ), |
|
134 | - 'recaptcha_publickey' => new EE_Text_Input( |
|
135 | - array( |
|
136 | - 'html_label_text' => esc_html__('Site Key', 'event_espresso'), |
|
137 | - 'html_help_text' => esc_html__('The site key is used to display the widget on your site.', |
|
138 | - 'event_espresso'), |
|
139 | - 'default' => $this->config->recaptcha_publickey !== null |
|
140 | - ? stripslashes($this->config->recaptcha_publickey) : '', |
|
141 | - ) |
|
142 | - ), |
|
143 | - 'recaptcha_privatekey' => new EE_Text_Input( |
|
144 | - array( |
|
145 | - 'html_label_text' => esc_html__('Secret Key', 'event_espresso'), |
|
146 | - 'html_help_text' => esc_html__('The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', |
|
147 | - 'event_espresso'), |
|
148 | - 'default' => $this->config->recaptcha_privatekey !== null |
|
149 | - ? stripslashes($this->config->recaptcha_privatekey) |
|
150 | - : '', |
|
151 | - ) |
|
152 | - ), |
|
153 | - 'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input( |
|
154 | - array( |
|
155 | - 'ticket_selector' => esc_html__('Ticket Selector', 'event_espresso'), |
|
156 | - 'registration_form' => esc_html__('Registration Form', 'event_espresso'), |
|
157 | - ), |
|
158 | - array( |
|
159 | - 'html_label_text' => esc_html__('Invisible reCAPTCHA Protection', 'event_espresso'), |
|
160 | - 'html_help_text' => esc_html__('Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.', |
|
161 | - 'event_espresso'), |
|
162 | - 'default' => is_array($this->config->recaptcha_protected_forms) |
|
163 | - ? $this->config->recaptcha_protected_forms |
|
164 | - : array(), |
|
165 | - 'display_html_label_text' => false, |
|
166 | - ) |
|
167 | - ), |
|
168 | - ) |
|
169 | - ), |
|
170 | - ) |
|
171 | - ); |
|
172 | - } |
|
105 | + /** |
|
106 | + * @return EE_Form_Section_Proper |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + protected function mainSettings() |
|
110 | + { |
|
111 | + return new EE_Form_Section_Proper( |
|
112 | + array( |
|
113 | + 'name' => 'recaptcha_settings_tbl', |
|
114 | + 'html_id' => 'recaptcha_settings_tbl', |
|
115 | + 'html_class' => 'form-table', |
|
116 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
117 | + 'subsections' => apply_filters( |
|
118 | + 'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections', |
|
119 | + array( |
|
120 | + 'use_captcha' => new EE_Yes_No_Input( |
|
121 | + array( |
|
122 | + 'html_label_text' => esc_html__('Use reCAPTCHA', 'event_espresso'), |
|
123 | + 'html_help_text' => sprintf( |
|
124 | + esc_html__('reCAPTCHA is a free service that protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', |
|
125 | + 'event_espresso'), |
|
126 | + '<a href="https://www.google.com/recaptcha/intro/index.html">', |
|
127 | + '</a>' |
|
128 | + ), |
|
129 | + 'default' => $this->config->use_captcha !== null |
|
130 | + ? $this->config->use_captcha : false, |
|
131 | + 'display_html_label_text' => false, |
|
132 | + ) |
|
133 | + ), |
|
134 | + 'recaptcha_publickey' => new EE_Text_Input( |
|
135 | + array( |
|
136 | + 'html_label_text' => esc_html__('Site Key', 'event_espresso'), |
|
137 | + 'html_help_text' => esc_html__('The site key is used to display the widget on your site.', |
|
138 | + 'event_espresso'), |
|
139 | + 'default' => $this->config->recaptcha_publickey !== null |
|
140 | + ? stripslashes($this->config->recaptcha_publickey) : '', |
|
141 | + ) |
|
142 | + ), |
|
143 | + 'recaptcha_privatekey' => new EE_Text_Input( |
|
144 | + array( |
|
145 | + 'html_label_text' => esc_html__('Secret Key', 'event_espresso'), |
|
146 | + 'html_help_text' => esc_html__('The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', |
|
147 | + 'event_espresso'), |
|
148 | + 'default' => $this->config->recaptcha_privatekey !== null |
|
149 | + ? stripslashes($this->config->recaptcha_privatekey) |
|
150 | + : '', |
|
151 | + ) |
|
152 | + ), |
|
153 | + 'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input( |
|
154 | + array( |
|
155 | + 'ticket_selector' => esc_html__('Ticket Selector', 'event_espresso'), |
|
156 | + 'registration_form' => esc_html__('Registration Form', 'event_espresso'), |
|
157 | + ), |
|
158 | + array( |
|
159 | + 'html_label_text' => esc_html__('Invisible reCAPTCHA Protection', 'event_espresso'), |
|
160 | + 'html_help_text' => esc_html__('Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.', |
|
161 | + 'event_espresso'), |
|
162 | + 'default' => is_array($this->config->recaptcha_protected_forms) |
|
163 | + ? $this->config->recaptcha_protected_forms |
|
164 | + : array(), |
|
165 | + 'display_html_label_text' => false, |
|
166 | + ) |
|
167 | + ), |
|
168 | + ) |
|
169 | + ), |
|
170 | + ) |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * @return EE_Form_Section_Proper |
|
177 | - * @throws EE_Error |
|
178 | - */ |
|
179 | - protected function appearanceSettings() |
|
180 | - { |
|
181 | - return new EE_Form_Section_Proper( |
|
182 | - array( |
|
183 | - 'name' => 'recaptcha_appearance_settings_tbl', |
|
184 | - 'html_id' => 'recaptcha_appearance_settings_tbl', |
|
185 | - 'html_class' => 'form-table', |
|
186 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
187 | - 'subsections' => apply_filters( |
|
188 | - 'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections', |
|
189 | - array( |
|
190 | - 'recaptcha_theme' => new EE_Radio_Button_Input( |
|
191 | - array( |
|
192 | - 'invisible' => esc_html__('Invisible', 'event_espresso'), |
|
193 | - 'light' => esc_html__('Light', 'event_espresso'), |
|
194 | - 'dark' => esc_html__('Dark', 'event_espresso'), |
|
195 | - ), |
|
196 | - array( |
|
197 | - 'html_label_text' => esc_html__('Theme', 'event_espresso'), |
|
198 | - 'html_help_text' => esc_html__('The color theme of the widget.', |
|
199 | - 'event_espresso'), |
|
200 | - 'default' => $this->config->recaptcha_theme !== null |
|
201 | - ? $this->config->recaptcha_theme |
|
202 | - : 'invisible', |
|
203 | - 'display_html_label_text' => false, |
|
204 | - ) |
|
205 | - ), |
|
206 | - 'recaptcha_badge' => new EE_Radio_Button_Input( |
|
207 | - array( |
|
208 | - 'bottomleft' => esc_html__('Bottom Left', 'event_espresso'), |
|
209 | - 'bottomright' => esc_html__('Bottom Right', 'event_espresso'), |
|
210 | - 'inline' => esc_html__('Inline', 'event_espresso'), |
|
211 | - ), |
|
212 | - array( |
|
213 | - 'html_label_text' => esc_html__('Invisible reCAPTCHA Badge Position', 'event_espresso'), |
|
214 | - 'html_help_text' => esc_html__( |
|
215 | - 'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - 'default' => $this->config->recaptcha_badge !== null |
|
219 | - ? $this->config->recaptcha_badge |
|
220 | - : 'bottomleft', |
|
221 | - 'display_html_label_text' => false, |
|
222 | - ) |
|
223 | - ), |
|
224 | - 'recaptcha_type' => new EE_Radio_Button_Input( |
|
225 | - array( |
|
226 | - 'image' => esc_html__('Image', 'event_espresso'), |
|
227 | - 'audio' => esc_html__('Audio', 'event_espresso'), |
|
228 | - ), |
|
229 | - array( |
|
230 | - 'html_label_text' => esc_html__('Type', 'event_espresso'), |
|
231 | - 'html_help_text' => esc_html__('The type of CAPTCHA to serve.', |
|
232 | - 'event_espresso'), |
|
233 | - 'default' => $this->config->recaptcha_type !== null |
|
234 | - ? $this->config->recaptcha_type |
|
235 | - : 'image', |
|
236 | - 'display_html_label_text' => false, |
|
237 | - ) |
|
238 | - ), |
|
239 | - 'recaptcha_language' => new EE_Select_Input( |
|
240 | - array( |
|
241 | - 'ar' => esc_html__('Arabic', 'event_espresso'), |
|
242 | - 'bg' => esc_html__('Bulgarian', 'event_espresso'), |
|
243 | - 'ca' => esc_html__('Catalan', 'event_espresso'), |
|
244 | - 'zh-CN' => esc_html__('Chinese (Simplified)', 'event_espresso'), |
|
245 | - 'zh-TW' => esc_html__('Chinese (Traditional) ', 'event_espresso'), |
|
246 | - 'hr' => esc_html__('Croatian', 'event_espresso'), |
|
247 | - 'cs' => esc_html__('Czech', 'event_espresso'), |
|
248 | - 'da' => esc_html__('Danish', 'event_espresso'), |
|
249 | - 'nl' => esc_html__('Dutch', 'event_espresso'), |
|
250 | - 'en-GB' => esc_html__('English (UK)', 'event_espresso'), |
|
251 | - 'en' => esc_html__('English (US)', 'event_espresso'), |
|
252 | - 'fil' => esc_html__('Filipino', 'event_espresso'), |
|
253 | - 'fi' => esc_html__('Finnish', 'event_espresso'), |
|
254 | - 'fr' => esc_html__('French', 'event_espresso'), |
|
255 | - 'fr-CA' => esc_html__('French (Canadian)', 'event_espresso'), |
|
256 | - 'de' => esc_html__('German', 'event_espresso'), |
|
257 | - 'de-AT' => esc_html__('German (Austria)', 'event_espresso'), |
|
258 | - 'de-CH' => esc_html__('German (Switzerland)', 'event_espresso'), |
|
259 | - 'el' => esc_html__('Greek', 'event_espresso'), |
|
260 | - 'iw' => esc_html__('Hebrew', 'event_espresso'), |
|
261 | - 'hi' => esc_html__('Hindi', 'event_espresso'), |
|
262 | - 'hu' => esc_html__('Hungarian', 'event_espresso'), |
|
263 | - 'id' => esc_html__('Indonesian', 'event_espresso'), |
|
264 | - 'it' => esc_html__('Italian', 'event_espresso'), |
|
265 | - 'ja' => esc_html__('Japanese', 'event_espresso'), |
|
266 | - 'ko' => esc_html__('Korean', 'event_espresso'), |
|
267 | - 'lv' => esc_html__('Latvian', 'event_espresso'), |
|
268 | - 'lt' => esc_html__('Lithuanian', 'event_espresso'), |
|
269 | - 'no' => esc_html__('Norwegian', 'event_espresso'), |
|
270 | - 'fa' => esc_html__('Persian', 'event_espresso'), |
|
271 | - 'pl' => esc_html__('Polish', 'event_espresso'), |
|
272 | - 'pt' => esc_html__('Portuguese', 'event_espresso'), |
|
273 | - 'pt-BR' => esc_html__('Portuguese (Brazil)', 'event_espresso'), |
|
274 | - 'pt-PT' => esc_html__('Portuguese (Portugal)', 'event_espresso'), |
|
275 | - 'ro' => esc_html__('Romanian', 'event_espresso'), |
|
276 | - 'ru' => esc_html__('Russian', 'event_espresso'), |
|
277 | - 'sr' => esc_html__('Serbian', 'event_espresso'), |
|
278 | - 'sk' => esc_html__('Slovak', 'event_espresso'), |
|
279 | - 'sl' => esc_html__('Slovenian', 'event_espresso'), |
|
280 | - 'es' => esc_html__('Spanish', 'event_espresso'), |
|
281 | - 'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'), |
|
282 | - 'sv' => esc_html__('Swedish', 'event_espresso'), |
|
283 | - 'th' => esc_html__('Thai', 'event_espresso'), |
|
284 | - 'tr' => esc_html__('Turkish', 'event_espresso'), |
|
285 | - 'uk' => esc_html__('Ukrainian', 'event_espresso'), |
|
286 | - 'vi' => esc_html__('Vietnamese', 'event_espresso'), |
|
287 | - ), |
|
288 | - array( |
|
289 | - 'html_label_text' => esc_html__('Language', 'event_espresso'), |
|
290 | - 'html_help_text' => esc_html__('Forces the widget to render in a specific language.', |
|
291 | - 'event_espresso'), |
|
292 | - 'default' => $this->config->recaptcha_language !== null |
|
293 | - ? $this->config->recaptcha_language : 'en', |
|
294 | - ) |
|
295 | - ), |
|
296 | - ) |
|
297 | - ), |
|
298 | - ) |
|
299 | - ); |
|
300 | - } |
|
175 | + /** |
|
176 | + * @return EE_Form_Section_Proper |
|
177 | + * @throws EE_Error |
|
178 | + */ |
|
179 | + protected function appearanceSettings() |
|
180 | + { |
|
181 | + return new EE_Form_Section_Proper( |
|
182 | + array( |
|
183 | + 'name' => 'recaptcha_appearance_settings_tbl', |
|
184 | + 'html_id' => 'recaptcha_appearance_settings_tbl', |
|
185 | + 'html_class' => 'form-table', |
|
186 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
187 | + 'subsections' => apply_filters( |
|
188 | + 'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections', |
|
189 | + array( |
|
190 | + 'recaptcha_theme' => new EE_Radio_Button_Input( |
|
191 | + array( |
|
192 | + 'invisible' => esc_html__('Invisible', 'event_espresso'), |
|
193 | + 'light' => esc_html__('Light', 'event_espresso'), |
|
194 | + 'dark' => esc_html__('Dark', 'event_espresso'), |
|
195 | + ), |
|
196 | + array( |
|
197 | + 'html_label_text' => esc_html__('Theme', 'event_espresso'), |
|
198 | + 'html_help_text' => esc_html__('The color theme of the widget.', |
|
199 | + 'event_espresso'), |
|
200 | + 'default' => $this->config->recaptcha_theme !== null |
|
201 | + ? $this->config->recaptcha_theme |
|
202 | + : 'invisible', |
|
203 | + 'display_html_label_text' => false, |
|
204 | + ) |
|
205 | + ), |
|
206 | + 'recaptcha_badge' => new EE_Radio_Button_Input( |
|
207 | + array( |
|
208 | + 'bottomleft' => esc_html__('Bottom Left', 'event_espresso'), |
|
209 | + 'bottomright' => esc_html__('Bottom Right', 'event_espresso'), |
|
210 | + 'inline' => esc_html__('Inline', 'event_espresso'), |
|
211 | + ), |
|
212 | + array( |
|
213 | + 'html_label_text' => esc_html__('Invisible reCAPTCHA Badge Position', 'event_espresso'), |
|
214 | + 'html_help_text' => esc_html__( |
|
215 | + 'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + 'default' => $this->config->recaptcha_badge !== null |
|
219 | + ? $this->config->recaptcha_badge |
|
220 | + : 'bottomleft', |
|
221 | + 'display_html_label_text' => false, |
|
222 | + ) |
|
223 | + ), |
|
224 | + 'recaptcha_type' => new EE_Radio_Button_Input( |
|
225 | + array( |
|
226 | + 'image' => esc_html__('Image', 'event_espresso'), |
|
227 | + 'audio' => esc_html__('Audio', 'event_espresso'), |
|
228 | + ), |
|
229 | + array( |
|
230 | + 'html_label_text' => esc_html__('Type', 'event_espresso'), |
|
231 | + 'html_help_text' => esc_html__('The type of CAPTCHA to serve.', |
|
232 | + 'event_espresso'), |
|
233 | + 'default' => $this->config->recaptcha_type !== null |
|
234 | + ? $this->config->recaptcha_type |
|
235 | + : 'image', |
|
236 | + 'display_html_label_text' => false, |
|
237 | + ) |
|
238 | + ), |
|
239 | + 'recaptcha_language' => new EE_Select_Input( |
|
240 | + array( |
|
241 | + 'ar' => esc_html__('Arabic', 'event_espresso'), |
|
242 | + 'bg' => esc_html__('Bulgarian', 'event_espresso'), |
|
243 | + 'ca' => esc_html__('Catalan', 'event_espresso'), |
|
244 | + 'zh-CN' => esc_html__('Chinese (Simplified)', 'event_espresso'), |
|
245 | + 'zh-TW' => esc_html__('Chinese (Traditional) ', 'event_espresso'), |
|
246 | + 'hr' => esc_html__('Croatian', 'event_espresso'), |
|
247 | + 'cs' => esc_html__('Czech', 'event_espresso'), |
|
248 | + 'da' => esc_html__('Danish', 'event_espresso'), |
|
249 | + 'nl' => esc_html__('Dutch', 'event_espresso'), |
|
250 | + 'en-GB' => esc_html__('English (UK)', 'event_espresso'), |
|
251 | + 'en' => esc_html__('English (US)', 'event_espresso'), |
|
252 | + 'fil' => esc_html__('Filipino', 'event_espresso'), |
|
253 | + 'fi' => esc_html__('Finnish', 'event_espresso'), |
|
254 | + 'fr' => esc_html__('French', 'event_espresso'), |
|
255 | + 'fr-CA' => esc_html__('French (Canadian)', 'event_espresso'), |
|
256 | + 'de' => esc_html__('German', 'event_espresso'), |
|
257 | + 'de-AT' => esc_html__('German (Austria)', 'event_espresso'), |
|
258 | + 'de-CH' => esc_html__('German (Switzerland)', 'event_espresso'), |
|
259 | + 'el' => esc_html__('Greek', 'event_espresso'), |
|
260 | + 'iw' => esc_html__('Hebrew', 'event_espresso'), |
|
261 | + 'hi' => esc_html__('Hindi', 'event_espresso'), |
|
262 | + 'hu' => esc_html__('Hungarian', 'event_espresso'), |
|
263 | + 'id' => esc_html__('Indonesian', 'event_espresso'), |
|
264 | + 'it' => esc_html__('Italian', 'event_espresso'), |
|
265 | + 'ja' => esc_html__('Japanese', 'event_espresso'), |
|
266 | + 'ko' => esc_html__('Korean', 'event_espresso'), |
|
267 | + 'lv' => esc_html__('Latvian', 'event_espresso'), |
|
268 | + 'lt' => esc_html__('Lithuanian', 'event_espresso'), |
|
269 | + 'no' => esc_html__('Norwegian', 'event_espresso'), |
|
270 | + 'fa' => esc_html__('Persian', 'event_espresso'), |
|
271 | + 'pl' => esc_html__('Polish', 'event_espresso'), |
|
272 | + 'pt' => esc_html__('Portuguese', 'event_espresso'), |
|
273 | + 'pt-BR' => esc_html__('Portuguese (Brazil)', 'event_espresso'), |
|
274 | + 'pt-PT' => esc_html__('Portuguese (Portugal)', 'event_espresso'), |
|
275 | + 'ro' => esc_html__('Romanian', 'event_espresso'), |
|
276 | + 'ru' => esc_html__('Russian', 'event_espresso'), |
|
277 | + 'sr' => esc_html__('Serbian', 'event_espresso'), |
|
278 | + 'sk' => esc_html__('Slovak', 'event_espresso'), |
|
279 | + 'sl' => esc_html__('Slovenian', 'event_espresso'), |
|
280 | + 'es' => esc_html__('Spanish', 'event_espresso'), |
|
281 | + 'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'), |
|
282 | + 'sv' => esc_html__('Swedish', 'event_espresso'), |
|
283 | + 'th' => esc_html__('Thai', 'event_espresso'), |
|
284 | + 'tr' => esc_html__('Turkish', 'event_espresso'), |
|
285 | + 'uk' => esc_html__('Ukrainian', 'event_espresso'), |
|
286 | + 'vi' => esc_html__('Vietnamese', 'event_espresso'), |
|
287 | + ), |
|
288 | + array( |
|
289 | + 'html_label_text' => esc_html__('Language', 'event_espresso'), |
|
290 | + 'html_help_text' => esc_html__('Forces the widget to render in a specific language.', |
|
291 | + 'event_espresso'), |
|
292 | + 'default' => $this->config->recaptcha_language !== null |
|
293 | + ? $this->config->recaptcha_language : 'en', |
|
294 | + ) |
|
295 | + ), |
|
296 | + ) |
|
297 | + ), |
|
298 | + ) |
|
299 | + ); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * @param EE_Registration_Config $EE_Registration_Config |
|
305 | - * @return EE_Registration_Config |
|
306 | - * @throws InvalidArgumentException |
|
307 | - * @throws InvalidInterfaceException |
|
308 | - * @throws InvalidDataTypeException |
|
309 | - * @throws EE_Error |
|
310 | - * @throws ReflectionException |
|
311 | - */ |
|
312 | - public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
313 | - { |
|
314 | - try { |
|
315 | - $recaptcha_settings_form = $this->settingsForm(); |
|
316 | - // if not displaying a form, then check for form submission |
|
317 | - if ($recaptcha_settings_form->was_submitted()) { |
|
318 | - // capture form data |
|
319 | - $recaptcha_settings_form->receive_form_submission(); |
|
320 | - // validate form data |
|
321 | - if ($recaptcha_settings_form->is_valid()) { |
|
322 | - // grab validated data from form |
|
323 | - $valid_data = $recaptcha_settings_form->valid_data(); |
|
324 | - // user proofing recaptcha: If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message. |
|
325 | - if ( |
|
326 | - $valid_data['main_settings']['use_captcha'] |
|
327 | - && ( |
|
328 | - ! $EE_Registration_Config->use_captcha |
|
329 | - && ( |
|
330 | - empty($valid_data['main_settings']['recaptcha_publickey']) |
|
331 | - || empty($valid_data['main_settings']['recaptcha_privatekey']) |
|
332 | - ) |
|
333 | - ) |
|
334 | - && apply_filters( |
|
335 | - 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', |
|
336 | - true, |
|
337 | - $EE_Registration_Config |
|
338 | - ) |
|
339 | - ) { |
|
340 | - $valid_data['main_settings']['use_captcha'] = false; |
|
341 | - EE_Error::add_error( |
|
342 | - esc_html__( |
|
343 | - 'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', |
|
344 | - 'event_espresso' |
|
345 | - ), |
|
346 | - __FILE__, __FUNCTION__, __LINE__ |
|
347 | - ); |
|
348 | - } |
|
349 | - $EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha']; |
|
350 | - $EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey']; |
|
351 | - $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms']; |
|
352 | - $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey']; |
|
353 | - $EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type']; |
|
354 | - $EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme']; |
|
355 | - $EE_Registration_Config->recaptcha_badge = $valid_data['appearance_settings']['recaptcha_badge']; |
|
356 | - $EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language']; |
|
357 | - } else { |
|
358 | - if ($recaptcha_settings_form->submission_error_message() !== '') { |
|
359 | - EE_Error::add_error( |
|
360 | - $recaptcha_settings_form->submission_error_message(), |
|
361 | - __FILE__, __FUNCTION__, __LINE__ |
|
362 | - ); |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - } catch (EE_Error $e) { |
|
367 | - $e->get_error(); |
|
368 | - } |
|
369 | - return $EE_Registration_Config; |
|
370 | - } |
|
303 | + /** |
|
304 | + * @param EE_Registration_Config $EE_Registration_Config |
|
305 | + * @return EE_Registration_Config |
|
306 | + * @throws InvalidArgumentException |
|
307 | + * @throws InvalidInterfaceException |
|
308 | + * @throws InvalidDataTypeException |
|
309 | + * @throws EE_Error |
|
310 | + * @throws ReflectionException |
|
311 | + */ |
|
312 | + public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
313 | + { |
|
314 | + try { |
|
315 | + $recaptcha_settings_form = $this->settingsForm(); |
|
316 | + // if not displaying a form, then check for form submission |
|
317 | + if ($recaptcha_settings_form->was_submitted()) { |
|
318 | + // capture form data |
|
319 | + $recaptcha_settings_form->receive_form_submission(); |
|
320 | + // validate form data |
|
321 | + if ($recaptcha_settings_form->is_valid()) { |
|
322 | + // grab validated data from form |
|
323 | + $valid_data = $recaptcha_settings_form->valid_data(); |
|
324 | + // user proofing recaptcha: If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message. |
|
325 | + if ( |
|
326 | + $valid_data['main_settings']['use_captcha'] |
|
327 | + && ( |
|
328 | + ! $EE_Registration_Config->use_captcha |
|
329 | + && ( |
|
330 | + empty($valid_data['main_settings']['recaptcha_publickey']) |
|
331 | + || empty($valid_data['main_settings']['recaptcha_privatekey']) |
|
332 | + ) |
|
333 | + ) |
|
334 | + && apply_filters( |
|
335 | + 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', |
|
336 | + true, |
|
337 | + $EE_Registration_Config |
|
338 | + ) |
|
339 | + ) { |
|
340 | + $valid_data['main_settings']['use_captcha'] = false; |
|
341 | + EE_Error::add_error( |
|
342 | + esc_html__( |
|
343 | + 'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', |
|
344 | + 'event_espresso' |
|
345 | + ), |
|
346 | + __FILE__, __FUNCTION__, __LINE__ |
|
347 | + ); |
|
348 | + } |
|
349 | + $EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha']; |
|
350 | + $EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey']; |
|
351 | + $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms']; |
|
352 | + $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey']; |
|
353 | + $EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type']; |
|
354 | + $EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme']; |
|
355 | + $EE_Registration_Config->recaptcha_badge = $valid_data['appearance_settings']['recaptcha_badge']; |
|
356 | + $EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language']; |
|
357 | + } else { |
|
358 | + if ($recaptcha_settings_form->submission_error_message() !== '') { |
|
359 | + EE_Error::add_error( |
|
360 | + $recaptcha_settings_form->submission_error_message(), |
|
361 | + __FILE__, __FUNCTION__, __LINE__ |
|
362 | + ); |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + } catch (EE_Error $e) { |
|
367 | + $e->get_error(); |
|
368 | + } |
|
369 | + return $EE_Registration_Config; |
|
370 | + } |
|
371 | 371 | } |
@@ -14,1529 +14,1529 @@ |
||
14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
15 | 15 | { |
16 | 16 | |
17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | - |
|
19 | - /** |
|
20 | - * Subsections |
|
21 | - * |
|
22 | - * @var EE_Form_Section_Validatable[] |
|
23 | - */ |
|
24 | - protected $_subsections = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Strategy for laying out the form |
|
28 | - * |
|
29 | - * @var EE_Form_Section_Layout_Base |
|
30 | - */ |
|
31 | - protected $_layout_strategy; |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether or not this form has received and validated a form submission yet |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_received_submission = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * message displayed to users upon successful form submission |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_form_submission_success_message = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * message displayed to users upon unsuccessful form submission |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_form_submission_error_message = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array like $_REQUEST |
|
56 | - */ |
|
57 | - protected $cached_request_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | - * @var boolean|null |
|
63 | - */ |
|
64 | - protected $is_valid; |
|
65 | - |
|
66 | - /** |
|
67 | - * Stores all the data that will localized for form validation |
|
68 | - * |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - static protected $_js_localization = array(); |
|
72 | - |
|
73 | - /** |
|
74 | - * whether or not the form's localized validation JS vars have been set |
|
75 | - * |
|
76 | - * @type boolean |
|
77 | - */ |
|
78 | - static protected $_scripts_localized = false; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * when constructing a proper form section, calls _construct_finalize on children |
|
83 | - * so that they know who their parent is, and what name they've been given. |
|
84 | - * |
|
85 | - * @param array[] $options_array { |
|
86 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | - * and in that order. This is handy if you want |
|
89 | - * the subsections to be ordered differently than the default, and if you override |
|
90 | - * which fields are shown |
|
91 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | - * items from that list of inclusions) |
|
95 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | - * } @see EE_Form_Section_Validatable::__construct() |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public function __construct($options_array = array()) |
|
100 | - { |
|
101 | - $options_array = (array) apply_filters( |
|
102 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | - $options_array, |
|
104 | - $this |
|
105 | - ); |
|
106 | - //call parent first, as it may be setting the name |
|
107 | - parent::__construct($options_array); |
|
108 | - //if they've included subsections in the constructor, add them now |
|
109 | - if (isset($options_array['include'])) { |
|
110 | - //we are going to make sure we ONLY have those subsections to include |
|
111 | - //AND we are going to make sure they're in that specified order |
|
112 | - $reordered_subsections = array(); |
|
113 | - foreach ($options_array['include'] as $input_name) { |
|
114 | - if (isset($this->_subsections[ $input_name ])) { |
|
115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | - } |
|
117 | - } |
|
118 | - $this->_subsections = $reordered_subsections; |
|
119 | - } |
|
120 | - if (isset($options_array['exclude'])) { |
|
121 | - $exclude = $options_array['exclude']; |
|
122 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | - } |
|
124 | - if (isset($options_array['layout_strategy'])) { |
|
125 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | - } |
|
127 | - if (! $this->_layout_strategy) { |
|
128 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | - } |
|
130 | - $this->_layout_strategy->_construct_finalize($this); |
|
131 | - //ok so we are definitely going to want the forms JS, |
|
132 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | - //ok so they've constructed this object after when they should have. |
|
135 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | - } else { |
|
138 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | - } |
|
141 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | - /** |
|
143 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | - * The form probably doesn't yet have a parent form section. |
|
145 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | - * |
|
149 | - * @since 4.9.32 |
|
150 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | - * except maybe calling _construct_finalize has been done |
|
152 | - * @param array $options_array options passed into the constructor |
|
153 | - */ |
|
154 | - do_action( |
|
155 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | - $this, |
|
157 | - $options_array |
|
158 | - ); |
|
159 | - if (isset($options_array['name'])) { |
|
160 | - $this->_construct_finalize(null, $options_array['name']); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Finishes construction given the parent form section and this form section's name |
|
167 | - * |
|
168 | - * @param EE_Form_Section_Proper $parent_form_section |
|
169 | - * @param string $name |
|
170 | - * @throws EE_Error |
|
171 | - */ |
|
172 | - public function _construct_finalize($parent_form_section, $name) |
|
173 | - { |
|
174 | - parent::_construct_finalize($parent_form_section, $name); |
|
175 | - $this->_set_default_name_if_empty(); |
|
176 | - $this->_set_default_html_id_if_empty(); |
|
177 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | - $subsection->_construct_finalize($this, $subsection_name); |
|
180 | - } else { |
|
181 | - throw new EE_Error( |
|
182 | - sprintf( |
|
183 | - esc_html__( |
|
184 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - $subsection_name, |
|
188 | - get_class($this), |
|
189 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - } |
|
194 | - /** |
|
195 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | - * ensured it has a name, HTML IDs, etc |
|
201 | - * |
|
202 | - * @param EE_Form_Section_Proper $this |
|
203 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | - * @param string $name |
|
205 | - */ |
|
206 | - do_action( |
|
207 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | - $this, |
|
209 | - $parent_form_section, |
|
210 | - $name |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Gets the layout strategy for this form section |
|
217 | - * |
|
218 | - * @return EE_Form_Section_Layout_Base |
|
219 | - */ |
|
220 | - public function get_layout_strategy() |
|
221 | - { |
|
222 | - return $this->_layout_strategy; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Gets the HTML for a single input for this form section according |
|
228 | - * to the layout strategy |
|
229 | - * |
|
230 | - * @param EE_Form_Input_Base $input |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function get_html_for_input($input) |
|
234 | - { |
|
235 | - return $this->_layout_strategy->layout_input($input); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * was_submitted - checks if form inputs are present in request data |
|
241 | - * Basically an alias for form_data_present_in() (which is used by both |
|
242 | - * proper form sections and form inputs) |
|
243 | - * |
|
244 | - * @param null $form_data |
|
245 | - * @return boolean |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function was_submitted($form_data = null) |
|
249 | - { |
|
250 | - return $this->form_data_present_in($form_data); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | - * something different, refresh the cache, and then return it |
|
256 | - * @param null $req_data |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - protected function getCachedRequest($req_data = null) |
|
260 | - { |
|
261 | - if ($this->cached_request_data === null |
|
262 | - || ( |
|
263 | - $req_data !== null && |
|
264 | - $req_data !== $this->cached_request_data |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $req_data = apply_filters( |
|
268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | - $req_data, |
|
270 | - $this |
|
271 | - ); |
|
272 | - if ($req_data === null) { |
|
273 | - $req_data = array_merge($_GET, $_POST); |
|
274 | - } |
|
275 | - $req_data = apply_filters( |
|
276 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | - $req_data, |
|
278 | - $this |
|
279 | - ); |
|
280 | - $this->cached_request_data = (array)$req_data; |
|
281 | - } |
|
282 | - return $this->cached_request_data; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | - * |
|
290 | - * @param array|null $req_data should usually be $_POST (the default). |
|
291 | - * However, you CAN supply a different array. |
|
292 | - * Consider using set_defaults() instead however. |
|
293 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | - * the inputs will have the correct name in the request data for this function |
|
295 | - * to find them and populate the form with them. |
|
296 | - * If you have a flat form (with only input subsections), |
|
297 | - * you can supply a flat array where keys |
|
298 | - * are the form input names and values are their values) |
|
299 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | - * of course, to validate that data, and set errors on the invalid values. |
|
301 | - * But if the data has already been validated |
|
302 | - * (eg you validated the data then stored it in the DB) |
|
303 | - * you may want to skip this step. |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws InvalidInterfaceException |
|
306 | - * @throws InvalidDataTypeException |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function receive_form_submission($req_data = null, $validate = true) |
|
310 | - { |
|
311 | - $req_data = $this->getCachedRequest($req_data); |
|
312 | - $this->_normalize($req_data); |
|
313 | - if ($validate) { |
|
314 | - $this->_validate(); |
|
315 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | - if (! $this->is_valid()) { |
|
317 | - $this->store_submitted_form_data_in_session(); |
|
318 | - } |
|
319 | - } |
|
320 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | - $this->set_submission_error_message(); |
|
322 | - } |
|
323 | - do_action( |
|
324 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | - $req_data, |
|
326 | - $this, |
|
327 | - $validate |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * caches the originally submitted input values in the session |
|
334 | - * so that they can be used to repopulate the form if it failed validation |
|
335 | - * |
|
336 | - * @return boolean whether or not the data was successfully stored in the session |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidInterfaceException |
|
339 | - * @throws InvalidDataTypeException |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - protected function store_submitted_form_data_in_session() |
|
343 | - { |
|
344 | - return EE_Registry::instance()->SSN->set_session_data( |
|
345 | - array( |
|
346 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | - ) |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * retrieves the originally submitted input values in the session |
|
354 | - * so that they can be used to repopulate the form if it failed validation |
|
355 | - * |
|
356 | - * @return array |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidInterfaceException |
|
359 | - * @throws InvalidDataTypeException |
|
360 | - */ |
|
361 | - protected function get_submitted_form_data_from_session() |
|
362 | - { |
|
363 | - $session = EE_Registry::instance()->SSN; |
|
364 | - if ($session instanceof EE_Session) { |
|
365 | - return $session->get_session_data( |
|
366 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | - ); |
|
368 | - } |
|
369 | - return array(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * flushed the originally submitted input values from the session |
|
375 | - * |
|
376 | - * @return boolean whether or not the data was successfully removed from the session |
|
377 | - * @throws InvalidArgumentException |
|
378 | - * @throws InvalidInterfaceException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - */ |
|
381 | - protected function flush_submitted_form_data_from_session() |
|
382 | - { |
|
383 | - return EE_Registry::instance()->SSN->reset_data( |
|
384 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Populates this form and its subsections with data from the session. |
|
391 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | - * validation errors when displaying too) |
|
393 | - * Returns true if the form was populated from the session, false otherwise |
|
394 | - * |
|
395 | - * @return boolean |
|
396 | - * @throws InvalidArgumentException |
|
397 | - * @throws InvalidInterfaceException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws EE_Error |
|
400 | - */ |
|
401 | - public function populate_from_session() |
|
402 | - { |
|
403 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | - if (empty($form_data_in_session)) { |
|
405 | - return false; |
|
406 | - } |
|
407 | - $this->receive_form_submission($form_data_in_session); |
|
408 | - $this->flush_submitted_form_data_from_session(); |
|
409 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | - return true; |
|
411 | - } |
|
412 | - return false; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Populates the default data for the form, given an array where keys are |
|
418 | - * the input names, and values are their values (preferably normalized to be their |
|
419 | - * proper PHP types, not all strings... although that should be ok too). |
|
420 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | - * the value being an array formatted in teh same way |
|
422 | - * |
|
423 | - * @param array $default_data |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function populate_defaults($default_data) |
|
427 | - { |
|
428 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | - if (isset($default_data[ $subsection_name ])) { |
|
430 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | - } |
|
435 | - } |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * returns true if subsection exists |
|
442 | - * |
|
443 | - * @param string $name |
|
444 | - * @return boolean |
|
445 | - */ |
|
446 | - public function subsection_exists($name) |
|
447 | - { |
|
448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Gets the subsection specified by its name |
|
454 | - * |
|
455 | - * @param string $name |
|
456 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | - * so that the inputs will be properly configured. |
|
458 | - * However, some client code may be ok |
|
459 | - * with construction finalize being called later |
|
460 | - * (realizing that the subsections' html names |
|
461 | - * might not be set yet, etc.) |
|
462 | - * @return EE_Form_Section_Base |
|
463 | - * @throws EE_Error |
|
464 | - */ |
|
465 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | - { |
|
467 | - if ($require_construction_to_be_finalized) { |
|
468 | - $this->ensure_construct_finalized_called(); |
|
469 | - } |
|
470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Gets all the validatable subsections of this form section |
|
476 | - * |
|
477 | - * @return EE_Form_Section_Validatable[] |
|
478 | - * @throws EE_Error |
|
479 | - */ |
|
480 | - public function get_validatable_subsections() |
|
481 | - { |
|
482 | - $validatable_subsections = array(); |
|
483 | - foreach ($this->subsections() as $name => $obj) { |
|
484 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | - $validatable_subsections[ $name ] = $obj; |
|
486 | - } |
|
487 | - } |
|
488 | - return $validatable_subsections; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | - * throw an EE_Error. |
|
495 | - * |
|
496 | - * @param string $name |
|
497 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | - * leave this as TRUE so that the inputs will be properly |
|
499 | - * configured. However, some client code may be ok with |
|
500 | - * construction finalize being called later |
|
501 | - * (realizing that the subsections' html names might not be |
|
502 | - * set yet, etc.) |
|
503 | - * @return EE_Form_Input_Base |
|
504 | - * @throws EE_Error |
|
505 | - */ |
|
506 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | - { |
|
508 | - $subsection = $this->get_subsection( |
|
509 | - $name, |
|
510 | - $require_construction_to_be_finalized |
|
511 | - ); |
|
512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | - throw new EE_Error( |
|
514 | - sprintf( |
|
515 | - esc_html__( |
|
516 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | - 'event_espresso' |
|
518 | - ), |
|
519 | - $name, |
|
520 | - get_class($this), |
|
521 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | - ) |
|
523 | - ); |
|
524 | - } |
|
525 | - return $subsection; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | - * otherwise throws an EE_Error |
|
532 | - * |
|
533 | - * @param string $name |
|
534 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | - * leave this as TRUE so that the inputs will be properly |
|
536 | - * configured. However, some client code may be ok with |
|
537 | - * construction finalize being called later |
|
538 | - * (realizing that the subsections' html names might not be |
|
539 | - * set yet, etc.) |
|
540 | - * @return EE_Form_Section_Proper |
|
541 | - * @throws EE_Error |
|
542 | - */ |
|
543 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | - { |
|
545 | - $subsection = $this->get_subsection( |
|
546 | - $name, |
|
547 | - $require_construction_to_be_finalized |
|
548 | - ); |
|
549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | - throw new EE_Error( |
|
551 | - sprintf( |
|
552 | - esc_html__( |
|
553 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - $name, |
|
557 | - get_class($this) |
|
558 | - ) |
|
559 | - ); |
|
560 | - } |
|
561 | - return $subsection; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | - * |
|
569 | - * @param string $name |
|
570 | - * @return mixed depending on the input's type and its normalization strategy |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - public function get_input_value($name) |
|
574 | - { |
|
575 | - $input = $this->get_input($name); |
|
576 | - return $input->normalized_value(); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Checks if this form section itself is valid, and then checks its subsections |
|
582 | - * |
|
583 | - * @throws EE_Error |
|
584 | - * @return boolean |
|
585 | - */ |
|
586 | - public function is_valid() |
|
587 | - { |
|
588 | - if($this->is_valid === null) { |
|
589 | - if (! $this->has_received_submission()) { |
|
590 | - throw new EE_Error( |
|
591 | - sprintf( |
|
592 | - esc_html__( |
|
593 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | - 'event_espresso' |
|
595 | - ) |
|
596 | - ) |
|
597 | - ); |
|
598 | - } |
|
599 | - if (! parent::is_valid()) { |
|
600 | - $this->is_valid = false; |
|
601 | - } else { |
|
602 | - // ok so no general errors to this entire form section. |
|
603 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | - $this->is_valid = true; |
|
605 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | - if (! $subsection->is_valid()) { |
|
607 | - $this->is_valid = false; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - return $this->is_valid; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * gets the default name of this form section if none is specified |
|
618 | - * |
|
619 | - * @return void |
|
620 | - */ |
|
621 | - protected function _set_default_name_if_empty() |
|
622 | - { |
|
623 | - if (! $this->_name) { |
|
624 | - $classname = get_class($this); |
|
625 | - $default_name = str_replace('EE_', '', $classname); |
|
626 | - $this->_name = $default_name; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | - * any CSS. |
|
639 | - * |
|
640 | - * @throws InvalidArgumentException |
|
641 | - * @throws InvalidInterfaceException |
|
642 | - * @throws InvalidDataTypeException |
|
643 | - * @throws EE_Error |
|
644 | - */ |
|
645 | - public function get_html_and_js() |
|
646 | - { |
|
647 | - $this->enqueue_js(); |
|
648 | - return $this->get_html(); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | - * |
|
655 | - * @param bool $display_previously_submitted_data |
|
656 | - * @return string |
|
657 | - * @throws InvalidArgumentException |
|
658 | - * @throws InvalidInterfaceException |
|
659 | - * @throws InvalidDataTypeException |
|
660 | - * @throws EE_Error |
|
661 | - * @throws EE_Error |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function get_html($display_previously_submitted_data = true) |
|
665 | - { |
|
666 | - $this->ensure_construct_finalized_called(); |
|
667 | - if ($display_previously_submitted_data) { |
|
668 | - $this->populate_from_session(); |
|
669 | - } |
|
670 | - return $this->_form_html_filter |
|
671 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | - : $this->_layout_strategy->layout_form(); |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * enqueues JS and CSS for the form. |
|
678 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | - * scripts and styles can be put in the header, but if called later |
|
680 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | - * only be in the header; but in HTML5 its ok in the body. |
|
682 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | - * |
|
685 | - * @return void |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - public function enqueue_js() |
|
689 | - { |
|
690 | - $this->_enqueue_and_localize_form_js(); |
|
691 | - foreach ($this->subsections() as $subsection) { |
|
692 | - $subsection->enqueue_js(); |
|
693 | - } |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | - * the wp_enqueue_scripts hook. |
|
701 | - * However, registering the form js and localizing it can happen when we |
|
702 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | - * could change until it's actually outputted) |
|
704 | - * |
|
705 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | - * to be triggered automatically or not |
|
707 | - * @return void |
|
708 | - */ |
|
709 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | - { |
|
711 | - wp_register_script( |
|
712 | - 'ee_form_section_validation', |
|
713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | - EVENT_ESPRESSO_VERSION, |
|
716 | - true |
|
717 | - ); |
|
718 | - wp_localize_script( |
|
719 | - 'ee_form_section_validation', |
|
720 | - 'ee_form_section_validation_init', |
|
721 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | - ); |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * gets the variables used by form_section_validation.js. |
|
728 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | - * but before the wordpress hook wp_loaded |
|
730 | - * |
|
731 | - * @throws EE_Error |
|
732 | - */ |
|
733 | - public function _enqueue_and_localize_form_js() |
|
734 | - { |
|
735 | - $this->ensure_construct_finalized_called(); |
|
736 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
738 | - //and localize it just before the footer |
|
739 | - $this->localize_validation_rules(); |
|
740 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * add our form section data to a static variable accessible by all form sections |
|
747 | - * |
|
748 | - * @param bool $return_for_subsection |
|
749 | - * @return void |
|
750 | - * @throws EE_Error |
|
751 | - */ |
|
752 | - public function localize_validation_rules($return_for_subsection = false) |
|
753 | - { |
|
754 | - // we only want to localize vars ONCE for the entire form, |
|
755 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | - 'form_section_id' => $this->html_id(true), |
|
759 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | - 'other_data' => $this->get_other_js_data(), |
|
761 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | - ); |
|
763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | - * This is primarily data added by inputs and forms in addition to any |
|
771 | - * scripts they might enqueue |
|
772 | - * |
|
773 | - * @param array $form_other_js_data |
|
774 | - * @return array |
|
775 | - * @throws EE_Error |
|
776 | - */ |
|
777 | - public function get_other_js_data($form_other_js_data = array()) |
|
778 | - { |
|
779 | - foreach ($this->subsections() as $subsection) { |
|
780 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | - } |
|
782 | - return $form_other_js_data; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Gets a flat array of inputs for this form section and its subsections. |
|
788 | - * Keys are their form names, and values are the inputs themselves |
|
789 | - * |
|
790 | - * @return EE_Form_Input_Base |
|
791 | - * @throws EE_Error |
|
792 | - */ |
|
793 | - public function inputs_in_subsections() |
|
794 | - { |
|
795 | - $inputs = array(); |
|
796 | - foreach ($this->subsections() as $subsection) { |
|
797 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | - $inputs += $subsection->inputs_in_subsections(); |
|
801 | - } |
|
802 | - } |
|
803 | - return $inputs; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * Gets a flat array of all the validation errors. |
|
809 | - * Keys are html names (because those should be unique) |
|
810 | - * and values are a string of all their validation errors |
|
811 | - * |
|
812 | - * @return string[] |
|
813 | - * @throws EE_Error |
|
814 | - */ |
|
815 | - public function subsection_validation_errors_by_html_name() |
|
816 | - { |
|
817 | - $inputs = $this->inputs(); |
|
818 | - $errors = array(); |
|
819 | - foreach ($inputs as $form_input) { |
|
820 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | - } |
|
823 | - } |
|
824 | - return $errors; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | - * |
|
832 | - * @throws InvalidArgumentException |
|
833 | - * @throws InvalidInterfaceException |
|
834 | - * @throws InvalidDataTypeException |
|
835 | - */ |
|
836 | - public static function localize_script_for_all_forms() |
|
837 | - { |
|
838 | - //allow inputs and stuff to hook in their JS and stuff here |
|
839 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | - : 'wp_default'; |
|
844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | - wp_enqueue_script('ee_form_section_validation'); |
|
846 | - wp_localize_script( |
|
847 | - 'ee_form_section_validation', |
|
848 | - 'ee_form_section_vars', |
|
849 | - EE_Form_Section_Proper::$_js_localization |
|
850 | - ); |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * ensure_scripts_localized |
|
856 | - * |
|
857 | - * @throws EE_Error |
|
858 | - */ |
|
859 | - public function ensure_scripts_localized() |
|
860 | - { |
|
861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | - $this->_enqueue_and_localize_form_js(); |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | - * |
|
871 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | - */ |
|
873 | - private static function _get_localized_error_messages() |
|
874 | - { |
|
875 | - return array( |
|
876 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | - ); |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * @return array |
|
884 | - */ |
|
885 | - public static function js_localization() |
|
886 | - { |
|
887 | - return self::$_js_localization; |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * @return void |
|
893 | - */ |
|
894 | - public static function reset_js_localization() |
|
895 | - { |
|
896 | - self::$_js_localization = array(); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | - * See parent function for more... |
|
903 | - * |
|
904 | - * @return array |
|
905 | - * @throws EE_Error |
|
906 | - */ |
|
907 | - public function get_jquery_validation_rules() |
|
908 | - { |
|
909 | - $jquery_validation_rules = array(); |
|
910 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | - $jquery_validation_rules = array_merge( |
|
912 | - $jquery_validation_rules, |
|
913 | - $subsection->get_jquery_validation_rules() |
|
914 | - ); |
|
915 | - } |
|
916 | - return $jquery_validation_rules; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Sanitizes all the data and sets the sanitized value of each field |
|
922 | - * |
|
923 | - * @param array $req_data like $_POST |
|
924 | - * @return void |
|
925 | - * @throws EE_Error |
|
926 | - */ |
|
927 | - protected function _normalize($req_data) |
|
928 | - { |
|
929 | - $this->_received_submission = true; |
|
930 | - $this->_validation_errors = array(); |
|
931 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | - try { |
|
933 | - $subsection->_normalize($req_data); |
|
934 | - } catch (EE_Validation_Error $e) { |
|
935 | - $subsection->add_validation_error($e); |
|
936 | - } |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - /** |
|
942 | - * Performs validation on this form section and its subsections. |
|
943 | - * For each subsection, |
|
944 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | - * and passes it the subsection, then calls _validate on that subsection. |
|
946 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | - * you would be best to override this _validate method, |
|
948 | - * calling parent::_validate() first. |
|
949 | - * |
|
950 | - * @throws EE_Error |
|
951 | - */ |
|
952 | - protected function _validate() |
|
953 | - { |
|
954 | - //reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | - $this->is_valid = null; |
|
956 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | - } |
|
960 | - $subsection->_validate(); |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * Gets all the validated inputs for the form section |
|
967 | - * |
|
968 | - * @return array |
|
969 | - * @throws EE_Error |
|
970 | - */ |
|
971 | - public function valid_data() |
|
972 | - { |
|
973 | - $inputs = array(); |
|
974 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | - } |
|
980 | - } |
|
981 | - return $inputs; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * Gets all the inputs on this form section |
|
987 | - * |
|
988 | - * @return EE_Form_Input_Base[] |
|
989 | - * @throws EE_Error |
|
990 | - */ |
|
991 | - public function inputs() |
|
992 | - { |
|
993 | - $inputs = array(); |
|
994 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | - $inputs[ $subsection_name ] = $subsection; |
|
997 | - } |
|
998 | - } |
|
999 | - return $inputs; |
|
1000 | - } |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * Gets all the subsections which are a proper form |
|
1005 | - * |
|
1006 | - * @return EE_Form_Section_Proper[] |
|
1007 | - * @throws EE_Error |
|
1008 | - */ |
|
1009 | - public function subforms() |
|
1010 | - { |
|
1011 | - $form_sections = array(); |
|
1012 | - foreach ($this->subsections() as $name => $obj) { |
|
1013 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | - $form_sections[ $name ] = $obj; |
|
1015 | - } |
|
1016 | - } |
|
1017 | - return $form_sections; |
|
1018 | - } |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | - * Consider using inputs() or subforms() |
|
1024 | - * if you only want form inputs or proper form sections. |
|
1025 | - * |
|
1026 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | - * leave this as TRUE so that the inputs will be properly |
|
1028 | - * configured. However, some client code may be ok with |
|
1029 | - * construction finalize being called later |
|
1030 | - * (realizing that the subsections' html names might not be |
|
1031 | - * set yet, etc.) |
|
1032 | - * @return EE_Form_Section_Proper[] |
|
1033 | - * @throws EE_Error |
|
1034 | - */ |
|
1035 | - public function subsections($require_construction_to_be_finalized = true) |
|
1036 | - { |
|
1037 | - if ($require_construction_to_be_finalized) { |
|
1038 | - $this->ensure_construct_finalized_called(); |
|
1039 | - } |
|
1040 | - return $this->_subsections; |
|
1041 | - } |
|
1042 | - |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Returns whether this form has any subforms or inputs |
|
1046 | - * @return bool |
|
1047 | - */ |
|
1048 | - public function hasSubsections() |
|
1049 | - { |
|
1050 | - return ! empty($this->_subsections); |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | - * values. (Similar to calling get_input_value on inputs) |
|
1057 | - * |
|
1058 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | - * or just this forms' direct children inputs |
|
1060 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | - * or allow multidimensional array |
|
1062 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | - * with array keys being input names |
|
1064 | - * (regardless of whether they are from a subsection or not), |
|
1065 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | - * where keys are always subsection names and values are either |
|
1067 | - * the input's normalized value, or an array like the top-level array |
|
1068 | - * @throws EE_Error |
|
1069 | - */ |
|
1070 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | - { |
|
1072 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | - * is not necessarily the value we want to display to users. This creates an array |
|
1080 | - * where keys are the input names, and values are their display values |
|
1081 | - * |
|
1082 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | - * or just this forms' direct children inputs |
|
1084 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | - * or allow multidimensional array |
|
1086 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | - * with array keys being input names |
|
1088 | - * (regardless of whether they are from a subsection or not), |
|
1089 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | - * where keys are always subsection names and values are either |
|
1091 | - * the input's normalized value, or an array like the top-level array |
|
1092 | - * @throws EE_Error |
|
1093 | - */ |
|
1094 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | - { |
|
1096 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Gets the input values from the form |
|
1102 | - * |
|
1103 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | - * or just the normalized value |
|
1105 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | - * or just this forms' direct children inputs |
|
1107 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | - * or allow multidimensional array |
|
1109 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | - * input names (regardless of whether they are from a subsection or not), |
|
1111 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | - * where keys are always subsection names and values are either |
|
1113 | - * the input's normalized value, or an array like the top-level array |
|
1114 | - * @throws EE_Error |
|
1115 | - */ |
|
1116 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | - { |
|
1118 | - $input_values = array(); |
|
1119 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | - $input_values[ $subsection_name ] = $pretty |
|
1122 | - ? $subsection->pretty_value() |
|
1123 | - : $subsection->normalized_value(); |
|
1124 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | - $subform_input_values = $subsection->_input_values( |
|
1126 | - $pretty, |
|
1127 | - $include_subform_inputs, |
|
1128 | - $flatten |
|
1129 | - ); |
|
1130 | - if ($flatten) { |
|
1131 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | - } else { |
|
1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | - } |
|
1135 | - } |
|
1136 | - } |
|
1137 | - return $input_values; |
|
1138 | - } |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Gets the originally submitted input values from the form |
|
1143 | - * |
|
1144 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | - * or just this forms' direct children inputs |
|
1146 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | - * with array keys being input names |
|
1148 | - * (regardless of whether they are from a subsection or not), |
|
1149 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | - * where keys are always subsection names and values are either |
|
1151 | - * the input's normalized value, or an array like the top-level array |
|
1152 | - * @throws EE_Error |
|
1153 | - */ |
|
1154 | - public function submitted_values($include_subforms = false) |
|
1155 | - { |
|
1156 | - $submitted_values = array(); |
|
1157 | - foreach ($this->subsections() as $subsection) { |
|
1158 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | - // is this input part of an array of inputs? |
|
1160 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | - explode( |
|
1163 | - '[', |
|
1164 | - str_replace(']', '', $subsection->html_name()) |
|
1165 | - ), |
|
1166 | - $subsection->raw_value() |
|
1167 | - ); |
|
1168 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | - } else { |
|
1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | - } |
|
1172 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - return $submitted_values; |
|
1178 | - } |
|
1179 | - |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Indicates whether or not this form has received a submission yet |
|
1183 | - * (ie, had receive_form_submission called on it yet) |
|
1184 | - * |
|
1185 | - * @return boolean |
|
1186 | - * @throws EE_Error |
|
1187 | - */ |
|
1188 | - public function has_received_submission() |
|
1189 | - { |
|
1190 | - $this->ensure_construct_finalized_called(); |
|
1191 | - return $this->_received_submission; |
|
1192 | - } |
|
1193 | - |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | - * Removes the listed inputs from the form |
|
1198 | - * |
|
1199 | - * @param array $inputs_to_exclude values are the input names |
|
1200 | - * @return void |
|
1201 | - */ |
|
1202 | - public function exclude(array $inputs_to_exclude = array()) |
|
1203 | - { |
|
1204 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | - } |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | - * @param array $inputs_to_hide |
|
1213 | - * @throws EE_Error |
|
1214 | - */ |
|
1215 | - public function hide(array $inputs_to_hide = array()) |
|
1216 | - { |
|
1217 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | - $input = $this->get_input($input_to_hide); |
|
1219 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * add_subsections |
|
1226 | - * Adds the listed subsections to the form section. |
|
1227 | - * If $subsection_name_to_target is provided, |
|
1228 | - * then new subsections are added before or after that subsection, |
|
1229 | - * otherwise to the start or end of the entire subsections array. |
|
1230 | - * |
|
1231 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | - * where keys are their names |
|
1233 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | - * should be added before or after |
|
1235 | - * IF $subsection_name_to_target is null, |
|
1236 | - * then $new_subsections will be added to |
|
1237 | - * the beginning or end of the entire subsections array |
|
1238 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | - * $subsection_name_to_target, |
|
1240 | - * or if $subsection_name_to_target is null, |
|
1241 | - * before or after entire subsections array |
|
1242 | - * @return void |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | - { |
|
1247 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | - EE_Error::add_error( |
|
1250 | - sprintf( |
|
1251 | - esc_html__( |
|
1252 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | - 'event_espresso' |
|
1254 | - ), |
|
1255 | - get_class($subsection), |
|
1256 | - $subsection_name, |
|
1257 | - $this->name() |
|
1258 | - ) |
|
1259 | - ); |
|
1260 | - unset($new_subsections[ $subsection_name ]); |
|
1261 | - } |
|
1262 | - } |
|
1263 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | - $this->_subsections, |
|
1265 | - $new_subsections, |
|
1266 | - $subsection_name_to_target, |
|
1267 | - $add_before |
|
1268 | - ); |
|
1269 | - if ($this->_construction_finalized) { |
|
1270 | - foreach ($this->_subsections as $name => $subsection) { |
|
1271 | - $subsection->_construct_finalize($this, $name); |
|
1272 | - } |
|
1273 | - } |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @param string $subsection_name |
|
1279 | - * @param bool $recursive |
|
1280 | - * @return bool |
|
1281 | - */ |
|
1282 | - public function has_subsection($subsection_name, $recursive = false) |
|
1283 | - { |
|
1284 | - foreach ($this->_subsections as $name => $subsection) {if( |
|
1285 | - $name === $subsection_name |
|
1286 | - || ( |
|
1287 | - $recursive |
|
1288 | - && $subsection instanceof EE_Form_Section_Proper |
|
1289 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | - ) |
|
1291 | - ) { |
|
1292 | - return true; |
|
1293 | - } |
|
1294 | - } |
|
1295 | - return false; |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * Just gets all validatable subsections to clean their sensitive data |
|
1302 | - * |
|
1303 | - * @throws EE_Error |
|
1304 | - */ |
|
1305 | - public function clean_sensitive_data() |
|
1306 | - { |
|
1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | - $subsection->clean_sensitive_data(); |
|
1309 | - } |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | - * @param string $form_submission_error_message |
|
1316 | - * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | - * @throws EE_Error |
|
1318 | - */ |
|
1319 | - public function set_submission_error_message( |
|
1320 | - $form_submission_error_message = '' |
|
1321 | - ) { |
|
1322 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | - ? $form_submission_error_message |
|
1324 | - : $this->getAllValidationErrorsString(); |
|
1325 | - } |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | - * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | - * set_submission_error_message |
|
1332 | - * |
|
1333 | - * @return string |
|
1334 | - */ |
|
1335 | - public function submission_error_message() |
|
1336 | - { |
|
1337 | - return $this->_form_submission_error_message; |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Sets a message to display if the data submitted to the form was valid. |
|
1343 | - * @param string $form_submission_success_message |
|
1344 | - */ |
|
1345 | - public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | - { |
|
1347 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | - ? $form_submission_success_message |
|
1349 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | - } |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | - * @return string |
|
1356 | - */ |
|
1357 | - public function submission_success_message() |
|
1358 | - { |
|
1359 | - return $this->_form_submission_success_message; |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Returns the prefix that should be used on child of this form section for |
|
1365 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | - * prefix onto this form section's prefix. Used primarily by |
|
1367 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | - * |
|
1369 | - * @return string |
|
1370 | - * @throws EE_Error |
|
1371 | - */ |
|
1372 | - public function html_name_prefix() |
|
1373 | - { |
|
1374 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | - } |
|
1377 | - return $this->name(); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | - * was set, which is probably nothing, or the classname) |
|
1385 | - * |
|
1386 | - * @return string |
|
1387 | - * @throws EE_Error |
|
1388 | - */ |
|
1389 | - public function name() |
|
1390 | - { |
|
1391 | - $this->ensure_construct_finalized_called(); |
|
1392 | - return parent::name(); |
|
1393 | - } |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * @return EE_Form_Section_Proper |
|
1398 | - * @throws EE_Error |
|
1399 | - */ |
|
1400 | - public function parent_section() |
|
1401 | - { |
|
1402 | - $this->ensure_construct_finalized_called(); |
|
1403 | - return parent::parent_section(); |
|
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | - * |
|
1410 | - * @return void |
|
1411 | - * @throws EE_Error |
|
1412 | - */ |
|
1413 | - public function ensure_construct_finalized_called() |
|
1414 | - { |
|
1415 | - if (! $this->_construction_finalized) { |
|
1416 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | - } |
|
1418 | - } |
|
1419 | - |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | - * are in teh form data. If any are found, returns true. Else false |
|
1424 | - * |
|
1425 | - * @param array $req_data |
|
1426 | - * @return boolean |
|
1427 | - * @throws EE_Error |
|
1428 | - */ |
|
1429 | - public function form_data_present_in($req_data = null) |
|
1430 | - { |
|
1431 | - $req_data = $this->getCachedRequest($req_data); |
|
1432 | - foreach ($this->subsections() as $subsection) { |
|
1433 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | - if ($subsection->form_data_present_in($req_data)) { |
|
1435 | - return true; |
|
1436 | - } |
|
1437 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | - if ($subsection->form_data_present_in($req_data)) { |
|
1439 | - return true; |
|
1440 | - } |
|
1441 | - } |
|
1442 | - } |
|
1443 | - return false; |
|
1444 | - } |
|
1445 | - |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * Gets validation errors for this form section and subsections |
|
1449 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | - * gets the validation errors for ALL subsection |
|
1451 | - * |
|
1452 | - * @return EE_Validation_Error[] |
|
1453 | - * @throws EE_Error |
|
1454 | - */ |
|
1455 | - public function get_validation_errors_accumulated() |
|
1456 | - { |
|
1457 | - $validation_errors = $this->get_validation_errors(); |
|
1458 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | - } else { |
|
1462 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | - } |
|
1464 | - if ($validation_errors_on_this_subsection) { |
|
1465 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | - } |
|
1467 | - } |
|
1468 | - return $validation_errors; |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | - * |
|
1476 | - * @return string |
|
1477 | - * @since $VID:$ |
|
1478 | - */ |
|
1479 | - protected function getAllValidationErrorsString() |
|
1480 | - { |
|
1481 | - $submission_error_messages = array(); |
|
1482 | - // bad, bad, bad registrant |
|
1483 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | - $form_section = $validation_error->get_form_section(); |
|
1486 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | - } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | - $label = $validation_error->get_form_section()->name(); |
|
1490 | - } else { |
|
1491 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | - } |
|
1493 | - $submission_error_messages[] = sprintf( |
|
1494 | - __('%s : %s', 'event_espresso'), |
|
1495 | - $label, |
|
1496 | - $validation_error->getMessage() |
|
1497 | - ); |
|
1498 | - } |
|
1499 | - } |
|
1500 | - return implode('<br', $submission_error_messages); |
|
1501 | - } |
|
1502 | - |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | - * which will be returned. |
|
1510 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | - * Etc |
|
1515 | - * |
|
1516 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | - * @return EE_Form_Section_Base |
|
1518 | - * @throws EE_Error |
|
1519 | - */ |
|
1520 | - public function find_section_from_path($form_section_path) |
|
1521 | - { |
|
1522 | - //check if we can find the input from purely going straight up the tree |
|
1523 | - $input = parent::find_section_from_path($form_section_path); |
|
1524 | - if ($input instanceof EE_Form_Section_Base) { |
|
1525 | - return $input; |
|
1526 | - } |
|
1527 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | - if ($next_slash_pos !== false) { |
|
1529 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | - } else { |
|
1532 | - $child_section_name = $form_section_path; |
|
1533 | - $subpath = ''; |
|
1534 | - } |
|
1535 | - $child_section = $this->get_subsection($child_section_name); |
|
1536 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | - return $child_section->find_section_from_path($subpath); |
|
1538 | - } |
|
1539 | - return null; |
|
1540 | - } |
|
17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | + |
|
19 | + /** |
|
20 | + * Subsections |
|
21 | + * |
|
22 | + * @var EE_Form_Section_Validatable[] |
|
23 | + */ |
|
24 | + protected $_subsections = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Strategy for laying out the form |
|
28 | + * |
|
29 | + * @var EE_Form_Section_Layout_Base |
|
30 | + */ |
|
31 | + protected $_layout_strategy; |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether or not this form has received and validated a form submission yet |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_received_submission = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * message displayed to users upon successful form submission |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_form_submission_success_message = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * message displayed to users upon unsuccessful form submission |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_form_submission_error_message = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array like $_REQUEST |
|
56 | + */ |
|
57 | + protected $cached_request_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | + * @var boolean|null |
|
63 | + */ |
|
64 | + protected $is_valid; |
|
65 | + |
|
66 | + /** |
|
67 | + * Stores all the data that will localized for form validation |
|
68 | + * |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + static protected $_js_localization = array(); |
|
72 | + |
|
73 | + /** |
|
74 | + * whether or not the form's localized validation JS vars have been set |
|
75 | + * |
|
76 | + * @type boolean |
|
77 | + */ |
|
78 | + static protected $_scripts_localized = false; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * when constructing a proper form section, calls _construct_finalize on children |
|
83 | + * so that they know who their parent is, and what name they've been given. |
|
84 | + * |
|
85 | + * @param array[] $options_array { |
|
86 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | + * and in that order. This is handy if you want |
|
89 | + * the subsections to be ordered differently than the default, and if you override |
|
90 | + * which fields are shown |
|
91 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | + * items from that list of inclusions) |
|
95 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | + * } @see EE_Form_Section_Validatable::__construct() |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public function __construct($options_array = array()) |
|
100 | + { |
|
101 | + $options_array = (array) apply_filters( |
|
102 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | + $options_array, |
|
104 | + $this |
|
105 | + ); |
|
106 | + //call parent first, as it may be setting the name |
|
107 | + parent::__construct($options_array); |
|
108 | + //if they've included subsections in the constructor, add them now |
|
109 | + if (isset($options_array['include'])) { |
|
110 | + //we are going to make sure we ONLY have those subsections to include |
|
111 | + //AND we are going to make sure they're in that specified order |
|
112 | + $reordered_subsections = array(); |
|
113 | + foreach ($options_array['include'] as $input_name) { |
|
114 | + if (isset($this->_subsections[ $input_name ])) { |
|
115 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | + } |
|
117 | + } |
|
118 | + $this->_subsections = $reordered_subsections; |
|
119 | + } |
|
120 | + if (isset($options_array['exclude'])) { |
|
121 | + $exclude = $options_array['exclude']; |
|
122 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | + } |
|
124 | + if (isset($options_array['layout_strategy'])) { |
|
125 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | + } |
|
127 | + if (! $this->_layout_strategy) { |
|
128 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | + } |
|
130 | + $this->_layout_strategy->_construct_finalize($this); |
|
131 | + //ok so we are definitely going to want the forms JS, |
|
132 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | + //ok so they've constructed this object after when they should have. |
|
135 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | + } else { |
|
138 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | + } |
|
141 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | + /** |
|
143 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | + * The form probably doesn't yet have a parent form section. |
|
145 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | + * |
|
149 | + * @since 4.9.32 |
|
150 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | + * except maybe calling _construct_finalize has been done |
|
152 | + * @param array $options_array options passed into the constructor |
|
153 | + */ |
|
154 | + do_action( |
|
155 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | + $this, |
|
157 | + $options_array |
|
158 | + ); |
|
159 | + if (isset($options_array['name'])) { |
|
160 | + $this->_construct_finalize(null, $options_array['name']); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Finishes construction given the parent form section and this form section's name |
|
167 | + * |
|
168 | + * @param EE_Form_Section_Proper $parent_form_section |
|
169 | + * @param string $name |
|
170 | + * @throws EE_Error |
|
171 | + */ |
|
172 | + public function _construct_finalize($parent_form_section, $name) |
|
173 | + { |
|
174 | + parent::_construct_finalize($parent_form_section, $name); |
|
175 | + $this->_set_default_name_if_empty(); |
|
176 | + $this->_set_default_html_id_if_empty(); |
|
177 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | + $subsection->_construct_finalize($this, $subsection_name); |
|
180 | + } else { |
|
181 | + throw new EE_Error( |
|
182 | + sprintf( |
|
183 | + esc_html__( |
|
184 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + $subsection_name, |
|
188 | + get_class($this), |
|
189 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + } |
|
194 | + /** |
|
195 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | + * ensured it has a name, HTML IDs, etc |
|
201 | + * |
|
202 | + * @param EE_Form_Section_Proper $this |
|
203 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | + * @param string $name |
|
205 | + */ |
|
206 | + do_action( |
|
207 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | + $this, |
|
209 | + $parent_form_section, |
|
210 | + $name |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Gets the layout strategy for this form section |
|
217 | + * |
|
218 | + * @return EE_Form_Section_Layout_Base |
|
219 | + */ |
|
220 | + public function get_layout_strategy() |
|
221 | + { |
|
222 | + return $this->_layout_strategy; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Gets the HTML for a single input for this form section according |
|
228 | + * to the layout strategy |
|
229 | + * |
|
230 | + * @param EE_Form_Input_Base $input |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function get_html_for_input($input) |
|
234 | + { |
|
235 | + return $this->_layout_strategy->layout_input($input); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * was_submitted - checks if form inputs are present in request data |
|
241 | + * Basically an alias for form_data_present_in() (which is used by both |
|
242 | + * proper form sections and form inputs) |
|
243 | + * |
|
244 | + * @param null $form_data |
|
245 | + * @return boolean |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function was_submitted($form_data = null) |
|
249 | + { |
|
250 | + return $this->form_data_present_in($form_data); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | + * something different, refresh the cache, and then return it |
|
256 | + * @param null $req_data |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + protected function getCachedRequest($req_data = null) |
|
260 | + { |
|
261 | + if ($this->cached_request_data === null |
|
262 | + || ( |
|
263 | + $req_data !== null && |
|
264 | + $req_data !== $this->cached_request_data |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $req_data = apply_filters( |
|
268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | + $req_data, |
|
270 | + $this |
|
271 | + ); |
|
272 | + if ($req_data === null) { |
|
273 | + $req_data = array_merge($_GET, $_POST); |
|
274 | + } |
|
275 | + $req_data = apply_filters( |
|
276 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | + $req_data, |
|
278 | + $this |
|
279 | + ); |
|
280 | + $this->cached_request_data = (array)$req_data; |
|
281 | + } |
|
282 | + return $this->cached_request_data; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | + * |
|
290 | + * @param array|null $req_data should usually be $_POST (the default). |
|
291 | + * However, you CAN supply a different array. |
|
292 | + * Consider using set_defaults() instead however. |
|
293 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | + * the inputs will have the correct name in the request data for this function |
|
295 | + * to find them and populate the form with them. |
|
296 | + * If you have a flat form (with only input subsections), |
|
297 | + * you can supply a flat array where keys |
|
298 | + * are the form input names and values are their values) |
|
299 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | + * of course, to validate that data, and set errors on the invalid values. |
|
301 | + * But if the data has already been validated |
|
302 | + * (eg you validated the data then stored it in the DB) |
|
303 | + * you may want to skip this step. |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws InvalidInterfaceException |
|
306 | + * @throws InvalidDataTypeException |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function receive_form_submission($req_data = null, $validate = true) |
|
310 | + { |
|
311 | + $req_data = $this->getCachedRequest($req_data); |
|
312 | + $this->_normalize($req_data); |
|
313 | + if ($validate) { |
|
314 | + $this->_validate(); |
|
315 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | + if (! $this->is_valid()) { |
|
317 | + $this->store_submitted_form_data_in_session(); |
|
318 | + } |
|
319 | + } |
|
320 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | + $this->set_submission_error_message(); |
|
322 | + } |
|
323 | + do_action( |
|
324 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | + $req_data, |
|
326 | + $this, |
|
327 | + $validate |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * caches the originally submitted input values in the session |
|
334 | + * so that they can be used to repopulate the form if it failed validation |
|
335 | + * |
|
336 | + * @return boolean whether or not the data was successfully stored in the session |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidInterfaceException |
|
339 | + * @throws InvalidDataTypeException |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + protected function store_submitted_form_data_in_session() |
|
343 | + { |
|
344 | + return EE_Registry::instance()->SSN->set_session_data( |
|
345 | + array( |
|
346 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * retrieves the originally submitted input values in the session |
|
354 | + * so that they can be used to repopulate the form if it failed validation |
|
355 | + * |
|
356 | + * @return array |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidInterfaceException |
|
359 | + * @throws InvalidDataTypeException |
|
360 | + */ |
|
361 | + protected function get_submitted_form_data_from_session() |
|
362 | + { |
|
363 | + $session = EE_Registry::instance()->SSN; |
|
364 | + if ($session instanceof EE_Session) { |
|
365 | + return $session->get_session_data( |
|
366 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | + ); |
|
368 | + } |
|
369 | + return array(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * flushed the originally submitted input values from the session |
|
375 | + * |
|
376 | + * @return boolean whether or not the data was successfully removed from the session |
|
377 | + * @throws InvalidArgumentException |
|
378 | + * @throws InvalidInterfaceException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + */ |
|
381 | + protected function flush_submitted_form_data_from_session() |
|
382 | + { |
|
383 | + return EE_Registry::instance()->SSN->reset_data( |
|
384 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Populates this form and its subsections with data from the session. |
|
391 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | + * validation errors when displaying too) |
|
393 | + * Returns true if the form was populated from the session, false otherwise |
|
394 | + * |
|
395 | + * @return boolean |
|
396 | + * @throws InvalidArgumentException |
|
397 | + * @throws InvalidInterfaceException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws EE_Error |
|
400 | + */ |
|
401 | + public function populate_from_session() |
|
402 | + { |
|
403 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | + if (empty($form_data_in_session)) { |
|
405 | + return false; |
|
406 | + } |
|
407 | + $this->receive_form_submission($form_data_in_session); |
|
408 | + $this->flush_submitted_form_data_from_session(); |
|
409 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | + return true; |
|
411 | + } |
|
412 | + return false; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Populates the default data for the form, given an array where keys are |
|
418 | + * the input names, and values are their values (preferably normalized to be their |
|
419 | + * proper PHP types, not all strings... although that should be ok too). |
|
420 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | + * the value being an array formatted in teh same way |
|
422 | + * |
|
423 | + * @param array $default_data |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function populate_defaults($default_data) |
|
427 | + { |
|
428 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | + if (isset($default_data[ $subsection_name ])) { |
|
430 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | + } |
|
435 | + } |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * returns true if subsection exists |
|
442 | + * |
|
443 | + * @param string $name |
|
444 | + * @return boolean |
|
445 | + */ |
|
446 | + public function subsection_exists($name) |
|
447 | + { |
|
448 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Gets the subsection specified by its name |
|
454 | + * |
|
455 | + * @param string $name |
|
456 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | + * so that the inputs will be properly configured. |
|
458 | + * However, some client code may be ok |
|
459 | + * with construction finalize being called later |
|
460 | + * (realizing that the subsections' html names |
|
461 | + * might not be set yet, etc.) |
|
462 | + * @return EE_Form_Section_Base |
|
463 | + * @throws EE_Error |
|
464 | + */ |
|
465 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | + { |
|
467 | + if ($require_construction_to_be_finalized) { |
|
468 | + $this->ensure_construct_finalized_called(); |
|
469 | + } |
|
470 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Gets all the validatable subsections of this form section |
|
476 | + * |
|
477 | + * @return EE_Form_Section_Validatable[] |
|
478 | + * @throws EE_Error |
|
479 | + */ |
|
480 | + public function get_validatable_subsections() |
|
481 | + { |
|
482 | + $validatable_subsections = array(); |
|
483 | + foreach ($this->subsections() as $name => $obj) { |
|
484 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | + $validatable_subsections[ $name ] = $obj; |
|
486 | + } |
|
487 | + } |
|
488 | + return $validatable_subsections; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | + * throw an EE_Error. |
|
495 | + * |
|
496 | + * @param string $name |
|
497 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | + * leave this as TRUE so that the inputs will be properly |
|
499 | + * configured. However, some client code may be ok with |
|
500 | + * construction finalize being called later |
|
501 | + * (realizing that the subsections' html names might not be |
|
502 | + * set yet, etc.) |
|
503 | + * @return EE_Form_Input_Base |
|
504 | + * @throws EE_Error |
|
505 | + */ |
|
506 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | + { |
|
508 | + $subsection = $this->get_subsection( |
|
509 | + $name, |
|
510 | + $require_construction_to_be_finalized |
|
511 | + ); |
|
512 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | + throw new EE_Error( |
|
514 | + sprintf( |
|
515 | + esc_html__( |
|
516 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | + 'event_espresso' |
|
518 | + ), |
|
519 | + $name, |
|
520 | + get_class($this), |
|
521 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | + ) |
|
523 | + ); |
|
524 | + } |
|
525 | + return $subsection; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | + * otherwise throws an EE_Error |
|
532 | + * |
|
533 | + * @param string $name |
|
534 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | + * leave this as TRUE so that the inputs will be properly |
|
536 | + * configured. However, some client code may be ok with |
|
537 | + * construction finalize being called later |
|
538 | + * (realizing that the subsections' html names might not be |
|
539 | + * set yet, etc.) |
|
540 | + * @return EE_Form_Section_Proper |
|
541 | + * @throws EE_Error |
|
542 | + */ |
|
543 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | + { |
|
545 | + $subsection = $this->get_subsection( |
|
546 | + $name, |
|
547 | + $require_construction_to_be_finalized |
|
548 | + ); |
|
549 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | + throw new EE_Error( |
|
551 | + sprintf( |
|
552 | + esc_html__( |
|
553 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + $name, |
|
557 | + get_class($this) |
|
558 | + ) |
|
559 | + ); |
|
560 | + } |
|
561 | + return $subsection; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | + * |
|
569 | + * @param string $name |
|
570 | + * @return mixed depending on the input's type and its normalization strategy |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + public function get_input_value($name) |
|
574 | + { |
|
575 | + $input = $this->get_input($name); |
|
576 | + return $input->normalized_value(); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Checks if this form section itself is valid, and then checks its subsections |
|
582 | + * |
|
583 | + * @throws EE_Error |
|
584 | + * @return boolean |
|
585 | + */ |
|
586 | + public function is_valid() |
|
587 | + { |
|
588 | + if($this->is_valid === null) { |
|
589 | + if (! $this->has_received_submission()) { |
|
590 | + throw new EE_Error( |
|
591 | + sprintf( |
|
592 | + esc_html__( |
|
593 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | + 'event_espresso' |
|
595 | + ) |
|
596 | + ) |
|
597 | + ); |
|
598 | + } |
|
599 | + if (! parent::is_valid()) { |
|
600 | + $this->is_valid = false; |
|
601 | + } else { |
|
602 | + // ok so no general errors to this entire form section. |
|
603 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | + $this->is_valid = true; |
|
605 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | + if (! $subsection->is_valid()) { |
|
607 | + $this->is_valid = false; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + return $this->is_valid; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * gets the default name of this form section if none is specified |
|
618 | + * |
|
619 | + * @return void |
|
620 | + */ |
|
621 | + protected function _set_default_name_if_empty() |
|
622 | + { |
|
623 | + if (! $this->_name) { |
|
624 | + $classname = get_class($this); |
|
625 | + $default_name = str_replace('EE_', '', $classname); |
|
626 | + $this->_name = $default_name; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | + * any CSS. |
|
639 | + * |
|
640 | + * @throws InvalidArgumentException |
|
641 | + * @throws InvalidInterfaceException |
|
642 | + * @throws InvalidDataTypeException |
|
643 | + * @throws EE_Error |
|
644 | + */ |
|
645 | + public function get_html_and_js() |
|
646 | + { |
|
647 | + $this->enqueue_js(); |
|
648 | + return $this->get_html(); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | + * |
|
655 | + * @param bool $display_previously_submitted_data |
|
656 | + * @return string |
|
657 | + * @throws InvalidArgumentException |
|
658 | + * @throws InvalidInterfaceException |
|
659 | + * @throws InvalidDataTypeException |
|
660 | + * @throws EE_Error |
|
661 | + * @throws EE_Error |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function get_html($display_previously_submitted_data = true) |
|
665 | + { |
|
666 | + $this->ensure_construct_finalized_called(); |
|
667 | + if ($display_previously_submitted_data) { |
|
668 | + $this->populate_from_session(); |
|
669 | + } |
|
670 | + return $this->_form_html_filter |
|
671 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | + : $this->_layout_strategy->layout_form(); |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * enqueues JS and CSS for the form. |
|
678 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | + * scripts and styles can be put in the header, but if called later |
|
680 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | + * only be in the header; but in HTML5 its ok in the body. |
|
682 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | + * |
|
685 | + * @return void |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + public function enqueue_js() |
|
689 | + { |
|
690 | + $this->_enqueue_and_localize_form_js(); |
|
691 | + foreach ($this->subsections() as $subsection) { |
|
692 | + $subsection->enqueue_js(); |
|
693 | + } |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | + * the wp_enqueue_scripts hook. |
|
701 | + * However, registering the form js and localizing it can happen when we |
|
702 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | + * could change until it's actually outputted) |
|
704 | + * |
|
705 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | + * to be triggered automatically or not |
|
707 | + * @return void |
|
708 | + */ |
|
709 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | + { |
|
711 | + wp_register_script( |
|
712 | + 'ee_form_section_validation', |
|
713 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | + EVENT_ESPRESSO_VERSION, |
|
716 | + true |
|
717 | + ); |
|
718 | + wp_localize_script( |
|
719 | + 'ee_form_section_validation', |
|
720 | + 'ee_form_section_validation_init', |
|
721 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | + ); |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * gets the variables used by form_section_validation.js. |
|
728 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | + * but before the wordpress hook wp_loaded |
|
730 | + * |
|
731 | + * @throws EE_Error |
|
732 | + */ |
|
733 | + public function _enqueue_and_localize_form_js() |
|
734 | + { |
|
735 | + $this->ensure_construct_finalized_called(); |
|
736 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
738 | + //and localize it just before the footer |
|
739 | + $this->localize_validation_rules(); |
|
740 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * add our form section data to a static variable accessible by all form sections |
|
747 | + * |
|
748 | + * @param bool $return_for_subsection |
|
749 | + * @return void |
|
750 | + * @throws EE_Error |
|
751 | + */ |
|
752 | + public function localize_validation_rules($return_for_subsection = false) |
|
753 | + { |
|
754 | + // we only want to localize vars ONCE for the entire form, |
|
755 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | + 'form_section_id' => $this->html_id(true), |
|
759 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | + 'other_data' => $this->get_other_js_data(), |
|
761 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | + ); |
|
763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | + * This is primarily data added by inputs and forms in addition to any |
|
771 | + * scripts they might enqueue |
|
772 | + * |
|
773 | + * @param array $form_other_js_data |
|
774 | + * @return array |
|
775 | + * @throws EE_Error |
|
776 | + */ |
|
777 | + public function get_other_js_data($form_other_js_data = array()) |
|
778 | + { |
|
779 | + foreach ($this->subsections() as $subsection) { |
|
780 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | + } |
|
782 | + return $form_other_js_data; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Gets a flat array of inputs for this form section and its subsections. |
|
788 | + * Keys are their form names, and values are the inputs themselves |
|
789 | + * |
|
790 | + * @return EE_Form_Input_Base |
|
791 | + * @throws EE_Error |
|
792 | + */ |
|
793 | + public function inputs_in_subsections() |
|
794 | + { |
|
795 | + $inputs = array(); |
|
796 | + foreach ($this->subsections() as $subsection) { |
|
797 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | + $inputs += $subsection->inputs_in_subsections(); |
|
801 | + } |
|
802 | + } |
|
803 | + return $inputs; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * Gets a flat array of all the validation errors. |
|
809 | + * Keys are html names (because those should be unique) |
|
810 | + * and values are a string of all their validation errors |
|
811 | + * |
|
812 | + * @return string[] |
|
813 | + * @throws EE_Error |
|
814 | + */ |
|
815 | + public function subsection_validation_errors_by_html_name() |
|
816 | + { |
|
817 | + $inputs = $this->inputs(); |
|
818 | + $errors = array(); |
|
819 | + foreach ($inputs as $form_input) { |
|
820 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | + } |
|
823 | + } |
|
824 | + return $errors; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | + * |
|
832 | + * @throws InvalidArgumentException |
|
833 | + * @throws InvalidInterfaceException |
|
834 | + * @throws InvalidDataTypeException |
|
835 | + */ |
|
836 | + public static function localize_script_for_all_forms() |
|
837 | + { |
|
838 | + //allow inputs and stuff to hook in their JS and stuff here |
|
839 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | + : 'wp_default'; |
|
844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | + wp_enqueue_script('ee_form_section_validation'); |
|
846 | + wp_localize_script( |
|
847 | + 'ee_form_section_validation', |
|
848 | + 'ee_form_section_vars', |
|
849 | + EE_Form_Section_Proper::$_js_localization |
|
850 | + ); |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * ensure_scripts_localized |
|
856 | + * |
|
857 | + * @throws EE_Error |
|
858 | + */ |
|
859 | + public function ensure_scripts_localized() |
|
860 | + { |
|
861 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | + $this->_enqueue_and_localize_form_js(); |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | + * |
|
871 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | + */ |
|
873 | + private static function _get_localized_error_messages() |
|
874 | + { |
|
875 | + return array( |
|
876 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | + ); |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * @return array |
|
884 | + */ |
|
885 | + public static function js_localization() |
|
886 | + { |
|
887 | + return self::$_js_localization; |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * @return void |
|
893 | + */ |
|
894 | + public static function reset_js_localization() |
|
895 | + { |
|
896 | + self::$_js_localization = array(); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | + * See parent function for more... |
|
903 | + * |
|
904 | + * @return array |
|
905 | + * @throws EE_Error |
|
906 | + */ |
|
907 | + public function get_jquery_validation_rules() |
|
908 | + { |
|
909 | + $jquery_validation_rules = array(); |
|
910 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | + $jquery_validation_rules = array_merge( |
|
912 | + $jquery_validation_rules, |
|
913 | + $subsection->get_jquery_validation_rules() |
|
914 | + ); |
|
915 | + } |
|
916 | + return $jquery_validation_rules; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Sanitizes all the data and sets the sanitized value of each field |
|
922 | + * |
|
923 | + * @param array $req_data like $_POST |
|
924 | + * @return void |
|
925 | + * @throws EE_Error |
|
926 | + */ |
|
927 | + protected function _normalize($req_data) |
|
928 | + { |
|
929 | + $this->_received_submission = true; |
|
930 | + $this->_validation_errors = array(); |
|
931 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | + try { |
|
933 | + $subsection->_normalize($req_data); |
|
934 | + } catch (EE_Validation_Error $e) { |
|
935 | + $subsection->add_validation_error($e); |
|
936 | + } |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + /** |
|
942 | + * Performs validation on this form section and its subsections. |
|
943 | + * For each subsection, |
|
944 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | + * and passes it the subsection, then calls _validate on that subsection. |
|
946 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | + * you would be best to override this _validate method, |
|
948 | + * calling parent::_validate() first. |
|
949 | + * |
|
950 | + * @throws EE_Error |
|
951 | + */ |
|
952 | + protected function _validate() |
|
953 | + { |
|
954 | + //reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | + $this->is_valid = null; |
|
956 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | + } |
|
960 | + $subsection->_validate(); |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * Gets all the validated inputs for the form section |
|
967 | + * |
|
968 | + * @return array |
|
969 | + * @throws EE_Error |
|
970 | + */ |
|
971 | + public function valid_data() |
|
972 | + { |
|
973 | + $inputs = array(); |
|
974 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | + } |
|
980 | + } |
|
981 | + return $inputs; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * Gets all the inputs on this form section |
|
987 | + * |
|
988 | + * @return EE_Form_Input_Base[] |
|
989 | + * @throws EE_Error |
|
990 | + */ |
|
991 | + public function inputs() |
|
992 | + { |
|
993 | + $inputs = array(); |
|
994 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | + $inputs[ $subsection_name ] = $subsection; |
|
997 | + } |
|
998 | + } |
|
999 | + return $inputs; |
|
1000 | + } |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * Gets all the subsections which are a proper form |
|
1005 | + * |
|
1006 | + * @return EE_Form_Section_Proper[] |
|
1007 | + * @throws EE_Error |
|
1008 | + */ |
|
1009 | + public function subforms() |
|
1010 | + { |
|
1011 | + $form_sections = array(); |
|
1012 | + foreach ($this->subsections() as $name => $obj) { |
|
1013 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | + $form_sections[ $name ] = $obj; |
|
1015 | + } |
|
1016 | + } |
|
1017 | + return $form_sections; |
|
1018 | + } |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | + * Consider using inputs() or subforms() |
|
1024 | + * if you only want form inputs or proper form sections. |
|
1025 | + * |
|
1026 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | + * leave this as TRUE so that the inputs will be properly |
|
1028 | + * configured. However, some client code may be ok with |
|
1029 | + * construction finalize being called later |
|
1030 | + * (realizing that the subsections' html names might not be |
|
1031 | + * set yet, etc.) |
|
1032 | + * @return EE_Form_Section_Proper[] |
|
1033 | + * @throws EE_Error |
|
1034 | + */ |
|
1035 | + public function subsections($require_construction_to_be_finalized = true) |
|
1036 | + { |
|
1037 | + if ($require_construction_to_be_finalized) { |
|
1038 | + $this->ensure_construct_finalized_called(); |
|
1039 | + } |
|
1040 | + return $this->_subsections; |
|
1041 | + } |
|
1042 | + |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Returns whether this form has any subforms or inputs |
|
1046 | + * @return bool |
|
1047 | + */ |
|
1048 | + public function hasSubsections() |
|
1049 | + { |
|
1050 | + return ! empty($this->_subsections); |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | + * values. (Similar to calling get_input_value on inputs) |
|
1057 | + * |
|
1058 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | + * or just this forms' direct children inputs |
|
1060 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | + * or allow multidimensional array |
|
1062 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | + * with array keys being input names |
|
1064 | + * (regardless of whether they are from a subsection or not), |
|
1065 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | + * where keys are always subsection names and values are either |
|
1067 | + * the input's normalized value, or an array like the top-level array |
|
1068 | + * @throws EE_Error |
|
1069 | + */ |
|
1070 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | + { |
|
1072 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | + * is not necessarily the value we want to display to users. This creates an array |
|
1080 | + * where keys are the input names, and values are their display values |
|
1081 | + * |
|
1082 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | + * or just this forms' direct children inputs |
|
1084 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | + * or allow multidimensional array |
|
1086 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | + * with array keys being input names |
|
1088 | + * (regardless of whether they are from a subsection or not), |
|
1089 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | + * where keys are always subsection names and values are either |
|
1091 | + * the input's normalized value, or an array like the top-level array |
|
1092 | + * @throws EE_Error |
|
1093 | + */ |
|
1094 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | + { |
|
1096 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Gets the input values from the form |
|
1102 | + * |
|
1103 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | + * or just the normalized value |
|
1105 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | + * or just this forms' direct children inputs |
|
1107 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | + * or allow multidimensional array |
|
1109 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | + * input names (regardless of whether they are from a subsection or not), |
|
1111 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | + * where keys are always subsection names and values are either |
|
1113 | + * the input's normalized value, or an array like the top-level array |
|
1114 | + * @throws EE_Error |
|
1115 | + */ |
|
1116 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | + { |
|
1118 | + $input_values = array(); |
|
1119 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | + $input_values[ $subsection_name ] = $pretty |
|
1122 | + ? $subsection->pretty_value() |
|
1123 | + : $subsection->normalized_value(); |
|
1124 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | + $subform_input_values = $subsection->_input_values( |
|
1126 | + $pretty, |
|
1127 | + $include_subform_inputs, |
|
1128 | + $flatten |
|
1129 | + ); |
|
1130 | + if ($flatten) { |
|
1131 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | + } else { |
|
1133 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | + } |
|
1135 | + } |
|
1136 | + } |
|
1137 | + return $input_values; |
|
1138 | + } |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Gets the originally submitted input values from the form |
|
1143 | + * |
|
1144 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | + * or just this forms' direct children inputs |
|
1146 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | + * with array keys being input names |
|
1148 | + * (regardless of whether they are from a subsection or not), |
|
1149 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | + * where keys are always subsection names and values are either |
|
1151 | + * the input's normalized value, or an array like the top-level array |
|
1152 | + * @throws EE_Error |
|
1153 | + */ |
|
1154 | + public function submitted_values($include_subforms = false) |
|
1155 | + { |
|
1156 | + $submitted_values = array(); |
|
1157 | + foreach ($this->subsections() as $subsection) { |
|
1158 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | + // is this input part of an array of inputs? |
|
1160 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | + explode( |
|
1163 | + '[', |
|
1164 | + str_replace(']', '', $subsection->html_name()) |
|
1165 | + ), |
|
1166 | + $subsection->raw_value() |
|
1167 | + ); |
|
1168 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | + } else { |
|
1170 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | + } |
|
1172 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + return $submitted_values; |
|
1178 | + } |
|
1179 | + |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Indicates whether or not this form has received a submission yet |
|
1183 | + * (ie, had receive_form_submission called on it yet) |
|
1184 | + * |
|
1185 | + * @return boolean |
|
1186 | + * @throws EE_Error |
|
1187 | + */ |
|
1188 | + public function has_received_submission() |
|
1189 | + { |
|
1190 | + $this->ensure_construct_finalized_called(); |
|
1191 | + return $this->_received_submission; |
|
1192 | + } |
|
1193 | + |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | + * Removes the listed inputs from the form |
|
1198 | + * |
|
1199 | + * @param array $inputs_to_exclude values are the input names |
|
1200 | + * @return void |
|
1201 | + */ |
|
1202 | + public function exclude(array $inputs_to_exclude = array()) |
|
1203 | + { |
|
1204 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | + } |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | + * @param array $inputs_to_hide |
|
1213 | + * @throws EE_Error |
|
1214 | + */ |
|
1215 | + public function hide(array $inputs_to_hide = array()) |
|
1216 | + { |
|
1217 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | + $input = $this->get_input($input_to_hide); |
|
1219 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * add_subsections |
|
1226 | + * Adds the listed subsections to the form section. |
|
1227 | + * If $subsection_name_to_target is provided, |
|
1228 | + * then new subsections are added before or after that subsection, |
|
1229 | + * otherwise to the start or end of the entire subsections array. |
|
1230 | + * |
|
1231 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | + * where keys are their names |
|
1233 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | + * should be added before or after |
|
1235 | + * IF $subsection_name_to_target is null, |
|
1236 | + * then $new_subsections will be added to |
|
1237 | + * the beginning or end of the entire subsections array |
|
1238 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | + * $subsection_name_to_target, |
|
1240 | + * or if $subsection_name_to_target is null, |
|
1241 | + * before or after entire subsections array |
|
1242 | + * @return void |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | + { |
|
1247 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | + EE_Error::add_error( |
|
1250 | + sprintf( |
|
1251 | + esc_html__( |
|
1252 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | + 'event_espresso' |
|
1254 | + ), |
|
1255 | + get_class($subsection), |
|
1256 | + $subsection_name, |
|
1257 | + $this->name() |
|
1258 | + ) |
|
1259 | + ); |
|
1260 | + unset($new_subsections[ $subsection_name ]); |
|
1261 | + } |
|
1262 | + } |
|
1263 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | + $this->_subsections, |
|
1265 | + $new_subsections, |
|
1266 | + $subsection_name_to_target, |
|
1267 | + $add_before |
|
1268 | + ); |
|
1269 | + if ($this->_construction_finalized) { |
|
1270 | + foreach ($this->_subsections as $name => $subsection) { |
|
1271 | + $subsection->_construct_finalize($this, $name); |
|
1272 | + } |
|
1273 | + } |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @param string $subsection_name |
|
1279 | + * @param bool $recursive |
|
1280 | + * @return bool |
|
1281 | + */ |
|
1282 | + public function has_subsection($subsection_name, $recursive = false) |
|
1283 | + { |
|
1284 | + foreach ($this->_subsections as $name => $subsection) {if( |
|
1285 | + $name === $subsection_name |
|
1286 | + || ( |
|
1287 | + $recursive |
|
1288 | + && $subsection instanceof EE_Form_Section_Proper |
|
1289 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | + ) |
|
1291 | + ) { |
|
1292 | + return true; |
|
1293 | + } |
|
1294 | + } |
|
1295 | + return false; |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * Just gets all validatable subsections to clean their sensitive data |
|
1302 | + * |
|
1303 | + * @throws EE_Error |
|
1304 | + */ |
|
1305 | + public function clean_sensitive_data() |
|
1306 | + { |
|
1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | + $subsection->clean_sensitive_data(); |
|
1309 | + } |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | + * @param string $form_submission_error_message |
|
1316 | + * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | + * @throws EE_Error |
|
1318 | + */ |
|
1319 | + public function set_submission_error_message( |
|
1320 | + $form_submission_error_message = '' |
|
1321 | + ) { |
|
1322 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | + ? $form_submission_error_message |
|
1324 | + : $this->getAllValidationErrorsString(); |
|
1325 | + } |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | + * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | + * set_submission_error_message |
|
1332 | + * |
|
1333 | + * @return string |
|
1334 | + */ |
|
1335 | + public function submission_error_message() |
|
1336 | + { |
|
1337 | + return $this->_form_submission_error_message; |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Sets a message to display if the data submitted to the form was valid. |
|
1343 | + * @param string $form_submission_success_message |
|
1344 | + */ |
|
1345 | + public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | + { |
|
1347 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | + ? $form_submission_success_message |
|
1349 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | + } |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | + * @return string |
|
1356 | + */ |
|
1357 | + public function submission_success_message() |
|
1358 | + { |
|
1359 | + return $this->_form_submission_success_message; |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Returns the prefix that should be used on child of this form section for |
|
1365 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | + * prefix onto this form section's prefix. Used primarily by |
|
1367 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | + * |
|
1369 | + * @return string |
|
1370 | + * @throws EE_Error |
|
1371 | + */ |
|
1372 | + public function html_name_prefix() |
|
1373 | + { |
|
1374 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | + } |
|
1377 | + return $this->name(); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | + * was set, which is probably nothing, or the classname) |
|
1385 | + * |
|
1386 | + * @return string |
|
1387 | + * @throws EE_Error |
|
1388 | + */ |
|
1389 | + public function name() |
|
1390 | + { |
|
1391 | + $this->ensure_construct_finalized_called(); |
|
1392 | + return parent::name(); |
|
1393 | + } |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * @return EE_Form_Section_Proper |
|
1398 | + * @throws EE_Error |
|
1399 | + */ |
|
1400 | + public function parent_section() |
|
1401 | + { |
|
1402 | + $this->ensure_construct_finalized_called(); |
|
1403 | + return parent::parent_section(); |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | + * |
|
1410 | + * @return void |
|
1411 | + * @throws EE_Error |
|
1412 | + */ |
|
1413 | + public function ensure_construct_finalized_called() |
|
1414 | + { |
|
1415 | + if (! $this->_construction_finalized) { |
|
1416 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | + } |
|
1418 | + } |
|
1419 | + |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | + * are in teh form data. If any are found, returns true. Else false |
|
1424 | + * |
|
1425 | + * @param array $req_data |
|
1426 | + * @return boolean |
|
1427 | + * @throws EE_Error |
|
1428 | + */ |
|
1429 | + public function form_data_present_in($req_data = null) |
|
1430 | + { |
|
1431 | + $req_data = $this->getCachedRequest($req_data); |
|
1432 | + foreach ($this->subsections() as $subsection) { |
|
1433 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | + if ($subsection->form_data_present_in($req_data)) { |
|
1435 | + return true; |
|
1436 | + } |
|
1437 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | + if ($subsection->form_data_present_in($req_data)) { |
|
1439 | + return true; |
|
1440 | + } |
|
1441 | + } |
|
1442 | + } |
|
1443 | + return false; |
|
1444 | + } |
|
1445 | + |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * Gets validation errors for this form section and subsections |
|
1449 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | + * gets the validation errors for ALL subsection |
|
1451 | + * |
|
1452 | + * @return EE_Validation_Error[] |
|
1453 | + * @throws EE_Error |
|
1454 | + */ |
|
1455 | + public function get_validation_errors_accumulated() |
|
1456 | + { |
|
1457 | + $validation_errors = $this->get_validation_errors(); |
|
1458 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | + } else { |
|
1462 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | + } |
|
1464 | + if ($validation_errors_on_this_subsection) { |
|
1465 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | + } |
|
1467 | + } |
|
1468 | + return $validation_errors; |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | + * |
|
1476 | + * @return string |
|
1477 | + * @since $VID:$ |
|
1478 | + */ |
|
1479 | + protected function getAllValidationErrorsString() |
|
1480 | + { |
|
1481 | + $submission_error_messages = array(); |
|
1482 | + // bad, bad, bad registrant |
|
1483 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | + $form_section = $validation_error->get_form_section(); |
|
1486 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | + } elseif($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | + $label = $validation_error->get_form_section()->name(); |
|
1490 | + } else { |
|
1491 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | + } |
|
1493 | + $submission_error_messages[] = sprintf( |
|
1494 | + __('%s : %s', 'event_espresso'), |
|
1495 | + $label, |
|
1496 | + $validation_error->getMessage() |
|
1497 | + ); |
|
1498 | + } |
|
1499 | + } |
|
1500 | + return implode('<br', $submission_error_messages); |
|
1501 | + } |
|
1502 | + |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | + * which will be returned. |
|
1510 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | + * Etc |
|
1515 | + * |
|
1516 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | + * @return EE_Form_Section_Base |
|
1518 | + * @throws EE_Error |
|
1519 | + */ |
|
1520 | + public function find_section_from_path($form_section_path) |
|
1521 | + { |
|
1522 | + //check if we can find the input from purely going straight up the tree |
|
1523 | + $input = parent::find_section_from_path($form_section_path); |
|
1524 | + if ($input instanceof EE_Form_Section_Base) { |
|
1525 | + return $input; |
|
1526 | + } |
|
1527 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | + if ($next_slash_pos !== false) { |
|
1529 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | + } else { |
|
1532 | + $child_section_name = $form_section_path; |
|
1533 | + $subpath = ''; |
|
1534 | + } |
|
1535 | + $child_section = $this->get_subsection($child_section_name); |
|
1536 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | + return $child_section->find_section_from_path($subpath); |
|
1538 | + } |
|
1539 | + return null; |
|
1540 | + } |
|
1541 | 1541 | } |
1542 | 1542 |
@@ -17,2460 +17,2460 @@ discard block |
||
17 | 17 | final class EE_Config implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - const OPTION_NAME = 'ee_config'; |
|
20 | + const OPTION_NAME = 'ee_config'; |
|
21 | + |
|
22 | + const LOG_NAME = 'ee_config_log'; |
|
23 | + |
|
24 | + const LOG_LENGTH = 100; |
|
25 | + |
|
26 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * instance of the EE_Config object |
|
31 | + * |
|
32 | + * @var EE_Config $_instance |
|
33 | + * @access private |
|
34 | + */ |
|
35 | + private static $_instance; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean $_logging_enabled |
|
39 | + */ |
|
40 | + private static $_logging_enabled = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
44 | + */ |
|
45 | + private $legacy_shortcodes_manager; |
|
46 | + |
|
47 | + /** |
|
48 | + * An StdClass whose property names are addon slugs, |
|
49 | + * and values are their config classes |
|
50 | + * |
|
51 | + * @var StdClass |
|
52 | + */ |
|
53 | + public $addons; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Admin_Config |
|
57 | + */ |
|
58 | + public $admin; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var EE_Core_Config |
|
62 | + */ |
|
63 | + public $core; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var EE_Currency_Config |
|
67 | + */ |
|
68 | + public $currency; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var EE_Organization_Config |
|
72 | + */ |
|
73 | + public $organization; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var EE_Registration_Config |
|
77 | + */ |
|
78 | + public $registration; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var EE_Template_Config |
|
82 | + */ |
|
83 | + public $template_settings; |
|
84 | + |
|
85 | + /** |
|
86 | + * Holds EE environment values. |
|
87 | + * |
|
88 | + * @var EE_Environment_Config |
|
89 | + */ |
|
90 | + public $environment; |
|
91 | + |
|
92 | + /** |
|
93 | + * settings pertaining to Google maps |
|
94 | + * |
|
95 | + * @var EE_Map_Config |
|
96 | + */ |
|
97 | + public $map_settings; |
|
98 | + |
|
99 | + /** |
|
100 | + * settings pertaining to Taxes |
|
101 | + * |
|
102 | + * @var EE_Tax_Config |
|
103 | + */ |
|
104 | + public $tax_settings; |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Settings pertaining to global messages settings. |
|
109 | + * |
|
110 | + * @var EE_Messages_Config |
|
111 | + */ |
|
112 | + public $messages; |
|
113 | + |
|
114 | + /** |
|
115 | + * @deprecated |
|
116 | + * @var EE_Gateway_Config |
|
117 | + */ |
|
118 | + public $gateway; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var array $_addon_option_names |
|
122 | + * @access private |
|
123 | + */ |
|
124 | + private $_addon_option_names = array(); |
|
125 | + |
|
126 | + /** |
|
127 | + * @var array $_module_route_map |
|
128 | + * @access private |
|
129 | + */ |
|
130 | + private static $_module_route_map = array(); |
|
131 | + |
|
132 | + /** |
|
133 | + * @var array $_module_forward_map |
|
134 | + * @access private |
|
135 | + */ |
|
136 | + private static $_module_forward_map = array(); |
|
137 | + |
|
138 | + /** |
|
139 | + * @var array $_module_view_map |
|
140 | + * @access private |
|
141 | + */ |
|
142 | + private static $_module_view_map = array(); |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @singleton method used to instantiate class object |
|
148 | + * @access public |
|
149 | + * @return EE_Config instance |
|
150 | + */ |
|
151 | + public static function instance() |
|
152 | + { |
|
153 | + // check if class object is instantiated, and instantiated properly |
|
154 | + if (! self::$_instance instanceof EE_Config) { |
|
155 | + self::$_instance = new self(); |
|
156 | + } |
|
157 | + return self::$_instance; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Resets the config |
|
164 | + * |
|
165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | + * reflect its state in the database |
|
168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | + * site was put into maintenance mode) |
|
172 | + * @return EE_Config |
|
173 | + */ |
|
174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | + { |
|
176 | + if (self::$_instance instanceof EE_Config) { |
|
177 | + if ($hard_reset) { |
|
178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
179 | + self::$_instance->_addon_option_names = array(); |
|
180 | + self::$_instance->_initialize_config(); |
|
181 | + self::$_instance->update_espresso_config(); |
|
182 | + } |
|
183 | + self::$_instance->update_addon_option_names(); |
|
184 | + } |
|
185 | + self::$_instance = null; |
|
186 | + //we don't need to reset the static properties imo because those should |
|
187 | + //only change when a module is added or removed. Currently we don't |
|
188 | + //support removing a module during a request when it previously existed |
|
189 | + if ($reinstantiate) { |
|
190 | + return self::instance(); |
|
191 | + } else { |
|
192 | + return null; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * class constructor |
|
200 | + * |
|
201 | + * @access private |
|
202 | + */ |
|
203 | + private function __construct() |
|
204 | + { |
|
205 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
206 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
207 | + // setup empty config classes |
|
208 | + $this->_initialize_config(); |
|
209 | + // load existing EE site settings |
|
210 | + $this->_load_core_config(); |
|
211 | + // confirm everything loaded correctly and set filtered defaults if not |
|
212 | + $this->_verify_config(); |
|
213 | + // register shortcodes and modules |
|
214 | + add_action( |
|
215 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
216 | + array($this, 'register_shortcodes_and_modules'), |
|
217 | + 999 |
|
218 | + ); |
|
219 | + // initialize shortcodes and modules |
|
220 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
221 | + // register widgets |
|
222 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
223 | + // shutdown |
|
224 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
225 | + // construct__end hook |
|
226 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
227 | + // hardcoded hack |
|
228 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @return boolean |
|
235 | + */ |
|
236 | + public static function logging_enabled() |
|
237 | + { |
|
238 | + return self::$_logging_enabled; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * use to get the current theme if needed from static context |
|
245 | + * |
|
246 | + * @return string current theme set. |
|
247 | + */ |
|
248 | + public static function get_current_theme() |
|
249 | + { |
|
250 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
251 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * _initialize_config |
|
258 | + * |
|
259 | + * @access private |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + private function _initialize_config() |
|
263 | + { |
|
264 | + EE_Config::trim_log(); |
|
265 | + //set defaults |
|
266 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
267 | + $this->addons = new stdClass(); |
|
268 | + // set _module_route_map |
|
269 | + EE_Config::$_module_route_map = array(); |
|
270 | + // set _module_forward_map |
|
271 | + EE_Config::$_module_forward_map = array(); |
|
272 | + // set _module_view_map |
|
273 | + EE_Config::$_module_view_map = array(); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * load core plugin configuration |
|
280 | + * |
|
281 | + * @access private |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + private function _load_core_config() |
|
285 | + { |
|
286 | + // load_core_config__start hook |
|
287 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
288 | + $espresso_config = $this->get_espresso_config(); |
|
289 | + foreach ($espresso_config as $config => $settings) { |
|
290 | + // load_core_config__start hook |
|
291 | + $settings = apply_filters( |
|
292 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
293 | + $settings, |
|
294 | + $config, |
|
295 | + $this |
|
296 | + ); |
|
297 | + if (is_object($settings) && property_exists($this, $config)) { |
|
298 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
299 | + //call configs populate method to ensure any defaults are set for empty values. |
|
300 | + if (method_exists($settings, 'populate')) { |
|
301 | + $this->{$config}->populate(); |
|
302 | + } |
|
303 | + if (method_exists($settings, 'do_hooks')) { |
|
304 | + $this->{$config}->do_hooks(); |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
309 | + $this->update_espresso_config(); |
|
310 | + } |
|
311 | + // load_core_config__end hook |
|
312 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * _verify_config |
|
319 | + * |
|
320 | + * @access protected |
|
321 | + * @return void |
|
322 | + */ |
|
323 | + protected function _verify_config() |
|
324 | + { |
|
325 | + $this->core = $this->core instanceof EE_Core_Config |
|
326 | + ? $this->core |
|
327 | + : new EE_Core_Config(); |
|
328 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
329 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
330 | + ? $this->organization |
|
331 | + : new EE_Organization_Config(); |
|
332 | + $this->organization = apply_filters( |
|
333 | + 'FHEE__EE_Config___initialize_config__organization', |
|
334 | + $this->organization |
|
335 | + ); |
|
336 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
337 | + ? $this->currency |
|
338 | + : new EE_Currency_Config(); |
|
339 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
340 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
341 | + ? $this->registration |
|
342 | + : new EE_Registration_Config(); |
|
343 | + $this->registration = apply_filters( |
|
344 | + 'FHEE__EE_Config___initialize_config__registration', |
|
345 | + $this->registration |
|
346 | + ); |
|
347 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
348 | + ? $this->admin |
|
349 | + : new EE_Admin_Config(); |
|
350 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
351 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
352 | + ? $this->template_settings |
|
353 | + : new EE_Template_Config(); |
|
354 | + $this->template_settings = apply_filters( |
|
355 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
356 | + $this->template_settings |
|
357 | + ); |
|
358 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
359 | + ? $this->map_settings |
|
360 | + : new EE_Map_Config(); |
|
361 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
362 | + $this->map_settings); |
|
363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | + ? $this->environment |
|
365 | + : new EE_Environment_Config(); |
|
366 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
367 | + $this->environment); |
|
368 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
369 | + ? $this->tax_settings |
|
370 | + : new EE_Tax_Config(); |
|
371 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
372 | + $this->tax_settings); |
|
373 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
374 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
375 | + ? $this->messages |
|
376 | + : new EE_Messages_Config(); |
|
377 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
378 | + ? $this->gateway |
|
379 | + : new EE_Gateway_Config(); |
|
380 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
381 | + $this->legacy_shortcodes_manager = null; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * get_espresso_config |
|
387 | + * |
|
388 | + * @access public |
|
389 | + * @return array of espresso config stuff |
|
390 | + */ |
|
391 | + public function get_espresso_config() |
|
392 | + { |
|
393 | + // grab espresso configuration |
|
394 | + return apply_filters( |
|
395 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
396 | + get_option(EE_Config::OPTION_NAME, array()) |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * double_check_config_comparison |
|
404 | + * |
|
405 | + * @access public |
|
406 | + * @param string $option |
|
407 | + * @param $old_value |
|
408 | + * @param $value |
|
409 | + */ |
|
410 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
411 | + { |
|
412 | + // make sure we're checking the ee config |
|
413 | + if ($option === EE_Config::OPTION_NAME) { |
|
414 | + // run a loose comparison of the old value against the new value for type and properties, |
|
415 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
416 | + if ($value != $old_value) { |
|
417 | + // if they are NOT the same, then remove the hook, |
|
418 | + // which means the subsequent update results will be based solely on the update query results |
|
419 | + // the reason we do this is because, as stated above, |
|
420 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
421 | + // this happens PRIOR to serialization and any subsequent update. |
|
422 | + // If values are found to match their previous old value, |
|
423 | + // then WP bails before performing any update. |
|
424 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
425 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
426 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
427 | + // MySQL MAY ALSO NOT perform the update because |
|
428 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
429 | + // This results in the query returning an "affected rows" value of ZERO, |
|
430 | + // which gets returned immediately by WP update_option and looks like an error. |
|
431 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * update_espresso_config |
|
440 | + * |
|
441 | + * @access public |
|
442 | + */ |
|
443 | + protected function _reset_espresso_addon_config() |
|
444 | + { |
|
445 | + $this->_addon_option_names = array(); |
|
446 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
447 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
448 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
449 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
450 | + } |
|
451 | + $this->addons->{$addon_name} = null; |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * update_espresso_config |
|
459 | + * |
|
460 | + * @access public |
|
461 | + * @param bool $add_success |
|
462 | + * @param bool $add_error |
|
463 | + * @return bool |
|
464 | + */ |
|
465 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
466 | + { |
|
467 | + // don't allow config updates during WP heartbeats |
|
468 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
469 | + return false; |
|
470 | + } |
|
471 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
472 | + //$clone = clone( self::$_instance ); |
|
473 | + //self::$_instance = NULL; |
|
474 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
475 | + $this->_reset_espresso_addon_config(); |
|
476 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
477 | + // but BEFORE the actual update occurs |
|
478 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
479 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
480 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
481 | + $this->legacy_shortcodes_manager = null; |
|
482 | + // now update "ee_config" |
|
483 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
484 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
485 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
486 | + // if not saved... check if the hook we just added still exists; |
|
487 | + // if it does, it means one of two things: |
|
488 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
489 | + // or... |
|
490 | + // the db update query returned 0 rows affected |
|
491 | + // (probably because the data value was the same from it's perspective) |
|
492 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
493 | + // but just means no update occurred, so don't display an error to the user. |
|
494 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
495 | + // then it means that something truly went wrong |
|
496 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
497 | + // remove our action since we don't want it in the system anymore |
|
498 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
499 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
500 | + //self::$_instance = $clone; |
|
501 | + //unset( $clone ); |
|
502 | + // if config remains the same or was updated successfully |
|
503 | + if ($saved) { |
|
504 | + if ($add_success) { |
|
505 | + EE_Error::add_success( |
|
506 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
507 | + __FILE__, |
|
508 | + __FUNCTION__, |
|
509 | + __LINE__ |
|
510 | + ); |
|
511 | + } |
|
512 | + return true; |
|
513 | + } else { |
|
514 | + if ($add_error) { |
|
515 | + EE_Error::add_error( |
|
516 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
517 | + __FILE__, |
|
518 | + __FUNCTION__, |
|
519 | + __LINE__ |
|
520 | + ); |
|
521 | + } |
|
522 | + return false; |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * _verify_config_params |
|
530 | + * |
|
531 | + * @access private |
|
532 | + * @param string $section |
|
533 | + * @param string $name |
|
534 | + * @param string $config_class |
|
535 | + * @param EE_Config_Base $config_obj |
|
536 | + * @param array $tests_to_run |
|
537 | + * @param bool $display_errors |
|
538 | + * @return bool TRUE on success, FALSE on fail |
|
539 | + */ |
|
540 | + private function _verify_config_params( |
|
541 | + $section = '', |
|
542 | + $name = '', |
|
543 | + $config_class = '', |
|
544 | + $config_obj = null, |
|
545 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
546 | + $display_errors = true |
|
547 | + ) { |
|
548 | + try { |
|
549 | + foreach ($tests_to_run as $test) { |
|
550 | + switch ($test) { |
|
551 | + // TEST #1 : check that section was set |
|
552 | + case 1 : |
|
553 | + if (empty($section)) { |
|
554 | + if ($display_errors) { |
|
555 | + throw new EE_Error( |
|
556 | + sprintf( |
|
557 | + __( |
|
558 | + 'No configuration section has been provided while attempting to save "%s".', |
|
559 | + 'event_espresso' |
|
560 | + ), |
|
561 | + $config_class |
|
562 | + ) |
|
563 | + ); |
|
564 | + } |
|
565 | + return false; |
|
566 | + } |
|
567 | + break; |
|
568 | + // TEST #2 : check that settings section exists |
|
569 | + case 2 : |
|
570 | + if (! isset($this->{$section})) { |
|
571 | + if ($display_errors) { |
|
572 | + throw new EE_Error( |
|
573 | + sprintf( |
|
574 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
575 | + $section |
|
576 | + ) |
|
577 | + ); |
|
578 | + } |
|
579 | + return false; |
|
580 | + } |
|
581 | + break; |
|
582 | + // TEST #3 : check that section is the proper format |
|
583 | + case 3 : |
|
584 | + if ( |
|
585 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
586 | + ) { |
|
587 | + if ($display_errors) { |
|
588 | + throw new EE_Error( |
|
589 | + sprintf( |
|
590 | + __( |
|
591 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
592 | + 'event_espresso' |
|
593 | + ), |
|
594 | + $section |
|
595 | + ) |
|
596 | + ); |
|
597 | + } |
|
598 | + return false; |
|
599 | + } |
|
600 | + break; |
|
601 | + // TEST #4 : check that config section name has been set |
|
602 | + case 4 : |
|
603 | + if (empty($name)) { |
|
604 | + if ($display_errors) { |
|
605 | + throw new EE_Error( |
|
606 | + __( |
|
607 | + 'No name has been provided for the specific configuration section.', |
|
608 | + 'event_espresso' |
|
609 | + ) |
|
610 | + ); |
|
611 | + } |
|
612 | + return false; |
|
613 | + } |
|
614 | + break; |
|
615 | + // TEST #5 : check that a config class name has been set |
|
616 | + case 5 : |
|
617 | + if (empty($config_class)) { |
|
618 | + if ($display_errors) { |
|
619 | + throw new EE_Error( |
|
620 | + __( |
|
621 | + 'No class name has been provided for the specific configuration section.', |
|
622 | + 'event_espresso' |
|
623 | + ) |
|
624 | + ); |
|
625 | + } |
|
626 | + return false; |
|
627 | + } |
|
628 | + break; |
|
629 | + // TEST #6 : verify config class is accessible |
|
630 | + case 6 : |
|
631 | + if (! class_exists($config_class)) { |
|
632 | + if ($display_errors) { |
|
633 | + throw new EE_Error( |
|
634 | + sprintf( |
|
635 | + __( |
|
636 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + $config_class |
|
640 | + ) |
|
641 | + ); |
|
642 | + } |
|
643 | + return false; |
|
644 | + } |
|
645 | + break; |
|
646 | + // TEST #7 : check that config has even been set |
|
647 | + case 7 : |
|
648 | + if (! isset($this->{$section}->{$name})) { |
|
649 | + if ($display_errors) { |
|
650 | + throw new EE_Error( |
|
651 | + sprintf( |
|
652 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
653 | + $section, |
|
654 | + $name |
|
655 | + ) |
|
656 | + ); |
|
657 | + } |
|
658 | + return false; |
|
659 | + } else { |
|
660 | + // and make sure it's not serialized |
|
661 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
662 | + } |
|
663 | + break; |
|
664 | + // TEST #8 : check that config is the requested type |
|
665 | + case 8 : |
|
666 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
667 | + if ($display_errors) { |
|
668 | + throw new EE_Error( |
|
669 | + sprintf( |
|
670 | + __( |
|
671 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
672 | + 'event_espresso' |
|
673 | + ), |
|
674 | + $section, |
|
675 | + $name, |
|
676 | + $config_class |
|
677 | + ) |
|
678 | + ); |
|
679 | + } |
|
680 | + return false; |
|
681 | + } |
|
682 | + break; |
|
683 | + // TEST #9 : verify config object |
|
684 | + case 9 : |
|
685 | + if (! $config_obj instanceof EE_Config_Base) { |
|
686 | + if ($display_errors) { |
|
687 | + throw new EE_Error( |
|
688 | + sprintf( |
|
689 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
690 | + print_r($config_obj, true) |
|
691 | + ) |
|
692 | + ); |
|
693 | + } |
|
694 | + return false; |
|
695 | + } |
|
696 | + break; |
|
697 | + } |
|
698 | + } |
|
699 | + } catch (EE_Error $e) { |
|
700 | + $e->get_error(); |
|
701 | + } |
|
702 | + // you have successfully run the gauntlet |
|
703 | + return true; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * _generate_config_option_name |
|
710 | + * |
|
711 | + * @access protected |
|
712 | + * @param string $section |
|
713 | + * @param string $name |
|
714 | + * @return string |
|
715 | + */ |
|
716 | + private function _generate_config_option_name($section = '', $name = '') |
|
717 | + { |
|
718 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * _set_config_class |
|
725 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
726 | + * |
|
727 | + * @access private |
|
728 | + * @param string $config_class |
|
729 | + * @param string $name |
|
730 | + * @return string |
|
731 | + */ |
|
732 | + private function _set_config_class($config_class = '', $name = '') |
|
733 | + { |
|
734 | + return ! empty($config_class) |
|
735 | + ? $config_class |
|
736 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * set_config |
|
743 | + * |
|
744 | + * @access protected |
|
745 | + * @param string $section |
|
746 | + * @param string $name |
|
747 | + * @param string $config_class |
|
748 | + * @param EE_Config_Base $config_obj |
|
749 | + * @return EE_Config_Base |
|
750 | + */ |
|
751 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
752 | + { |
|
753 | + // ensure config class is set to something |
|
754 | + $config_class = $this->_set_config_class($config_class, $name); |
|
755 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
756 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
757 | + return null; |
|
758 | + } |
|
759 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
760 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
761 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
762 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
763 | + $this->update_addon_option_names(); |
|
764 | + } |
|
765 | + // verify the incoming config object but suppress errors |
|
766 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
767 | + $config_obj = new $config_class(); |
|
768 | + } |
|
769 | + if (get_option($config_option_name)) { |
|
770 | + EE_Config::log($config_option_name); |
|
771 | + update_option($config_option_name, $config_obj); |
|
772 | + $this->{$section}->{$name} = $config_obj; |
|
773 | + return $this->{$section}->{$name}; |
|
774 | + } else { |
|
775 | + // create a wp-option for this config |
|
776 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
777 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
778 | + return $this->{$section}->{$name}; |
|
779 | + } else { |
|
780 | + EE_Error::add_error( |
|
781 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
782 | + __FILE__, |
|
783 | + __FUNCTION__, |
|
784 | + __LINE__ |
|
785 | + ); |
|
786 | + return null; |
|
787 | + } |
|
788 | + } |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * update_config |
|
795 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
796 | + * |
|
797 | + * @access public |
|
798 | + * @param string $section |
|
799 | + * @param string $name |
|
800 | + * @param EE_Config_Base|string $config_obj |
|
801 | + * @param bool $throw_errors |
|
802 | + * @return bool |
|
803 | + */ |
|
804 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
805 | + { |
|
806 | + // don't allow config updates during WP heartbeats |
|
807 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
808 | + return false; |
|
809 | + } |
|
810 | + $config_obj = maybe_unserialize($config_obj); |
|
811 | + // get class name of the incoming object |
|
812 | + $config_class = get_class($config_obj); |
|
813 | + // run tests 1-5 and 9 to verify config |
|
814 | + if (! $this->_verify_config_params( |
|
815 | + $section, |
|
816 | + $name, |
|
817 | + $config_class, |
|
818 | + $config_obj, |
|
819 | + array(1, 2, 3, 4, 7, 9) |
|
820 | + ) |
|
821 | + ) { |
|
822 | + return false; |
|
823 | + } |
|
824 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
825 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
826 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
827 | + // save new config to db |
|
828 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
829 | + return true; |
|
830 | + } |
|
831 | + } else { |
|
832 | + // first check if the record already exists |
|
833 | + $existing_config = get_option($config_option_name); |
|
834 | + $config_obj = serialize($config_obj); |
|
835 | + // just return if db record is already up to date (NOT type safe comparison) |
|
836 | + if ($existing_config == $config_obj) { |
|
837 | + $this->{$section}->{$name} = $config_obj; |
|
838 | + return true; |
|
839 | + } else if (update_option($config_option_name, $config_obj)) { |
|
840 | + EE_Config::log($config_option_name); |
|
841 | + // update wp-option for this config class |
|
842 | + $this->{$section}->{$name} = $config_obj; |
|
843 | + return true; |
|
844 | + } elseif ($throw_errors) { |
|
845 | + EE_Error::add_error( |
|
846 | + sprintf( |
|
847 | + __( |
|
848 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + $config_class, |
|
852 | + 'EE_Config->' . $section . '->' . $name |
|
853 | + ), |
|
854 | + __FILE__, |
|
855 | + __FUNCTION__, |
|
856 | + __LINE__ |
|
857 | + ); |
|
858 | + } |
|
859 | + } |
|
860 | + return false; |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * get_config |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @param string $section |
|
870 | + * @param string $name |
|
871 | + * @param string $config_class |
|
872 | + * @return mixed EE_Config_Base | NULL |
|
873 | + */ |
|
874 | + public function get_config($section = '', $name = '', $config_class = '') |
|
875 | + { |
|
876 | + // ensure config class is set to something |
|
877 | + $config_class = $this->_set_config_class($config_class, $name); |
|
878 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
879 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
880 | + return null; |
|
881 | + } |
|
882 | + // now test if the requested config object exists, but suppress errors |
|
883 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
884 | + // config already exists, so pass it back |
|
885 | + return $this->{$section}->{$name}; |
|
886 | + } |
|
887 | + // load config option from db if it exists |
|
888 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
889 | + // verify the newly retrieved config object, but suppress errors |
|
890 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
891 | + // config is good, so set it and pass it back |
|
892 | + $this->{$section}->{$name} = $config_obj; |
|
893 | + return $this->{$section}->{$name}; |
|
894 | + } |
|
895 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
896 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
897 | + // verify the newly created config object |
|
898 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
899 | + return $this->{$section}->{$name}; |
|
900 | + } else { |
|
901 | + EE_Error::add_error( |
|
902 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
903 | + __FILE__, |
|
904 | + __FUNCTION__, |
|
905 | + __LINE__ |
|
906 | + ); |
|
907 | + } |
|
908 | + return null; |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + |
|
913 | + /** |
|
914 | + * get_config_option |
|
915 | + * |
|
916 | + * @access public |
|
917 | + * @param string $config_option_name |
|
918 | + * @return mixed EE_Config_Base | FALSE |
|
919 | + */ |
|
920 | + public function get_config_option($config_option_name = '') |
|
921 | + { |
|
922 | + // retrieve the wp-option for this config class. |
|
923 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
924 | + if (empty($config_option)) { |
|
925 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
926 | + } |
|
927 | + return $config_option; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + |
|
932 | + /** |
|
933 | + * log |
|
934 | + * |
|
935 | + * @param string $config_option_name |
|
936 | + */ |
|
937 | + public static function log($config_option_name = '') |
|
938 | + { |
|
939 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
940 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
941 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
942 | + $_request = $_REQUEST; |
|
943 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
944 | + $config_log[(string)microtime(true)] = array( |
|
945 | + 'config_name' => $config_option_name, |
|
946 | + 'request' => $_request, |
|
947 | + ); |
|
948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
949 | + } |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * trim_log |
|
956 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
957 | + */ |
|
958 | + public static function trim_log() |
|
959 | + { |
|
960 | + if (! EE_Config::logging_enabled()) { |
|
961 | + return; |
|
962 | + } |
|
963 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
964 | + $log_length = count($config_log); |
|
965 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
966 | + ksort($config_log); |
|
967 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
968 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
969 | + } |
|
970 | + } |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * get_page_for_posts |
|
976 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
977 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
978 | + * |
|
979 | + * @access public |
|
980 | + * @return string |
|
981 | + */ |
|
982 | + public static function get_page_for_posts() |
|
983 | + { |
|
984 | + $page_for_posts = get_option('page_for_posts'); |
|
985 | + if (! $page_for_posts) { |
|
986 | + return 'posts'; |
|
987 | + } |
|
988 | + /** @type WPDB $wpdb */ |
|
989 | + global $wpdb; |
|
990 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
991 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * register_shortcodes_and_modules. |
|
998 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
999 | + * In fact, this is where we give modules a chance to let core know they exist |
|
1000 | + * so they can help trigger maintenance mode if it's needed |
|
1001 | + * |
|
1002 | + * @access public |
|
1003 | + * @return void |
|
1004 | + */ |
|
1005 | + public function register_shortcodes_and_modules() |
|
1006 | + { |
|
1007 | + // allow modules to set hooks for the rest of the system |
|
1008 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * initialize_shortcodes_and_modules |
|
1015 | + * meaning they can start adding their hooks to get stuff done |
|
1016 | + * |
|
1017 | + * @access public |
|
1018 | + * @return void |
|
1019 | + */ |
|
1020 | + public function initialize_shortcodes_and_modules() |
|
1021 | + { |
|
1022 | + // allow modules to set hooks for the rest of the system |
|
1023 | + $this->_initialize_modules(); |
|
1024 | + } |
|
1025 | + |
|
1026 | + |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * widgets_init |
|
1030 | + * |
|
1031 | + * @access private |
|
1032 | + * @return void |
|
1033 | + */ |
|
1034 | + public function widgets_init() |
|
1035 | + { |
|
1036 | + //only init widgets on admin pages when not in complete maintenance, and |
|
1037 | + //on frontend when not in any maintenance mode |
|
1038 | + if ( |
|
1039 | + ! EE_Maintenance_Mode::instance()->level() |
|
1040 | + || ( |
|
1041 | + is_admin() |
|
1042 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1043 | + ) |
|
1044 | + ) { |
|
1045 | + // grab list of installed widgets |
|
1046 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1047 | + // filter list of modules to register |
|
1048 | + $widgets_to_register = apply_filters( |
|
1049 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1050 | + $widgets_to_register |
|
1051 | + ); |
|
1052 | + if (! empty($widgets_to_register)) { |
|
1053 | + // cycle thru widget folders |
|
1054 | + foreach ($widgets_to_register as $widget_path) { |
|
1055 | + // add to list of installed widget modules |
|
1056 | + EE_Config::register_ee_widget($widget_path); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + // filter list of installed modules |
|
1060 | + EE_Registry::instance()->widgets = apply_filters( |
|
1061 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1062 | + EE_Registry::instance()->widgets |
|
1063 | + ); |
|
1064 | + } |
|
1065 | + } |
|
1066 | + |
|
1067 | + |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * register_ee_widget - makes core aware of this widget |
|
1071 | + * |
|
1072 | + * @access public |
|
1073 | + * @param string $widget_path - full path up to and including widget folder |
|
1074 | + * @return void |
|
1075 | + */ |
|
1076 | + public static function register_ee_widget($widget_path = null) |
|
1077 | + { |
|
1078 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1079 | + $widget_ext = '.widget.php'; |
|
1080 | + // make all separators match |
|
1081 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1082 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1083 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
1084 | + // grab and shortcode file name from directory name and break apart at dots |
|
1085 | + $file_name = explode('.', basename($widget_path)); |
|
1086 | + // take first segment from file name pieces and remove class prefix if it exists |
|
1087 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1088 | + // sanitize shortcode directory name |
|
1089 | + $widget = sanitize_key($widget); |
|
1090 | + // now we need to rebuild the shortcode path |
|
1091 | + $widget_path = explode(DS, $widget_path); |
|
1092 | + // remove last segment |
|
1093 | + array_pop($widget_path); |
|
1094 | + // glue it back together |
|
1095 | + $widget_path = implode(DS, $widget_path); |
|
1096 | + } else { |
|
1097 | + // grab and sanitize widget directory name |
|
1098 | + $widget = sanitize_key(basename($widget_path)); |
|
1099 | + } |
|
1100 | + // create classname from widget directory name |
|
1101 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1102 | + // add class prefix |
|
1103 | + $widget_class = 'EEW_' . $widget; |
|
1104 | + // does the widget exist ? |
|
1105 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1106 | + $msg = sprintf( |
|
1107 | + __( |
|
1108 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1109 | + 'event_espresso' |
|
1110 | + ), |
|
1111 | + $widget_class, |
|
1112 | + $widget_path . DS . $widget_class . $widget_ext |
|
1113 | + ); |
|
1114 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1115 | + return; |
|
1116 | + } |
|
1117 | + // load the widget class file |
|
1118 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1119 | + // verify that class exists |
|
1120 | + if (! class_exists($widget_class)) { |
|
1121 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1122 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1123 | + return; |
|
1124 | + } |
|
1125 | + register_widget($widget_class); |
|
1126 | + // add to array of registered widgets |
|
1127 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * _register_modules |
|
1134 | + * |
|
1135 | + * @access private |
|
1136 | + * @return array |
|
1137 | + */ |
|
1138 | + private function _register_modules() |
|
1139 | + { |
|
1140 | + // grab list of installed modules |
|
1141 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1142 | + // filter list of modules to register |
|
1143 | + $modules_to_register = apply_filters( |
|
1144 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1145 | + $modules_to_register |
|
1146 | + ); |
|
1147 | + if (! empty($modules_to_register)) { |
|
1148 | + // loop through folders |
|
1149 | + foreach ($modules_to_register as $module_path) { |
|
1150 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1151 | + if ( |
|
1152 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1153 | + && $module_path !== EE_MODULES . 'gateways' |
|
1154 | + ) { |
|
1155 | + // add to list of installed modules |
|
1156 | + EE_Config::register_module($module_path); |
|
1157 | + } |
|
1158 | + } |
|
1159 | + } |
|
1160 | + // filter list of installed modules |
|
1161 | + return apply_filters( |
|
1162 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
1163 | + EE_Registry::instance()->modules |
|
1164 | + ); |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * register_module - makes core aware of this module |
|
1171 | + * |
|
1172 | + * @access public |
|
1173 | + * @param string $module_path - full path up to and including module folder |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | + public static function register_module($module_path = null) |
|
1177 | + { |
|
1178 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1179 | + $module_ext = '.module.php'; |
|
1180 | + // make all separators match |
|
1181 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1182 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1183 | + if (strpos($module_path, $module_ext) !== false) { |
|
1184 | + // grab and shortcode file name from directory name and break apart at dots |
|
1185 | + $module_file = explode('.', basename($module_path)); |
|
1186 | + // now we need to rebuild the shortcode path |
|
1187 | + $module_path = explode(DS, $module_path); |
|
1188 | + // remove last segment |
|
1189 | + array_pop($module_path); |
|
1190 | + // glue it back together |
|
1191 | + $module_path = implode(DS, $module_path) . DS; |
|
1192 | + // take first segment from file name pieces and sanitize it |
|
1193 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1194 | + // ensure class prefix is added |
|
1195 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1196 | + } else { |
|
1197 | + // we need to generate the filename based off of the folder name |
|
1198 | + // grab and sanitize module name |
|
1199 | + $module = strtolower(basename($module_path)); |
|
1200 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1201 | + // like trailingslashit() |
|
1202 | + $module_path = rtrim($module_path, DS) . DS; |
|
1203 | + // create classname from module directory name |
|
1204 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1205 | + // add class prefix |
|
1206 | + $module_class = 'EED_' . $module; |
|
1207 | + } |
|
1208 | + // does the module exist ? |
|
1209 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1210 | + $msg = sprintf( |
|
1211 | + __( |
|
1212 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1213 | + 'event_espresso' |
|
1214 | + ), |
|
1215 | + $module |
|
1216 | + ); |
|
1217 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1218 | + return false; |
|
1219 | + } |
|
1220 | + // load the module class file |
|
1221 | + require_once($module_path . $module_class . $module_ext); |
|
1222 | + // verify that class exists |
|
1223 | + if (! class_exists($module_class)) { |
|
1224 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1225 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1226 | + return false; |
|
1227 | + } |
|
1228 | + // add to array of registered modules |
|
1229 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1230 | + do_action( |
|
1231 | + 'AHEE__EE_Config__register_module__complete', |
|
1232 | + $module_class, |
|
1233 | + EE_Registry::instance()->modules->{$module_class} |
|
1234 | + ); |
|
1235 | + return true; |
|
1236 | + } |
|
1237 | + |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * _initialize_modules |
|
1242 | + * allow modules to set hooks for the rest of the system |
|
1243 | + * |
|
1244 | + * @access private |
|
1245 | + * @return void |
|
1246 | + */ |
|
1247 | + private function _initialize_modules() |
|
1248 | + { |
|
1249 | + // cycle thru shortcode folders |
|
1250 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1251 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1252 | + // which set hooks ? |
|
1253 | + if (is_admin()) { |
|
1254 | + // fire immediately |
|
1255 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
1256 | + } else { |
|
1257 | + // delay until other systems are online |
|
1258 | + add_action( |
|
1259 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1260 | + array($module_class, 'set_hooks') |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + } |
|
1265 | + |
|
1266 | + |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * register_route - adds module method routes to route_map |
|
1270 | + * |
|
1271 | + * @access public |
|
1272 | + * @param string $route - "pretty" public alias for module method |
|
1273 | + * @param string $module - module name (classname without EED_ prefix) |
|
1274 | + * @param string $method_name - the actual module method to be routed to |
|
1275 | + * @param string $key - url param key indicating a route is being called |
|
1276 | + * @return bool |
|
1277 | + */ |
|
1278 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1279 | + { |
|
1280 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1281 | + $module = str_replace('EED_', '', $module); |
|
1282 | + $module_class = 'EED_' . $module; |
|
1283 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1284 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1285 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1286 | + return false; |
|
1287 | + } |
|
1288 | + if (empty($route)) { |
|
1289 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1290 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1291 | + return false; |
|
1292 | + } |
|
1293 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
1294 | + $msg = sprintf( |
|
1295 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1296 | + $route |
|
1297 | + ); |
|
1298 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1299 | + return false; |
|
1300 | + } |
|
1301 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1302 | + return true; |
|
1303 | + } |
|
1304 | + |
|
1305 | + |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * get_route - get module method route |
|
1309 | + * |
|
1310 | + * @access public |
|
1311 | + * @param string $route - "pretty" public alias for module method |
|
1312 | + * @param string $key - url param key indicating a route is being called |
|
1313 | + * @return string |
|
1314 | + */ |
|
1315 | + public static function get_route($route = null, $key = 'ee') |
|
1316 | + { |
|
1317 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1318 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1319 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1320 | + return EE_Config::$_module_route_map[$key][$route]; |
|
1321 | + } |
|
1322 | + return null; |
|
1323 | + } |
|
1324 | + |
|
1325 | + |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * get_routes - get ALL module method routes |
|
1329 | + * |
|
1330 | + * @access public |
|
1331 | + * @return array |
|
1332 | + */ |
|
1333 | + public static function get_routes() |
|
1334 | + { |
|
1335 | + return EE_Config::$_module_route_map; |
|
1336 | + } |
|
1337 | + |
|
1338 | + |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * register_forward - allows modules to forward request to another module for further processing |
|
1342 | + * |
|
1343 | + * @access public |
|
1344 | + * @param string $route - "pretty" public alias for module method |
|
1345 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1346 | + * class, allows different forwards to be served based on status |
|
1347 | + * @param array|string $forward - function name or array( class, method ) |
|
1348 | + * @param string $key - url param key indicating a route is being called |
|
1349 | + * @return bool |
|
1350 | + */ |
|
1351 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1352 | + { |
|
1353 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1354 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1355 | + $msg = sprintf( |
|
1356 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1357 | + $route |
|
1358 | + ); |
|
1359 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1360 | + return false; |
|
1361 | + } |
|
1362 | + if (empty($forward)) { |
|
1363 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1364 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1365 | + return false; |
|
1366 | + } |
|
1367 | + if (is_array($forward)) { |
|
1368 | + if (! isset($forward[1])) { |
|
1369 | + $msg = sprintf( |
|
1370 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1371 | + $route |
|
1372 | + ); |
|
1373 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1374 | + return false; |
|
1375 | + } |
|
1376 | + if (! method_exists($forward[0], $forward[1])) { |
|
1377 | + $msg = sprintf( |
|
1378 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1379 | + $forward[1], |
|
1380 | + $route |
|
1381 | + ); |
|
1382 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1383 | + return false; |
|
1384 | + } |
|
1385 | + } else if (! function_exists($forward)) { |
|
1386 | + $msg = sprintf( |
|
1387 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1388 | + $forward, |
|
1389 | + $route |
|
1390 | + ); |
|
1391 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1392 | + return false; |
|
1393 | + } |
|
1394 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1395 | + return true; |
|
1396 | + } |
|
1397 | + |
|
1398 | + |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * get_forward - get forwarding route |
|
1402 | + * |
|
1403 | + * @access public |
|
1404 | + * @param string $route - "pretty" public alias for module method |
|
1405 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1406 | + * allows different forwards to be served based on status |
|
1407 | + * @param string $key - url param key indicating a route is being called |
|
1408 | + * @return string |
|
1409 | + */ |
|
1410 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1411 | + { |
|
1412 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1413 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1414 | + return apply_filters( |
|
1415 | + 'FHEE__EE_Config__get_forward', |
|
1416 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
1417 | + $route, |
|
1418 | + $status |
|
1419 | + ); |
|
1420 | + } |
|
1421 | + return null; |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
1428 | + * results |
|
1429 | + * |
|
1430 | + * @access public |
|
1431 | + * @param string $route - "pretty" public alias for module method |
|
1432 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1433 | + * allows different views to be served based on status |
|
1434 | + * @param string $view |
|
1435 | + * @param string $key - url param key indicating a route is being called |
|
1436 | + * @return bool |
|
1437 | + */ |
|
1438 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1439 | + { |
|
1440 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1441 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1442 | + $msg = sprintf( |
|
1443 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1444 | + $route |
|
1445 | + ); |
|
1446 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1447 | + return false; |
|
1448 | + } |
|
1449 | + if (! is_readable($view)) { |
|
1450 | + $msg = sprintf( |
|
1451 | + __( |
|
1452 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
1453 | + 'event_espresso' |
|
1454 | + ), |
|
1455 | + $view |
|
1456 | + ); |
|
1457 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1461 | + return true; |
|
1462 | + } |
|
1463 | + |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * get_view - get view for route and status |
|
1468 | + * |
|
1469 | + * @access public |
|
1470 | + * @param string $route - "pretty" public alias for module method |
|
1471 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1472 | + * allows different views to be served based on status |
|
1473 | + * @param string $key - url param key indicating a route is being called |
|
1474 | + * @return string |
|
1475 | + */ |
|
1476 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1477 | + { |
|
1478 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1479 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1480 | + return apply_filters( |
|
1481 | + 'FHEE__EE_Config__get_view', |
|
1482 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
1483 | + $route, |
|
1484 | + $status |
|
1485 | + ); |
|
1486 | + } |
|
1487 | + return null; |
|
1488 | + } |
|
1489 | + |
|
1490 | + |
|
1491 | + |
|
1492 | + public function update_addon_option_names() |
|
1493 | + { |
|
1494 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1495 | + } |
|
1496 | + |
|
1497 | + |
|
1498 | + |
|
1499 | + public function shutdown() |
|
1500 | + { |
|
1501 | + $this->update_addon_option_names(); |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * @return LegacyShortcodesManager |
|
1508 | + */ |
|
1509 | + public static function getLegacyShortcodesManager() |
|
1510 | + { |
|
1511 | + |
|
1512 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1513 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1514 | + EE_Registry::instance() |
|
1515 | + ); |
|
1516 | + } |
|
1517 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
1518 | + } |
|
1519 | + |
|
1520 | + |
|
1521 | + |
|
1522 | + /** |
|
1523 | + * register_shortcode - makes core aware of this shortcode |
|
1524 | + * |
|
1525 | + * @deprecated 4.9.26 |
|
1526 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
1527 | + * @return bool |
|
1528 | + */ |
|
1529 | + public static function register_shortcode($shortcode_path = null) |
|
1530 | + { |
|
1531 | + EE_Error::doing_it_wrong( |
|
1532 | + __METHOD__, |
|
1533 | + __( |
|
1534 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1535 | + 'event_espresso' |
|
1536 | + ), |
|
1537 | + '4.9.26' |
|
1538 | + ); |
|
1539 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1540 | + } |
|
21 | 1541 | |
22 | - const LOG_NAME = 'ee_config_log'; |
|
23 | 1542 | |
24 | - const LOG_LENGTH = 100; |
|
25 | 1543 | |
26 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * instance of the EE_Config object |
|
31 | - * |
|
32 | - * @var EE_Config $_instance |
|
33 | - * @access private |
|
34 | - */ |
|
35 | - private static $_instance; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean $_logging_enabled |
|
39 | - */ |
|
40 | - private static $_logging_enabled = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
44 | - */ |
|
45 | - private $legacy_shortcodes_manager; |
|
46 | - |
|
47 | - /** |
|
48 | - * An StdClass whose property names are addon slugs, |
|
49 | - * and values are their config classes |
|
50 | - * |
|
51 | - * @var StdClass |
|
52 | - */ |
|
53 | - public $addons; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Admin_Config |
|
57 | - */ |
|
58 | - public $admin; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var EE_Core_Config |
|
62 | - */ |
|
63 | - public $core; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var EE_Currency_Config |
|
67 | - */ |
|
68 | - public $currency; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var EE_Organization_Config |
|
72 | - */ |
|
73 | - public $organization; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var EE_Registration_Config |
|
77 | - */ |
|
78 | - public $registration; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var EE_Template_Config |
|
82 | - */ |
|
83 | - public $template_settings; |
|
84 | - |
|
85 | - /** |
|
86 | - * Holds EE environment values. |
|
87 | - * |
|
88 | - * @var EE_Environment_Config |
|
89 | - */ |
|
90 | - public $environment; |
|
91 | - |
|
92 | - /** |
|
93 | - * settings pertaining to Google maps |
|
94 | - * |
|
95 | - * @var EE_Map_Config |
|
96 | - */ |
|
97 | - public $map_settings; |
|
98 | - |
|
99 | - /** |
|
100 | - * settings pertaining to Taxes |
|
101 | - * |
|
102 | - * @var EE_Tax_Config |
|
103 | - */ |
|
104 | - public $tax_settings; |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Settings pertaining to global messages settings. |
|
109 | - * |
|
110 | - * @var EE_Messages_Config |
|
111 | - */ |
|
112 | - public $messages; |
|
113 | - |
|
114 | - /** |
|
115 | - * @deprecated |
|
116 | - * @var EE_Gateway_Config |
|
117 | - */ |
|
118 | - public $gateway; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var array $_addon_option_names |
|
122 | - * @access private |
|
123 | - */ |
|
124 | - private $_addon_option_names = array(); |
|
125 | - |
|
126 | - /** |
|
127 | - * @var array $_module_route_map |
|
128 | - * @access private |
|
129 | - */ |
|
130 | - private static $_module_route_map = array(); |
|
131 | - |
|
132 | - /** |
|
133 | - * @var array $_module_forward_map |
|
134 | - * @access private |
|
135 | - */ |
|
136 | - private static $_module_forward_map = array(); |
|
137 | - |
|
138 | - /** |
|
139 | - * @var array $_module_view_map |
|
140 | - * @access private |
|
141 | - */ |
|
142 | - private static $_module_view_map = array(); |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @singleton method used to instantiate class object |
|
148 | - * @access public |
|
149 | - * @return EE_Config instance |
|
150 | - */ |
|
151 | - public static function instance() |
|
152 | - { |
|
153 | - // check if class object is instantiated, and instantiated properly |
|
154 | - if (! self::$_instance instanceof EE_Config) { |
|
155 | - self::$_instance = new self(); |
|
156 | - } |
|
157 | - return self::$_instance; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Resets the config |
|
164 | - * |
|
165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | - * reflect its state in the database |
|
168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | - * site was put into maintenance mode) |
|
172 | - * @return EE_Config |
|
173 | - */ |
|
174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | - { |
|
176 | - if (self::$_instance instanceof EE_Config) { |
|
177 | - if ($hard_reset) { |
|
178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
179 | - self::$_instance->_addon_option_names = array(); |
|
180 | - self::$_instance->_initialize_config(); |
|
181 | - self::$_instance->update_espresso_config(); |
|
182 | - } |
|
183 | - self::$_instance->update_addon_option_names(); |
|
184 | - } |
|
185 | - self::$_instance = null; |
|
186 | - //we don't need to reset the static properties imo because those should |
|
187 | - //only change when a module is added or removed. Currently we don't |
|
188 | - //support removing a module during a request when it previously existed |
|
189 | - if ($reinstantiate) { |
|
190 | - return self::instance(); |
|
191 | - } else { |
|
192 | - return null; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * class constructor |
|
200 | - * |
|
201 | - * @access private |
|
202 | - */ |
|
203 | - private function __construct() |
|
204 | - { |
|
205 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
206 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
207 | - // setup empty config classes |
|
208 | - $this->_initialize_config(); |
|
209 | - // load existing EE site settings |
|
210 | - $this->_load_core_config(); |
|
211 | - // confirm everything loaded correctly and set filtered defaults if not |
|
212 | - $this->_verify_config(); |
|
213 | - // register shortcodes and modules |
|
214 | - add_action( |
|
215 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
216 | - array($this, 'register_shortcodes_and_modules'), |
|
217 | - 999 |
|
218 | - ); |
|
219 | - // initialize shortcodes and modules |
|
220 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
221 | - // register widgets |
|
222 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
223 | - // shutdown |
|
224 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
225 | - // construct__end hook |
|
226 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
227 | - // hardcoded hack |
|
228 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @return boolean |
|
235 | - */ |
|
236 | - public static function logging_enabled() |
|
237 | - { |
|
238 | - return self::$_logging_enabled; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * use to get the current theme if needed from static context |
|
245 | - * |
|
246 | - * @return string current theme set. |
|
247 | - */ |
|
248 | - public static function get_current_theme() |
|
249 | - { |
|
250 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
251 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * _initialize_config |
|
258 | - * |
|
259 | - * @access private |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - private function _initialize_config() |
|
263 | - { |
|
264 | - EE_Config::trim_log(); |
|
265 | - //set defaults |
|
266 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
267 | - $this->addons = new stdClass(); |
|
268 | - // set _module_route_map |
|
269 | - EE_Config::$_module_route_map = array(); |
|
270 | - // set _module_forward_map |
|
271 | - EE_Config::$_module_forward_map = array(); |
|
272 | - // set _module_view_map |
|
273 | - EE_Config::$_module_view_map = array(); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * load core plugin configuration |
|
280 | - * |
|
281 | - * @access private |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - private function _load_core_config() |
|
285 | - { |
|
286 | - // load_core_config__start hook |
|
287 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
288 | - $espresso_config = $this->get_espresso_config(); |
|
289 | - foreach ($espresso_config as $config => $settings) { |
|
290 | - // load_core_config__start hook |
|
291 | - $settings = apply_filters( |
|
292 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
293 | - $settings, |
|
294 | - $config, |
|
295 | - $this |
|
296 | - ); |
|
297 | - if (is_object($settings) && property_exists($this, $config)) { |
|
298 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
299 | - //call configs populate method to ensure any defaults are set for empty values. |
|
300 | - if (method_exists($settings, 'populate')) { |
|
301 | - $this->{$config}->populate(); |
|
302 | - } |
|
303 | - if (method_exists($settings, 'do_hooks')) { |
|
304 | - $this->{$config}->do_hooks(); |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
309 | - $this->update_espresso_config(); |
|
310 | - } |
|
311 | - // load_core_config__end hook |
|
312 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * _verify_config |
|
319 | - * |
|
320 | - * @access protected |
|
321 | - * @return void |
|
322 | - */ |
|
323 | - protected function _verify_config() |
|
324 | - { |
|
325 | - $this->core = $this->core instanceof EE_Core_Config |
|
326 | - ? $this->core |
|
327 | - : new EE_Core_Config(); |
|
328 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
329 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
330 | - ? $this->organization |
|
331 | - : new EE_Organization_Config(); |
|
332 | - $this->organization = apply_filters( |
|
333 | - 'FHEE__EE_Config___initialize_config__organization', |
|
334 | - $this->organization |
|
335 | - ); |
|
336 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
337 | - ? $this->currency |
|
338 | - : new EE_Currency_Config(); |
|
339 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
340 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
341 | - ? $this->registration |
|
342 | - : new EE_Registration_Config(); |
|
343 | - $this->registration = apply_filters( |
|
344 | - 'FHEE__EE_Config___initialize_config__registration', |
|
345 | - $this->registration |
|
346 | - ); |
|
347 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
348 | - ? $this->admin |
|
349 | - : new EE_Admin_Config(); |
|
350 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
351 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
352 | - ? $this->template_settings |
|
353 | - : new EE_Template_Config(); |
|
354 | - $this->template_settings = apply_filters( |
|
355 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
356 | - $this->template_settings |
|
357 | - ); |
|
358 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
359 | - ? $this->map_settings |
|
360 | - : new EE_Map_Config(); |
|
361 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
362 | - $this->map_settings); |
|
363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | - ? $this->environment |
|
365 | - : new EE_Environment_Config(); |
|
366 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
367 | - $this->environment); |
|
368 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
369 | - ? $this->tax_settings |
|
370 | - : new EE_Tax_Config(); |
|
371 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
372 | - $this->tax_settings); |
|
373 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
374 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
375 | - ? $this->messages |
|
376 | - : new EE_Messages_Config(); |
|
377 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
378 | - ? $this->gateway |
|
379 | - : new EE_Gateway_Config(); |
|
380 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
381 | - $this->legacy_shortcodes_manager = null; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * get_espresso_config |
|
387 | - * |
|
388 | - * @access public |
|
389 | - * @return array of espresso config stuff |
|
390 | - */ |
|
391 | - public function get_espresso_config() |
|
392 | - { |
|
393 | - // grab espresso configuration |
|
394 | - return apply_filters( |
|
395 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
396 | - get_option(EE_Config::OPTION_NAME, array()) |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * double_check_config_comparison |
|
404 | - * |
|
405 | - * @access public |
|
406 | - * @param string $option |
|
407 | - * @param $old_value |
|
408 | - * @param $value |
|
409 | - */ |
|
410 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
411 | - { |
|
412 | - // make sure we're checking the ee config |
|
413 | - if ($option === EE_Config::OPTION_NAME) { |
|
414 | - // run a loose comparison of the old value against the new value for type and properties, |
|
415 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
416 | - if ($value != $old_value) { |
|
417 | - // if they are NOT the same, then remove the hook, |
|
418 | - // which means the subsequent update results will be based solely on the update query results |
|
419 | - // the reason we do this is because, as stated above, |
|
420 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
421 | - // this happens PRIOR to serialization and any subsequent update. |
|
422 | - // If values are found to match their previous old value, |
|
423 | - // then WP bails before performing any update. |
|
424 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
425 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
426 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
427 | - // MySQL MAY ALSO NOT perform the update because |
|
428 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
429 | - // This results in the query returning an "affected rows" value of ZERO, |
|
430 | - // which gets returned immediately by WP update_option and looks like an error. |
|
431 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * update_espresso_config |
|
440 | - * |
|
441 | - * @access public |
|
442 | - */ |
|
443 | - protected function _reset_espresso_addon_config() |
|
444 | - { |
|
445 | - $this->_addon_option_names = array(); |
|
446 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
447 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
448 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
449 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
450 | - } |
|
451 | - $this->addons->{$addon_name} = null; |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * update_espresso_config |
|
459 | - * |
|
460 | - * @access public |
|
461 | - * @param bool $add_success |
|
462 | - * @param bool $add_error |
|
463 | - * @return bool |
|
464 | - */ |
|
465 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
466 | - { |
|
467 | - // don't allow config updates during WP heartbeats |
|
468 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
469 | - return false; |
|
470 | - } |
|
471 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
472 | - //$clone = clone( self::$_instance ); |
|
473 | - //self::$_instance = NULL; |
|
474 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
475 | - $this->_reset_espresso_addon_config(); |
|
476 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
477 | - // but BEFORE the actual update occurs |
|
478 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
479 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
480 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
481 | - $this->legacy_shortcodes_manager = null; |
|
482 | - // now update "ee_config" |
|
483 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
484 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
485 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
486 | - // if not saved... check if the hook we just added still exists; |
|
487 | - // if it does, it means one of two things: |
|
488 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
489 | - // or... |
|
490 | - // the db update query returned 0 rows affected |
|
491 | - // (probably because the data value was the same from it's perspective) |
|
492 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
493 | - // but just means no update occurred, so don't display an error to the user. |
|
494 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
495 | - // then it means that something truly went wrong |
|
496 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
497 | - // remove our action since we don't want it in the system anymore |
|
498 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
499 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
500 | - //self::$_instance = $clone; |
|
501 | - //unset( $clone ); |
|
502 | - // if config remains the same or was updated successfully |
|
503 | - if ($saved) { |
|
504 | - if ($add_success) { |
|
505 | - EE_Error::add_success( |
|
506 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
507 | - __FILE__, |
|
508 | - __FUNCTION__, |
|
509 | - __LINE__ |
|
510 | - ); |
|
511 | - } |
|
512 | - return true; |
|
513 | - } else { |
|
514 | - if ($add_error) { |
|
515 | - EE_Error::add_error( |
|
516 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
517 | - __FILE__, |
|
518 | - __FUNCTION__, |
|
519 | - __LINE__ |
|
520 | - ); |
|
521 | - } |
|
522 | - return false; |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * _verify_config_params |
|
530 | - * |
|
531 | - * @access private |
|
532 | - * @param string $section |
|
533 | - * @param string $name |
|
534 | - * @param string $config_class |
|
535 | - * @param EE_Config_Base $config_obj |
|
536 | - * @param array $tests_to_run |
|
537 | - * @param bool $display_errors |
|
538 | - * @return bool TRUE on success, FALSE on fail |
|
539 | - */ |
|
540 | - private function _verify_config_params( |
|
541 | - $section = '', |
|
542 | - $name = '', |
|
543 | - $config_class = '', |
|
544 | - $config_obj = null, |
|
545 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
546 | - $display_errors = true |
|
547 | - ) { |
|
548 | - try { |
|
549 | - foreach ($tests_to_run as $test) { |
|
550 | - switch ($test) { |
|
551 | - // TEST #1 : check that section was set |
|
552 | - case 1 : |
|
553 | - if (empty($section)) { |
|
554 | - if ($display_errors) { |
|
555 | - throw new EE_Error( |
|
556 | - sprintf( |
|
557 | - __( |
|
558 | - 'No configuration section has been provided while attempting to save "%s".', |
|
559 | - 'event_espresso' |
|
560 | - ), |
|
561 | - $config_class |
|
562 | - ) |
|
563 | - ); |
|
564 | - } |
|
565 | - return false; |
|
566 | - } |
|
567 | - break; |
|
568 | - // TEST #2 : check that settings section exists |
|
569 | - case 2 : |
|
570 | - if (! isset($this->{$section})) { |
|
571 | - if ($display_errors) { |
|
572 | - throw new EE_Error( |
|
573 | - sprintf( |
|
574 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
575 | - $section |
|
576 | - ) |
|
577 | - ); |
|
578 | - } |
|
579 | - return false; |
|
580 | - } |
|
581 | - break; |
|
582 | - // TEST #3 : check that section is the proper format |
|
583 | - case 3 : |
|
584 | - if ( |
|
585 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
586 | - ) { |
|
587 | - if ($display_errors) { |
|
588 | - throw new EE_Error( |
|
589 | - sprintf( |
|
590 | - __( |
|
591 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
592 | - 'event_espresso' |
|
593 | - ), |
|
594 | - $section |
|
595 | - ) |
|
596 | - ); |
|
597 | - } |
|
598 | - return false; |
|
599 | - } |
|
600 | - break; |
|
601 | - // TEST #4 : check that config section name has been set |
|
602 | - case 4 : |
|
603 | - if (empty($name)) { |
|
604 | - if ($display_errors) { |
|
605 | - throw new EE_Error( |
|
606 | - __( |
|
607 | - 'No name has been provided for the specific configuration section.', |
|
608 | - 'event_espresso' |
|
609 | - ) |
|
610 | - ); |
|
611 | - } |
|
612 | - return false; |
|
613 | - } |
|
614 | - break; |
|
615 | - // TEST #5 : check that a config class name has been set |
|
616 | - case 5 : |
|
617 | - if (empty($config_class)) { |
|
618 | - if ($display_errors) { |
|
619 | - throw new EE_Error( |
|
620 | - __( |
|
621 | - 'No class name has been provided for the specific configuration section.', |
|
622 | - 'event_espresso' |
|
623 | - ) |
|
624 | - ); |
|
625 | - } |
|
626 | - return false; |
|
627 | - } |
|
628 | - break; |
|
629 | - // TEST #6 : verify config class is accessible |
|
630 | - case 6 : |
|
631 | - if (! class_exists($config_class)) { |
|
632 | - if ($display_errors) { |
|
633 | - throw new EE_Error( |
|
634 | - sprintf( |
|
635 | - __( |
|
636 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - $config_class |
|
640 | - ) |
|
641 | - ); |
|
642 | - } |
|
643 | - return false; |
|
644 | - } |
|
645 | - break; |
|
646 | - // TEST #7 : check that config has even been set |
|
647 | - case 7 : |
|
648 | - if (! isset($this->{$section}->{$name})) { |
|
649 | - if ($display_errors) { |
|
650 | - throw new EE_Error( |
|
651 | - sprintf( |
|
652 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
653 | - $section, |
|
654 | - $name |
|
655 | - ) |
|
656 | - ); |
|
657 | - } |
|
658 | - return false; |
|
659 | - } else { |
|
660 | - // and make sure it's not serialized |
|
661 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
662 | - } |
|
663 | - break; |
|
664 | - // TEST #8 : check that config is the requested type |
|
665 | - case 8 : |
|
666 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
667 | - if ($display_errors) { |
|
668 | - throw new EE_Error( |
|
669 | - sprintf( |
|
670 | - __( |
|
671 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
672 | - 'event_espresso' |
|
673 | - ), |
|
674 | - $section, |
|
675 | - $name, |
|
676 | - $config_class |
|
677 | - ) |
|
678 | - ); |
|
679 | - } |
|
680 | - return false; |
|
681 | - } |
|
682 | - break; |
|
683 | - // TEST #9 : verify config object |
|
684 | - case 9 : |
|
685 | - if (! $config_obj instanceof EE_Config_Base) { |
|
686 | - if ($display_errors) { |
|
687 | - throw new EE_Error( |
|
688 | - sprintf( |
|
689 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
690 | - print_r($config_obj, true) |
|
691 | - ) |
|
692 | - ); |
|
693 | - } |
|
694 | - return false; |
|
695 | - } |
|
696 | - break; |
|
697 | - } |
|
698 | - } |
|
699 | - } catch (EE_Error $e) { |
|
700 | - $e->get_error(); |
|
701 | - } |
|
702 | - // you have successfully run the gauntlet |
|
703 | - return true; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * _generate_config_option_name |
|
710 | - * |
|
711 | - * @access protected |
|
712 | - * @param string $section |
|
713 | - * @param string $name |
|
714 | - * @return string |
|
715 | - */ |
|
716 | - private function _generate_config_option_name($section = '', $name = '') |
|
717 | - { |
|
718 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * _set_config_class |
|
725 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
726 | - * |
|
727 | - * @access private |
|
728 | - * @param string $config_class |
|
729 | - * @param string $name |
|
730 | - * @return string |
|
731 | - */ |
|
732 | - private function _set_config_class($config_class = '', $name = '') |
|
733 | - { |
|
734 | - return ! empty($config_class) |
|
735 | - ? $config_class |
|
736 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * set_config |
|
743 | - * |
|
744 | - * @access protected |
|
745 | - * @param string $section |
|
746 | - * @param string $name |
|
747 | - * @param string $config_class |
|
748 | - * @param EE_Config_Base $config_obj |
|
749 | - * @return EE_Config_Base |
|
750 | - */ |
|
751 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
752 | - { |
|
753 | - // ensure config class is set to something |
|
754 | - $config_class = $this->_set_config_class($config_class, $name); |
|
755 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
756 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
757 | - return null; |
|
758 | - } |
|
759 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
760 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
761 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
762 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
763 | - $this->update_addon_option_names(); |
|
764 | - } |
|
765 | - // verify the incoming config object but suppress errors |
|
766 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
767 | - $config_obj = new $config_class(); |
|
768 | - } |
|
769 | - if (get_option($config_option_name)) { |
|
770 | - EE_Config::log($config_option_name); |
|
771 | - update_option($config_option_name, $config_obj); |
|
772 | - $this->{$section}->{$name} = $config_obj; |
|
773 | - return $this->{$section}->{$name}; |
|
774 | - } else { |
|
775 | - // create a wp-option for this config |
|
776 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
777 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
778 | - return $this->{$section}->{$name}; |
|
779 | - } else { |
|
780 | - EE_Error::add_error( |
|
781 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
782 | - __FILE__, |
|
783 | - __FUNCTION__, |
|
784 | - __LINE__ |
|
785 | - ); |
|
786 | - return null; |
|
787 | - } |
|
788 | - } |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * update_config |
|
795 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
796 | - * |
|
797 | - * @access public |
|
798 | - * @param string $section |
|
799 | - * @param string $name |
|
800 | - * @param EE_Config_Base|string $config_obj |
|
801 | - * @param bool $throw_errors |
|
802 | - * @return bool |
|
803 | - */ |
|
804 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
805 | - { |
|
806 | - // don't allow config updates during WP heartbeats |
|
807 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
808 | - return false; |
|
809 | - } |
|
810 | - $config_obj = maybe_unserialize($config_obj); |
|
811 | - // get class name of the incoming object |
|
812 | - $config_class = get_class($config_obj); |
|
813 | - // run tests 1-5 and 9 to verify config |
|
814 | - if (! $this->_verify_config_params( |
|
815 | - $section, |
|
816 | - $name, |
|
817 | - $config_class, |
|
818 | - $config_obj, |
|
819 | - array(1, 2, 3, 4, 7, 9) |
|
820 | - ) |
|
821 | - ) { |
|
822 | - return false; |
|
823 | - } |
|
824 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
825 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
826 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
827 | - // save new config to db |
|
828 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
829 | - return true; |
|
830 | - } |
|
831 | - } else { |
|
832 | - // first check if the record already exists |
|
833 | - $existing_config = get_option($config_option_name); |
|
834 | - $config_obj = serialize($config_obj); |
|
835 | - // just return if db record is already up to date (NOT type safe comparison) |
|
836 | - if ($existing_config == $config_obj) { |
|
837 | - $this->{$section}->{$name} = $config_obj; |
|
838 | - return true; |
|
839 | - } else if (update_option($config_option_name, $config_obj)) { |
|
840 | - EE_Config::log($config_option_name); |
|
841 | - // update wp-option for this config class |
|
842 | - $this->{$section}->{$name} = $config_obj; |
|
843 | - return true; |
|
844 | - } elseif ($throw_errors) { |
|
845 | - EE_Error::add_error( |
|
846 | - sprintf( |
|
847 | - __( |
|
848 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - $config_class, |
|
852 | - 'EE_Config->' . $section . '->' . $name |
|
853 | - ), |
|
854 | - __FILE__, |
|
855 | - __FUNCTION__, |
|
856 | - __LINE__ |
|
857 | - ); |
|
858 | - } |
|
859 | - } |
|
860 | - return false; |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * get_config |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @param string $section |
|
870 | - * @param string $name |
|
871 | - * @param string $config_class |
|
872 | - * @return mixed EE_Config_Base | NULL |
|
873 | - */ |
|
874 | - public function get_config($section = '', $name = '', $config_class = '') |
|
875 | - { |
|
876 | - // ensure config class is set to something |
|
877 | - $config_class = $this->_set_config_class($config_class, $name); |
|
878 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
879 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
880 | - return null; |
|
881 | - } |
|
882 | - // now test if the requested config object exists, but suppress errors |
|
883 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
884 | - // config already exists, so pass it back |
|
885 | - return $this->{$section}->{$name}; |
|
886 | - } |
|
887 | - // load config option from db if it exists |
|
888 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
889 | - // verify the newly retrieved config object, but suppress errors |
|
890 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
891 | - // config is good, so set it and pass it back |
|
892 | - $this->{$section}->{$name} = $config_obj; |
|
893 | - return $this->{$section}->{$name}; |
|
894 | - } |
|
895 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
896 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
897 | - // verify the newly created config object |
|
898 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
899 | - return $this->{$section}->{$name}; |
|
900 | - } else { |
|
901 | - EE_Error::add_error( |
|
902 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
903 | - __FILE__, |
|
904 | - __FUNCTION__, |
|
905 | - __LINE__ |
|
906 | - ); |
|
907 | - } |
|
908 | - return null; |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - |
|
913 | - /** |
|
914 | - * get_config_option |
|
915 | - * |
|
916 | - * @access public |
|
917 | - * @param string $config_option_name |
|
918 | - * @return mixed EE_Config_Base | FALSE |
|
919 | - */ |
|
920 | - public function get_config_option($config_option_name = '') |
|
921 | - { |
|
922 | - // retrieve the wp-option for this config class. |
|
923 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
924 | - if (empty($config_option)) { |
|
925 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
926 | - } |
|
927 | - return $config_option; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - |
|
932 | - /** |
|
933 | - * log |
|
934 | - * |
|
935 | - * @param string $config_option_name |
|
936 | - */ |
|
937 | - public static function log($config_option_name = '') |
|
938 | - { |
|
939 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
940 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
941 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
942 | - $_request = $_REQUEST; |
|
943 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
944 | - $config_log[(string)microtime(true)] = array( |
|
945 | - 'config_name' => $config_option_name, |
|
946 | - 'request' => $_request, |
|
947 | - ); |
|
948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
949 | - } |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * trim_log |
|
956 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
957 | - */ |
|
958 | - public static function trim_log() |
|
959 | - { |
|
960 | - if (! EE_Config::logging_enabled()) { |
|
961 | - return; |
|
962 | - } |
|
963 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
964 | - $log_length = count($config_log); |
|
965 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
966 | - ksort($config_log); |
|
967 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
968 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
969 | - } |
|
970 | - } |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * get_page_for_posts |
|
976 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
977 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
978 | - * |
|
979 | - * @access public |
|
980 | - * @return string |
|
981 | - */ |
|
982 | - public static function get_page_for_posts() |
|
983 | - { |
|
984 | - $page_for_posts = get_option('page_for_posts'); |
|
985 | - if (! $page_for_posts) { |
|
986 | - return 'posts'; |
|
987 | - } |
|
988 | - /** @type WPDB $wpdb */ |
|
989 | - global $wpdb; |
|
990 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
991 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * register_shortcodes_and_modules. |
|
998 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
999 | - * In fact, this is where we give modules a chance to let core know they exist |
|
1000 | - * so they can help trigger maintenance mode if it's needed |
|
1001 | - * |
|
1002 | - * @access public |
|
1003 | - * @return void |
|
1004 | - */ |
|
1005 | - public function register_shortcodes_and_modules() |
|
1006 | - { |
|
1007 | - // allow modules to set hooks for the rest of the system |
|
1008 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * initialize_shortcodes_and_modules |
|
1015 | - * meaning they can start adding their hooks to get stuff done |
|
1016 | - * |
|
1017 | - * @access public |
|
1018 | - * @return void |
|
1019 | - */ |
|
1020 | - public function initialize_shortcodes_and_modules() |
|
1021 | - { |
|
1022 | - // allow modules to set hooks for the rest of the system |
|
1023 | - $this->_initialize_modules(); |
|
1024 | - } |
|
1025 | - |
|
1026 | - |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * widgets_init |
|
1030 | - * |
|
1031 | - * @access private |
|
1032 | - * @return void |
|
1033 | - */ |
|
1034 | - public function widgets_init() |
|
1035 | - { |
|
1036 | - //only init widgets on admin pages when not in complete maintenance, and |
|
1037 | - //on frontend when not in any maintenance mode |
|
1038 | - if ( |
|
1039 | - ! EE_Maintenance_Mode::instance()->level() |
|
1040 | - || ( |
|
1041 | - is_admin() |
|
1042 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1043 | - ) |
|
1044 | - ) { |
|
1045 | - // grab list of installed widgets |
|
1046 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1047 | - // filter list of modules to register |
|
1048 | - $widgets_to_register = apply_filters( |
|
1049 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1050 | - $widgets_to_register |
|
1051 | - ); |
|
1052 | - if (! empty($widgets_to_register)) { |
|
1053 | - // cycle thru widget folders |
|
1054 | - foreach ($widgets_to_register as $widget_path) { |
|
1055 | - // add to list of installed widget modules |
|
1056 | - EE_Config::register_ee_widget($widget_path); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - // filter list of installed modules |
|
1060 | - EE_Registry::instance()->widgets = apply_filters( |
|
1061 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1062 | - EE_Registry::instance()->widgets |
|
1063 | - ); |
|
1064 | - } |
|
1065 | - } |
|
1066 | - |
|
1067 | - |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * register_ee_widget - makes core aware of this widget |
|
1071 | - * |
|
1072 | - * @access public |
|
1073 | - * @param string $widget_path - full path up to and including widget folder |
|
1074 | - * @return void |
|
1075 | - */ |
|
1076 | - public static function register_ee_widget($widget_path = null) |
|
1077 | - { |
|
1078 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1079 | - $widget_ext = '.widget.php'; |
|
1080 | - // make all separators match |
|
1081 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1082 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1083 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
1084 | - // grab and shortcode file name from directory name and break apart at dots |
|
1085 | - $file_name = explode('.', basename($widget_path)); |
|
1086 | - // take first segment from file name pieces and remove class prefix if it exists |
|
1087 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1088 | - // sanitize shortcode directory name |
|
1089 | - $widget = sanitize_key($widget); |
|
1090 | - // now we need to rebuild the shortcode path |
|
1091 | - $widget_path = explode(DS, $widget_path); |
|
1092 | - // remove last segment |
|
1093 | - array_pop($widget_path); |
|
1094 | - // glue it back together |
|
1095 | - $widget_path = implode(DS, $widget_path); |
|
1096 | - } else { |
|
1097 | - // grab and sanitize widget directory name |
|
1098 | - $widget = sanitize_key(basename($widget_path)); |
|
1099 | - } |
|
1100 | - // create classname from widget directory name |
|
1101 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1102 | - // add class prefix |
|
1103 | - $widget_class = 'EEW_' . $widget; |
|
1104 | - // does the widget exist ? |
|
1105 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1106 | - $msg = sprintf( |
|
1107 | - __( |
|
1108 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1109 | - 'event_espresso' |
|
1110 | - ), |
|
1111 | - $widget_class, |
|
1112 | - $widget_path . DS . $widget_class . $widget_ext |
|
1113 | - ); |
|
1114 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1115 | - return; |
|
1116 | - } |
|
1117 | - // load the widget class file |
|
1118 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1119 | - // verify that class exists |
|
1120 | - if (! class_exists($widget_class)) { |
|
1121 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1122 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1123 | - return; |
|
1124 | - } |
|
1125 | - register_widget($widget_class); |
|
1126 | - // add to array of registered widgets |
|
1127 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * _register_modules |
|
1134 | - * |
|
1135 | - * @access private |
|
1136 | - * @return array |
|
1137 | - */ |
|
1138 | - private function _register_modules() |
|
1139 | - { |
|
1140 | - // grab list of installed modules |
|
1141 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1142 | - // filter list of modules to register |
|
1143 | - $modules_to_register = apply_filters( |
|
1144 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1145 | - $modules_to_register |
|
1146 | - ); |
|
1147 | - if (! empty($modules_to_register)) { |
|
1148 | - // loop through folders |
|
1149 | - foreach ($modules_to_register as $module_path) { |
|
1150 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1151 | - if ( |
|
1152 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1153 | - && $module_path !== EE_MODULES . 'gateways' |
|
1154 | - ) { |
|
1155 | - // add to list of installed modules |
|
1156 | - EE_Config::register_module($module_path); |
|
1157 | - } |
|
1158 | - } |
|
1159 | - } |
|
1160 | - // filter list of installed modules |
|
1161 | - return apply_filters( |
|
1162 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
1163 | - EE_Registry::instance()->modules |
|
1164 | - ); |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * register_module - makes core aware of this module |
|
1171 | - * |
|
1172 | - * @access public |
|
1173 | - * @param string $module_path - full path up to and including module folder |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1176 | - public static function register_module($module_path = null) |
|
1177 | - { |
|
1178 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1179 | - $module_ext = '.module.php'; |
|
1180 | - // make all separators match |
|
1181 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1182 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1183 | - if (strpos($module_path, $module_ext) !== false) { |
|
1184 | - // grab and shortcode file name from directory name and break apart at dots |
|
1185 | - $module_file = explode('.', basename($module_path)); |
|
1186 | - // now we need to rebuild the shortcode path |
|
1187 | - $module_path = explode(DS, $module_path); |
|
1188 | - // remove last segment |
|
1189 | - array_pop($module_path); |
|
1190 | - // glue it back together |
|
1191 | - $module_path = implode(DS, $module_path) . DS; |
|
1192 | - // take first segment from file name pieces and sanitize it |
|
1193 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1194 | - // ensure class prefix is added |
|
1195 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1196 | - } else { |
|
1197 | - // we need to generate the filename based off of the folder name |
|
1198 | - // grab and sanitize module name |
|
1199 | - $module = strtolower(basename($module_path)); |
|
1200 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1201 | - // like trailingslashit() |
|
1202 | - $module_path = rtrim($module_path, DS) . DS; |
|
1203 | - // create classname from module directory name |
|
1204 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1205 | - // add class prefix |
|
1206 | - $module_class = 'EED_' . $module; |
|
1207 | - } |
|
1208 | - // does the module exist ? |
|
1209 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1210 | - $msg = sprintf( |
|
1211 | - __( |
|
1212 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1213 | - 'event_espresso' |
|
1214 | - ), |
|
1215 | - $module |
|
1216 | - ); |
|
1217 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1218 | - return false; |
|
1219 | - } |
|
1220 | - // load the module class file |
|
1221 | - require_once($module_path . $module_class . $module_ext); |
|
1222 | - // verify that class exists |
|
1223 | - if (! class_exists($module_class)) { |
|
1224 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1225 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1226 | - return false; |
|
1227 | - } |
|
1228 | - // add to array of registered modules |
|
1229 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1230 | - do_action( |
|
1231 | - 'AHEE__EE_Config__register_module__complete', |
|
1232 | - $module_class, |
|
1233 | - EE_Registry::instance()->modules->{$module_class} |
|
1234 | - ); |
|
1235 | - return true; |
|
1236 | - } |
|
1237 | - |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * _initialize_modules |
|
1242 | - * allow modules to set hooks for the rest of the system |
|
1243 | - * |
|
1244 | - * @access private |
|
1245 | - * @return void |
|
1246 | - */ |
|
1247 | - private function _initialize_modules() |
|
1248 | - { |
|
1249 | - // cycle thru shortcode folders |
|
1250 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1251 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1252 | - // which set hooks ? |
|
1253 | - if (is_admin()) { |
|
1254 | - // fire immediately |
|
1255 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
1256 | - } else { |
|
1257 | - // delay until other systems are online |
|
1258 | - add_action( |
|
1259 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1260 | - array($module_class, 'set_hooks') |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - } |
|
1265 | - |
|
1266 | - |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * register_route - adds module method routes to route_map |
|
1270 | - * |
|
1271 | - * @access public |
|
1272 | - * @param string $route - "pretty" public alias for module method |
|
1273 | - * @param string $module - module name (classname without EED_ prefix) |
|
1274 | - * @param string $method_name - the actual module method to be routed to |
|
1275 | - * @param string $key - url param key indicating a route is being called |
|
1276 | - * @return bool |
|
1277 | - */ |
|
1278 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1279 | - { |
|
1280 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1281 | - $module = str_replace('EED_', '', $module); |
|
1282 | - $module_class = 'EED_' . $module; |
|
1283 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1284 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1285 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1286 | - return false; |
|
1287 | - } |
|
1288 | - if (empty($route)) { |
|
1289 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1291 | - return false; |
|
1292 | - } |
|
1293 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
1294 | - $msg = sprintf( |
|
1295 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1296 | - $route |
|
1297 | - ); |
|
1298 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1299 | - return false; |
|
1300 | - } |
|
1301 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1302 | - return true; |
|
1303 | - } |
|
1304 | - |
|
1305 | - |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * get_route - get module method route |
|
1309 | - * |
|
1310 | - * @access public |
|
1311 | - * @param string $route - "pretty" public alias for module method |
|
1312 | - * @param string $key - url param key indicating a route is being called |
|
1313 | - * @return string |
|
1314 | - */ |
|
1315 | - public static function get_route($route = null, $key = 'ee') |
|
1316 | - { |
|
1317 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1318 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1319 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1320 | - return EE_Config::$_module_route_map[$key][$route]; |
|
1321 | - } |
|
1322 | - return null; |
|
1323 | - } |
|
1324 | - |
|
1325 | - |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * get_routes - get ALL module method routes |
|
1329 | - * |
|
1330 | - * @access public |
|
1331 | - * @return array |
|
1332 | - */ |
|
1333 | - public static function get_routes() |
|
1334 | - { |
|
1335 | - return EE_Config::$_module_route_map; |
|
1336 | - } |
|
1337 | - |
|
1338 | - |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * register_forward - allows modules to forward request to another module for further processing |
|
1342 | - * |
|
1343 | - * @access public |
|
1344 | - * @param string $route - "pretty" public alias for module method |
|
1345 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1346 | - * class, allows different forwards to be served based on status |
|
1347 | - * @param array|string $forward - function name or array( class, method ) |
|
1348 | - * @param string $key - url param key indicating a route is being called |
|
1349 | - * @return bool |
|
1350 | - */ |
|
1351 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1352 | - { |
|
1353 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1354 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1355 | - $msg = sprintf( |
|
1356 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1357 | - $route |
|
1358 | - ); |
|
1359 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1360 | - return false; |
|
1361 | - } |
|
1362 | - if (empty($forward)) { |
|
1363 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1365 | - return false; |
|
1366 | - } |
|
1367 | - if (is_array($forward)) { |
|
1368 | - if (! isset($forward[1])) { |
|
1369 | - $msg = sprintf( |
|
1370 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1371 | - $route |
|
1372 | - ); |
|
1373 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1374 | - return false; |
|
1375 | - } |
|
1376 | - if (! method_exists($forward[0], $forward[1])) { |
|
1377 | - $msg = sprintf( |
|
1378 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1379 | - $forward[1], |
|
1380 | - $route |
|
1381 | - ); |
|
1382 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1383 | - return false; |
|
1384 | - } |
|
1385 | - } else if (! function_exists($forward)) { |
|
1386 | - $msg = sprintf( |
|
1387 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1388 | - $forward, |
|
1389 | - $route |
|
1390 | - ); |
|
1391 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1392 | - return false; |
|
1393 | - } |
|
1394 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1395 | - return true; |
|
1396 | - } |
|
1397 | - |
|
1398 | - |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * get_forward - get forwarding route |
|
1402 | - * |
|
1403 | - * @access public |
|
1404 | - * @param string $route - "pretty" public alias for module method |
|
1405 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1406 | - * allows different forwards to be served based on status |
|
1407 | - * @param string $key - url param key indicating a route is being called |
|
1408 | - * @return string |
|
1409 | - */ |
|
1410 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1411 | - { |
|
1412 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1413 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1414 | - return apply_filters( |
|
1415 | - 'FHEE__EE_Config__get_forward', |
|
1416 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
1417 | - $route, |
|
1418 | - $status |
|
1419 | - ); |
|
1420 | - } |
|
1421 | - return null; |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
1428 | - * results |
|
1429 | - * |
|
1430 | - * @access public |
|
1431 | - * @param string $route - "pretty" public alias for module method |
|
1432 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1433 | - * allows different views to be served based on status |
|
1434 | - * @param string $view |
|
1435 | - * @param string $key - url param key indicating a route is being called |
|
1436 | - * @return bool |
|
1437 | - */ |
|
1438 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1439 | - { |
|
1440 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1441 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1442 | - $msg = sprintf( |
|
1443 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1444 | - $route |
|
1445 | - ); |
|
1446 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1447 | - return false; |
|
1448 | - } |
|
1449 | - if (! is_readable($view)) { |
|
1450 | - $msg = sprintf( |
|
1451 | - __( |
|
1452 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
1453 | - 'event_espresso' |
|
1454 | - ), |
|
1455 | - $view |
|
1456 | - ); |
|
1457 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1458 | - return false; |
|
1459 | - } |
|
1460 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1461 | - return true; |
|
1462 | - } |
|
1463 | - |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * get_view - get view for route and status |
|
1468 | - * |
|
1469 | - * @access public |
|
1470 | - * @param string $route - "pretty" public alias for module method |
|
1471 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1472 | - * allows different views to be served based on status |
|
1473 | - * @param string $key - url param key indicating a route is being called |
|
1474 | - * @return string |
|
1475 | - */ |
|
1476 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1477 | - { |
|
1478 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1479 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1480 | - return apply_filters( |
|
1481 | - 'FHEE__EE_Config__get_view', |
|
1482 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
1483 | - $route, |
|
1484 | - $status |
|
1485 | - ); |
|
1486 | - } |
|
1487 | - return null; |
|
1488 | - } |
|
1489 | - |
|
1490 | - |
|
1491 | - |
|
1492 | - public function update_addon_option_names() |
|
1493 | - { |
|
1494 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1495 | - } |
|
1496 | - |
|
1497 | - |
|
1498 | - |
|
1499 | - public function shutdown() |
|
1500 | - { |
|
1501 | - $this->update_addon_option_names(); |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * @return LegacyShortcodesManager |
|
1508 | - */ |
|
1509 | - public static function getLegacyShortcodesManager() |
|
1510 | - { |
|
1511 | - |
|
1512 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1513 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1514 | - EE_Registry::instance() |
|
1515 | - ); |
|
1516 | - } |
|
1517 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
1518 | - } |
|
1519 | - |
|
1520 | - |
|
1521 | - |
|
1522 | - /** |
|
1523 | - * register_shortcode - makes core aware of this shortcode |
|
1524 | - * |
|
1525 | - * @deprecated 4.9.26 |
|
1526 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
1527 | - * @return bool |
|
1528 | - */ |
|
1529 | - public static function register_shortcode($shortcode_path = null) |
|
1530 | - { |
|
1531 | - EE_Error::doing_it_wrong( |
|
1532 | - __METHOD__, |
|
1533 | - __( |
|
1534 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1535 | - 'event_espresso' |
|
1536 | - ), |
|
1537 | - '4.9.26' |
|
1538 | - ); |
|
1539 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1540 | - } |
|
1541 | - |
|
1542 | - |
|
1543 | - |
|
1544 | -} |
|
1545 | - |
|
1546 | - |
|
1547 | - |
|
1548 | -/** |
|
1549 | - * Base class used for config classes. These classes should generally not have |
|
1550 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1551 | - * basically, they should just be well-defined stdClasses |
|
1552 | - */ |
|
1553 | -class EE_Config_Base |
|
1554 | -{ |
|
1555 | - |
|
1556 | - /** |
|
1557 | - * Utility function for escaping the value of a property and returning. |
|
1558 | - * |
|
1559 | - * @param string $property property name (checks to see if exists). |
|
1560 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1561 | - * @throws \EE_Error |
|
1562 | - */ |
|
1563 | - public function get_pretty($property) |
|
1564 | - { |
|
1565 | - if (! property_exists($this, $property)) { |
|
1566 | - throw new EE_Error( |
|
1567 | - sprintf( |
|
1568 | - __( |
|
1569 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1570 | - 'event_espresso' |
|
1571 | - ), |
|
1572 | - get_class($this), |
|
1573 | - $property |
|
1574 | - ) |
|
1575 | - ); |
|
1576 | - } |
|
1577 | - //just handling escaping of strings for now. |
|
1578 | - if (is_string($this->{$property})) { |
|
1579 | - return stripslashes($this->{$property}); |
|
1580 | - } |
|
1581 | - return $this->{$property}; |
|
1582 | - } |
|
1583 | - |
|
1584 | - |
|
1585 | - |
|
1586 | - public function populate() |
|
1587 | - { |
|
1588 | - //grab defaults via a new instance of this class. |
|
1589 | - $class_name = get_class($this); |
|
1590 | - $defaults = new $class_name; |
|
1591 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1592 | - //default from our $defaults object. |
|
1593 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
1594 | - if ($this->{$property} === null) { |
|
1595 | - $this->{$property} = $value; |
|
1596 | - } |
|
1597 | - } |
|
1598 | - //cleanup |
|
1599 | - unset($defaults); |
|
1600 | - } |
|
1601 | - |
|
1602 | - |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * __isset |
|
1606 | - * |
|
1607 | - * @param $a |
|
1608 | - * @return bool |
|
1609 | - */ |
|
1610 | - public function __isset($a) |
|
1611 | - { |
|
1612 | - return false; |
|
1613 | - } |
|
1614 | - |
|
1615 | - |
|
1616 | - |
|
1617 | - /** |
|
1618 | - * __unset |
|
1619 | - * |
|
1620 | - * @param $a |
|
1621 | - * @return bool |
|
1622 | - */ |
|
1623 | - public function __unset($a) |
|
1624 | - { |
|
1625 | - return false; |
|
1626 | - } |
|
1627 | - |
|
1628 | - |
|
1629 | - |
|
1630 | - /** |
|
1631 | - * __clone |
|
1632 | - */ |
|
1633 | - public function __clone() |
|
1634 | - { |
|
1635 | - } |
|
1636 | - |
|
1637 | - |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * __wakeup |
|
1641 | - */ |
|
1642 | - public function __wakeup() |
|
1643 | - { |
|
1644 | - } |
|
1645 | - |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * __destruct |
|
1650 | - */ |
|
1651 | - public function __destruct() |
|
1652 | - { |
|
1653 | - } |
|
1654 | -} |
|
1655 | - |
|
1656 | - |
|
1657 | - |
|
1658 | -/** |
|
1659 | - * Class for defining what's in the EE_Config relating to registration settings |
|
1660 | - */ |
|
1661 | -class EE_Core_Config extends EE_Config_Base |
|
1662 | -{ |
|
1663 | - |
|
1664 | - public $current_blog_id; |
|
1665 | - |
|
1666 | - public $ee_ueip_optin; |
|
1667 | - |
|
1668 | - public $ee_ueip_has_notified; |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * Not to be confused with the 4 critical page variables (See |
|
1672 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1673 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1674 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1675 | - * |
|
1676 | - * @var array |
|
1677 | - */ |
|
1678 | - public $post_shortcodes; |
|
1679 | - |
|
1680 | - public $module_route_map; |
|
1681 | - |
|
1682 | - public $module_forward_map; |
|
1683 | - |
|
1684 | - public $module_view_map; |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * The next 4 vars are the IDs of critical EE pages. |
|
1688 | - * |
|
1689 | - * @var int |
|
1690 | - */ |
|
1691 | - public $reg_page_id; |
|
1692 | - |
|
1693 | - public $txn_page_id; |
|
1694 | - |
|
1695 | - public $thank_you_page_id; |
|
1696 | - |
|
1697 | - public $cancel_page_id; |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * The next 4 vars are the URLs of critical EE pages. |
|
1701 | - * |
|
1702 | - * @var int |
|
1703 | - */ |
|
1704 | - public $reg_page_url; |
|
1705 | - |
|
1706 | - public $txn_page_url; |
|
1707 | - |
|
1708 | - public $thank_you_page_url; |
|
1709 | - |
|
1710 | - public $cancel_page_url; |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * The next vars relate to the custom slugs for EE CPT routes |
|
1714 | - */ |
|
1715 | - public $event_cpt_slug; |
|
1716 | - |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
1720 | - * request across blog switches in a multisite context. |
|
1721 | - * Avoids extra queries to the db for this option. |
|
1722 | - * |
|
1723 | - * @var bool |
|
1724 | - */ |
|
1725 | - public static $ee_ueip_option; |
|
1726 | - |
|
1727 | - |
|
1728 | - |
|
1729 | - /** |
|
1730 | - * class constructor |
|
1731 | - * |
|
1732 | - * @access public |
|
1733 | - */ |
|
1734 | - public function __construct() |
|
1735 | - { |
|
1736 | - // set default organization settings |
|
1737 | - $this->current_blog_id = get_current_blog_id(); |
|
1738 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1739 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1740 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1741 | - $this->post_shortcodes = array(); |
|
1742 | - $this->module_route_map = array(); |
|
1743 | - $this->module_forward_map = array(); |
|
1744 | - $this->module_view_map = array(); |
|
1745 | - // critical EE page IDs |
|
1746 | - $this->reg_page_id = 0; |
|
1747 | - $this->txn_page_id = 0; |
|
1748 | - $this->thank_you_page_id = 0; |
|
1749 | - $this->cancel_page_id = 0; |
|
1750 | - // critical EE page URLs |
|
1751 | - $this->reg_page_url = ''; |
|
1752 | - $this->txn_page_url = ''; |
|
1753 | - $this->thank_you_page_url = ''; |
|
1754 | - $this->cancel_page_url = ''; |
|
1755 | - //cpt slugs |
|
1756 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1757 | - //ueip constant check |
|
1758 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1759 | - $this->ee_ueip_optin = false; |
|
1760 | - $this->ee_ueip_has_notified = true; |
|
1761 | - } |
|
1762 | - } |
|
1763 | - |
|
1764 | - |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * @return array |
|
1768 | - */ |
|
1769 | - public function get_critical_pages_array() |
|
1770 | - { |
|
1771 | - return array( |
|
1772 | - $this->reg_page_id, |
|
1773 | - $this->txn_page_id, |
|
1774 | - $this->thank_you_page_id, |
|
1775 | - $this->cancel_page_id, |
|
1776 | - ); |
|
1777 | - } |
|
1778 | - |
|
1779 | - |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * @return array |
|
1783 | - */ |
|
1784 | - public function get_critical_pages_shortcodes_array() |
|
1785 | - { |
|
1786 | - return array( |
|
1787 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1788 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1789 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1790 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1791 | - ); |
|
1792 | - } |
|
1793 | - |
|
1794 | - |
|
1795 | - |
|
1796 | - /** |
|
1797 | - * gets/returns URL for EE reg_page |
|
1798 | - * |
|
1799 | - * @access public |
|
1800 | - * @return string |
|
1801 | - */ |
|
1802 | - public function reg_page_url() |
|
1803 | - { |
|
1804 | - if (! $this->reg_page_url) { |
|
1805 | - $this->reg_page_url = add_query_arg( |
|
1806 | - array('uts' => time()), |
|
1807 | - get_permalink($this->reg_page_id) |
|
1808 | - ) . '#checkout'; |
|
1809 | - } |
|
1810 | - return $this->reg_page_url; |
|
1811 | - } |
|
1812 | - |
|
1813 | - |
|
1814 | - |
|
1815 | - /** |
|
1816 | - * gets/returns URL for EE txn_page |
|
1817 | - * |
|
1818 | - * @param array $query_args like what gets passed to |
|
1819 | - * add_query_arg() as the first argument |
|
1820 | - * @access public |
|
1821 | - * @return string |
|
1822 | - */ |
|
1823 | - public function txn_page_url($query_args = array()) |
|
1824 | - { |
|
1825 | - if (! $this->txn_page_url) { |
|
1826 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1827 | - } |
|
1828 | - if ($query_args) { |
|
1829 | - return add_query_arg($query_args, $this->txn_page_url); |
|
1830 | - } else { |
|
1831 | - return $this->txn_page_url; |
|
1832 | - } |
|
1833 | - } |
|
1834 | - |
|
1835 | - |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * gets/returns URL for EE thank_you_page |
|
1839 | - * |
|
1840 | - * @param array $query_args like what gets passed to |
|
1841 | - * add_query_arg() as the first argument |
|
1842 | - * @access public |
|
1843 | - * @return string |
|
1844 | - */ |
|
1845 | - public function thank_you_page_url($query_args = array()) |
|
1846 | - { |
|
1847 | - if (! $this->thank_you_page_url) { |
|
1848 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1849 | - } |
|
1850 | - if ($query_args) { |
|
1851 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
1852 | - } else { |
|
1853 | - return $this->thank_you_page_url; |
|
1854 | - } |
|
1855 | - } |
|
1856 | - |
|
1857 | - |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * gets/returns URL for EE cancel_page |
|
1861 | - * |
|
1862 | - * @access public |
|
1863 | - * @return string |
|
1864 | - */ |
|
1865 | - public function cancel_page_url() |
|
1866 | - { |
|
1867 | - if (! $this->cancel_page_url) { |
|
1868 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1869 | - } |
|
1870 | - return $this->cancel_page_url; |
|
1871 | - } |
|
1872 | - |
|
1873 | - |
|
1874 | - |
|
1875 | - /** |
|
1876 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1877 | - * |
|
1878 | - * @since 4.7.5 |
|
1879 | - */ |
|
1880 | - protected function _reset_urls() |
|
1881 | - { |
|
1882 | - $this->reg_page_url = ''; |
|
1883 | - $this->txn_page_url = ''; |
|
1884 | - $this->cancel_page_url = ''; |
|
1885 | - $this->thank_you_page_url = ''; |
|
1886 | - } |
|
1887 | - |
|
1888 | - |
|
1889 | - |
|
1890 | - /** |
|
1891 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
1892 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1893 | - * on the main site only. |
|
1894 | - * |
|
1895 | - * @return mixed|void |
|
1896 | - */ |
|
1897 | - protected function _get_main_ee_ueip_optin() |
|
1898 | - { |
|
1899 | - //if this is the main site then we can just bypass our direct query. |
|
1900 | - if (is_main_site()) { |
|
1901 | - return get_option('ee_ueip_optin', false); |
|
1902 | - } |
|
1903 | - //is this already cached for this request? If so use it. |
|
1904 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1905 | - return EE_Core_Config::$ee_ueip_option; |
|
1906 | - } |
|
1907 | - global $wpdb; |
|
1908 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1909 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1910 | - $option = 'ee_ueip_optin'; |
|
1911 | - //set correct table for query |
|
1912 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1913 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1914 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1915 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1916 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1917 | - //for the purpose of caching. |
|
1918 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1919 | - if (false !== $pre) { |
|
1920 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
1921 | - return EE_Core_Config::$ee_ueip_option; |
|
1922 | - } |
|
1923 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1924 | - $option)); |
|
1925 | - if (is_object($row)) { |
|
1926 | - $value = $row->option_value; |
|
1927 | - } else { //option does not exist so use default. |
|
1928 | - return apply_filters('default_option_' . $option, false, $option); |
|
1929 | - } |
|
1930 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1931 | - return EE_Core_Config::$ee_ueip_option; |
|
1932 | - } |
|
1933 | - |
|
1934 | - |
|
1935 | - |
|
1936 | - /** |
|
1937 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1938 | - * on the object. |
|
1939 | - * |
|
1940 | - * @return array |
|
1941 | - */ |
|
1942 | - public function __sleep() |
|
1943 | - { |
|
1944 | - //reset all url properties |
|
1945 | - $this->_reset_urls(); |
|
1946 | - //return what to save to db |
|
1947 | - return array_keys(get_object_vars($this)); |
|
1948 | - } |
|
1949 | - |
|
1950 | -} |
|
1951 | - |
|
1952 | - |
|
1953 | - |
|
1954 | -/** |
|
1955 | - * Config class for storing info on the Organization |
|
1956 | - */ |
|
1957 | -class EE_Organization_Config extends EE_Config_Base |
|
1958 | -{ |
|
1959 | - |
|
1960 | - /** |
|
1961 | - * @var string $name |
|
1962 | - * eg EE4.1 |
|
1963 | - */ |
|
1964 | - public $name; |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * @var string $address_1 |
|
1968 | - * eg 123 Onna Road |
|
1969 | - */ |
|
1970 | - public $address_1; |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * @var string $address_2 |
|
1974 | - * eg PO Box 123 |
|
1975 | - */ |
|
1976 | - public $address_2; |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @var string $city |
|
1980 | - * eg Inna City |
|
1981 | - */ |
|
1982 | - public $city; |
|
1983 | - |
|
1984 | - /** |
|
1985 | - * @var int $STA_ID |
|
1986 | - * eg 4 |
|
1987 | - */ |
|
1988 | - public $STA_ID; |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * @var string $CNT_ISO |
|
1992 | - * eg US |
|
1993 | - */ |
|
1994 | - public $CNT_ISO; |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * @var string $zip |
|
1998 | - * eg 12345 or V1A 2B3 |
|
1999 | - */ |
|
2000 | - public $zip; |
|
2001 | - |
|
2002 | - /** |
|
2003 | - * @var string $email |
|
2004 | - * eg [email protected] |
|
2005 | - */ |
|
2006 | - public $email; |
|
2007 | - |
|
2008 | - |
|
2009 | - /** |
|
2010 | - * @var string $phone |
|
2011 | - * eg. 111-111-1111 |
|
2012 | - */ |
|
2013 | - public $phone; |
|
2014 | - |
|
2015 | - |
|
2016 | - /** |
|
2017 | - * @var string $vat |
|
2018 | - * VAT/Tax Number |
|
2019 | - */ |
|
2020 | - public $vat; |
|
2021 | - |
|
2022 | - /** |
|
2023 | - * @var string $logo_url |
|
2024 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2025 | - */ |
|
2026 | - public $logo_url; |
|
2027 | - |
|
2028 | - |
|
2029 | - /** |
|
2030 | - * The below are all various properties for holding links to organization social network profiles |
|
2031 | - * |
|
2032 | - * @var string |
|
2033 | - */ |
|
2034 | - /** |
|
2035 | - * facebook (facebook.com/profile.name) |
|
2036 | - * |
|
2037 | - * @var string |
|
2038 | - */ |
|
2039 | - public $facebook; |
|
2040 | - |
|
2041 | - |
|
2042 | - /** |
|
2043 | - * twitter (twitter.com/twitter_handle) |
|
2044 | - * |
|
2045 | - * @var string |
|
2046 | - */ |
|
2047 | - public $twitter; |
|
2048 | - |
|
2049 | - |
|
2050 | - /** |
|
2051 | - * linkedin (linkedin.com/in/profile_name) |
|
2052 | - * |
|
2053 | - * @var string |
|
2054 | - */ |
|
2055 | - public $linkedin; |
|
2056 | - |
|
2057 | - |
|
2058 | - /** |
|
2059 | - * pinterest (www.pinterest.com/profile_name) |
|
2060 | - * |
|
2061 | - * @var string |
|
2062 | - */ |
|
2063 | - public $pinterest; |
|
2064 | - |
|
2065 | - |
|
2066 | - /** |
|
2067 | - * google+ (google.com/+profileName) |
|
2068 | - * |
|
2069 | - * @var string |
|
2070 | - */ |
|
2071 | - public $google; |
|
2072 | - |
|
2073 | - |
|
2074 | - /** |
|
2075 | - * instagram (instagram.com/handle) |
|
2076 | - * |
|
2077 | - * @var string |
|
2078 | - */ |
|
2079 | - public $instagram; |
|
2080 | - |
|
2081 | - |
|
2082 | - |
|
2083 | - /** |
|
2084 | - * class constructor |
|
2085 | - * |
|
2086 | - * @access public |
|
2087 | - */ |
|
2088 | - public function __construct() |
|
2089 | - { |
|
2090 | - // set default organization settings |
|
2091 | - //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
2092 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
2093 | - $this->address_1 = '123 Onna Road'; |
|
2094 | - $this->address_2 = 'PO Box 123'; |
|
2095 | - $this->city = 'Inna City'; |
|
2096 | - $this->STA_ID = 4; |
|
2097 | - $this->CNT_ISO = 'US'; |
|
2098 | - $this->zip = '12345'; |
|
2099 | - $this->email = get_bloginfo('admin_email'); |
|
2100 | - $this->phone = ''; |
|
2101 | - $this->vat = '123456789'; |
|
2102 | - $this->logo_url = ''; |
|
2103 | - $this->facebook = ''; |
|
2104 | - $this->twitter = ''; |
|
2105 | - $this->linkedin = ''; |
|
2106 | - $this->pinterest = ''; |
|
2107 | - $this->google = ''; |
|
2108 | - $this->instagram = ''; |
|
2109 | - } |
|
2110 | - |
|
2111 | -} |
|
2112 | - |
|
2113 | - |
|
2114 | - |
|
2115 | -/** |
|
2116 | - * Class for defining what's in the EE_Config relating to currency |
|
2117 | - */ |
|
2118 | -class EE_Currency_Config extends EE_Config_Base |
|
2119 | -{ |
|
2120 | - |
|
2121 | - /** |
|
2122 | - * @var string $code |
|
2123 | - * eg 'US' |
|
2124 | - */ |
|
2125 | - public $code; |
|
2126 | - |
|
2127 | - /** |
|
2128 | - * @var string $name |
|
2129 | - * eg 'Dollar' |
|
2130 | - */ |
|
2131 | - public $name; |
|
2132 | - |
|
2133 | - /** |
|
2134 | - * plural name |
|
2135 | - * |
|
2136 | - * @var string $plural |
|
2137 | - * eg 'Dollars' |
|
2138 | - */ |
|
2139 | - public $plural; |
|
2140 | - |
|
2141 | - /** |
|
2142 | - * currency sign |
|
2143 | - * |
|
2144 | - * @var string $sign |
|
2145 | - * eg '$' |
|
2146 | - */ |
|
2147 | - public $sign; |
|
2148 | - |
|
2149 | - /** |
|
2150 | - * Whether the currency sign should come before the number or not |
|
2151 | - * |
|
2152 | - * @var boolean $sign_b4 |
|
2153 | - */ |
|
2154 | - public $sign_b4; |
|
2155 | - |
|
2156 | - /** |
|
2157 | - * How many digits should come after the decimal place |
|
2158 | - * |
|
2159 | - * @var int $dec_plc |
|
2160 | - */ |
|
2161 | - public $dec_plc; |
|
2162 | - |
|
2163 | - /** |
|
2164 | - * Symbol to use for decimal mark |
|
2165 | - * |
|
2166 | - * @var string $dec_mrk |
|
2167 | - * eg '.' |
|
2168 | - */ |
|
2169 | - public $dec_mrk; |
|
2170 | - |
|
2171 | - /** |
|
2172 | - * Symbol to use for thousands |
|
2173 | - * |
|
2174 | - * @var string $thsnds |
|
2175 | - * eg ',' |
|
2176 | - */ |
|
2177 | - public $thsnds; |
|
2178 | - |
|
2179 | - |
|
2180 | - |
|
2181 | - /** |
|
2182 | - * class constructor |
|
2183 | - * |
|
2184 | - * @access public |
|
2185 | - * @param string $CNT_ISO |
|
2186 | - * @throws \EE_Error |
|
2187 | - */ |
|
2188 | - public function __construct($CNT_ISO = '') |
|
2189 | - { |
|
2190 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2191 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2192 | - // get country code from organization settings or use default |
|
2193 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2194 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2195 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2196 | - : ''; |
|
2197 | - // but override if requested |
|
2198 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2199 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2200 | - if ( |
|
2201 | - ! empty($CNT_ISO) |
|
2202 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
2203 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2204 | - ) { |
|
2205 | - // retrieve the country settings from the db, just in case they have been customized |
|
2206 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2207 | - if ($country instanceof EE_Country) { |
|
2208 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2209 | - $this->name = $country->currency_name_single(); // Dollar |
|
2210 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
2211 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
2212 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2213 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2214 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2215 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2216 | - } |
|
2217 | - } |
|
2218 | - // fallback to hardcoded defaults, in case the above failed |
|
2219 | - if (empty($this->code)) { |
|
2220 | - // set default currency settings |
|
2221 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2222 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2223 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2224 | - $this->sign = '$'; // currency sign: $ |
|
2225 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2226 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2227 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2228 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2229 | - } |
|
2230 | - } |
|
2231 | -} |
|
2232 | - |
|
2233 | - |
|
2234 | - |
|
2235 | -/** |
|
2236 | - * Class for defining what's in the EE_Config relating to registration settings |
|
2237 | - */ |
|
2238 | -class EE_Registration_Config extends EE_Config_Base |
|
2239 | -{ |
|
2240 | - |
|
2241 | - /** |
|
2242 | - * Default registration status |
|
2243 | - * |
|
2244 | - * @var string $default_STS_ID |
|
2245 | - * eg 'RPP' |
|
2246 | - */ |
|
2247 | - public $default_STS_ID; |
|
2248 | - |
|
2249 | - |
|
2250 | - /** |
|
2251 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2252 | - * registrations) |
|
2253 | - * @var int |
|
2254 | - */ |
|
2255 | - public $default_maximum_number_of_tickets; |
|
2256 | - |
|
2257 | - |
|
2258 | - /** |
|
2259 | - * level of validation to apply to email addresses |
|
2260 | - * |
|
2261 | - * @var string $email_validation_level |
|
2262 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2263 | - */ |
|
2264 | - public $email_validation_level; |
|
2265 | - |
|
2266 | - /** |
|
2267 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2268 | - * |
|
2269 | - * @var boolean $show_pending_payment_options |
|
2270 | - */ |
|
2271 | - public $show_pending_payment_options; |
|
2272 | - |
|
2273 | - /** |
|
2274 | - * Whether to skip the registration confirmation page |
|
2275 | - * |
|
2276 | - * @var boolean $skip_reg_confirmation |
|
2277 | - */ |
|
2278 | - public $skip_reg_confirmation; |
|
2279 | - |
|
2280 | - /** |
|
2281 | - * an array of SPCO reg steps where: |
|
2282 | - * the keys denotes the reg step order |
|
2283 | - * each element consists of an array with the following elements: |
|
2284 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2285 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2286 | - * "slug" => the URL param used to trigger the reg step |
|
2287 | - * |
|
2288 | - * @var array $reg_steps |
|
2289 | - */ |
|
2290 | - public $reg_steps; |
|
2291 | - |
|
2292 | - /** |
|
2293 | - * Whether registration confirmation should be the last page of SPCO |
|
2294 | - * |
|
2295 | - * @var boolean $reg_confirmation_last |
|
2296 | - */ |
|
2297 | - public $reg_confirmation_last; |
|
2298 | - |
|
2299 | - /** |
|
2300 | - * Whether or not to enable the EE Bot Trap |
|
2301 | - * |
|
2302 | - * @var boolean $use_bot_trap |
|
2303 | - */ |
|
2304 | - public $use_bot_trap; |
|
2305 | - |
|
2306 | - /** |
|
2307 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2308 | - * |
|
2309 | - * @var boolean $use_encryption |
|
2310 | - */ |
|
2311 | - public $use_encryption; |
|
2312 | - |
|
2313 | - /** |
|
2314 | - * Whether or not to use ReCaptcha |
|
2315 | - * |
|
2316 | - * @var boolean $use_captcha |
|
2317 | - */ |
|
2318 | - public $use_captcha; |
|
2319 | - |
|
2320 | - /** |
|
2321 | - * ReCaptcha Theme |
|
2322 | - * |
|
2323 | - * @var string $recaptcha_theme |
|
2324 | - * options: 'dark', 'light', 'invisible' |
|
2325 | - */ |
|
2326 | - public $recaptcha_theme; |
|
1544 | +} |
|
2327 | 1545 | |
2328 | - /** |
|
2329 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
2330 | - * |
|
2331 | - * @var string $recaptcha_badge |
|
2332 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
2333 | - */ |
|
2334 | - public $recaptcha_badge; |
|
2335 | 1546 | |
2336 | - /** |
|
2337 | - * ReCaptcha Type |
|
2338 | - * |
|
2339 | - * @var string $recaptcha_type |
|
2340 | - * options: 'audio', 'image' |
|
2341 | - */ |
|
2342 | - public $recaptcha_type; |
|
2343 | 1547 | |
2344 | - /** |
|
2345 | - * ReCaptcha language |
|
2346 | - * |
|
2347 | - * @var string $recaptcha_language |
|
2348 | - * eg 'en' |
|
2349 | - */ |
|
2350 | - public $recaptcha_language; |
|
1548 | +/** |
|
1549 | + * Base class used for config classes. These classes should generally not have |
|
1550 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1551 | + * basically, they should just be well-defined stdClasses |
|
1552 | + */ |
|
1553 | +class EE_Config_Base |
|
1554 | +{ |
|
2351 | 1555 | |
2352 | - /** |
|
2353 | - * ReCaptcha public key |
|
2354 | - * |
|
2355 | - * @var string $recaptcha_publickey |
|
2356 | - */ |
|
2357 | - public $recaptcha_publickey; |
|
1556 | + /** |
|
1557 | + * Utility function for escaping the value of a property and returning. |
|
1558 | + * |
|
1559 | + * @param string $property property name (checks to see if exists). |
|
1560 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1561 | + * @throws \EE_Error |
|
1562 | + */ |
|
1563 | + public function get_pretty($property) |
|
1564 | + { |
|
1565 | + if (! property_exists($this, $property)) { |
|
1566 | + throw new EE_Error( |
|
1567 | + sprintf( |
|
1568 | + __( |
|
1569 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1570 | + 'event_espresso' |
|
1571 | + ), |
|
1572 | + get_class($this), |
|
1573 | + $property |
|
1574 | + ) |
|
1575 | + ); |
|
1576 | + } |
|
1577 | + //just handling escaping of strings for now. |
|
1578 | + if (is_string($this->{$property})) { |
|
1579 | + return stripslashes($this->{$property}); |
|
1580 | + } |
|
1581 | + return $this->{$property}; |
|
1582 | + } |
|
1583 | + |
|
1584 | + |
|
1585 | + |
|
1586 | + public function populate() |
|
1587 | + { |
|
1588 | + //grab defaults via a new instance of this class. |
|
1589 | + $class_name = get_class($this); |
|
1590 | + $defaults = new $class_name; |
|
1591 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1592 | + //default from our $defaults object. |
|
1593 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
1594 | + if ($this->{$property} === null) { |
|
1595 | + $this->{$property} = $value; |
|
1596 | + } |
|
1597 | + } |
|
1598 | + //cleanup |
|
1599 | + unset($defaults); |
|
1600 | + } |
|
1601 | + |
|
1602 | + |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * __isset |
|
1606 | + * |
|
1607 | + * @param $a |
|
1608 | + * @return bool |
|
1609 | + */ |
|
1610 | + public function __isset($a) |
|
1611 | + { |
|
1612 | + return false; |
|
1613 | + } |
|
1614 | + |
|
1615 | + |
|
1616 | + |
|
1617 | + /** |
|
1618 | + * __unset |
|
1619 | + * |
|
1620 | + * @param $a |
|
1621 | + * @return bool |
|
1622 | + */ |
|
1623 | + public function __unset($a) |
|
1624 | + { |
|
1625 | + return false; |
|
1626 | + } |
|
1627 | + |
|
1628 | + |
|
1629 | + |
|
1630 | + /** |
|
1631 | + * __clone |
|
1632 | + */ |
|
1633 | + public function __clone() |
|
1634 | + { |
|
1635 | + } |
|
1636 | + |
|
1637 | + |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * __wakeup |
|
1641 | + */ |
|
1642 | + public function __wakeup() |
|
1643 | + { |
|
1644 | + } |
|
1645 | + |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * __destruct |
|
1650 | + */ |
|
1651 | + public function __destruct() |
|
1652 | + { |
|
1653 | + } |
|
1654 | +} |
|
2358 | 1655 | |
2359 | - /** |
|
2360 | - * ReCaptcha private key |
|
2361 | - * |
|
2362 | - * @var string $recaptcha_privatekey |
|
2363 | - */ |
|
2364 | - public $recaptcha_privatekey; |
|
2365 | 1656 | |
2366 | - /** |
|
2367 | - * array of form names protected by ReCaptcha |
|
2368 | - * |
|
2369 | - * @var array $recaptcha_protected_forms |
|
2370 | - */ |
|
2371 | - public $recaptcha_protected_forms; |
|
2372 | 1657 | |
2373 | - /** |
|
2374 | - * ReCaptcha width |
|
2375 | - * |
|
2376 | - * @var int $recaptcha_width |
|
2377 | - * @deprecated |
|
2378 | - */ |
|
2379 | - public $recaptcha_width; |
|
1658 | +/** |
|
1659 | + * Class for defining what's in the EE_Config relating to registration settings |
|
1660 | + */ |
|
1661 | +class EE_Core_Config extends EE_Config_Base |
|
1662 | +{ |
|
2380 | 1663 | |
2381 | - /** |
|
2382 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2383 | - * |
|
2384 | - * @var boolean $track_invalid_checkout_access |
|
2385 | - */ |
|
2386 | - protected $track_invalid_checkout_access = true; |
|
1664 | + public $current_blog_id; |
|
1665 | + |
|
1666 | + public $ee_ueip_optin; |
|
1667 | + |
|
1668 | + public $ee_ueip_has_notified; |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * Not to be confused with the 4 critical page variables (See |
|
1672 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1673 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1674 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1675 | + * |
|
1676 | + * @var array |
|
1677 | + */ |
|
1678 | + public $post_shortcodes; |
|
1679 | + |
|
1680 | + public $module_route_map; |
|
1681 | + |
|
1682 | + public $module_forward_map; |
|
1683 | + |
|
1684 | + public $module_view_map; |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * The next 4 vars are the IDs of critical EE pages. |
|
1688 | + * |
|
1689 | + * @var int |
|
1690 | + */ |
|
1691 | + public $reg_page_id; |
|
1692 | + |
|
1693 | + public $txn_page_id; |
|
1694 | + |
|
1695 | + public $thank_you_page_id; |
|
1696 | + |
|
1697 | + public $cancel_page_id; |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * The next 4 vars are the URLs of critical EE pages. |
|
1701 | + * |
|
1702 | + * @var int |
|
1703 | + */ |
|
1704 | + public $reg_page_url; |
|
1705 | + |
|
1706 | + public $txn_page_url; |
|
1707 | + |
|
1708 | + public $thank_you_page_url; |
|
1709 | + |
|
1710 | + public $cancel_page_url; |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * The next vars relate to the custom slugs for EE CPT routes |
|
1714 | + */ |
|
1715 | + public $event_cpt_slug; |
|
1716 | + |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
1720 | + * request across blog switches in a multisite context. |
|
1721 | + * Avoids extra queries to the db for this option. |
|
1722 | + * |
|
1723 | + * @var bool |
|
1724 | + */ |
|
1725 | + public static $ee_ueip_option; |
|
1726 | + |
|
1727 | + |
|
1728 | + |
|
1729 | + /** |
|
1730 | + * class constructor |
|
1731 | + * |
|
1732 | + * @access public |
|
1733 | + */ |
|
1734 | + public function __construct() |
|
1735 | + { |
|
1736 | + // set default organization settings |
|
1737 | + $this->current_blog_id = get_current_blog_id(); |
|
1738 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1739 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1740 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1741 | + $this->post_shortcodes = array(); |
|
1742 | + $this->module_route_map = array(); |
|
1743 | + $this->module_forward_map = array(); |
|
1744 | + $this->module_view_map = array(); |
|
1745 | + // critical EE page IDs |
|
1746 | + $this->reg_page_id = 0; |
|
1747 | + $this->txn_page_id = 0; |
|
1748 | + $this->thank_you_page_id = 0; |
|
1749 | + $this->cancel_page_id = 0; |
|
1750 | + // critical EE page URLs |
|
1751 | + $this->reg_page_url = ''; |
|
1752 | + $this->txn_page_url = ''; |
|
1753 | + $this->thank_you_page_url = ''; |
|
1754 | + $this->cancel_page_url = ''; |
|
1755 | + //cpt slugs |
|
1756 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1757 | + //ueip constant check |
|
1758 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1759 | + $this->ee_ueip_optin = false; |
|
1760 | + $this->ee_ueip_has_notified = true; |
|
1761 | + } |
|
1762 | + } |
|
1763 | + |
|
1764 | + |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * @return array |
|
1768 | + */ |
|
1769 | + public function get_critical_pages_array() |
|
1770 | + { |
|
1771 | + return array( |
|
1772 | + $this->reg_page_id, |
|
1773 | + $this->txn_page_id, |
|
1774 | + $this->thank_you_page_id, |
|
1775 | + $this->cancel_page_id, |
|
1776 | + ); |
|
1777 | + } |
|
1778 | + |
|
1779 | + |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * @return array |
|
1783 | + */ |
|
1784 | + public function get_critical_pages_shortcodes_array() |
|
1785 | + { |
|
1786 | + return array( |
|
1787 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1788 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1789 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1790 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1791 | + ); |
|
1792 | + } |
|
1793 | + |
|
1794 | + |
|
1795 | + |
|
1796 | + /** |
|
1797 | + * gets/returns URL for EE reg_page |
|
1798 | + * |
|
1799 | + * @access public |
|
1800 | + * @return string |
|
1801 | + */ |
|
1802 | + public function reg_page_url() |
|
1803 | + { |
|
1804 | + if (! $this->reg_page_url) { |
|
1805 | + $this->reg_page_url = add_query_arg( |
|
1806 | + array('uts' => time()), |
|
1807 | + get_permalink($this->reg_page_id) |
|
1808 | + ) . '#checkout'; |
|
1809 | + } |
|
1810 | + return $this->reg_page_url; |
|
1811 | + } |
|
1812 | + |
|
1813 | + |
|
1814 | + |
|
1815 | + /** |
|
1816 | + * gets/returns URL for EE txn_page |
|
1817 | + * |
|
1818 | + * @param array $query_args like what gets passed to |
|
1819 | + * add_query_arg() as the first argument |
|
1820 | + * @access public |
|
1821 | + * @return string |
|
1822 | + */ |
|
1823 | + public function txn_page_url($query_args = array()) |
|
1824 | + { |
|
1825 | + if (! $this->txn_page_url) { |
|
1826 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1827 | + } |
|
1828 | + if ($query_args) { |
|
1829 | + return add_query_arg($query_args, $this->txn_page_url); |
|
1830 | + } else { |
|
1831 | + return $this->txn_page_url; |
|
1832 | + } |
|
1833 | + } |
|
1834 | + |
|
1835 | + |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * gets/returns URL for EE thank_you_page |
|
1839 | + * |
|
1840 | + * @param array $query_args like what gets passed to |
|
1841 | + * add_query_arg() as the first argument |
|
1842 | + * @access public |
|
1843 | + * @return string |
|
1844 | + */ |
|
1845 | + public function thank_you_page_url($query_args = array()) |
|
1846 | + { |
|
1847 | + if (! $this->thank_you_page_url) { |
|
1848 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1849 | + } |
|
1850 | + if ($query_args) { |
|
1851 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
1852 | + } else { |
|
1853 | + return $this->thank_you_page_url; |
|
1854 | + } |
|
1855 | + } |
|
1856 | + |
|
1857 | + |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * gets/returns URL for EE cancel_page |
|
1861 | + * |
|
1862 | + * @access public |
|
1863 | + * @return string |
|
1864 | + */ |
|
1865 | + public function cancel_page_url() |
|
1866 | + { |
|
1867 | + if (! $this->cancel_page_url) { |
|
1868 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1869 | + } |
|
1870 | + return $this->cancel_page_url; |
|
1871 | + } |
|
1872 | + |
|
1873 | + |
|
1874 | + |
|
1875 | + /** |
|
1876 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1877 | + * |
|
1878 | + * @since 4.7.5 |
|
1879 | + */ |
|
1880 | + protected function _reset_urls() |
|
1881 | + { |
|
1882 | + $this->reg_page_url = ''; |
|
1883 | + $this->txn_page_url = ''; |
|
1884 | + $this->cancel_page_url = ''; |
|
1885 | + $this->thank_you_page_url = ''; |
|
1886 | + } |
|
1887 | + |
|
1888 | + |
|
1889 | + |
|
1890 | + /** |
|
1891 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
1892 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1893 | + * on the main site only. |
|
1894 | + * |
|
1895 | + * @return mixed|void |
|
1896 | + */ |
|
1897 | + protected function _get_main_ee_ueip_optin() |
|
1898 | + { |
|
1899 | + //if this is the main site then we can just bypass our direct query. |
|
1900 | + if (is_main_site()) { |
|
1901 | + return get_option('ee_ueip_optin', false); |
|
1902 | + } |
|
1903 | + //is this already cached for this request? If so use it. |
|
1904 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1905 | + return EE_Core_Config::$ee_ueip_option; |
|
1906 | + } |
|
1907 | + global $wpdb; |
|
1908 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1909 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1910 | + $option = 'ee_ueip_optin'; |
|
1911 | + //set correct table for query |
|
1912 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1913 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1914 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1915 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1916 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1917 | + //for the purpose of caching. |
|
1918 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1919 | + if (false !== $pre) { |
|
1920 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
1921 | + return EE_Core_Config::$ee_ueip_option; |
|
1922 | + } |
|
1923 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1924 | + $option)); |
|
1925 | + if (is_object($row)) { |
|
1926 | + $value = $row->option_value; |
|
1927 | + } else { //option does not exist so use default. |
|
1928 | + return apply_filters('default_option_' . $option, false, $option); |
|
1929 | + } |
|
1930 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1931 | + return EE_Core_Config::$ee_ueip_option; |
|
1932 | + } |
|
1933 | + |
|
1934 | + |
|
1935 | + |
|
1936 | + /** |
|
1937 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1938 | + * on the object. |
|
1939 | + * |
|
1940 | + * @return array |
|
1941 | + */ |
|
1942 | + public function __sleep() |
|
1943 | + { |
|
1944 | + //reset all url properties |
|
1945 | + $this->_reset_urls(); |
|
1946 | + //return what to save to db |
|
1947 | + return array_keys(get_object_vars($this)); |
|
1948 | + } |
|
2387 | 1949 | |
1950 | +} |
|
2388 | 1951 | |
2389 | 1952 | |
2390 | - /** |
|
2391 | - * class constructor |
|
2392 | - * |
|
2393 | - * @access public |
|
2394 | - */ |
|
2395 | - public function __construct() |
|
2396 | - { |
|
2397 | - // set default registration settings |
|
2398 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2399 | - $this->email_validation_level = 'wp_default'; |
|
2400 | - $this->show_pending_payment_options = true; |
|
2401 | - $this->skip_reg_confirmation = false; |
|
2402 | - $this->reg_steps = array(); |
|
2403 | - $this->reg_confirmation_last = false; |
|
2404 | - $this->use_bot_trap = true; |
|
2405 | - $this->use_encryption = true; |
|
2406 | - $this->use_captcha = false; |
|
2407 | - $this->recaptcha_theme = 'light'; |
|
2408 | - $this->recaptcha_badge = 'bottomleft'; |
|
2409 | - $this->recaptcha_type = 'image'; |
|
2410 | - $this->recaptcha_language = 'en'; |
|
2411 | - $this->recaptcha_publickey = null; |
|
2412 | - $this->recaptcha_privatekey = null; |
|
2413 | - $this->recaptcha_protected_forms = array(); |
|
2414 | - $this->recaptcha_width = 500; |
|
2415 | - $this->default_maximum_number_of_tickets = 10; |
|
2416 | - } |
|
2417 | - |
|
2418 | - |
|
2419 | - |
|
2420 | - /** |
|
2421 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2422 | - * |
|
2423 | - * @since 4.8.8.rc.019 |
|
2424 | - */ |
|
2425 | - public function do_hooks() |
|
2426 | - { |
|
2427 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2428 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2429 | - } |
|
2430 | 1953 | |
1954 | +/** |
|
1955 | + * Config class for storing info on the Organization |
|
1956 | + */ |
|
1957 | +class EE_Organization_Config extends EE_Config_Base |
|
1958 | +{ |
|
2431 | 1959 | |
1960 | + /** |
|
1961 | + * @var string $name |
|
1962 | + * eg EE4.1 |
|
1963 | + */ |
|
1964 | + public $name; |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * @var string $address_1 |
|
1968 | + * eg 123 Onna Road |
|
1969 | + */ |
|
1970 | + public $address_1; |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * @var string $address_2 |
|
1974 | + * eg PO Box 123 |
|
1975 | + */ |
|
1976 | + public $address_2; |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @var string $city |
|
1980 | + * eg Inna City |
|
1981 | + */ |
|
1982 | + public $city; |
|
1983 | + |
|
1984 | + /** |
|
1985 | + * @var int $STA_ID |
|
1986 | + * eg 4 |
|
1987 | + */ |
|
1988 | + public $STA_ID; |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * @var string $CNT_ISO |
|
1992 | + * eg US |
|
1993 | + */ |
|
1994 | + public $CNT_ISO; |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * @var string $zip |
|
1998 | + * eg 12345 or V1A 2B3 |
|
1999 | + */ |
|
2000 | + public $zip; |
|
2001 | + |
|
2002 | + /** |
|
2003 | + * @var string $email |
|
2004 | + * eg [email protected] |
|
2005 | + */ |
|
2006 | + public $email; |
|
2007 | + |
|
2008 | + |
|
2009 | + /** |
|
2010 | + * @var string $phone |
|
2011 | + * eg. 111-111-1111 |
|
2012 | + */ |
|
2013 | + public $phone; |
|
2014 | + |
|
2015 | + |
|
2016 | + /** |
|
2017 | + * @var string $vat |
|
2018 | + * VAT/Tax Number |
|
2019 | + */ |
|
2020 | + public $vat; |
|
2021 | + |
|
2022 | + /** |
|
2023 | + * @var string $logo_url |
|
2024 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2025 | + */ |
|
2026 | + public $logo_url; |
|
2027 | + |
|
2028 | + |
|
2029 | + /** |
|
2030 | + * The below are all various properties for holding links to organization social network profiles |
|
2031 | + * |
|
2032 | + * @var string |
|
2033 | + */ |
|
2034 | + /** |
|
2035 | + * facebook (facebook.com/profile.name) |
|
2036 | + * |
|
2037 | + * @var string |
|
2038 | + */ |
|
2039 | + public $facebook; |
|
2040 | + |
|
2041 | + |
|
2042 | + /** |
|
2043 | + * twitter (twitter.com/twitter_handle) |
|
2044 | + * |
|
2045 | + * @var string |
|
2046 | + */ |
|
2047 | + public $twitter; |
|
2048 | + |
|
2049 | + |
|
2050 | + /** |
|
2051 | + * linkedin (linkedin.com/in/profile_name) |
|
2052 | + * |
|
2053 | + * @var string |
|
2054 | + */ |
|
2055 | + public $linkedin; |
|
2056 | + |
|
2057 | + |
|
2058 | + /** |
|
2059 | + * pinterest (www.pinterest.com/profile_name) |
|
2060 | + * |
|
2061 | + * @var string |
|
2062 | + */ |
|
2063 | + public $pinterest; |
|
2064 | + |
|
2065 | + |
|
2066 | + /** |
|
2067 | + * google+ (google.com/+profileName) |
|
2068 | + * |
|
2069 | + * @var string |
|
2070 | + */ |
|
2071 | + public $google; |
|
2072 | + |
|
2073 | + |
|
2074 | + /** |
|
2075 | + * instagram (instagram.com/handle) |
|
2076 | + * |
|
2077 | + * @var string |
|
2078 | + */ |
|
2079 | + public $instagram; |
|
2080 | + |
|
2081 | + |
|
2082 | + |
|
2083 | + /** |
|
2084 | + * class constructor |
|
2085 | + * |
|
2086 | + * @access public |
|
2087 | + */ |
|
2088 | + public function __construct() |
|
2089 | + { |
|
2090 | + // set default organization settings |
|
2091 | + //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
2092 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
2093 | + $this->address_1 = '123 Onna Road'; |
|
2094 | + $this->address_2 = 'PO Box 123'; |
|
2095 | + $this->city = 'Inna City'; |
|
2096 | + $this->STA_ID = 4; |
|
2097 | + $this->CNT_ISO = 'US'; |
|
2098 | + $this->zip = '12345'; |
|
2099 | + $this->email = get_bloginfo('admin_email'); |
|
2100 | + $this->phone = ''; |
|
2101 | + $this->vat = '123456789'; |
|
2102 | + $this->logo_url = ''; |
|
2103 | + $this->facebook = ''; |
|
2104 | + $this->twitter = ''; |
|
2105 | + $this->linkedin = ''; |
|
2106 | + $this->pinterest = ''; |
|
2107 | + $this->google = ''; |
|
2108 | + $this->instagram = ''; |
|
2109 | + } |
|
2432 | 2110 | |
2433 | - /** |
|
2434 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
2435 | - * field matches the config setting for default_STS_ID. |
|
2436 | - */ |
|
2437 | - public function set_default_reg_status_on_EEM_Event() |
|
2438 | - { |
|
2439 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2440 | - } |
|
2111 | +} |
|
2441 | 2112 | |
2442 | 2113 | |
2443 | - /** |
|
2444 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2445 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
2446 | - */ |
|
2447 | - public function set_default_max_ticket_on_EEM_Event() |
|
2448 | - { |
|
2449 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2450 | - } |
|
2451 | 2114 | |
2115 | +/** |
|
2116 | + * Class for defining what's in the EE_Config relating to currency |
|
2117 | + */ |
|
2118 | +class EE_Currency_Config extends EE_Config_Base |
|
2119 | +{ |
|
2452 | 2120 | |
2121 | + /** |
|
2122 | + * @var string $code |
|
2123 | + * eg 'US' |
|
2124 | + */ |
|
2125 | + public $code; |
|
2126 | + |
|
2127 | + /** |
|
2128 | + * @var string $name |
|
2129 | + * eg 'Dollar' |
|
2130 | + */ |
|
2131 | + public $name; |
|
2132 | + |
|
2133 | + /** |
|
2134 | + * plural name |
|
2135 | + * |
|
2136 | + * @var string $plural |
|
2137 | + * eg 'Dollars' |
|
2138 | + */ |
|
2139 | + public $plural; |
|
2140 | + |
|
2141 | + /** |
|
2142 | + * currency sign |
|
2143 | + * |
|
2144 | + * @var string $sign |
|
2145 | + * eg '$' |
|
2146 | + */ |
|
2147 | + public $sign; |
|
2148 | + |
|
2149 | + /** |
|
2150 | + * Whether the currency sign should come before the number or not |
|
2151 | + * |
|
2152 | + * @var boolean $sign_b4 |
|
2153 | + */ |
|
2154 | + public $sign_b4; |
|
2155 | + |
|
2156 | + /** |
|
2157 | + * How many digits should come after the decimal place |
|
2158 | + * |
|
2159 | + * @var int $dec_plc |
|
2160 | + */ |
|
2161 | + public $dec_plc; |
|
2162 | + |
|
2163 | + /** |
|
2164 | + * Symbol to use for decimal mark |
|
2165 | + * |
|
2166 | + * @var string $dec_mrk |
|
2167 | + * eg '.' |
|
2168 | + */ |
|
2169 | + public $dec_mrk; |
|
2170 | + |
|
2171 | + /** |
|
2172 | + * Symbol to use for thousands |
|
2173 | + * |
|
2174 | + * @var string $thsnds |
|
2175 | + * eg ',' |
|
2176 | + */ |
|
2177 | + public $thsnds; |
|
2178 | + |
|
2179 | + |
|
2180 | + |
|
2181 | + /** |
|
2182 | + * class constructor |
|
2183 | + * |
|
2184 | + * @access public |
|
2185 | + * @param string $CNT_ISO |
|
2186 | + * @throws \EE_Error |
|
2187 | + */ |
|
2188 | + public function __construct($CNT_ISO = '') |
|
2189 | + { |
|
2190 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2191 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2192 | + // get country code from organization settings or use default |
|
2193 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2194 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2195 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2196 | + : ''; |
|
2197 | + // but override if requested |
|
2198 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2199 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2200 | + if ( |
|
2201 | + ! empty($CNT_ISO) |
|
2202 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
2203 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2204 | + ) { |
|
2205 | + // retrieve the country settings from the db, just in case they have been customized |
|
2206 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2207 | + if ($country instanceof EE_Country) { |
|
2208 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2209 | + $this->name = $country->currency_name_single(); // Dollar |
|
2210 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
2211 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
2212 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2213 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2214 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2215 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2216 | + } |
|
2217 | + } |
|
2218 | + // fallback to hardcoded defaults, in case the above failed |
|
2219 | + if (empty($this->code)) { |
|
2220 | + // set default currency settings |
|
2221 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2222 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2223 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2224 | + $this->sign = '$'; // currency sign: $ |
|
2225 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2226 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2227 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2228 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2229 | + } |
|
2230 | + } |
|
2231 | +} |
|
2453 | 2232 | |
2454 | - /** |
|
2455 | - * @return boolean |
|
2456 | - */ |
|
2457 | - public function track_invalid_checkout_access() |
|
2458 | - { |
|
2459 | - return $this->track_invalid_checkout_access; |
|
2460 | - } |
|
2461 | 2233 | |
2462 | 2234 | |
2235 | +/** |
|
2236 | + * Class for defining what's in the EE_Config relating to registration settings |
|
2237 | + */ |
|
2238 | +class EE_Registration_Config extends EE_Config_Base |
|
2239 | +{ |
|
2463 | 2240 | |
2464 | - /** |
|
2465 | - * @param boolean $track_invalid_checkout_access |
|
2466 | - */ |
|
2467 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2468 | - { |
|
2469 | - $this->track_invalid_checkout_access = filter_var( |
|
2470 | - $track_invalid_checkout_access, |
|
2471 | - FILTER_VALIDATE_BOOLEAN |
|
2472 | - ); |
|
2473 | - } |
|
2241 | + /** |
|
2242 | + * Default registration status |
|
2243 | + * |
|
2244 | + * @var string $default_STS_ID |
|
2245 | + * eg 'RPP' |
|
2246 | + */ |
|
2247 | + public $default_STS_ID; |
|
2248 | + |
|
2249 | + |
|
2250 | + /** |
|
2251 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2252 | + * registrations) |
|
2253 | + * @var int |
|
2254 | + */ |
|
2255 | + public $default_maximum_number_of_tickets; |
|
2256 | + |
|
2257 | + |
|
2258 | + /** |
|
2259 | + * level of validation to apply to email addresses |
|
2260 | + * |
|
2261 | + * @var string $email_validation_level |
|
2262 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2263 | + */ |
|
2264 | + public $email_validation_level; |
|
2265 | + |
|
2266 | + /** |
|
2267 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2268 | + * |
|
2269 | + * @var boolean $show_pending_payment_options |
|
2270 | + */ |
|
2271 | + public $show_pending_payment_options; |
|
2272 | + |
|
2273 | + /** |
|
2274 | + * Whether to skip the registration confirmation page |
|
2275 | + * |
|
2276 | + * @var boolean $skip_reg_confirmation |
|
2277 | + */ |
|
2278 | + public $skip_reg_confirmation; |
|
2279 | + |
|
2280 | + /** |
|
2281 | + * an array of SPCO reg steps where: |
|
2282 | + * the keys denotes the reg step order |
|
2283 | + * each element consists of an array with the following elements: |
|
2284 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2285 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2286 | + * "slug" => the URL param used to trigger the reg step |
|
2287 | + * |
|
2288 | + * @var array $reg_steps |
|
2289 | + */ |
|
2290 | + public $reg_steps; |
|
2291 | + |
|
2292 | + /** |
|
2293 | + * Whether registration confirmation should be the last page of SPCO |
|
2294 | + * |
|
2295 | + * @var boolean $reg_confirmation_last |
|
2296 | + */ |
|
2297 | + public $reg_confirmation_last; |
|
2298 | + |
|
2299 | + /** |
|
2300 | + * Whether or not to enable the EE Bot Trap |
|
2301 | + * |
|
2302 | + * @var boolean $use_bot_trap |
|
2303 | + */ |
|
2304 | + public $use_bot_trap; |
|
2305 | + |
|
2306 | + /** |
|
2307 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2308 | + * |
|
2309 | + * @var boolean $use_encryption |
|
2310 | + */ |
|
2311 | + public $use_encryption; |
|
2312 | + |
|
2313 | + /** |
|
2314 | + * Whether or not to use ReCaptcha |
|
2315 | + * |
|
2316 | + * @var boolean $use_captcha |
|
2317 | + */ |
|
2318 | + public $use_captcha; |
|
2319 | + |
|
2320 | + /** |
|
2321 | + * ReCaptcha Theme |
|
2322 | + * |
|
2323 | + * @var string $recaptcha_theme |
|
2324 | + * options: 'dark', 'light', 'invisible' |
|
2325 | + */ |
|
2326 | + public $recaptcha_theme; |
|
2327 | + |
|
2328 | + /** |
|
2329 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
2330 | + * |
|
2331 | + * @var string $recaptcha_badge |
|
2332 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
2333 | + */ |
|
2334 | + public $recaptcha_badge; |
|
2335 | + |
|
2336 | + /** |
|
2337 | + * ReCaptcha Type |
|
2338 | + * |
|
2339 | + * @var string $recaptcha_type |
|
2340 | + * options: 'audio', 'image' |
|
2341 | + */ |
|
2342 | + public $recaptcha_type; |
|
2343 | + |
|
2344 | + /** |
|
2345 | + * ReCaptcha language |
|
2346 | + * |
|
2347 | + * @var string $recaptcha_language |
|
2348 | + * eg 'en' |
|
2349 | + */ |
|
2350 | + public $recaptcha_language; |
|
2351 | + |
|
2352 | + /** |
|
2353 | + * ReCaptcha public key |
|
2354 | + * |
|
2355 | + * @var string $recaptcha_publickey |
|
2356 | + */ |
|
2357 | + public $recaptcha_publickey; |
|
2358 | + |
|
2359 | + /** |
|
2360 | + * ReCaptcha private key |
|
2361 | + * |
|
2362 | + * @var string $recaptcha_privatekey |
|
2363 | + */ |
|
2364 | + public $recaptcha_privatekey; |
|
2365 | + |
|
2366 | + /** |
|
2367 | + * array of form names protected by ReCaptcha |
|
2368 | + * |
|
2369 | + * @var array $recaptcha_protected_forms |
|
2370 | + */ |
|
2371 | + public $recaptcha_protected_forms; |
|
2372 | + |
|
2373 | + /** |
|
2374 | + * ReCaptcha width |
|
2375 | + * |
|
2376 | + * @var int $recaptcha_width |
|
2377 | + * @deprecated |
|
2378 | + */ |
|
2379 | + public $recaptcha_width; |
|
2380 | + |
|
2381 | + /** |
|
2382 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2383 | + * |
|
2384 | + * @var boolean $track_invalid_checkout_access |
|
2385 | + */ |
|
2386 | + protected $track_invalid_checkout_access = true; |
|
2387 | + |
|
2388 | + |
|
2389 | + |
|
2390 | + /** |
|
2391 | + * class constructor |
|
2392 | + * |
|
2393 | + * @access public |
|
2394 | + */ |
|
2395 | + public function __construct() |
|
2396 | + { |
|
2397 | + // set default registration settings |
|
2398 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2399 | + $this->email_validation_level = 'wp_default'; |
|
2400 | + $this->show_pending_payment_options = true; |
|
2401 | + $this->skip_reg_confirmation = false; |
|
2402 | + $this->reg_steps = array(); |
|
2403 | + $this->reg_confirmation_last = false; |
|
2404 | + $this->use_bot_trap = true; |
|
2405 | + $this->use_encryption = true; |
|
2406 | + $this->use_captcha = false; |
|
2407 | + $this->recaptcha_theme = 'light'; |
|
2408 | + $this->recaptcha_badge = 'bottomleft'; |
|
2409 | + $this->recaptcha_type = 'image'; |
|
2410 | + $this->recaptcha_language = 'en'; |
|
2411 | + $this->recaptcha_publickey = null; |
|
2412 | + $this->recaptcha_privatekey = null; |
|
2413 | + $this->recaptcha_protected_forms = array(); |
|
2414 | + $this->recaptcha_width = 500; |
|
2415 | + $this->default_maximum_number_of_tickets = 10; |
|
2416 | + } |
|
2417 | + |
|
2418 | + |
|
2419 | + |
|
2420 | + /** |
|
2421 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2422 | + * |
|
2423 | + * @since 4.8.8.rc.019 |
|
2424 | + */ |
|
2425 | + public function do_hooks() |
|
2426 | + { |
|
2427 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2428 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2429 | + } |
|
2430 | + |
|
2431 | + |
|
2432 | + |
|
2433 | + /** |
|
2434 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
2435 | + * field matches the config setting for default_STS_ID. |
|
2436 | + */ |
|
2437 | + public function set_default_reg_status_on_EEM_Event() |
|
2438 | + { |
|
2439 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2440 | + } |
|
2441 | + |
|
2442 | + |
|
2443 | + /** |
|
2444 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2445 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
2446 | + */ |
|
2447 | + public function set_default_max_ticket_on_EEM_Event() |
|
2448 | + { |
|
2449 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2450 | + } |
|
2451 | + |
|
2452 | + |
|
2453 | + |
|
2454 | + /** |
|
2455 | + * @return boolean |
|
2456 | + */ |
|
2457 | + public function track_invalid_checkout_access() |
|
2458 | + { |
|
2459 | + return $this->track_invalid_checkout_access; |
|
2460 | + } |
|
2461 | + |
|
2462 | + |
|
2463 | + |
|
2464 | + /** |
|
2465 | + * @param boolean $track_invalid_checkout_access |
|
2466 | + */ |
|
2467 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2468 | + { |
|
2469 | + $this->track_invalid_checkout_access = filter_var( |
|
2470 | + $track_invalid_checkout_access, |
|
2471 | + FILTER_VALIDATE_BOOLEAN |
|
2472 | + ); |
|
2473 | + } |
|
2474 | 2474 | |
2475 | 2475 | |
2476 | 2476 | |
@@ -2484,160 +2484,160 @@ discard block |
||
2484 | 2484 | class EE_Admin_Config extends EE_Config_Base |
2485 | 2485 | { |
2486 | 2486 | |
2487 | - /** |
|
2488 | - * @var boolean $use_personnel_manager |
|
2489 | - */ |
|
2490 | - public $use_personnel_manager; |
|
2491 | - |
|
2492 | - /** |
|
2493 | - * @var boolean $use_dashboard_widget |
|
2494 | - */ |
|
2495 | - public $use_dashboard_widget; |
|
2496 | - |
|
2497 | - /** |
|
2498 | - * @var int $events_in_dashboard |
|
2499 | - */ |
|
2500 | - public $events_in_dashboard; |
|
2501 | - |
|
2502 | - /** |
|
2503 | - * @var boolean $use_event_timezones |
|
2504 | - */ |
|
2505 | - public $use_event_timezones; |
|
2506 | - |
|
2507 | - /** |
|
2508 | - * @var boolean $use_full_logging |
|
2509 | - */ |
|
2510 | - public $use_full_logging; |
|
2511 | - |
|
2512 | - /** |
|
2513 | - * @var string $log_file_name |
|
2514 | - */ |
|
2515 | - public $log_file_name; |
|
2516 | - |
|
2517 | - /** |
|
2518 | - * @var string $debug_file_name |
|
2519 | - */ |
|
2520 | - public $debug_file_name; |
|
2521 | - |
|
2522 | - /** |
|
2523 | - * @var boolean $use_remote_logging |
|
2524 | - */ |
|
2525 | - public $use_remote_logging; |
|
2526 | - |
|
2527 | - /** |
|
2528 | - * @var string $remote_logging_url |
|
2529 | - */ |
|
2530 | - public $remote_logging_url; |
|
2531 | - |
|
2532 | - /** |
|
2533 | - * @var boolean $show_reg_footer |
|
2534 | - */ |
|
2535 | - public $show_reg_footer; |
|
2536 | - |
|
2537 | - /** |
|
2538 | - * @var string $affiliate_id |
|
2539 | - */ |
|
2540 | - public $affiliate_id; |
|
2541 | - |
|
2542 | - /** |
|
2543 | - * help tours on or off (global setting) |
|
2544 | - * |
|
2545 | - * @var boolean |
|
2546 | - */ |
|
2547 | - public $help_tour_activation; |
|
2548 | - |
|
2549 | - /** |
|
2550 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
2551 | - * but is incompatible with some server configuration errors |
|
2552 | - * if you get "500 internal server errors" during registration, try turning this on |
|
2553 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2554 | - * |
|
2555 | - * @var boolean $encode_session_data |
|
2556 | - */ |
|
2557 | - private $encode_session_data = false; |
|
2558 | - |
|
2559 | - |
|
2560 | - |
|
2561 | - /** |
|
2562 | - * class constructor |
|
2563 | - * |
|
2564 | - * @access public |
|
2565 | - */ |
|
2566 | - public function __construct() |
|
2567 | - { |
|
2568 | - // set default general admin settings |
|
2569 | - $this->use_personnel_manager = true; |
|
2570 | - $this->use_dashboard_widget = true; |
|
2571 | - $this->events_in_dashboard = 30; |
|
2572 | - $this->use_event_timezones = false; |
|
2573 | - $this->use_full_logging = false; |
|
2574 | - $this->use_remote_logging = false; |
|
2575 | - $this->remote_logging_url = null; |
|
2576 | - $this->show_reg_footer = true; |
|
2577 | - $this->affiliate_id = 'default'; |
|
2578 | - $this->help_tour_activation = true; |
|
2579 | - $this->encode_session_data = false; |
|
2580 | - } |
|
2581 | - |
|
2582 | - |
|
2583 | - |
|
2584 | - /** |
|
2585 | - * @param bool $reset |
|
2586 | - * @return string |
|
2587 | - */ |
|
2588 | - public function log_file_name($reset = false) |
|
2589 | - { |
|
2590 | - if (empty($this->log_file_name) || $reset) { |
|
2591 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2592 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2593 | - } |
|
2594 | - return $this->log_file_name; |
|
2595 | - } |
|
2596 | - |
|
2597 | - |
|
2598 | - |
|
2599 | - /** |
|
2600 | - * @param bool $reset |
|
2601 | - * @return string |
|
2602 | - */ |
|
2603 | - public function debug_file_name($reset = false) |
|
2604 | - { |
|
2605 | - if (empty($this->debug_file_name) || $reset) { |
|
2606 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2607 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2608 | - } |
|
2609 | - return $this->debug_file_name; |
|
2610 | - } |
|
2611 | - |
|
2612 | - |
|
2613 | - |
|
2614 | - /** |
|
2615 | - * @return string |
|
2616 | - */ |
|
2617 | - public function affiliate_id() |
|
2618 | - { |
|
2619 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2620 | - } |
|
2621 | - |
|
2622 | - |
|
2623 | - |
|
2624 | - /** |
|
2625 | - * @return boolean |
|
2626 | - */ |
|
2627 | - public function encode_session_data() |
|
2628 | - { |
|
2629 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2630 | - } |
|
2631 | - |
|
2632 | - |
|
2633 | - |
|
2634 | - /** |
|
2635 | - * @param boolean $encode_session_data |
|
2636 | - */ |
|
2637 | - public function set_encode_session_data($encode_session_data) |
|
2638 | - { |
|
2639 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2640 | - } |
|
2487 | + /** |
|
2488 | + * @var boolean $use_personnel_manager |
|
2489 | + */ |
|
2490 | + public $use_personnel_manager; |
|
2491 | + |
|
2492 | + /** |
|
2493 | + * @var boolean $use_dashboard_widget |
|
2494 | + */ |
|
2495 | + public $use_dashboard_widget; |
|
2496 | + |
|
2497 | + /** |
|
2498 | + * @var int $events_in_dashboard |
|
2499 | + */ |
|
2500 | + public $events_in_dashboard; |
|
2501 | + |
|
2502 | + /** |
|
2503 | + * @var boolean $use_event_timezones |
|
2504 | + */ |
|
2505 | + public $use_event_timezones; |
|
2506 | + |
|
2507 | + /** |
|
2508 | + * @var boolean $use_full_logging |
|
2509 | + */ |
|
2510 | + public $use_full_logging; |
|
2511 | + |
|
2512 | + /** |
|
2513 | + * @var string $log_file_name |
|
2514 | + */ |
|
2515 | + public $log_file_name; |
|
2516 | + |
|
2517 | + /** |
|
2518 | + * @var string $debug_file_name |
|
2519 | + */ |
|
2520 | + public $debug_file_name; |
|
2521 | + |
|
2522 | + /** |
|
2523 | + * @var boolean $use_remote_logging |
|
2524 | + */ |
|
2525 | + public $use_remote_logging; |
|
2526 | + |
|
2527 | + /** |
|
2528 | + * @var string $remote_logging_url |
|
2529 | + */ |
|
2530 | + public $remote_logging_url; |
|
2531 | + |
|
2532 | + /** |
|
2533 | + * @var boolean $show_reg_footer |
|
2534 | + */ |
|
2535 | + public $show_reg_footer; |
|
2536 | + |
|
2537 | + /** |
|
2538 | + * @var string $affiliate_id |
|
2539 | + */ |
|
2540 | + public $affiliate_id; |
|
2541 | + |
|
2542 | + /** |
|
2543 | + * help tours on or off (global setting) |
|
2544 | + * |
|
2545 | + * @var boolean |
|
2546 | + */ |
|
2547 | + public $help_tour_activation; |
|
2548 | + |
|
2549 | + /** |
|
2550 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
2551 | + * but is incompatible with some server configuration errors |
|
2552 | + * if you get "500 internal server errors" during registration, try turning this on |
|
2553 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2554 | + * |
|
2555 | + * @var boolean $encode_session_data |
|
2556 | + */ |
|
2557 | + private $encode_session_data = false; |
|
2558 | + |
|
2559 | + |
|
2560 | + |
|
2561 | + /** |
|
2562 | + * class constructor |
|
2563 | + * |
|
2564 | + * @access public |
|
2565 | + */ |
|
2566 | + public function __construct() |
|
2567 | + { |
|
2568 | + // set default general admin settings |
|
2569 | + $this->use_personnel_manager = true; |
|
2570 | + $this->use_dashboard_widget = true; |
|
2571 | + $this->events_in_dashboard = 30; |
|
2572 | + $this->use_event_timezones = false; |
|
2573 | + $this->use_full_logging = false; |
|
2574 | + $this->use_remote_logging = false; |
|
2575 | + $this->remote_logging_url = null; |
|
2576 | + $this->show_reg_footer = true; |
|
2577 | + $this->affiliate_id = 'default'; |
|
2578 | + $this->help_tour_activation = true; |
|
2579 | + $this->encode_session_data = false; |
|
2580 | + } |
|
2581 | + |
|
2582 | + |
|
2583 | + |
|
2584 | + /** |
|
2585 | + * @param bool $reset |
|
2586 | + * @return string |
|
2587 | + */ |
|
2588 | + public function log_file_name($reset = false) |
|
2589 | + { |
|
2590 | + if (empty($this->log_file_name) || $reset) { |
|
2591 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2592 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2593 | + } |
|
2594 | + return $this->log_file_name; |
|
2595 | + } |
|
2596 | + |
|
2597 | + |
|
2598 | + |
|
2599 | + /** |
|
2600 | + * @param bool $reset |
|
2601 | + * @return string |
|
2602 | + */ |
|
2603 | + public function debug_file_name($reset = false) |
|
2604 | + { |
|
2605 | + if (empty($this->debug_file_name) || $reset) { |
|
2606 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2607 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2608 | + } |
|
2609 | + return $this->debug_file_name; |
|
2610 | + } |
|
2611 | + |
|
2612 | + |
|
2613 | + |
|
2614 | + /** |
|
2615 | + * @return string |
|
2616 | + */ |
|
2617 | + public function affiliate_id() |
|
2618 | + { |
|
2619 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2620 | + } |
|
2621 | + |
|
2622 | + |
|
2623 | + |
|
2624 | + /** |
|
2625 | + * @return boolean |
|
2626 | + */ |
|
2627 | + public function encode_session_data() |
|
2628 | + { |
|
2629 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2630 | + } |
|
2631 | + |
|
2632 | + |
|
2633 | + |
|
2634 | + /** |
|
2635 | + * @param boolean $encode_session_data |
|
2636 | + */ |
|
2637 | + public function set_encode_session_data($encode_session_data) |
|
2638 | + { |
|
2639 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2640 | + } |
|
2641 | 2641 | |
2642 | 2642 | |
2643 | 2643 | |
@@ -2651,71 +2651,71 @@ discard block |
||
2651 | 2651 | class EE_Template_Config extends EE_Config_Base |
2652 | 2652 | { |
2653 | 2653 | |
2654 | - /** |
|
2655 | - * @var boolean $enable_default_style |
|
2656 | - */ |
|
2657 | - public $enable_default_style; |
|
2658 | - |
|
2659 | - /** |
|
2660 | - * @var string $custom_style_sheet |
|
2661 | - */ |
|
2662 | - public $custom_style_sheet; |
|
2663 | - |
|
2664 | - /** |
|
2665 | - * @var boolean $display_address_in_regform |
|
2666 | - */ |
|
2667 | - public $display_address_in_regform; |
|
2668 | - |
|
2669 | - /** |
|
2670 | - * @var int $display_description_on_multi_reg_page |
|
2671 | - */ |
|
2672 | - public $display_description_on_multi_reg_page; |
|
2673 | - |
|
2674 | - /** |
|
2675 | - * @var boolean $use_custom_templates |
|
2676 | - */ |
|
2677 | - public $use_custom_templates; |
|
2678 | - |
|
2679 | - /** |
|
2680 | - * @var string $current_espresso_theme |
|
2681 | - */ |
|
2682 | - public $current_espresso_theme; |
|
2683 | - |
|
2684 | - /** |
|
2685 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2686 | - */ |
|
2687 | - public $EED_Ticket_Selector; |
|
2688 | - |
|
2689 | - /** |
|
2690 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
2691 | - */ |
|
2692 | - public $EED_Event_Single; |
|
2693 | - |
|
2694 | - /** |
|
2695 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2696 | - */ |
|
2697 | - public $EED_Events_Archive; |
|
2698 | - |
|
2699 | - |
|
2700 | - |
|
2701 | - /** |
|
2702 | - * class constructor |
|
2703 | - * |
|
2704 | - * @access public |
|
2705 | - */ |
|
2706 | - public function __construct() |
|
2707 | - { |
|
2708 | - // set default template settings |
|
2709 | - $this->enable_default_style = true; |
|
2710 | - $this->custom_style_sheet = null; |
|
2711 | - $this->display_address_in_regform = true; |
|
2712 | - $this->display_description_on_multi_reg_page = false; |
|
2713 | - $this->use_custom_templates = false; |
|
2714 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2715 | - $this->EED_Event_Single = null; |
|
2716 | - $this->EED_Events_Archive = null; |
|
2717 | - $this->EED_Ticket_Selector = null; |
|
2718 | - } |
|
2654 | + /** |
|
2655 | + * @var boolean $enable_default_style |
|
2656 | + */ |
|
2657 | + public $enable_default_style; |
|
2658 | + |
|
2659 | + /** |
|
2660 | + * @var string $custom_style_sheet |
|
2661 | + */ |
|
2662 | + public $custom_style_sheet; |
|
2663 | + |
|
2664 | + /** |
|
2665 | + * @var boolean $display_address_in_regform |
|
2666 | + */ |
|
2667 | + public $display_address_in_regform; |
|
2668 | + |
|
2669 | + /** |
|
2670 | + * @var int $display_description_on_multi_reg_page |
|
2671 | + */ |
|
2672 | + public $display_description_on_multi_reg_page; |
|
2673 | + |
|
2674 | + /** |
|
2675 | + * @var boolean $use_custom_templates |
|
2676 | + */ |
|
2677 | + public $use_custom_templates; |
|
2678 | + |
|
2679 | + /** |
|
2680 | + * @var string $current_espresso_theme |
|
2681 | + */ |
|
2682 | + public $current_espresso_theme; |
|
2683 | + |
|
2684 | + /** |
|
2685 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2686 | + */ |
|
2687 | + public $EED_Ticket_Selector; |
|
2688 | + |
|
2689 | + /** |
|
2690 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
2691 | + */ |
|
2692 | + public $EED_Event_Single; |
|
2693 | + |
|
2694 | + /** |
|
2695 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2696 | + */ |
|
2697 | + public $EED_Events_Archive; |
|
2698 | + |
|
2699 | + |
|
2700 | + |
|
2701 | + /** |
|
2702 | + * class constructor |
|
2703 | + * |
|
2704 | + * @access public |
|
2705 | + */ |
|
2706 | + public function __construct() |
|
2707 | + { |
|
2708 | + // set default template settings |
|
2709 | + $this->enable_default_style = true; |
|
2710 | + $this->custom_style_sheet = null; |
|
2711 | + $this->display_address_in_regform = true; |
|
2712 | + $this->display_description_on_multi_reg_page = false; |
|
2713 | + $this->use_custom_templates = false; |
|
2714 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2715 | + $this->EED_Event_Single = null; |
|
2716 | + $this->EED_Events_Archive = null; |
|
2717 | + $this->EED_Ticket_Selector = null; |
|
2718 | + } |
|
2719 | 2719 | |
2720 | 2720 | } |
2721 | 2721 | |
@@ -2727,115 +2727,115 @@ discard block |
||
2727 | 2727 | class EE_Map_Config extends EE_Config_Base |
2728 | 2728 | { |
2729 | 2729 | |
2730 | - /** |
|
2731 | - * @var boolean $use_google_maps |
|
2732 | - */ |
|
2733 | - public $use_google_maps; |
|
2734 | - |
|
2735 | - /** |
|
2736 | - * @var string $api_key |
|
2737 | - */ |
|
2738 | - public $google_map_api_key; |
|
2739 | - |
|
2740 | - /** |
|
2741 | - * @var int $event_details_map_width |
|
2742 | - */ |
|
2743 | - public $event_details_map_width; |
|
2744 | - |
|
2745 | - /** |
|
2746 | - * @var int $event_details_map_height |
|
2747 | - */ |
|
2748 | - public $event_details_map_height; |
|
2749 | - |
|
2750 | - /** |
|
2751 | - * @var int $event_details_map_zoom |
|
2752 | - */ |
|
2753 | - public $event_details_map_zoom; |
|
2754 | - |
|
2755 | - /** |
|
2756 | - * @var boolean $event_details_display_nav |
|
2757 | - */ |
|
2758 | - public $event_details_display_nav; |
|
2759 | - |
|
2760 | - /** |
|
2761 | - * @var boolean $event_details_nav_size |
|
2762 | - */ |
|
2763 | - public $event_details_nav_size; |
|
2764 | - |
|
2765 | - /** |
|
2766 | - * @var string $event_details_control_type |
|
2767 | - */ |
|
2768 | - public $event_details_control_type; |
|
2769 | - |
|
2770 | - /** |
|
2771 | - * @var string $event_details_map_align |
|
2772 | - */ |
|
2773 | - public $event_details_map_align; |
|
2774 | - |
|
2775 | - /** |
|
2776 | - * @var int $event_list_map_width |
|
2777 | - */ |
|
2778 | - public $event_list_map_width; |
|
2779 | - |
|
2780 | - /** |
|
2781 | - * @var int $event_list_map_height |
|
2782 | - */ |
|
2783 | - public $event_list_map_height; |
|
2784 | - |
|
2785 | - /** |
|
2786 | - * @var int $event_list_map_zoom |
|
2787 | - */ |
|
2788 | - public $event_list_map_zoom; |
|
2789 | - |
|
2790 | - /** |
|
2791 | - * @var boolean $event_list_display_nav |
|
2792 | - */ |
|
2793 | - public $event_list_display_nav; |
|
2794 | - |
|
2795 | - /** |
|
2796 | - * @var boolean $event_list_nav_size |
|
2797 | - */ |
|
2798 | - public $event_list_nav_size; |
|
2799 | - |
|
2800 | - /** |
|
2801 | - * @var string $event_list_control_type |
|
2802 | - */ |
|
2803 | - public $event_list_control_type; |
|
2804 | - |
|
2805 | - /** |
|
2806 | - * @var string $event_list_map_align |
|
2807 | - */ |
|
2808 | - public $event_list_map_align; |
|
2809 | - |
|
2810 | - |
|
2811 | - |
|
2812 | - /** |
|
2813 | - * class constructor |
|
2814 | - * |
|
2815 | - * @access public |
|
2816 | - */ |
|
2817 | - public function __construct() |
|
2818 | - { |
|
2819 | - // set default map settings |
|
2820 | - $this->use_google_maps = true; |
|
2821 | - $this->google_map_api_key = ''; |
|
2822 | - // for event details pages (reg page) |
|
2823 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
2824 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
2825 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2826 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2827 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2828 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2829 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2830 | - // for event list pages |
|
2831 | - $this->event_list_map_width = 300; // ee_map_width |
|
2832 | - $this->event_list_map_height = 185; // ee_map_height |
|
2833 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2834 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
2835 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
2836 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2837 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
2838 | - } |
|
2730 | + /** |
|
2731 | + * @var boolean $use_google_maps |
|
2732 | + */ |
|
2733 | + public $use_google_maps; |
|
2734 | + |
|
2735 | + /** |
|
2736 | + * @var string $api_key |
|
2737 | + */ |
|
2738 | + public $google_map_api_key; |
|
2739 | + |
|
2740 | + /** |
|
2741 | + * @var int $event_details_map_width |
|
2742 | + */ |
|
2743 | + public $event_details_map_width; |
|
2744 | + |
|
2745 | + /** |
|
2746 | + * @var int $event_details_map_height |
|
2747 | + */ |
|
2748 | + public $event_details_map_height; |
|
2749 | + |
|
2750 | + /** |
|
2751 | + * @var int $event_details_map_zoom |
|
2752 | + */ |
|
2753 | + public $event_details_map_zoom; |
|
2754 | + |
|
2755 | + /** |
|
2756 | + * @var boolean $event_details_display_nav |
|
2757 | + */ |
|
2758 | + public $event_details_display_nav; |
|
2759 | + |
|
2760 | + /** |
|
2761 | + * @var boolean $event_details_nav_size |
|
2762 | + */ |
|
2763 | + public $event_details_nav_size; |
|
2764 | + |
|
2765 | + /** |
|
2766 | + * @var string $event_details_control_type |
|
2767 | + */ |
|
2768 | + public $event_details_control_type; |
|
2769 | + |
|
2770 | + /** |
|
2771 | + * @var string $event_details_map_align |
|
2772 | + */ |
|
2773 | + public $event_details_map_align; |
|
2774 | + |
|
2775 | + /** |
|
2776 | + * @var int $event_list_map_width |
|
2777 | + */ |
|
2778 | + public $event_list_map_width; |
|
2779 | + |
|
2780 | + /** |
|
2781 | + * @var int $event_list_map_height |
|
2782 | + */ |
|
2783 | + public $event_list_map_height; |
|
2784 | + |
|
2785 | + /** |
|
2786 | + * @var int $event_list_map_zoom |
|
2787 | + */ |
|
2788 | + public $event_list_map_zoom; |
|
2789 | + |
|
2790 | + /** |
|
2791 | + * @var boolean $event_list_display_nav |
|
2792 | + */ |
|
2793 | + public $event_list_display_nav; |
|
2794 | + |
|
2795 | + /** |
|
2796 | + * @var boolean $event_list_nav_size |
|
2797 | + */ |
|
2798 | + public $event_list_nav_size; |
|
2799 | + |
|
2800 | + /** |
|
2801 | + * @var string $event_list_control_type |
|
2802 | + */ |
|
2803 | + public $event_list_control_type; |
|
2804 | + |
|
2805 | + /** |
|
2806 | + * @var string $event_list_map_align |
|
2807 | + */ |
|
2808 | + public $event_list_map_align; |
|
2809 | + |
|
2810 | + |
|
2811 | + |
|
2812 | + /** |
|
2813 | + * class constructor |
|
2814 | + * |
|
2815 | + * @access public |
|
2816 | + */ |
|
2817 | + public function __construct() |
|
2818 | + { |
|
2819 | + // set default map settings |
|
2820 | + $this->use_google_maps = true; |
|
2821 | + $this->google_map_api_key = ''; |
|
2822 | + // for event details pages (reg page) |
|
2823 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
2824 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
2825 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2826 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2827 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2828 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2829 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2830 | + // for event list pages |
|
2831 | + $this->event_list_map_width = 300; // ee_map_width |
|
2832 | + $this->event_list_map_height = 185; // ee_map_height |
|
2833 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2834 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
2835 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
2836 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2837 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
2838 | + } |
|
2839 | 2839 | |
2840 | 2840 | } |
2841 | 2841 | |
@@ -2847,47 +2847,47 @@ discard block |
||
2847 | 2847 | class EE_Events_Archive_Config extends EE_Config_Base |
2848 | 2848 | { |
2849 | 2849 | |
2850 | - public $display_status_banner; |
|
2850 | + public $display_status_banner; |
|
2851 | 2851 | |
2852 | - public $display_description; |
|
2852 | + public $display_description; |
|
2853 | 2853 | |
2854 | - public $display_ticket_selector; |
|
2854 | + public $display_ticket_selector; |
|
2855 | 2855 | |
2856 | - public $display_datetimes; |
|
2856 | + public $display_datetimes; |
|
2857 | 2857 | |
2858 | - public $display_venue; |
|
2858 | + public $display_venue; |
|
2859 | 2859 | |
2860 | - public $display_expired_events; |
|
2860 | + public $display_expired_events; |
|
2861 | 2861 | |
2862 | - public $use_sortable_display_order; |
|
2862 | + public $use_sortable_display_order; |
|
2863 | 2863 | |
2864 | - public $display_order_tickets; |
|
2864 | + public $display_order_tickets; |
|
2865 | 2865 | |
2866 | - public $display_order_datetimes; |
|
2866 | + public $display_order_datetimes; |
|
2867 | 2867 | |
2868 | - public $display_order_event; |
|
2868 | + public $display_order_event; |
|
2869 | 2869 | |
2870 | - public $display_order_venue; |
|
2870 | + public $display_order_venue; |
|
2871 | 2871 | |
2872 | 2872 | |
2873 | 2873 | |
2874 | - /** |
|
2875 | - * class constructor |
|
2876 | - */ |
|
2877 | - public function __construct() |
|
2878 | - { |
|
2879 | - $this->display_status_banner = 0; |
|
2880 | - $this->display_description = 1; |
|
2881 | - $this->display_ticket_selector = 0; |
|
2882 | - $this->display_datetimes = 1; |
|
2883 | - $this->display_venue = 0; |
|
2884 | - $this->display_expired_events = 0; |
|
2885 | - $this->use_sortable_display_order = false; |
|
2886 | - $this->display_order_tickets = 100; |
|
2887 | - $this->display_order_datetimes = 110; |
|
2888 | - $this->display_order_event = 120; |
|
2889 | - $this->display_order_venue = 130; |
|
2890 | - } |
|
2874 | + /** |
|
2875 | + * class constructor |
|
2876 | + */ |
|
2877 | + public function __construct() |
|
2878 | + { |
|
2879 | + $this->display_status_banner = 0; |
|
2880 | + $this->display_description = 1; |
|
2881 | + $this->display_ticket_selector = 0; |
|
2882 | + $this->display_datetimes = 1; |
|
2883 | + $this->display_venue = 0; |
|
2884 | + $this->display_expired_events = 0; |
|
2885 | + $this->use_sortable_display_order = false; |
|
2886 | + $this->display_order_tickets = 100; |
|
2887 | + $this->display_order_datetimes = 110; |
|
2888 | + $this->display_order_event = 120; |
|
2889 | + $this->display_order_venue = 130; |
|
2890 | + } |
|
2891 | 2891 | } |
2892 | 2892 | |
2893 | 2893 | |
@@ -2898,35 +2898,35 @@ discard block |
||
2898 | 2898 | class EE_Event_Single_Config extends EE_Config_Base |
2899 | 2899 | { |
2900 | 2900 | |
2901 | - public $display_status_banner_single; |
|
2901 | + public $display_status_banner_single; |
|
2902 | 2902 | |
2903 | - public $display_venue; |
|
2903 | + public $display_venue; |
|
2904 | 2904 | |
2905 | - public $use_sortable_display_order; |
|
2905 | + public $use_sortable_display_order; |
|
2906 | 2906 | |
2907 | - public $display_order_tickets; |
|
2907 | + public $display_order_tickets; |
|
2908 | 2908 | |
2909 | - public $display_order_datetimes; |
|
2909 | + public $display_order_datetimes; |
|
2910 | 2910 | |
2911 | - public $display_order_event; |
|
2911 | + public $display_order_event; |
|
2912 | 2912 | |
2913 | - public $display_order_venue; |
|
2913 | + public $display_order_venue; |
|
2914 | 2914 | |
2915 | 2915 | |
2916 | 2916 | |
2917 | - /** |
|
2918 | - * class constructor |
|
2919 | - */ |
|
2920 | - public function __construct() |
|
2921 | - { |
|
2922 | - $this->display_status_banner_single = 0; |
|
2923 | - $this->display_venue = 1; |
|
2924 | - $this->use_sortable_display_order = false; |
|
2925 | - $this->display_order_tickets = 100; |
|
2926 | - $this->display_order_datetimes = 110; |
|
2927 | - $this->display_order_event = 120; |
|
2928 | - $this->display_order_venue = 130; |
|
2929 | - } |
|
2917 | + /** |
|
2918 | + * class constructor |
|
2919 | + */ |
|
2920 | + public function __construct() |
|
2921 | + { |
|
2922 | + $this->display_status_banner_single = 0; |
|
2923 | + $this->display_venue = 1; |
|
2924 | + $this->use_sortable_display_order = false; |
|
2925 | + $this->display_order_tickets = 100; |
|
2926 | + $this->display_order_datetimes = 110; |
|
2927 | + $this->display_order_event = 120; |
|
2928 | + $this->display_order_venue = 130; |
|
2929 | + } |
|
2930 | 2930 | } |
2931 | 2931 | |
2932 | 2932 | |
@@ -2937,152 +2937,152 @@ discard block |
||
2937 | 2937 | class EE_Ticket_Selector_Config extends EE_Config_Base |
2938 | 2938 | { |
2939 | 2939 | |
2940 | - /** |
|
2941 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2942 | - */ |
|
2943 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2944 | - |
|
2945 | - /** |
|
2946 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2947 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2948 | - */ |
|
2949 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2950 | - |
|
2951 | - /** |
|
2952 | - * @var boolean $show_ticket_sale_columns |
|
2953 | - */ |
|
2954 | - public $show_ticket_sale_columns; |
|
2955 | - |
|
2956 | - /** |
|
2957 | - * @var boolean $show_ticket_details |
|
2958 | - */ |
|
2959 | - public $show_ticket_details; |
|
2960 | - |
|
2961 | - /** |
|
2962 | - * @var boolean $show_expired_tickets |
|
2963 | - */ |
|
2964 | - public $show_expired_tickets; |
|
2965 | - |
|
2966 | - /** |
|
2967 | - * whether or not to display a dropdown box populated with event datetimes |
|
2968 | - * that toggles which tickets are displayed for a ticket selector. |
|
2969 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2970 | - * |
|
2971 | - * @var string $show_datetime_selector |
|
2972 | - */ |
|
2973 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
2974 | - |
|
2975 | - /** |
|
2976 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2977 | - * |
|
2978 | - * @var int $datetime_selector_threshold |
|
2979 | - */ |
|
2980 | - private $datetime_selector_threshold = 3; |
|
2981 | - |
|
2982 | - |
|
2983 | - |
|
2984 | - /** |
|
2985 | - * class constructor |
|
2986 | - */ |
|
2987 | - public function __construct() |
|
2988 | - { |
|
2989 | - $this->show_ticket_sale_columns = true; |
|
2990 | - $this->show_ticket_details = true; |
|
2991 | - $this->show_expired_tickets = true; |
|
2992 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2993 | - $this->datetime_selector_threshold = 3; |
|
2994 | - } |
|
2995 | - |
|
2996 | - |
|
2997 | - |
|
2998 | - /** |
|
2999 | - * returns true if a datetime selector should be displayed |
|
3000 | - * |
|
3001 | - * @param array $datetimes |
|
3002 | - * @return bool |
|
3003 | - */ |
|
3004 | - public function showDatetimeSelector(array $datetimes) |
|
3005 | - { |
|
3006 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
3007 | - return ! ( |
|
3008 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
3009 | - || ( |
|
3010 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
3011 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
3012 | - ) |
|
3013 | - ); |
|
3014 | - } |
|
3015 | - |
|
3016 | - |
|
3017 | - |
|
3018 | - /** |
|
3019 | - * @return string |
|
3020 | - */ |
|
3021 | - public function getShowDatetimeSelector() |
|
3022 | - { |
|
3023 | - return $this->show_datetime_selector; |
|
3024 | - } |
|
3025 | - |
|
3026 | - |
|
3027 | - |
|
3028 | - /** |
|
3029 | - * @param bool $keys_only |
|
3030 | - * @return array |
|
3031 | - */ |
|
3032 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3033 | - { |
|
3034 | - return $keys_only |
|
3035 | - ? array( |
|
3036 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3037 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3038 | - ) |
|
3039 | - : array( |
|
3040 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3041 | - 'Do not show date & time filter', 'event_espresso' |
|
3042 | - ), |
|
3043 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3044 | - 'Maybe show date & time filter', 'event_espresso' |
|
3045 | - ), |
|
3046 | - ); |
|
3047 | - } |
|
3048 | - |
|
3049 | - |
|
3050 | - |
|
3051 | - /** |
|
3052 | - * @param string $show_datetime_selector |
|
3053 | - */ |
|
3054 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
3055 | - { |
|
3056 | - $this->show_datetime_selector = in_array( |
|
3057 | - $show_datetime_selector, |
|
3058 | - $this->getShowDatetimeSelectorOptions(), |
|
3059 | - true |
|
3060 | - ) |
|
3061 | - ? $show_datetime_selector |
|
3062 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3063 | - } |
|
3064 | - |
|
3065 | - |
|
3066 | - |
|
3067 | - /** |
|
3068 | - * @return int |
|
3069 | - */ |
|
3070 | - public function getDatetimeSelectorThreshold() |
|
3071 | - { |
|
3072 | - return $this->datetime_selector_threshold; |
|
3073 | - } |
|
3074 | - |
|
3075 | - |
|
3076 | - |
|
3077 | - |
|
3078 | - /** |
|
3079 | - * @param int $datetime_selector_threshold |
|
3080 | - */ |
|
3081 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3082 | - { |
|
3083 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3084 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3085 | - } |
|
2940 | + /** |
|
2941 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2942 | + */ |
|
2943 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2944 | + |
|
2945 | + /** |
|
2946 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2947 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2948 | + */ |
|
2949 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2950 | + |
|
2951 | + /** |
|
2952 | + * @var boolean $show_ticket_sale_columns |
|
2953 | + */ |
|
2954 | + public $show_ticket_sale_columns; |
|
2955 | + |
|
2956 | + /** |
|
2957 | + * @var boolean $show_ticket_details |
|
2958 | + */ |
|
2959 | + public $show_ticket_details; |
|
2960 | + |
|
2961 | + /** |
|
2962 | + * @var boolean $show_expired_tickets |
|
2963 | + */ |
|
2964 | + public $show_expired_tickets; |
|
2965 | + |
|
2966 | + /** |
|
2967 | + * whether or not to display a dropdown box populated with event datetimes |
|
2968 | + * that toggles which tickets are displayed for a ticket selector. |
|
2969 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2970 | + * |
|
2971 | + * @var string $show_datetime_selector |
|
2972 | + */ |
|
2973 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
2974 | + |
|
2975 | + /** |
|
2976 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2977 | + * |
|
2978 | + * @var int $datetime_selector_threshold |
|
2979 | + */ |
|
2980 | + private $datetime_selector_threshold = 3; |
|
2981 | + |
|
2982 | + |
|
2983 | + |
|
2984 | + /** |
|
2985 | + * class constructor |
|
2986 | + */ |
|
2987 | + public function __construct() |
|
2988 | + { |
|
2989 | + $this->show_ticket_sale_columns = true; |
|
2990 | + $this->show_ticket_details = true; |
|
2991 | + $this->show_expired_tickets = true; |
|
2992 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2993 | + $this->datetime_selector_threshold = 3; |
|
2994 | + } |
|
2995 | + |
|
2996 | + |
|
2997 | + |
|
2998 | + /** |
|
2999 | + * returns true if a datetime selector should be displayed |
|
3000 | + * |
|
3001 | + * @param array $datetimes |
|
3002 | + * @return bool |
|
3003 | + */ |
|
3004 | + public function showDatetimeSelector(array $datetimes) |
|
3005 | + { |
|
3006 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
3007 | + return ! ( |
|
3008 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
3009 | + || ( |
|
3010 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
3011 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
3012 | + ) |
|
3013 | + ); |
|
3014 | + } |
|
3015 | + |
|
3016 | + |
|
3017 | + |
|
3018 | + /** |
|
3019 | + * @return string |
|
3020 | + */ |
|
3021 | + public function getShowDatetimeSelector() |
|
3022 | + { |
|
3023 | + return $this->show_datetime_selector; |
|
3024 | + } |
|
3025 | + |
|
3026 | + |
|
3027 | + |
|
3028 | + /** |
|
3029 | + * @param bool $keys_only |
|
3030 | + * @return array |
|
3031 | + */ |
|
3032 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3033 | + { |
|
3034 | + return $keys_only |
|
3035 | + ? array( |
|
3036 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3037 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3038 | + ) |
|
3039 | + : array( |
|
3040 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3041 | + 'Do not show date & time filter', 'event_espresso' |
|
3042 | + ), |
|
3043 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3044 | + 'Maybe show date & time filter', 'event_espresso' |
|
3045 | + ), |
|
3046 | + ); |
|
3047 | + } |
|
3048 | + |
|
3049 | + |
|
3050 | + |
|
3051 | + /** |
|
3052 | + * @param string $show_datetime_selector |
|
3053 | + */ |
|
3054 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
3055 | + { |
|
3056 | + $this->show_datetime_selector = in_array( |
|
3057 | + $show_datetime_selector, |
|
3058 | + $this->getShowDatetimeSelectorOptions(), |
|
3059 | + true |
|
3060 | + ) |
|
3061 | + ? $show_datetime_selector |
|
3062 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3063 | + } |
|
3064 | + |
|
3065 | + |
|
3066 | + |
|
3067 | + /** |
|
3068 | + * @return int |
|
3069 | + */ |
|
3070 | + public function getDatetimeSelectorThreshold() |
|
3071 | + { |
|
3072 | + return $this->datetime_selector_threshold; |
|
3073 | + } |
|
3074 | + |
|
3075 | + |
|
3076 | + |
|
3077 | + |
|
3078 | + /** |
|
3079 | + * @param int $datetime_selector_threshold |
|
3080 | + */ |
|
3081 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3082 | + { |
|
3083 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3084 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3085 | + } |
|
3086 | 3086 | |
3087 | 3087 | |
3088 | 3088 | |
@@ -3100,85 +3100,85 @@ discard block |
||
3100 | 3100 | class EE_Environment_Config extends EE_Config_Base |
3101 | 3101 | { |
3102 | 3102 | |
3103 | - /** |
|
3104 | - * Hold any php environment variables that we want to track. |
|
3105 | - * |
|
3106 | - * @var stdClass; |
|
3107 | - */ |
|
3108 | - public $php; |
|
3109 | - |
|
3110 | - |
|
3111 | - |
|
3112 | - /** |
|
3113 | - * constructor |
|
3114 | - */ |
|
3115 | - public function __construct() |
|
3116 | - { |
|
3117 | - $this->php = new stdClass(); |
|
3118 | - $this->_set_php_values(); |
|
3119 | - } |
|
3120 | - |
|
3121 | - |
|
3122 | - |
|
3123 | - /** |
|
3124 | - * This sets the php environment variables. |
|
3125 | - * |
|
3126 | - * @since 4.4.0 |
|
3127 | - * @return void |
|
3128 | - */ |
|
3129 | - protected function _set_php_values() |
|
3130 | - { |
|
3131 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3132 | - $this->php->version = phpversion(); |
|
3133 | - } |
|
3134 | - |
|
3135 | - |
|
3136 | - |
|
3137 | - /** |
|
3138 | - * helper method for determining whether input_count is |
|
3139 | - * reaching the potential maximum the server can handle |
|
3140 | - * according to max_input_vars |
|
3141 | - * |
|
3142 | - * @param int $input_count the count of input vars. |
|
3143 | - * @return array { |
|
3144 | - * An array that represents whether available space and if no available space the error |
|
3145 | - * message. |
|
3146 | - * @type bool $has_space whether more inputs can be added. |
|
3147 | - * @type string $msg Any message to be displayed. |
|
3148 | - * } |
|
3149 | - */ |
|
3150 | - public function max_input_vars_limit_check($input_count = 0) |
|
3151 | - { |
|
3152 | - if (! empty($this->php->max_input_vars) |
|
3153 | - && ($input_count >= $this->php->max_input_vars) |
|
3154 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3155 | - ) { |
|
3156 | - return sprintf( |
|
3157 | - __( |
|
3158 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3159 | - 'event_espresso' |
|
3160 | - ), |
|
3161 | - '<br>', |
|
3162 | - $input_count, |
|
3163 | - $this->php->max_input_vars |
|
3164 | - ); |
|
3165 | - } else { |
|
3166 | - return ''; |
|
3167 | - } |
|
3168 | - } |
|
3169 | - |
|
3170 | - |
|
3171 | - |
|
3172 | - /** |
|
3173 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3174 | - * |
|
3175 | - * @since 4.4.1 |
|
3176 | - * @return void |
|
3177 | - */ |
|
3178 | - public function recheck_values() |
|
3179 | - { |
|
3180 | - $this->_set_php_values(); |
|
3181 | - } |
|
3103 | + /** |
|
3104 | + * Hold any php environment variables that we want to track. |
|
3105 | + * |
|
3106 | + * @var stdClass; |
|
3107 | + */ |
|
3108 | + public $php; |
|
3109 | + |
|
3110 | + |
|
3111 | + |
|
3112 | + /** |
|
3113 | + * constructor |
|
3114 | + */ |
|
3115 | + public function __construct() |
|
3116 | + { |
|
3117 | + $this->php = new stdClass(); |
|
3118 | + $this->_set_php_values(); |
|
3119 | + } |
|
3120 | + |
|
3121 | + |
|
3122 | + |
|
3123 | + /** |
|
3124 | + * This sets the php environment variables. |
|
3125 | + * |
|
3126 | + * @since 4.4.0 |
|
3127 | + * @return void |
|
3128 | + */ |
|
3129 | + protected function _set_php_values() |
|
3130 | + { |
|
3131 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3132 | + $this->php->version = phpversion(); |
|
3133 | + } |
|
3134 | + |
|
3135 | + |
|
3136 | + |
|
3137 | + /** |
|
3138 | + * helper method for determining whether input_count is |
|
3139 | + * reaching the potential maximum the server can handle |
|
3140 | + * according to max_input_vars |
|
3141 | + * |
|
3142 | + * @param int $input_count the count of input vars. |
|
3143 | + * @return array { |
|
3144 | + * An array that represents whether available space and if no available space the error |
|
3145 | + * message. |
|
3146 | + * @type bool $has_space whether more inputs can be added. |
|
3147 | + * @type string $msg Any message to be displayed. |
|
3148 | + * } |
|
3149 | + */ |
|
3150 | + public function max_input_vars_limit_check($input_count = 0) |
|
3151 | + { |
|
3152 | + if (! empty($this->php->max_input_vars) |
|
3153 | + && ($input_count >= $this->php->max_input_vars) |
|
3154 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3155 | + ) { |
|
3156 | + return sprintf( |
|
3157 | + __( |
|
3158 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3159 | + 'event_espresso' |
|
3160 | + ), |
|
3161 | + '<br>', |
|
3162 | + $input_count, |
|
3163 | + $this->php->max_input_vars |
|
3164 | + ); |
|
3165 | + } else { |
|
3166 | + return ''; |
|
3167 | + } |
|
3168 | + } |
|
3169 | + |
|
3170 | + |
|
3171 | + |
|
3172 | + /** |
|
3173 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3174 | + * |
|
3175 | + * @since 4.4.1 |
|
3176 | + * @return void |
|
3177 | + */ |
|
3178 | + public function recheck_values() |
|
3179 | + { |
|
3180 | + $this->_set_php_values(); |
|
3181 | + } |
|
3182 | 3182 | |
3183 | 3183 | |
3184 | 3184 | |
@@ -3196,22 +3196,22 @@ discard block |
||
3196 | 3196 | class EE_Tax_Config extends EE_Config_Base |
3197 | 3197 | { |
3198 | 3198 | |
3199 | - /* |
|
3199 | + /* |
|
3200 | 3200 | * flag to indicate whether or not to display ticket prices with the taxes included |
3201 | 3201 | * |
3202 | 3202 | * @var boolean $prices_displayed_including_taxes |
3203 | 3203 | */ |
3204 | - public $prices_displayed_including_taxes; |
|
3204 | + public $prices_displayed_including_taxes; |
|
3205 | 3205 | |
3206 | 3206 | |
3207 | 3207 | |
3208 | - /** |
|
3209 | - * class constructor |
|
3210 | - */ |
|
3211 | - public function __construct() |
|
3212 | - { |
|
3213 | - $this->prices_displayed_including_taxes = true; |
|
3214 | - } |
|
3208 | + /** |
|
3209 | + * class constructor |
|
3210 | + */ |
|
3211 | + public function __construct() |
|
3212 | + { |
|
3213 | + $this->prices_displayed_including_taxes = true; |
|
3214 | + } |
|
3215 | 3215 | } |
3216 | 3216 | |
3217 | 3217 | |
@@ -3226,17 +3226,17 @@ discard block |
||
3226 | 3226 | class EE_Messages_Config extends EE_Config_Base |
3227 | 3227 | { |
3228 | 3228 | |
3229 | - /** |
|
3230 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3231 | - * A value of 0 represents never deleting. Default is 0. |
|
3232 | - * |
|
3233 | - * @var integer |
|
3234 | - */ |
|
3235 | - public $delete_threshold; |
|
3236 | - |
|
3237 | - public function __construct() { |
|
3238 | - $this->delete_threshold = 0; |
|
3239 | - } |
|
3229 | + /** |
|
3230 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3231 | + * A value of 0 represents never deleting. Default is 0. |
|
3232 | + * |
|
3233 | + * @var integer |
|
3234 | + */ |
|
3235 | + public $delete_threshold; |
|
3236 | + |
|
3237 | + public function __construct() { |
|
3238 | + $this->delete_threshold = 0; |
|
3239 | + } |
|
3240 | 3240 | } |
3241 | 3241 | |
3242 | 3242 | |
@@ -3248,34 +3248,34 @@ discard block |
||
3248 | 3248 | class EE_Gateway_Config extends EE_Config_Base |
3249 | 3249 | { |
3250 | 3250 | |
3251 | - /** |
|
3252 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
3253 | - * with any config info the gateway wants to store |
|
3254 | - * |
|
3255 | - * @var array |
|
3256 | - */ |
|
3257 | - public $payment_settings; |
|
3258 | - |
|
3259 | - /** |
|
3260 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3261 | - * the gateway is stored in the uploads directory |
|
3262 | - * |
|
3263 | - * @var array |
|
3264 | - */ |
|
3265 | - public $active_gateways; |
|
3266 | - |
|
3267 | - |
|
3268 | - |
|
3269 | - /** |
|
3270 | - * class constructor |
|
3271 | - * |
|
3272 | - * @deprecated |
|
3273 | - */ |
|
3274 | - public function __construct() |
|
3275 | - { |
|
3276 | - $this->payment_settings = array(); |
|
3277 | - $this->active_gateways = array('Invoice' => false); |
|
3278 | - } |
|
3251 | + /** |
|
3252 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
3253 | + * with any config info the gateway wants to store |
|
3254 | + * |
|
3255 | + * @var array |
|
3256 | + */ |
|
3257 | + public $payment_settings; |
|
3258 | + |
|
3259 | + /** |
|
3260 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3261 | + * the gateway is stored in the uploads directory |
|
3262 | + * |
|
3263 | + * @var array |
|
3264 | + */ |
|
3265 | + public $active_gateways; |
|
3266 | + |
|
3267 | + |
|
3268 | + |
|
3269 | + /** |
|
3270 | + * class constructor |
|
3271 | + * |
|
3272 | + * @deprecated |
|
3273 | + */ |
|
3274 | + public function __construct() |
|
3275 | + { |
|
3276 | + $this->payment_settings = array(); |
|
3277 | + $this->active_gateways = array('Invoice' => false); |
|
3278 | + } |
|
3279 | 3279 | } |
3280 | 3280 | |
3281 | 3281 | // End of file EE_Config.core.php |