@@ -15,223 +15,223 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Attendee_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - /** |
|
19 | - * hold all extra data. |
|
20 | - * |
|
21 | - * @var array|stdClass|null |
|
22 | - */ |
|
23 | - protected $_extra; |
|
24 | - |
|
25 | - |
|
26 | - protected function _init_props() |
|
27 | - { |
|
28 | - $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
29 | - $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
30 | - $this->_shortcodes = [ |
|
31 | - '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
32 | - '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
33 | - '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
34 | - '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
35 | - 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - '[REGISTRATION_ID]' => esc_html__( |
|
39 | - 'Unique Registration ID for the registration', |
|
40 | - 'event_espresso' |
|
41 | - ), |
|
42 | - '[REGISTRATION_CODE]' => esc_html__( |
|
43 | - 'Unique Registration Code for the registration', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
47 | - 'Parses to the registration status for the attendee', |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
51 | - 'Parses to the status label for the registrant', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
55 | - 'Parses to the total amount paid for this registration.', |
|
56 | - 'event_espresso' |
|
57 | - ), |
|
58 | - '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
59 | - 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
60 | - 'event_espresso' |
|
61 | - ), |
|
62 | - '[PHONE_NUMBER]' => esc_html__( |
|
63 | - 'The Phone Number for the Registration.', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
67 | - '[ADDRESS2]' => esc_html__( |
|
68 | - 'Whatever was in the address 2 field for the registration.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
72 | - '[ZIP_PC]' => esc_html__( |
|
73 | - 'The ZIP (or Postal) Code for the Registration.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - '[ADDRESS_STATE]' => esc_html__( |
|
77 | - 'The state/province for the registration.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
81 | - ]; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * handles shortcode parsing |
|
87 | - * |
|
88 | - * @param string $shortcode the shortcode to be parsed. |
|
89 | - * @return string |
|
90 | - * @throws EE_Error |
|
91 | - * @throws ReflectionException |
|
92 | - */ |
|
93 | - protected function _parser($shortcode) |
|
94 | - { |
|
95 | - $this->_extra = isset($this->_extra_data['data']) |
|
96 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
97 | - ? $this->_extra_data['data'] |
|
98 | - : null; |
|
99 | - |
|
100 | - $registration = $this->getRegistration(); |
|
101 | - $attendee = $this->getAttendee($registration); |
|
102 | - |
|
103 | - switch ($shortcode) { |
|
104 | - case '[FNAME]': |
|
105 | - return $attendee->fname(); |
|
106 | - |
|
107 | - case '[LNAME]': |
|
108 | - return $attendee->lname(); |
|
109 | - |
|
110 | - case '[ATTENDEE_EMAIL]': |
|
111 | - return $attendee->email(); |
|
112 | - |
|
113 | - case '[EDIT_ATTENDEE_LINK]': |
|
114 | - return $registration->get_admin_edit_url(); |
|
115 | - |
|
116 | - case '[REGISTRATION_CODE]': |
|
117 | - return $registration->reg_code(); |
|
118 | - |
|
119 | - case '[REGISTRATION_ID]': |
|
120 | - return $registration->ID(); |
|
121 | - |
|
122 | - case '[FRONTEND_EDIT_REG_LINK]': |
|
123 | - return $registration->edit_attendee_information_url(); |
|
124 | - |
|
125 | - case '[PHONE_NUMBER]': |
|
126 | - return $attendee->phone(); |
|
127 | - |
|
128 | - case '[ADDRESS]': |
|
129 | - return $attendee->address(); |
|
130 | - |
|
131 | - case '[ADDRESS2]': |
|
132 | - return $attendee->address2(); |
|
133 | - |
|
134 | - case '[CITY]': |
|
135 | - return $attendee->city(); |
|
136 | - |
|
137 | - case '[ZIP_PC]': |
|
138 | - return $attendee->zip(); |
|
139 | - |
|
140 | - case '[ADDRESS_STATE]': |
|
141 | - $state_obj = $attendee->state_obj(); |
|
142 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
143 | - |
|
144 | - case '[COUNTRY]': |
|
145 | - $country_obj = $attendee->country_obj(); |
|
146 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
147 | - |
|
148 | - case '[REGISTRATION_STATUS_ID]': |
|
149 | - return $registration->status_ID(); |
|
150 | - |
|
151 | - case '[REGISTRATION_STATUS_LABEL]': |
|
152 | - return $registration->pretty_status(); |
|
153 | - |
|
154 | - case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
155 | - return $registration->pretty_paid(); |
|
156 | - } |
|
157 | - |
|
158 | - return apply_filters( |
|
159 | - 'FHEE__EE_Attendee_Shortcodes__parsed', |
|
160 | - '', |
|
161 | - $shortcode, |
|
162 | - $registration, |
|
163 | - $attendee, |
|
164 | - $this->_data, |
|
165 | - $this->_extra_data, |
|
166 | - $this |
|
167 | - ); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return EE_Registration |
|
173 | - * @throws EE_Error |
|
174 | - * @since 5.0.20.p |
|
175 | - */ |
|
176 | - private function getRegistration(): EE_Registration |
|
177 | - { |
|
178 | - // incoming object should only be a registration object. |
|
179 | - if ($this->_data instanceof EE_Registration) { |
|
180 | - return $this->_data; |
|
181 | - } |
|
182 | - if ($this->_data instanceof EE_Messages_Addressee) { |
|
183 | - if ($this->_data->primary_reg_obj instanceof EE_Registration) { |
|
184 | - return $this->_data->primary_reg_obj; |
|
185 | - } |
|
186 | - if ($this->_data->reg_obj instanceof EE_Registration) { |
|
187 | - return $this->_data->reg_obj; |
|
188 | - } |
|
189 | - } |
|
190 | - // let's attempt to get the txn_id for the error message. |
|
191 | - $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
192 | - ? $this->_extra->txn->ID() |
|
193 | - : esc_html__('Unknown', 'event_espresso'); |
|
194 | - $msg = esc_html__( |
|
195 | - 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
196 | - 'event_espresso' |
|
197 | - ); |
|
198 | - $dev_msg = sprintf( |
|
199 | - esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
200 | - $txn_id |
|
201 | - ); |
|
202 | - throw new EE_Error("$msg||$msg $dev_msg"); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @param EE_Registration $registration |
|
208 | - * @return EE_Attendee |
|
209 | - * @throws EE_Error |
|
210 | - * @throws ReflectionException |
|
211 | - * @since 5.0.20.p |
|
212 | - */ |
|
213 | - private function getAttendee(EE_Registration $registration): EE_Attendee |
|
214 | - { |
|
215 | - $attendee = $registration->attendee(); |
|
216 | - if ($attendee instanceof EE_Attendee) { |
|
217 | - return $attendee; |
|
218 | - } |
|
219 | - // attendee obj for this registration |
|
220 | - if ( |
|
221 | - isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
222 | - && $this->_extra->registrations[ $registration->ID() ]['att_obj'] instanceof EE_Attendee |
|
223 | - ) { |
|
224 | - return $this->_extra->registrations[ $registration->ID() ]['att_obj']; |
|
225 | - } |
|
226 | - |
|
227 | - $msg = esc_html__( |
|
228 | - 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
229 | - 'event_espresso' |
|
230 | - ); |
|
231 | - $dev_msg = sprintf( |
|
232 | - esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
233 | - $registration->ID() |
|
234 | - ); |
|
235 | - throw new EE_Error("$msg||$msg $dev_msg"); |
|
236 | - } |
|
18 | + /** |
|
19 | + * hold all extra data. |
|
20 | + * |
|
21 | + * @var array|stdClass|null |
|
22 | + */ |
|
23 | + protected $_extra; |
|
24 | + |
|
25 | + |
|
26 | + protected function _init_props() |
|
27 | + { |
|
28 | + $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
29 | + $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
30 | + $this->_shortcodes = [ |
|
31 | + '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
32 | + '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
33 | + '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
34 | + '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
35 | + 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + '[REGISTRATION_ID]' => esc_html__( |
|
39 | + 'Unique Registration ID for the registration', |
|
40 | + 'event_espresso' |
|
41 | + ), |
|
42 | + '[REGISTRATION_CODE]' => esc_html__( |
|
43 | + 'Unique Registration Code for the registration', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
47 | + 'Parses to the registration status for the attendee', |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
51 | + 'Parses to the status label for the registrant', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
55 | + 'Parses to the total amount paid for this registration.', |
|
56 | + 'event_espresso' |
|
57 | + ), |
|
58 | + '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
59 | + 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
60 | + 'event_espresso' |
|
61 | + ), |
|
62 | + '[PHONE_NUMBER]' => esc_html__( |
|
63 | + 'The Phone Number for the Registration.', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
67 | + '[ADDRESS2]' => esc_html__( |
|
68 | + 'Whatever was in the address 2 field for the registration.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
72 | + '[ZIP_PC]' => esc_html__( |
|
73 | + 'The ZIP (or Postal) Code for the Registration.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + '[ADDRESS_STATE]' => esc_html__( |
|
77 | + 'The state/province for the registration.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
81 | + ]; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * handles shortcode parsing |
|
87 | + * |
|
88 | + * @param string $shortcode the shortcode to be parsed. |
|
89 | + * @return string |
|
90 | + * @throws EE_Error |
|
91 | + * @throws ReflectionException |
|
92 | + */ |
|
93 | + protected function _parser($shortcode) |
|
94 | + { |
|
95 | + $this->_extra = isset($this->_extra_data['data']) |
|
96 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
97 | + ? $this->_extra_data['data'] |
|
98 | + : null; |
|
99 | + |
|
100 | + $registration = $this->getRegistration(); |
|
101 | + $attendee = $this->getAttendee($registration); |
|
102 | + |
|
103 | + switch ($shortcode) { |
|
104 | + case '[FNAME]': |
|
105 | + return $attendee->fname(); |
|
106 | + |
|
107 | + case '[LNAME]': |
|
108 | + return $attendee->lname(); |
|
109 | + |
|
110 | + case '[ATTENDEE_EMAIL]': |
|
111 | + return $attendee->email(); |
|
112 | + |
|
113 | + case '[EDIT_ATTENDEE_LINK]': |
|
114 | + return $registration->get_admin_edit_url(); |
|
115 | + |
|
116 | + case '[REGISTRATION_CODE]': |
|
117 | + return $registration->reg_code(); |
|
118 | + |
|
119 | + case '[REGISTRATION_ID]': |
|
120 | + return $registration->ID(); |
|
121 | + |
|
122 | + case '[FRONTEND_EDIT_REG_LINK]': |
|
123 | + return $registration->edit_attendee_information_url(); |
|
124 | + |
|
125 | + case '[PHONE_NUMBER]': |
|
126 | + return $attendee->phone(); |
|
127 | + |
|
128 | + case '[ADDRESS]': |
|
129 | + return $attendee->address(); |
|
130 | + |
|
131 | + case '[ADDRESS2]': |
|
132 | + return $attendee->address2(); |
|
133 | + |
|
134 | + case '[CITY]': |
|
135 | + return $attendee->city(); |
|
136 | + |
|
137 | + case '[ZIP_PC]': |
|
138 | + return $attendee->zip(); |
|
139 | + |
|
140 | + case '[ADDRESS_STATE]': |
|
141 | + $state_obj = $attendee->state_obj(); |
|
142 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
143 | + |
|
144 | + case '[COUNTRY]': |
|
145 | + $country_obj = $attendee->country_obj(); |
|
146 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
147 | + |
|
148 | + case '[REGISTRATION_STATUS_ID]': |
|
149 | + return $registration->status_ID(); |
|
150 | + |
|
151 | + case '[REGISTRATION_STATUS_LABEL]': |
|
152 | + return $registration->pretty_status(); |
|
153 | + |
|
154 | + case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
155 | + return $registration->pretty_paid(); |
|
156 | + } |
|
157 | + |
|
158 | + return apply_filters( |
|
159 | + 'FHEE__EE_Attendee_Shortcodes__parsed', |
|
160 | + '', |
|
161 | + $shortcode, |
|
162 | + $registration, |
|
163 | + $attendee, |
|
164 | + $this->_data, |
|
165 | + $this->_extra_data, |
|
166 | + $this |
|
167 | + ); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return EE_Registration |
|
173 | + * @throws EE_Error |
|
174 | + * @since 5.0.20.p |
|
175 | + */ |
|
176 | + private function getRegistration(): EE_Registration |
|
177 | + { |
|
178 | + // incoming object should only be a registration object. |
|
179 | + if ($this->_data instanceof EE_Registration) { |
|
180 | + return $this->_data; |
|
181 | + } |
|
182 | + if ($this->_data instanceof EE_Messages_Addressee) { |
|
183 | + if ($this->_data->primary_reg_obj instanceof EE_Registration) { |
|
184 | + return $this->_data->primary_reg_obj; |
|
185 | + } |
|
186 | + if ($this->_data->reg_obj instanceof EE_Registration) { |
|
187 | + return $this->_data->reg_obj; |
|
188 | + } |
|
189 | + } |
|
190 | + // let's attempt to get the txn_id for the error message. |
|
191 | + $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
192 | + ? $this->_extra->txn->ID() |
|
193 | + : esc_html__('Unknown', 'event_espresso'); |
|
194 | + $msg = esc_html__( |
|
195 | + 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
196 | + 'event_espresso' |
|
197 | + ); |
|
198 | + $dev_msg = sprintf( |
|
199 | + esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
200 | + $txn_id |
|
201 | + ); |
|
202 | + throw new EE_Error("$msg||$msg $dev_msg"); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @param EE_Registration $registration |
|
208 | + * @return EE_Attendee |
|
209 | + * @throws EE_Error |
|
210 | + * @throws ReflectionException |
|
211 | + * @since 5.0.20.p |
|
212 | + */ |
|
213 | + private function getAttendee(EE_Registration $registration): EE_Attendee |
|
214 | + { |
|
215 | + $attendee = $registration->attendee(); |
|
216 | + if ($attendee instanceof EE_Attendee) { |
|
217 | + return $attendee; |
|
218 | + } |
|
219 | + // attendee obj for this registration |
|
220 | + if ( |
|
221 | + isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
222 | + && $this->_extra->registrations[ $registration->ID() ]['att_obj'] instanceof EE_Attendee |
|
223 | + ) { |
|
224 | + return $this->_extra->registrations[ $registration->ID() ]['att_obj']; |
|
225 | + } |
|
226 | + |
|
227 | + $msg = esc_html__( |
|
228 | + 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
229 | + 'event_espresso' |
|
230 | + ); |
|
231 | + $dev_msg = sprintf( |
|
232 | + esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
233 | + $registration->ID() |
|
234 | + ); |
|
235 | + throw new EE_Error("$msg||$msg $dev_msg"); |
|
236 | + } |
|
237 | 237 | } |
@@ -218,13 +218,13 @@ |
||
218 | 218 | } |
219 | 219 | // attendee obj for this registration |
220 | 220 | if ( |
221 | - isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
222 | - && $this->_extra->registrations[ $registration->ID() ]['att_obj'] instanceof EE_Attendee |
|
221 | + isset($this->_extra->registrations[$registration->ID()]['att_obj']) |
|
222 | + && $this->_extra->registrations[$registration->ID()]['att_obj'] instanceof EE_Attendee |
|
223 | 223 | ) { |
224 | - return $this->_extra->registrations[ $registration->ID() ]['att_obj']; |
|
224 | + return $this->_extra->registrations[$registration->ID()]['att_obj']; |
|
225 | 225 | } |
226 | 226 | |
227 | - $msg = esc_html__( |
|
227 | + $msg = esc_html__( |
|
228 | 228 | 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
229 | 229 | 'event_espresso' |
230 | 230 | ); |
@@ -15,212 +15,212 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Primary_Registration_Details_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - protected function _init_props() |
|
19 | - { |
|
20 | - $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso'); |
|
21 | - $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso'); |
|
22 | - $this->_shortcodes = [ |
|
23 | - '[PRIMARY_REGISTRANT_FNAME]' => esc_html__( |
|
24 | - 'Parses to the first name of the primary registration for the transaction.', |
|
25 | - 'event_espresso' |
|
26 | - ), |
|
27 | - '[PRIMARY_REGISTRANT_LNAME]' => esc_html__( |
|
28 | - 'Parses to the last name of the primary registration for the transaction.', |
|
29 | - 'event_espresso' |
|
30 | - ), |
|
31 | - '[PRIMARY_REGISTRANT_EMAIL]' => esc_html__( |
|
32 | - 'Parses to the email address of the primary registration for the transaction.', |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - '[PRIMARY_REGISTRANT_REGISTRATION_ID]' => esc_html__( |
|
36 | - 'Parses to the registration ID of the primary registrant for the transaction.', |
|
37 | - 'event_espresso' |
|
38 | - ), |
|
39 | - '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' => esc_html__( |
|
40 | - 'Parses to the registration code of the primary registrant for the transaction.', |
|
41 | - 'event_espresso' |
|
42 | - ), |
|
43 | - '[PRIMARY_REGISTRANT_PHONE_NUMBER]' => esc_html__( |
|
44 | - 'The Phone Number for the primary registrant for the transaction.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - '[PRIMARY_REGISTRANT_ADDRESS]' => esc_html__( |
|
48 | - 'The Address for the primary registrant for the transaction.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '[PRIMARY_REGISTRANT_ADDRESS2]' => esc_html__( |
|
52 | - 'Whatever was in the address 2 field for the primary registrant for the transaction.', |
|
53 | - 'event_espresso' |
|
54 | - ), |
|
55 | - '[PRIMARY_REGISTRANT_CITY]' => esc_html__( |
|
56 | - 'The city for the primary registrant for the transaction.', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '[PRIMARY_REGISTRANT_ZIP_PC]' => esc_html__( |
|
60 | - 'The ZIP (or Postal) Code for the primary registrant for the transaction.', |
|
61 | - 'event_espresso' |
|
62 | - ), |
|
63 | - '[PRIMARY_REGISTRANT_ADDRESS_STATE]' => esc_html__( |
|
64 | - 'The state/province for the primary registrant for the transaction.', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - '[PRIMARY_REGISTRANT_COUNTRY]' => esc_html__( |
|
68 | - 'The country for the primary registrant for the transaction.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' => esc_html__( |
|
72 | - 'The date the registration occured for the primary registration.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
76 | - 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '[PRIMARY_REGISTRANT_ANSWER_*]' => esc_html__( |
|
80 | - 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $shortcode |
|
89 | - * @return string |
|
90 | - * @throws EE_Error |
|
91 | - * @throws ReflectionException |
|
92 | - * @since 5.0.20.p |
|
93 | - */ |
|
94 | - protected function _parser($shortcode) |
|
95 | - { |
|
96 | - // make sure we end up with a copy of the EE_Messages_Addressee object |
|
97 | - $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
98 | - $primary_registration = ( |
|
99 | - ! $primary_registration instanceof EE_Messages_Addressee |
|
100 | - && is_array($this->_data) |
|
101 | - && isset($this->_data['data']) |
|
102 | - && $this->_data['data'] instanceof EE_Messages_Addressee |
|
103 | - ) |
|
104 | - ? $this->_data['data'] |
|
105 | - : $primary_registration; |
|
106 | - $primary_registration = ( |
|
107 | - ! $primary_registration instanceof EE_Messages_Addressee |
|
108 | - && ! empty($this->_extra_data['data']) |
|
109 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
110 | - ) |
|
111 | - ? $this->_extra_data['data'] |
|
112 | - : $primary_registration; |
|
113 | - |
|
114 | - if (! $primary_registration instanceof EE_Messages_Addressee) { |
|
115 | - return ''; |
|
116 | - } |
|
117 | - |
|
118 | - $attendee = $primary_registration->primary_att_obj; |
|
119 | - $primary_reg = $primary_registration->primary_reg_obj; |
|
120 | - |
|
121 | - if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
122 | - return ''; |
|
123 | - } |
|
124 | - |
|
125 | - switch ($shortcode) { |
|
126 | - case '[PRIMARY_REGISTRANT_FNAME]': |
|
127 | - return $attendee->fname(); |
|
128 | - |
|
129 | - case '[PRIMARY_REGISTRANT_LNAME]': |
|
130 | - return $attendee->lname(); |
|
131 | - |
|
132 | - case '[PRIMARY_REGISTRANT_EMAIL]': |
|
133 | - return $attendee->email(); |
|
134 | - |
|
135 | - case '[PRIMARY_REGISTRANT_REGISTRATION_ID]': |
|
136 | - return $primary_reg->ID(); |
|
137 | - |
|
138 | - case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]': |
|
139 | - return $primary_reg->reg_code(); |
|
140 | - |
|
141 | - case '[PRIMARY_REGISTRANT_PHONE_NUMBER]': |
|
142 | - return $attendee->phone(); |
|
143 | - |
|
144 | - case '[PRIMARY_REGISTRANT_ADDRESS]': |
|
145 | - return $attendee->address(); |
|
146 | - |
|
147 | - case '[PRIMARY_REGISTRANT_ADDRESS2]': |
|
148 | - return $attendee->address2(); |
|
149 | - |
|
150 | - case '[PRIMARY_REGISTRANT_CITY]': |
|
151 | - return $attendee->city(); |
|
152 | - |
|
153 | - case '[PRIMARY_REGISTRANT_ZIP_PC]': |
|
154 | - return $attendee->zip(); |
|
155 | - |
|
156 | - case '[PRIMARY_REGISTRANT_ADDRESS_STATE]': |
|
157 | - $state_obj = $attendee->state_obj(); |
|
158 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
159 | - |
|
160 | - case '[PRIMARY_REGISTRANT_COUNTRY]': |
|
161 | - $country_obj = $attendee->country_obj(); |
|
162 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
163 | - |
|
164 | - case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]': |
|
165 | - if (! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
166 | - return ''; |
|
167 | - } |
|
168 | - return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format')); |
|
169 | - |
|
170 | - case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]': |
|
171 | - return $primary_reg->edit_attendee_information_url(); |
|
172 | - } |
|
173 | - |
|
174 | - if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) { |
|
175 | - $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode); |
|
176 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
177 | - |
|
178 | - |
|
179 | - // now let's figure out what question has this text |
|
180 | - if (empty($primary_registration->questions)) { |
|
181 | - return ''; |
|
182 | - } |
|
183 | - |
|
184 | - foreach ($primary_registration->questions as $ansid => $question) { |
|
185 | - if ( |
|
186 | - $question instanceof EE_Question |
|
187 | - && trim($question->get('QST_display_text')) === trim($shortcode) |
|
188 | - && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]) |
|
189 | - ) { |
|
190 | - /** @var EE_Answer $primary_reg_ansid */ |
|
191 | - $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]; |
|
192 | - |
|
193 | - // what we show for the answer depends on the question type! |
|
194 | - switch ($question->get('QST_type')) { |
|
195 | - case EEM_Question::QST_type_state: |
|
196 | - $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
197 | - $answer = $state instanceof EE_State ? $state->name() : ''; |
|
198 | - break; |
|
199 | - |
|
200 | - case EEM_Question::QST_type_country: |
|
201 | - $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
202 | - $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
203 | - break; |
|
204 | - |
|
205 | - default: |
|
206 | - $answer = (string) $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
207 | - break; |
|
208 | - } |
|
209 | - |
|
210 | - return $answer; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - return apply_filters( |
|
216 | - 'FHEE__EE_Primary_Registration_Details_Shortcodes__parsed', |
|
217 | - '', |
|
218 | - $shortcode, |
|
219 | - $primary_reg, |
|
220 | - $attendee, |
|
221 | - $this->_data, |
|
222 | - $this->_extra_data, |
|
223 | - $this |
|
224 | - ); |
|
225 | - } |
|
18 | + protected function _init_props() |
|
19 | + { |
|
20 | + $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso'); |
|
21 | + $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso'); |
|
22 | + $this->_shortcodes = [ |
|
23 | + '[PRIMARY_REGISTRANT_FNAME]' => esc_html__( |
|
24 | + 'Parses to the first name of the primary registration for the transaction.', |
|
25 | + 'event_espresso' |
|
26 | + ), |
|
27 | + '[PRIMARY_REGISTRANT_LNAME]' => esc_html__( |
|
28 | + 'Parses to the last name of the primary registration for the transaction.', |
|
29 | + 'event_espresso' |
|
30 | + ), |
|
31 | + '[PRIMARY_REGISTRANT_EMAIL]' => esc_html__( |
|
32 | + 'Parses to the email address of the primary registration for the transaction.', |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + '[PRIMARY_REGISTRANT_REGISTRATION_ID]' => esc_html__( |
|
36 | + 'Parses to the registration ID of the primary registrant for the transaction.', |
|
37 | + 'event_espresso' |
|
38 | + ), |
|
39 | + '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' => esc_html__( |
|
40 | + 'Parses to the registration code of the primary registrant for the transaction.', |
|
41 | + 'event_espresso' |
|
42 | + ), |
|
43 | + '[PRIMARY_REGISTRANT_PHONE_NUMBER]' => esc_html__( |
|
44 | + 'The Phone Number for the primary registrant for the transaction.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + '[PRIMARY_REGISTRANT_ADDRESS]' => esc_html__( |
|
48 | + 'The Address for the primary registrant for the transaction.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '[PRIMARY_REGISTRANT_ADDRESS2]' => esc_html__( |
|
52 | + 'Whatever was in the address 2 field for the primary registrant for the transaction.', |
|
53 | + 'event_espresso' |
|
54 | + ), |
|
55 | + '[PRIMARY_REGISTRANT_CITY]' => esc_html__( |
|
56 | + 'The city for the primary registrant for the transaction.', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '[PRIMARY_REGISTRANT_ZIP_PC]' => esc_html__( |
|
60 | + 'The ZIP (or Postal) Code for the primary registrant for the transaction.', |
|
61 | + 'event_espresso' |
|
62 | + ), |
|
63 | + '[PRIMARY_REGISTRANT_ADDRESS_STATE]' => esc_html__( |
|
64 | + 'The state/province for the primary registrant for the transaction.', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + '[PRIMARY_REGISTRANT_COUNTRY]' => esc_html__( |
|
68 | + 'The country for the primary registrant for the transaction.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' => esc_html__( |
|
72 | + 'The date the registration occured for the primary registration.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
76 | + 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '[PRIMARY_REGISTRANT_ANSWER_*]' => esc_html__( |
|
80 | + 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + ]; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $shortcode |
|
89 | + * @return string |
|
90 | + * @throws EE_Error |
|
91 | + * @throws ReflectionException |
|
92 | + * @since 5.0.20.p |
|
93 | + */ |
|
94 | + protected function _parser($shortcode) |
|
95 | + { |
|
96 | + // make sure we end up with a copy of the EE_Messages_Addressee object |
|
97 | + $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
98 | + $primary_registration = ( |
|
99 | + ! $primary_registration instanceof EE_Messages_Addressee |
|
100 | + && is_array($this->_data) |
|
101 | + && isset($this->_data['data']) |
|
102 | + && $this->_data['data'] instanceof EE_Messages_Addressee |
|
103 | + ) |
|
104 | + ? $this->_data['data'] |
|
105 | + : $primary_registration; |
|
106 | + $primary_registration = ( |
|
107 | + ! $primary_registration instanceof EE_Messages_Addressee |
|
108 | + && ! empty($this->_extra_data['data']) |
|
109 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
110 | + ) |
|
111 | + ? $this->_extra_data['data'] |
|
112 | + : $primary_registration; |
|
113 | + |
|
114 | + if (! $primary_registration instanceof EE_Messages_Addressee) { |
|
115 | + return ''; |
|
116 | + } |
|
117 | + |
|
118 | + $attendee = $primary_registration->primary_att_obj; |
|
119 | + $primary_reg = $primary_registration->primary_reg_obj; |
|
120 | + |
|
121 | + if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
122 | + return ''; |
|
123 | + } |
|
124 | + |
|
125 | + switch ($shortcode) { |
|
126 | + case '[PRIMARY_REGISTRANT_FNAME]': |
|
127 | + return $attendee->fname(); |
|
128 | + |
|
129 | + case '[PRIMARY_REGISTRANT_LNAME]': |
|
130 | + return $attendee->lname(); |
|
131 | + |
|
132 | + case '[PRIMARY_REGISTRANT_EMAIL]': |
|
133 | + return $attendee->email(); |
|
134 | + |
|
135 | + case '[PRIMARY_REGISTRANT_REGISTRATION_ID]': |
|
136 | + return $primary_reg->ID(); |
|
137 | + |
|
138 | + case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]': |
|
139 | + return $primary_reg->reg_code(); |
|
140 | + |
|
141 | + case '[PRIMARY_REGISTRANT_PHONE_NUMBER]': |
|
142 | + return $attendee->phone(); |
|
143 | + |
|
144 | + case '[PRIMARY_REGISTRANT_ADDRESS]': |
|
145 | + return $attendee->address(); |
|
146 | + |
|
147 | + case '[PRIMARY_REGISTRANT_ADDRESS2]': |
|
148 | + return $attendee->address2(); |
|
149 | + |
|
150 | + case '[PRIMARY_REGISTRANT_CITY]': |
|
151 | + return $attendee->city(); |
|
152 | + |
|
153 | + case '[PRIMARY_REGISTRANT_ZIP_PC]': |
|
154 | + return $attendee->zip(); |
|
155 | + |
|
156 | + case '[PRIMARY_REGISTRANT_ADDRESS_STATE]': |
|
157 | + $state_obj = $attendee->state_obj(); |
|
158 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
159 | + |
|
160 | + case '[PRIMARY_REGISTRANT_COUNTRY]': |
|
161 | + $country_obj = $attendee->country_obj(); |
|
162 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
163 | + |
|
164 | + case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]': |
|
165 | + if (! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
166 | + return ''; |
|
167 | + } |
|
168 | + return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format')); |
|
169 | + |
|
170 | + case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]': |
|
171 | + return $primary_reg->edit_attendee_information_url(); |
|
172 | + } |
|
173 | + |
|
174 | + if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) { |
|
175 | + $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode); |
|
176 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
177 | + |
|
178 | + |
|
179 | + // now let's figure out what question has this text |
|
180 | + if (empty($primary_registration->questions)) { |
|
181 | + return ''; |
|
182 | + } |
|
183 | + |
|
184 | + foreach ($primary_registration->questions as $ansid => $question) { |
|
185 | + if ( |
|
186 | + $question instanceof EE_Question |
|
187 | + && trim($question->get('QST_display_text')) === trim($shortcode) |
|
188 | + && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]) |
|
189 | + ) { |
|
190 | + /** @var EE_Answer $primary_reg_ansid */ |
|
191 | + $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]; |
|
192 | + |
|
193 | + // what we show for the answer depends on the question type! |
|
194 | + switch ($question->get('QST_type')) { |
|
195 | + case EEM_Question::QST_type_state: |
|
196 | + $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
197 | + $answer = $state instanceof EE_State ? $state->name() : ''; |
|
198 | + break; |
|
199 | + |
|
200 | + case EEM_Question::QST_type_country: |
|
201 | + $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
202 | + $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
203 | + break; |
|
204 | + |
|
205 | + default: |
|
206 | + $answer = (string) $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
207 | + break; |
|
208 | + } |
|
209 | + |
|
210 | + return $answer; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + return apply_filters( |
|
216 | + 'FHEE__EE_Primary_Registration_Details_Shortcodes__parsed', |
|
217 | + '', |
|
218 | + $shortcode, |
|
219 | + $primary_reg, |
|
220 | + $attendee, |
|
221 | + $this->_data, |
|
222 | + $this->_extra_data, |
|
223 | + $this |
|
224 | + ); |
|
225 | + } |
|
226 | 226 | } |
@@ -15,453 +15,453 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class EE_Shortcodes extends EE_Base |
17 | 17 | { |
18 | - /** |
|
19 | - * holds label for library |
|
20 | - * This is used for referencing the library label |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public string $label; |
|
25 | - |
|
26 | - |
|
27 | - public string $name; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This property is used for referencing a short description of the library |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public string $description; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
40 | - * label/description for the shortcode. |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected array $_shortcodes = []; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This will hold the incoming data item sent to the parser method |
|
49 | - * |
|
50 | - * @var array|object |
|
51 | - */ |
|
52 | - protected $_data; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * some shortcodes may require extra data to parse. This property is provided for that. |
|
57 | - * |
|
58 | - * @var array|EE_Messages_Addressee |
|
59 | - */ |
|
60 | - protected $_extra_data; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * EE_messenger used to generate the template being parsed. |
|
65 | - * |
|
66 | - * @since 4.5.0 |
|
67 | - * @var EE_messenger |
|
68 | - */ |
|
69 | - protected EE_messenger $_messenger; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * message type used to generate the template being parsed. |
|
74 | - * |
|
75 | - * @since 4.5.0 |
|
76 | - * @var EE_message_type|null |
|
77 | - */ |
|
78 | - protected ?EE_message_type $_message_type = null; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * context used for the template being parsed |
|
83 | - * |
|
84 | - * @since 4.5.0 |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - protected string $_context; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Specific Message Template Group ID |
|
92 | - * |
|
93 | - * @since 4.5.0 |
|
94 | - * @var int |
|
95 | - */ |
|
96 | - protected int $_GRP_ID; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @since 4.9.0 |
|
101 | - * @type EE_Message|null |
|
102 | - */ |
|
103 | - protected ?EE_Message $_message = null; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
108 | - * shortcodes |
|
109 | - * |
|
110 | - * @var EEH_Parse_Shortcodes |
|
111 | - */ |
|
112 | - protected EEH_Parse_Shortcodes $_shortcode_helper; |
|
113 | - |
|
114 | - |
|
115 | - public function __construct() |
|
116 | - { |
|
117 | - $this->_set_defaults(); |
|
118 | - $this->_set_shortcode_helper(); |
|
119 | - $this->_init_props(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
125 | - * method |
|
126 | - */ |
|
127 | - private function _set_defaults() |
|
128 | - { |
|
129 | - $this->name = $this->description = ''; |
|
130 | - $this->_shortcodes = []; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * loads an instance of the EE_Shortcode_Parser helper when requested |
|
136 | - */ |
|
137 | - protected function _set_shortcode_helper() |
|
138 | - { |
|
139 | - // get shortcode_replace instance - set when _get_messages is called in child... |
|
140 | - $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - public function get_shortcode_helper(): EEH_Parse_Shortcodes |
|
145 | - { |
|
146 | - return $this->_shortcode_helper; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
152 | - * classes if necessary (see EE_Questions_Answers for example) |
|
153 | - * |
|
154 | - * @param string $shortcode incoming shortcode to be parsed |
|
155 | - * @param object|array $data incoming data to be used for parsing |
|
156 | - * @param object|array $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
157 | - * @return string parsed shortcode. |
|
158 | - */ |
|
159 | - public function parser(string $shortcode, $data, $extra_data = []): string |
|
160 | - { |
|
161 | - // filter setup shortcodes |
|
162 | - $this->_shortcodes = $this->get_shortcodes(); |
|
163 | - |
|
164 | - // we need to set up any dynamic shortcodes so that they work with the array_key_exists |
|
165 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
166 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
167 | - |
|
168 | - // first we want to make sure this is a valid shortcode |
|
169 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
170 | - // get out, this parser doesn't handle the incoming shortcode. |
|
171 | - return ''; |
|
172 | - } |
|
173 | - $this->_data = $data; |
|
174 | - $this->_extra_data = $extra_data; |
|
175 | - $this->_set_messages_properties(); |
|
176 | - $parsed = (string) apply_filters( |
|
177 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
178 | - $this->_parser($shortcode), |
|
179 | - $shortcode, |
|
180 | - $data, |
|
181 | - $extra_data, |
|
182 | - $this |
|
183 | - ); |
|
184 | - |
|
185 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
186 | - return (string) apply_filters( |
|
187 | - 'FHEE__EE_Shortcodes__parser_after', |
|
188 | - $parsed, |
|
189 | - $shortcode, |
|
190 | - $data, |
|
191 | - $extra_data, |
|
192 | - $this |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * This method just returns the shortcodes in the $_shortcodes array property. |
|
199 | - * |
|
200 | - * @return array array of shortcodes => description pairs |
|
201 | - */ |
|
202 | - public function get_shortcodes(): array |
|
203 | - { |
|
204 | - $this->_shortcodes = (array) apply_filters( |
|
205 | - 'FHEE__' . get_class($this) . '__shortcodes', |
|
206 | - $this->_shortcodes, |
|
207 | - $this |
|
208 | - ); |
|
209 | - |
|
210 | - // note the below filter applies to ALL shortcode parsers... be careful! |
|
211 | - return (array) apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
217 | - * |
|
218 | - * @abstract |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - abstract protected function _init_props(); |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
226 | - * will have to take care of handling. |
|
227 | - * |
|
228 | - * @abstract |
|
229 | - * @param string $shortcode the shortcode to be parsed. |
|
230 | - * @return string parsed shortcode |
|
231 | - */ |
|
232 | - abstract protected function _parser($shortcode); |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
237 | - * meets their requirements |
|
238 | - * |
|
239 | - * @return void If validation fails we'll throw an exception. |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - protected function _validate_list_requirements() |
|
243 | - { |
|
244 | - // first test to make sure we've got an array! |
|
245 | - if (! is_array($this->_data)) { |
|
246 | - throw new EE_Error( |
|
247 | - sprintf( |
|
248 | - esc_html__( |
|
249 | - 'Expecting an array for the data sent to %s. Instead it was %s', |
|
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - get_class($this), |
|
253 | - gettype($this->_data) |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - |
|
258 | - // next test to make sure we've got the required template in the index! |
|
259 | - if (! isset($this->_data['template'])) { |
|
260 | - throw new EE_Error( |
|
261 | - esc_html__( |
|
262 | - 'The incoming data does not have the required template index in its array', |
|
263 | - 'event_espresso' |
|
264 | - ) |
|
265 | - ); |
|
266 | - } |
|
267 | - |
|
268 | - // next test to make sure we've got a data index in the incoming data array |
|
269 | - if (! isset($this->_data['data'])) { |
|
270 | - throw new EE_Error( |
|
271 | - esc_html__( |
|
272 | - 'The incoming data does not have the required data index in its array', |
|
273 | - 'event_espresso' |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - // all is well let's make sure _extra_data always has the values needed. |
|
279 | - // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
280 | - if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
281 | - $this->_extra_data['data'] = $this->_data['data']; |
|
282 | - $this->_extra_data['template'] = $this->_data['template']; |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * This returns any attributes that may be existing on an EE_Shortcode |
|
289 | - * |
|
290 | - * @param string $shortcode incoming shortcode |
|
291 | - * @return array An array with the attributes |
|
292 | - * @since 4.5.0 |
|
293 | - */ |
|
294 | - protected function _get_shortcode_attrs(string $shortcode): array |
|
295 | - { |
|
296 | - // make sure the required wp helper function is present |
|
297 | - // require the shortcode file if necessary |
|
298 | - if (! function_exists('shortcode_parse_atts')) { |
|
299 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
300 | - } |
|
301 | - |
|
302 | - // let's get any attributes that may be present and set the defaults. |
|
303 | - $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
304 | - return shortcode_parse_atts($shortcode_to_parse); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
310 | - * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
311 | - * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
312 | - * conditional content. |
|
313 | - * |
|
314 | - * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | - * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
316 | - * false means the opening and closing tags and the contained content are removed. |
|
317 | - * @return string The template for the shortcode is returned. |
|
318 | - * @since 4.9.32 |
|
319 | - * |
|
320 | - */ |
|
321 | - protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string |
|
322 | - { |
|
323 | - // first let's get all the matches in the template for this particular shortcode. |
|
324 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
325 | - |
|
326 | - if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
327 | - // we need to hide all instances of the matches |
|
328 | - foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
329 | - $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
330 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
331 | - $this->_data['template'] = preg_replace( |
|
332 | - '~' . $content_to_show_or_hide . '~', |
|
333 | - $replacement, |
|
334 | - $this->_data['template'] |
|
335 | - ); |
|
336 | - } |
|
337 | - } |
|
338 | - // return $template |
|
339 | - return $this->_data['template']; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * This returns the regex pattern to use for conditional shortcodes parsing. |
|
345 | - * |
|
346 | - * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
347 | - * |
|
348 | - * @param string $shortcode |
|
349 | - * @return string |
|
350 | - * @since 4.9.32 |
|
351 | - */ |
|
352 | - private function _get_conditional_block_regex(string $shortcode): string |
|
353 | - { |
|
354 | - // get just the shortcode tag for the match |
|
355 | - preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
356 | - if (empty($shortcode_tag_matches[1])) { |
|
357 | - return $this->_data['template']; |
|
358 | - } |
|
359 | - |
|
360 | - $shortcode_tag = $shortcode_tag_matches[1]; |
|
361 | - // get attributes_part_of_tag |
|
362 | - $attributes_part = preg_quote(str_replace([$shortcode_tag, '[', ']'], '', $shortcode)); |
|
363 | - // escape |
|
364 | - $shortcode_tag = preg_quote($shortcode_tag); |
|
365 | - |
|
366 | - return |
|
367 | - '\[' // Opening Bracket |
|
368 | - . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
369 | - . '(?![\w-])' // Not followed by word character or hyphen |
|
370 | - . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
371 | - . '[^\]\/]*' // Not a closing bracket or forward slash |
|
372 | - . '(?:' |
|
373 | - . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
374 | - . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
375 | - . ')*?' |
|
376 | - . ')' |
|
377 | - . '(?:' |
|
378 | - . '(\/)' // 3. Self closing tag ... |
|
379 | - . '\]' // ... and closing bracket |
|
380 | - . '|' |
|
381 | - . '\]' // Closing bracket |
|
382 | - . '(?:' |
|
383 | - . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
384 | - . '[^\[]*+' // Not an opening bracket |
|
385 | - . '(?:' |
|
386 | - . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
387 | - . '[^\[]*+' // Not an opening bracket |
|
388 | - . ')*+' |
|
389 | - . ')' |
|
390 | - . '\[\/\1\]' // Closing shortcode tag |
|
391 | - . ')?' |
|
392 | - . ')'; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * This sets the properties related to the messages system |
|
398 | - * |
|
399 | - * @return void |
|
400 | - * @since 4.5.0 |
|
401 | - */ |
|
402 | - protected function _set_messages_properties() |
|
403 | - { |
|
404 | - // should be in _extra_data |
|
405 | - if (isset($this->_extra_data['messenger'])) { |
|
406 | - $this->_messenger = $this->_extra_data['messenger']; |
|
407 | - $this->_message_type = $this->_extra_data['message_type']; |
|
408 | - $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
409 | - ? $this->_extra_data['message']->context() |
|
410 | - : ''; |
|
411 | - $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
412 | - ? $this->_extra_data['message']->GRP_ID() |
|
413 | - : 0; |
|
414 | - $this->_message = $this->_extra_data['message'] instanceof EE_Message |
|
415 | - ? $this->_extra_data['message'] |
|
416 | - : null; |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * This returns whatever the set message type object is that was set on this shortcode parser. |
|
423 | - * |
|
424 | - * @return EE_message_type|null |
|
425 | - * @since 4.5.0 |
|
426 | - */ |
|
427 | - public function get_set_message_type(): ?EE_message_type |
|
428 | - { |
|
429 | - return $this->_message_type; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * This returns whatever the set messenger object is that was set on this shortcode parser |
|
435 | - * |
|
436 | - * @return EE_messenger |
|
437 | - * @since 4.5.0 |
|
438 | - */ |
|
439 | - public function get_set_messenger(): EE_messenger |
|
440 | - { |
|
441 | - return $this->_messenger; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * This returns whatever the set context string is on this shortcode parser. |
|
447 | - * |
|
448 | - * @return string |
|
449 | - * @since 4.5.0 |
|
450 | - */ |
|
451 | - public function get_set_context(): string |
|
452 | - { |
|
453 | - return $this->_context; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * This returns whatever the set EE_Message object is on this shortcode. |
|
459 | - * |
|
460 | - * @return EE_Message|null |
|
461 | - * @since 4.9.0 |
|
462 | - */ |
|
463 | - public function get_set_message(): ?EE_Message |
|
464 | - { |
|
465 | - return $this->_message; |
|
466 | - } |
|
18 | + /** |
|
19 | + * holds label for library |
|
20 | + * This is used for referencing the library label |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public string $label; |
|
25 | + |
|
26 | + |
|
27 | + public string $name; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This property is used for referencing a short description of the library |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public string $description; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
40 | + * label/description for the shortcode. |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected array $_shortcodes = []; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This will hold the incoming data item sent to the parser method |
|
49 | + * |
|
50 | + * @var array|object |
|
51 | + */ |
|
52 | + protected $_data; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * some shortcodes may require extra data to parse. This property is provided for that. |
|
57 | + * |
|
58 | + * @var array|EE_Messages_Addressee |
|
59 | + */ |
|
60 | + protected $_extra_data; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * EE_messenger used to generate the template being parsed. |
|
65 | + * |
|
66 | + * @since 4.5.0 |
|
67 | + * @var EE_messenger |
|
68 | + */ |
|
69 | + protected EE_messenger $_messenger; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * message type used to generate the template being parsed. |
|
74 | + * |
|
75 | + * @since 4.5.0 |
|
76 | + * @var EE_message_type|null |
|
77 | + */ |
|
78 | + protected ?EE_message_type $_message_type = null; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * context used for the template being parsed |
|
83 | + * |
|
84 | + * @since 4.5.0 |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + protected string $_context; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Specific Message Template Group ID |
|
92 | + * |
|
93 | + * @since 4.5.0 |
|
94 | + * @var int |
|
95 | + */ |
|
96 | + protected int $_GRP_ID; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @since 4.9.0 |
|
101 | + * @type EE_Message|null |
|
102 | + */ |
|
103 | + protected ?EE_Message $_message = null; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
108 | + * shortcodes |
|
109 | + * |
|
110 | + * @var EEH_Parse_Shortcodes |
|
111 | + */ |
|
112 | + protected EEH_Parse_Shortcodes $_shortcode_helper; |
|
113 | + |
|
114 | + |
|
115 | + public function __construct() |
|
116 | + { |
|
117 | + $this->_set_defaults(); |
|
118 | + $this->_set_shortcode_helper(); |
|
119 | + $this->_init_props(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
125 | + * method |
|
126 | + */ |
|
127 | + private function _set_defaults() |
|
128 | + { |
|
129 | + $this->name = $this->description = ''; |
|
130 | + $this->_shortcodes = []; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * loads an instance of the EE_Shortcode_Parser helper when requested |
|
136 | + */ |
|
137 | + protected function _set_shortcode_helper() |
|
138 | + { |
|
139 | + // get shortcode_replace instance - set when _get_messages is called in child... |
|
140 | + $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + public function get_shortcode_helper(): EEH_Parse_Shortcodes |
|
145 | + { |
|
146 | + return $this->_shortcode_helper; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
152 | + * classes if necessary (see EE_Questions_Answers for example) |
|
153 | + * |
|
154 | + * @param string $shortcode incoming shortcode to be parsed |
|
155 | + * @param object|array $data incoming data to be used for parsing |
|
156 | + * @param object|array $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
157 | + * @return string parsed shortcode. |
|
158 | + */ |
|
159 | + public function parser(string $shortcode, $data, $extra_data = []): string |
|
160 | + { |
|
161 | + // filter setup shortcodes |
|
162 | + $this->_shortcodes = $this->get_shortcodes(); |
|
163 | + |
|
164 | + // we need to set up any dynamic shortcodes so that they work with the array_key_exists |
|
165 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
166 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
167 | + |
|
168 | + // first we want to make sure this is a valid shortcode |
|
169 | + if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
170 | + // get out, this parser doesn't handle the incoming shortcode. |
|
171 | + return ''; |
|
172 | + } |
|
173 | + $this->_data = $data; |
|
174 | + $this->_extra_data = $extra_data; |
|
175 | + $this->_set_messages_properties(); |
|
176 | + $parsed = (string) apply_filters( |
|
177 | + 'FHEE__' . get_class($this) . '__parser_after', |
|
178 | + $this->_parser($shortcode), |
|
179 | + $shortcode, |
|
180 | + $data, |
|
181 | + $extra_data, |
|
182 | + $this |
|
183 | + ); |
|
184 | + |
|
185 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
186 | + return (string) apply_filters( |
|
187 | + 'FHEE__EE_Shortcodes__parser_after', |
|
188 | + $parsed, |
|
189 | + $shortcode, |
|
190 | + $data, |
|
191 | + $extra_data, |
|
192 | + $this |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * This method just returns the shortcodes in the $_shortcodes array property. |
|
199 | + * |
|
200 | + * @return array array of shortcodes => description pairs |
|
201 | + */ |
|
202 | + public function get_shortcodes(): array |
|
203 | + { |
|
204 | + $this->_shortcodes = (array) apply_filters( |
|
205 | + 'FHEE__' . get_class($this) . '__shortcodes', |
|
206 | + $this->_shortcodes, |
|
207 | + $this |
|
208 | + ); |
|
209 | + |
|
210 | + // note the below filter applies to ALL shortcode parsers... be careful! |
|
211 | + return (array) apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
217 | + * |
|
218 | + * @abstract |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + abstract protected function _init_props(); |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
226 | + * will have to take care of handling. |
|
227 | + * |
|
228 | + * @abstract |
|
229 | + * @param string $shortcode the shortcode to be parsed. |
|
230 | + * @return string parsed shortcode |
|
231 | + */ |
|
232 | + abstract protected function _parser($shortcode); |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
237 | + * meets their requirements |
|
238 | + * |
|
239 | + * @return void If validation fails we'll throw an exception. |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + protected function _validate_list_requirements() |
|
243 | + { |
|
244 | + // first test to make sure we've got an array! |
|
245 | + if (! is_array($this->_data)) { |
|
246 | + throw new EE_Error( |
|
247 | + sprintf( |
|
248 | + esc_html__( |
|
249 | + 'Expecting an array for the data sent to %s. Instead it was %s', |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + get_class($this), |
|
253 | + gettype($this->_data) |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + |
|
258 | + // next test to make sure we've got the required template in the index! |
|
259 | + if (! isset($this->_data['template'])) { |
|
260 | + throw new EE_Error( |
|
261 | + esc_html__( |
|
262 | + 'The incoming data does not have the required template index in its array', |
|
263 | + 'event_espresso' |
|
264 | + ) |
|
265 | + ); |
|
266 | + } |
|
267 | + |
|
268 | + // next test to make sure we've got a data index in the incoming data array |
|
269 | + if (! isset($this->_data['data'])) { |
|
270 | + throw new EE_Error( |
|
271 | + esc_html__( |
|
272 | + 'The incoming data does not have the required data index in its array', |
|
273 | + 'event_espresso' |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + // all is well let's make sure _extra_data always has the values needed. |
|
279 | + // let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
280 | + if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
281 | + $this->_extra_data['data'] = $this->_data['data']; |
|
282 | + $this->_extra_data['template'] = $this->_data['template']; |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * This returns any attributes that may be existing on an EE_Shortcode |
|
289 | + * |
|
290 | + * @param string $shortcode incoming shortcode |
|
291 | + * @return array An array with the attributes |
|
292 | + * @since 4.5.0 |
|
293 | + */ |
|
294 | + protected function _get_shortcode_attrs(string $shortcode): array |
|
295 | + { |
|
296 | + // make sure the required wp helper function is present |
|
297 | + // require the shortcode file if necessary |
|
298 | + if (! function_exists('shortcode_parse_atts')) { |
|
299 | + require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
300 | + } |
|
301 | + |
|
302 | + // let's get any attributes that may be present and set the defaults. |
|
303 | + $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
304 | + return shortcode_parse_atts($shortcode_to_parse); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
310 | + * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever |
|
311 | + * conditions existed in the opening tag. This method handles parsing the actual template to show/hide this |
|
312 | + * conditional content. |
|
313 | + * |
|
314 | + * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | + * @param bool $show true means the opening and closing tags are removed and the content is left showing, |
|
316 | + * false means the opening and closing tags and the contained content are removed. |
|
317 | + * @return string The template for the shortcode is returned. |
|
318 | + * @since 4.9.32 |
|
319 | + * |
|
320 | + */ |
|
321 | + protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string |
|
322 | + { |
|
323 | + // first let's get all the matches in the template for this particular shortcode. |
|
324 | + preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
325 | + |
|
326 | + if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
327 | + // we need to hide all instances of the matches |
|
328 | + foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
329 | + $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
330 | + $replacement = $show ? $matches[4][ $index ] : ''; |
|
331 | + $this->_data['template'] = preg_replace( |
|
332 | + '~' . $content_to_show_or_hide . '~', |
|
333 | + $replacement, |
|
334 | + $this->_data['template'] |
|
335 | + ); |
|
336 | + } |
|
337 | + } |
|
338 | + // return $template |
|
339 | + return $this->_data['template']; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * This returns the regex pattern to use for conditional shortcodes parsing. |
|
345 | + * |
|
346 | + * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
347 | + * |
|
348 | + * @param string $shortcode |
|
349 | + * @return string |
|
350 | + * @since 4.9.32 |
|
351 | + */ |
|
352 | + private function _get_conditional_block_regex(string $shortcode): string |
|
353 | + { |
|
354 | + // get just the shortcode tag for the match |
|
355 | + preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
356 | + if (empty($shortcode_tag_matches[1])) { |
|
357 | + return $this->_data['template']; |
|
358 | + } |
|
359 | + |
|
360 | + $shortcode_tag = $shortcode_tag_matches[1]; |
|
361 | + // get attributes_part_of_tag |
|
362 | + $attributes_part = preg_quote(str_replace([$shortcode_tag, '[', ']'], '', $shortcode)); |
|
363 | + // escape |
|
364 | + $shortcode_tag = preg_quote($shortcode_tag); |
|
365 | + |
|
366 | + return |
|
367 | + '\[' // Opening Bracket |
|
368 | + . "($shortcode_tag)$attributes_part" // 1: Shortcode Name |
|
369 | + . '(?![\w-])' // Not followed by word character or hyphen |
|
370 | + . '(' // 2: Unroll the loop: Inside the opening shortcode tag |
|
371 | + . '[^\]\/]*' // Not a closing bracket or forward slash |
|
372 | + . '(?:' |
|
373 | + . '\/(?!\])' // A forward slash not followed by a closing bracket |
|
374 | + . '[^\]\/]*' // Not a closing bracket or forward slash. |
|
375 | + . ')*?' |
|
376 | + . ')' |
|
377 | + . '(?:' |
|
378 | + . '(\/)' // 3. Self closing tag ... |
|
379 | + . '\]' // ... and closing bracket |
|
380 | + . '|' |
|
381 | + . '\]' // Closing bracket |
|
382 | + . '(?:' |
|
383 | + . '(' // 4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
384 | + . '[^\[]*+' // Not an opening bracket |
|
385 | + . '(?:' |
|
386 | + . '\[(?!\/\1\])' // An opening bracket not followed by the closing shortcode tag. |
|
387 | + . '[^\[]*+' // Not an opening bracket |
|
388 | + . ')*+' |
|
389 | + . ')' |
|
390 | + . '\[\/\1\]' // Closing shortcode tag |
|
391 | + . ')?' |
|
392 | + . ')'; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * This sets the properties related to the messages system |
|
398 | + * |
|
399 | + * @return void |
|
400 | + * @since 4.5.0 |
|
401 | + */ |
|
402 | + protected function _set_messages_properties() |
|
403 | + { |
|
404 | + // should be in _extra_data |
|
405 | + if (isset($this->_extra_data['messenger'])) { |
|
406 | + $this->_messenger = $this->_extra_data['messenger']; |
|
407 | + $this->_message_type = $this->_extra_data['message_type']; |
|
408 | + $this->_context = $this->_extra_data['message'] instanceof EE_Message |
|
409 | + ? $this->_extra_data['message']->context() |
|
410 | + : ''; |
|
411 | + $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message |
|
412 | + ? $this->_extra_data['message']->GRP_ID() |
|
413 | + : 0; |
|
414 | + $this->_message = $this->_extra_data['message'] instanceof EE_Message |
|
415 | + ? $this->_extra_data['message'] |
|
416 | + : null; |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * This returns whatever the set message type object is that was set on this shortcode parser. |
|
423 | + * |
|
424 | + * @return EE_message_type|null |
|
425 | + * @since 4.5.0 |
|
426 | + */ |
|
427 | + public function get_set_message_type(): ?EE_message_type |
|
428 | + { |
|
429 | + return $this->_message_type; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * This returns whatever the set messenger object is that was set on this shortcode parser |
|
435 | + * |
|
436 | + * @return EE_messenger |
|
437 | + * @since 4.5.0 |
|
438 | + */ |
|
439 | + public function get_set_messenger(): EE_messenger |
|
440 | + { |
|
441 | + return $this->_messenger; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * This returns whatever the set context string is on this shortcode parser. |
|
447 | + * |
|
448 | + * @return string |
|
449 | + * @since 4.5.0 |
|
450 | + */ |
|
451 | + public function get_set_context(): string |
|
452 | + { |
|
453 | + return $this->_context; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * This returns whatever the set EE_Message object is on this shortcode. |
|
459 | + * |
|
460 | + * @return EE_Message|null |
|
461 | + * @since 4.9.0 |
|
462 | + */ |
|
463 | + public function get_set_message(): ?EE_Message |
|
464 | + { |
|
465 | + return $this->_message; |
|
466 | + } |
|
467 | 467 | } |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | |
164 | 164 | // we need to set up any dynamic shortcodes so that they work with the array_key_exists |
165 | 165 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
166 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
166 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
167 | 167 | |
168 | 168 | // first we want to make sure this is a valid shortcode |
169 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
169 | + if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
170 | 170 | // get out, this parser doesn't handle the incoming shortcode. |
171 | 171 | return ''; |
172 | 172 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $this->_extra_data = $extra_data; |
175 | 175 | $this->_set_messages_properties(); |
176 | 176 | $parsed = (string) apply_filters( |
177 | - 'FHEE__' . get_class($this) . '__parser_after', |
|
177 | + 'FHEE__'.get_class($this).'__parser_after', |
|
178 | 178 | $this->_parser($shortcode), |
179 | 179 | $shortcode, |
180 | 180 | $data, |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | public function get_shortcodes(): array |
203 | 203 | { |
204 | 204 | $this->_shortcodes = (array) apply_filters( |
205 | - 'FHEE__' . get_class($this) . '__shortcodes', |
|
205 | + 'FHEE__'.get_class($this).'__shortcodes', |
|
206 | 206 | $this->_shortcodes, |
207 | 207 | $this |
208 | 208 | ); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | protected function _validate_list_requirements() |
243 | 243 | { |
244 | 244 | // first test to make sure we've got an array! |
245 | - if (! is_array($this->_data)) { |
|
245 | + if ( ! is_array($this->_data)) { |
|
246 | 246 | throw new EE_Error( |
247 | 247 | sprintf( |
248 | 248 | esc_html__( |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | // next test to make sure we've got the required template in the index! |
259 | - if (! isset($this->_data['template'])) { |
|
259 | + if ( ! isset($this->_data['template'])) { |
|
260 | 260 | throw new EE_Error( |
261 | 261 | esc_html__( |
262 | 262 | 'The incoming data does not have the required template index in its array', |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | } |
267 | 267 | |
268 | 268 | // next test to make sure we've got a data index in the incoming data array |
269 | - if (! isset($this->_data['data'])) { |
|
269 | + if ( ! isset($this->_data['data'])) { |
|
270 | 270 | throw new EE_Error( |
271 | 271 | esc_html__( |
272 | 272 | 'The incoming data does not have the required data index in its array', |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | { |
296 | 296 | // make sure the required wp helper function is present |
297 | 297 | // require the shortcode file if necessary |
298 | - if (! function_exists('shortcode_parse_atts')) { |
|
299 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
298 | + if ( ! function_exists('shortcode_parse_atts')) { |
|
299 | + require_once(ABSPATH.WPINC.'/shortcodes.php'); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // let's get any attributes that may be present and set the defaults. |
@@ -321,15 +321,15 @@ discard block |
||
321 | 321 | protected function _mutate_conditional_block_in_template(string $shortcode, bool $show = true): string |
322 | 322 | { |
323 | 323 | // first let's get all the matches in the template for this particular shortcode. |
324 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
324 | + preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches); |
|
325 | 325 | |
326 | 326 | if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
327 | 327 | // we need to hide all instances of the matches |
328 | 328 | foreach ($matches[0] as $index => $content_to_show_or_hide) { |
329 | 329 | $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
330 | - $replacement = $show ? $matches[4][ $index ] : ''; |
|
330 | + $replacement = $show ? $matches[4][$index] : ''; |
|
331 | 331 | $this->_data['template'] = preg_replace( |
332 | - '~' . $content_to_show_or_hide . '~', |
|
332 | + '~'.$content_to_show_or_hide.'~', |
|
333 | 333 | $replacement, |
334 | 334 | $this->_data['template'] |
335 | 335 | ); |
@@ -16,363 +16,363 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Recipient_Details_Shortcodes extends EE_Shortcodes |
18 | 18 | { |
19 | - protected $_recipient; |
|
20 | - |
|
21 | - protected $_registrations_for_recipient; |
|
22 | - |
|
23 | - |
|
24 | - protected function _init_props() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso'); |
|
27 | - $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso'); |
|
28 | - $this->_shortcodes = array( |
|
29 | - '[RECIPIENT_FNAME]' => esc_html__( |
|
30 | - 'Parses to the first name of the recipient for the message.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - '[RECIPIENT_LNAME]' => esc_html__( |
|
34 | - 'Parses to the last name of the recipient for the message.', |
|
35 | - 'event_espresso' |
|
36 | - ), |
|
37 | - '[RECIPIENT_EMAIL]' => esc_html__( |
|
38 | - 'Parses to the email address of the recipient for the message.', |
|
39 | - 'event_espresso' |
|
40 | - ), |
|
41 | - '[RECIPIENT_REGISTRATION_ID]' => esc_html__( |
|
42 | - 'Parses to the registration ID of the recipient for the message.', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - '[RECIPIENT_REGISTRATION_CODE]' => esc_html__( |
|
46 | - 'Parses to the registration code of the recipient for the message.', |
|
47 | - 'event_espresso' |
|
48 | - ), |
|
49 | - '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__( |
|
50 | - 'Parses to a link for frontend editing of the registration for the recipient.', |
|
51 | - 'event_espresso' |
|
52 | - ), |
|
53 | - '[RECIPIENT_PHONE_NUMBER]' => esc_html__( |
|
54 | - 'The Phone Number for the recipient of the message.', |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - '[RECIPIENT_ADDRESS]' => esc_html__( |
|
58 | - 'The Address for the recipient of the message.', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - '[RECIPIENT_ADDRESS2]' => esc_html__( |
|
62 | - 'Whatever was in the address 2 field for the recipient of the message.', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - '[RECIPIENT_CITY]' => esc_html__( |
|
66 | - 'The city for the recipient of the message.', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - '[RECIPIENT_ZIP_PC]' => esc_html__( |
|
70 | - 'The ZIP (or Postal) Code for the recipient of the message.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - '[RECIPIENT_ADDRESS_STATE]' => esc_html__( |
|
74 | - 'The state/province for the recipient of the message.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - '[RECIPIENT_COUNTRY]' => esc_html__( |
|
78 | - 'The country for the recipient of the message.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - '[RECIPIENT_ANSWER_*]' => esc_html__( |
|
82 | - 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '[RECIPIENT_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
86 | - 'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient. Otherwise the value of 0 is printed.', |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - '[RECIPIENT_CANCELLATION_LINK]' => esc_html__( |
|
90 | - 'Generates a link that the recipient can use to cancel their registration.', |
|
91 | - 'event_espresso' |
|
92 | - ), |
|
93 | - '[RECIPIENT_CANCEL_CONFIRMATION_CODE]' => esc_html__( |
|
94 | - 'Generates the confirmation code that the recipient will need to cancel their registration.', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @access protected |
|
103 | - * @param string $shortcode the shortcode to be parsed. |
|
104 | - * @return string parsed shortcode |
|
105 | - * @throws EE_Error |
|
106 | - * @throws ReflectionException |
|
107 | - */ |
|
108 | - protected function _parser($shortcode) |
|
109 | - { |
|
110 | - |
|
111 | - // make sure we end up with a copy of the EE_Messages_Addressee object |
|
112 | - $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
113 | - $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
|
114 | - && is_array($this->_data) |
|
115 | - && isset($this->_data['data']) |
|
116 | - && $this->_data['data'] instanceof EE_Messages_Addressee |
|
117 | - ? $this->_data['data'] |
|
118 | - : $this->_recipient; |
|
119 | - $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
|
120 | - && ! empty($this->_extra_data['data']) |
|
121 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
122 | - ? $this->_extra_data['data'] |
|
123 | - : $this->_recipient; |
|
124 | - |
|
125 | - if (! $this->_recipient instanceof EE_Messages_Addressee) { |
|
126 | - return ''; |
|
127 | - } |
|
128 | - |
|
129 | - $attendee = $this->_recipient->att_obj; |
|
130 | - if (! $attendee instanceof EE_Attendee) { |
|
131 | - return ''; |
|
132 | - } |
|
133 | - |
|
134 | - $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs']) |
|
135 | - ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs'] |
|
136 | - : array(); |
|
137 | - |
|
138 | - switch ($shortcode) { |
|
139 | - case '[RECIPIENT_FNAME]': |
|
140 | - return $attendee->fname(); |
|
141 | - |
|
142 | - case '[RECIPIENT_LNAME]': |
|
143 | - return $attendee->lname(); |
|
144 | - |
|
145 | - case '[RECIPIENT_EMAIL]': |
|
146 | - return $attendee->email(); |
|
147 | - |
|
148 | - case '[RECIPIENT_REGISTRATION_ID]': |
|
149 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
150 | - return ''; |
|
151 | - } |
|
152 | - return $this->_get_reg_id(); |
|
153 | - |
|
154 | - case '[RECIPIENT_REGISTRATION_CODE]': |
|
155 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
156 | - return ''; |
|
157 | - } |
|
158 | - return $this->_get_reg_code(); |
|
159 | - |
|
160 | - case '[RECIPIENT_EDIT_REGISTRATION_LINK]': |
|
161 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
162 | - return ''; |
|
163 | - } |
|
164 | - return $this->_recipient->reg_obj->edit_attendee_information_url(); |
|
165 | - |
|
166 | - case '[RECIPIENT_PHONE_NUMBER]': |
|
167 | - return $attendee->phone(); |
|
168 | - |
|
169 | - case '[RECIPIENT_ADDRESS]': |
|
170 | - return $attendee->address(); |
|
171 | - |
|
172 | - case '[RECIPIENT_ADDRESS2]': |
|
173 | - return $attendee->address2(); |
|
174 | - |
|
175 | - case '[RECIPIENT_CITY]': |
|
176 | - return $attendee->city(); |
|
177 | - |
|
178 | - case '[RECIPIENT_ZIP_PC]': |
|
179 | - return $attendee->zip(); |
|
180 | - |
|
181 | - case '[RECIPIENT_ADDRESS_STATE]': |
|
182 | - $state_obj = $attendee->state_obj(); |
|
183 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
184 | - |
|
185 | - case '[RECIPIENT_COUNTRY]': |
|
186 | - $country_obj = $attendee->country_obj(); |
|
187 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
188 | - |
|
189 | - case '[RECIPIENT_TOTAL_AMOUNT_PAID]': |
|
190 | - return $this->_recipient->reg_obj instanceof EE_Registration |
|
191 | - ? $this->_recipient->reg_obj->pretty_paid() |
|
192 | - : 0; |
|
193 | - |
|
194 | - case '[RECIPIENT_CANCELLATION_LINK]': |
|
195 | - return $this->_recipient->reg_obj instanceof EE_Registration |
|
196 | - ? add_query_arg( |
|
197 | - [ 'e_reg_url_link' => $this->_recipient->reg_obj->reg_url_link() ], |
|
198 | - EE_Registry::instance()->CFG->core->cancel_page_url() |
|
199 | - ) |
|
200 | - : ''; |
|
201 | - |
|
202 | - case '[RECIPIENT_CANCEL_CONFIRMATION_CODE]': |
|
203 | - return $this->_recipient->reg_obj instanceof EE_Registration |
|
204 | - ? $this->_recipient->reg_obj->cancelRegistrationConfirmationCode() |
|
205 | - : ''; |
|
206 | - } |
|
207 | - |
|
208 | - if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) { |
|
209 | - $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode); |
|
210 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
211 | - |
|
212 | - |
|
213 | - // now let's figure out what question has this text |
|
214 | - if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
215 | - return ''; |
|
216 | - } |
|
217 | - |
|
218 | - foreach ($this->_recipient->questions as $ansid => $question) { |
|
219 | - if ( |
|
220 | - $question instanceof EE_Question |
|
221 | - && trim($question->display_text()) === trim($shortcode) |
|
222 | - && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]) |
|
223 | - ) { |
|
224 | - $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]; |
|
225 | - |
|
226 | - // what we show for the answer depends on the question type! |
|
227 | - switch ($question->get('QST_type')) { |
|
228 | - case EEM_Question::QST_type_state: |
|
229 | - $state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value')); |
|
230 | - $answer = $state instanceof EE_State ? $state->name() : ''; |
|
231 | - break; |
|
232 | - |
|
233 | - case EEM_Question::QST_type_country: |
|
234 | - $country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value')); |
|
235 | - $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
236 | - break; |
|
237 | - |
|
238 | - default: |
|
239 | - $answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
240 | - break; |
|
241 | - } |
|
242 | - |
|
243 | - return $answer; |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - return ''; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Returns the EE_Messages_Addressee object for the recipient. |
|
254 | - * |
|
255 | - * @since 4.5.0 |
|
256 | - * |
|
257 | - * @return EE_Messages_Addressee |
|
258 | - */ |
|
259 | - public function get_recipient() |
|
260 | - { |
|
261 | - return $this->_recipient; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * returns the reg code for the recipient depending on the context and whether the recipient has multiple |
|
267 | - * registrations or not. |
|
268 | - * |
|
269 | - * @return string |
|
270 | - */ |
|
271 | - protected function _get_reg_code() |
|
272 | - { |
|
273 | - |
|
274 | - // if only one related registration for the recipient then just return that reg code. |
|
275 | - if (count($this->_registrations_for_recipient) <= 1) { |
|
276 | - return $this->_recipient->reg_obj->reg_code(); |
|
277 | - } |
|
278 | - |
|
279 | - // k more than one registration so let's see if we can get specific to context |
|
280 | - // are we parsing event_list? |
|
281 | - if ($this->_data instanceof EE_Event) { |
|
282 | - $reg_code = array(); |
|
283 | - // loop through registrations for recipient and see if there is a match for this event |
|
284 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
285 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
286 | - $reg_code[] = $reg->reg_code(); |
|
287 | - } |
|
288 | - } |
|
289 | - return implode(', ', $reg_code); |
|
290 | - } |
|
291 | - |
|
292 | - // are we parsing ticket list? |
|
293 | - if ($this->_data instanceof EE_Ticket) { |
|
294 | - $reg_code = array(); |
|
295 | - // loop through each registration for recipient and see if there is a match for this ticket |
|
296 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
297 | - if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
298 | - $reg_code[] = $reg->reg_code(); |
|
299 | - } |
|
300 | - } |
|
301 | - return implode(', ', $reg_code); |
|
302 | - } |
|
303 | - |
|
304 | - // do we have a specific reg_obj? Let's use it |
|
305 | - if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
306 | - return $this->_data->reg_obj->reg_code(); |
|
307 | - } |
|
308 | - |
|
309 | - // do we have a specific reg_obj? Let's use it |
|
310 | - if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
311 | - return $this->_data->reg_obj->reg_code(); |
|
312 | - } |
|
313 | - |
|
314 | - // not able to determine the single reg code so let's return a comma delimited list of reg codes. |
|
315 | - $reg_code = array(); |
|
316 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
317 | - if ($reg instanceof EE_Registration) { |
|
318 | - $reg_code[] = $reg->reg_code(); |
|
319 | - } |
|
320 | - } |
|
321 | - return implode(', ', $reg_code); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * returns the reg ID for the recipient depending on the context and whether the recipient has multiple |
|
327 | - * registrations or not. |
|
328 | - * |
|
329 | - * @return int|string |
|
330 | - */ |
|
331 | - protected function _get_reg_id() |
|
332 | - { |
|
333 | - |
|
334 | - // if only one related registration for the recipient then just return that reg code. |
|
335 | - if (count($this->_registrations_for_recipient) <= 1) { |
|
336 | - return $this->_recipient->reg_obj->ID(); |
|
337 | - } |
|
338 | - |
|
339 | - // k more than one registration so let's see if we can get specific to context |
|
340 | - // are we parsing event_list? |
|
341 | - if ($this->_data instanceof EE_Event) { |
|
342 | - $registration_ids = array(); |
|
343 | - // loop through registrations for recipient and see if there is a match for this event |
|
344 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
345 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
346 | - $registration_ids[] = $reg->ID(); |
|
347 | - } |
|
348 | - } |
|
349 | - return implode(', ', $registration_ids); |
|
350 | - } |
|
351 | - |
|
352 | - // are we parsing ticket list? |
|
353 | - if ($this->_data instanceof EE_Ticket) { |
|
354 | - $registration_ids = array(); |
|
355 | - // loop through each registration for recipient and see if there is a match for this ticket |
|
356 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
357 | - if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
358 | - $registration_ids = $reg->ID(); |
|
359 | - } |
|
360 | - } |
|
361 | - return implode(', ', $registration_ids); |
|
362 | - } |
|
363 | - |
|
364 | - // do we have a specific reg_obj? Let's use it |
|
365 | - if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
366 | - return $this->_data->reg_obj->ID(); |
|
367 | - } |
|
368 | - |
|
369 | - // not able to determine the single reg code so let's return a comma delimited list of reg codes. |
|
370 | - $registration_ids = array(); |
|
371 | - foreach ($this->_registrations_for_recipient as $reg) { |
|
372 | - if ($reg instanceof EE_Registration) { |
|
373 | - $registration_ids[] = $reg->ID(); |
|
374 | - } |
|
375 | - } |
|
376 | - return implode(', ', $registration_ids); |
|
377 | - } |
|
19 | + protected $_recipient; |
|
20 | + |
|
21 | + protected $_registrations_for_recipient; |
|
22 | + |
|
23 | + |
|
24 | + protected function _init_props() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso'); |
|
27 | + $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso'); |
|
28 | + $this->_shortcodes = array( |
|
29 | + '[RECIPIENT_FNAME]' => esc_html__( |
|
30 | + 'Parses to the first name of the recipient for the message.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + '[RECIPIENT_LNAME]' => esc_html__( |
|
34 | + 'Parses to the last name of the recipient for the message.', |
|
35 | + 'event_espresso' |
|
36 | + ), |
|
37 | + '[RECIPIENT_EMAIL]' => esc_html__( |
|
38 | + 'Parses to the email address of the recipient for the message.', |
|
39 | + 'event_espresso' |
|
40 | + ), |
|
41 | + '[RECIPIENT_REGISTRATION_ID]' => esc_html__( |
|
42 | + 'Parses to the registration ID of the recipient for the message.', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + '[RECIPIENT_REGISTRATION_CODE]' => esc_html__( |
|
46 | + 'Parses to the registration code of the recipient for the message.', |
|
47 | + 'event_espresso' |
|
48 | + ), |
|
49 | + '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__( |
|
50 | + 'Parses to a link for frontend editing of the registration for the recipient.', |
|
51 | + 'event_espresso' |
|
52 | + ), |
|
53 | + '[RECIPIENT_PHONE_NUMBER]' => esc_html__( |
|
54 | + 'The Phone Number for the recipient of the message.', |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + '[RECIPIENT_ADDRESS]' => esc_html__( |
|
58 | + 'The Address for the recipient of the message.', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + '[RECIPIENT_ADDRESS2]' => esc_html__( |
|
62 | + 'Whatever was in the address 2 field for the recipient of the message.', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + '[RECIPIENT_CITY]' => esc_html__( |
|
66 | + 'The city for the recipient of the message.', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + '[RECIPIENT_ZIP_PC]' => esc_html__( |
|
70 | + 'The ZIP (or Postal) Code for the recipient of the message.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + '[RECIPIENT_ADDRESS_STATE]' => esc_html__( |
|
74 | + 'The state/province for the recipient of the message.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + '[RECIPIENT_COUNTRY]' => esc_html__( |
|
78 | + 'The country for the recipient of the message.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + '[RECIPIENT_ANSWER_*]' => esc_html__( |
|
82 | + 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '[RECIPIENT_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
86 | + 'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient. Otherwise the value of 0 is printed.', |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + '[RECIPIENT_CANCELLATION_LINK]' => esc_html__( |
|
90 | + 'Generates a link that the recipient can use to cancel their registration.', |
|
91 | + 'event_espresso' |
|
92 | + ), |
|
93 | + '[RECIPIENT_CANCEL_CONFIRMATION_CODE]' => esc_html__( |
|
94 | + 'Generates the confirmation code that the recipient will need to cancel their registration.', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @access protected |
|
103 | + * @param string $shortcode the shortcode to be parsed. |
|
104 | + * @return string parsed shortcode |
|
105 | + * @throws EE_Error |
|
106 | + * @throws ReflectionException |
|
107 | + */ |
|
108 | + protected function _parser($shortcode) |
|
109 | + { |
|
110 | + |
|
111 | + // make sure we end up with a copy of the EE_Messages_Addressee object |
|
112 | + $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
113 | + $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
|
114 | + && is_array($this->_data) |
|
115 | + && isset($this->_data['data']) |
|
116 | + && $this->_data['data'] instanceof EE_Messages_Addressee |
|
117 | + ? $this->_data['data'] |
|
118 | + : $this->_recipient; |
|
119 | + $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
|
120 | + && ! empty($this->_extra_data['data']) |
|
121 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
122 | + ? $this->_extra_data['data'] |
|
123 | + : $this->_recipient; |
|
124 | + |
|
125 | + if (! $this->_recipient instanceof EE_Messages_Addressee) { |
|
126 | + return ''; |
|
127 | + } |
|
128 | + |
|
129 | + $attendee = $this->_recipient->att_obj; |
|
130 | + if (! $attendee instanceof EE_Attendee) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | + |
|
134 | + $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs']) |
|
135 | + ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs'] |
|
136 | + : array(); |
|
137 | + |
|
138 | + switch ($shortcode) { |
|
139 | + case '[RECIPIENT_FNAME]': |
|
140 | + return $attendee->fname(); |
|
141 | + |
|
142 | + case '[RECIPIENT_LNAME]': |
|
143 | + return $attendee->lname(); |
|
144 | + |
|
145 | + case '[RECIPIENT_EMAIL]': |
|
146 | + return $attendee->email(); |
|
147 | + |
|
148 | + case '[RECIPIENT_REGISTRATION_ID]': |
|
149 | + if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
150 | + return ''; |
|
151 | + } |
|
152 | + return $this->_get_reg_id(); |
|
153 | + |
|
154 | + case '[RECIPIENT_REGISTRATION_CODE]': |
|
155 | + if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
156 | + return ''; |
|
157 | + } |
|
158 | + return $this->_get_reg_code(); |
|
159 | + |
|
160 | + case '[RECIPIENT_EDIT_REGISTRATION_LINK]': |
|
161 | + if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
162 | + return ''; |
|
163 | + } |
|
164 | + return $this->_recipient->reg_obj->edit_attendee_information_url(); |
|
165 | + |
|
166 | + case '[RECIPIENT_PHONE_NUMBER]': |
|
167 | + return $attendee->phone(); |
|
168 | + |
|
169 | + case '[RECIPIENT_ADDRESS]': |
|
170 | + return $attendee->address(); |
|
171 | + |
|
172 | + case '[RECIPIENT_ADDRESS2]': |
|
173 | + return $attendee->address2(); |
|
174 | + |
|
175 | + case '[RECIPIENT_CITY]': |
|
176 | + return $attendee->city(); |
|
177 | + |
|
178 | + case '[RECIPIENT_ZIP_PC]': |
|
179 | + return $attendee->zip(); |
|
180 | + |
|
181 | + case '[RECIPIENT_ADDRESS_STATE]': |
|
182 | + $state_obj = $attendee->state_obj(); |
|
183 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
184 | + |
|
185 | + case '[RECIPIENT_COUNTRY]': |
|
186 | + $country_obj = $attendee->country_obj(); |
|
187 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
188 | + |
|
189 | + case '[RECIPIENT_TOTAL_AMOUNT_PAID]': |
|
190 | + return $this->_recipient->reg_obj instanceof EE_Registration |
|
191 | + ? $this->_recipient->reg_obj->pretty_paid() |
|
192 | + : 0; |
|
193 | + |
|
194 | + case '[RECIPIENT_CANCELLATION_LINK]': |
|
195 | + return $this->_recipient->reg_obj instanceof EE_Registration |
|
196 | + ? add_query_arg( |
|
197 | + [ 'e_reg_url_link' => $this->_recipient->reg_obj->reg_url_link() ], |
|
198 | + EE_Registry::instance()->CFG->core->cancel_page_url() |
|
199 | + ) |
|
200 | + : ''; |
|
201 | + |
|
202 | + case '[RECIPIENT_CANCEL_CONFIRMATION_CODE]': |
|
203 | + return $this->_recipient->reg_obj instanceof EE_Registration |
|
204 | + ? $this->_recipient->reg_obj->cancelRegistrationConfirmationCode() |
|
205 | + : ''; |
|
206 | + } |
|
207 | + |
|
208 | + if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) { |
|
209 | + $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode); |
|
210 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
211 | + |
|
212 | + |
|
213 | + // now let's figure out what question has this text |
|
214 | + if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
215 | + return ''; |
|
216 | + } |
|
217 | + |
|
218 | + foreach ($this->_recipient->questions as $ansid => $question) { |
|
219 | + if ( |
|
220 | + $question instanceof EE_Question |
|
221 | + && trim($question->display_text()) === trim($shortcode) |
|
222 | + && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]) |
|
223 | + ) { |
|
224 | + $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]; |
|
225 | + |
|
226 | + // what we show for the answer depends on the question type! |
|
227 | + switch ($question->get('QST_type')) { |
|
228 | + case EEM_Question::QST_type_state: |
|
229 | + $state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value')); |
|
230 | + $answer = $state instanceof EE_State ? $state->name() : ''; |
|
231 | + break; |
|
232 | + |
|
233 | + case EEM_Question::QST_type_country: |
|
234 | + $country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value')); |
|
235 | + $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
236 | + break; |
|
237 | + |
|
238 | + default: |
|
239 | + $answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
240 | + break; |
|
241 | + } |
|
242 | + |
|
243 | + return $answer; |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + return ''; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Returns the EE_Messages_Addressee object for the recipient. |
|
254 | + * |
|
255 | + * @since 4.5.0 |
|
256 | + * |
|
257 | + * @return EE_Messages_Addressee |
|
258 | + */ |
|
259 | + public function get_recipient() |
|
260 | + { |
|
261 | + return $this->_recipient; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * returns the reg code for the recipient depending on the context and whether the recipient has multiple |
|
267 | + * registrations or not. |
|
268 | + * |
|
269 | + * @return string |
|
270 | + */ |
|
271 | + protected function _get_reg_code() |
|
272 | + { |
|
273 | + |
|
274 | + // if only one related registration for the recipient then just return that reg code. |
|
275 | + if (count($this->_registrations_for_recipient) <= 1) { |
|
276 | + return $this->_recipient->reg_obj->reg_code(); |
|
277 | + } |
|
278 | + |
|
279 | + // k more than one registration so let's see if we can get specific to context |
|
280 | + // are we parsing event_list? |
|
281 | + if ($this->_data instanceof EE_Event) { |
|
282 | + $reg_code = array(); |
|
283 | + // loop through registrations for recipient and see if there is a match for this event |
|
284 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
285 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
286 | + $reg_code[] = $reg->reg_code(); |
|
287 | + } |
|
288 | + } |
|
289 | + return implode(', ', $reg_code); |
|
290 | + } |
|
291 | + |
|
292 | + // are we parsing ticket list? |
|
293 | + if ($this->_data instanceof EE_Ticket) { |
|
294 | + $reg_code = array(); |
|
295 | + // loop through each registration for recipient and see if there is a match for this ticket |
|
296 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
297 | + if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
298 | + $reg_code[] = $reg->reg_code(); |
|
299 | + } |
|
300 | + } |
|
301 | + return implode(', ', $reg_code); |
|
302 | + } |
|
303 | + |
|
304 | + // do we have a specific reg_obj? Let's use it |
|
305 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
306 | + return $this->_data->reg_obj->reg_code(); |
|
307 | + } |
|
308 | + |
|
309 | + // do we have a specific reg_obj? Let's use it |
|
310 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
311 | + return $this->_data->reg_obj->reg_code(); |
|
312 | + } |
|
313 | + |
|
314 | + // not able to determine the single reg code so let's return a comma delimited list of reg codes. |
|
315 | + $reg_code = array(); |
|
316 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
317 | + if ($reg instanceof EE_Registration) { |
|
318 | + $reg_code[] = $reg->reg_code(); |
|
319 | + } |
|
320 | + } |
|
321 | + return implode(', ', $reg_code); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * returns the reg ID for the recipient depending on the context and whether the recipient has multiple |
|
327 | + * registrations or not. |
|
328 | + * |
|
329 | + * @return int|string |
|
330 | + */ |
|
331 | + protected function _get_reg_id() |
|
332 | + { |
|
333 | + |
|
334 | + // if only one related registration for the recipient then just return that reg code. |
|
335 | + if (count($this->_registrations_for_recipient) <= 1) { |
|
336 | + return $this->_recipient->reg_obj->ID(); |
|
337 | + } |
|
338 | + |
|
339 | + // k more than one registration so let's see if we can get specific to context |
|
340 | + // are we parsing event_list? |
|
341 | + if ($this->_data instanceof EE_Event) { |
|
342 | + $registration_ids = array(); |
|
343 | + // loop through registrations for recipient and see if there is a match for this event |
|
344 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
345 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
346 | + $registration_ids[] = $reg->ID(); |
|
347 | + } |
|
348 | + } |
|
349 | + return implode(', ', $registration_ids); |
|
350 | + } |
|
351 | + |
|
352 | + // are we parsing ticket list? |
|
353 | + if ($this->_data instanceof EE_Ticket) { |
|
354 | + $registration_ids = array(); |
|
355 | + // loop through each registration for recipient and see if there is a match for this ticket |
|
356 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
357 | + if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
358 | + $registration_ids = $reg->ID(); |
|
359 | + } |
|
360 | + } |
|
361 | + return implode(', ', $registration_ids); |
|
362 | + } |
|
363 | + |
|
364 | + // do we have a specific reg_obj? Let's use it |
|
365 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
366 | + return $this->_data->reg_obj->ID(); |
|
367 | + } |
|
368 | + |
|
369 | + // not able to determine the single reg code so let's return a comma delimited list of reg codes. |
|
370 | + $registration_ids = array(); |
|
371 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
372 | + if ($reg instanceof EE_Registration) { |
|
373 | + $registration_ids[] = $reg->ID(); |
|
374 | + } |
|
375 | + } |
|
376 | + return implode(', ', $registration_ids); |
|
377 | + } |
|
378 | 378 | } |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | ? $this->_extra_data['data'] |
123 | 123 | : $this->_recipient; |
124 | 124 | |
125 | - if (! $this->_recipient instanceof EE_Messages_Addressee) { |
|
125 | + if ( ! $this->_recipient instanceof EE_Messages_Addressee) { |
|
126 | 126 | return ''; |
127 | 127 | } |
128 | 128 | |
129 | 129 | $attendee = $this->_recipient->att_obj; |
130 | - if (! $attendee instanceof EE_Attendee) { |
|
130 | + if ( ! $attendee instanceof EE_Attendee) { |
|
131 | 131 | return ''; |
132 | 132 | } |
133 | 133 | |
134 | - $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs']) |
|
135 | - ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs'] |
|
134 | + $this->_registrations_for_recipient = isset($this->_recipient->attendees[$attendee->ID()]['reg_objs']) |
|
135 | + ? $this->_recipient->attendees[$attendee->ID()]['reg_objs'] |
|
136 | 136 | : array(); |
137 | 137 | |
138 | 138 | switch ($shortcode) { |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | return $attendee->email(); |
147 | 147 | |
148 | 148 | case '[RECIPIENT_REGISTRATION_ID]': |
149 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
149 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
150 | 150 | return ''; |
151 | 151 | } |
152 | 152 | return $this->_get_reg_id(); |
153 | 153 | |
154 | 154 | case '[RECIPIENT_REGISTRATION_CODE]': |
155 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
155 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
156 | 156 | return ''; |
157 | 157 | } |
158 | 158 | return $this->_get_reg_code(); |
159 | 159 | |
160 | 160 | case '[RECIPIENT_EDIT_REGISTRATION_LINK]': |
161 | - if (! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
161 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
162 | 162 | return ''; |
163 | 163 | } |
164 | 164 | return $this->_recipient->reg_obj->edit_attendee_information_url(); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | case '[RECIPIENT_CANCELLATION_LINK]': |
195 | 195 | return $this->_recipient->reg_obj instanceof EE_Registration |
196 | 196 | ? add_query_arg( |
197 | - [ 'e_reg_url_link' => $this->_recipient->reg_obj->reg_url_link() ], |
|
197 | + ['e_reg_url_link' => $this->_recipient->reg_obj->reg_url_link()], |
|
198 | 198 | EE_Registry::instance()->CFG->core->cancel_page_url() |
199 | 199 | ) |
200 | 200 | : ''; |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | if ( |
220 | 220 | $question instanceof EE_Question |
221 | 221 | && trim($question->display_text()) === trim($shortcode) |
222 | - && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]) |
|
222 | + && isset($this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid]) |
|
223 | 223 | ) { |
224 | - $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]; |
|
224 | + $recipient_ansid = $this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid]; |
|
225 | 225 | |
226 | 226 | // what we show for the answer depends on the question type! |
227 | 227 | switch ($question->get('QST_type')) { |
@@ -20,206 +20,206 @@ |
||
20 | 20 | */ |
21 | 21 | interface FormHandlerInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * the absolute top level form section being used on the page |
|
25 | - * |
|
26 | - * @return EE_Form_Section_Proper |
|
27 | - */ |
|
28 | - public function form(); |
|
23 | + /** |
|
24 | + * the absolute top level form section being used on the page |
|
25 | + * |
|
26 | + * @return EE_Form_Section_Proper |
|
27 | + */ |
|
28 | + public function form(); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param EE_Form_Section_Proper $form |
|
34 | - */ |
|
35 | - public function setForm(EE_Form_Section_Proper $form); |
|
32 | + /** |
|
33 | + * @param EE_Form_Section_Proper $form |
|
34 | + */ |
|
35 | + public function setForm(EE_Form_Section_Proper $form); |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * if set to false, then this form has no displayable content, |
|
41 | - * and will only be used for processing data sent passed via GET or POST |
|
42 | - * |
|
43 | - * @return boolean |
|
44 | - */ |
|
45 | - public function displayable(); |
|
39 | + /** |
|
40 | + * if set to false, then this form has no displayable content, |
|
41 | + * and will only be used for processing data sent passed via GET or POST |
|
42 | + * |
|
43 | + * @return boolean |
|
44 | + */ |
|
45 | + public function displayable(); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @param boolean $displayable |
|
51 | - */ |
|
52 | - public function setDisplayable($displayable = false); |
|
49 | + /** |
|
50 | + * @param boolean $displayable |
|
51 | + */ |
|
52 | + public function setDisplayable($displayable = false); |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * a public name for the form that can be displayed on the frontend of a site |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function formName(); |
|
56 | + /** |
|
57 | + * a public name for the form that can be displayed on the frontend of a site |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function formName(); |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * a public name for the form that can be displayed, but only in the admin |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function adminName(); |
|
65 | + /** |
|
66 | + * a public name for the form that can be displayed, but only in the admin |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function adminName(); |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * a URL friendly string that can be used for identifying the form |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function slug(); |
|
74 | + /** |
|
75 | + * a URL friendly string that can be used for identifying the form |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function slug(); |
|
80 | 80 | |
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function submitBtnText(); |
|
83 | + /** |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function submitBtnText(); |
|
87 | 87 | |
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * @param string $submit_btn_text |
|
92 | - */ |
|
93 | - public function setSubmitBtnText($submit_btn_text); |
|
90 | + /** |
|
91 | + * @param string $submit_btn_text |
|
92 | + */ |
|
93 | + public function setSubmitBtnText($submit_btn_text); |
|
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function formAction(); |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function formAction(); |
|
101 | 101 | |
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @param string $form_action |
|
106 | - */ |
|
107 | - public function setFormAction($form_action); |
|
104 | + /** |
|
105 | + * @param string $form_action |
|
106 | + */ |
|
107 | + public function setFormAction($form_action); |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * @param array $form_args |
|
113 | - */ |
|
114 | - public function addFormActionArgs($form_args = array()); |
|
111 | + /** |
|
112 | + * @param array $form_args |
|
113 | + */ |
|
114 | + public function addFormActionArgs($form_args = array()); |
|
115 | 115 | |
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * if data regarding the form's state needs to be persisted, |
|
120 | - * then this method can be used to retrieve that data |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function formConfig(); |
|
118 | + /** |
|
119 | + * if data regarding the form's state needs to be persisted, |
|
120 | + * then this method can be used to retrieve that data |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function formConfig(); |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * if data regarding the form's state needs to be persisted, |
|
130 | - * then this method can be used for setting the persisted data locally |
|
131 | - * |
|
132 | - * @param string $form_config |
|
133 | - */ |
|
134 | - public function setFormConfig($form_config); |
|
128 | + /** |
|
129 | + * if data regarding the form's state needs to be persisted, |
|
130 | + * then this method can be used for setting the persisted data locally |
|
131 | + * |
|
132 | + * @param string $form_config |
|
133 | + */ |
|
134 | + public function setFormConfig($form_config); |
|
135 | 135 | |
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * called after the form is instantiated |
|
140 | - * and used for performing any logic that needs to occur early |
|
141 | - * before any of the other methods are called. |
|
142 | - * returns true if everything is ok to proceed, |
|
143 | - * and false if no further form logic should be implemented |
|
144 | - * |
|
145 | - * @return boolean |
|
146 | - */ |
|
147 | - public function initialize(); |
|
138 | + /** |
|
139 | + * called after the form is instantiated |
|
140 | + * and used for performing any logic that needs to occur early |
|
141 | + * before any of the other methods are called. |
|
142 | + * returns true if everything is ok to proceed, |
|
143 | + * and false if no further form logic should be implemented |
|
144 | + * |
|
145 | + * @return boolean |
|
146 | + */ |
|
147 | + public function initialize(); |
|
148 | 148 | |
149 | 149 | |
150 | 150 | |
151 | - /** |
|
152 | - * used for setting up css and js |
|
153 | - * |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function enqueueStylesAndScripts(); |
|
151 | + /** |
|
152 | + * used for setting up css and js |
|
153 | + * |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function enqueueStylesAndScripts(); |
|
157 | 157 | |
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * creates and returns the actual form |
|
162 | - * |
|
163 | - * @return EE_Form_Section_Proper |
|
164 | - */ |
|
165 | - public function generate(); |
|
160 | + /** |
|
161 | + * creates and returns the actual form |
|
162 | + * |
|
163 | + * @return EE_Form_Section_Proper |
|
164 | + */ |
|
165 | + public function generate(); |
|
166 | 166 | |
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
171 | - * returns a string of HTML that can be directly echoed in a template |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function display(); |
|
169 | + /** |
|
170 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
171 | + * returns a string of HTML that can be directly echoed in a template |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function display(); |
|
176 | 176 | |
177 | 177 | |
178 | 178 | |
179 | - /** |
|
180 | - * handles processing the form submission |
|
181 | - * returns true or false depending on whether the form was processed successfully or not |
|
182 | - * |
|
183 | - * @param array $submitted_form_data |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function process($submitted_form_data = array()); |
|
179 | + /** |
|
180 | + * handles processing the form submission |
|
181 | + * returns true or false depending on whether the form was processed successfully or not |
|
182 | + * |
|
183 | + * @param array $submitted_form_data |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function process($submitted_form_data = array()); |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
192 | - * |
|
193 | - * @param string $text |
|
194 | - * @return EE_Submit_Input |
|
195 | - */ |
|
196 | - public function generateSubmitButton($text = ''); |
|
190 | + /** |
|
191 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
192 | + * |
|
193 | + * @param string $text |
|
194 | + * @return EE_Submit_Input |
|
195 | + */ |
|
196 | + public function generateSubmitButton($text = ''); |
|
197 | 197 | |
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
202 | - * |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function appendSubmitButton(); |
|
200 | + /** |
|
201 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
202 | + * |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function appendSubmitButton(); |
|
206 | 206 | |
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
211 | - * |
|
212 | - * @param string $text |
|
213 | - * @return EE_Submit_Input |
|
214 | - */ |
|
215 | - public function generateCancelButton($text = ''); |
|
209 | + /** |
|
210 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
211 | + * |
|
212 | + * @param string $text |
|
213 | + * @return EE_Submit_Input |
|
214 | + */ |
|
215 | + public function generateCancelButton($text = ''); |
|
216 | 216 | |
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * appends a float clearing div onto end of form |
|
221 | - * |
|
222 | - * @return void |
|
223 | - */ |
|
224 | - public function clearFormButtonFloats(); |
|
219 | + /** |
|
220 | + * appends a float clearing div onto end of form |
|
221 | + * |
|
222 | + * @return void |
|
223 | + */ |
|
224 | + public function clearFormButtonFloats(); |
|
225 | 225 | } |
@@ -31,616 +31,616 @@ |
||
31 | 31 | */ |
32 | 32 | abstract class FormHandler implements FormHandlerInterface |
33 | 33 | { |
34 | - /** |
|
35 | - * will add opening and closing HTML form tags as well as a submit button |
|
36 | - */ |
|
37 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
38 | - |
|
39 | - /** |
|
40 | - * will add opening and closing HTML form tags but NOT a submit button |
|
41 | - */ |
|
42 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
43 | - |
|
44 | - /** |
|
45 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
46 | - */ |
|
47 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
48 | - |
|
49 | - /** |
|
50 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
51 | - */ |
|
52 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
53 | - |
|
54 | - /** |
|
55 | - * if set to false, then this form has no displayable content, |
|
56 | - * and will only be used for processing data sent passed via GET or POST |
|
57 | - * defaults to true ( ie: form has displayable content ) |
|
58 | - */ |
|
59 | - private bool $displayable = true; |
|
60 | - |
|
61 | - private string $form_name; |
|
62 | - |
|
63 | - private string $admin_name; |
|
64 | - |
|
65 | - private string $slug; |
|
66 | - |
|
67 | - private string $submit_btn_text; |
|
68 | - |
|
69 | - private string $form_action; |
|
70 | - |
|
71 | - /** |
|
72 | - * form params in key value pairs |
|
73 | - * can be added to form action URL or as hidden inputs |
|
74 | - */ |
|
75 | - private array $form_args = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * value of one of the string constant above |
|
79 | - */ |
|
80 | - private string $form_config; |
|
81 | - |
|
82 | - private bool $form_has_errors = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * the absolute top level form section being used on the page |
|
86 | - */ |
|
87 | - private ?EE_Form_Section_Proper $form = null; |
|
88 | - |
|
89 | - protected ?EE_Registry $registry = null; |
|
90 | - |
|
91 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Form constructor. |
|
96 | - * |
|
97 | - * @param string $form_name |
|
98 | - * @param string $admin_name |
|
99 | - * @param string $slug |
|
100 | - * @param string $form_action |
|
101 | - * @param string $form_config |
|
102 | - * @param EE_Registry|null $registry |
|
103 | - */ |
|
104 | - public function __construct( |
|
105 | - string $form_name, |
|
106 | - string $admin_name, |
|
107 | - string $slug, |
|
108 | - string $form_action = '', |
|
109 | - string $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | - ?EE_Registry $registry = null |
|
111 | - ) { |
|
112 | - $this->setFormName($form_name); |
|
113 | - $this->setAdminName($admin_name); |
|
114 | - $this->setSlug($slug); |
|
115 | - $this->setFormAction($form_action); |
|
116 | - $this->setFormConfig($form_config); |
|
117 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
118 | - $this->registry = $registry; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public static function getFormConfigConstants(): array |
|
126 | - { |
|
127 | - return [ |
|
128 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
129 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
130 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
131 | - FormHandler::DO_NOT_SETUP_FORM, |
|
132 | - ]; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param bool $for_display |
|
138 | - * @return EE_Form_Section_Proper |
|
139 | - * @throws EE_Error |
|
140 | - * @throws LogicException |
|
141 | - */ |
|
142 | - public function form($for_display = false) |
|
143 | - { |
|
144 | - if (! $this->formIsValid()) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - if ($for_display) { |
|
148 | - $form_config = $this->formConfig(); |
|
149 | - if ( |
|
150 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
151 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
152 | - ) { |
|
153 | - $this->appendSubmitButton(); |
|
154 | - $this->clearFormButtonFloats(); |
|
155 | - } |
|
156 | - } |
|
157 | - return $this->form; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return bool |
|
163 | - * @throws LogicException |
|
164 | - */ |
|
165 | - public function formIsValid(): bool |
|
166 | - { |
|
167 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
168 | - return true; |
|
169 | - } |
|
170 | - $form = apply_filters( |
|
171 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
172 | - $this->generate(), |
|
173 | - $this |
|
174 | - ); |
|
175 | - if ($this->verifyForm($form)) { |
|
176 | - $this->setForm($form); |
|
177 | - } |
|
178 | - return true; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param EE_Form_Section_Proper|null $form |
|
184 | - * @return bool |
|
185 | - * @throws LogicException |
|
186 | - */ |
|
187 | - public function verifyForm(?EE_Form_Section_Proper $form = null): bool |
|
188 | - { |
|
189 | - $form = $form !== null ? $form : $this->form; |
|
190 | - if ($form instanceof EE_Form_Section_Proper) { |
|
191 | - return true; |
|
192 | - } |
|
193 | - throw new LogicException( |
|
194 | - sprintf( |
|
195 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
196 | - $this->form_name, |
|
197 | - var_export($form, true) |
|
198 | - ) |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @param EE_Form_Section_Proper $form |
|
205 | - */ |
|
206 | - public function setForm(EE_Form_Section_Proper $form) |
|
207 | - { |
|
208 | - $this->form = $form; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @return bool |
|
214 | - */ |
|
215 | - public function displayable(): bool |
|
216 | - { |
|
217 | - return $this->displayable; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param bool|int|string $displayable |
|
223 | - */ |
|
224 | - public function setDisplayable($displayable = false) |
|
225 | - { |
|
226 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * a public name for the form that can be displayed on the frontend of a site |
|
232 | - * |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function formName(): string |
|
236 | - { |
|
237 | - return $this->form_name; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $form_name |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - */ |
|
245 | - public function setFormName(string $form_name) |
|
246 | - { |
|
247 | - $this->form_name = $form_name; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * a public name for the form that can be displayed, but only in the admin |
|
253 | - * |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public function adminName(): string |
|
257 | - { |
|
258 | - return $this->admin_name; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param string $admin_name |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - */ |
|
266 | - public function setAdminName($admin_name) |
|
267 | - { |
|
268 | - if (! is_string($admin_name)) { |
|
269 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
270 | - } |
|
271 | - $this->admin_name = $admin_name; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * a URL friendly string that can be used for identifying the form |
|
277 | - * |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function slug() |
|
281 | - { |
|
282 | - return $this->slug; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param string $slug |
|
288 | - * @throws InvalidDataTypeException |
|
289 | - */ |
|
290 | - public function setSlug($slug) |
|
291 | - { |
|
292 | - if (! is_string($slug)) { |
|
293 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
294 | - } |
|
295 | - $this->slug = $slug; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function submitBtnText() |
|
303 | - { |
|
304 | - return $this->submit_btn_text; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param string $submit_btn_text |
|
310 | - * @throws InvalidDataTypeException |
|
311 | - * @throws InvalidArgumentException |
|
312 | - */ |
|
313 | - public function setSubmitBtnText($submit_btn_text) |
|
314 | - { |
|
315 | - if (! is_string($submit_btn_text)) { |
|
316 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
317 | - } |
|
318 | - if (empty($submit_btn_text)) { |
|
319 | - throw new InvalidArgumentException( |
|
320 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
321 | - ); |
|
322 | - } |
|
323 | - $this->submit_btn_text = $submit_btn_text; |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function formAction() |
|
331 | - { |
|
332 | - return ! empty($this->form_args) |
|
333 | - ? add_query_arg($this->form_args, $this->form_action) |
|
334 | - : $this->form_action; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $form_action |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - */ |
|
342 | - public function setFormAction($form_action) |
|
343 | - { |
|
344 | - if (! is_string($form_action)) { |
|
345 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
346 | - } |
|
347 | - if (empty($form_action)) { |
|
348 | - $request = LoaderFactory::getShared(RequestInterface::class); |
|
349 | - $form_action = $request instanceof RequestInterface |
|
350 | - ? $request->requestUri() |
|
351 | - : ''; |
|
352 | - } |
|
353 | - $this->form_action = $form_action; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param array $form_args |
|
359 | - * @throws InvalidDataTypeException |
|
360 | - * @throws InvalidArgumentException |
|
361 | - */ |
|
362 | - public function addFormActionArgs($form_args = []) |
|
363 | - { |
|
364 | - if (is_object($form_args)) { |
|
365 | - throw new InvalidDataTypeException( |
|
366 | - '$form_args', |
|
367 | - $form_args, |
|
368 | - 'anything other than an object was expected.' |
|
369 | - ); |
|
370 | - } |
|
371 | - if (empty($form_args)) { |
|
372 | - throw new InvalidArgumentException( |
|
373 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
374 | - ); |
|
375 | - } |
|
376 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - public function formConfig() |
|
384 | - { |
|
385 | - return $this->form_config; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @param string $form_config |
|
391 | - * @throws DomainException |
|
392 | - */ |
|
393 | - public function setFormConfig($form_config) |
|
394 | - { |
|
395 | - if ( |
|
396 | - ! in_array( |
|
397 | - $form_config, |
|
398 | - [ |
|
399 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
400 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
401 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
402 | - FormHandler::DO_NOT_SETUP_FORM, |
|
403 | - ], |
|
404 | - true |
|
405 | - ) |
|
406 | - ) { |
|
407 | - throw new DomainException( |
|
408 | - sprintf( |
|
409 | - esc_html__( |
|
410 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
411 | - 'event_espresso' |
|
412 | - ), |
|
413 | - $form_config |
|
414 | - ) |
|
415 | - ); |
|
416 | - } |
|
417 | - $this->form_config = $form_config; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * called after the form is instantiated |
|
423 | - * and used for performing any logic that needs to occur early |
|
424 | - * before any of the other methods are called. |
|
425 | - * returns true if everything is ok to proceed, |
|
426 | - * and false if no further form logic should be implemented |
|
427 | - * |
|
428 | - * @return boolean |
|
429 | - */ |
|
430 | - public function initialize() |
|
431 | - { |
|
432 | - $this->form_has_errors = EE_Error::has_error(true); |
|
433 | - return true; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * used for setting up css and js |
|
439 | - * |
|
440 | - * @return void |
|
441 | - * @throws LogicException |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function enqueueStylesAndScripts() |
|
445 | - { |
|
446 | - $this->form()->enqueue_js(); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * creates and returns the actual form |
|
452 | - * |
|
453 | - * @return EE_Form_Section_Proper |
|
454 | - */ |
|
455 | - abstract public function generate(); |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
460 | - * |
|
461 | - * @param string $text |
|
462 | - * @return EE_Submit_Input |
|
463 | - */ |
|
464 | - public function generateSubmitButton($text = '') |
|
465 | - { |
|
466 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
467 | - return new EE_Submit_Input( |
|
468 | - [ |
|
469 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
470 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
471 | - 'html_class' => 'ee-form-submit', |
|
472 | - 'html_label' => ' ', |
|
473 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
474 | - 'default' => $text, |
|
475 | - ] |
|
476 | - ); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
482 | - * |
|
483 | - * @param string $text |
|
484 | - * @return void |
|
485 | - * @throws EE_Error |
|
486 | - */ |
|
487 | - public function appendSubmitButton($text = '') |
|
488 | - { |
|
489 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
490 | - return; |
|
491 | - } |
|
492 | - $this->form->add_subsections( |
|
493 | - [$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)], |
|
494 | - null, |
|
495 | - false |
|
496 | - ); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
502 | - * |
|
503 | - * @param string $text |
|
504 | - * @return EE_Submit_Input |
|
505 | - */ |
|
506 | - public function generateCancelButton($text = '') |
|
507 | - { |
|
508 | - $cancel_button = new EE_Submit_Input( |
|
509 | - [ |
|
510 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
511 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
512 | - 'html_class' => 'ee-cancel-form', |
|
513 | - 'html_label' => ' ', |
|
514 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
515 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
516 | - ] |
|
517 | - ); |
|
518 | - $cancel_button->set_button_css_attributes(false); |
|
519 | - return $cancel_button; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * appends a float clearing div onto end of form |
|
525 | - * |
|
526 | - * @return void |
|
527 | - * @throws EE_Error |
|
528 | - */ |
|
529 | - public function clearFormButtonFloats() |
|
530 | - { |
|
531 | - $this->form->add_subsections( |
|
532 | - [ |
|
533 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
534 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
535 | - ), |
|
536 | - ], |
|
537 | - null, |
|
538 | - false |
|
539 | - ); |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
545 | - * returns a string of HTML that can be directly echoed in a template |
|
546 | - * |
|
547 | - * @return string |
|
548 | - * @throws InvalidArgumentException |
|
549 | - * @throws InvalidInterfaceException |
|
550 | - * @throws InvalidDataTypeException |
|
551 | - * @throws LogicException |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function display() |
|
555 | - { |
|
556 | - $form_html = apply_filters( |
|
557 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
558 | - '' |
|
559 | - ); |
|
560 | - $form_config = $this->formConfig(); |
|
561 | - if ( |
|
562 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
563 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
564 | - ) { |
|
565 | - $additional_props = $this->requiresMultipartEnctype() |
|
566 | - ? ' enctype="multipart/form-data"' |
|
567 | - : ''; |
|
568 | - $form_html .= $this->form()->form_open( |
|
569 | - $this->formAction(), |
|
570 | - 'POST', |
|
571 | - $additional_props |
|
572 | - ); |
|
573 | - } |
|
574 | - $form_html .= $this->form(true)->get_html(); |
|
575 | - if ( |
|
576 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
577 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
578 | - ) { |
|
579 | - $form_html .= $this->form()->form_close(); |
|
580 | - } |
|
581 | - $form_html .= apply_filters( |
|
582 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
583 | - '' |
|
584 | - ); |
|
585 | - return $form_html; |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
591 | - * |
|
592 | - * @return bool |
|
593 | - * @throws EE_Error |
|
594 | - * @since 4.9.80.p |
|
595 | - */ |
|
596 | - public function requiresMultipartEnctype(): bool |
|
597 | - { |
|
598 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
599 | - if ($input instanceof EE_File_Input) { |
|
600 | - return true; |
|
601 | - } |
|
602 | - } |
|
603 | - return false; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * handles processing the form submission |
|
609 | - * returns true or false depending on whether the form was processed successfully or not |
|
610 | - * |
|
611 | - * @param array $submitted_form_data |
|
612 | - * @return array |
|
613 | - * @throws InvalidArgumentException |
|
614 | - * @throws InvalidInterfaceException |
|
615 | - * @throws InvalidDataTypeException |
|
616 | - * @throws EE_Error |
|
617 | - * @throws LogicException |
|
618 | - * @throws InvalidFormSubmissionException |
|
619 | - */ |
|
620 | - public function process($submitted_form_data = []) |
|
621 | - { |
|
622 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
623 | - throw new InvalidFormSubmissionException($this->form_name); |
|
624 | - } |
|
625 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
626 | - if (! $this->form()->is_valid()) { |
|
627 | - throw new InvalidFormSubmissionException( |
|
628 | - $this->form_name, |
|
629 | - sprintf( |
|
630 | - esc_html__( |
|
631 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
632 | - 'event_espresso' |
|
633 | - ), |
|
634 | - $this->form_name, |
|
635 | - '<br />', |
|
636 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
637 | - ) |
|
638 | - ); |
|
639 | - } |
|
640 | - return (array) apply_filters( |
|
641 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
642 | - $this->form()->valid_data(), |
|
643 | - $this |
|
644 | - ); |
|
645 | - } |
|
34 | + /** |
|
35 | + * will add opening and closing HTML form tags as well as a submit button |
|
36 | + */ |
|
37 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
38 | + |
|
39 | + /** |
|
40 | + * will add opening and closing HTML form tags but NOT a submit button |
|
41 | + */ |
|
42 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
43 | + |
|
44 | + /** |
|
45 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
46 | + */ |
|
47 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
48 | + |
|
49 | + /** |
|
50 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
51 | + */ |
|
52 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
53 | + |
|
54 | + /** |
|
55 | + * if set to false, then this form has no displayable content, |
|
56 | + * and will only be used for processing data sent passed via GET or POST |
|
57 | + * defaults to true ( ie: form has displayable content ) |
|
58 | + */ |
|
59 | + private bool $displayable = true; |
|
60 | + |
|
61 | + private string $form_name; |
|
62 | + |
|
63 | + private string $admin_name; |
|
64 | + |
|
65 | + private string $slug; |
|
66 | + |
|
67 | + private string $submit_btn_text; |
|
68 | + |
|
69 | + private string $form_action; |
|
70 | + |
|
71 | + /** |
|
72 | + * form params in key value pairs |
|
73 | + * can be added to form action URL or as hidden inputs |
|
74 | + */ |
|
75 | + private array $form_args = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * value of one of the string constant above |
|
79 | + */ |
|
80 | + private string $form_config; |
|
81 | + |
|
82 | + private bool $form_has_errors = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * the absolute top level form section being used on the page |
|
86 | + */ |
|
87 | + private ?EE_Form_Section_Proper $form = null; |
|
88 | + |
|
89 | + protected ?EE_Registry $registry = null; |
|
90 | + |
|
91 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Form constructor. |
|
96 | + * |
|
97 | + * @param string $form_name |
|
98 | + * @param string $admin_name |
|
99 | + * @param string $slug |
|
100 | + * @param string $form_action |
|
101 | + * @param string $form_config |
|
102 | + * @param EE_Registry|null $registry |
|
103 | + */ |
|
104 | + public function __construct( |
|
105 | + string $form_name, |
|
106 | + string $admin_name, |
|
107 | + string $slug, |
|
108 | + string $form_action = '', |
|
109 | + string $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | + ?EE_Registry $registry = null |
|
111 | + ) { |
|
112 | + $this->setFormName($form_name); |
|
113 | + $this->setAdminName($admin_name); |
|
114 | + $this->setSlug($slug); |
|
115 | + $this->setFormAction($form_action); |
|
116 | + $this->setFormConfig($form_config); |
|
117 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
118 | + $this->registry = $registry; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public static function getFormConfigConstants(): array |
|
126 | + { |
|
127 | + return [ |
|
128 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
129 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
130 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
131 | + FormHandler::DO_NOT_SETUP_FORM, |
|
132 | + ]; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param bool $for_display |
|
138 | + * @return EE_Form_Section_Proper |
|
139 | + * @throws EE_Error |
|
140 | + * @throws LogicException |
|
141 | + */ |
|
142 | + public function form($for_display = false) |
|
143 | + { |
|
144 | + if (! $this->formIsValid()) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + if ($for_display) { |
|
148 | + $form_config = $this->formConfig(); |
|
149 | + if ( |
|
150 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
151 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
152 | + ) { |
|
153 | + $this->appendSubmitButton(); |
|
154 | + $this->clearFormButtonFloats(); |
|
155 | + } |
|
156 | + } |
|
157 | + return $this->form; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return bool |
|
163 | + * @throws LogicException |
|
164 | + */ |
|
165 | + public function formIsValid(): bool |
|
166 | + { |
|
167 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
168 | + return true; |
|
169 | + } |
|
170 | + $form = apply_filters( |
|
171 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
172 | + $this->generate(), |
|
173 | + $this |
|
174 | + ); |
|
175 | + if ($this->verifyForm($form)) { |
|
176 | + $this->setForm($form); |
|
177 | + } |
|
178 | + return true; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param EE_Form_Section_Proper|null $form |
|
184 | + * @return bool |
|
185 | + * @throws LogicException |
|
186 | + */ |
|
187 | + public function verifyForm(?EE_Form_Section_Proper $form = null): bool |
|
188 | + { |
|
189 | + $form = $form !== null ? $form : $this->form; |
|
190 | + if ($form instanceof EE_Form_Section_Proper) { |
|
191 | + return true; |
|
192 | + } |
|
193 | + throw new LogicException( |
|
194 | + sprintf( |
|
195 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
196 | + $this->form_name, |
|
197 | + var_export($form, true) |
|
198 | + ) |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @param EE_Form_Section_Proper $form |
|
205 | + */ |
|
206 | + public function setForm(EE_Form_Section_Proper $form) |
|
207 | + { |
|
208 | + $this->form = $form; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @return bool |
|
214 | + */ |
|
215 | + public function displayable(): bool |
|
216 | + { |
|
217 | + return $this->displayable; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @param bool|int|string $displayable |
|
223 | + */ |
|
224 | + public function setDisplayable($displayable = false) |
|
225 | + { |
|
226 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * a public name for the form that can be displayed on the frontend of a site |
|
232 | + * |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function formName(): string |
|
236 | + { |
|
237 | + return $this->form_name; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $form_name |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + */ |
|
245 | + public function setFormName(string $form_name) |
|
246 | + { |
|
247 | + $this->form_name = $form_name; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * a public name for the form that can be displayed, but only in the admin |
|
253 | + * |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public function adminName(): string |
|
257 | + { |
|
258 | + return $this->admin_name; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param string $admin_name |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + */ |
|
266 | + public function setAdminName($admin_name) |
|
267 | + { |
|
268 | + if (! is_string($admin_name)) { |
|
269 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
270 | + } |
|
271 | + $this->admin_name = $admin_name; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * a URL friendly string that can be used for identifying the form |
|
277 | + * |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function slug() |
|
281 | + { |
|
282 | + return $this->slug; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param string $slug |
|
288 | + * @throws InvalidDataTypeException |
|
289 | + */ |
|
290 | + public function setSlug($slug) |
|
291 | + { |
|
292 | + if (! is_string($slug)) { |
|
293 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
294 | + } |
|
295 | + $this->slug = $slug; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function submitBtnText() |
|
303 | + { |
|
304 | + return $this->submit_btn_text; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param string $submit_btn_text |
|
310 | + * @throws InvalidDataTypeException |
|
311 | + * @throws InvalidArgumentException |
|
312 | + */ |
|
313 | + public function setSubmitBtnText($submit_btn_text) |
|
314 | + { |
|
315 | + if (! is_string($submit_btn_text)) { |
|
316 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
317 | + } |
|
318 | + if (empty($submit_btn_text)) { |
|
319 | + throw new InvalidArgumentException( |
|
320 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
321 | + ); |
|
322 | + } |
|
323 | + $this->submit_btn_text = $submit_btn_text; |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function formAction() |
|
331 | + { |
|
332 | + return ! empty($this->form_args) |
|
333 | + ? add_query_arg($this->form_args, $this->form_action) |
|
334 | + : $this->form_action; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $form_action |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + */ |
|
342 | + public function setFormAction($form_action) |
|
343 | + { |
|
344 | + if (! is_string($form_action)) { |
|
345 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
346 | + } |
|
347 | + if (empty($form_action)) { |
|
348 | + $request = LoaderFactory::getShared(RequestInterface::class); |
|
349 | + $form_action = $request instanceof RequestInterface |
|
350 | + ? $request->requestUri() |
|
351 | + : ''; |
|
352 | + } |
|
353 | + $this->form_action = $form_action; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param array $form_args |
|
359 | + * @throws InvalidDataTypeException |
|
360 | + * @throws InvalidArgumentException |
|
361 | + */ |
|
362 | + public function addFormActionArgs($form_args = []) |
|
363 | + { |
|
364 | + if (is_object($form_args)) { |
|
365 | + throw new InvalidDataTypeException( |
|
366 | + '$form_args', |
|
367 | + $form_args, |
|
368 | + 'anything other than an object was expected.' |
|
369 | + ); |
|
370 | + } |
|
371 | + if (empty($form_args)) { |
|
372 | + throw new InvalidArgumentException( |
|
373 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
374 | + ); |
|
375 | + } |
|
376 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + public function formConfig() |
|
384 | + { |
|
385 | + return $this->form_config; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @param string $form_config |
|
391 | + * @throws DomainException |
|
392 | + */ |
|
393 | + public function setFormConfig($form_config) |
|
394 | + { |
|
395 | + if ( |
|
396 | + ! in_array( |
|
397 | + $form_config, |
|
398 | + [ |
|
399 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
400 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
401 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
402 | + FormHandler::DO_NOT_SETUP_FORM, |
|
403 | + ], |
|
404 | + true |
|
405 | + ) |
|
406 | + ) { |
|
407 | + throw new DomainException( |
|
408 | + sprintf( |
|
409 | + esc_html__( |
|
410 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
411 | + 'event_espresso' |
|
412 | + ), |
|
413 | + $form_config |
|
414 | + ) |
|
415 | + ); |
|
416 | + } |
|
417 | + $this->form_config = $form_config; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * called after the form is instantiated |
|
423 | + * and used for performing any logic that needs to occur early |
|
424 | + * before any of the other methods are called. |
|
425 | + * returns true if everything is ok to proceed, |
|
426 | + * and false if no further form logic should be implemented |
|
427 | + * |
|
428 | + * @return boolean |
|
429 | + */ |
|
430 | + public function initialize() |
|
431 | + { |
|
432 | + $this->form_has_errors = EE_Error::has_error(true); |
|
433 | + return true; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * used for setting up css and js |
|
439 | + * |
|
440 | + * @return void |
|
441 | + * @throws LogicException |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function enqueueStylesAndScripts() |
|
445 | + { |
|
446 | + $this->form()->enqueue_js(); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * creates and returns the actual form |
|
452 | + * |
|
453 | + * @return EE_Form_Section_Proper |
|
454 | + */ |
|
455 | + abstract public function generate(); |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
460 | + * |
|
461 | + * @param string $text |
|
462 | + * @return EE_Submit_Input |
|
463 | + */ |
|
464 | + public function generateSubmitButton($text = '') |
|
465 | + { |
|
466 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
467 | + return new EE_Submit_Input( |
|
468 | + [ |
|
469 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
470 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
471 | + 'html_class' => 'ee-form-submit', |
|
472 | + 'html_label' => ' ', |
|
473 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
474 | + 'default' => $text, |
|
475 | + ] |
|
476 | + ); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
482 | + * |
|
483 | + * @param string $text |
|
484 | + * @return void |
|
485 | + * @throws EE_Error |
|
486 | + */ |
|
487 | + public function appendSubmitButton($text = '') |
|
488 | + { |
|
489 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
490 | + return; |
|
491 | + } |
|
492 | + $this->form->add_subsections( |
|
493 | + [$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)], |
|
494 | + null, |
|
495 | + false |
|
496 | + ); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
502 | + * |
|
503 | + * @param string $text |
|
504 | + * @return EE_Submit_Input |
|
505 | + */ |
|
506 | + public function generateCancelButton($text = '') |
|
507 | + { |
|
508 | + $cancel_button = new EE_Submit_Input( |
|
509 | + [ |
|
510 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
511 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
512 | + 'html_class' => 'ee-cancel-form', |
|
513 | + 'html_label' => ' ', |
|
514 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
515 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
516 | + ] |
|
517 | + ); |
|
518 | + $cancel_button->set_button_css_attributes(false); |
|
519 | + return $cancel_button; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * appends a float clearing div onto end of form |
|
525 | + * |
|
526 | + * @return void |
|
527 | + * @throws EE_Error |
|
528 | + */ |
|
529 | + public function clearFormButtonFloats() |
|
530 | + { |
|
531 | + $this->form->add_subsections( |
|
532 | + [ |
|
533 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
534 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
535 | + ), |
|
536 | + ], |
|
537 | + null, |
|
538 | + false |
|
539 | + ); |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
545 | + * returns a string of HTML that can be directly echoed in a template |
|
546 | + * |
|
547 | + * @return string |
|
548 | + * @throws InvalidArgumentException |
|
549 | + * @throws InvalidInterfaceException |
|
550 | + * @throws InvalidDataTypeException |
|
551 | + * @throws LogicException |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function display() |
|
555 | + { |
|
556 | + $form_html = apply_filters( |
|
557 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
558 | + '' |
|
559 | + ); |
|
560 | + $form_config = $this->formConfig(); |
|
561 | + if ( |
|
562 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
563 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
564 | + ) { |
|
565 | + $additional_props = $this->requiresMultipartEnctype() |
|
566 | + ? ' enctype="multipart/form-data"' |
|
567 | + : ''; |
|
568 | + $form_html .= $this->form()->form_open( |
|
569 | + $this->formAction(), |
|
570 | + 'POST', |
|
571 | + $additional_props |
|
572 | + ); |
|
573 | + } |
|
574 | + $form_html .= $this->form(true)->get_html(); |
|
575 | + if ( |
|
576 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
577 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
578 | + ) { |
|
579 | + $form_html .= $this->form()->form_close(); |
|
580 | + } |
|
581 | + $form_html .= apply_filters( |
|
582 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
583 | + '' |
|
584 | + ); |
|
585 | + return $form_html; |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
591 | + * |
|
592 | + * @return bool |
|
593 | + * @throws EE_Error |
|
594 | + * @since 4.9.80.p |
|
595 | + */ |
|
596 | + public function requiresMultipartEnctype(): bool |
|
597 | + { |
|
598 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
599 | + if ($input instanceof EE_File_Input) { |
|
600 | + return true; |
|
601 | + } |
|
602 | + } |
|
603 | + return false; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * handles processing the form submission |
|
609 | + * returns true or false depending on whether the form was processed successfully or not |
|
610 | + * |
|
611 | + * @param array $submitted_form_data |
|
612 | + * @return array |
|
613 | + * @throws InvalidArgumentException |
|
614 | + * @throws InvalidInterfaceException |
|
615 | + * @throws InvalidDataTypeException |
|
616 | + * @throws EE_Error |
|
617 | + * @throws LogicException |
|
618 | + * @throws InvalidFormSubmissionException |
|
619 | + */ |
|
620 | + public function process($submitted_form_data = []) |
|
621 | + { |
|
622 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
623 | + throw new InvalidFormSubmissionException($this->form_name); |
|
624 | + } |
|
625 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
626 | + if (! $this->form()->is_valid()) { |
|
627 | + throw new InvalidFormSubmissionException( |
|
628 | + $this->form_name, |
|
629 | + sprintf( |
|
630 | + esc_html__( |
|
631 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
632 | + 'event_espresso' |
|
633 | + ), |
|
634 | + $this->form_name, |
|
635 | + '<br />', |
|
636 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
637 | + ) |
|
638 | + ); |
|
639 | + } |
|
640 | + return (array) apply_filters( |
|
641 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
642 | + $this->form()->valid_data(), |
|
643 | + $this |
|
644 | + ); |
|
645 | + } |
|
646 | 646 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function form($for_display = false) |
143 | 143 | { |
144 | - if (! $this->formIsValid()) { |
|
144 | + if ( ! $this->formIsValid()) { |
|
145 | 145 | return null; |
146 | 146 | } |
147 | 147 | if ($for_display) { |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function setAdminName($admin_name) |
267 | 267 | { |
268 | - if (! is_string($admin_name)) { |
|
268 | + if ( ! is_string($admin_name)) { |
|
269 | 269 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
270 | 270 | } |
271 | 271 | $this->admin_name = $admin_name; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function setSlug($slug) |
291 | 291 | { |
292 | - if (! is_string($slug)) { |
|
292 | + if ( ! is_string($slug)) { |
|
293 | 293 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
294 | 294 | } |
295 | 295 | $this->slug = $slug; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | */ |
313 | 313 | public function setSubmitBtnText($submit_btn_text) |
314 | 314 | { |
315 | - if (! is_string($submit_btn_text)) { |
|
315 | + if ( ! is_string($submit_btn_text)) { |
|
316 | 316 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
317 | 317 | } |
318 | 318 | if (empty($submit_btn_text)) { |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function setFormAction($form_action) |
343 | 343 | { |
344 | - if (! is_string($form_action)) { |
|
344 | + if ( ! is_string($form_action)) { |
|
345 | 345 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
346 | 346 | } |
347 | 347 | if (empty($form_action)) { |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
467 | 467 | return new EE_Submit_Input( |
468 | 468 | [ |
469 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
470 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
469 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
470 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
471 | 471 | 'html_class' => 'ee-form-submit', |
472 | 472 | 'html_label' => ' ', |
473 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
473 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
474 | 474 | 'default' => $text, |
475 | 475 | ] |
476 | 476 | ); |
@@ -486,11 +486,11 @@ discard block |
||
486 | 486 | */ |
487 | 487 | public function appendSubmitButton($text = '') |
488 | 488 | { |
489 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
489 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | $this->form->add_subsections( |
493 | - [$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)], |
|
493 | + [$this->slug().'-submit-btn' => $this->generateSubmitButton($text)], |
|
494 | 494 | null, |
495 | 495 | false |
496 | 496 | ); |
@@ -507,11 +507,11 @@ discard block |
||
507 | 507 | { |
508 | 508 | $cancel_button = new EE_Submit_Input( |
509 | 509 | [ |
510 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
511 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
510 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
511 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
512 | 512 | 'html_class' => 'ee-cancel-form', |
513 | 513 | 'html_label' => ' ', |
514 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
514 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
515 | 515 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
516 | 516 | ] |
517 | 517 | ); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | $this->form->add_subsections( |
532 | 532 | [ |
533 | 533 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
534 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
534 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
535 | 535 | ), |
536 | 536 | ], |
537 | 537 | null, |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | */ |
554 | 554 | public function display() |
555 | 555 | { |
556 | - $form_html = apply_filters( |
|
556 | + $form_html = apply_filters( |
|
557 | 557 | 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
558 | 558 | '' |
559 | 559 | ); |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | $additional_props = $this->requiresMultipartEnctype() |
566 | 566 | ? ' enctype="multipart/form-data"' |
567 | 567 | : ''; |
568 | - $form_html .= $this->form()->form_open( |
|
568 | + $form_html .= $this->form()->form_open( |
|
569 | 569 | $this->formAction(), |
570 | 570 | 'POST', |
571 | 571 | $additional_props |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | */ |
620 | 620 | public function process($submitted_form_data = []) |
621 | 621 | { |
622 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
622 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
623 | 623 | throw new InvalidFormSubmissionException($this->form_name); |
624 | 624 | } |
625 | 625 | $this->form(true)->receive_form_submission($submitted_form_data); |
626 | - if (! $this->form()->is_valid()) { |
|
626 | + if ( ! $this->form()->is_valid()) { |
|
627 | 627 | throw new InvalidFormSubmissionException( |
628 | 628 | $this->form_name, |
629 | 629 | sprintf( |
@@ -11,176 +11,176 @@ discard block |
||
11 | 11 | */ |
12 | 12 | abstract class EE_Form_Section_Layout_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Form section to lay out |
|
16 | - * |
|
17 | - * @var EE_Form_Section_Proper |
|
18 | - */ |
|
19 | - protected $_form_section; |
|
20 | - |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * __construct |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * The form section on which this strategy is to perform |
|
34 | - * |
|
35 | - * @param EE_Form_Section_Proper $form |
|
36 | - */ |
|
37 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
38 | - { |
|
39 | - $this->_form_section = $form; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return EE_Form_Section_Proper |
|
46 | - */ |
|
47 | - public function form_section() |
|
48 | - { |
|
49 | - return $this->_form_section; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
56 | - * this form. |
|
57 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
58 | - * proper subsections. |
|
59 | - * Returns the HTML |
|
60 | - * |
|
61 | - * @return string HTML for displaying |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public function layout_form() |
|
65 | - { |
|
66 | - $html = ''; |
|
67 | - // layout_form_begin |
|
68 | - $html .= apply_filters( |
|
69 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
70 | - $this->layout_form_begin(), |
|
71 | - $this->_form_section |
|
72 | - ); |
|
73 | - // layout_form_loop |
|
74 | - $html .= apply_filters( |
|
75 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
76 | - $this->layout_form_loop(), |
|
77 | - $this->_form_section |
|
78 | - ); |
|
79 | - // layout_form_end |
|
80 | - $html .= apply_filters( |
|
81 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
82 | - $this->layout_form_end(), |
|
83 | - $this->_form_section |
|
84 | - ); |
|
85 | - return $this->add_form_section_hooks_and_filters($html); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return string |
|
92 | - * @throws EE_Error |
|
93 | - */ |
|
94 | - public function layout_form_loop() |
|
95 | - { |
|
96 | - $html = ''; |
|
97 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
98 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
99 | - $html .= apply_filters( |
|
100 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
101 | - . $name . '__in_' . $this->_form_section->name(), |
|
102 | - $this->layout_input($subsection), |
|
103 | - $this->_form_section, |
|
104 | - $subsection |
|
105 | - ); |
|
106 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
107 | - $html .= apply_filters( |
|
108 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
109 | - . $name . '__in_' . $this->_form_section->name(), |
|
110 | - $this->layout_subsection($subsection), |
|
111 | - $this->_form_section, |
|
112 | - $subsection |
|
113 | - ); |
|
114 | - } |
|
115 | - } |
|
116 | - return $html; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - abstract public function layout_form_begin(); |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc.) |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - abstract public function layout_form_end(); |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Should be used internally by layout_form() to lay out each input (eg, if this layout |
|
141 | - * is putting each input in a row of its own, this should probably be called by a |
|
142 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | - * customize the form's layout, but would like to make use of it for laying out |
|
145 | - * 'easy-to-layout' inputs |
|
146 | - * |
|
147 | - * @param EE_Form_Input_Base $input |
|
148 | - * @return string html |
|
149 | - */ |
|
150 | - abstract public function layout_input($input); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | - * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | - * that the proper subsection will lay out its container, label, etc on its own. |
|
158 | - * |
|
159 | - * @param EE_Form_Section_Base $subsection |
|
160 | - * @return string html |
|
161 | - */ |
|
162 | - abstract public function layout_subsection($subsection); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Gets the HTML for the label tag and its contents for the input |
|
167 | - * |
|
168 | - * @param EE_Form_Input_Base $input |
|
169 | - * @return string |
|
170 | - * @throws EE_Error |
|
171 | - */ |
|
172 | - public function display_label($input) |
|
173 | - { |
|
174 | - if (! $input->hasLabel()) { |
|
175 | - return ''; |
|
176 | - } |
|
177 | - $class = $input->required() |
|
178 | - ? 'ee-required-label ' . $input->html_label_class() |
|
179 | - : $input->html_label_class(); |
|
180 | - |
|
181 | - $label_text = $input->html_label_text(); |
|
182 | - $required = $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
|
183 | - return ' |
|
14 | + /** |
|
15 | + * Form section to lay out |
|
16 | + * |
|
17 | + * @var EE_Form_Section_Proper |
|
18 | + */ |
|
19 | + protected $_form_section; |
|
20 | + |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * __construct |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * The form section on which this strategy is to perform |
|
34 | + * |
|
35 | + * @param EE_Form_Section_Proper $form |
|
36 | + */ |
|
37 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
38 | + { |
|
39 | + $this->_form_section = $form; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return EE_Form_Section_Proper |
|
46 | + */ |
|
47 | + public function form_section() |
|
48 | + { |
|
49 | + return $this->_form_section; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
56 | + * this form. |
|
57 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
58 | + * proper subsections. |
|
59 | + * Returns the HTML |
|
60 | + * |
|
61 | + * @return string HTML for displaying |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public function layout_form() |
|
65 | + { |
|
66 | + $html = ''; |
|
67 | + // layout_form_begin |
|
68 | + $html .= apply_filters( |
|
69 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
70 | + $this->layout_form_begin(), |
|
71 | + $this->_form_section |
|
72 | + ); |
|
73 | + // layout_form_loop |
|
74 | + $html .= apply_filters( |
|
75 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
76 | + $this->layout_form_loop(), |
|
77 | + $this->_form_section |
|
78 | + ); |
|
79 | + // layout_form_end |
|
80 | + $html .= apply_filters( |
|
81 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
82 | + $this->layout_form_end(), |
|
83 | + $this->_form_section |
|
84 | + ); |
|
85 | + return $this->add_form_section_hooks_and_filters($html); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return string |
|
92 | + * @throws EE_Error |
|
93 | + */ |
|
94 | + public function layout_form_loop() |
|
95 | + { |
|
96 | + $html = ''; |
|
97 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
98 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
99 | + $html .= apply_filters( |
|
100 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
101 | + . $name . '__in_' . $this->_form_section->name(), |
|
102 | + $this->layout_input($subsection), |
|
103 | + $this->_form_section, |
|
104 | + $subsection |
|
105 | + ); |
|
106 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
107 | + $html .= apply_filters( |
|
108 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
109 | + . $name . '__in_' . $this->_form_section->name(), |
|
110 | + $this->layout_subsection($subsection), |
|
111 | + $this->_form_section, |
|
112 | + $subsection |
|
113 | + ); |
|
114 | + } |
|
115 | + } |
|
116 | + return $html; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + abstract public function layout_form_begin(); |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc.) |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + abstract public function layout_form_end(); |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Should be used internally by layout_form() to lay out each input (eg, if this layout |
|
141 | + * is putting each input in a row of its own, this should probably be called by a |
|
142 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
143 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
144 | + * customize the form's layout, but would like to make use of it for laying out |
|
145 | + * 'easy-to-layout' inputs |
|
146 | + * |
|
147 | + * @param EE_Form_Input_Base $input |
|
148 | + * @return string html |
|
149 | + */ |
|
150 | + abstract public function layout_input($input); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
156 | + * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed |
|
157 | + * that the proper subsection will lay out its container, label, etc on its own. |
|
158 | + * |
|
159 | + * @param EE_Form_Section_Base $subsection |
|
160 | + * @return string html |
|
161 | + */ |
|
162 | + abstract public function layout_subsection($subsection); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Gets the HTML for the label tag and its contents for the input |
|
167 | + * |
|
168 | + * @param EE_Form_Input_Base $input |
|
169 | + * @return string |
|
170 | + * @throws EE_Error |
|
171 | + */ |
|
172 | + public function display_label($input) |
|
173 | + { |
|
174 | + if (! $input->hasLabel()) { |
|
175 | + return ''; |
|
176 | + } |
|
177 | + $class = $input->required() |
|
178 | + ? 'ee-required-label ' . $input->html_label_class() |
|
179 | + : $input->html_label_class(); |
|
180 | + |
|
181 | + $label_text = $input->html_label_text(); |
|
182 | + $required = $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
|
183 | + return ' |
|
184 | 184 | <label id="' . esc_attr($input->html_label_id()) . '" |
185 | 185 | class="' . esc_attr($class) . '" |
186 | 186 | style="' . esc_attr($input->html_label_style()) . '" |
@@ -188,101 +188,101 @@ discard block |
||
188 | 188 | > |
189 | 189 | ' . $label_text . $required . ' |
190 | 190 | </label>'; |
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
197 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
198 | - * those errors would probably be on the form section, not one of its inputs) |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function display_form_wide_errors() |
|
202 | - { |
|
203 | - $html = ''; |
|
204 | - if ($this->_form_section->get_validation_errors()) { |
|
205 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
206 | - // get all the errors on THIS form section (errors which aren't |
|
207 | - // for specific inputs, but instead for the entire form section) |
|
208 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
209 | - $html .= $error->getMessage() . '<br>'; |
|
210 | - } |
|
211 | - $html .= '</div>'; |
|
212 | - } |
|
213 | - return apply_filters( |
|
214 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
215 | - $html, |
|
216 | - $this |
|
217 | - ); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * returns the HTML for the server-side validation errors for the specified input |
|
223 | - * Note that if JS is enabled, it should remove these and instead |
|
224 | - * populate the form's errors in the jquery validate fashion |
|
225 | - * using the localized data provided to the JS |
|
226 | - * |
|
227 | - * @param EE_Form_Input_Base $input |
|
228 | - * @return string |
|
229 | - * @throws EE_Error |
|
230 | - */ |
|
231 | - public function display_errors($input) |
|
232 | - { |
|
233 | - if ($input->get_validation_errors()) { |
|
234 | - return " |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
197 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
198 | + * those errors would probably be on the form section, not one of its inputs) |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function display_form_wide_errors() |
|
202 | + { |
|
203 | + $html = ''; |
|
204 | + if ($this->_form_section->get_validation_errors()) { |
|
205 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
206 | + // get all the errors on THIS form section (errors which aren't |
|
207 | + // for specific inputs, but instead for the entire form section) |
|
208 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
209 | + $html .= $error->getMessage() . '<br>'; |
|
210 | + } |
|
211 | + $html .= '</div>'; |
|
212 | + } |
|
213 | + return apply_filters( |
|
214 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
215 | + $html, |
|
216 | + $this |
|
217 | + ); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * returns the HTML for the server-side validation errors for the specified input |
|
223 | + * Note that if JS is enabled, it should remove these and instead |
|
224 | + * populate the form's errors in the jquery validate fashion |
|
225 | + * using the localized data provided to the JS |
|
226 | + * |
|
227 | + * @param EE_Form_Input_Base $input |
|
228 | + * @return string |
|
229 | + * @throws EE_Error |
|
230 | + */ |
|
231 | + public function display_errors($input) |
|
232 | + { |
|
233 | + if ($input->get_validation_errors()) { |
|
234 | + return " |
|
235 | 235 | <label id='" . esc_attr($input->html_id()) . "-error' |
236 | 236 | class='error' |
237 | 237 | for='" . esc_attr($input->html_name()) . "' |
238 | 238 | > |
239 | 239 | " . esc_html($input->get_validation_error_string()) . ' |
240 | 240 | </label>'; |
241 | - } |
|
242 | - return ''; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Displays the help span for the specified input |
|
248 | - * |
|
249 | - * @param EE_Form_Input_Base $input |
|
250 | - * @return string |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - public function display_help_text($input) |
|
254 | - { |
|
255 | - $help_text = $input->html_help_text(); |
|
256 | - if (! $help_text) { |
|
257 | - return ''; |
|
258 | - } |
|
259 | - $tag = is_admin() ? 'p' : 'span'; |
|
260 | - return ' |
|
241 | + } |
|
242 | + return ''; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Displays the help span for the specified input |
|
248 | + * |
|
249 | + * @param EE_Form_Input_Base $input |
|
250 | + * @return string |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + public function display_help_text($input) |
|
254 | + { |
|
255 | + $help_text = $input->html_help_text(); |
|
256 | + if (! $help_text) { |
|
257 | + return ''; |
|
258 | + } |
|
259 | + $tag = is_admin() ? 'p' : 'span'; |
|
260 | + return ' |
|
261 | 261 | <' . $tag . ' id="' . esc_attr($input->html_id()) . '-help" |
262 | 262 | class="' . esc_attr($input->html_help_class()) . '" |
263 | 263 | style="' . esc_attr($input->html_help_style()) . '" |
264 | 264 | > |
265 | 265 | ' . $help_text . ' |
266 | 266 | </' . $tag . '>'; |
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Does an action and hook onto the end of teh form |
|
272 | - * |
|
273 | - * @param string $html |
|
274 | - * @return string |
|
275 | - * @throws EE_Error |
|
276 | - */ |
|
277 | - public function add_form_section_hooks_and_filters(string $html): string |
|
278 | - { |
|
279 | - // replace dashes and spaces with underscores |
|
280 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
281 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
282 | - return (string) apply_filters( |
|
283 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
284 | - $html, |
|
285 | - $this->_form_section |
|
286 | - ); |
|
287 | - } |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Does an action and hook onto the end of teh form |
|
272 | + * |
|
273 | + * @param string $html |
|
274 | + * @return string |
|
275 | + * @throws EE_Error |
|
276 | + */ |
|
277 | + public function add_form_section_hooks_and_filters(string $html): string |
|
278 | + { |
|
279 | + // replace dashes and spaces with underscores |
|
280 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
281 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
282 | + return (string) apply_filters( |
|
283 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
284 | + $html, |
|
285 | + $this->_form_section |
|
286 | + ); |
|
287 | + } |
|
288 | 288 | } |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | $html = ''; |
67 | 67 | // layout_form_begin |
68 | 68 | $html .= apply_filters( |
69 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
69 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
70 | 70 | $this->layout_form_begin(), |
71 | 71 | $this->_form_section |
72 | 72 | ); |
73 | 73 | // layout_form_loop |
74 | 74 | $html .= apply_filters( |
75 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
75 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
76 | 76 | $this->layout_form_loop(), |
77 | 77 | $this->_form_section |
78 | 78 | ); |
79 | 79 | // layout_form_end |
80 | 80 | $html .= apply_filters( |
81 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
81 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
82 | 82 | $this->layout_form_end(), |
83 | 83 | $this->_form_section |
84 | 84 | ); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | if ($subsection instanceof EE_Form_Input_Base) { |
99 | 99 | $html .= apply_filters( |
100 | 100 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
101 | - . $name . '__in_' . $this->_form_section->name(), |
|
101 | + . $name.'__in_'.$this->_form_section->name(), |
|
102 | 102 | $this->layout_input($subsection), |
103 | 103 | $this->_form_section, |
104 | 104 | $subsection |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
107 | 107 | $html .= apply_filters( |
108 | 108 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
109 | - . $name . '__in_' . $this->_form_section->name(), |
|
109 | + . $name.'__in_'.$this->_form_section->name(), |
|
110 | 110 | $this->layout_subsection($subsection), |
111 | 111 | $this->_form_section, |
112 | 112 | $subsection |
@@ -171,22 +171,22 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function display_label($input) |
173 | 173 | { |
174 | - if (! $input->hasLabel()) { |
|
174 | + if ( ! $input->hasLabel()) { |
|
175 | 175 | return ''; |
176 | 176 | } |
177 | 177 | $class = $input->required() |
178 | - ? 'ee-required-label ' . $input->html_label_class() |
|
178 | + ? 'ee-required-label '.$input->html_label_class() |
|
179 | 179 | : $input->html_label_class(); |
180 | 180 | |
181 | 181 | $label_text = $input->html_label_text(); |
182 | 182 | $required = $input->required() ? '<span class="ee-asterisk">*</span>' : ''; |
183 | 183 | return ' |
184 | - <label id="' . esc_attr($input->html_label_id()) . '" |
|
185 | - class="' . esc_attr($class) . '" |
|
186 | - style="' . esc_attr($input->html_label_style()) . '" |
|
187 | - for="' . esc_attr($input->html_id()) . '" |
|
184 | + <label id="' . esc_attr($input->html_label_id()).'" |
|
185 | + class="' . esc_attr($class).'" |
|
186 | + style="' . esc_attr($input->html_label_style()).'" |
|
187 | + for="' . esc_attr($input->html_id()).'" |
|
188 | 188 | > |
189 | - ' . $label_text . $required . ' |
|
189 | + ' . $label_text.$required.' |
|
190 | 190 | </label>'; |
191 | 191 | } |
192 | 192 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | // get all the errors on THIS form section (errors which aren't |
207 | 207 | // for specific inputs, but instead for the entire form section) |
208 | 208 | foreach ($this->_form_section->get_validation_errors() as $error) { |
209 | - $html .= $error->getMessage() . '<br>'; |
|
209 | + $html .= $error->getMessage().'<br>'; |
|
210 | 210 | } |
211 | 211 | $html .= '</div>'; |
212 | 212 | } |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | { |
233 | 233 | if ($input->get_validation_errors()) { |
234 | 234 | return " |
235 | - <label id='" . esc_attr($input->html_id()) . "-error' |
|
235 | + <label id='" . esc_attr($input->html_id())."-error' |
|
236 | 236 | class='error' |
237 | - for='" . esc_attr($input->html_name()) . "' |
|
237 | + for='" . esc_attr($input->html_name())."' |
|
238 | 238 | > |
239 | - " . esc_html($input->get_validation_error_string()) . ' |
|
239 | + " . esc_html($input->get_validation_error_string()).' |
|
240 | 240 | </label>'; |
241 | 241 | } |
242 | 242 | return ''; |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | public function display_help_text($input) |
254 | 254 | { |
255 | 255 | $help_text = $input->html_help_text(); |
256 | - if (! $help_text) { |
|
256 | + if ( ! $help_text) { |
|
257 | 257 | return ''; |
258 | 258 | } |
259 | 259 | $tag = is_admin() ? 'p' : 'span'; |
260 | 260 | return ' |
261 | - <' . $tag . ' id="' . esc_attr($input->html_id()) . '-help" |
|
262 | - class="' . esc_attr($input->html_help_class()) . '" |
|
263 | - style="' . esc_attr($input->html_help_style()) . '" |
|
261 | + <' . $tag.' id="'.esc_attr($input->html_id()).'-help" |
|
262 | + class="' . esc_attr($input->html_help_class()).'" |
|
263 | + style="' . esc_attr($input->html_help_style()).'" |
|
264 | 264 | > |
265 | - ' . $help_text . ' |
|
266 | - </' . $tag . '>'; |
|
265 | + ' . $help_text.' |
|
266 | + </' . $tag.'>'; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | { |
279 | 279 | // replace dashes and spaces with underscores |
280 | 280 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
281 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
281 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
282 | 282 | return (string) apply_filters( |
283 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
283 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
284 | 284 | $html, |
285 | 285 | $this->_form_section |
286 | 286 | ); |
@@ -10,116 +10,116 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_No_Layout extends EE_Div_Per_Section_Layout |
12 | 12 | { |
13 | - /** |
|
14 | - * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
15 | - * strategy. |
|
16 | - * |
|
17 | - * @var bool |
|
18 | - */ |
|
19 | - protected $_use_break_tags = true; |
|
20 | - |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * EE_No_Layout constructor. |
|
25 | - * |
|
26 | - * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
27 | - * property on the class. |
|
28 | - */ |
|
29 | - public function __construct($options = array()) |
|
30 | - { |
|
31 | - $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
32 | - ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
33 | - : $this->_use_break_tags; |
|
34 | - parent::__construct(); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Add line break at beginning of form |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function layout_form_begin() |
|
45 | - { |
|
46 | - return EEH_HTML::nl(1); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Lays out the row for the input, including label and errors |
|
53 | - * |
|
54 | - * @param EE_Form_Input_Base $input |
|
55 | - * @return string |
|
56 | - * @throws \EE_Error |
|
57 | - */ |
|
58 | - public function layout_input($input) |
|
59 | - { |
|
60 | - $html = ''; |
|
61 | - if ($input instanceof EE_Hidden_Input) { |
|
62 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
63 | - } elseif ($input instanceof EE_Submit_Input) { |
|
64 | - $html .= $this->br(); |
|
65 | - $html .= $input->get_html_for_input(); |
|
66 | - } elseif ($input instanceof EE_Select_Input) { |
|
67 | - $html .= $this->br(); |
|
68 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
69 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
70 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
71 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
72 | - $html .= $this->br(); |
|
73 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
74 | - $html .= $this->br(); |
|
75 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
76 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
77 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
78 | - } else { |
|
79 | - $html .= $this->br(); |
|
80 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
81 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
82 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
83 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
84 | - } |
|
85 | - $html .= EEH_HTML::nl(-1); |
|
86 | - return $html; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Lays out a row for the subsection |
|
93 | - * |
|
94 | - * @param EE_Form_Section_Proper $form_section |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function layout_subsection($form_section) |
|
98 | - { |
|
99 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Add line break at end of form. |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function layout_form_end() |
|
110 | - { |
|
111 | - return EEH_HTML::nl(-1); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
118 | - * |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - protected function br() |
|
122 | - { |
|
123 | - return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
124 | - } |
|
13 | + /** |
|
14 | + * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
15 | + * strategy. |
|
16 | + * |
|
17 | + * @var bool |
|
18 | + */ |
|
19 | + protected $_use_break_tags = true; |
|
20 | + |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * EE_No_Layout constructor. |
|
25 | + * |
|
26 | + * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
27 | + * property on the class. |
|
28 | + */ |
|
29 | + public function __construct($options = array()) |
|
30 | + { |
|
31 | + $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
32 | + ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
33 | + : $this->_use_break_tags; |
|
34 | + parent::__construct(); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Add line break at beginning of form |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function layout_form_begin() |
|
45 | + { |
|
46 | + return EEH_HTML::nl(1); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Lays out the row for the input, including label and errors |
|
53 | + * |
|
54 | + * @param EE_Form_Input_Base $input |
|
55 | + * @return string |
|
56 | + * @throws \EE_Error |
|
57 | + */ |
|
58 | + public function layout_input($input) |
|
59 | + { |
|
60 | + $html = ''; |
|
61 | + if ($input instanceof EE_Hidden_Input) { |
|
62 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
63 | + } elseif ($input instanceof EE_Submit_Input) { |
|
64 | + $html .= $this->br(); |
|
65 | + $html .= $input->get_html_for_input(); |
|
66 | + } elseif ($input instanceof EE_Select_Input) { |
|
67 | + $html .= $this->br(); |
|
68 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
69 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
70 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
71 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
72 | + $html .= $this->br(); |
|
73 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
74 | + $html .= $this->br(); |
|
75 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
76 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
77 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
78 | + } else { |
|
79 | + $html .= $this->br(); |
|
80 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
81 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
82 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
83 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
84 | + } |
|
85 | + $html .= EEH_HTML::nl(-1); |
|
86 | + return $html; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Lays out a row for the subsection |
|
93 | + * |
|
94 | + * @param EE_Form_Section_Proper $form_section |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function layout_subsection($form_section) |
|
98 | + { |
|
99 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Add line break at end of form. |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function layout_form_end() |
|
110 | + { |
|
111 | + return EEH_HTML::nl(-1); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + protected function br() |
|
122 | + { |
|
123 | + return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
124 | + } |
|
125 | 125 | } |
@@ -59,28 +59,28 @@ discard block |
||
59 | 59 | { |
60 | 60 | $html = ''; |
61 | 61 | if ($input instanceof EE_Hidden_Input) { |
62 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
62 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
63 | 63 | } elseif ($input instanceof EE_Submit_Input) { |
64 | 64 | $html .= $this->br(); |
65 | 65 | $html .= $input->get_html_for_input(); |
66 | 66 | } elseif ($input instanceof EE_Select_Input) { |
67 | 67 | $html .= $this->br(); |
68 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
69 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
70 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
71 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
68 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
69 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
70 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
71 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
72 | 72 | $html .= $this->br(); |
73 | 73 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
74 | 74 | $html .= $this->br(); |
75 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
76 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
77 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
75 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
76 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
77 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
78 | 78 | } else { |
79 | 79 | $html .= $this->br(); |
80 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
81 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
82 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
83 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
80 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
81 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
82 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
83 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
84 | 84 | } |
85 | 85 | $html .= EEH_HTML::nl(-1); |
86 | 86 | return $html; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function layout_subsection($form_section) |
98 | 98 | { |
99 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
99 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 |
@@ -2,98 +2,98 @@ |
||
2 | 2 | |
3 | 3 | class EE_Two_Column_Layout extends EE_Form_Section_Layout_Base |
4 | 4 | { |
5 | - /** |
|
6 | - * @param EE_Form_Section_Proper $form |
|
7 | - */ |
|
8 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
9 | - { |
|
10 | - parent::_construct_finalize($form); |
|
11 | - $this->_form_section->set_html_class('ee-two-column-layout'); |
|
12 | - } |
|
5 | + /** |
|
6 | + * @param EE_Form_Section_Proper $form |
|
7 | + */ |
|
8 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
9 | + { |
|
10 | + parent::_construct_finalize($form); |
|
11 | + $this->_form_section->set_html_class('ee-two-column-layout'); |
|
12 | + } |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
17 | - * |
|
18 | - * @param array $additional_args |
|
19 | - * @return string |
|
20 | - * @throws EE_Error |
|
21 | - */ |
|
22 | - public function layout_form_begin($additional_args = array()) |
|
23 | - { |
|
24 | - return $this->display_form_wide_errors() |
|
25 | - . EEH_HTML::table( |
|
26 | - '', |
|
27 | - $this->_form_section->html_id(), |
|
28 | - $this->_form_section->html_class(), |
|
29 | - $this->_form_section->html_style() |
|
30 | - ) . EEH_HTML::tbody(); |
|
31 | - } |
|
15 | + /** |
|
16 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
17 | + * |
|
18 | + * @param array $additional_args |
|
19 | + * @return string |
|
20 | + * @throws EE_Error |
|
21 | + */ |
|
22 | + public function layout_form_begin($additional_args = array()) |
|
23 | + { |
|
24 | + return $this->display_form_wide_errors() |
|
25 | + . EEH_HTML::table( |
|
26 | + '', |
|
27 | + $this->_form_section->html_id(), |
|
28 | + $this->_form_section->html_class(), |
|
29 | + $this->_form_section->html_style() |
|
30 | + ) . EEH_HTML::tbody(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
37 | - * |
|
38 | - * @param array $additional_args |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function layout_form_end($additional_args = array()) |
|
42 | - { |
|
43 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
37 | + * |
|
38 | + * @param array $additional_args |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function layout_form_end($additional_args = array()) |
|
42 | + { |
|
43 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Lays out the row for the input, including label and errors |
|
50 | - * |
|
51 | - * @param EE_Form_Input_Base $input |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function layout_input($input) |
|
55 | - { |
|
56 | - $html = ''; |
|
57 | - if ($input instanceof EE_Hidden_Input) { |
|
58 | - $html .= $input->get_html_for_input(); |
|
59 | - } else { |
|
60 | - $html_for_input = $input->get_html_for_input(); |
|
61 | - $html_for_input .= $input->get_html_for_errors() != '' |
|
62 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
63 | - : ''; |
|
64 | - $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
65 | - $html .= EEH_HTML::tr( |
|
66 | - EEH_HTML::th($input->get_html_for_label()) . |
|
67 | - EEH_HTML::td($html_for_input) |
|
68 | - ); |
|
69 | - } |
|
70 | - return $html; |
|
71 | - } |
|
48 | + /** |
|
49 | + * Lays out the row for the input, including label and errors |
|
50 | + * |
|
51 | + * @param EE_Form_Input_Base $input |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function layout_input($input) |
|
55 | + { |
|
56 | + $html = ''; |
|
57 | + if ($input instanceof EE_Hidden_Input) { |
|
58 | + $html .= $input->get_html_for_input(); |
|
59 | + } else { |
|
60 | + $html_for_input = $input->get_html_for_input(); |
|
61 | + $html_for_input .= $input->get_html_for_errors() != '' |
|
62 | + ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
63 | + : ''; |
|
64 | + $html_for_input .= $input->get_html_for_help() != '' ? EEH_HTML::nl() . $input->get_html_for_help() : ''; |
|
65 | + $html .= EEH_HTML::tr( |
|
66 | + EEH_HTML::th($input->get_html_for_label()) . |
|
67 | + EEH_HTML::td($html_for_input) |
|
68 | + ); |
|
69 | + } |
|
70 | + return $html; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Lays out a row for the subsection. Please note that if you have a subsection which you don't want wrapped in |
|
76 | - * a 'tr' and 'td' with a colspan=2, you should either: |
|
77 | - * - set the layout strategy options 'add_wrapper' value to false |
|
78 | - * - use a different layout strategy, like EE_No_Layout, EE_Template_Layout, or EE_Div_Per_Section_Layout, |
|
79 | - * and create subsections using EE_Two_Column_Layout for everywhere you want the two-column layout, |
|
80 | - * and then other subsections can be outside the EE_Two_Column_Layout table. |
|
81 | - * |
|
82 | - * @param EE_Form_Section_Proper $form_section |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - */ |
|
86 | - public function layout_subsection($form_section) |
|
87 | - { |
|
88 | - if ($form_section instanceof EE_Form_Section_Proper) { |
|
89 | - $html = $form_section->get_html(); |
|
90 | - return ! empty($html) ? EEH_HTML::no_row($html) : ''; |
|
91 | - } |
|
92 | - if ($form_section instanceof EE_Form_Section_HTML) { |
|
93 | - return $form_section->addWrapper() |
|
94 | - ? EEH_HTML::no_row($form_section->get_html()) |
|
95 | - : $form_section->get_html(); |
|
96 | - } |
|
97 | - return ''; |
|
98 | - } |
|
74 | + /** |
|
75 | + * Lays out a row for the subsection. Please note that if you have a subsection which you don't want wrapped in |
|
76 | + * a 'tr' and 'td' with a colspan=2, you should either: |
|
77 | + * - set the layout strategy options 'add_wrapper' value to false |
|
78 | + * - use a different layout strategy, like EE_No_Layout, EE_Template_Layout, or EE_Div_Per_Section_Layout, |
|
79 | + * and create subsections using EE_Two_Column_Layout for everywhere you want the two-column layout, |
|
80 | + * and then other subsections can be outside the EE_Two_Column_Layout table. |
|
81 | + * |
|
82 | + * @param EE_Form_Section_Proper $form_section |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + */ |
|
86 | + public function layout_subsection($form_section) |
|
87 | + { |
|
88 | + if ($form_section instanceof EE_Form_Section_Proper) { |
|
89 | + $html = $form_section->get_html(); |
|
90 | + return ! empty($html) ? EEH_HTML::no_row($html) : ''; |
|
91 | + } |
|
92 | + if ($form_section instanceof EE_Form_Section_HTML) { |
|
93 | + return $form_section->addWrapper() |
|
94 | + ? EEH_HTML::no_row($form_section->get_html()) |
|
95 | + : $form_section->get_html(); |
|
96 | + } |
|
97 | + return ''; |
|
98 | + } |
|
99 | 99 | } |