PluginProbe
Booking Calendar / 11.9.1
Booking Calendar v11.9.1
11.9.1 11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 All 206 releases
booking / includes / page-setup-wizard / step-booking-form-template / template.php

template.php in Booking Calendar 11.9.1, at includes/page-setup-wizard/step-booking-form-template/template.php

247 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Modular Page 9 Booking Form template selector.
4 *
5 * @package Booking Calendar
6 * @var array<string,mixed> $template_context Authorized step context.
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 $step_data = $template_context['step_data'];
14 $templates = isset( $step_data['templates'] ) && is_array( $step_data['templates'] ) ? $step_data['templates'] : array();
15 $filters = isset( $step_data['filters'] ) && is_array( $step_data['filters'] ) ? $step_data['filters'] : array();
16 $usage_options = isset( $step_data['usage_options'] ) && is_array( $step_data['usage_options'] ) ? $step_data['usage_options'] : array();
17 $selected_template = isset( $step_data['selected_template'] ) && is_array( $step_data['selected_template'] ) ? $step_data['selected_template'] : array();
18 $selected_slug = isset( $step_data['values']['booking_form_template'] ) ? (string) $step_data['values']['booking_form_template'] : '';
19 $selected_usage = isset( $step_data['values']['booking_form_usage'] ) ? sanitize_key( (string) $step_data['values']['booking_form_usage'] ) : 'direct_booking_form';
20 $selected_category = isset( $selected_template['category'] ) ? sanitize_key( (string) $selected_template['category'] ) : '';
21 $initial_filter = ! empty( $selected_template['is_recommended'] )
22 ? 'recommended'
23 : ( in_array( $selected_category, array( 'appointments', 'time_slots', 'full_days' ), true ) ? $selected_category : 'all' );
24 $preview_title = isset( $selected_template['title'] ) ? (string) $selected_template['title'] : '';
25 $preview_kind = isset( $step_data['preview_kind'] ) ? sanitize_key( (string) $step_data['preview_kind'] ) : '';
26 $preview_html = isset( $step_data['preview_html'] ) ? (string) $step_data['preview_html'] : '';
27 $preview_bootstrap = isset( $step_data['preview_bootstrap'] ) && is_array( $step_data['preview_bootstrap'] ) ? $step_data['preview_bootstrap'] : array();
28 $preview_error = isset( $step_data['preview_error'] ) ? (string) $step_data['preview_error'] : '';
29 $has_inline_preview = 'inline' === $preview_kind && '' !== trim( $preview_html ) && ! empty( $preview_bootstrap );
30 $preview_shortcode = 'appointment_flow' === $selected_usage
31 ? '[booking_appointment]'
32 : '[booking]';
33 ?>
34 <section class="wpbc_setup_wizard__step-content wpbc_setup_wizard__booking-form-step" aria-labelledby="wpbc-setup-wizard-step-title">
35 <header class="wpbc_setup_wizard__step-heading">
36 <h1 id="wpbc-setup-wizard-step-title"><?php esc_html_e( 'Choose a booking form template', 'booking' ); ?></h1>
37 <p class="wpbc_setup_wizard__lead"><?php esc_html_e( 'Select a template and try the real booking form before continuing.', 'booking' ); ?></p>
38 </header>
39 <?php
40 $template_context['templates']->render(
41 'settings-hint',
42 array( 'settings_hint' => $template_context['settings_hint'] )
43 );
44 ?>
45
46 <form id="wpbc-setup-wizard-step-form" novalidate>
47 <div class="wpbc_setup_wizard__booking-form-layout" data-wpbc-booking-form-template-editor data-initial-filter="<?php echo esc_attr( $initial_filter ); ?>">
48 <section class="wpbc_setup_wizard__template-library" aria-labelledby="wpbc-setup-wizard-template-library-title">
49 <div class="wpbc_setup_wizard__template-controls">
50 <h2 id="wpbc-setup-wizard-template-library-title"><?php esc_html_e( 'Templates', 'booking' ); ?></h2>
51
52 <label class="wpbc_setup_wizard__template-search">
53 <span class="screen-reader-text"><?php esc_html_e( 'Search booking form templates', 'booking' ); ?></span>
54 <input type="search" placeholder="<?php esc_attr_e( 'Search templates', 'booking' ); ?>" autocomplete="off" data-wpbc-template-search>
55 </label>
56
57 <div class="wpbc_setup_wizard__template-filters" role="tablist" aria-label="<?php esc_attr_e( 'Filter booking form templates', 'booking' ); ?>">
58 <?php foreach ( $filters as $filter_index => $filter ) : ?>
59 <?php
60 $filter_id = isset( $filter['id'] ) ? sanitize_key( (string) $filter['id'] ) : '';
61 $filter_label = isset( $filter['label'] ) ? (string) $filter['label'] : '';
62 $filter_count = isset( $filter['count'] ) ? absint( $filter['count'] ) : 0;
63 $is_active = $initial_filter === $filter_id;
64 ?>
65 <button
66 type="button"
67 role="tab"
68 id="wpbc-setup-wizard-template-filter-<?php echo esc_attr( $filter_id ); ?>"
69 aria-selected="<?php echo $is_active ? 'true' : 'false'; ?>"
70 tabindex="<?php echo $is_active ? '0' : '-1'; ?>"
71 class="wpbc_setup_wizard__template-filter<?php echo $is_active ? ' is-active' : ''; ?>"
72 data-wpbc-template-filter="<?php echo esc_attr( $filter_id ); ?>"
73 data-template-count="<?php echo esc_attr( (string) $filter_count ); ?>"
74 >
75 <?php echo esc_html( $filter_label ); ?><?php if ( 'all' === $filter_id ) : ?> <span>(<?php echo esc_html( (string) $filter_count ); ?>)</span><?php endif; ?>
76 </button>
77 <?php endforeach; ?>
78 </div>
79 </div>
80
81 <div
82 class="wpbc_setup_wizard__template-grid"
83 role="tabpanel"
84 tabindex="0"
85 aria-live="polite"
86 aria-labelledby="wpbc-setup-wizard-template-filter-<?php echo esc_attr( $initial_filter ); ?>"
87 data-wpbc-template-grid
88 >
89 <?php foreach ( $templates as $template ) : ?>
90 <?php
91 $template_slug = isset( $template['slug'] ) ? (string) $template['slug'] : '';
92 $template_title = isset( $template['title'] ) ? (string) $template['title'] : '';
93 $template_description = isset( $template['description'] ) ? (string) $template['description'] : '';
94 $template_picture_url = isset( $template['picture_url'] ) ? (string) $template['picture_url'] : '';
95 $template_category = isset( $template['category'] ) ? sanitize_key( (string) $template['category'] ) : 'other';
96 $is_recommended = ! empty( $template['is_recommended'] );
97 $is_selected = $selected_slug === $template_slug;
98 ?>
99 <article
100 class="wpbc_setup_wizard__template-card<?php echo $is_selected ? ' is-selected' : ''; ?>"
101 data-wpbc-template-card
102 data-template-slug="<?php echo esc_attr( $template_slug ); ?>"
103 data-template-category="<?php echo esc_attr( $template_category ); ?>"
104 data-template-recommended="<?php echo $is_recommended ? 'true' : 'false'; ?>"
105 data-template-picture-url="<?php echo esc_url( $template_picture_url ); ?>"
106 >
107 <label>
108 <span class="wpbc_setup_wizard__template-card-preview" data-wpbc-template-card-preview>
109 <?php if ( '' !== $template_picture_url ) : ?>
110 <img src="<?php echo esc_url( $template_picture_url ); ?>" alt="" loading="lazy" data-wpbc-template-card-image>
111 <?php endif; ?>
112 <span class="wpbc_setup_wizard__template-image-placeholder"<?php if ( '' !== $template_picture_url ) : ?> hidden<?php endif; ?> data-wpbc-template-image-placeholder>
113 <i class="menu_icon icon-2x wpbc-bi-image-fill" aria-hidden="true"></i>
114 <span><?php esc_html_e( 'Preview unavailable', 'booking' ); ?></span>
115 </span>
116 </span>
117 <span class="wpbc_setup_wizard__template-card-heading">
118 <input
119 type="radio"
120 name="booking_form_template"
121 value="<?php echo esc_attr( $template_slug ); ?>"
122 required
123 data-wpbc-setup-wizard-field
124 data-wpbc-template-radio
125 <?php checked( $is_selected ); ?>
126 >
127 <span class="wpbc_setup_wizard__radio-mark" aria-hidden="true"></span>
128 <strong data-wpbc-template-title><?php echo esc_html( $template_title ); ?></strong>
129 </span>
130 <span class="screen-reader-text" data-wpbc-template-description><?php echo esc_html( $template_description ); ?></span>
131 </label>
132 </article>
133 <?php endforeach; ?>
134 </div>
135 <p class="wpbc_setup_wizard__template-empty" data-wpbc-template-empty hidden><?php esc_html_e( 'No templates match this search and filter.', 'booking' ); ?></p>
136 <?php if ( empty( $templates ) ) : ?>
137 <p class="wpbc_setup_wizard__template-catalog-unavailable wpbc_setup_wizard__message wpbc_setup_wizard__message--warning"><?php esc_html_e( 'Booking form templates are temporarily unavailable. You can go back without changing any live form.', 'booking' ); ?></p>
138 <?php endif; ?>
139 <span class="wpbc_setup_wizard__field-error wpbc_setup_wizard__field-error--group" id="wpbc-setup-wizard-booking-form-template-error" data-wpbc-setup-wizard-error-for="booking_form_template"></span>
140 </section>
141
142 <section class="wpbc_setup_wizard__booking-form-usage-panel" aria-labelledby="wpbc-setup-wizard-booking-form-usage-title">
143 <fieldset class="wpbc_setup_wizard__booking-form-usage" data-wpbc-booking-form-usage>
144 <legend id="wpbc-setup-wizard-booking-form-usage-title"><?php esc_html_e( 'Use template with', 'booking' ); ?></legend>
145 <div class="wpbc_setup_wizard__booking-form-usage-options">
146 <?php foreach ( $usage_options as $usage_option ) : ?>
147 <?php
148 $usage_id = isset( $usage_option['id'] ) ? sanitize_key( (string) $usage_option['id'] ) : '';
149 $usage_label = isset( $usage_option['label'] ) ? (string) $usage_option['label'] : '';
150 $usage_description = isset( $usage_option['description'] ) ? (string) $usage_option['description'] : '';
151 ?>
152 <label class="wpbc_setup_wizard__booking-form-usage-option<?php echo $selected_usage === $usage_id ? ' is-selected' : ''; ?>">
153 <input
154 type="radio"
155 name="booking_form_usage"
156 value="<?php echo esc_attr( $usage_id ); ?>"
157 required
158 data-wpbc-setup-wizard-field
159 data-wpbc-booking-form-usage-radio
160 <?php checked( $selected_usage, $usage_id ); ?>
161 >
162 <span>
163 <strong><?php echo esc_html( $usage_label ); ?></strong>
164 <small><?php echo esc_html( $usage_description ); ?></small>
165 </span>
166 </label>
167 <?php endforeach; ?>
168 </div>
169 <span class="wpbc_setup_wizard__field-error wpbc_setup_wizard__field-error--group" data-wpbc-setup-wizard-error-for="booking_form_usage"></span>
170 </fieldset>
171 </section>
172
173 <section class="wpbc_setup_wizard__template-preview-panel" aria-labelledby="wpbc-setup-wizard-template-preview-title">
174 <header class="wpbc_setup_wizard__template-preview-toolbar">
175 <div class="wpbc_setup_wizard__template-preview-heading">
176 <h2 id="wpbc-setup-wizard-template-preview-title"><?php esc_html_e( 'Live preview', 'booking' ); ?></h2>
177 <span><i aria-hidden="true"></i><?php esc_html_e( 'Real booking form preview', 'booking' ); ?></span>
178 </div>
179 <div class="wpbc_setup_wizard__template-preview-actions">
180 <button type="button" class="button button-secondary" data-wpbc-template-refresh>
181 <i class="menu_icon icon-1x wpbc_icn_refresh" aria-hidden="true"></i>
182 <span><?php esc_html_e( 'Refresh', 'booking' ); ?></span>
183 </button>
184 <button
185 type="button"
186 class="button button-secondary"
187 data-wpbc-template-open-preview
188 >
189 <i class="menu_icon icon-1x wpbc_icn_open_in_new" aria-hidden="true"></i>
190 <span><?php esc_html_e( 'Open in new window', 'booking' ); ?></span>
191 </button>
192 </div>
193 </header>
194
195 <div
196 class="wpbc_setup_wizard__template-preview-stage"
197 data-wpbc-template-preview-stage
198 data-initial-preview-kind="<?php echo esc_attr( $has_inline_preview ? 'inline' : '' ); ?>"
199 data-initial-preview-template-slug="<?php echo esc_attr( $has_inline_preview ? $selected_slug : '' ); ?>"
200 data-initial-preview-booking-form-usage="<?php echo esc_attr( $has_inline_preview ? $selected_usage : '' ); ?>"
201 >
202 <div class="wpbc_setup_wizard__template-preview-loader" role="status" aria-live="polite" <?php echo $has_inline_preview || '' !== $preview_error ? 'hidden' : ''; ?> data-wpbc-template-preview-loader>
203 <span class="spinner is-active" aria-hidden="true"></span>
204 <span><?php esc_html_e( 'Loading the interactive booking form preview.', 'booking' ); ?></span>
205 </div>
206 <div class="wpbc_setup_wizard__template-inline-preview" <?php echo $has_inline_preview ? '' : 'hidden'; ?> data-wpbc-template-inline-preview data-wpbc-inline-booking-preview="1">
207 <div class="wpbc_theme_preview wpbc_theme_preview_mode_form" data-wpbc-theme-preview="1">
208 <div class="wpbc_theme_real_preview" data-wpbc-template-inline-preview-content>
209 <?php echo $preview_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- generated by the shared Form Builder renderer after server registry resolution and preview sanitization. ?>
210 </div>
211 </div>
212 </div>
213 <?php if ( $has_inline_preview ) : ?>
214 <script type="application/json" data-wpbc-template-initial-preview-bootstrap><?php echo wp_json_encode( $preview_bootstrap, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON is hex encoded and parsed only as data by the allow-listed preview renderer. ?></script>
215 <?php endif; ?>
216 <iframe
217 title="<?php esc_attr_e( 'Interactive booking form template preview', 'booking' ); ?>"
218 src="about:blank"
219 hidden
220 data-wpbc-template-preview-frame
221 ></iframe>
222 <div class="wpbc_setup_wizard__template-preview-error" role="alert" <?php echo '' === $preview_error ? 'hidden' : ''; ?> data-wpbc-template-preview-error>
223 <i class="menu_icon icon-1x wpbc_icn_error_outline" aria-hidden="true"></i>
224 <span><?php echo '' !== $preview_error ? esc_html( $preview_error ) : esc_html__( 'The interactive preview could not be loaded. Try refreshing it.', 'booking' ); ?></span>
225 </div>
226 </div>
227
228 <footer class="wpbc_setup_wizard__template-preview-details">
229 <div>
230 <strong data-wpbc-template-preview-title><?php echo esc_html( $preview_title ); ?></strong>
231 <code data-wpbc-template-preview-slug><?php echo esc_html( $selected_slug ); ?></code>
232 <span class="wpbc_setup_wizard__template-preview-shortcode">
233 <span><?php esc_html_e( 'Shortcode:', 'booking' ); ?></span>
234 <code data-wpbc-template-preview-shortcode><?php echo esc_html( $preview_shortcode ); ?></code>
235 </span>
236 </div>
237 <p data-wpbc-template-preview-description><?php echo isset( $selected_template['description'] ) ? esc_html( (string) $selected_template['description'] ) : ''; ?></p>
238 </footer>
239 <p class="wpbc_setup_wizard__template-preview-note wpbc_setup_wizard__message wpbc_setup_wizard__message--info">
240 <i class="menu_icon icon-1x wpbc_icn_info_outline" aria-hidden="true"></i>
241 <span><?php esc_html_e( 'The embedded preview uses the real booking form and Booking Calendar styles. In this request-local preview, calculated date, time, capacity, and cost summaries are marked Preview only and final booking submission is disabled. Open it in a new window to use the complete preview behavior and check the active site theme. Selecting or trying a template does not replace a saved form. Update booking form & continue applies the selected template to the Standard Booking Form used on the front end.', 'booking' ); ?></span>
242 </p>
243 </section>
244 </div>
245 </form>
246 </section>
247