@@ -9,7 +9,7 @@ |
||
9 | 9 | <div id="<?php echo esc_attr($admin_page_wrapper_div_id); ?>"> |
10 | 10 | <div id="post-body" class="metabox-holder columns-1"> |
11 | 11 | |
12 | - <?php if (! empty($admin_page_header)) : ?> |
|
12 | + <?php if ( ! empty($admin_page_header)) : ?> |
|
13 | 13 | <div id="admin-page-header"> |
14 | 14 | <?php echo $admin_page_header; // already escaped ?> |
15 | 15 | </div> |
@@ -20,28 +20,28 @@ discard block |
||
20 | 20 | use EventEspresso\modules\ticket_selector\TicketDetails; |
21 | 21 | |
22 | 22 | $event_date_label = apply_filters( |
23 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
|
24 | - esc_html__('Event Date ', 'event_espresso') |
|
23 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
|
24 | + esc_html__('Event Date ', 'event_espresso') |
|
25 | 25 | ); |
26 | 26 | |
27 | 27 | $sold_label = apply_filters( |
28 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
|
29 | - esc_html__('Sold', 'event_espresso') |
|
28 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
|
29 | + esc_html__('Sold', 'event_espresso') |
|
30 | 30 | ); |
31 | 31 | |
32 | 32 | $remaining_label = apply_filters( |
33 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
|
34 | - esc_html__('Remaining', 'event_espresso') |
|
33 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
|
34 | + esc_html__('Remaining', 'event_espresso') |
|
35 | 35 | ); |
36 | 36 | |
37 | 37 | $total_sold_label = apply_filters( |
38 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
|
39 | - esc_html__('Total Sold', 'event_espresso') |
|
38 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
|
39 | + esc_html__('Total Sold', 'event_espresso') |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | $spaces_left_label = apply_filters( |
43 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
|
44 | - esc_html__('Total Spaces Left', 'event_espresso') |
|
43 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
|
44 | + esc_html__('Total Spaces Left', 'event_espresso') |
|
45 | 45 | ); |
46 | 46 | |
47 | 47 | ?> |
@@ -55,32 +55,32 @@ discard block |
||
55 | 55 | <p><?php echo $ticket->description(); // already escaped ?></p> |
56 | 56 | |
57 | 57 | <?php |
58 | - do_action( |
|
59 | - 'AHEE__ticket_selector_chart_template__ticket_details__after_description', |
|
60 | - $ticket, |
|
61 | - $ticket_price, |
|
62 | - $display_ticket_price |
|
63 | - ); |
|
64 | - ?> |
|
58 | + do_action( |
|
59 | + 'AHEE__ticket_selector_chart_template__ticket_details__after_description', |
|
60 | + $ticket, |
|
61 | + $ticket_price, |
|
62 | + $display_ticket_price |
|
63 | + ); |
|
64 | + ?> |
|
65 | 65 | <section class="tckt-slctr-tkt-sale-dates-sctn"> |
66 | 66 | <h5> |
67 | 67 | <?php echo apply_filters( |
68 | - 'FHEE__ticket_selector_chart_template__ticket_details_sales_date_heading', |
|
69 | - esc_html__('Sale Dates', 'event_espresso') |
|
70 | - ); ?> |
|
68 | + 'FHEE__ticket_selector_chart_template__ticket_details_sales_date_heading', |
|
69 | + esc_html__('Sale Dates', 'event_espresso') |
|
70 | + ); ?> |
|
71 | 71 | </h5> |
72 | 72 | <span class="drk-grey-text small-text no-bold"> - |
73 | 73 | <?php echo apply_filters( |
74 | - 'FHEE__ticket_selector_chart_template__ticket_details_dates_available_message', |
|
75 | - esc_html__('The dates when this option is available for purchase.', 'event_espresso') |
|
76 | - ); ?> |
|
74 | + 'FHEE__ticket_selector_chart_template__ticket_details_dates_available_message', |
|
75 | + esc_html__('The dates when this option is available for purchase.', 'event_espresso') |
|
76 | + ); ?> |
|
77 | 77 | </span> |
78 | 78 | <br /> |
79 | 79 | <span class="ticket-details-label-spn drk-grey-text"> |
80 | 80 | <?php echo apply_filters( |
81 | - 'FHEE__ticket_selector_chart_template__ticket_details_goes_on_sale', |
|
82 | - esc_html__('Goes On Sale:', 'event_espresso') |
|
83 | - ); ?> |
|
81 | + 'FHEE__ticket_selector_chart_template__ticket_details_goes_on_sale', |
|
82 | + esc_html__('Goes On Sale:', 'event_espresso') |
|
83 | + ); ?> |
|
84 | 84 | </span> |
85 | 85 | <span class="dashicons dashicons-calendar"></span> |
86 | 86 | <?php echo $ticket->get_i18n_datetime('TKT_start_date', $date_format) . ' '; ?> |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | <br /> |
90 | 90 | <span class="ticket-details-label-spn drk-grey-text"> |
91 | 91 | <?php echo apply_filters( |
92 | - 'FHEE__ticket_selector_chart_template__ticket_details_sales_end', |
|
93 | - esc_html__('Sales End:', 'event_espresso') |
|
94 | - ); ?> |
|
92 | + 'FHEE__ticket_selector_chart_template__ticket_details_sales_end', |
|
93 | + esc_html__('Sales End:', 'event_espresso') |
|
94 | + ); ?> |
|
95 | 95 | </span> |
96 | 96 | <span class="dashicons dashicons-calendar"></span> |
97 | 97 | <?php echo $ticket->get_i18n_datetime('TKT_end_date', $date_format) . ' '; ?> |
@@ -107,53 +107,53 @@ discard block |
||
107 | 107 | <section class="tckt-slctr-tkt-quantities-sctn"> |
108 | 108 | <h5> |
109 | 109 | <?php echo apply_filters( |
110 | - 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_heading', |
|
111 | - esc_html__('Purchasable Quantities', 'event_espresso') |
|
112 | - ); ?> |
|
110 | + 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_heading', |
|
111 | + esc_html__('Purchasable Quantities', 'event_espresso') |
|
112 | + ); ?> |
|
113 | 113 | </h5> |
114 | 114 | <span class="drk-grey-text small-text no-bold"> - |
115 | 115 | <?php echo apply_filters( |
116 | - 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_message', |
|
117 | - esc_html__( |
|
118 | - 'The number of tickets that can be purchased per transaction (if available).', |
|
119 | - 'event_espresso' |
|
120 | - ) |
|
121 | - ); ?> |
|
116 | + 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_message', |
|
117 | + esc_html__( |
|
118 | + 'The number of tickets that can be purchased per transaction (if available).', |
|
119 | + 'event_espresso' |
|
120 | + ) |
|
121 | + ); ?> |
|
122 | 122 | </span> |
123 | 123 | <br /> |
124 | 124 | <span class="ticket-details-label-spn drk-grey-text"> |
125 | 125 | <?php echo apply_filters( |
126 | - 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty', |
|
127 | - esc_html__('Minimum Qty:', 'event_espresso') |
|
128 | - ); ?> |
|
126 | + 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty', |
|
127 | + esc_html__('Minimum Qty:', 'event_espresso') |
|
128 | + ); ?> |
|
129 | 129 | </span> |
130 | 130 | <?php |
131 | - echo $ticket->min() > 0 ? $ticket->min() : 0; |
|
131 | + echo $ticket->min() > 0 ? $ticket->min() : 0; |
|
132 | 132 | |
133 | - if ($ticket->min() > $remaining) { |
|
134 | - ?> |
|
133 | + if ($ticket->min() > $remaining) { |
|
134 | + ?> |
|
135 | 135 | <span class="important-notice small-text"> |
136 | 136 | <?php echo apply_filters( |
137 | - 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty_message', |
|
138 | - esc_html__( |
|
139 | - 'The Minimum Quantity purchasable for this ticket exceeds the number of spaces remaining', |
|
140 | - 'event_espresso' |
|
141 | - ) |
|
142 | - ); ?> |
|
137 | + 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty_message', |
|
138 | + esc_html__( |
|
139 | + 'The Minimum Quantity purchasable for this ticket exceeds the number of spaces remaining', |
|
140 | + 'event_espresso' |
|
141 | + ) |
|
142 | + ); ?> |
|
143 | 143 | </span> |
144 | 144 | <?php } ?> |
145 | 145 | <br /> |
146 | 146 | <?php // $max = min( $max, $max_atndz );?> |
147 | 147 | <span class="ticket-details-label-spn drk-grey-text"> |
148 | 148 | <?php echo apply_filters( |
149 | - 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_max_qty', |
|
150 | - esc_html__('Maximum Qty:', 'event_espresso') |
|
151 | - ); ?> |
|
149 | + 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_max_qty', |
|
150 | + esc_html__('Maximum Qty:', 'event_espresso') |
|
151 | + ); ?> |
|
152 | 152 | </span> |
153 | 153 | <?php echo $ticket->max() === EE_INF |
154 | - ? esc_html__('no limit', 'event_espresso') |
|
155 | - : max($ticket->max(), 1); |
|
156 | - ?> |
|
154 | + ? esc_html__('no limit', 'event_espresso') |
|
155 | + : max($ticket->max(), 1); |
|
156 | + ?> |
|
157 | 157 | <br /> |
158 | 158 | </section> |
159 | 159 | <br /> |
@@ -163,31 +163,31 @@ discard block |
||
163 | 163 | <section class="tckt-slctr-tkt-uses-sctn"> |
164 | 164 | <h5> |
165 | 165 | <?php echo apply_filters( |
166 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_date_ticket_uses_heading', |
|
167 | - esc_html__('Event Date Ticket Uses', 'event_espresso') |
|
168 | - ); ?> |
|
166 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_date_ticket_uses_heading', |
|
167 | + esc_html__('Event Date Ticket Uses', 'event_espresso') |
|
168 | + ); ?> |
|
169 | 169 | </h5> |
170 | 170 | <span class="drk-grey-text small-text no-bold"> - |
171 | 171 | <?php echo apply_filters( |
172 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_date_ticket_uses_message', |
|
173 | - sprintf( |
|
174 | - esc_html__( |
|
175 | - 'The number of separate event datetimes (see table below) that this ticket can be used to gain admittance to.%1$s%2$sAdmission is always one person per ticket.%3$s', |
|
176 | - 'event_espresso' |
|
177 | - ), |
|
178 | - '<br/>', |
|
179 | - '<strong>', |
|
180 | - '</strong>' |
|
181 | - ) |
|
182 | - ); |
|
183 | - ?> |
|
172 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_date_ticket_uses_message', |
|
173 | + sprintf( |
|
174 | + esc_html__( |
|
175 | + 'The number of separate event datetimes (see table below) that this ticket can be used to gain admittance to.%1$s%2$sAdmission is always one person per ticket.%3$s', |
|
176 | + 'event_espresso' |
|
177 | + ), |
|
178 | + '<br/>', |
|
179 | + '<strong>', |
|
180 | + '</strong>' |
|
181 | + ) |
|
182 | + ); |
|
183 | + ?> |
|
184 | 184 | </span> |
185 | 185 | <br /> |
186 | 186 | <span class="ticket-details-label-spn drk-grey-text"> |
187 | 187 | <?php echo apply_filters( |
188 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_date_number_datetimes', |
|
189 | - esc_html__('# Datetimes:', 'event_espresso') |
|
190 | - ); ?> |
|
188 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_date_number_datetimes', |
|
189 | + esc_html__('# Datetimes:', 'event_espresso') |
|
190 | + ); ?> |
|
191 | 191 | </span> |
192 | 192 | <?php echo $ticket->uses(); ?> |
193 | 193 | <br /> |
@@ -195,24 +195,24 @@ discard block |
||
195 | 195 | <?php } ?> |
196 | 196 | |
197 | 197 | <?php |
198 | - $datetimes = $ticket->datetimes_ordered($event_is_expired, false); |
|
199 | - $chart_column_width = $show_ticket_sale_columns ? ' ee-fourth-width' : ' ee-half-width'; |
|
200 | - if (! empty($datetimes)) { ?> |
|
198 | + $datetimes = $ticket->datetimes_ordered($event_is_expired, false); |
|
199 | + $chart_column_width = $show_ticket_sale_columns ? ' ee-fourth-width' : ' ee-half-width'; |
|
200 | + if (! empty($datetimes)) { ?> |
|
201 | 201 | <section class="tckt-slctr-tkt-datetimes-sctn"> |
202 | 202 | <h5> |
203 | 203 | <?php echo apply_filters( |
204 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_heading', |
|
205 | - esc_html__('Access', 'event_espresso') |
|
206 | - ); ?> |
|
204 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_heading', |
|
205 | + esc_html__('Access', 'event_espresso') |
|
206 | + ); ?> |
|
207 | 207 | </h5> |
208 | 208 | <span class="drk-grey-text small-text no-bold"> - |
209 | 209 | <?php echo apply_filters( |
210 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_message', |
|
211 | - esc_html__( |
|
212 | - 'This option allows access to the following dates and times.', |
|
213 | - 'event_espresso' |
|
214 | - ) |
|
215 | - ); ?> |
|
210 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_message', |
|
211 | + esc_html__( |
|
212 | + 'This option allows access to the following dates and times.', |
|
213 | + 'event_espresso' |
|
214 | + ) |
|
215 | + ); ?> |
|
216 | 216 | </span> |
217 | 217 | <div class="tckt-slctr-tkt-details-tbl-wrap-dv"> |
218 | 218 | <table class="tckt-slctr-tkt-details-tbl"> |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | <span class="dashicons dashicons-calendar"></span> |
223 | 223 | <span class="small-text"> |
224 | 224 | <?php echo apply_filters( |
225 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
|
226 | - esc_html__('Date ', 'event_espresso') |
|
227 | - ); ?> |
|
225 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
|
226 | + esc_html__('Date ', 'event_espresso') |
|
227 | + ); ?> |
|
228 | 228 | </span> |
229 | 229 | </th> |
230 | 230 | <th class="tckt-slctr-tkt-details-time-th <?php echo esc_attr($chart_column_width); ?>"> |
@@ -237,33 +237,33 @@ discard block |
||
237 | 237 | <th class="tckt-slctr-tkt-details-this-ticket-sold-th ee-fourth-width cntr"> |
238 | 238 | <span class="smaller-text"> |
239 | 239 | <?php echo apply_filters( |
240 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
|
241 | - sprintf(esc_html__('Sold', 'event_espresso'), '<br/>') |
|
242 | - ); ?> |
|
240 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
|
241 | + sprintf(esc_html__('Sold', 'event_espresso'), '<br/>') |
|
242 | + ); ?> |
|
243 | 243 | </span> |
244 | 244 | </th> |
245 | 245 | <th class="tckt-slctr-tkt-details-this-ticket-left-th ee-fourth-width cntr"> |
246 | 246 | <span class="smaller-text"> |
247 | 247 | <?php echo apply_filters( |
248 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
|
249 | - sprintf(esc_html__('Remaining', 'event_espresso'), '<br/>') |
|
250 | - ); ?> |
|
248 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
|
249 | + sprintf(esc_html__('Remaining', 'event_espresso'), '<br/>') |
|
250 | + ); ?> |
|
251 | 251 | </span> |
252 | 252 | </th> |
253 | 253 | <th class="tckt-slctr-tkt-details-total-tickets-sold-th ee-fourth-width cntr"> |
254 | 254 | <span class="smaller-text"> |
255 | 255 | <?php echo apply_filters( |
256 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
|
257 | - sprintf(esc_html__('Total%sSold', 'event_espresso'), '<br/>') |
|
258 | - ); ?> |
|
256 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
|
257 | + sprintf(esc_html__('Total%sSold', 'event_espresso'), '<br/>') |
|
258 | + ); ?> |
|
259 | 259 | </span> |
260 | 260 | </th> |
261 | 261 | <th class="tckt-slctr-tkt-details-total-tickets-left-th ee-fourth-width cntr"> |
262 | 262 | <span class="smaller-text"> |
263 | 263 | <?php echo apply_filters( |
264 | - 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
|
265 | - sprintf(esc_html__('Total Spaces%sLeft', 'event_espresso'), '<br/>') |
|
266 | - ); ?> |
|
264 | + 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
|
265 | + sprintf(esc_html__('Total Spaces%sLeft', 'event_espresso'), '<br/>') |
|
266 | + ); ?> |
|
267 | 267 | </span> |
268 | 268 | </th> |
269 | 269 | <?php endif; // end $show_ticket_sale_columns conditional ?> |
@@ -271,25 +271,25 @@ discard block |
||
271 | 271 | </thead> |
272 | 272 | <tbody> |
273 | 273 | <?php foreach ($datetimes as $datetime) { |
274 | - if ($datetime instanceof EE_Datetime) { ?> |
|
274 | + if ($datetime instanceof EE_Datetime) { ?> |
|
275 | 275 | <tr> |
276 | 276 | <td data-th="<?php echo esc_attr($event_date_label); ?>" class="small-text"> |
277 | 277 | <?php $datetime_name = $datetime->name(); ?> |
278 | 278 | <?php echo ! empty($datetime_name) |
279 | - ? '<b>' . esc_html($datetime_name) . '</b><br/>' |
|
280 | - : ''; ?> |
|
279 | + ? '<b>' . esc_html($datetime_name) . '</b><br/>' |
|
280 | + : ''; ?> |
|
281 | 281 | <?php echo $datetime->date_range( |
282 | - $date_format, |
|
283 | - esc_html__(' to ', 'event_espresso') |
|
284 | - ); ?> |
|
282 | + $date_format, |
|
283 | + esc_html__(' to ', 'event_espresso') |
|
284 | + ); ?> |
|
285 | 285 | </td> |
286 | 286 | <td data-th="<?php esc_html_e('Time ', 'event_espresso'); ?>" |
287 | 287 | class="cntr small-text" |
288 | 288 | > |
289 | 289 | <?php echo $datetime->time_range( |
290 | - $time_format, |
|
291 | - esc_html__(' to ', 'event_espresso') |
|
292 | - ); ?> |
|
290 | + $time_format, |
|
291 | + esc_html__(' to ', 'event_espresso') |
|
292 | + ); ?> |
|
293 | 293 | </td> |
294 | 294 | <?php if ($show_ticket_sale_columns) : ?> |
295 | 295 | <td data-th="<?php echo esc_attr($sold_label); ?>" class="cntr small-text"> |
@@ -297,25 +297,25 @@ discard block |
||
297 | 297 | </td> |
298 | 298 | <td data-th="<?php echo esc_attr($remaining_label); ?>" class="cntr small-text"> |
299 | 299 | <?php echo $remaining === EE_INF |
300 | - ? '<span class="smaller-text">' |
|
301 | - . esc_html__('unlimited ', 'event_espresso') |
|
302 | - . '</span>' |
|
303 | - : $remaining; ?> |
|
300 | + ? '<span class="smaller-text">' |
|
301 | + . esc_html__('unlimited ', 'event_espresso') |
|
302 | + . '</span>' |
|
303 | + : $remaining; ?> |
|
304 | 304 | </td> |
305 | 305 | <td data-th="<?php echo esc_attr($total_sold_label); ?>" class="cntr small-text"> |
306 | 306 | <?php echo $datetime->sold(); ?> |
307 | 307 | </td> |
308 | 308 | <?php $tkts_left = $datetime->sold_out() |
309 | - ? '<span class="sold-out smaller-text">' |
|
310 | - . esc_html__('Sold Out', 'event_espresso') |
|
311 | - . '</span>' |
|
312 | - : $datetime->spaces_remaining(); ?> |
|
309 | + ? '<span class="sold-out smaller-text">' |
|
310 | + . esc_html__('Sold Out', 'event_espresso') |
|
311 | + . '</span>' |
|
312 | + : $datetime->spaces_remaining(); ?> |
|
313 | 313 | <td data-th="<?php echo esc_attr($spaces_left_label); ?>" class="cntr small-text"> |
314 | 314 | <?php echo $tkts_left === EE_INF |
315 | - ? '<span class="smaller-text">' |
|
316 | - . esc_html__('unlimited ', 'event_espresso') |
|
317 | - . '</span>' |
|
318 | - : $tkts_left; ?> |
|
315 | + ? '<span class="smaller-text">' |
|
316 | + . esc_html__('unlimited ', 'event_espresso') |
|
317 | + . '</span>' |
|
318 | + : $tkts_left; ?> |
|
319 | 319 | </td> |
320 | 320 | <?php endif; // end $show_ticket_sale_columns conditional ?> |
321 | 321 | </tr> |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | ); ?> |
84 | 84 | </span> |
85 | 85 | <span class="dashicons dashicons-calendar"></span> |
86 | - <?php echo $ticket->get_i18n_datetime('TKT_start_date', $date_format) . ' '; ?> |
|
86 | + <?php echo $ticket->get_i18n_datetime('TKT_start_date', $date_format).' '; ?> |
|
87 | 87 | <span class="dashicons dashicons-clock"></span> |
88 | 88 | <?php echo $ticket->get_i18n_datetime('TKT_start_date', $time_format); ?> |
89 | 89 | <br /> |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ); ?> |
95 | 95 | </span> |
96 | 96 | <span class="dashicons dashicons-calendar"></span> |
97 | - <?php echo $ticket->get_i18n_datetime('TKT_end_date', $date_format) . ' '; ?> |
|
97 | + <?php echo $ticket->get_i18n_datetime('TKT_end_date', $date_format).' '; ?> |
|
98 | 98 | <span class="dashicons dashicons-clock"></span> |
99 | 99 | <?php echo $ticket->get_i18n_datetime('TKT_end_date', $time_format); ?> |
100 | 100 | <br /> |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | <br /> |
160 | 160 | <?php } ?> |
161 | 161 | |
162 | - <?php if ((! defined('EE_DECAF') || EE_DECAF !== true) && $ticket->uses() !== EE_INF) { ?> |
|
162 | + <?php if (( ! defined('EE_DECAF') || EE_DECAF !== true) && $ticket->uses() !== EE_INF) { ?> |
|
163 | 163 | <section class="tckt-slctr-tkt-uses-sctn"> |
164 | 164 | <h5> |
165 | 165 | <?php echo apply_filters( |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | <?php |
198 | 198 | $datetimes = $ticket->datetimes_ordered($event_is_expired, false); |
199 | 199 | $chart_column_width = $show_ticket_sale_columns ? ' ee-fourth-width' : ' ee-half-width'; |
200 | - if (! empty($datetimes)) { ?> |
|
200 | + if ( ! empty($datetimes)) { ?> |
|
201 | 201 | <section class="tckt-slctr-tkt-datetimes-sctn"> |
202 | 202 | <h5> |
203 | 203 | <?php echo apply_filters( |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | <td data-th="<?php echo esc_attr($event_date_label); ?>" class="small-text"> |
277 | 277 | <?php $datetime_name = $datetime->name(); ?> |
278 | 278 | <?php echo ! empty($datetime_name) |
279 | - ? '<b>' . esc_html($datetime_name) . '</b><br/>' |
|
279 | + ? '<b>'.esc_html($datetime_name).'</b><br/>' |
|
280 | 280 | : ''; ?> |
281 | 281 | <?php echo $datetime->date_range( |
282 | 282 | $date_format, |
@@ -333,4 +333,4 @@ discard block |
||
333 | 333 | </div> |
334 | 334 | </td> |
335 | 335 | </tr> |
336 | -<?php endif; // end template_settings->show_ticket_details check |
|
336 | +<?php endif; // end template_settings->show_ticket_details check |
@@ -10,16 +10,16 @@ discard block |
||
10 | 10 | <?php if (! is_admin()) : ?> |
11 | 11 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
12 | 12 | <?php echo apply_filters( |
13 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
14 | - sprintf( |
|
15 | - esc_html__( |
|
16 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
17 | - 'event_espresso' |
|
18 | - ), |
|
19 | - '<br />', |
|
20 | - '<span class="asterisk">*</span>' |
|
21 | - ) |
|
22 | - ); ?> |
|
13 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
14 | + sprintf( |
|
15 | + esc_html__( |
|
16 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
17 | + 'event_espresso' |
|
18 | + ), |
|
19 | + '<br />', |
|
20 | + '<span class="asterisk">*</span>' |
|
21 | + ) |
|
22 | + ); ?> |
|
23 | 23 | </p> |
24 | 24 | <?php endif; ?> |
25 | 25 | |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $prev_ticket = 0; |
30 | 30 | |
31 | 31 | if (count($registrations) > 0) { |
32 | - $ticketID = esc_attr(key($template_args['ticket_count'])); |
|
33 | - ?> |
|
32 | + $ticketID = esc_attr(key($template_args['ticket_count'])); |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div id="spco-attendee-panel-dv-<?php echo esc_attr($ticketID); ?>" |
36 | 36 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo sanitize_html_class($ticketID); ?>" |
@@ -58,37 +58,37 @@ discard block |
||
58 | 58 | </thead> |
59 | 59 | <tbody> |
60 | 60 | <?php |
61 | - // Store previous values to avoid duplicated rows. |
|
62 | - $prev_ticket = 0; |
|
63 | - // Display all tickets inside. |
|
64 | - foreach ($registrations as $registration) { |
|
65 | - if ($registration instanceof EE_Registration) { |
|
66 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
67 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; // already escaped |
|
68 | - } |
|
61 | + // Store previous values to avoid duplicated rows. |
|
62 | + $prev_ticket = 0; |
|
63 | + // Display all tickets inside. |
|
64 | + foreach ($registrations as $registration) { |
|
65 | + if ($registration instanceof EE_Registration) { |
|
66 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
67 | + echo $ticket_line_item[ $registration->ticket()->ID() ]; // already escaped |
|
68 | + } |
|
69 | 69 | |
70 | - $prev_ticket = $registration->ticket()->ID(); |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
70 | + $prev_ticket = $registration->ticket()->ID(); |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </tbody> |
75 | 75 | </table> |
76 | 76 | </div><!-- close spco-ticket-info-dv --> |
77 | 77 | |
78 | 78 | <?php |
79 | - // Display the forms below the table. |
|
80 | - foreach ($registrations as $registration) { |
|
81 | - if ($registration instanceof EE_Registration) { |
|
82 | - // Attendee Questions. |
|
83 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | - echo ${$reg_form}; // already escaped |
|
85 | - } // if ( $registration instanceof EE_Registration ) |
|
86 | - } // end foreach ( $registrations as $registration ) |
|
79 | + // Display the forms below the table. |
|
80 | + foreach ($registrations as $registration) { |
|
81 | + if ($registration instanceof EE_Registration) { |
|
82 | + // Attendee Questions. |
|
83 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | + echo ${$reg_form}; // already escaped |
|
85 | + } // if ( $registration instanceof EE_Registration ) |
|
86 | + } // end foreach ( $registrations as $registration ) |
|
87 | 87 | |
88 | - ?> |
|
88 | + ?> |
|
89 | 89 | </div><!-- close spco-attendee-panel-dv --> |
90 | 90 | <?php |
91 | - echo $default_hidden_inputs; // already escaped |
|
91 | + echo $default_hidden_inputs; // already escaped |
|
92 | 92 | } // end if ( count( $registrations ) > 0 ) |
93 | 93 | |
94 | 94 | ?> |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | <input type="hidden" name="batch_message[id_type]" value="<?php echo esc_attr($id_type); ?>"> |
36 | 36 | <input id="newsletter-batch-ids" type="hidden" name="batch_message[ids]" value=""> |
37 | 37 | <h3 class="newsletter-send-form-title"><?php |
38 | - printf( |
|
39 | - esc_html__('Sending batch message to %s people...', 'event_espresso'), |
|
40 | - '[NUMPEOPLE]' |
|
41 | - ); ?></h3> |
|
38 | + printf( |
|
39 | + esc_html__('Sending batch message to %s people...', 'event_espresso'), |
|
40 | + '[NUMPEOPLE]' |
|
41 | + ); ?></h3> |
|
42 | 42 | <label for="batch-message-template-selector"><?php esc_html_e('Select Template:', 'event_espresso'); ?></label> |
43 | 43 | <?php echo $template_selector; ?> |
44 | 44 | <div class="batch-message-edit-fields" style="display:none;"> |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | <div id="shortcode-container-subject" |
61 | 61 | class="shortcodes-info-container ee_shortcode_chooser_container" style="display:none"> |
62 | 62 | <p><?php |
63 | - esc_html_e( |
|
64 | - 'The following shortcodes can be used in the subject field:', |
|
65 | - 'event_espresso' |
|
66 | - ); ?></p> |
|
63 | + esc_html_e( |
|
64 | + 'The following shortcodes can be used in the subject field:', |
|
65 | + 'event_espresso' |
|
66 | + ); ?></p> |
|
67 | 67 | <p><?php echo $shortcodes['Subject']; ?></p> |
68 | 68 | </div> |
69 | 69 | <input type="text" name="batch_message[subject]" id="batch-message-subject" |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | <div id="shortcode-container-content" |
77 | 77 | class="shortcodes-info-container ee_shortcode_chooser_container" style="display:none"> |
78 | 78 | <p><?php |
79 | - esc_html_e( |
|
80 | - 'The following shortcodes can be used in the content area:', |
|
81 | - 'event_espresso' |
|
82 | - ); ?></p> |
|
79 | + esc_html_e( |
|
80 | + 'The following shortcodes can be used in the content area:', |
|
81 | + 'event_espresso' |
|
82 | + ); ?></p> |
|
83 | 83 | <p><?php echo $shortcodes['[NEWSLETTER_CONTENT]']; ?></p> |
84 | 84 | </div> |
85 | 85 | <textarea name="batch_message[content]" id="batch-message-content" |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | <input type="submit" class="batch-message-submit button button-primary alignright" |
89 | 89 | name="batch-message-submit" value="<?php esc_html_e('Send', 'event_espresso'); ?>"> |
90 | 90 | <button class="batch-message-cancel button button-secondary alignright"><?php |
91 | - esc_html_e( |
|
92 | - 'Cancel', |
|
93 | - 'event_espresso' |
|
94 | - ); ?></button> |
|
91 | + esc_html_e( |
|
92 | + 'Cancel', |
|
93 | + 'event_espresso' |
|
94 | + ); ?></button> |
|
95 | 95 | <div style="clear:both"></div> |
96 | 96 | </div> |
97 | 97 | </form> |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <div class="import-area"> |
2 | 2 | <div class="important-notice"> |
3 | 3 | <?php esc_html_e( |
4 | - 'The import feature has been disabled because of bugs. It is expected to be put back in place soon.', |
|
5 | - 'event_espresso' |
|
6 | - ); ?> |
|
4 | + 'The import feature has been disabled because of bugs. It is expected to be put back in place soon.', |
|
5 | + 'event_espresso' |
|
6 | + ); ?> |
|
7 | 7 | </div> |
8 | 8 | <?php // echo $form; ?> |
9 | 9 | </div> |
@@ -7,7 +7,7 @@ |
||
7 | 7 | <?php esc_html_e('URL of Event:', 'event_espresso'); ?> |
8 | 8 | </label> |
9 | 9 | <?php //phpcs:disable Generic.Files.LineLength.TooLong |
10 | - // no new lines within <textarea> here because they'll output whitespace ?> |
|
10 | + // no new lines within <textarea> here because they'll output whitespace ?> |
|
11 | 11 | <textarea id="url-event" cols="30" rows="4" tabindex="112" name="vnu_virtual_url"><?php echo esc_textarea($_venue->get_f('VNU_virtual_url')); ?></textarea> |
12 | 12 | <?php //phpcs:enable ?> |
13 | 13 | </p> |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | <h1><?php esc_html_e("Data Migration Error", "event_espresso"); ?></h1> |
8 | 8 | <p class='error'> |
9 | 9 | <?php printf( |
10 | - esc_html__( |
|
11 | - "Your last Database Update had a %s fatal error and was halted%s.", |
|
12 | - "event_espresso" |
|
13 | - ), |
|
14 | - "<b>", |
|
15 | - "</b>" |
|
16 | - ); ?> |
|
10 | + esc_html__( |
|
11 | + "Your last Database Update had a %s fatal error and was halted%s.", |
|
12 | + "event_espresso" |
|
13 | + ), |
|
14 | + "<b>", |
|
15 | + "</b>" |
|
16 | + ); ?> |
|
17 | 17 | </p> |
18 | 18 | <a id="show-hide-migration-warnings" class="display-the-hidden"> |
19 | 19 | <?php esc_html_e("Show Errors", 'event_espresso'); ?> |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | </ul> |
26 | 26 | <h2> |
27 | 27 | <?php esc_html_e( |
28 | - "Fill out the below form to automatically Send Event Espresso a Crash Report", |
|
29 | - "event_espresso" |
|
30 | - ); ?> |
|
28 | + "Fill out the below form to automatically Send Event Espresso a Crash Report", |
|
29 | + "event_espresso" |
|
30 | + ); ?> |
|
31 | 31 | </h2> |
32 | 32 | <form action='<?php echo esc_url_raw( |
33 | - EE_Admin_Page::add_query_args_and_nonce( |
|
34 | - ['action' => 'send_migration_crash_report'], |
|
35 | - EE_MAINTENANCE_ADMIN_URL |
|
36 | - ) |
|
33 | + EE_Admin_Page::add_query_args_and_nonce( |
|
34 | + ['action' => 'send_migration_crash_report'], |
|
35 | + EE_MAINTENANCE_ADMIN_URL |
|
36 | + ) |
|
37 | 37 | ); |
38 | 38 | ?>' method='post' |
39 | 39 | > |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | type='text' |
60 | 60 | style="width:200px" |
61 | 61 | value='<?php printf( |
62 | - esc_html__("Admin of %s", "event_espresso"), |
|
63 | - get_bloginfo('name', 'display') |
|
64 | - ); ?>' |
|
62 | + esc_html__("Admin of %s", "event_espresso"), |
|
63 | + get_bloginfo('name', 'display') |
|
64 | + ); ?>' |
|
65 | 65 | /> |
66 | 66 | </td> |
67 | 67 | </tr> |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | <td> |
73 | 73 | <textarea name="body" id="body" class='system_status_info'> |
74 | 74 | <?php esc_textarea(__( |
75 | - "Enter any comments about why you think the error may have occurred", |
|
76 | - "event_espresso" |
|
77 | - )); ?> |
|
75 | + "Enter any comments about why you think the error may have occurred", |
|
76 | + "event_espresso" |
|
77 | + )); ?> |
|
78 | 78 | </textarea> |
79 | 79 | <p class='description'> |
80 | 80 | <?php esc_textarea(__( |
81 | - "Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", |
|
82 | - "event_espresso" |
|
83 | - )); ?> |
|
81 | + "Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", |
|
82 | + "event_espresso" |
|
83 | + )); ?> |
|
84 | 84 | </p> |
85 | 85 | </td> |
86 | 86 | </tr> |
@@ -96,26 +96,26 @@ discard block |
||
96 | 96 | <br> |
97 | 97 | <p> |
98 | 98 | <?php printf( |
99 | - esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"), |
|
100 | - '<a href="mailto:' . EE_SUPPORT_EMAIL . '">', |
|
101 | - EE_SUPPORT_EMAIL, |
|
102 | - "</a>" |
|
103 | - ); ?> |
|
99 | + esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"), |
|
100 | + '<a href="mailto:' . EE_SUPPORT_EMAIL . '">', |
|
101 | + EE_SUPPORT_EMAIL, |
|
102 | + "</a>" |
|
103 | + ); ?> |
|
104 | 104 | </p> |
105 | 105 | <textarea class="system_status_info"> |
106 | 106 | <?php print_r(EEM_System_Status::instance()->get_system_stati()) ?> |
107 | 107 | </textarea> |
108 | 108 | <p> |
109 | 109 | <?php printf( |
110 | - esc_html__('%1$sNext Step%2$s', 'event_espresso'), |
|
111 | - "<a href='$next_url'>", |
|
112 | - "</a>" |
|
113 | - ); ?> |
|
110 | + esc_html__('%1$sNext Step%2$s', 'event_espresso'), |
|
111 | + "<a href='$next_url'>", |
|
112 | + "</a>" |
|
113 | + ); ?> |
|
114 | 114 | </p> |
115 | 115 | <p> |
116 | 116 | <?php printf( |
117 | - esc_html__('...or %1$sDON\'T send crash report%2$s.', 'event_espresso'), |
|
118 | - "<a href='$next_url'>", |
|
119 | - "</a>" |
|
120 | - ); ?> |
|
117 | + esc_html__('...or %1$sDON\'T send crash report%2$s.', 'event_espresso'), |
|
118 | + "<a href='$next_url'>", |
|
119 | + "</a>" |
|
120 | + ); ?> |
|
121 | 121 | </p> |
@@ -4,40 +4,40 @@ discard block |
||
4 | 4 | <tbody> |
5 | 5 | <tr valign="top"> |
6 | 6 | <th><label for="PRT_ID"><?php |
7 | - esc_html_e( |
|
8 | - 'Type', |
|
9 | - 'event_espresso' |
|
10 | - ); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info'); ?></th> |
|
7 | + esc_html_e( |
|
8 | + 'Type', |
|
9 | + 'event_espresso' |
|
10 | + ); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info'); ?></th> |
|
11 | 11 | <td> |
12 | 12 | <?php if ($price->type_obj() && $price->type_obj()->base_type() === 1) : ?> |
13 | 13 | <input type="hidden" name="PRT_ID" id="PRT_ID" value="<?php echo esc_attr($price->type()); ?>"/> |
14 | 14 | <p><strong><?php esc_html_e('Price', 'event_espresso'); ?></strong></p> |
15 | 15 | <p class="description"> |
16 | 16 | <?php |
17 | - esc_html_e( |
|
18 | - 'This is the default base price. Every new ticket created will start off with this base price.', |
|
19 | - 'event_espresso' |
|
20 | - ); |
|
21 | - ?> |
|
17 | + esc_html_e( |
|
18 | + 'This is the default base price. Every new ticket created will start off with this base price.', |
|
19 | + 'event_espresso' |
|
20 | + ); |
|
21 | + ?> |
|
22 | 22 | </p> |
23 | 23 | <?php else : ?> |
24 | 24 | <?php echo EEH_Form_Fields::select_input('PRT_ID', $price_types, $price->type(), 'id="PRT_ID"'); ?> |
25 | 25 | <p class="description"> |
26 | 26 | <?php |
27 | - esc_html_e( |
|
28 | - 'Price Modifier. Default items will apply to ALL new events you create.', |
|
29 | - 'event_espresso' |
|
30 | - ); |
|
31 | - ?></p> |
|
27 | + esc_html_e( |
|
28 | + 'Price Modifier. Default items will apply to ALL new events you create.', |
|
29 | + 'event_espresso' |
|
30 | + ); |
|
31 | + ?></p> |
|
32 | 32 | <?php endif; ?> |
33 | 33 | </td> |
34 | 34 | </tr> |
35 | 35 | <tr valign="top"> |
36 | 36 | <th><label for="PRC_name"><?php |
37 | - esc_html_e( |
|
38 | - 'Name', |
|
39 | - 'event_espresso' |
|
40 | - ); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info'); ?></th> |
|
37 | + esc_html_e( |
|
38 | + 'Name', |
|
39 | + 'event_espresso' |
|
40 | + ); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info'); ?></th> |
|
41 | 41 | <td> |
42 | 42 | <input class="regular-text" type="text" id="PRC_name" name="PRC_name" |
43 | 43 | value="<?php $price->f('PRC_name'); ?>"/> |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | </tr> |
46 | 46 | <tr valign="top"> |
47 | 47 | <th><label for="PRC_desc"><?php |
48 | - esc_html_e( |
|
49 | - 'Description', |
|
50 | - 'event_espresso' |
|
51 | - ); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info'); ?></th> |
|
48 | + esc_html_e( |
|
49 | + 'Description', |
|
50 | + 'event_espresso' |
|
51 | + ); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info'); ?></th> |
|
52 | 52 | <td> |
53 | 53 | <textarea class="regular-text" id="PRC_desc" name="PRC_desc" rows="5"><?php |
54 | - echo esc_textarea($price->get_f('PRC_desc')); |
|
55 | - ?></textarea><br/> |
|
54 | + echo esc_textarea($price->get_f('PRC_desc')); |
|
55 | + ?></textarea><br/> |
|
56 | 56 | </td> |
57 | 57 | </tr> |
58 | 58 | <tr valign="top"> |
59 | 59 | <th><label for="PRC_amount"><?php |
60 | - esc_html_e( |
|
61 | - 'Amount', |
|
62 | - 'event_espresso' |
|
63 | - ); ?><?php echo EEH_Template::get_help_tab_link('amount_field_info'); ?></label></th> |
|
60 | + esc_html_e( |
|
61 | + 'Amount', |
|
62 | + 'event_espresso' |
|
63 | + ); ?><?php echo EEH_Template::get_help_tab_link('amount_field_info'); ?></label></th> |
|
64 | 64 | <td> |
65 | 65 | <input class="small-text ee-numeric" type="text" id="PRC_amount" name="PRC_amount" |
66 | 66 | value="<?php echo esc_attr($price->amount()); ?>"/> |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | $type = $input_value['input']; |
111 | 111 | $value = $input_value['value']; |
112 | 112 | |
113 | - $id = $form_id ? $form_id . '-' . $input_key : $input_key; |
|
114 | - $class = $required ? 'required ' . $css_class : $css_class; |
|
113 | + $id = $form_id ? $form_id.'-'.$input_key : $input_key; |
|
114 | + $class = $required ? 'required '.$css_class : $css_class; |
|
115 | 115 | |
116 | 116 | // what type of input are we dealing with ? |
117 | 117 | switch ($type) { |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | } |
164 | 164 | } // end foreach( $input_vars as $input_key => $input_value ) |
165 | 165 | |
166 | - if (! empty($inputs)) { |
|
167 | - $glue = " |
|
166 | + if ( ! empty($inputs)) { |
|
167 | + $glue = " |
|
168 | 168 | </li> |
169 | 169 | <li> |
170 | 170 | "; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | </ul> |
178 | 178 | "; |
179 | 179 | } |
180 | - return $output . implode("\n", $hidden_inputs); |
|
180 | + return $output.implode("\n", $hidden_inputs); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | // generate label |
259 | 259 | $label = ! empty($label) ? self::adminLabel($id, $label, $required) : ''; |
260 | 260 | // generate field name |
261 | - $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
261 | + $name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name; |
|
262 | 262 | |
263 | 263 | // we determine what we're building based on the type |
264 | 264 | switch ($type) { |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | foreach ($value as $key => $val) { |
270 | 270 | $c_input .= self::adminMulti( |
271 | 271 | $default, |
272 | - isset($classes[ $key ]) ? $classes[ $key ] : '', |
|
273 | - $field_name . '_' . $value, |
|
272 | + isset($classes[$key]) ? $classes[$key] : '', |
|
273 | + $field_name.'_'.$value, |
|
274 | 274 | $name, |
275 | 275 | $required, |
276 | 276 | $tab_index, |
277 | 277 | $type, |
278 | 278 | $val, |
279 | - isset($labels[ $key ]) ? $labels[ $key ] : '' |
|
279 | + isset($labels[$key]) ? $labels[$key] : '' |
|
280 | 280 | ); |
281 | 281 | } |
282 | 282 | $field = $c_input; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | case 'select': |
303 | 303 | $options = []; |
304 | 304 | foreach ($value as $key => $val) { |
305 | - $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : ''; |
|
305 | + $options[$val] = isset($labels[$key]) ? $labels[$key] : ''; |
|
306 | 306 | } |
307 | 307 | $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options); |
308 | 308 | break; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $field = self::adminText($class, $id, $name, $required, $tab_index, $value); |
329 | 329 | } |
330 | 330 | |
331 | - $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc]; |
|
331 | + $form_fields[$field_name] = ['label' => $label, 'field' => $field.$extra_desc]; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return $form_fields; |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
537 | 537 | { |
538 | 538 | // if $values was submitted in the wrong format, convert it over |
539 | - if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) { |
|
539 | + if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) { |
|
540 | 540 | $converted_values = []; |
541 | 541 | foreach ($values as $id => $text) { |
542 | 542 | $converted_values[] = ['id' => $id, 'text' => $text]; |
@@ -545,18 +545,18 @@ discard block |
||
545 | 545 | } |
546 | 546 | |
547 | 547 | $field = |
548 | - '<select id="' . EEH_Formatter::ee_tep_output_string($name) |
|
549 | - . '" name="' . EEH_Formatter::ee_tep_output_string($name) |
|
548 | + '<select id="'.EEH_Formatter::ee_tep_output_string($name) |
|
549 | + . '" name="'.EEH_Formatter::ee_tep_output_string($name) |
|
550 | 550 | . '"'; |
551 | 551 | |
552 | 552 | if (EEH_Formatter::ee_tep_not_null($parameters)) { |
553 | - $field .= ' ' . $parameters; |
|
553 | + $field .= ' '.$parameters; |
|
554 | 554 | } |
555 | 555 | if ($autosize) { |
556 | 556 | $size = 'med'; |
557 | 557 | for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
558 | - if ($values[ $ii ]['text']) { |
|
559 | - if (strlen($values[ $ii ]['text']) > 5) { |
|
558 | + if ($values[$ii]['text']) { |
|
559 | + if (strlen($values[$ii]['text']) > 5) { |
|
560 | 560 | $size = 'wide'; |
561 | 561 | } |
562 | 562 | } |
@@ -565,22 +565,22 @@ discard block |
||
565 | 565 | $size = ''; |
566 | 566 | } |
567 | 567 | |
568 | - $field .= ' class="' . $class . ' ' . $size . '">'; |
|
568 | + $field .= ' class="'.$class.' '.$size.'">'; |
|
569 | 569 | |
570 | - if (empty($default) && isset($GLOBALS[ $name ])) { |
|
571 | - $default = stripslashes($GLOBALS[ $name ]); |
|
570 | + if (empty($default) && isset($GLOBALS[$name])) { |
|
571 | + $default = stripslashes($GLOBALS[$name]); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | |
575 | 575 | for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
576 | - $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
577 | - if ($default == $values[ $i ]['id']) { |
|
576 | + $field .= '<option value="'.$values[$i]['id'].'"'; |
|
577 | + if ($default == $values[$i]['id']) { |
|
578 | 578 | $field .= ' selected = "selected"'; |
579 | 579 | } |
580 | - if (isset($values[ $i ]['class'])) { |
|
581 | - $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
580 | + if (isset($values[$i]['class'])) { |
|
581 | + $field .= ' class="'.$values[$i]['class'].'"'; |
|
582 | 582 | } |
583 | - $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
583 | + $field .= '>'.$values[$i]['text'].'</option>'; |
|
584 | 584 | } |
585 | 585 | $field .= '</select>'; |
586 | 586 | |
@@ -606,11 +606,11 @@ discard block |
||
606 | 606 | $after_question_group_questions = |
607 | 607 | apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
608 | 608 | |
609 | - if (! empty($question_groups)) { |
|
609 | + if ( ! empty($question_groups)) { |
|
610 | 610 | // loop thru question groups |
611 | 611 | foreach ($question_groups as $QSG) { |
612 | 612 | // check that questions exist |
613 | - if (! empty($QSG['QSG_questions'])) { |
|
613 | + if ( ! empty($QSG['QSG_questions'])) { |
|
614 | 614 | // use fieldsets |
615 | 615 | $html .= "\n\t" |
616 | 616 | . '<' |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | $html .= $before_question_group_questions; |
636 | 636 | // loop thru questions |
637 | 637 | foreach ($QSG['QSG_questions'] as $question) { |
638 | - $QFI = new EE_Question_Form_Input( |
|
638 | + $QFI = new EE_Question_Form_Input( |
|
639 | 639 | $question['qst_obj'], |
640 | 640 | $question['ans_obj'], |
641 | 641 | $question |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | $html .= self::generate_form_input($QFI); |
644 | 644 | } |
645 | 645 | $html .= $after_question_group_questions; |
646 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
646 | + $html .= "\n\t".'</'.$group_wrapper.'>'; |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | } |
@@ -683,25 +683,25 @@ discard block |
||
683 | 683 | 'input_id' => '', |
684 | 684 | 'input_class' => '', |
685 | 685 | ]; |
686 | - $q_meta = array_merge($default_q_meta, $q_meta); |
|
686 | + $q_meta = array_merge($default_q_meta, $q_meta); |
|
687 | 687 | |
688 | - if (! empty($question_groups)) { |
|
688 | + if ( ! empty($question_groups)) { |
|
689 | 689 | // loop thru question groups |
690 | 690 | foreach ($question_groups as $QSG) { |
691 | 691 | if ($QSG instanceof EE_Question_Group) { |
692 | 692 | // check that questions exist |
693 | 693 | |
694 | 694 | $where = ['QST_deleted' => 0]; |
695 | - if (! $from_admin) { |
|
695 | + if ( ! $from_admin) { |
|
696 | 696 | $where['QST_admin_only'] = 0; |
697 | 697 | } |
698 | 698 | $questions = |
699 | 699 | $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]); |
700 | - if (! empty($questions)) { |
|
700 | + if ( ! empty($questions)) { |
|
701 | 701 | // use fieldsets |
702 | 702 | $html .= "\n\t" |
703 | - . '<' . $group_wrapper . ' class="espresso-question-group-wrap" ' |
|
704 | - . 'id="' . $QSG->get('QSG_identifier') . '">'; |
|
703 | + . '<'.$group_wrapper.' class="espresso-question-group-wrap" ' |
|
704 | + . 'id="'.$QSG->get('QSG_identifier').'">'; |
|
705 | 705 | // group_name |
706 | 706 | if ($QSG->show_group_name()) { |
707 | 707 | $html .= "\n\t\t" |
@@ -726,21 +726,21 @@ discard block |
||
726 | 726 | /** @var RequestInterface $request */ |
727 | 727 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
728 | 728 | $request_qstn = $request->getRequestParam('qstn', [], 'string', true); |
729 | - if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
729 | + if ( ! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
730 | 730 | // check for answer in $request_qstn in case we are reprocessing a form after an error |
731 | - if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) { |
|
732 | - $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]) |
|
733 | - ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ] |
|
734 | - : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]); |
|
731 | + if (isset($request_qstn[$q_meta['input_id']][$qstn_id])) { |
|
732 | + $answer = is_array($request_qstn[$q_meta['input_id']][$qstn_id]) |
|
733 | + ? $request_qstn[$q_meta['input_id']][$qstn_id] |
|
734 | + : sanitize_text_field($request_qstn[$q_meta['input_id']][$qstn_id]); |
|
735 | 735 | } |
736 | 736 | } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
737 | 737 | // attendee data from the session |
738 | 738 | $answer = |
739 | - isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
739 | + isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null; |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | |
743 | - $QFI = new EE_Question_Form_Input( |
|
743 | + $QFI = new EE_Question_Form_Input( |
|
744 | 744 | $QST, |
745 | 745 | EE_Answer::new_instance( |
746 | 746 | [ |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | $html .= self::generate_form_input($QFI); |
756 | 756 | } |
757 | 757 | $html .= $after_question_group_questions; |
758 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
758 | + $html .= "\n\t".'</'.$group_wrapper.'>'; |
|
759 | 759 | } |
760 | 760 | } |
761 | 761 | } |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | $QFI->get('QST_required_text') != '' |
804 | 804 | ? $QFI->get('QST_required_text') |
805 | 805 | : esc_html__('This field is required', 'event_espresso'); |
806 | - $required_text = $QST_required |
|
806 | + $required_text = $QST_required |
|
807 | 807 | ? "\n\t\t\t" |
808 | 808 | . '<div class="required-text hidden">' |
809 | 809 | . self::prep_answer($required_text, $use_html_entities) |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | $use_html_entities = true |
950 | 950 | ) { |
951 | 951 | // need these |
952 | - if (! $question || ! $name) { |
|
952 | + if ( ! $question || ! $name) { |
|
953 | 953 | return null; |
954 | 954 | } |
955 | 955 | // prep the answer |
@@ -961,13 +961,13 @@ discard block |
||
961 | 961 | // ya gots ta have style man!!! |
962 | 962 | $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
963 | 963 | $class = empty($class) ? $txt_class : $class; |
964 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
964 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
965 | 965 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
966 | 966 | |
967 | 967 | $label_html = |
968 | 968 | $required_text |
969 | 969 | . "\n\t\t\t" |
970 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
970 | + . '<label for="'.$name.'" class="'.$label_class.'">' |
|
971 | 971 | . self::prep_question($question) |
972 | 972 | . $required['label'] |
973 | 973 | . '</label><br/>'; |
@@ -976,12 +976,12 @@ discard block |
||
976 | 976 | |
977 | 977 | $input_html = |
978 | 978 | "\n\t\t\t" |
979 | - . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
980 | - . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" ' |
|
981 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
979 | + . '<input type="text" name="'.$name.'" id="'.$id.'" ' |
|
980 | + . 'class="'.$class.' '.$required['class'].'" value="'.esc_attr($answer).'" ' |
|
981 | + . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>'; |
|
982 | 982 | |
983 | 983 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
984 | - return $label_html . $input_html; |
|
984 | + return $label_html.$input_html; |
|
985 | 985 | } |
986 | 986 | |
987 | 987 | |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | $use_html_entities = true |
1016 | 1016 | ) { |
1017 | 1017 | // need these |
1018 | - if (! $question || ! $name) { |
|
1018 | + if ( ! $question || ! $name) { |
|
1019 | 1019 | return null; |
1020 | 1020 | } |
1021 | 1021 | // prep the answer |
@@ -1031,13 +1031,13 @@ discard block |
||
1031 | 1031 | // ya gots ta have style man!!! |
1032 | 1032 | $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
1033 | 1033 | $class = empty($class) ? $txt_class : $class; |
1034 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1034 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1035 | 1035 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
1036 | 1036 | |
1037 | 1037 | $label_html = |
1038 | 1038 | $required_text |
1039 | 1039 | . "\n\t\t\t" |
1040 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1040 | + . '<label for="'.$name.'" class="'.$label_class.'">' |
|
1041 | 1041 | . self::prep_question($question) |
1042 | 1042 | . $required['label'] |
1043 | 1043 | . '</label><br/>'; |
@@ -1046,14 +1046,14 @@ discard block |
||
1046 | 1046 | |
1047 | 1047 | $input_html = |
1048 | 1048 | "\n\t\t\t" |
1049 | - . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1050 | - . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" ' |
|
1051 | - . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' |
|
1049 | + . '<textarea name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" ' |
|
1050 | + . 'rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'" ' |
|
1051 | + . 'title="'.$required['msg'].'" '.$disabled.' '.$extra.'>' |
|
1052 | 1052 | . esc_textarea($answer) |
1053 | 1053 | . '</textarea>'; |
1054 | 1054 | |
1055 | 1055 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
1056 | - return $label_html . $input_html; |
|
1056 | + return $label_html.$input_html; |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
@@ -1090,7 +1090,7 @@ discard block |
||
1090 | 1090 | ) { |
1091 | 1091 | |
1092 | 1092 | // need these |
1093 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1093 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1094 | 1094 | return null; |
1095 | 1095 | } |
1096 | 1096 | // prep the answer |
@@ -1108,13 +1108,13 @@ discard block |
||
1108 | 1108 | // ya gots ta have style man!!! |
1109 | 1109 | $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
1110 | 1110 | $class = empty($class) ? $txt_class : $class; |
1111 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1111 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1112 | 1112 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
1113 | 1113 | |
1114 | 1114 | $label_html = |
1115 | 1115 | $required_text |
1116 | 1116 | . "\n\t\t\t" |
1117 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1117 | + . '<label for="'.$name.'" class="'.$label_class.'">' |
|
1118 | 1118 | . self::prep_question($question) |
1119 | 1119 | . $required['label'] |
1120 | 1120 | . '</label><br/>'; |
@@ -1123,16 +1123,16 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | $input_html = |
1125 | 1125 | "\n\t\t\t" |
1126 | - . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1127 | - . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
1126 | + . '<select name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" ' |
|
1127 | + . 'title="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>'; |
|
1128 | 1128 | // recursively count array elements, to determine total number of options |
1129 | 1129 | $only_option = count($options, 1) == 1; |
1130 | - if (! $only_option) { |
|
1130 | + if ( ! $only_option) { |
|
1131 | 1131 | // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
1132 | - $selected = $answer === null ? ' selected="selected"' : ''; |
|
1132 | + $selected = $answer === null ? ' selected="selected"' : ''; |
|
1133 | 1133 | $input_html .= $add_please_select_option |
1134 | 1134 | ? "\n\t\t\t\t" |
1135 | - . '<option value=""' . $selected . '>' |
|
1135 | + . '<option value=""'.$selected.'>' |
|
1136 | 1136 | . esc_html__(' - please select - ', 'event_espresso') |
1137 | 1137 | . '</option>' |
1138 | 1138 | : ''; |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | ); |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - $input_html .= "\n\t\t\t" . '</select>'; |
|
1158 | + $input_html .= "\n\t\t\t".'</select>'; |
|
1159 | 1159 | |
1160 | 1160 | $input_html = |
1161 | 1161 | apply_filters( |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | ); |
1171 | 1171 | |
1172 | 1172 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
1173 | - return $label_html . $input_html; |
|
1173 | + return $label_html.$input_html; |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | |
@@ -1188,11 +1188,11 @@ discard block |
||
1188 | 1188 | */ |
1189 | 1189 | private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
1190 | 1190 | { |
1191 | - $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
1191 | + $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">'; |
|
1192 | 1192 | foreach ($QSOs as $QSO) { |
1193 | 1193 | $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
1194 | 1194 | } |
1195 | - $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
1195 | + $html .= "\n\t\t\t\t".'</optgroup>'; |
|
1196 | 1196 | return $html; |
1197 | 1197 | } |
1198 | 1198 | |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | $value = ! empty($value) ? $value : $key; |
1220 | 1220 | $selected = ($answer == $key || $only_option) ? 'selected="selected"' : ''; |
1221 | 1221 | return "\n\t\t\t\t" |
1222 | - . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> ' |
|
1222 | + . '<option value="'.self::prep_option_value($key).'" '.$selected.'> ' |
|
1223 | 1223 | . $value |
1224 | 1224 | . ' </option>'; |
1225 | 1225 | } |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | $use_desc_4_label = false |
1264 | 1264 | ) { |
1265 | 1265 | // need these |
1266 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1266 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1267 | 1267 | return null; |
1268 | 1268 | } |
1269 | 1269 | // prep the answer |
@@ -1280,7 +1280,7 @@ discard block |
||
1280 | 1280 | $label_html = |
1281 | 1281 | $required_text |
1282 | 1282 | . "\n\t\t\t" |
1283 | - . '<label class="' . $label_class . '">' |
|
1283 | + . '<label class="'.$label_class.'">' |
|
1284 | 1284 | . self::prep_question($question) |
1285 | 1285 | . $required['label'] |
1286 | 1286 | . '</label> '; |
@@ -1289,49 +1289,49 @@ discard block |
||
1289 | 1289 | |
1290 | 1290 | $input_html = |
1291 | 1291 | "\n\t\t\t" |
1292 | - . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1292 | + . '<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$label_class.' '.$class.'-ul">'; |
|
1293 | 1293 | |
1294 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1295 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1294 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1295 | + $class .= ! empty($required['class']) ? ' '.$required['class'] : ''; |
|
1296 | 1296 | |
1297 | 1297 | foreach ($options as $OPT) { |
1298 | 1298 | if ($OPT instanceof EE_Question_Option) { |
1299 | 1299 | $value = self::prep_option_value($OPT->value()); |
1300 | 1300 | $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
1301 | 1301 | $size = $use_desc_4_label |
1302 | - ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) |
|
1302 | + ? self::get_label_size_class($OPT->value().' '.$OPT->desc()) |
|
1303 | 1303 | : self::get_label_size_class($OPT->value()); |
1304 | - $desc = $OPT->desc();// no self::prep_answer |
|
1304 | + $desc = $OPT->desc(); // no self::prep_answer |
|
1305 | 1305 | $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
1306 | 1306 | $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
1307 | - $opt = '-' . sanitize_key($value); |
|
1307 | + $opt = '-'.sanitize_key($value); |
|
1308 | 1308 | |
1309 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1310 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
1311 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
1309 | + $input_html .= "\n\t\t\t\t".'<li'.$size.'>'; |
|
1310 | + $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">'; |
|
1311 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>' : ''; |
|
1312 | 1312 | $input_html .= "\n\t\t\t\t\t\t" |
1313 | - . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" ' |
|
1314 | - . 'class="' . $class . '" value="' . $value . '" ' |
|
1315 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled |
|
1316 | - . $checked . ' ' . $extra . '/>'; |
|
1313 | + . '<input type="radio" name="'.$name.'" id="'.$id.$opt.'" ' |
|
1314 | + . 'class="'.$class.'" value="'.$value.'" ' |
|
1315 | + . 'title="'.esc_attr($required['msg']).'" '.$disabled |
|
1316 | + . $checked.' '.$extra.'/>'; |
|
1317 | 1317 | $input_html .= ! $label_b4 |
1318 | 1318 | ? "\n\t\t\t\t\t\t" |
1319 | 1319 | . '<span class="espresso-radio-btn-desc">' |
1320 | 1320 | . $label |
1321 | 1321 | . '</span>' |
1322 | 1322 | : ''; |
1323 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1323 | + $input_html .= "\n\t\t\t\t\t".'</label>'; |
|
1324 | 1324 | $input_html .= $use_desc_4_label |
1325 | 1325 | ? '' |
1326 | - : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
1327 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1326 | + : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>'; |
|
1327 | + $input_html .= "\n\t\t\t\t".'</li>'; |
|
1328 | 1328 | } |
1329 | 1329 | } |
1330 | 1330 | |
1331 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
1331 | + $input_html .= "\n\t\t\t".'</ul>'; |
|
1332 | 1332 | |
1333 | 1333 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
1334 | - return $label_html . $input_html; |
|
1334 | + return $label_html.$input_html; |
|
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | |
@@ -1366,7 +1366,7 @@ discard block |
||
1366 | 1366 | $use_html_entities = true |
1367 | 1367 | ) { |
1368 | 1368 | // need these |
1369 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1369 | + if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1370 | 1370 | return null; |
1371 | 1371 | } |
1372 | 1372 | $answer = maybe_unserialize($answer); |
@@ -1376,7 +1376,7 @@ discard block |
||
1376 | 1376 | |
1377 | 1377 | foreach ($answer as $key => $value) { |
1378 | 1378 | $key = self::prep_option_value($key); |
1379 | - $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
1379 | + $answer[$key] = self::prep_answer($value, $use_html_entities); |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | // prep the required array |
@@ -1391,7 +1391,7 @@ discard block |
||
1391 | 1391 | $label_html = |
1392 | 1392 | $required_text |
1393 | 1393 | . "\n\t\t\t" |
1394 | - . '<label class="' . $label_class . '">' |
|
1394 | + . '<label class="'.$label_class.'">' |
|
1395 | 1395 | . self::prep_question($question) |
1396 | 1396 | . $required['label'] |
1397 | 1397 | . '</label> '; |
@@ -1400,42 +1400,42 @@ discard block |
||
1400 | 1400 | |
1401 | 1401 | $input_html = |
1402 | 1402 | "\n\t\t\t" |
1403 | - . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1403 | + . '<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$label_class.' '.$class.'-ul">'; |
|
1404 | 1404 | |
1405 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1406 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1405 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1406 | + $class .= ! empty($required['class']) ? ' '.$required['class'] : ''; |
|
1407 | 1407 | |
1408 | 1408 | foreach ($options as $OPT) { |
1409 | - $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
1410 | - $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
1409 | + $value = $OPT->value(); // self::prep_option_value( $OPT->value() ); |
|
1410 | + $size = self::get_label_size_class($OPT->value().' '.$OPT->desc()); |
|
1411 | 1411 | $text = self::prep_answer($OPT->value()); |
1412 | 1412 | $desc = $OPT->desc(); |
1413 | - $opt = '-' . sanitize_key($value); |
|
1413 | + $opt = '-'.sanitize_key($value); |
|
1414 | 1414 | |
1415 | 1415 | $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
1416 | 1416 | |
1417 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1418 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
1419 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1417 | + $input_html .= "\n\t\t\t\t".'<li'.$size.'>'; |
|
1418 | + $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">'; |
|
1419 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : ''; |
|
1420 | 1420 | $input_html .= "\n\t\t\t\t\t\t" |
1421 | - . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" ' |
|
1422 | - . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" ' |
|
1423 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
1424 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1425 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1426 | - if (! empty($desc) && $desc != $text) { |
|
1421 | + . '<input type="checkbox" name="'.$name.'['.$OPT->ID().']" ' |
|
1422 | + . 'id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" ' |
|
1423 | + . 'title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>'; |
|
1424 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : ''; |
|
1425 | + $input_html .= "\n\t\t\t\t\t".'</label>'; |
|
1426 | + if ( ! empty($desc) && $desc != $text) { |
|
1427 | 1427 | $input_html .= "\n\t\t\t\t\t" |
1428 | 1428 | . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' |
1429 | 1429 | . $desc |
1430 | 1430 | . '</div>'; |
1431 | 1431 | } |
1432 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1432 | + $input_html .= "\n\t\t\t\t".'</li>'; |
|
1433 | 1433 | } |
1434 | 1434 | |
1435 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
1435 | + $input_html .= "\n\t\t\t".'</ul>'; |
|
1436 | 1436 | |
1437 | 1437 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
1438 | - return $label_html . $input_html; |
|
1438 | + return $label_html.$input_html; |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | |
@@ -1467,7 +1467,7 @@ discard block |
||
1467 | 1467 | $use_html_entities = true |
1468 | 1468 | ) { |
1469 | 1469 | // need these |
1470 | - if (! $question || ! $name) { |
|
1470 | + if ( ! $question || ! $name) { |
|
1471 | 1471 | return null; |
1472 | 1472 | } |
1473 | 1473 | // prep the answer |
@@ -1479,13 +1479,13 @@ discard block |
||
1479 | 1479 | // ya gots ta have style man!!! |
1480 | 1480 | $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
1481 | 1481 | $class = empty($class) ? $txt_class : $class; |
1482 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1482 | + $class .= ! empty($system_ID) ? ' '.$system_ID : ''; |
|
1483 | 1483 | $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
1484 | 1484 | |
1485 | 1485 | $label_html = |
1486 | 1486 | $required_text |
1487 | 1487 | . "\n\t\t\t" |
1488 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1488 | + . '<label for="'.$name.'" class="'.$label_class.'">' |
|
1489 | 1489 | . self::prep_question($question) |
1490 | 1490 | . $required['label'] |
1491 | 1491 | . '</label><br/>'; |
@@ -1494,14 +1494,14 @@ discard block |
||
1494 | 1494 | |
1495 | 1495 | $input_html = |
1496 | 1496 | "\n\t\t\t" |
1497 | - . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
1498 | - . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" ' |
|
1499 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1497 | + . '<input type="text" name="'.$name.'" id="'.$id.'" ' |
|
1498 | + . 'class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'" ' |
|
1499 | + . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>'; |
|
1500 | 1500 | |
1501 | 1501 | // enqueue scripts |
1502 | 1502 | wp_register_style( |
1503 | 1503 | 'espresso-ui-theme', |
1504 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1504 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1505 | 1505 | [], |
1506 | 1506 | EVENT_ESPRESSO_VERSION |
1507 | 1507 | ); |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | wp_enqueue_script('jquery-ui-datepicker'); |
1510 | 1510 | |
1511 | 1511 | $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
1512 | - return $label_html . $input_html; |
|
1512 | + return $label_html.$input_html; |
|
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | |
@@ -1536,7 +1536,7 @@ discard block |
||
1536 | 1536 | public static function hidden_input($name, $value, $id = '') |
1537 | 1537 | { |
1538 | 1538 | $id = ! empty($id) ? $id : $name; |
1539 | - return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1539 | + return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>'; |
|
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | |
@@ -1581,7 +1581,7 @@ discard block |
||
1581 | 1581 | $prepped_answer_options = []; |
1582 | 1582 | if (is_array($QSOs) && ! empty($QSOs)) { |
1583 | 1583 | foreach ($QSOs as $key => $QSO) { |
1584 | - if (! $QSO instanceof EE_Question_Option) { |
|
1584 | + if ( ! $QSO instanceof EE_Question_Option) { |
|
1585 | 1585 | $QSO = EE_Question_Option::new_instance( |
1586 | 1586 | [ |
1587 | 1587 | 'QSO_value' => is_array($QSO) && isset($QSO['id']) |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | ); |
1595 | 1595 | } |
1596 | 1596 | if ($QSO->opt_group()) { |
1597 | - $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1597 | + $prepped_answer_options[$QSO->opt_group()][] = $QSO; |
|
1598 | 1598 | } else { |
1599 | 1599 | $prepped_answer_options[] = $QSO; |
1600 | 1600 | } |
@@ -1806,7 +1806,7 @@ discard block |
||
1806 | 1806 | $options = []; |
1807 | 1807 | for ($x = 1; $x <= 12; $x++) { |
1808 | 1808 | $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
1809 | - $options[ $mm ] = $mm; |
|
1809 | + $options[$mm] = $mm; |
|
1810 | 1810 | } |
1811 | 1811 | return EEH_Form_Fields::prep_answer_options($options); |
1812 | 1812 | } |
@@ -1824,7 +1824,7 @@ discard block |
||
1824 | 1824 | $next_decade = $current_year + 10; |
1825 | 1825 | for ($x = $current_year; $x <= $next_decade; $x++) { |
1826 | 1826 | $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
1827 | - $options[ $yy ] = $yy; |
|
1827 | + $options[$yy] = $yy; |
|
1828 | 1828 | } |
1829 | 1829 | return EEH_Form_Fields::prep_answer_options($options); |
1830 | 1830 | } |
@@ -1843,7 +1843,7 @@ discard block |
||
1843 | 1843 | public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
1844 | 1844 | { |
1845 | 1845 | $_where = []; |
1846 | - if (! empty($status)) { |
|
1846 | + if ( ! empty($status)) { |
|
1847 | 1847 | $_where['STS_ID'] = $status; |
1848 | 1848 | } |
1849 | 1849 | |
@@ -1862,7 +1862,7 @@ discard block |
||
1862 | 1862 | ]; |
1863 | 1863 | |
1864 | 1864 | foreach ($regdtts as $regdtt) { |
1865 | - $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1865 | + $date = $regdtt->reg_month.' '.$regdtt->reg_year; |
|
1866 | 1866 | $options[] = [ |
1867 | 1867 | 'text' => $date, |
1868 | 1868 | 'id' => $date, |
@@ -1911,7 +1911,7 @@ discard block |
||
1911 | 1911 | // categories? |
1912 | 1912 | |
1913 | 1913 | |
1914 | - if (! empty($evt_category)) { |
|
1914 | + if ( ! empty($evt_category)) { |
|
1915 | 1915 | $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
1916 | 1916 | $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
1917 | 1917 | } |
@@ -1934,8 +1934,8 @@ discard block |
||
1934 | 1934 | global $wp_locale; |
1935 | 1935 | |
1936 | 1936 | foreach ($DTTS as $DTT) { |
1937 | - $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1938 | - $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1937 | + $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year; |
|
1938 | + $id = $DTT->dtt_month.' '.$DTT->dtt_year; |
|
1939 | 1939 | $options[] = [ |
1940 | 1940 | 'text' => $localized_date, |
1941 | 1941 | 'id' => $id, |
@@ -2008,16 +2008,16 @@ discard block |
||
2008 | 2008 | return $btn; |
2009 | 2009 | } |
2010 | 2010 | $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso'); |
2011 | - $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" ' |
|
2012 | - . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
2013 | - if (! $input_only) { |
|
2014 | - $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
2011 | + $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" ' |
|
2012 | + . 'type="submit" value="'.$text.'" '.$extra_attributes.'/>'; |
|
2013 | + if ( ! $input_only) { |
|
2014 | + $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">'; |
|
2015 | 2015 | $btn_frm .= ! empty($nonce_action) |
2016 | - ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) |
|
2016 | + ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false) |
|
2017 | 2017 | : ''; |
2018 | 2018 | $btn_frm .= $btn; |
2019 | 2019 | $btn_frm .= '</form>'; |
2020 | - $btn = $btn_frm; |
|
2020 | + $btn = $btn_frm; |
|
2021 | 2021 | unset($btn_frm); |
2022 | 2022 | } |
2023 | 2023 | return $btn; |
@@ -29,1997 +29,1997 @@ |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Generates HTML for the forms used on admin pages |
|
34 | - * |
|
35 | - * |
|
36 | - * @static |
|
37 | - * @access public |
|
38 | - * @param array $input_vars - array of input field details |
|
39 | - * format: |
|
40 | - * $template_form_fields['field-id'] = array( |
|
41 | - * 'name' => 'name_attribute', |
|
42 | - * 'label' => esc_html__('Field Label', 'event_espresso'), //or false |
|
43 | - * 'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', |
|
44 | - * 'checkbox', 'wp_editor' |
|
45 | - * 'type' => 'int', //what "type" the value is (i.e. string, int etc) |
|
46 | - * 'required' => false, //boolean for whether the field is required |
|
47 | - * 'validation' => true, //boolean, whether to validate the field (todo) |
|
48 | - * 'value' => 'some_value_for_field', //what value is used for field |
|
49 | - * 'format' => '%d', //what format the value is (%d, %f, or %s) |
|
50 | - * 'db-col' => 'column_in_db' //used to indicate which column the field corresponds with |
|
51 | - * in the db |
|
52 | - * 'options' => optiona, optionb || array('value' => 'label', '') //if the input type is |
|
53 | - * "select", this allows you to set the args for the different <option> tags. |
|
54 | - * 'tabindex' => 1 //this allows you to set the tabindex for the field. |
|
55 | - * 'append_content' => '' //this allows you to send in html content to append to the |
|
56 | - * field. |
|
57 | - * ) |
|
58 | - * @param array $form_id - used for defining unique identifiers for the form. |
|
59 | - * @return string |
|
60 | - * @todo : at some point we can break this down into other static methods to abstract it a bit better. |
|
61 | - */ |
|
62 | - public static function get_form_fields($input_vars = [], $form_id = false) |
|
63 | - { |
|
64 | - |
|
65 | - if (empty($input_vars)) { |
|
66 | - EE_Error::add_error( |
|
67 | - esc_html__('missing required variables for the form field generator', 'event_espresso'), |
|
68 | - __FILE__, |
|
69 | - __FUNCTION__, |
|
70 | - __LINE__ |
|
71 | - ); |
|
72 | - return false; |
|
73 | - } |
|
74 | - |
|
75 | - $output = ""; |
|
76 | - $inputs = []; |
|
77 | - $hidden_inputs = []; |
|
78 | - |
|
79 | - // cycle thru inputs |
|
80 | - foreach ($input_vars as $input_key => $input_value) { |
|
81 | - $defaults = [ |
|
82 | - 'append_content' => '', |
|
83 | - 'css_class' => '', |
|
84 | - 'cols' => 80, |
|
85 | - 'db-col' => 'column_in_db', |
|
86 | - 'format' => '%d', |
|
87 | - 'input' => 'hidden', |
|
88 | - 'label' => esc_html__('No label', 'event_espresso'), |
|
89 | - 'name' => $input_key, |
|
90 | - 'options' => [], |
|
91 | - 'required' => false, |
|
92 | - 'tabindex' => 0, |
|
93 | - 'rows' => 10, |
|
94 | - 'type' => 'int', |
|
95 | - 'validation' => true, |
|
96 | - 'value' => 'some_value_for_field', |
|
97 | - ]; |
|
98 | - |
|
99 | - $input_value = wp_parse_args($input_value, $defaults); |
|
100 | - |
|
101 | - $append_content = $input_value['append_content']; |
|
102 | - $css_class = $input_value['css_class']; |
|
103 | - $cols = $input_value['cols']; |
|
104 | - $label = $input_value['label']; |
|
105 | - $name = $input_value['name']; |
|
106 | - $options = $input_value['options']; |
|
107 | - $required = $input_value['required']; |
|
108 | - $tab_index = $input_value['tabindex']; |
|
109 | - $rows = $input_value['rows']; |
|
110 | - $type = $input_value['input']; |
|
111 | - $value = $input_value['value']; |
|
112 | - |
|
113 | - $id = $form_id ? $form_id . '-' . $input_key : $input_key; |
|
114 | - $class = $required ? 'required ' . $css_class : $css_class; |
|
115 | - |
|
116 | - // what type of input are we dealing with ? |
|
117 | - switch ($type) { |
|
118 | - case 'checkbox': |
|
119 | - case 'radio': |
|
120 | - $field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label); |
|
121 | - $field .= $append_content ?: ''; |
|
122 | - break; |
|
123 | - |
|
124 | - case 'hidden': |
|
125 | - $field = null; |
|
126 | - $hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value); |
|
127 | - break; |
|
128 | - |
|
129 | - case 'select': |
|
130 | - $options = is_array($options) ? $options : explode(',', $options); |
|
131 | - $field = self::adminLabel($id, $label, $required); |
|
132 | - $field .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options); |
|
133 | - $field .= $append_content ?: ''; |
|
134 | - break; |
|
135 | - |
|
136 | - case 'textarea': |
|
137 | - $field = self::adminLabel($id, $label, $required); |
|
138 | - $field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value); |
|
139 | - $field .= $append_content ?: ''; |
|
140 | - break; |
|
141 | - |
|
142 | - case 'wp_editor': |
|
143 | - $label = esc_html($label); |
|
144 | - $field = "<h4>{$label}</h4>"; |
|
145 | - $field .= $append_content ?: ''; |
|
146 | - $field .= self::adminWpEditor( |
|
147 | - $class, |
|
148 | - $id, |
|
149 | - $name, |
|
150 | - $rows, |
|
151 | - $tab_index, |
|
152 | - $value |
|
153 | - ); |
|
154 | - break; |
|
155 | - |
|
156 | - default: |
|
157 | - $field = self::adminLabel($id, $label, $required); |
|
158 | - $field .= self::adminText($class, $id, $name, $required, $tab_index, $value); |
|
159 | - $field .= $append_content ?: ''; |
|
160 | - } |
|
161 | - if ($field) { |
|
162 | - $inputs[] = $field; |
|
163 | - } |
|
164 | - } // end foreach( $input_vars as $input_key => $input_value ) |
|
165 | - |
|
166 | - if (! empty($inputs)) { |
|
167 | - $glue = " |
|
32 | + /** |
|
33 | + * Generates HTML for the forms used on admin pages |
|
34 | + * |
|
35 | + * |
|
36 | + * @static |
|
37 | + * @access public |
|
38 | + * @param array $input_vars - array of input field details |
|
39 | + * format: |
|
40 | + * $template_form_fields['field-id'] = array( |
|
41 | + * 'name' => 'name_attribute', |
|
42 | + * 'label' => esc_html__('Field Label', 'event_espresso'), //or false |
|
43 | + * 'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden', |
|
44 | + * 'checkbox', 'wp_editor' |
|
45 | + * 'type' => 'int', //what "type" the value is (i.e. string, int etc) |
|
46 | + * 'required' => false, //boolean for whether the field is required |
|
47 | + * 'validation' => true, //boolean, whether to validate the field (todo) |
|
48 | + * 'value' => 'some_value_for_field', //what value is used for field |
|
49 | + * 'format' => '%d', //what format the value is (%d, %f, or %s) |
|
50 | + * 'db-col' => 'column_in_db' //used to indicate which column the field corresponds with |
|
51 | + * in the db |
|
52 | + * 'options' => optiona, optionb || array('value' => 'label', '') //if the input type is |
|
53 | + * "select", this allows you to set the args for the different <option> tags. |
|
54 | + * 'tabindex' => 1 //this allows you to set the tabindex for the field. |
|
55 | + * 'append_content' => '' //this allows you to send in html content to append to the |
|
56 | + * field. |
|
57 | + * ) |
|
58 | + * @param array $form_id - used for defining unique identifiers for the form. |
|
59 | + * @return string |
|
60 | + * @todo : at some point we can break this down into other static methods to abstract it a bit better. |
|
61 | + */ |
|
62 | + public static function get_form_fields($input_vars = [], $form_id = false) |
|
63 | + { |
|
64 | + |
|
65 | + if (empty($input_vars)) { |
|
66 | + EE_Error::add_error( |
|
67 | + esc_html__('missing required variables for the form field generator', 'event_espresso'), |
|
68 | + __FILE__, |
|
69 | + __FUNCTION__, |
|
70 | + __LINE__ |
|
71 | + ); |
|
72 | + return false; |
|
73 | + } |
|
74 | + |
|
75 | + $output = ""; |
|
76 | + $inputs = []; |
|
77 | + $hidden_inputs = []; |
|
78 | + |
|
79 | + // cycle thru inputs |
|
80 | + foreach ($input_vars as $input_key => $input_value) { |
|
81 | + $defaults = [ |
|
82 | + 'append_content' => '', |
|
83 | + 'css_class' => '', |
|
84 | + 'cols' => 80, |
|
85 | + 'db-col' => 'column_in_db', |
|
86 | + 'format' => '%d', |
|
87 | + 'input' => 'hidden', |
|
88 | + 'label' => esc_html__('No label', 'event_espresso'), |
|
89 | + 'name' => $input_key, |
|
90 | + 'options' => [], |
|
91 | + 'required' => false, |
|
92 | + 'tabindex' => 0, |
|
93 | + 'rows' => 10, |
|
94 | + 'type' => 'int', |
|
95 | + 'validation' => true, |
|
96 | + 'value' => 'some_value_for_field', |
|
97 | + ]; |
|
98 | + |
|
99 | + $input_value = wp_parse_args($input_value, $defaults); |
|
100 | + |
|
101 | + $append_content = $input_value['append_content']; |
|
102 | + $css_class = $input_value['css_class']; |
|
103 | + $cols = $input_value['cols']; |
|
104 | + $label = $input_value['label']; |
|
105 | + $name = $input_value['name']; |
|
106 | + $options = $input_value['options']; |
|
107 | + $required = $input_value['required']; |
|
108 | + $tab_index = $input_value['tabindex']; |
|
109 | + $rows = $input_value['rows']; |
|
110 | + $type = $input_value['input']; |
|
111 | + $value = $input_value['value']; |
|
112 | + |
|
113 | + $id = $form_id ? $form_id . '-' . $input_key : $input_key; |
|
114 | + $class = $required ? 'required ' . $css_class : $css_class; |
|
115 | + |
|
116 | + // what type of input are we dealing with ? |
|
117 | + switch ($type) { |
|
118 | + case 'checkbox': |
|
119 | + case 'radio': |
|
120 | + $field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label); |
|
121 | + $field .= $append_content ?: ''; |
|
122 | + break; |
|
123 | + |
|
124 | + case 'hidden': |
|
125 | + $field = null; |
|
126 | + $hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value); |
|
127 | + break; |
|
128 | + |
|
129 | + case 'select': |
|
130 | + $options = is_array($options) ? $options : explode(',', $options); |
|
131 | + $field = self::adminLabel($id, $label, $required); |
|
132 | + $field .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options); |
|
133 | + $field .= $append_content ?: ''; |
|
134 | + break; |
|
135 | + |
|
136 | + case 'textarea': |
|
137 | + $field = self::adminLabel($id, $label, $required); |
|
138 | + $field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value); |
|
139 | + $field .= $append_content ?: ''; |
|
140 | + break; |
|
141 | + |
|
142 | + case 'wp_editor': |
|
143 | + $label = esc_html($label); |
|
144 | + $field = "<h4>{$label}</h4>"; |
|
145 | + $field .= $append_content ?: ''; |
|
146 | + $field .= self::adminWpEditor( |
|
147 | + $class, |
|
148 | + $id, |
|
149 | + $name, |
|
150 | + $rows, |
|
151 | + $tab_index, |
|
152 | + $value |
|
153 | + ); |
|
154 | + break; |
|
155 | + |
|
156 | + default: |
|
157 | + $field = self::adminLabel($id, $label, $required); |
|
158 | + $field .= self::adminText($class, $id, $name, $required, $tab_index, $value); |
|
159 | + $field .= $append_content ?: ''; |
|
160 | + } |
|
161 | + if ($field) { |
|
162 | + $inputs[] = $field; |
|
163 | + } |
|
164 | + } // end foreach( $input_vars as $input_key => $input_value ) |
|
165 | + |
|
166 | + if (! empty($inputs)) { |
|
167 | + $glue = " |
|
168 | 168 | </li> |
169 | 169 | <li> |
170 | 170 | "; |
171 | - $inputs = implode($glue, $inputs); |
|
172 | - $output = " |
|
171 | + $inputs = implode($glue, $inputs); |
|
172 | + $output = " |
|
173 | 173 | <ul> |
174 | 174 | <li> |
175 | 175 | {$inputs} |
176 | 176 | </li> |
177 | 177 | </ul> |
178 | 178 | "; |
179 | - } |
|
180 | - return $output . implode("\n", $hidden_inputs); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * form_fields_array |
|
186 | - * This utility function assembles form fields from a given structured array with field information. |
|
187 | - * //TODO: This is an alternate generator that we may want to use instead. |
|
188 | - * |
|
189 | - * @param array $fields structured array of fields to assemble in the following format: |
|
190 | - * [field_name] => array( |
|
191 | - * ['label'] => 'label for field', |
|
192 | - * ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select |
|
193 | - * type of field you can indicated the labels for each option via this index |
|
194 | - * ['extra_desc'] => 'extra description for the field', //optional |
|
195 | - * ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults |
|
196 | - * to text |
|
197 | - * ['value'] => 'value that goes in the field', //(if multi then this is an array of values |
|
198 | - * and the 'default' paramater will be used for what is selected) |
|
199 | - * ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)', |
|
200 | - * ['class'] => 'name-of-class(es)-for-input', |
|
201 | - * ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi |
|
202 | - * select type of field you can indicate the css class for each option via this index. |
|
203 | - * ['id'] => 'css-id-for-input') //defaults to 'field_name' |
|
204 | - * ['unique_id'] => 1 //defaults to empty string. This is useful for when the fields |
|
205 | - * generated are going to be used in a loop and you want to make sure that the field |
|
206 | - * identifiers are unique from each other. |
|
207 | - * ['dimensions'] => array(100,300), //defaults to empty array. This is used by field types |
|
208 | - * such as textarea to indicate cols/rows. |
|
209 | - * ['tabindex'] => '' //this allows you to set the tabindex for the field. |
|
210 | - * ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally |
|
211 | - * contain an array of arguments for the editor setup. |
|
212 | - * |
|
213 | - * @return array an array of inputs for form indexed by field name, and in the following structure: |
|
214 | - * [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}' |
|
215 | - */ |
|
216 | - public static function get_form_fields_array($fields) |
|
217 | - { |
|
218 | - |
|
219 | - $form_fields = []; |
|
220 | - $fields = (array) $fields; |
|
221 | - |
|
222 | - foreach ($fields as $field_name => $field_atts) { |
|
223 | - // defaults: |
|
224 | - $defaults = [ |
|
225 | - 'class' => '', |
|
226 | - 'classes' => '', |
|
227 | - 'default' => '', |
|
228 | - 'dimensions' => ['10', '5'], |
|
229 | - 'extra_desc' => '', |
|
230 | - 'id' => $field_name, |
|
231 | - 'label' => '', |
|
232 | - 'labels' => '', |
|
233 | - 'required' => false, |
|
234 | - 'tabindex' => 0, |
|
235 | - 'type' => 'text', |
|
236 | - 'unique_id' => '', |
|
237 | - 'value' => '', |
|
238 | - 'wpeditor_args' => [], |
|
239 | - ]; |
|
240 | - // merge defaults with passed arguments |
|
241 | - $_fields = wp_parse_args($field_atts, $defaults); |
|
242 | - |
|
243 | - $class = $_fields['class']; |
|
244 | - $classes = $_fields['classes']; |
|
245 | - $default = $_fields['default']; |
|
246 | - $dims = $_fields['dimensions']; |
|
247 | - $extra_desc = $_fields['extra_desc']; |
|
248 | - $id = $_fields['id']; |
|
249 | - $label = $_fields['label']; |
|
250 | - $labels = $_fields['labels']; |
|
251 | - $required = $_fields['required']; |
|
252 | - $tab_index = $_fields['tabindex']; |
|
253 | - $type = $_fields['type']; |
|
254 | - $unique_id = $_fields['unique_id']; |
|
255 | - $value = $_fields['value']; |
|
256 | - $wp_editor_args = $_fields['wpeditor_args']; |
|
257 | - |
|
258 | - // generate label |
|
259 | - $label = ! empty($label) ? self::adminLabel($id, $label, $required) : ''; |
|
260 | - // generate field name |
|
261 | - $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
262 | - |
|
263 | - // we determine what we're building based on the type |
|
264 | - switch ($type) { |
|
265 | - case 'checkbox': |
|
266 | - case 'radio': |
|
267 | - if (is_array($value)) { |
|
268 | - $c_input = ''; |
|
269 | - foreach ($value as $key => $val) { |
|
270 | - $c_input .= self::adminMulti( |
|
271 | - $default, |
|
272 | - isset($classes[ $key ]) ? $classes[ $key ] : '', |
|
273 | - $field_name . '_' . $value, |
|
274 | - $name, |
|
275 | - $required, |
|
276 | - $tab_index, |
|
277 | - $type, |
|
278 | - $val, |
|
279 | - isset($labels[ $key ]) ? $labels[ $key ] : '' |
|
280 | - ); |
|
281 | - } |
|
282 | - $field = $c_input; |
|
283 | - } else { |
|
284 | - $field = self::adminMulti( |
|
285 | - $default, |
|
286 | - $class, |
|
287 | - $id, |
|
288 | - $name, |
|
289 | - $required, |
|
290 | - $tab_index, |
|
291 | - $type, |
|
292 | - $value, |
|
293 | - $_fields['label'] |
|
294 | - ); |
|
295 | - } |
|
296 | - break; |
|
297 | - |
|
298 | - case 'hidden': |
|
299 | - $field = self::adminHidden($class, $id, $name, $value); |
|
300 | - break; |
|
301 | - |
|
302 | - case 'select': |
|
303 | - $options = []; |
|
304 | - foreach ($value as $key => $val) { |
|
305 | - $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : ''; |
|
306 | - } |
|
307 | - $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options); |
|
308 | - break; |
|
309 | - |
|
310 | - case 'textarea': |
|
311 | - $field = |
|
312 | - self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value); |
|
313 | - break; |
|
314 | - |
|
315 | - case 'wp_editor': |
|
316 | - $field = self::adminWpEditor( |
|
317 | - $class, |
|
318 | - $_fields['id'], |
|
319 | - $name, |
|
320 | - $dims[1], |
|
321 | - $tab_index, |
|
322 | - $value, |
|
323 | - $wp_editor_args |
|
324 | - ); |
|
325 | - break; |
|
326 | - |
|
327 | - default: |
|
328 | - $field = self::adminText($class, $id, $name, $required, $tab_index, $value); |
|
329 | - } |
|
330 | - |
|
331 | - $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc]; |
|
332 | - } |
|
333 | - |
|
334 | - return $form_fields; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $class |
|
340 | - * @param string $id |
|
341 | - * @param string $name |
|
342 | - * @param string $value |
|
343 | - * @return string |
|
344 | - * @since 4.10.14.p |
|
345 | - */ |
|
346 | - private static function adminHidden($class, $id, $name, $value) |
|
347 | - { |
|
348 | - $id = esc_attr($id); |
|
349 | - $name = esc_attr($name); |
|
350 | - $class = esc_attr($class); |
|
351 | - return " |
|
179 | + } |
|
180 | + return $output . implode("\n", $hidden_inputs); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * form_fields_array |
|
186 | + * This utility function assembles form fields from a given structured array with field information. |
|
187 | + * //TODO: This is an alternate generator that we may want to use instead. |
|
188 | + * |
|
189 | + * @param array $fields structured array of fields to assemble in the following format: |
|
190 | + * [field_name] => array( |
|
191 | + * ['label'] => 'label for field', |
|
192 | + * ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select |
|
193 | + * type of field you can indicated the labels for each option via this index |
|
194 | + * ['extra_desc'] => 'extra description for the field', //optional |
|
195 | + * ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults |
|
196 | + * to text |
|
197 | + * ['value'] => 'value that goes in the field', //(if multi then this is an array of values |
|
198 | + * and the 'default' paramater will be used for what is selected) |
|
199 | + * ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)', |
|
200 | + * ['class'] => 'name-of-class(es)-for-input', |
|
201 | + * ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi |
|
202 | + * select type of field you can indicate the css class for each option via this index. |
|
203 | + * ['id'] => 'css-id-for-input') //defaults to 'field_name' |
|
204 | + * ['unique_id'] => 1 //defaults to empty string. This is useful for when the fields |
|
205 | + * generated are going to be used in a loop and you want to make sure that the field |
|
206 | + * identifiers are unique from each other. |
|
207 | + * ['dimensions'] => array(100,300), //defaults to empty array. This is used by field types |
|
208 | + * such as textarea to indicate cols/rows. |
|
209 | + * ['tabindex'] => '' //this allows you to set the tabindex for the field. |
|
210 | + * ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally |
|
211 | + * contain an array of arguments for the editor setup. |
|
212 | + * |
|
213 | + * @return array an array of inputs for form indexed by field name, and in the following structure: |
|
214 | + * [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}' |
|
215 | + */ |
|
216 | + public static function get_form_fields_array($fields) |
|
217 | + { |
|
218 | + |
|
219 | + $form_fields = []; |
|
220 | + $fields = (array) $fields; |
|
221 | + |
|
222 | + foreach ($fields as $field_name => $field_atts) { |
|
223 | + // defaults: |
|
224 | + $defaults = [ |
|
225 | + 'class' => '', |
|
226 | + 'classes' => '', |
|
227 | + 'default' => '', |
|
228 | + 'dimensions' => ['10', '5'], |
|
229 | + 'extra_desc' => '', |
|
230 | + 'id' => $field_name, |
|
231 | + 'label' => '', |
|
232 | + 'labels' => '', |
|
233 | + 'required' => false, |
|
234 | + 'tabindex' => 0, |
|
235 | + 'type' => 'text', |
|
236 | + 'unique_id' => '', |
|
237 | + 'value' => '', |
|
238 | + 'wpeditor_args' => [], |
|
239 | + ]; |
|
240 | + // merge defaults with passed arguments |
|
241 | + $_fields = wp_parse_args($field_atts, $defaults); |
|
242 | + |
|
243 | + $class = $_fields['class']; |
|
244 | + $classes = $_fields['classes']; |
|
245 | + $default = $_fields['default']; |
|
246 | + $dims = $_fields['dimensions']; |
|
247 | + $extra_desc = $_fields['extra_desc']; |
|
248 | + $id = $_fields['id']; |
|
249 | + $label = $_fields['label']; |
|
250 | + $labels = $_fields['labels']; |
|
251 | + $required = $_fields['required']; |
|
252 | + $tab_index = $_fields['tabindex']; |
|
253 | + $type = $_fields['type']; |
|
254 | + $unique_id = $_fields['unique_id']; |
|
255 | + $value = $_fields['value']; |
|
256 | + $wp_editor_args = $_fields['wpeditor_args']; |
|
257 | + |
|
258 | + // generate label |
|
259 | + $label = ! empty($label) ? self::adminLabel($id, $label, $required) : ''; |
|
260 | + // generate field name |
|
261 | + $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name; |
|
262 | + |
|
263 | + // we determine what we're building based on the type |
|
264 | + switch ($type) { |
|
265 | + case 'checkbox': |
|
266 | + case 'radio': |
|
267 | + if (is_array($value)) { |
|
268 | + $c_input = ''; |
|
269 | + foreach ($value as $key => $val) { |
|
270 | + $c_input .= self::adminMulti( |
|
271 | + $default, |
|
272 | + isset($classes[ $key ]) ? $classes[ $key ] : '', |
|
273 | + $field_name . '_' . $value, |
|
274 | + $name, |
|
275 | + $required, |
|
276 | + $tab_index, |
|
277 | + $type, |
|
278 | + $val, |
|
279 | + isset($labels[ $key ]) ? $labels[ $key ] : '' |
|
280 | + ); |
|
281 | + } |
|
282 | + $field = $c_input; |
|
283 | + } else { |
|
284 | + $field = self::adminMulti( |
|
285 | + $default, |
|
286 | + $class, |
|
287 | + $id, |
|
288 | + $name, |
|
289 | + $required, |
|
290 | + $tab_index, |
|
291 | + $type, |
|
292 | + $value, |
|
293 | + $_fields['label'] |
|
294 | + ); |
|
295 | + } |
|
296 | + break; |
|
297 | + |
|
298 | + case 'hidden': |
|
299 | + $field = self::adminHidden($class, $id, $name, $value); |
|
300 | + break; |
|
301 | + |
|
302 | + case 'select': |
|
303 | + $options = []; |
|
304 | + foreach ($value as $key => $val) { |
|
305 | + $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : ''; |
|
306 | + } |
|
307 | + $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options); |
|
308 | + break; |
|
309 | + |
|
310 | + case 'textarea': |
|
311 | + $field = |
|
312 | + self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value); |
|
313 | + break; |
|
314 | + |
|
315 | + case 'wp_editor': |
|
316 | + $field = self::adminWpEditor( |
|
317 | + $class, |
|
318 | + $_fields['id'], |
|
319 | + $name, |
|
320 | + $dims[1], |
|
321 | + $tab_index, |
|
322 | + $value, |
|
323 | + $wp_editor_args |
|
324 | + ); |
|
325 | + break; |
|
326 | + |
|
327 | + default: |
|
328 | + $field = self::adminText($class, $id, $name, $required, $tab_index, $value); |
|
329 | + } |
|
330 | + |
|
331 | + $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc]; |
|
332 | + } |
|
333 | + |
|
334 | + return $form_fields; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $class |
|
340 | + * @param string $id |
|
341 | + * @param string $name |
|
342 | + * @param string $value |
|
343 | + * @return string |
|
344 | + * @since 4.10.14.p |
|
345 | + */ |
|
346 | + private static function adminHidden($class, $id, $name, $value) |
|
347 | + { |
|
348 | + $id = esc_attr($id); |
|
349 | + $name = esc_attr($name); |
|
350 | + $class = esc_attr($class); |
|
351 | + return " |
|
352 | 352 | <input name='{$name}' type='hidden' id='{$id}' class='{$class}' value='{$value}' />"; |
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @param string $id |
|
358 | - * @param string $label |
|
359 | - * @param string $required |
|
360 | - * @return string |
|
361 | - * @since 4.10.14.p |
|
362 | - */ |
|
363 | - private static function adminLabel($id, $label, $required) |
|
364 | - { |
|
365 | - $id = esc_attr($id); |
|
366 | - $label = esc_html($label); |
|
367 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : ''; |
|
368 | - return "<label for='{$id}'>{$label}{$required}</label>"; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @param string $default |
|
374 | - * @param string $class |
|
375 | - * @param string $id |
|
376 | - * @param string $name |
|
377 | - * @param string $required |
|
378 | - * @param int $tab_index |
|
379 | - * @param string $type |
|
380 | - * @param string $value |
|
381 | - * @param string $label |
|
382 | - * @return string |
|
383 | - * @since 4.10.14.p |
|
384 | - */ |
|
385 | - private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '') |
|
386 | - { |
|
387 | - $id = esc_attr($id); |
|
388 | - $name = esc_attr($name); |
|
389 | - $class = esc_attr($class); |
|
390 | - $tab_index = absint($tab_index); |
|
391 | - $checked = ! empty($default) && $default == $value ? 'checked="checked" ' : ''; |
|
392 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
393 | - $input = " |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @param string $id |
|
358 | + * @param string $label |
|
359 | + * @param string $required |
|
360 | + * @return string |
|
361 | + * @since 4.10.14.p |
|
362 | + */ |
|
363 | + private static function adminLabel($id, $label, $required) |
|
364 | + { |
|
365 | + $id = esc_attr($id); |
|
366 | + $label = esc_html($label); |
|
367 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : ''; |
|
368 | + return "<label for='{$id}'>{$label}{$required}</label>"; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @param string $default |
|
374 | + * @param string $class |
|
375 | + * @param string $id |
|
376 | + * @param string $name |
|
377 | + * @param string $required |
|
378 | + * @param int $tab_index |
|
379 | + * @param string $type |
|
380 | + * @param string $value |
|
381 | + * @param string $label |
|
382 | + * @return string |
|
383 | + * @since 4.10.14.p |
|
384 | + */ |
|
385 | + private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '') |
|
386 | + { |
|
387 | + $id = esc_attr($id); |
|
388 | + $name = esc_attr($name); |
|
389 | + $class = esc_attr($class); |
|
390 | + $tab_index = absint($tab_index); |
|
391 | + $checked = ! empty($default) && $default == $value ? 'checked="checked" ' : ''; |
|
392 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
393 | + $input = " |
|
394 | 394 | <input name='{$name}[]' type='{$type}' id='{$id}' class='{$class}' value='{$value}' {$checked} {$required} tabindex='{$tab_index}'/>"; |
395 | - if ($label === '') { |
|
396 | - return $input; |
|
397 | - } |
|
398 | - $label = esc_html($label); |
|
399 | - return " |
|
395 | + if ($label === '') { |
|
396 | + return $input; |
|
397 | + } |
|
398 | + $label = esc_html($label); |
|
399 | + return " |
|
400 | 400 | <label for='$id'> |
401 | 401 | {$input} |
402 | 402 | {$label} |
403 | 403 | </label>"; |
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @param string $default |
|
409 | - * @param string $class |
|
410 | - * @param string $id |
|
411 | - * @param string $name |
|
412 | - * @param string $required |
|
413 | - * @param int $tab_index |
|
414 | - * @param array $options |
|
415 | - * @return string |
|
416 | - * @since 4.10.14.p |
|
417 | - */ |
|
418 | - private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = []) |
|
419 | - { |
|
420 | - $options_array = []; |
|
421 | - foreach ($options as $value => $label) { |
|
422 | - $selected = ! empty($default) && $default == $value ? 'selected="selected"' : ''; |
|
423 | - $value = esc_attr($value); |
|
424 | - $label = wp_strip_all_tags($label); |
|
425 | - $options_array[] = "<option value='{$value}' {$selected}>{$label}</option>"; |
|
426 | - } |
|
427 | - $options_html = implode($options_array, "\n"); |
|
428 | - $id = esc_attr($id); |
|
429 | - $name = esc_attr($name); |
|
430 | - $class = esc_attr($class); |
|
431 | - $tab_index = absint($tab_index); |
|
432 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
433 | - return " |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @param string $default |
|
409 | + * @param string $class |
|
410 | + * @param string $id |
|
411 | + * @param string $name |
|
412 | + * @param string $required |
|
413 | + * @param int $tab_index |
|
414 | + * @param array $options |
|
415 | + * @return string |
|
416 | + * @since 4.10.14.p |
|
417 | + */ |
|
418 | + private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = []) |
|
419 | + { |
|
420 | + $options_array = []; |
|
421 | + foreach ($options as $value => $label) { |
|
422 | + $selected = ! empty($default) && $default == $value ? 'selected="selected"' : ''; |
|
423 | + $value = esc_attr($value); |
|
424 | + $label = wp_strip_all_tags($label); |
|
425 | + $options_array[] = "<option value='{$value}' {$selected}>{$label}</option>"; |
|
426 | + } |
|
427 | + $options_html = implode($options_array, "\n"); |
|
428 | + $id = esc_attr($id); |
|
429 | + $name = esc_attr($name); |
|
430 | + $class = esc_attr($class); |
|
431 | + $tab_index = absint($tab_index); |
|
432 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
433 | + return " |
|
434 | 434 | <select name='{$name}' id='{$id}' class='{$class}' {$required} tabindex='{$tab_index}'> |
435 | 435 | {$options_html} |
436 | 436 | </select>"; |
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @param string $class |
|
442 | - * @param string $id |
|
443 | - * @param string $name |
|
444 | - * @param string $required |
|
445 | - * @param int $tab_index |
|
446 | - * @param string $value |
|
447 | - * @return string |
|
448 | - * @since 4.10.14.p |
|
449 | - */ |
|
450 | - private static function adminText($class, $id, $name, $required, $tab_index, $value) |
|
451 | - { |
|
452 | - $id = esc_attr($id); |
|
453 | - $name = esc_attr($name); |
|
454 | - $class = esc_attr($class); |
|
455 | - $tab_index = absint($tab_index); |
|
456 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
457 | - return " |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @param string $class |
|
442 | + * @param string $id |
|
443 | + * @param string $name |
|
444 | + * @param string $required |
|
445 | + * @param int $tab_index |
|
446 | + * @param string $value |
|
447 | + * @return string |
|
448 | + * @since 4.10.14.p |
|
449 | + */ |
|
450 | + private static function adminText($class, $id, $name, $required, $tab_index, $value) |
|
451 | + { |
|
452 | + $id = esc_attr($id); |
|
453 | + $name = esc_attr($name); |
|
454 | + $class = esc_attr($class); |
|
455 | + $tab_index = absint($tab_index); |
|
456 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
457 | + return " |
|
458 | 458 | <input name='{$name}' type='text' id='{$id}' class='{$class}' value='{$value}' {$required} tabindex='{$tab_index}'/>"; |
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param string $class |
|
464 | - * @param int $cols |
|
465 | - * @param string $id |
|
466 | - * @param string $name |
|
467 | - * @param string $required |
|
468 | - * @param int $rows |
|
469 | - * @param int $tab_index |
|
470 | - * @param string $value |
|
471 | - * @return string |
|
472 | - * @since 4.10.14.p |
|
473 | - */ |
|
474 | - private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value) |
|
475 | - { |
|
476 | - $id = esc_attr($id); |
|
477 | - $name = esc_attr($name); |
|
478 | - $class = esc_attr($class); |
|
479 | - $cols = absint($cols); |
|
480 | - $rows = absint($rows); |
|
481 | - $value = esc_textarea($value); |
|
482 | - $tab_index = absint($tab_index); |
|
483 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
484 | - return " |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param string $class |
|
464 | + * @param int $cols |
|
465 | + * @param string $id |
|
466 | + * @param string $name |
|
467 | + * @param string $required |
|
468 | + * @param int $rows |
|
469 | + * @param int $tab_index |
|
470 | + * @param string $value |
|
471 | + * @return string |
|
472 | + * @since 4.10.14.p |
|
473 | + */ |
|
474 | + private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value) |
|
475 | + { |
|
476 | + $id = esc_attr($id); |
|
477 | + $name = esc_attr($name); |
|
478 | + $class = esc_attr($class); |
|
479 | + $cols = absint($cols); |
|
480 | + $rows = absint($rows); |
|
481 | + $value = esc_textarea($value); |
|
482 | + $tab_index = absint($tab_index); |
|
483 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : ''; |
|
484 | + return " |
|
485 | 485 | <textarea name='{$name}' id='{$id}' class='{$class}' rows='{$rows}' cols='{$cols}' {$required} tabindex='{$tab_index}'> |
486 | 486 | {$value} |
487 | 487 | </textarea>"; |
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * @param string $class |
|
493 | - * @param string $id |
|
494 | - * @param string $name |
|
495 | - * @param int $rows |
|
496 | - * @param int $tab_index |
|
497 | - * @param string $value |
|
498 | - * @param array $wp_editor_args |
|
499 | - * @return false|string |
|
500 | - * @since 4.10.14.p |
|
501 | - */ |
|
502 | - private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = []) |
|
503 | - { |
|
504 | - $editor_settings = $wp_editor_args + [ |
|
505 | - 'textarea_name' => esc_attr($name), |
|
506 | - 'textarea_rows' => absint($rows), |
|
507 | - 'editor_class' => esc_attr($class), |
|
508 | - 'tabindex' => absint($tab_index), |
|
509 | - ]; |
|
510 | - ob_start(); |
|
511 | - wp_editor($value, esc_attr($id), $editor_settings); |
|
512 | - return ob_get_clean(); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * espresso admin page select_input |
|
518 | - * Turns an array into a select fields |
|
519 | - * |
|
520 | - * @static |
|
521 | - * @access public |
|
522 | - * @param string $name field name |
|
523 | - * @param array $values option values, numbered array starting at 0, where each value is an array with a key |
|
524 | - * 'text' (meaning text to display' and 'id' (meaning the internal value) eg: |
|
525 | - * array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or |
|
526 | - * as an array of key-value pairs, where the key is to be used for the select input's |
|
527 | - * name, and the value will be the text shown to the user. Optionally you can also |
|
528 | - * include an additional key of "class" which will add a specific class to the option |
|
529 | - * for that value. |
|
530 | - * @param string $default default value |
|
531 | - * @param string $parameters extra parameters |
|
532 | - * @param string $class css class |
|
533 | - * @param boolean $autosize whether to autosize the select or not |
|
534 | - * @return string html string for the select input |
|
535 | - */ |
|
536 | - public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
|
537 | - { |
|
538 | - // if $values was submitted in the wrong format, convert it over |
|
539 | - if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) { |
|
540 | - $converted_values = []; |
|
541 | - foreach ($values as $id => $text) { |
|
542 | - $converted_values[] = ['id' => $id, 'text' => $text]; |
|
543 | - } |
|
544 | - $values = $converted_values; |
|
545 | - } |
|
546 | - |
|
547 | - $field = |
|
548 | - '<select id="' . EEH_Formatter::ee_tep_output_string($name) |
|
549 | - . '" name="' . EEH_Formatter::ee_tep_output_string($name) |
|
550 | - . '"'; |
|
551 | - |
|
552 | - if (EEH_Formatter::ee_tep_not_null($parameters)) { |
|
553 | - $field .= ' ' . $parameters; |
|
554 | - } |
|
555 | - if ($autosize) { |
|
556 | - $size = 'med'; |
|
557 | - for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
|
558 | - if ($values[ $ii ]['text']) { |
|
559 | - if (strlen($values[ $ii ]['text']) > 5) { |
|
560 | - $size = 'wide'; |
|
561 | - } |
|
562 | - } |
|
563 | - } |
|
564 | - } else { |
|
565 | - $size = ''; |
|
566 | - } |
|
567 | - |
|
568 | - $field .= ' class="' . $class . ' ' . $size . '">'; |
|
569 | - |
|
570 | - if (empty($default) && isset($GLOBALS[ $name ])) { |
|
571 | - $default = stripslashes($GLOBALS[ $name ]); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
|
576 | - $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
577 | - if ($default == $values[ $i ]['id']) { |
|
578 | - $field .= ' selected = "selected"'; |
|
579 | - } |
|
580 | - if (isset($values[ $i ]['class'])) { |
|
581 | - $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
582 | - } |
|
583 | - $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
584 | - } |
|
585 | - $field .= '</select>'; |
|
586 | - |
|
587 | - return $field; |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * generate_question_groups_html |
|
593 | - * |
|
594 | - * @param array $question_groups |
|
595 | - * @param string $group_wrapper |
|
596 | - * @return string HTML |
|
597 | - * @throws EE_Error |
|
598 | - * @throws ReflectionException |
|
599 | - */ |
|
600 | - public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset') |
|
601 | - { |
|
602 | - |
|
603 | - $html = ''; |
|
604 | - $before_question_group_questions = |
|
605 | - apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
606 | - $after_question_group_questions = |
|
607 | - apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
608 | - |
|
609 | - if (! empty($question_groups)) { |
|
610 | - // loop thru question groups |
|
611 | - foreach ($question_groups as $QSG) { |
|
612 | - // check that questions exist |
|
613 | - if (! empty($QSG['QSG_questions'])) { |
|
614 | - // use fieldsets |
|
615 | - $html .= "\n\t" |
|
616 | - . '<' |
|
617 | - . $group_wrapper |
|
618 | - . ' class="espresso-question-group-wrap" id="' |
|
619 | - . $QSG['QSG_identifier'] |
|
620 | - . '">'; |
|
621 | - // group_name |
|
622 | - $html .= $QSG['QSG_show_group_name'] |
|
623 | - ? "\n\t\t" |
|
624 | - . '<h5 class="espresso-question-group-title-h5 section-title">' |
|
625 | - . self::prep_answer($QSG['QSG_name']) |
|
626 | - . '</h5>' |
|
627 | - : ''; |
|
628 | - // group_desc |
|
629 | - $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) |
|
630 | - ? '<div class="espresso-question-group-desc-pg">' |
|
631 | - . self::prep_answer($QSG['QSG_desc']) |
|
632 | - . '</div>' |
|
633 | - : ''; |
|
634 | - |
|
635 | - $html .= $before_question_group_questions; |
|
636 | - // loop thru questions |
|
637 | - foreach ($QSG['QSG_questions'] as $question) { |
|
638 | - $QFI = new EE_Question_Form_Input( |
|
639 | - $question['qst_obj'], |
|
640 | - $question['ans_obj'], |
|
641 | - $question |
|
642 | - ); |
|
643 | - $html .= self::generate_form_input($QFI); |
|
644 | - } |
|
645 | - $html .= $after_question_group_questions; |
|
646 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
647 | - } |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - return $html; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * generate_question_groups_html |
|
657 | - * |
|
658 | - * @param array $question_groups |
|
659 | - * @param array $q_meta |
|
660 | - * @param bool $from_admin |
|
661 | - * @param string $group_wrapper |
|
662 | - * @return string HTML |
|
663 | - * @throws EE_Error |
|
664 | - * @throws ReflectionException |
|
665 | - */ |
|
666 | - public static function generate_question_groups_html2( |
|
667 | - $question_groups = [], |
|
668 | - $q_meta = [], |
|
669 | - $from_admin = false, |
|
670 | - $group_wrapper = 'fieldset' |
|
671 | - ) { |
|
672 | - |
|
673 | - $html = ''; |
|
674 | - $before_question_group_questions = |
|
675 | - apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
676 | - $after_question_group_questions = |
|
677 | - apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
678 | - |
|
679 | - $default_q_meta = [ |
|
680 | - 'att_nmbr' => 1, |
|
681 | - 'ticket_id' => '', |
|
682 | - 'input_name' => '', |
|
683 | - 'input_id' => '', |
|
684 | - 'input_class' => '', |
|
685 | - ]; |
|
686 | - $q_meta = array_merge($default_q_meta, $q_meta); |
|
687 | - |
|
688 | - if (! empty($question_groups)) { |
|
689 | - // loop thru question groups |
|
690 | - foreach ($question_groups as $QSG) { |
|
691 | - if ($QSG instanceof EE_Question_Group) { |
|
692 | - // check that questions exist |
|
693 | - |
|
694 | - $where = ['QST_deleted' => 0]; |
|
695 | - if (! $from_admin) { |
|
696 | - $where['QST_admin_only'] = 0; |
|
697 | - } |
|
698 | - $questions = |
|
699 | - $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]); |
|
700 | - if (! empty($questions)) { |
|
701 | - // use fieldsets |
|
702 | - $html .= "\n\t" |
|
703 | - . '<' . $group_wrapper . ' class="espresso-question-group-wrap" ' |
|
704 | - . 'id="' . $QSG->get('QSG_identifier') . '">'; |
|
705 | - // group_name |
|
706 | - if ($QSG->show_group_name()) { |
|
707 | - $html .= "\n\t\t" |
|
708 | - . '<h5 class="espresso-question-group-title-h5 section-title">' |
|
709 | - . $QSG->get_pretty('QSG_name') |
|
710 | - . '</h5>'; |
|
711 | - } |
|
712 | - // group_desc |
|
713 | - if ($QSG->show_group_desc()) { |
|
714 | - $html .= '<div class="espresso-question-group-desc-pg">' |
|
715 | - . $QSG->get_pretty('QSG_desc') |
|
716 | - . '</div>'; |
|
717 | - } |
|
718 | - |
|
719 | - $html .= $before_question_group_questions; |
|
720 | - // loop thru questions |
|
721 | - foreach ($questions as $QST) { |
|
722 | - $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID(); |
|
723 | - |
|
724 | - $answer = null; |
|
725 | - |
|
726 | - /** @var RequestInterface $request */ |
|
727 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
728 | - $request_qstn = $request->getRequestParam('qstn', [], 'string', true); |
|
729 | - if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
730 | - // check for answer in $request_qstn in case we are reprocessing a form after an error |
|
731 | - if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) { |
|
732 | - $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]) |
|
733 | - ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ] |
|
734 | - : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]); |
|
735 | - } |
|
736 | - } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
|
737 | - // attendee data from the session |
|
738 | - $answer = |
|
739 | - isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - $QFI = new EE_Question_Form_Input( |
|
744 | - $QST, |
|
745 | - EE_Answer::new_instance( |
|
746 | - [ |
|
747 | - 'ANS_ID' => 0, |
|
748 | - 'QST_ID' => 0, |
|
749 | - 'REG_ID' => 0, |
|
750 | - 'ANS_value' => $answer, |
|
751 | - ] |
|
752 | - ), |
|
753 | - $q_meta |
|
754 | - ); |
|
755 | - $html .= self::generate_form_input($QFI); |
|
756 | - } |
|
757 | - $html .= $after_question_group_questions; |
|
758 | - $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
759 | - } |
|
760 | - } |
|
761 | - } |
|
762 | - } |
|
763 | - return $html; |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * generate_form_input |
|
769 | - * |
|
770 | - * @param EE_Question_Form_Input $QFI |
|
771 | - * @return string HTML |
|
772 | - * @throws EE_Error |
|
773 | - * @throws ReflectionException |
|
774 | - */ |
|
775 | - public static function generate_form_input(EE_Question_Form_Input $QFI) |
|
776 | - { |
|
777 | - if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) { |
|
778 | - return ''; |
|
779 | - } |
|
780 | - /** @var RequestInterface $request */ |
|
781 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
782 | - |
|
783 | - $QFI = self::_load_system_dropdowns($QFI); |
|
784 | - $QFI = self::_load_specialized_dropdowns($QFI); |
|
785 | - |
|
786 | - // we also need to verify |
|
787 | - |
|
788 | - $display_text = $QFI->get('QST_display_text'); |
|
789 | - $input_name = $QFI->get('QST_input_name'); |
|
790 | - $answer = $request->getRequestParam($input_name, $QFI->get('ANS_value')); |
|
791 | - $input_id = $QFI->get('QST_input_id'); |
|
792 | - $input_class = $QFI->get('QST_input_class'); |
|
793 | - // $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : ''; |
|
794 | - $disabled = $QFI->get('QST_disabled'); |
|
795 | - $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>'); |
|
796 | - $QST_required = $QFI->get('QST_required'); |
|
797 | - $required = |
|
798 | - $QST_required |
|
799 | - ? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required] |
|
800 | - : []; |
|
801 | - $use_html_entities = $QFI->get_meta('htmlentities'); |
|
802 | - $required_text = |
|
803 | - $QFI->get('QST_required_text') != '' |
|
804 | - ? $QFI->get('QST_required_text') |
|
805 | - : esc_html__('This field is required', 'event_espresso'); |
|
806 | - $required_text = $QST_required |
|
807 | - ? "\n\t\t\t" |
|
808 | - . '<div class="required-text hidden">' |
|
809 | - . self::prep_answer($required_text, $use_html_entities) |
|
810 | - . '</div>' |
|
811 | - : ''; |
|
812 | - $label_class = 'espresso-form-input-lbl'; |
|
813 | - $QST_options = $QFI->options(true, $answer); |
|
814 | - $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : []; |
|
815 | - $system_ID = $QFI->get('QST_system'); |
|
816 | - $label_b4 = $QFI->get_meta('label_b4'); |
|
817 | - $use_desc_4_label = $QFI->get_meta('use_desc_4_label'); |
|
818 | - |
|
819 | - |
|
820 | - switch ($QFI->get('QST_type')) { |
|
821 | - case 'TEXTAREA': |
|
822 | - return EEH_Form_Fields::textarea( |
|
823 | - $display_text, |
|
824 | - $answer, |
|
825 | - $input_name, |
|
826 | - $input_id, |
|
827 | - $input_class, |
|
828 | - [], |
|
829 | - $required, |
|
830 | - $required_text, |
|
831 | - $label_class, |
|
832 | - $disabled, |
|
833 | - $system_ID, |
|
834 | - $use_html_entities |
|
835 | - ); |
|
836 | - |
|
837 | - case 'DROPDOWN': |
|
838 | - return EEH_Form_Fields::select( |
|
839 | - $display_text, |
|
840 | - $answer, |
|
841 | - $options, |
|
842 | - $input_name, |
|
843 | - $input_id, |
|
844 | - $input_class, |
|
845 | - $required, |
|
846 | - $required_text, |
|
847 | - $label_class, |
|
848 | - $disabled, |
|
849 | - $system_ID, |
|
850 | - $use_html_entities, |
|
851 | - true |
|
852 | - ); |
|
853 | - |
|
854 | - |
|
855 | - case 'RADIO_BTN': |
|
856 | - return EEH_Form_Fields::radio( |
|
857 | - $display_text, |
|
858 | - $answer, |
|
859 | - $options, |
|
860 | - $input_name, |
|
861 | - $input_id, |
|
862 | - $input_class, |
|
863 | - $required, |
|
864 | - $required_text, |
|
865 | - $label_class, |
|
866 | - $disabled, |
|
867 | - $system_ID, |
|
868 | - $use_html_entities, |
|
869 | - $label_b4, |
|
870 | - $use_desc_4_label |
|
871 | - ); |
|
872 | - |
|
873 | - case 'CHECKBOX': |
|
874 | - return EEH_Form_Fields::checkbox( |
|
875 | - $display_text, |
|
876 | - $answer, |
|
877 | - $options, |
|
878 | - $input_name, |
|
879 | - $input_id, |
|
880 | - $input_class, |
|
881 | - $required, |
|
882 | - $required_text, |
|
883 | - $label_class, |
|
884 | - $disabled, |
|
885 | - $label_b4, |
|
886 | - $system_ID, |
|
887 | - $use_html_entities |
|
888 | - ); |
|
889 | - |
|
890 | - case 'DATE': |
|
891 | - return EEH_Form_Fields::datepicker( |
|
892 | - $display_text, |
|
893 | - $answer, |
|
894 | - $input_name, |
|
895 | - $input_id, |
|
896 | - $input_class, |
|
897 | - $required, |
|
898 | - $required_text, |
|
899 | - $label_class, |
|
900 | - $disabled, |
|
901 | - $system_ID, |
|
902 | - $use_html_entities |
|
903 | - ); |
|
904 | - |
|
905 | - case 'TEXT': |
|
906 | - default: |
|
907 | - return EEH_Form_Fields::text( |
|
908 | - $display_text, |
|
909 | - $answer, |
|
910 | - $input_name, |
|
911 | - $input_id, |
|
912 | - $input_class, |
|
913 | - $required, |
|
914 | - $required_text, |
|
915 | - $label_class, |
|
916 | - $disabled, |
|
917 | - $system_ID, |
|
918 | - $use_html_entities |
|
919 | - ); |
|
920 | - } |
|
921 | - } |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * generates HTML for a form text input |
|
926 | - * |
|
927 | - * @param string $question label content |
|
928 | - * @param string $answer form input value attribute |
|
929 | - * @param string $name form input name attribute |
|
930 | - * @param string $id form input css id attribute |
|
931 | - * @param string $class form input css class attribute |
|
932 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
933 | - * required 'class', and required 'msg' attribute |
|
934 | - * @param string $label_class css class attribute for the label |
|
935 | - * @param string $disabled disabled="disabled" or null |
|
936 | - * @return string HTML |
|
937 | - */ |
|
938 | - public static function text( |
|
939 | - $question = false, |
|
940 | - $answer = null, |
|
941 | - $name = false, |
|
942 | - $id = '', |
|
943 | - $class = '', |
|
944 | - $required = false, |
|
945 | - $required_text = '', |
|
946 | - $label_class = '', |
|
947 | - $disabled = false, |
|
948 | - $system_ID = false, |
|
949 | - $use_html_entities = true |
|
950 | - ) { |
|
951 | - // need these |
|
952 | - if (! $question || ! $name) { |
|
953 | - return null; |
|
954 | - } |
|
955 | - // prep the answer |
|
956 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
957 | - // prep the required array |
|
958 | - $required = self::prep_required($required); |
|
959 | - // set disabled tag |
|
960 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
961 | - // ya gots ta have style man!!! |
|
962 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
|
963 | - $class = empty($class) ? $txt_class : $class; |
|
964 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
965 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
966 | - |
|
967 | - $label_html = |
|
968 | - $required_text |
|
969 | - . "\n\t\t\t" |
|
970 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
971 | - . self::prep_question($question) |
|
972 | - . $required['label'] |
|
973 | - . '</label><br/>'; |
|
974 | - // filter label but ensure required text comes before it |
|
975 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
976 | - |
|
977 | - $input_html = |
|
978 | - "\n\t\t\t" |
|
979 | - . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
980 | - . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" ' |
|
981 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
982 | - |
|
983 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
984 | - return $label_html . $input_html; |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * generates HTML for a form textarea |
|
990 | - * |
|
991 | - * @param string $question label content |
|
992 | - * @param string $answer form input value attribute |
|
993 | - * @param string $name form input name attribute |
|
994 | - * @param string $id form input css id attribute |
|
995 | - * @param string $class form input css class attribute |
|
996 | - * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 ) |
|
997 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
998 | - * required 'class', and required 'msg' attribute |
|
999 | - * @param string $label_class css class attribute for the label |
|
1000 | - * @param string $disabled disabled="disabled" or null |
|
1001 | - * @return string HTML |
|
1002 | - */ |
|
1003 | - public static function textarea( |
|
1004 | - $question = false, |
|
1005 | - $answer = null, |
|
1006 | - $name = false, |
|
1007 | - $id = '', |
|
1008 | - $class = '', |
|
1009 | - $dimensions = false, |
|
1010 | - $required = false, |
|
1011 | - $required_text = '', |
|
1012 | - $label_class = '', |
|
1013 | - $disabled = false, |
|
1014 | - $system_ID = false, |
|
1015 | - $use_html_entities = true |
|
1016 | - ) { |
|
1017 | - // need these |
|
1018 | - if (! $question || ! $name) { |
|
1019 | - return null; |
|
1020 | - } |
|
1021 | - // prep the answer |
|
1022 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1023 | - // prep the required array |
|
1024 | - $required = self::prep_required($required); |
|
1025 | - // make sure $dimensions is an array |
|
1026 | - $dimensions = is_array($dimensions) ? $dimensions : []; |
|
1027 | - // and set some defaults |
|
1028 | - $dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions); |
|
1029 | - // set disabled tag |
|
1030 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1031 | - // ya gots ta have style man!!! |
|
1032 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
|
1033 | - $class = empty($class) ? $txt_class : $class; |
|
1034 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1035 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1036 | - |
|
1037 | - $label_html = |
|
1038 | - $required_text |
|
1039 | - . "\n\t\t\t" |
|
1040 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1041 | - . self::prep_question($question) |
|
1042 | - . $required['label'] |
|
1043 | - . '</label><br/>'; |
|
1044 | - // filter label but ensure required text comes before it |
|
1045 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1046 | - |
|
1047 | - $input_html = |
|
1048 | - "\n\t\t\t" |
|
1049 | - . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1050 | - . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" ' |
|
1051 | - . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' |
|
1052 | - . esc_textarea($answer) |
|
1053 | - . '</textarea>'; |
|
1054 | - |
|
1055 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1056 | - return $label_html . $input_html; |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * generates HTML for a form select input |
|
1062 | - * |
|
1063 | - * @param string $question label content |
|
1064 | - * @param string $answer form input value attribute |
|
1065 | - * @param array $options array of answer options where array key = option value and array value = option |
|
1066 | - * display text |
|
1067 | - * @param string $name form input name attribute |
|
1068 | - * @param string $id form input css id attribute |
|
1069 | - * @param string $class form input css class attribute |
|
1070 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1071 | - * required 'class', and required 'msg' attribute |
|
1072 | - * @param string $label_class css class attribute for the label |
|
1073 | - * @param string $disabled disabled="disabled" or null |
|
1074 | - * @return string HTML |
|
1075 | - */ |
|
1076 | - public static function select( |
|
1077 | - $question = false, |
|
1078 | - $answer = null, |
|
1079 | - $options = false, |
|
1080 | - $name = false, |
|
1081 | - $id = '', |
|
1082 | - $class = '', |
|
1083 | - $required = false, |
|
1084 | - $required_text = '', |
|
1085 | - $label_class = '', |
|
1086 | - $disabled = false, |
|
1087 | - $system_ID = false, |
|
1088 | - $use_html_entities = true, |
|
1089 | - $add_please_select_option = false |
|
1090 | - ) { |
|
1091 | - |
|
1092 | - // need these |
|
1093 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1094 | - return null; |
|
1095 | - } |
|
1096 | - // prep the answer |
|
1097 | - $answer = |
|
1098 | - is_array($answer) |
|
1099 | - ? self::prep_answer(array_shift($answer), $use_html_entities) |
|
1100 | - : self::prep_answer( |
|
1101 | - $answer, |
|
1102 | - $use_html_entities |
|
1103 | - ); |
|
1104 | - // prep the required array |
|
1105 | - $required = self::prep_required($required); |
|
1106 | - // set disabled tag |
|
1107 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1108 | - // ya gots ta have style man!!! |
|
1109 | - $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
|
1110 | - $class = empty($class) ? $txt_class : $class; |
|
1111 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1112 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1113 | - |
|
1114 | - $label_html = |
|
1115 | - $required_text |
|
1116 | - . "\n\t\t\t" |
|
1117 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1118 | - . self::prep_question($question) |
|
1119 | - . $required['label'] |
|
1120 | - . '</label><br/>'; |
|
1121 | - // filter label but ensure required text comes before it |
|
1122 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1123 | - |
|
1124 | - $input_html = |
|
1125 | - "\n\t\t\t" |
|
1126 | - . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1127 | - . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
1128 | - // recursively count array elements, to determine total number of options |
|
1129 | - $only_option = count($options, 1) == 1; |
|
1130 | - if (! $only_option) { |
|
1131 | - // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
|
1132 | - $selected = $answer === null ? ' selected="selected"' : ''; |
|
1133 | - $input_html .= $add_please_select_option |
|
1134 | - ? "\n\t\t\t\t" |
|
1135 | - . '<option value=""' . $selected . '>' |
|
1136 | - . esc_html__(' - please select - ', 'event_espresso') |
|
1137 | - . '</option>' |
|
1138 | - : ''; |
|
1139 | - } |
|
1140 | - foreach ($options as $key => $value) { |
|
1141 | - // if value is an array, then create option groups, else create regular ol' options |
|
1142 | - $input_html .= is_array($value) |
|
1143 | - ? self::_generate_select_option_group( |
|
1144 | - $key, |
|
1145 | - $value, |
|
1146 | - $answer, |
|
1147 | - $use_html_entities |
|
1148 | - ) |
|
1149 | - : self::_generate_select_option( |
|
1150 | - $value->value(), |
|
1151 | - $value->desc(), |
|
1152 | - $answer, |
|
1153 | - $only_option, |
|
1154 | - $use_html_entities |
|
1155 | - ); |
|
1156 | - } |
|
1157 | - |
|
1158 | - $input_html .= "\n\t\t\t" . '</select>'; |
|
1159 | - |
|
1160 | - $input_html = |
|
1161 | - apply_filters( |
|
1162 | - 'FHEE__EEH_Form_Fields__select__before_end_wrapper', |
|
1163 | - $input_html, |
|
1164 | - $question, |
|
1165 | - $answer, |
|
1166 | - $name, |
|
1167 | - $id, |
|
1168 | - $class, |
|
1169 | - $system_ID |
|
1170 | - ); |
|
1171 | - |
|
1172 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1173 | - return $label_html . $input_html; |
|
1174 | - } |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * _generate_select_option_group |
|
1179 | - * |
|
1180 | - * if $value for a select box is an array, then the key will be used as the optgroup label |
|
1181 | - * and the value array will be looped thru and the elements sent to _generate_select_option |
|
1182 | - * |
|
1183 | - * @param mixed $opt_group |
|
1184 | - * @param mixed $QSOs |
|
1185 | - * @param mixed $answer |
|
1186 | - * @param boolean $use_html_entities |
|
1187 | - * @return string |
|
1188 | - */ |
|
1189 | - private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
|
1190 | - { |
|
1191 | - $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
1192 | - foreach ($QSOs as $QSO) { |
|
1193 | - $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
|
1194 | - } |
|
1195 | - $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
1196 | - return $html; |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * _generate_select_option |
|
1202 | - * |
|
1203 | - * @param mixed $key |
|
1204 | - * @param mixed $value |
|
1205 | - * @param mixed $answer |
|
1206 | - * @param int $only_option |
|
1207 | - * @param boolean $use_html_entities |
|
1208 | - * @return string |
|
1209 | - */ |
|
1210 | - private static function _generate_select_option( |
|
1211 | - $key, |
|
1212 | - $value, |
|
1213 | - $answer, |
|
1214 | - $only_option = false, |
|
1215 | - $use_html_entities = true |
|
1216 | - ) { |
|
1217 | - $key = self::prep_answer($key, $use_html_entities); |
|
1218 | - $value = self::prep_answer($value, $use_html_entities); |
|
1219 | - $value = ! empty($value) ? $value : $key; |
|
1220 | - $selected = ($answer == $key || $only_option) ? 'selected="selected"' : ''; |
|
1221 | - return "\n\t\t\t\t" |
|
1222 | - . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> ' |
|
1223 | - . $value |
|
1224 | - . ' </option>'; |
|
1225 | - } |
|
1226 | - |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * generates HTML for form radio button inputs |
|
1230 | - * |
|
1231 | - * @param bool|string $question label content |
|
1232 | - * @param string $answer form input value attribute |
|
1233 | - * @param array|bool $options array of answer options where array key = option value and array value = option |
|
1234 | - * display text |
|
1235 | - * @param bool|string $name form input name attribute |
|
1236 | - * @param string $id form input css id attribute |
|
1237 | - * @param string $class form input css class attribute |
|
1238 | - * @param array|bool $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1239 | - * required 'class', and required 'msg' attribute |
|
1240 | - * @param string $required_text |
|
1241 | - * @param string $label_class css class attribute for the label |
|
1242 | - * @param bool|string $disabled disabled="disabled" or null |
|
1243 | - * @param bool $system_ID |
|
1244 | - * @param bool $use_html_entities |
|
1245 | - * @param bool $label_b4 |
|
1246 | - * @param bool $use_desc_4_label |
|
1247 | - * @return string HTML |
|
1248 | - */ |
|
1249 | - public static function radio( |
|
1250 | - $question = false, |
|
1251 | - $answer = null, |
|
1252 | - $options = false, |
|
1253 | - $name = false, |
|
1254 | - $id = '', |
|
1255 | - $class = '', |
|
1256 | - $required = false, |
|
1257 | - $required_text = '', |
|
1258 | - $label_class = '', |
|
1259 | - $disabled = false, |
|
1260 | - $system_ID = false, |
|
1261 | - $use_html_entities = true, |
|
1262 | - $label_b4 = false, |
|
1263 | - $use_desc_4_label = false |
|
1264 | - ) { |
|
1265 | - // need these |
|
1266 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1267 | - return null; |
|
1268 | - } |
|
1269 | - // prep the answer |
|
1270 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1271 | - // prep the required array |
|
1272 | - $required = self::prep_required($required); |
|
1273 | - // set disabled tag |
|
1274 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1275 | - // ya gots ta have style man!!! |
|
1276 | - $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
1277 | - $class = ! empty($class) ? $class : 'espresso-radio-btn-inp'; |
|
1278 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1279 | - |
|
1280 | - $label_html = |
|
1281 | - $required_text |
|
1282 | - . "\n\t\t\t" |
|
1283 | - . '<label class="' . $label_class . '">' |
|
1284 | - . self::prep_question($question) |
|
1285 | - . $required['label'] |
|
1286 | - . '</label> '; |
|
1287 | - // filter label but ensure required text comes before it |
|
1288 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1289 | - |
|
1290 | - $input_html = |
|
1291 | - "\n\t\t\t" |
|
1292 | - . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1293 | - |
|
1294 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1295 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1296 | - |
|
1297 | - foreach ($options as $OPT) { |
|
1298 | - if ($OPT instanceof EE_Question_Option) { |
|
1299 | - $value = self::prep_option_value($OPT->value()); |
|
1300 | - $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
|
1301 | - $size = $use_desc_4_label |
|
1302 | - ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) |
|
1303 | - : self::get_label_size_class($OPT->value()); |
|
1304 | - $desc = $OPT->desc();// no self::prep_answer |
|
1305 | - $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
|
1306 | - $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
|
1307 | - $opt = '-' . sanitize_key($value); |
|
1308 | - |
|
1309 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1310 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
1311 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
1312 | - $input_html .= "\n\t\t\t\t\t\t" |
|
1313 | - . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" ' |
|
1314 | - . 'class="' . $class . '" value="' . $value . '" ' |
|
1315 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled |
|
1316 | - . $checked . ' ' . $extra . '/>'; |
|
1317 | - $input_html .= ! $label_b4 |
|
1318 | - ? "\n\t\t\t\t\t\t" |
|
1319 | - . '<span class="espresso-radio-btn-desc">' |
|
1320 | - . $label |
|
1321 | - . '</span>' |
|
1322 | - : ''; |
|
1323 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1324 | - $input_html .= $use_desc_4_label |
|
1325 | - ? '' |
|
1326 | - : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
1327 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1328 | - } |
|
1329 | - } |
|
1330 | - |
|
1331 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
1332 | - |
|
1333 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1334 | - return $label_html . $input_html; |
|
1335 | - } |
|
1336 | - |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * generates HTML for form checkbox inputs |
|
1340 | - * |
|
1341 | - * @param string $question label content |
|
1342 | - * @param string $answer form input value attribute |
|
1343 | - * @param array $options array of options where array key = option value and array value = option display text |
|
1344 | - * @param string $name form input name attribute |
|
1345 | - * @param string $id form input css id attribute |
|
1346 | - * @param string $class form input css class attribute |
|
1347 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1348 | - * required 'class', and required 'msg' attribute |
|
1349 | - * @param string $label_class css class attribute for the label |
|
1350 | - * @param string $disabled disabled="disabled" or null |
|
1351 | - * @return string HTML |
|
1352 | - */ |
|
1353 | - public static function checkbox( |
|
1354 | - $question = false, |
|
1355 | - $answer = null, |
|
1356 | - $options = false, |
|
1357 | - $name = false, |
|
1358 | - $id = '', |
|
1359 | - $class = '', |
|
1360 | - $required = false, |
|
1361 | - $required_text = '', |
|
1362 | - $label_class = '', |
|
1363 | - $disabled = false, |
|
1364 | - $label_b4 = false, |
|
1365 | - $system_ID = false, |
|
1366 | - $use_html_entities = true |
|
1367 | - ) { |
|
1368 | - // need these |
|
1369 | - if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1370 | - return null; |
|
1371 | - } |
|
1372 | - $answer = maybe_unserialize($answer); |
|
1373 | - |
|
1374 | - // prep the answer(s) |
|
1375 | - $answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer]; |
|
1376 | - |
|
1377 | - foreach ($answer as $key => $value) { |
|
1378 | - $key = self::prep_option_value($key); |
|
1379 | - $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
1380 | - } |
|
1381 | - |
|
1382 | - // prep the required array |
|
1383 | - $required = self::prep_required($required); |
|
1384 | - // set disabled tag |
|
1385 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1386 | - // ya gots ta have style man!!! |
|
1387 | - $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
1388 | - $class = empty($class) ? 'espresso-radio-btn-inp' : $class; |
|
1389 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1390 | - |
|
1391 | - $label_html = |
|
1392 | - $required_text |
|
1393 | - . "\n\t\t\t" |
|
1394 | - . '<label class="' . $label_class . '">' |
|
1395 | - . self::prep_question($question) |
|
1396 | - . $required['label'] |
|
1397 | - . '</label> '; |
|
1398 | - // filter label but ensure required text comes before it |
|
1399 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1400 | - |
|
1401 | - $input_html = |
|
1402 | - "\n\t\t\t" |
|
1403 | - . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1404 | - |
|
1405 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1406 | - $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1407 | - |
|
1408 | - foreach ($options as $OPT) { |
|
1409 | - $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
1410 | - $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
1411 | - $text = self::prep_answer($OPT->value()); |
|
1412 | - $desc = $OPT->desc(); |
|
1413 | - $opt = '-' . sanitize_key($value); |
|
1414 | - |
|
1415 | - $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
|
1416 | - |
|
1417 | - $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1418 | - $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
1419 | - $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1420 | - $input_html .= "\n\t\t\t\t\t\t" |
|
1421 | - . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" ' |
|
1422 | - . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" ' |
|
1423 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
1424 | - $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1425 | - $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1426 | - if (! empty($desc) && $desc != $text) { |
|
1427 | - $input_html .= "\n\t\t\t\t\t" |
|
1428 | - . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' |
|
1429 | - . $desc |
|
1430 | - . '</div>'; |
|
1431 | - } |
|
1432 | - $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1433 | - } |
|
1434 | - |
|
1435 | - $input_html .= "\n\t\t\t" . '</ul>'; |
|
1436 | - |
|
1437 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1438 | - return $label_html . $input_html; |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * generates HTML for a form datepicker input |
|
1444 | - * |
|
1445 | - * @param string $question label content |
|
1446 | - * @param string $answer form input value attribute |
|
1447 | - * @param string $name form input name attribute |
|
1448 | - * @param string $id form input css id attribute |
|
1449 | - * @param string $class form input css class attribute |
|
1450 | - * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1451 | - * required 'class', and required 'msg' attribute |
|
1452 | - * @param string $label_class css class attribute for the label |
|
1453 | - * @param string $disabled disabled="disabled" or null |
|
1454 | - * @return string HTML |
|
1455 | - */ |
|
1456 | - public static function datepicker( |
|
1457 | - $question = false, |
|
1458 | - $answer = null, |
|
1459 | - $name = false, |
|
1460 | - $id = '', |
|
1461 | - $class = '', |
|
1462 | - $required = false, |
|
1463 | - $required_text = '', |
|
1464 | - $label_class = '', |
|
1465 | - $disabled = false, |
|
1466 | - $system_ID = false, |
|
1467 | - $use_html_entities = true |
|
1468 | - ) { |
|
1469 | - // need these |
|
1470 | - if (! $question || ! $name) { |
|
1471 | - return null; |
|
1472 | - } |
|
1473 | - // prep the answer |
|
1474 | - $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1475 | - // prep the required array |
|
1476 | - $required = self::prep_required($required); |
|
1477 | - // set disabled tag |
|
1478 | - $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1479 | - // ya gots ta have style man!!! |
|
1480 | - $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
|
1481 | - $class = empty($class) ? $txt_class : $class; |
|
1482 | - $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1483 | - $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1484 | - |
|
1485 | - $label_html = |
|
1486 | - $required_text |
|
1487 | - . "\n\t\t\t" |
|
1488 | - . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1489 | - . self::prep_question($question) |
|
1490 | - . $required['label'] |
|
1491 | - . '</label><br/>'; |
|
1492 | - // filter label but ensure required text comes before it |
|
1493 | - $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1494 | - |
|
1495 | - $input_html = |
|
1496 | - "\n\t\t\t" |
|
1497 | - . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
1498 | - . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" ' |
|
1499 | - . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1500 | - |
|
1501 | - // enqueue scripts |
|
1502 | - wp_register_style( |
|
1503 | - 'espresso-ui-theme', |
|
1504 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1505 | - [], |
|
1506 | - EVENT_ESPRESSO_VERSION |
|
1507 | - ); |
|
1508 | - wp_enqueue_style('espresso-ui-theme'); |
|
1509 | - wp_enqueue_script('jquery-ui-datepicker'); |
|
1510 | - |
|
1511 | - $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1512 | - return $label_html . $input_html; |
|
1513 | - } |
|
1514 | - |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * remove_label_keep_required_msg |
|
1518 | - * this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label |
|
1519 | - * |
|
1520 | - * @access public |
|
1521 | - * @return string |
|
1522 | - */ |
|
1523 | - public static function remove_label_keep_required_msg($label_html, $required_text) |
|
1524 | - { |
|
1525 | - return $required_text; |
|
1526 | - } |
|
1527 | - |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Simply returns the HTML for a hidden input of the given name and value. |
|
1531 | - * |
|
1532 | - * @param string $name |
|
1533 | - * @param string $value |
|
1534 | - * @return string HTML |
|
1535 | - */ |
|
1536 | - public static function hidden_input($name, $value, $id = '') |
|
1537 | - { |
|
1538 | - $id = ! empty($id) ? $id : $name; |
|
1539 | - return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1540 | - } |
|
1541 | - |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * prep_question |
|
1545 | - * |
|
1546 | - * @param string $question |
|
1547 | - * @return string |
|
1548 | - */ |
|
1549 | - public static function prep_question($question) |
|
1550 | - { |
|
1551 | - return $question; |
|
1552 | - } |
|
1553 | - |
|
1554 | - |
|
1555 | - /** |
|
1556 | - * prep_answer |
|
1557 | - * |
|
1558 | - * @param mixed $answer |
|
1559 | - * @return string |
|
1560 | - */ |
|
1561 | - public static function prep_answer($answer, $use_html_entities = true) |
|
1562 | - { |
|
1563 | - // make sure we convert bools first. Otherwise (bool) false becomes an empty string which is NOT desired, |
|
1564 | - // we want "0". |
|
1565 | - if (is_bool($answer)) { |
|
1566 | - $answer = $answer ? 1 : 0; |
|
1567 | - } |
|
1568 | - $answer = trim(stripslashes(str_replace(''', "'", $answer))); |
|
1569 | - return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer; |
|
1570 | - } |
|
1571 | - |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * prep_answer_options |
|
1575 | - * |
|
1576 | - * @param array $QSOs array of EE_Question_Option objects |
|
1577 | - * @return array |
|
1578 | - */ |
|
1579 | - public static function prep_answer_options($QSOs = []) |
|
1580 | - { |
|
1581 | - $prepped_answer_options = []; |
|
1582 | - if (is_array($QSOs) && ! empty($QSOs)) { |
|
1583 | - foreach ($QSOs as $key => $QSO) { |
|
1584 | - if (! $QSO instanceof EE_Question_Option) { |
|
1585 | - $QSO = EE_Question_Option::new_instance( |
|
1586 | - [ |
|
1587 | - 'QSO_value' => is_array($QSO) && isset($QSO['id']) |
|
1588 | - ? (string) $QSO['id'] |
|
1589 | - : (string) $key, |
|
1590 | - 'QSO_desc' => is_array($QSO) && isset($QSO['text']) |
|
1591 | - ? (string) $QSO['text'] |
|
1592 | - : (string) $QSO, |
|
1593 | - ] |
|
1594 | - ); |
|
1595 | - } |
|
1596 | - if ($QSO->opt_group()) { |
|
1597 | - $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1598 | - } else { |
|
1599 | - $prepped_answer_options[] = $QSO; |
|
1600 | - } |
|
1601 | - } |
|
1602 | - } |
|
1603 | - // d( $prepped_answer_options ); |
|
1604 | - return $prepped_answer_options; |
|
1605 | - } |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * prep_option_value |
|
1610 | - * |
|
1611 | - * @param string $option_value |
|
1612 | - * @return string |
|
1613 | - */ |
|
1614 | - public static function prep_option_value($option_value) |
|
1615 | - { |
|
1616 | - return esc_attr(trim(stripslashes($option_value))); |
|
1617 | - } |
|
1618 | - |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * prep_required |
|
1622 | - * |
|
1623 | - * @param string|array $required |
|
1624 | - * @return array |
|
1625 | - */ |
|
1626 | - public static function prep_required($required = []) |
|
1627 | - { |
|
1628 | - // make sure required is an array |
|
1629 | - $required = is_array($required) ? $required : []; |
|
1630 | - // and set some defaults |
|
1631 | - return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required); |
|
1632 | - } |
|
1633 | - |
|
1634 | - |
|
1635 | - /** |
|
1636 | - * get_label_size_class |
|
1637 | - * |
|
1638 | - * @param string $value |
|
1639 | - * @return string |
|
1640 | - */ |
|
1641 | - public static function get_label_size_class($value = false) |
|
1642 | - { |
|
1643 | - if ($value === false || $value === '') { |
|
1644 | - return ' class="medium-lbl"'; |
|
1645 | - } |
|
1646 | - // determine length of option value |
|
1647 | - $val_size = strlen($value); |
|
1648 | - switch ($val_size) { |
|
1649 | - case $val_size < 3: |
|
1650 | - $size = ' class="nano-lbl"'; |
|
1651 | - break; |
|
1652 | - case $val_size < 6: |
|
1653 | - $size = ' class="micro-lbl"'; |
|
1654 | - break; |
|
1655 | - case $val_size < 12: |
|
1656 | - $size = ' class="tiny-lbl"'; |
|
1657 | - break; |
|
1658 | - case $val_size < 25: |
|
1659 | - $size = ' class="small-lbl"'; |
|
1660 | - break; |
|
1661 | - case $val_size > 100: |
|
1662 | - $size = ' class="big-lbl"'; |
|
1663 | - break; |
|
1664 | - default: |
|
1665 | - $size = ' class="medium-lbl"'; |
|
1666 | - break; |
|
1667 | - } |
|
1668 | - return $size; |
|
1669 | - } |
|
1670 | - |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * _load_system_dropdowns |
|
1674 | - * |
|
1675 | - * @param EE_Question_Form_Input $QFI |
|
1676 | - * @return array |
|
1677 | - * @throws EE_Error |
|
1678 | - * @throws ReflectionException |
|
1679 | - */ |
|
1680 | - private static function _load_system_dropdowns($QFI) |
|
1681 | - { |
|
1682 | - $QST_system = $QFI->get('QST_system'); |
|
1683 | - switch ($QST_system) { |
|
1684 | - case 'state': |
|
1685 | - $QFI = self::generate_state_dropdown($QFI); |
|
1686 | - break; |
|
1687 | - case 'country': |
|
1688 | - $QFI = self::generate_country_dropdown($QFI); |
|
1689 | - break; |
|
1690 | - case 'admin-state': |
|
1691 | - $QFI = self::generate_state_dropdown($QFI, true); |
|
1692 | - break; |
|
1693 | - case 'admin-country': |
|
1694 | - $QFI = self::generate_country_dropdown($QFI, true); |
|
1695 | - break; |
|
1696 | - } |
|
1697 | - return $QFI; |
|
1698 | - } |
|
1699 | - |
|
1700 | - |
|
1701 | - /** |
|
1702 | - * This preps dropdowns that are specialized. |
|
1703 | - * |
|
1704 | - * @param EE_Question_Form_Input $QFI |
|
1705 | - * |
|
1706 | - * @return EE_Question_Form_Input |
|
1707 | - * @throws EE_Error |
|
1708 | - * @throws ReflectionException |
|
1709 | - * @since 4.6.0 |
|
1710 | - */ |
|
1711 | - protected static function _load_specialized_dropdowns($QFI) |
|
1712 | - { |
|
1713 | - switch ($QFI->get('QST_type')) { |
|
1714 | - case 'STATE': |
|
1715 | - $QFI = self::generate_state_dropdown($QFI); |
|
1716 | - break; |
|
1717 | - case 'COUNTRY': |
|
1718 | - $QFI = self::generate_country_dropdown($QFI); |
|
1719 | - break; |
|
1720 | - } |
|
1721 | - return $QFI; |
|
1722 | - } |
|
1723 | - |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * generate_state_dropdown |
|
1727 | - * |
|
1728 | - * @param EE_Question_Form_Input $QST |
|
1729 | - * @param bool $get_all |
|
1730 | - * @return EE_Question_Form_Input |
|
1731 | - * @throws EE_Error |
|
1732 | - * @throws ReflectionException |
|
1733 | - */ |
|
1734 | - public static function generate_state_dropdown($QST, $get_all = false) |
|
1735 | - { |
|
1736 | - $states = $get_all |
|
1737 | - ? EEM_State::instance()->get_all_states() |
|
1738 | - : EEM_State::instance()->get_all_states_of_active_countries(); |
|
1739 | - if ($states && count($states) != count($QST->options())) { |
|
1740 | - $QST->set('QST_type', 'DROPDOWN'); |
|
1741 | - // if multiple countries, we'll create option groups within the dropdown |
|
1742 | - foreach ($states as $state) { |
|
1743 | - if ($state instanceof EE_State) { |
|
1744 | - $QSO = EE_Question_Option::new_instance( |
|
1745 | - [ |
|
1746 | - 'QSO_value' => $state->ID(), |
|
1747 | - 'QSO_desc' => $state->name(), |
|
1748 | - 'QST_ID' => $QST->get('QST_ID'), |
|
1749 | - 'QSO_deleted' => false, |
|
1750 | - ] |
|
1751 | - ); |
|
1752 | - // set option group |
|
1753 | - $QSO->set_opt_group($state->country()->name()); |
|
1754 | - // add option to question |
|
1755 | - $QST->add_temp_option($QSO); |
|
1756 | - } |
|
1757 | - } |
|
1758 | - } |
|
1759 | - return $QST; |
|
1760 | - } |
|
1761 | - |
|
1762 | - |
|
1763 | - /** |
|
1764 | - * generate_country_dropdown |
|
1765 | - * |
|
1766 | - * @param $QST |
|
1767 | - * @param bool $get_all |
|
1768 | - * @return array |
|
1769 | - * @throws EE_Error |
|
1770 | - * @throws ReflectionException |
|
1771 | - * @internal param array $question |
|
1772 | - */ |
|
1773 | - public static function generate_country_dropdown($QST, $get_all = false) |
|
1774 | - { |
|
1775 | - $countries = $get_all |
|
1776 | - ? EEM_Country::instance()->get_all_countries() |
|
1777 | - : EEM_Country::instance()->get_all_active_countries(); |
|
1778 | - if ($countries && count($countries) != count($QST->options())) { |
|
1779 | - $QST->set('QST_type', 'DROPDOWN'); |
|
1780 | - // now add countries |
|
1781 | - foreach ($countries as $country) { |
|
1782 | - if ($country instanceof EE_Country) { |
|
1783 | - $QSO = EE_Question_Option::new_instance( |
|
1784 | - [ |
|
1785 | - 'QSO_value' => $country->ID(), |
|
1786 | - 'QSO_desc' => $country->name(), |
|
1787 | - 'QST_ID' => $QST->get('QST_ID'), |
|
1788 | - 'QSO_deleted' => false, |
|
1789 | - ] |
|
1790 | - ); |
|
1791 | - $QST->add_temp_option($QSO); |
|
1792 | - } |
|
1793 | - } |
|
1794 | - } |
|
1795 | - return $QST; |
|
1796 | - } |
|
1797 | - |
|
1798 | - |
|
1799 | - /** |
|
1800 | - * generates options for a month dropdown selector with numbers from 01 to 12 |
|
1801 | - * |
|
1802 | - * @return array() |
|
1803 | - */ |
|
1804 | - public static function two_digit_months_dropdown_options() |
|
1805 | - { |
|
1806 | - $options = []; |
|
1807 | - for ($x = 1; $x <= 12; $x++) { |
|
1808 | - $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1809 | - $options[ $mm ] = $mm; |
|
1810 | - } |
|
1811 | - return EEH_Form_Fields::prep_answer_options($options); |
|
1812 | - } |
|
1813 | - |
|
1814 | - |
|
1815 | - /** |
|
1816 | - * generates a year dropdown selector with numbers for the next ten years |
|
1817 | - * |
|
1818 | - * @return array |
|
1819 | - */ |
|
1820 | - public static function next_decade_two_digit_year_dropdown_options() |
|
1821 | - { |
|
1822 | - $options = []; |
|
1823 | - $current_year = date('y'); |
|
1824 | - $next_decade = $current_year + 10; |
|
1825 | - for ($x = $current_year; $x <= $next_decade; $x++) { |
|
1826 | - $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1827 | - $options[ $yy ] = $yy; |
|
1828 | - } |
|
1829 | - return EEH_Form_Fields::prep_answer_options($options); |
|
1830 | - } |
|
1831 | - |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * generates a month/year dropdown selector for all registrations matching the given criteria. Typically used for |
|
1835 | - * list table filter. |
|
1836 | - * |
|
1837 | - * @param string $cur_date any currently selected date can be entered here. |
|
1838 | - * @param string $status Registration status |
|
1839 | - * @param integer $evt_category Event Category ID if the Event Category filter is selected |
|
1840 | - * @return string html |
|
1841 | - * @throws EE_Error |
|
1842 | - */ |
|
1843 | - public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
|
1844 | - { |
|
1845 | - $_where = []; |
|
1846 | - if (! empty($status)) { |
|
1847 | - $_where['STS_ID'] = $status; |
|
1848 | - } |
|
1849 | - |
|
1850 | - if ($evt_category > 0) { |
|
1851 | - $_where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1852 | - } |
|
1853 | - |
|
1854 | - $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where); |
|
1855 | - |
|
1856 | - // setup vals for select input helper |
|
1857 | - $options = [ |
|
1858 | - 0 => [ |
|
1859 | - 'text' => esc_html__('Select a Month/Year', 'event_espresso'), |
|
1860 | - 'id' => '', |
|
1861 | - ], |
|
1862 | - ]; |
|
1863 | - |
|
1864 | - foreach ($regdtts as $regdtt) { |
|
1865 | - $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1866 | - $options[] = [ |
|
1867 | - 'text' => $date, |
|
1868 | - 'id' => $date, |
|
1869 | - ]; |
|
1870 | - } |
|
1871 | - |
|
1872 | - return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1873 | - } |
|
1874 | - |
|
1875 | - |
|
1876 | - /** |
|
1877 | - * generates a month/year dropdown selector for all events matching the given criteria |
|
1878 | - * Typically used for list table filter |
|
1879 | - * |
|
1880 | - * @param string $cur_date any currently selected date can be entered here. |
|
1881 | - * @param string $status "view" (i.e. all, today, month, draft) |
|
1882 | - * @param int $evt_category category event belongs to |
|
1883 | - * @param string $evt_active_status "upcoming", "expired", "active", or "inactive" |
|
1884 | - * @return string html |
|
1885 | - * @throws EE_Error |
|
1886 | - */ |
|
1887 | - public static function generate_event_months_dropdown( |
|
1888 | - $cur_date = '', |
|
1889 | - $status = null, |
|
1890 | - $evt_category = null, |
|
1891 | - $evt_active_status = null |
|
1892 | - ) { |
|
1893 | - // determine what post_status our condition will have for the query. |
|
1894 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
1895 | - switch ($status) { |
|
1896 | - case 'month': |
|
1897 | - case 'today': |
|
1898 | - case null: |
|
1899 | - case 'all': |
|
1900 | - $where['Event.status'] = ['NOT IN', ['trash']]; |
|
1901 | - break; |
|
1902 | - case 'draft': |
|
1903 | - $where['Event.status'] = ['IN', ['draft', 'auto-draft']]; |
|
1904 | - break; |
|
1905 | - default: |
|
1906 | - $where['Event.status'] = $status; |
|
1907 | - } |
|
1908 | - |
|
1909 | - // phpcs:enable |
|
1910 | - |
|
1911 | - // categories? |
|
1912 | - |
|
1913 | - |
|
1914 | - if (! empty($evt_category)) { |
|
1915 | - $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1916 | - $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1917 | - } |
|
1918 | - |
|
1919 | - |
|
1920 | - // $where['DTT_is_primary'] = 1; |
|
1921 | - |
|
1922 | - $DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status); |
|
1923 | - |
|
1924 | - // let's setup vals for select input helper |
|
1925 | - $options = [ |
|
1926 | - 0 => [ |
|
1927 | - 'text' => esc_html__('Select a Month/Year', 'event_espresso'), |
|
1928 | - 'id' => "", |
|
1929 | - ], |
|
1930 | - ]; |
|
1931 | - |
|
1932 | - |
|
1933 | - // translate month and date |
|
1934 | - global $wp_locale; |
|
1935 | - |
|
1936 | - foreach ($DTTS as $DTT) { |
|
1937 | - $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1938 | - $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1939 | - $options[] = [ |
|
1940 | - 'text' => $localized_date, |
|
1941 | - 'id' => $id, |
|
1942 | - ]; |
|
1943 | - } |
|
1944 | - |
|
1945 | - |
|
1946 | - return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1947 | - } |
|
1948 | - |
|
1949 | - |
|
1950 | - /** |
|
1951 | - * generates the dropdown selector for event categories |
|
1952 | - * typically used as a filter on list tables. |
|
1953 | - * |
|
1954 | - * @param integer $current_cat currently selected category |
|
1955 | - * @return string html for dropdown |
|
1956 | - * @throws EE_Error |
|
1957 | - * @throws ReflectionException |
|
1958 | - */ |
|
1959 | - public static function generate_event_category_dropdown($current_cat = -1) |
|
1960 | - { |
|
1961 | - $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
1962 | - $options = [ |
|
1963 | - '0' => [ |
|
1964 | - 'text' => esc_html__('All Categories', 'event_espresso'), |
|
1965 | - 'id' => -1, |
|
1966 | - ], |
|
1967 | - ]; |
|
1968 | - |
|
1969 | - // setup categories for dropdown |
|
1970 | - foreach ($categories as $category) { |
|
1971 | - $options[] = [ |
|
1972 | - 'text' => $category->get('name'), |
|
1973 | - 'id' => $category->ID(), |
|
1974 | - ]; |
|
1975 | - } |
|
1976 | - |
|
1977 | - return self::select_input('EVT_CAT', $options, $current_cat); |
|
1978 | - } |
|
1979 | - |
|
1980 | - |
|
1981 | - /** |
|
1982 | - * generate a submit button with or without it's own microform |
|
1983 | - * this is the only way to create buttons that are compatible across all themes |
|
1984 | - * |
|
1985 | - * @access public |
|
1986 | - * @param string $url - the form action |
|
1987 | - * @param string $ID - some kind of unique ID, appended with "-sbmt" for the input and "-frm" |
|
1988 | - * for the form |
|
1989 | - * @param string $class - css classes (separated by spaces if more than one) |
|
1990 | - * @param string $text - what appears on the button |
|
1991 | - * @param string $nonce_action - if using nonces |
|
1992 | - * @param bool|string $input_only - whether to print form header and footer. TRUE returns the input without |
|
1993 | - * the form |
|
1994 | - * @param string $extra_attributes - any extra attributes that need to be attached to the form input |
|
1995 | - * @return string |
|
1996 | - */ |
|
1997 | - public static function submit_button( |
|
1998 | - $url = '', |
|
1999 | - $ID = '', |
|
2000 | - $class = '', |
|
2001 | - $text = '', |
|
2002 | - $nonce_action = '', |
|
2003 | - $input_only = false, |
|
2004 | - $extra_attributes = '' |
|
2005 | - ) { |
|
2006 | - $btn = ''; |
|
2007 | - if (empty($url) || empty($ID)) { |
|
2008 | - return $btn; |
|
2009 | - } |
|
2010 | - $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso'); |
|
2011 | - $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" ' |
|
2012 | - . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
2013 | - if (! $input_only) { |
|
2014 | - $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
2015 | - $btn_frm .= ! empty($nonce_action) |
|
2016 | - ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) |
|
2017 | - : ''; |
|
2018 | - $btn_frm .= $btn; |
|
2019 | - $btn_frm .= '</form>'; |
|
2020 | - $btn = $btn_frm; |
|
2021 | - unset($btn_frm); |
|
2022 | - } |
|
2023 | - return $btn; |
|
2024 | - } |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * @param string $class |
|
493 | + * @param string $id |
|
494 | + * @param string $name |
|
495 | + * @param int $rows |
|
496 | + * @param int $tab_index |
|
497 | + * @param string $value |
|
498 | + * @param array $wp_editor_args |
|
499 | + * @return false|string |
|
500 | + * @since 4.10.14.p |
|
501 | + */ |
|
502 | + private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = []) |
|
503 | + { |
|
504 | + $editor_settings = $wp_editor_args + [ |
|
505 | + 'textarea_name' => esc_attr($name), |
|
506 | + 'textarea_rows' => absint($rows), |
|
507 | + 'editor_class' => esc_attr($class), |
|
508 | + 'tabindex' => absint($tab_index), |
|
509 | + ]; |
|
510 | + ob_start(); |
|
511 | + wp_editor($value, esc_attr($id), $editor_settings); |
|
512 | + return ob_get_clean(); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * espresso admin page select_input |
|
518 | + * Turns an array into a select fields |
|
519 | + * |
|
520 | + * @static |
|
521 | + * @access public |
|
522 | + * @param string $name field name |
|
523 | + * @param array $values option values, numbered array starting at 0, where each value is an array with a key |
|
524 | + * 'text' (meaning text to display' and 'id' (meaning the internal value) eg: |
|
525 | + * array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or |
|
526 | + * as an array of key-value pairs, where the key is to be used for the select input's |
|
527 | + * name, and the value will be the text shown to the user. Optionally you can also |
|
528 | + * include an additional key of "class" which will add a specific class to the option |
|
529 | + * for that value. |
|
530 | + * @param string $default default value |
|
531 | + * @param string $parameters extra parameters |
|
532 | + * @param string $class css class |
|
533 | + * @param boolean $autosize whether to autosize the select or not |
|
534 | + * @return string html string for the select input |
|
535 | + */ |
|
536 | + public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true) |
|
537 | + { |
|
538 | + // if $values was submitted in the wrong format, convert it over |
|
539 | + if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) { |
|
540 | + $converted_values = []; |
|
541 | + foreach ($values as $id => $text) { |
|
542 | + $converted_values[] = ['id' => $id, 'text' => $text]; |
|
543 | + } |
|
544 | + $values = $converted_values; |
|
545 | + } |
|
546 | + |
|
547 | + $field = |
|
548 | + '<select id="' . EEH_Formatter::ee_tep_output_string($name) |
|
549 | + . '" name="' . EEH_Formatter::ee_tep_output_string($name) |
|
550 | + . '"'; |
|
551 | + |
|
552 | + if (EEH_Formatter::ee_tep_not_null($parameters)) { |
|
553 | + $field .= ' ' . $parameters; |
|
554 | + } |
|
555 | + if ($autosize) { |
|
556 | + $size = 'med'; |
|
557 | + for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) { |
|
558 | + if ($values[ $ii ]['text']) { |
|
559 | + if (strlen($values[ $ii ]['text']) > 5) { |
|
560 | + $size = 'wide'; |
|
561 | + } |
|
562 | + } |
|
563 | + } |
|
564 | + } else { |
|
565 | + $size = ''; |
|
566 | + } |
|
567 | + |
|
568 | + $field .= ' class="' . $class . ' ' . $size . '">'; |
|
569 | + |
|
570 | + if (empty($default) && isset($GLOBALS[ $name ])) { |
|
571 | + $default = stripslashes($GLOBALS[ $name ]); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + for ($i = 0, $n = sizeof($values); $i < $n; $i++) { |
|
576 | + $field .= '<option value="' . $values[ $i ]['id'] . '"'; |
|
577 | + if ($default == $values[ $i ]['id']) { |
|
578 | + $field .= ' selected = "selected"'; |
|
579 | + } |
|
580 | + if (isset($values[ $i ]['class'])) { |
|
581 | + $field .= ' class="' . $values[ $i ]['class'] . '"'; |
|
582 | + } |
|
583 | + $field .= '>' . $values[ $i ]['text'] . '</option>'; |
|
584 | + } |
|
585 | + $field .= '</select>'; |
|
586 | + |
|
587 | + return $field; |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * generate_question_groups_html |
|
593 | + * |
|
594 | + * @param array $question_groups |
|
595 | + * @param string $group_wrapper |
|
596 | + * @return string HTML |
|
597 | + * @throws EE_Error |
|
598 | + * @throws ReflectionException |
|
599 | + */ |
|
600 | + public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset') |
|
601 | + { |
|
602 | + |
|
603 | + $html = ''; |
|
604 | + $before_question_group_questions = |
|
605 | + apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
606 | + $after_question_group_questions = |
|
607 | + apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
608 | + |
|
609 | + if (! empty($question_groups)) { |
|
610 | + // loop thru question groups |
|
611 | + foreach ($question_groups as $QSG) { |
|
612 | + // check that questions exist |
|
613 | + if (! empty($QSG['QSG_questions'])) { |
|
614 | + // use fieldsets |
|
615 | + $html .= "\n\t" |
|
616 | + . '<' |
|
617 | + . $group_wrapper |
|
618 | + . ' class="espresso-question-group-wrap" id="' |
|
619 | + . $QSG['QSG_identifier'] |
|
620 | + . '">'; |
|
621 | + // group_name |
|
622 | + $html .= $QSG['QSG_show_group_name'] |
|
623 | + ? "\n\t\t" |
|
624 | + . '<h5 class="espresso-question-group-title-h5 section-title">' |
|
625 | + . self::prep_answer($QSG['QSG_name']) |
|
626 | + . '</h5>' |
|
627 | + : ''; |
|
628 | + // group_desc |
|
629 | + $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc']) |
|
630 | + ? '<div class="espresso-question-group-desc-pg">' |
|
631 | + . self::prep_answer($QSG['QSG_desc']) |
|
632 | + . '</div>' |
|
633 | + : ''; |
|
634 | + |
|
635 | + $html .= $before_question_group_questions; |
|
636 | + // loop thru questions |
|
637 | + foreach ($QSG['QSG_questions'] as $question) { |
|
638 | + $QFI = new EE_Question_Form_Input( |
|
639 | + $question['qst_obj'], |
|
640 | + $question['ans_obj'], |
|
641 | + $question |
|
642 | + ); |
|
643 | + $html .= self::generate_form_input($QFI); |
|
644 | + } |
|
645 | + $html .= $after_question_group_questions; |
|
646 | + $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
647 | + } |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + return $html; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * generate_question_groups_html |
|
657 | + * |
|
658 | + * @param array $question_groups |
|
659 | + * @param array $q_meta |
|
660 | + * @param bool $from_admin |
|
661 | + * @param string $group_wrapper |
|
662 | + * @return string HTML |
|
663 | + * @throws EE_Error |
|
664 | + * @throws ReflectionException |
|
665 | + */ |
|
666 | + public static function generate_question_groups_html2( |
|
667 | + $question_groups = [], |
|
668 | + $q_meta = [], |
|
669 | + $from_admin = false, |
|
670 | + $group_wrapper = 'fieldset' |
|
671 | + ) { |
|
672 | + |
|
673 | + $html = ''; |
|
674 | + $before_question_group_questions = |
|
675 | + apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', ''); |
|
676 | + $after_question_group_questions = |
|
677 | + apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', ''); |
|
678 | + |
|
679 | + $default_q_meta = [ |
|
680 | + 'att_nmbr' => 1, |
|
681 | + 'ticket_id' => '', |
|
682 | + 'input_name' => '', |
|
683 | + 'input_id' => '', |
|
684 | + 'input_class' => '', |
|
685 | + ]; |
|
686 | + $q_meta = array_merge($default_q_meta, $q_meta); |
|
687 | + |
|
688 | + if (! empty($question_groups)) { |
|
689 | + // loop thru question groups |
|
690 | + foreach ($question_groups as $QSG) { |
|
691 | + if ($QSG instanceof EE_Question_Group) { |
|
692 | + // check that questions exist |
|
693 | + |
|
694 | + $where = ['QST_deleted' => 0]; |
|
695 | + if (! $from_admin) { |
|
696 | + $where['QST_admin_only'] = 0; |
|
697 | + } |
|
698 | + $questions = |
|
699 | + $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]); |
|
700 | + if (! empty($questions)) { |
|
701 | + // use fieldsets |
|
702 | + $html .= "\n\t" |
|
703 | + . '<' . $group_wrapper . ' class="espresso-question-group-wrap" ' |
|
704 | + . 'id="' . $QSG->get('QSG_identifier') . '">'; |
|
705 | + // group_name |
|
706 | + if ($QSG->show_group_name()) { |
|
707 | + $html .= "\n\t\t" |
|
708 | + . '<h5 class="espresso-question-group-title-h5 section-title">' |
|
709 | + . $QSG->get_pretty('QSG_name') |
|
710 | + . '</h5>'; |
|
711 | + } |
|
712 | + // group_desc |
|
713 | + if ($QSG->show_group_desc()) { |
|
714 | + $html .= '<div class="espresso-question-group-desc-pg">' |
|
715 | + . $QSG->get_pretty('QSG_desc') |
|
716 | + . '</div>'; |
|
717 | + } |
|
718 | + |
|
719 | + $html .= $before_question_group_questions; |
|
720 | + // loop thru questions |
|
721 | + foreach ($questions as $QST) { |
|
722 | + $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID(); |
|
723 | + |
|
724 | + $answer = null; |
|
725 | + |
|
726 | + /** @var RequestInterface $request */ |
|
727 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
728 | + $request_qstn = $request->getRequestParam('qstn', [], 'string', true); |
|
729 | + if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) { |
|
730 | + // check for answer in $request_qstn in case we are reprocessing a form after an error |
|
731 | + if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) { |
|
732 | + $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]) |
|
733 | + ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ] |
|
734 | + : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]); |
|
735 | + } |
|
736 | + } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) { |
|
737 | + // attendee data from the session |
|
738 | + $answer = |
|
739 | + isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null; |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + $QFI = new EE_Question_Form_Input( |
|
744 | + $QST, |
|
745 | + EE_Answer::new_instance( |
|
746 | + [ |
|
747 | + 'ANS_ID' => 0, |
|
748 | + 'QST_ID' => 0, |
|
749 | + 'REG_ID' => 0, |
|
750 | + 'ANS_value' => $answer, |
|
751 | + ] |
|
752 | + ), |
|
753 | + $q_meta |
|
754 | + ); |
|
755 | + $html .= self::generate_form_input($QFI); |
|
756 | + } |
|
757 | + $html .= $after_question_group_questions; |
|
758 | + $html .= "\n\t" . '</' . $group_wrapper . '>'; |
|
759 | + } |
|
760 | + } |
|
761 | + } |
|
762 | + } |
|
763 | + return $html; |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * generate_form_input |
|
769 | + * |
|
770 | + * @param EE_Question_Form_Input $QFI |
|
771 | + * @return string HTML |
|
772 | + * @throws EE_Error |
|
773 | + * @throws ReflectionException |
|
774 | + */ |
|
775 | + public static function generate_form_input(EE_Question_Form_Input $QFI) |
|
776 | + { |
|
777 | + if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) { |
|
778 | + return ''; |
|
779 | + } |
|
780 | + /** @var RequestInterface $request */ |
|
781 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
782 | + |
|
783 | + $QFI = self::_load_system_dropdowns($QFI); |
|
784 | + $QFI = self::_load_specialized_dropdowns($QFI); |
|
785 | + |
|
786 | + // we also need to verify |
|
787 | + |
|
788 | + $display_text = $QFI->get('QST_display_text'); |
|
789 | + $input_name = $QFI->get('QST_input_name'); |
|
790 | + $answer = $request->getRequestParam($input_name, $QFI->get('ANS_value')); |
|
791 | + $input_id = $QFI->get('QST_input_id'); |
|
792 | + $input_class = $QFI->get('QST_input_class'); |
|
793 | + // $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : ''; |
|
794 | + $disabled = $QFI->get('QST_disabled'); |
|
795 | + $required_label = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>'); |
|
796 | + $QST_required = $QFI->get('QST_required'); |
|
797 | + $required = |
|
798 | + $QST_required |
|
799 | + ? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required] |
|
800 | + : []; |
|
801 | + $use_html_entities = $QFI->get_meta('htmlentities'); |
|
802 | + $required_text = |
|
803 | + $QFI->get('QST_required_text') != '' |
|
804 | + ? $QFI->get('QST_required_text') |
|
805 | + : esc_html__('This field is required', 'event_espresso'); |
|
806 | + $required_text = $QST_required |
|
807 | + ? "\n\t\t\t" |
|
808 | + . '<div class="required-text hidden">' |
|
809 | + . self::prep_answer($required_text, $use_html_entities) |
|
810 | + . '</div>' |
|
811 | + : ''; |
|
812 | + $label_class = 'espresso-form-input-lbl'; |
|
813 | + $QST_options = $QFI->options(true, $answer); |
|
814 | + $options = is_array($QST_options) ? self::prep_answer_options($QST_options) : []; |
|
815 | + $system_ID = $QFI->get('QST_system'); |
|
816 | + $label_b4 = $QFI->get_meta('label_b4'); |
|
817 | + $use_desc_4_label = $QFI->get_meta('use_desc_4_label'); |
|
818 | + |
|
819 | + |
|
820 | + switch ($QFI->get('QST_type')) { |
|
821 | + case 'TEXTAREA': |
|
822 | + return EEH_Form_Fields::textarea( |
|
823 | + $display_text, |
|
824 | + $answer, |
|
825 | + $input_name, |
|
826 | + $input_id, |
|
827 | + $input_class, |
|
828 | + [], |
|
829 | + $required, |
|
830 | + $required_text, |
|
831 | + $label_class, |
|
832 | + $disabled, |
|
833 | + $system_ID, |
|
834 | + $use_html_entities |
|
835 | + ); |
|
836 | + |
|
837 | + case 'DROPDOWN': |
|
838 | + return EEH_Form_Fields::select( |
|
839 | + $display_text, |
|
840 | + $answer, |
|
841 | + $options, |
|
842 | + $input_name, |
|
843 | + $input_id, |
|
844 | + $input_class, |
|
845 | + $required, |
|
846 | + $required_text, |
|
847 | + $label_class, |
|
848 | + $disabled, |
|
849 | + $system_ID, |
|
850 | + $use_html_entities, |
|
851 | + true |
|
852 | + ); |
|
853 | + |
|
854 | + |
|
855 | + case 'RADIO_BTN': |
|
856 | + return EEH_Form_Fields::radio( |
|
857 | + $display_text, |
|
858 | + $answer, |
|
859 | + $options, |
|
860 | + $input_name, |
|
861 | + $input_id, |
|
862 | + $input_class, |
|
863 | + $required, |
|
864 | + $required_text, |
|
865 | + $label_class, |
|
866 | + $disabled, |
|
867 | + $system_ID, |
|
868 | + $use_html_entities, |
|
869 | + $label_b4, |
|
870 | + $use_desc_4_label |
|
871 | + ); |
|
872 | + |
|
873 | + case 'CHECKBOX': |
|
874 | + return EEH_Form_Fields::checkbox( |
|
875 | + $display_text, |
|
876 | + $answer, |
|
877 | + $options, |
|
878 | + $input_name, |
|
879 | + $input_id, |
|
880 | + $input_class, |
|
881 | + $required, |
|
882 | + $required_text, |
|
883 | + $label_class, |
|
884 | + $disabled, |
|
885 | + $label_b4, |
|
886 | + $system_ID, |
|
887 | + $use_html_entities |
|
888 | + ); |
|
889 | + |
|
890 | + case 'DATE': |
|
891 | + return EEH_Form_Fields::datepicker( |
|
892 | + $display_text, |
|
893 | + $answer, |
|
894 | + $input_name, |
|
895 | + $input_id, |
|
896 | + $input_class, |
|
897 | + $required, |
|
898 | + $required_text, |
|
899 | + $label_class, |
|
900 | + $disabled, |
|
901 | + $system_ID, |
|
902 | + $use_html_entities |
|
903 | + ); |
|
904 | + |
|
905 | + case 'TEXT': |
|
906 | + default: |
|
907 | + return EEH_Form_Fields::text( |
|
908 | + $display_text, |
|
909 | + $answer, |
|
910 | + $input_name, |
|
911 | + $input_id, |
|
912 | + $input_class, |
|
913 | + $required, |
|
914 | + $required_text, |
|
915 | + $label_class, |
|
916 | + $disabled, |
|
917 | + $system_ID, |
|
918 | + $use_html_entities |
|
919 | + ); |
|
920 | + } |
|
921 | + } |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * generates HTML for a form text input |
|
926 | + * |
|
927 | + * @param string $question label content |
|
928 | + * @param string $answer form input value attribute |
|
929 | + * @param string $name form input name attribute |
|
930 | + * @param string $id form input css id attribute |
|
931 | + * @param string $class form input css class attribute |
|
932 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
933 | + * required 'class', and required 'msg' attribute |
|
934 | + * @param string $label_class css class attribute for the label |
|
935 | + * @param string $disabled disabled="disabled" or null |
|
936 | + * @return string HTML |
|
937 | + */ |
|
938 | + public static function text( |
|
939 | + $question = false, |
|
940 | + $answer = null, |
|
941 | + $name = false, |
|
942 | + $id = '', |
|
943 | + $class = '', |
|
944 | + $required = false, |
|
945 | + $required_text = '', |
|
946 | + $label_class = '', |
|
947 | + $disabled = false, |
|
948 | + $system_ID = false, |
|
949 | + $use_html_entities = true |
|
950 | + ) { |
|
951 | + // need these |
|
952 | + if (! $question || ! $name) { |
|
953 | + return null; |
|
954 | + } |
|
955 | + // prep the answer |
|
956 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
957 | + // prep the required array |
|
958 | + $required = self::prep_required($required); |
|
959 | + // set disabled tag |
|
960 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
961 | + // ya gots ta have style man!!! |
|
962 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp'; |
|
963 | + $class = empty($class) ? $txt_class : $class; |
|
964 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
965 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
966 | + |
|
967 | + $label_html = |
|
968 | + $required_text |
|
969 | + . "\n\t\t\t" |
|
970 | + . '<label for="' . $name . '" class="' . $label_class . '">' |
|
971 | + . self::prep_question($question) |
|
972 | + . $required['label'] |
|
973 | + . '</label><br/>'; |
|
974 | + // filter label but ensure required text comes before it |
|
975 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
976 | + |
|
977 | + $input_html = |
|
978 | + "\n\t\t\t" |
|
979 | + . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
980 | + . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '" ' |
|
981 | + . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
982 | + |
|
983 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
984 | + return $label_html . $input_html; |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * generates HTML for a form textarea |
|
990 | + * |
|
991 | + * @param string $question label content |
|
992 | + * @param string $answer form input value attribute |
|
993 | + * @param string $name form input name attribute |
|
994 | + * @param string $id form input css id attribute |
|
995 | + * @param string $class form input css class attribute |
|
996 | + * @param array $dimensions array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 ) |
|
997 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
998 | + * required 'class', and required 'msg' attribute |
|
999 | + * @param string $label_class css class attribute for the label |
|
1000 | + * @param string $disabled disabled="disabled" or null |
|
1001 | + * @return string HTML |
|
1002 | + */ |
|
1003 | + public static function textarea( |
|
1004 | + $question = false, |
|
1005 | + $answer = null, |
|
1006 | + $name = false, |
|
1007 | + $id = '', |
|
1008 | + $class = '', |
|
1009 | + $dimensions = false, |
|
1010 | + $required = false, |
|
1011 | + $required_text = '', |
|
1012 | + $label_class = '', |
|
1013 | + $disabled = false, |
|
1014 | + $system_ID = false, |
|
1015 | + $use_html_entities = true |
|
1016 | + ) { |
|
1017 | + // need these |
|
1018 | + if (! $question || ! $name) { |
|
1019 | + return null; |
|
1020 | + } |
|
1021 | + // prep the answer |
|
1022 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1023 | + // prep the required array |
|
1024 | + $required = self::prep_required($required); |
|
1025 | + // make sure $dimensions is an array |
|
1026 | + $dimensions = is_array($dimensions) ? $dimensions : []; |
|
1027 | + // and set some defaults |
|
1028 | + $dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions); |
|
1029 | + // set disabled tag |
|
1030 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1031 | + // ya gots ta have style man!!! |
|
1032 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp'; |
|
1033 | + $class = empty($class) ? $txt_class : $class; |
|
1034 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1035 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1036 | + |
|
1037 | + $label_html = |
|
1038 | + $required_text |
|
1039 | + . "\n\t\t\t" |
|
1040 | + . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1041 | + . self::prep_question($question) |
|
1042 | + . $required['label'] |
|
1043 | + . '</label><br/>'; |
|
1044 | + // filter label but ensure required text comes before it |
|
1045 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1046 | + |
|
1047 | + $input_html = |
|
1048 | + "\n\t\t\t" |
|
1049 | + . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1050 | + . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '" ' |
|
1051 | + . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>' |
|
1052 | + . esc_textarea($answer) |
|
1053 | + . '</textarea>'; |
|
1054 | + |
|
1055 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1056 | + return $label_html . $input_html; |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * generates HTML for a form select input |
|
1062 | + * |
|
1063 | + * @param string $question label content |
|
1064 | + * @param string $answer form input value attribute |
|
1065 | + * @param array $options array of answer options where array key = option value and array value = option |
|
1066 | + * display text |
|
1067 | + * @param string $name form input name attribute |
|
1068 | + * @param string $id form input css id attribute |
|
1069 | + * @param string $class form input css class attribute |
|
1070 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1071 | + * required 'class', and required 'msg' attribute |
|
1072 | + * @param string $label_class css class attribute for the label |
|
1073 | + * @param string $disabled disabled="disabled" or null |
|
1074 | + * @return string HTML |
|
1075 | + */ |
|
1076 | + public static function select( |
|
1077 | + $question = false, |
|
1078 | + $answer = null, |
|
1079 | + $options = false, |
|
1080 | + $name = false, |
|
1081 | + $id = '', |
|
1082 | + $class = '', |
|
1083 | + $required = false, |
|
1084 | + $required_text = '', |
|
1085 | + $label_class = '', |
|
1086 | + $disabled = false, |
|
1087 | + $system_ID = false, |
|
1088 | + $use_html_entities = true, |
|
1089 | + $add_please_select_option = false |
|
1090 | + ) { |
|
1091 | + |
|
1092 | + // need these |
|
1093 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1094 | + return null; |
|
1095 | + } |
|
1096 | + // prep the answer |
|
1097 | + $answer = |
|
1098 | + is_array($answer) |
|
1099 | + ? self::prep_answer(array_shift($answer), $use_html_entities) |
|
1100 | + : self::prep_answer( |
|
1101 | + $answer, |
|
1102 | + $use_html_entities |
|
1103 | + ); |
|
1104 | + // prep the required array |
|
1105 | + $required = self::prep_required($required); |
|
1106 | + // set disabled tag |
|
1107 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1108 | + // ya gots ta have style man!!! |
|
1109 | + $txt_class = is_admin() ? 'wide' : 'espresso-select-inp'; |
|
1110 | + $class = empty($class) ? $txt_class : $class; |
|
1111 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1112 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1113 | + |
|
1114 | + $label_html = |
|
1115 | + $required_text |
|
1116 | + . "\n\t\t\t" |
|
1117 | + . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1118 | + . self::prep_question($question) |
|
1119 | + . $required['label'] |
|
1120 | + . '</label><br/>'; |
|
1121 | + // filter label but ensure required text comes before it |
|
1122 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1123 | + |
|
1124 | + $input_html = |
|
1125 | + "\n\t\t\t" |
|
1126 | + . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" ' |
|
1127 | + . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>'; |
|
1128 | + // recursively count array elements, to determine total number of options |
|
1129 | + $only_option = count($options, 1) == 1; |
|
1130 | + if (! $only_option) { |
|
1131 | + // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected |
|
1132 | + $selected = $answer === null ? ' selected="selected"' : ''; |
|
1133 | + $input_html .= $add_please_select_option |
|
1134 | + ? "\n\t\t\t\t" |
|
1135 | + . '<option value=""' . $selected . '>' |
|
1136 | + . esc_html__(' - please select - ', 'event_espresso') |
|
1137 | + . '</option>' |
|
1138 | + : ''; |
|
1139 | + } |
|
1140 | + foreach ($options as $key => $value) { |
|
1141 | + // if value is an array, then create option groups, else create regular ol' options |
|
1142 | + $input_html .= is_array($value) |
|
1143 | + ? self::_generate_select_option_group( |
|
1144 | + $key, |
|
1145 | + $value, |
|
1146 | + $answer, |
|
1147 | + $use_html_entities |
|
1148 | + ) |
|
1149 | + : self::_generate_select_option( |
|
1150 | + $value->value(), |
|
1151 | + $value->desc(), |
|
1152 | + $answer, |
|
1153 | + $only_option, |
|
1154 | + $use_html_entities |
|
1155 | + ); |
|
1156 | + } |
|
1157 | + |
|
1158 | + $input_html .= "\n\t\t\t" . '</select>'; |
|
1159 | + |
|
1160 | + $input_html = |
|
1161 | + apply_filters( |
|
1162 | + 'FHEE__EEH_Form_Fields__select__before_end_wrapper', |
|
1163 | + $input_html, |
|
1164 | + $question, |
|
1165 | + $answer, |
|
1166 | + $name, |
|
1167 | + $id, |
|
1168 | + $class, |
|
1169 | + $system_ID |
|
1170 | + ); |
|
1171 | + |
|
1172 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1173 | + return $label_html . $input_html; |
|
1174 | + } |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * _generate_select_option_group |
|
1179 | + * |
|
1180 | + * if $value for a select box is an array, then the key will be used as the optgroup label |
|
1181 | + * and the value array will be looped thru and the elements sent to _generate_select_option |
|
1182 | + * |
|
1183 | + * @param mixed $opt_group |
|
1184 | + * @param mixed $QSOs |
|
1185 | + * @param mixed $answer |
|
1186 | + * @param boolean $use_html_entities |
|
1187 | + * @return string |
|
1188 | + */ |
|
1189 | + private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true) |
|
1190 | + { |
|
1191 | + $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">'; |
|
1192 | + foreach ($QSOs as $QSO) { |
|
1193 | + $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities); |
|
1194 | + } |
|
1195 | + $html .= "\n\t\t\t\t" . '</optgroup>'; |
|
1196 | + return $html; |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * _generate_select_option |
|
1202 | + * |
|
1203 | + * @param mixed $key |
|
1204 | + * @param mixed $value |
|
1205 | + * @param mixed $answer |
|
1206 | + * @param int $only_option |
|
1207 | + * @param boolean $use_html_entities |
|
1208 | + * @return string |
|
1209 | + */ |
|
1210 | + private static function _generate_select_option( |
|
1211 | + $key, |
|
1212 | + $value, |
|
1213 | + $answer, |
|
1214 | + $only_option = false, |
|
1215 | + $use_html_entities = true |
|
1216 | + ) { |
|
1217 | + $key = self::prep_answer($key, $use_html_entities); |
|
1218 | + $value = self::prep_answer($value, $use_html_entities); |
|
1219 | + $value = ! empty($value) ? $value : $key; |
|
1220 | + $selected = ($answer == $key || $only_option) ? 'selected="selected"' : ''; |
|
1221 | + return "\n\t\t\t\t" |
|
1222 | + . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> ' |
|
1223 | + . $value |
|
1224 | + . ' </option>'; |
|
1225 | + } |
|
1226 | + |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * generates HTML for form radio button inputs |
|
1230 | + * |
|
1231 | + * @param bool|string $question label content |
|
1232 | + * @param string $answer form input value attribute |
|
1233 | + * @param array|bool $options array of answer options where array key = option value and array value = option |
|
1234 | + * display text |
|
1235 | + * @param bool|string $name form input name attribute |
|
1236 | + * @param string $id form input css id attribute |
|
1237 | + * @param string $class form input css class attribute |
|
1238 | + * @param array|bool $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1239 | + * required 'class', and required 'msg' attribute |
|
1240 | + * @param string $required_text |
|
1241 | + * @param string $label_class css class attribute for the label |
|
1242 | + * @param bool|string $disabled disabled="disabled" or null |
|
1243 | + * @param bool $system_ID |
|
1244 | + * @param bool $use_html_entities |
|
1245 | + * @param bool $label_b4 |
|
1246 | + * @param bool $use_desc_4_label |
|
1247 | + * @return string HTML |
|
1248 | + */ |
|
1249 | + public static function radio( |
|
1250 | + $question = false, |
|
1251 | + $answer = null, |
|
1252 | + $options = false, |
|
1253 | + $name = false, |
|
1254 | + $id = '', |
|
1255 | + $class = '', |
|
1256 | + $required = false, |
|
1257 | + $required_text = '', |
|
1258 | + $label_class = '', |
|
1259 | + $disabled = false, |
|
1260 | + $system_ID = false, |
|
1261 | + $use_html_entities = true, |
|
1262 | + $label_b4 = false, |
|
1263 | + $use_desc_4_label = false |
|
1264 | + ) { |
|
1265 | + // need these |
|
1266 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1267 | + return null; |
|
1268 | + } |
|
1269 | + // prep the answer |
|
1270 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1271 | + // prep the required array |
|
1272 | + $required = self::prep_required($required); |
|
1273 | + // set disabled tag |
|
1274 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1275 | + // ya gots ta have style man!!! |
|
1276 | + $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
1277 | + $class = ! empty($class) ? $class : 'espresso-radio-btn-inp'; |
|
1278 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1279 | + |
|
1280 | + $label_html = |
|
1281 | + $required_text |
|
1282 | + . "\n\t\t\t" |
|
1283 | + . '<label class="' . $label_class . '">' |
|
1284 | + . self::prep_question($question) |
|
1285 | + . $required['label'] |
|
1286 | + . '</label> '; |
|
1287 | + // filter label but ensure required text comes before it |
|
1288 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1289 | + |
|
1290 | + $input_html = |
|
1291 | + "\n\t\t\t" |
|
1292 | + . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1293 | + |
|
1294 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1295 | + $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1296 | + |
|
1297 | + foreach ($options as $OPT) { |
|
1298 | + if ($OPT instanceof EE_Question_Option) { |
|
1299 | + $value = self::prep_option_value($OPT->value()); |
|
1300 | + $label = $use_desc_4_label ? $OPT->desc() : $OPT->value(); |
|
1301 | + $size = $use_desc_4_label |
|
1302 | + ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()) |
|
1303 | + : self::get_label_size_class($OPT->value()); |
|
1304 | + $desc = $OPT->desc();// no self::prep_answer |
|
1305 | + $answer = is_numeric($value) && empty($answer) ? 0 : $answer; |
|
1306 | + $checked = (string) $value == (string) $answer ? ' checked="checked"' : ''; |
|
1307 | + $opt = '-' . sanitize_key($value); |
|
1308 | + |
|
1309 | + $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1310 | + $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">'; |
|
1311 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : ''; |
|
1312 | + $input_html .= "\n\t\t\t\t\t\t" |
|
1313 | + . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" ' |
|
1314 | + . 'class="' . $class . '" value="' . $value . '" ' |
|
1315 | + . 'title="' . esc_attr($required['msg']) . '" ' . $disabled |
|
1316 | + . $checked . ' ' . $extra . '/>'; |
|
1317 | + $input_html .= ! $label_b4 |
|
1318 | + ? "\n\t\t\t\t\t\t" |
|
1319 | + . '<span class="espresso-radio-btn-desc">' |
|
1320 | + . $label |
|
1321 | + . '</span>' |
|
1322 | + : ''; |
|
1323 | + $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1324 | + $input_html .= $use_desc_4_label |
|
1325 | + ? '' |
|
1326 | + : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>'; |
|
1327 | + $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1328 | + } |
|
1329 | + } |
|
1330 | + |
|
1331 | + $input_html .= "\n\t\t\t" . '</ul>'; |
|
1332 | + |
|
1333 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1334 | + return $label_html . $input_html; |
|
1335 | + } |
|
1336 | + |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * generates HTML for form checkbox inputs |
|
1340 | + * |
|
1341 | + * @param string $question label content |
|
1342 | + * @param string $answer form input value attribute |
|
1343 | + * @param array $options array of options where array key = option value and array value = option display text |
|
1344 | + * @param string $name form input name attribute |
|
1345 | + * @param string $id form input css id attribute |
|
1346 | + * @param string $class form input css class attribute |
|
1347 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1348 | + * required 'class', and required 'msg' attribute |
|
1349 | + * @param string $label_class css class attribute for the label |
|
1350 | + * @param string $disabled disabled="disabled" or null |
|
1351 | + * @return string HTML |
|
1352 | + */ |
|
1353 | + public static function checkbox( |
|
1354 | + $question = false, |
|
1355 | + $answer = null, |
|
1356 | + $options = false, |
|
1357 | + $name = false, |
|
1358 | + $id = '', |
|
1359 | + $class = '', |
|
1360 | + $required = false, |
|
1361 | + $required_text = '', |
|
1362 | + $label_class = '', |
|
1363 | + $disabled = false, |
|
1364 | + $label_b4 = false, |
|
1365 | + $system_ID = false, |
|
1366 | + $use_html_entities = true |
|
1367 | + ) { |
|
1368 | + // need these |
|
1369 | + if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) { |
|
1370 | + return null; |
|
1371 | + } |
|
1372 | + $answer = maybe_unserialize($answer); |
|
1373 | + |
|
1374 | + // prep the answer(s) |
|
1375 | + $answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer]; |
|
1376 | + |
|
1377 | + foreach ($answer as $key => $value) { |
|
1378 | + $key = self::prep_option_value($key); |
|
1379 | + $answer[ $key ] = self::prep_answer($value, $use_html_entities); |
|
1380 | + } |
|
1381 | + |
|
1382 | + // prep the required array |
|
1383 | + $required = self::prep_required($required); |
|
1384 | + // set disabled tag |
|
1385 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1386 | + // ya gots ta have style man!!! |
|
1387 | + $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class; |
|
1388 | + $class = empty($class) ? 'espresso-radio-btn-inp' : $class; |
|
1389 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1390 | + |
|
1391 | + $label_html = |
|
1392 | + $required_text |
|
1393 | + . "\n\t\t\t" |
|
1394 | + . '<label class="' . $label_class . '">' |
|
1395 | + . self::prep_question($question) |
|
1396 | + . $required['label'] |
|
1397 | + . '</label> '; |
|
1398 | + // filter label but ensure required text comes before it |
|
1399 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1400 | + |
|
1401 | + $input_html = |
|
1402 | + "\n\t\t\t" |
|
1403 | + . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">'; |
|
1404 | + |
|
1405 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1406 | + $class .= ! empty($required['class']) ? ' ' . $required['class'] : ''; |
|
1407 | + |
|
1408 | + foreach ($options as $OPT) { |
|
1409 | + $value = $OPT->value();// self::prep_option_value( $OPT->value() ); |
|
1410 | + $size = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc()); |
|
1411 | + $text = self::prep_answer($OPT->value()); |
|
1412 | + $desc = $OPT->desc(); |
|
1413 | + $opt = '-' . sanitize_key($value); |
|
1414 | + |
|
1415 | + $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : ''; |
|
1416 | + |
|
1417 | + $input_html .= "\n\t\t\t\t" . '<li' . $size . '>'; |
|
1418 | + $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">'; |
|
1419 | + $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1420 | + $input_html .= "\n\t\t\t\t\t\t" |
|
1421 | + . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" ' |
|
1422 | + . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" ' |
|
1423 | + . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>'; |
|
1424 | + $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : ''; |
|
1425 | + $input_html .= "\n\t\t\t\t\t" . '</label>'; |
|
1426 | + if (! empty($desc) && $desc != $text) { |
|
1427 | + $input_html .= "\n\t\t\t\t\t" |
|
1428 | + . ' <br/><div class="espresso-checkbox-option-desc small-text grey-text">' |
|
1429 | + . $desc |
|
1430 | + . '</div>'; |
|
1431 | + } |
|
1432 | + $input_html .= "\n\t\t\t\t" . '</li>'; |
|
1433 | + } |
|
1434 | + |
|
1435 | + $input_html .= "\n\t\t\t" . '</ul>'; |
|
1436 | + |
|
1437 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1438 | + return $label_html . $input_html; |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * generates HTML for a form datepicker input |
|
1444 | + * |
|
1445 | + * @param string $question label content |
|
1446 | + * @param string $answer form input value attribute |
|
1447 | + * @param string $name form input name attribute |
|
1448 | + * @param string $id form input css id attribute |
|
1449 | + * @param string $class form input css class attribute |
|
1450 | + * @param array $required 'label', 'class', and 'msg' - array of values for required "label" content, css |
|
1451 | + * required 'class', and required 'msg' attribute |
|
1452 | + * @param string $label_class css class attribute for the label |
|
1453 | + * @param string $disabled disabled="disabled" or null |
|
1454 | + * @return string HTML |
|
1455 | + */ |
|
1456 | + public static function datepicker( |
|
1457 | + $question = false, |
|
1458 | + $answer = null, |
|
1459 | + $name = false, |
|
1460 | + $id = '', |
|
1461 | + $class = '', |
|
1462 | + $required = false, |
|
1463 | + $required_text = '', |
|
1464 | + $label_class = '', |
|
1465 | + $disabled = false, |
|
1466 | + $system_ID = false, |
|
1467 | + $use_html_entities = true |
|
1468 | + ) { |
|
1469 | + // need these |
|
1470 | + if (! $question || ! $name) { |
|
1471 | + return null; |
|
1472 | + } |
|
1473 | + // prep the answer |
|
1474 | + $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities); |
|
1475 | + // prep the required array |
|
1476 | + $required = self::prep_required($required); |
|
1477 | + // set disabled tag |
|
1478 | + $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"'; |
|
1479 | + // ya gots ta have style man!!! |
|
1480 | + $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp'; |
|
1481 | + $class = empty($class) ? $txt_class : $class; |
|
1482 | + $class .= ! empty($system_ID) ? ' ' . $system_ID : ''; |
|
1483 | + $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', ''); |
|
1484 | + |
|
1485 | + $label_html = |
|
1486 | + $required_text |
|
1487 | + . "\n\t\t\t" |
|
1488 | + . '<label for="' . $name . '" class="' . $label_class . '">' |
|
1489 | + . self::prep_question($question) |
|
1490 | + . $required['label'] |
|
1491 | + . '</label><br/>'; |
|
1492 | + // filter label but ensure required text comes before it |
|
1493 | + $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text); |
|
1494 | + |
|
1495 | + $input_html = |
|
1496 | + "\n\t\t\t" |
|
1497 | + . '<input type="text" name="' . $name . '" id="' . $id . '" ' |
|
1498 | + . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '" ' |
|
1499 | + . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>'; |
|
1500 | + |
|
1501 | + // enqueue scripts |
|
1502 | + wp_register_style( |
|
1503 | + 'espresso-ui-theme', |
|
1504 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1505 | + [], |
|
1506 | + EVENT_ESPRESSO_VERSION |
|
1507 | + ); |
|
1508 | + wp_enqueue_style('espresso-ui-theme'); |
|
1509 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
1510 | + |
|
1511 | + $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id); |
|
1512 | + return $label_html . $input_html; |
|
1513 | + } |
|
1514 | + |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * remove_label_keep_required_msg |
|
1518 | + * this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label |
|
1519 | + * |
|
1520 | + * @access public |
|
1521 | + * @return string |
|
1522 | + */ |
|
1523 | + public static function remove_label_keep_required_msg($label_html, $required_text) |
|
1524 | + { |
|
1525 | + return $required_text; |
|
1526 | + } |
|
1527 | + |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Simply returns the HTML for a hidden input of the given name and value. |
|
1531 | + * |
|
1532 | + * @param string $name |
|
1533 | + * @param string $value |
|
1534 | + * @return string HTML |
|
1535 | + */ |
|
1536 | + public static function hidden_input($name, $value, $id = '') |
|
1537 | + { |
|
1538 | + $id = ! empty($id) ? $id : $name; |
|
1539 | + return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>'; |
|
1540 | + } |
|
1541 | + |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * prep_question |
|
1545 | + * |
|
1546 | + * @param string $question |
|
1547 | + * @return string |
|
1548 | + */ |
|
1549 | + public static function prep_question($question) |
|
1550 | + { |
|
1551 | + return $question; |
|
1552 | + } |
|
1553 | + |
|
1554 | + |
|
1555 | + /** |
|
1556 | + * prep_answer |
|
1557 | + * |
|
1558 | + * @param mixed $answer |
|
1559 | + * @return string |
|
1560 | + */ |
|
1561 | + public static function prep_answer($answer, $use_html_entities = true) |
|
1562 | + { |
|
1563 | + // make sure we convert bools first. Otherwise (bool) false becomes an empty string which is NOT desired, |
|
1564 | + // we want "0". |
|
1565 | + if (is_bool($answer)) { |
|
1566 | + $answer = $answer ? 1 : 0; |
|
1567 | + } |
|
1568 | + $answer = trim(stripslashes(str_replace(''', "'", $answer))); |
|
1569 | + return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer; |
|
1570 | + } |
|
1571 | + |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * prep_answer_options |
|
1575 | + * |
|
1576 | + * @param array $QSOs array of EE_Question_Option objects |
|
1577 | + * @return array |
|
1578 | + */ |
|
1579 | + public static function prep_answer_options($QSOs = []) |
|
1580 | + { |
|
1581 | + $prepped_answer_options = []; |
|
1582 | + if (is_array($QSOs) && ! empty($QSOs)) { |
|
1583 | + foreach ($QSOs as $key => $QSO) { |
|
1584 | + if (! $QSO instanceof EE_Question_Option) { |
|
1585 | + $QSO = EE_Question_Option::new_instance( |
|
1586 | + [ |
|
1587 | + 'QSO_value' => is_array($QSO) && isset($QSO['id']) |
|
1588 | + ? (string) $QSO['id'] |
|
1589 | + : (string) $key, |
|
1590 | + 'QSO_desc' => is_array($QSO) && isset($QSO['text']) |
|
1591 | + ? (string) $QSO['text'] |
|
1592 | + : (string) $QSO, |
|
1593 | + ] |
|
1594 | + ); |
|
1595 | + } |
|
1596 | + if ($QSO->opt_group()) { |
|
1597 | + $prepped_answer_options[ $QSO->opt_group() ][] = $QSO; |
|
1598 | + } else { |
|
1599 | + $prepped_answer_options[] = $QSO; |
|
1600 | + } |
|
1601 | + } |
|
1602 | + } |
|
1603 | + // d( $prepped_answer_options ); |
|
1604 | + return $prepped_answer_options; |
|
1605 | + } |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * prep_option_value |
|
1610 | + * |
|
1611 | + * @param string $option_value |
|
1612 | + * @return string |
|
1613 | + */ |
|
1614 | + public static function prep_option_value($option_value) |
|
1615 | + { |
|
1616 | + return esc_attr(trim(stripslashes($option_value))); |
|
1617 | + } |
|
1618 | + |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * prep_required |
|
1622 | + * |
|
1623 | + * @param string|array $required |
|
1624 | + * @return array |
|
1625 | + */ |
|
1626 | + public static function prep_required($required = []) |
|
1627 | + { |
|
1628 | + // make sure required is an array |
|
1629 | + $required = is_array($required) ? $required : []; |
|
1630 | + // and set some defaults |
|
1631 | + return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required); |
|
1632 | + } |
|
1633 | + |
|
1634 | + |
|
1635 | + /** |
|
1636 | + * get_label_size_class |
|
1637 | + * |
|
1638 | + * @param string $value |
|
1639 | + * @return string |
|
1640 | + */ |
|
1641 | + public static function get_label_size_class($value = false) |
|
1642 | + { |
|
1643 | + if ($value === false || $value === '') { |
|
1644 | + return ' class="medium-lbl"'; |
|
1645 | + } |
|
1646 | + // determine length of option value |
|
1647 | + $val_size = strlen($value); |
|
1648 | + switch ($val_size) { |
|
1649 | + case $val_size < 3: |
|
1650 | + $size = ' class="nano-lbl"'; |
|
1651 | + break; |
|
1652 | + case $val_size < 6: |
|
1653 | + $size = ' class="micro-lbl"'; |
|
1654 | + break; |
|
1655 | + case $val_size < 12: |
|
1656 | + $size = ' class="tiny-lbl"'; |
|
1657 | + break; |
|
1658 | + case $val_size < 25: |
|
1659 | + $size = ' class="small-lbl"'; |
|
1660 | + break; |
|
1661 | + case $val_size > 100: |
|
1662 | + $size = ' class="big-lbl"'; |
|
1663 | + break; |
|
1664 | + default: |
|
1665 | + $size = ' class="medium-lbl"'; |
|
1666 | + break; |
|
1667 | + } |
|
1668 | + return $size; |
|
1669 | + } |
|
1670 | + |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * _load_system_dropdowns |
|
1674 | + * |
|
1675 | + * @param EE_Question_Form_Input $QFI |
|
1676 | + * @return array |
|
1677 | + * @throws EE_Error |
|
1678 | + * @throws ReflectionException |
|
1679 | + */ |
|
1680 | + private static function _load_system_dropdowns($QFI) |
|
1681 | + { |
|
1682 | + $QST_system = $QFI->get('QST_system'); |
|
1683 | + switch ($QST_system) { |
|
1684 | + case 'state': |
|
1685 | + $QFI = self::generate_state_dropdown($QFI); |
|
1686 | + break; |
|
1687 | + case 'country': |
|
1688 | + $QFI = self::generate_country_dropdown($QFI); |
|
1689 | + break; |
|
1690 | + case 'admin-state': |
|
1691 | + $QFI = self::generate_state_dropdown($QFI, true); |
|
1692 | + break; |
|
1693 | + case 'admin-country': |
|
1694 | + $QFI = self::generate_country_dropdown($QFI, true); |
|
1695 | + break; |
|
1696 | + } |
|
1697 | + return $QFI; |
|
1698 | + } |
|
1699 | + |
|
1700 | + |
|
1701 | + /** |
|
1702 | + * This preps dropdowns that are specialized. |
|
1703 | + * |
|
1704 | + * @param EE_Question_Form_Input $QFI |
|
1705 | + * |
|
1706 | + * @return EE_Question_Form_Input |
|
1707 | + * @throws EE_Error |
|
1708 | + * @throws ReflectionException |
|
1709 | + * @since 4.6.0 |
|
1710 | + */ |
|
1711 | + protected static function _load_specialized_dropdowns($QFI) |
|
1712 | + { |
|
1713 | + switch ($QFI->get('QST_type')) { |
|
1714 | + case 'STATE': |
|
1715 | + $QFI = self::generate_state_dropdown($QFI); |
|
1716 | + break; |
|
1717 | + case 'COUNTRY': |
|
1718 | + $QFI = self::generate_country_dropdown($QFI); |
|
1719 | + break; |
|
1720 | + } |
|
1721 | + return $QFI; |
|
1722 | + } |
|
1723 | + |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * generate_state_dropdown |
|
1727 | + * |
|
1728 | + * @param EE_Question_Form_Input $QST |
|
1729 | + * @param bool $get_all |
|
1730 | + * @return EE_Question_Form_Input |
|
1731 | + * @throws EE_Error |
|
1732 | + * @throws ReflectionException |
|
1733 | + */ |
|
1734 | + public static function generate_state_dropdown($QST, $get_all = false) |
|
1735 | + { |
|
1736 | + $states = $get_all |
|
1737 | + ? EEM_State::instance()->get_all_states() |
|
1738 | + : EEM_State::instance()->get_all_states_of_active_countries(); |
|
1739 | + if ($states && count($states) != count($QST->options())) { |
|
1740 | + $QST->set('QST_type', 'DROPDOWN'); |
|
1741 | + // if multiple countries, we'll create option groups within the dropdown |
|
1742 | + foreach ($states as $state) { |
|
1743 | + if ($state instanceof EE_State) { |
|
1744 | + $QSO = EE_Question_Option::new_instance( |
|
1745 | + [ |
|
1746 | + 'QSO_value' => $state->ID(), |
|
1747 | + 'QSO_desc' => $state->name(), |
|
1748 | + 'QST_ID' => $QST->get('QST_ID'), |
|
1749 | + 'QSO_deleted' => false, |
|
1750 | + ] |
|
1751 | + ); |
|
1752 | + // set option group |
|
1753 | + $QSO->set_opt_group($state->country()->name()); |
|
1754 | + // add option to question |
|
1755 | + $QST->add_temp_option($QSO); |
|
1756 | + } |
|
1757 | + } |
|
1758 | + } |
|
1759 | + return $QST; |
|
1760 | + } |
|
1761 | + |
|
1762 | + |
|
1763 | + /** |
|
1764 | + * generate_country_dropdown |
|
1765 | + * |
|
1766 | + * @param $QST |
|
1767 | + * @param bool $get_all |
|
1768 | + * @return array |
|
1769 | + * @throws EE_Error |
|
1770 | + * @throws ReflectionException |
|
1771 | + * @internal param array $question |
|
1772 | + */ |
|
1773 | + public static function generate_country_dropdown($QST, $get_all = false) |
|
1774 | + { |
|
1775 | + $countries = $get_all |
|
1776 | + ? EEM_Country::instance()->get_all_countries() |
|
1777 | + : EEM_Country::instance()->get_all_active_countries(); |
|
1778 | + if ($countries && count($countries) != count($QST->options())) { |
|
1779 | + $QST->set('QST_type', 'DROPDOWN'); |
|
1780 | + // now add countries |
|
1781 | + foreach ($countries as $country) { |
|
1782 | + if ($country instanceof EE_Country) { |
|
1783 | + $QSO = EE_Question_Option::new_instance( |
|
1784 | + [ |
|
1785 | + 'QSO_value' => $country->ID(), |
|
1786 | + 'QSO_desc' => $country->name(), |
|
1787 | + 'QST_ID' => $QST->get('QST_ID'), |
|
1788 | + 'QSO_deleted' => false, |
|
1789 | + ] |
|
1790 | + ); |
|
1791 | + $QST->add_temp_option($QSO); |
|
1792 | + } |
|
1793 | + } |
|
1794 | + } |
|
1795 | + return $QST; |
|
1796 | + } |
|
1797 | + |
|
1798 | + |
|
1799 | + /** |
|
1800 | + * generates options for a month dropdown selector with numbers from 01 to 12 |
|
1801 | + * |
|
1802 | + * @return array() |
|
1803 | + */ |
|
1804 | + public static function two_digit_months_dropdown_options() |
|
1805 | + { |
|
1806 | + $options = []; |
|
1807 | + for ($x = 1; $x <= 12; $x++) { |
|
1808 | + $mm = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1809 | + $options[ $mm ] = $mm; |
|
1810 | + } |
|
1811 | + return EEH_Form_Fields::prep_answer_options($options); |
|
1812 | + } |
|
1813 | + |
|
1814 | + |
|
1815 | + /** |
|
1816 | + * generates a year dropdown selector with numbers for the next ten years |
|
1817 | + * |
|
1818 | + * @return array |
|
1819 | + */ |
|
1820 | + public static function next_decade_two_digit_year_dropdown_options() |
|
1821 | + { |
|
1822 | + $options = []; |
|
1823 | + $current_year = date('y'); |
|
1824 | + $next_decade = $current_year + 10; |
|
1825 | + for ($x = $current_year; $x <= $next_decade; $x++) { |
|
1826 | + $yy = str_pad($x, 2, '0', STR_PAD_LEFT); |
|
1827 | + $options[ $yy ] = $yy; |
|
1828 | + } |
|
1829 | + return EEH_Form_Fields::prep_answer_options($options); |
|
1830 | + } |
|
1831 | + |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * generates a month/year dropdown selector for all registrations matching the given criteria. Typically used for |
|
1835 | + * list table filter. |
|
1836 | + * |
|
1837 | + * @param string $cur_date any currently selected date can be entered here. |
|
1838 | + * @param string $status Registration status |
|
1839 | + * @param integer $evt_category Event Category ID if the Event Category filter is selected |
|
1840 | + * @return string html |
|
1841 | + * @throws EE_Error |
|
1842 | + */ |
|
1843 | + public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0) |
|
1844 | + { |
|
1845 | + $_where = []; |
|
1846 | + if (! empty($status)) { |
|
1847 | + $_where['STS_ID'] = $status; |
|
1848 | + } |
|
1849 | + |
|
1850 | + if ($evt_category > 0) { |
|
1851 | + $_where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1852 | + } |
|
1853 | + |
|
1854 | + $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where); |
|
1855 | + |
|
1856 | + // setup vals for select input helper |
|
1857 | + $options = [ |
|
1858 | + 0 => [ |
|
1859 | + 'text' => esc_html__('Select a Month/Year', 'event_espresso'), |
|
1860 | + 'id' => '', |
|
1861 | + ], |
|
1862 | + ]; |
|
1863 | + |
|
1864 | + foreach ($regdtts as $regdtt) { |
|
1865 | + $date = $regdtt->reg_month . ' ' . $regdtt->reg_year; |
|
1866 | + $options[] = [ |
|
1867 | + 'text' => $date, |
|
1868 | + 'id' => $date, |
|
1869 | + ]; |
|
1870 | + } |
|
1871 | + |
|
1872 | + return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1873 | + } |
|
1874 | + |
|
1875 | + |
|
1876 | + /** |
|
1877 | + * generates a month/year dropdown selector for all events matching the given criteria |
|
1878 | + * Typically used for list table filter |
|
1879 | + * |
|
1880 | + * @param string $cur_date any currently selected date can be entered here. |
|
1881 | + * @param string $status "view" (i.e. all, today, month, draft) |
|
1882 | + * @param int $evt_category category event belongs to |
|
1883 | + * @param string $evt_active_status "upcoming", "expired", "active", or "inactive" |
|
1884 | + * @return string html |
|
1885 | + * @throws EE_Error |
|
1886 | + */ |
|
1887 | + public static function generate_event_months_dropdown( |
|
1888 | + $cur_date = '', |
|
1889 | + $status = null, |
|
1890 | + $evt_category = null, |
|
1891 | + $evt_active_status = null |
|
1892 | + ) { |
|
1893 | + // determine what post_status our condition will have for the query. |
|
1894 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
1895 | + switch ($status) { |
|
1896 | + case 'month': |
|
1897 | + case 'today': |
|
1898 | + case null: |
|
1899 | + case 'all': |
|
1900 | + $where['Event.status'] = ['NOT IN', ['trash']]; |
|
1901 | + break; |
|
1902 | + case 'draft': |
|
1903 | + $where['Event.status'] = ['IN', ['draft', 'auto-draft']]; |
|
1904 | + break; |
|
1905 | + default: |
|
1906 | + $where['Event.status'] = $status; |
|
1907 | + } |
|
1908 | + |
|
1909 | + // phpcs:enable |
|
1910 | + |
|
1911 | + // categories? |
|
1912 | + |
|
1913 | + |
|
1914 | + if (! empty($evt_category)) { |
|
1915 | + $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1916 | + $where['Event.Term_Taxonomy.term_id'] = $evt_category; |
|
1917 | + } |
|
1918 | + |
|
1919 | + |
|
1920 | + // $where['DTT_is_primary'] = 1; |
|
1921 | + |
|
1922 | + $DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status); |
|
1923 | + |
|
1924 | + // let's setup vals for select input helper |
|
1925 | + $options = [ |
|
1926 | + 0 => [ |
|
1927 | + 'text' => esc_html__('Select a Month/Year', 'event_espresso'), |
|
1928 | + 'id' => "", |
|
1929 | + ], |
|
1930 | + ]; |
|
1931 | + |
|
1932 | + |
|
1933 | + // translate month and date |
|
1934 | + global $wp_locale; |
|
1935 | + |
|
1936 | + foreach ($DTTS as $DTT) { |
|
1937 | + $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year; |
|
1938 | + $id = $DTT->dtt_month . ' ' . $DTT->dtt_year; |
|
1939 | + $options[] = [ |
|
1940 | + 'text' => $localized_date, |
|
1941 | + 'id' => $id, |
|
1942 | + ]; |
|
1943 | + } |
|
1944 | + |
|
1945 | + |
|
1946 | + return self::select_input('month_range', $options, $cur_date, '', 'wide'); |
|
1947 | + } |
|
1948 | + |
|
1949 | + |
|
1950 | + /** |
|
1951 | + * generates the dropdown selector for event categories |
|
1952 | + * typically used as a filter on list tables. |
|
1953 | + * |
|
1954 | + * @param integer $current_cat currently selected category |
|
1955 | + * @return string html for dropdown |
|
1956 | + * @throws EE_Error |
|
1957 | + * @throws ReflectionException |
|
1958 | + */ |
|
1959 | + public static function generate_event_category_dropdown($current_cat = -1) |
|
1960 | + { |
|
1961 | + $categories = EEM_Term::instance()->get_all_ee_categories(true); |
|
1962 | + $options = [ |
|
1963 | + '0' => [ |
|
1964 | + 'text' => esc_html__('All Categories', 'event_espresso'), |
|
1965 | + 'id' => -1, |
|
1966 | + ], |
|
1967 | + ]; |
|
1968 | + |
|
1969 | + // setup categories for dropdown |
|
1970 | + foreach ($categories as $category) { |
|
1971 | + $options[] = [ |
|
1972 | + 'text' => $category->get('name'), |
|
1973 | + 'id' => $category->ID(), |
|
1974 | + ]; |
|
1975 | + } |
|
1976 | + |
|
1977 | + return self::select_input('EVT_CAT', $options, $current_cat); |
|
1978 | + } |
|
1979 | + |
|
1980 | + |
|
1981 | + /** |
|
1982 | + * generate a submit button with or without it's own microform |
|
1983 | + * this is the only way to create buttons that are compatible across all themes |
|
1984 | + * |
|
1985 | + * @access public |
|
1986 | + * @param string $url - the form action |
|
1987 | + * @param string $ID - some kind of unique ID, appended with "-sbmt" for the input and "-frm" |
|
1988 | + * for the form |
|
1989 | + * @param string $class - css classes (separated by spaces if more than one) |
|
1990 | + * @param string $text - what appears on the button |
|
1991 | + * @param string $nonce_action - if using nonces |
|
1992 | + * @param bool|string $input_only - whether to print form header and footer. TRUE returns the input without |
|
1993 | + * the form |
|
1994 | + * @param string $extra_attributes - any extra attributes that need to be attached to the form input |
|
1995 | + * @return string |
|
1996 | + */ |
|
1997 | + public static function submit_button( |
|
1998 | + $url = '', |
|
1999 | + $ID = '', |
|
2000 | + $class = '', |
|
2001 | + $text = '', |
|
2002 | + $nonce_action = '', |
|
2003 | + $input_only = false, |
|
2004 | + $extra_attributes = '' |
|
2005 | + ) { |
|
2006 | + $btn = ''; |
|
2007 | + if (empty($url) || empty($ID)) { |
|
2008 | + return $btn; |
|
2009 | + } |
|
2010 | + $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso'); |
|
2011 | + $btn .= '<input id="' . $ID . '-btn" class="' . $class . '" ' |
|
2012 | + . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>'; |
|
2013 | + if (! $input_only) { |
|
2014 | + $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">'; |
|
2015 | + $btn_frm .= ! empty($nonce_action) |
|
2016 | + ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false) |
|
2017 | + : ''; |
|
2018 | + $btn_frm .= $btn; |
|
2019 | + $btn_frm .= '</form>'; |
|
2020 | + $btn = $btn_frm; |
|
2021 | + unset($btn_frm); |
|
2022 | + } |
|
2023 | + return $btn; |
|
2024 | + } |
|
2025 | 2025 | } |