PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
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 10.10.2 All 205 releases
booking / includes / page-form-builder / field-packs / time-picker-appearance.php

time-picker-appearance.php in Booking Calendar 11.9, at includes/page-form-builder/field-packs/time-picker-appearance.php

225 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shared global time-picker appearance controls for Booking Form Builder time fields.
4 *
5 * Every time-based field uses this renderer so the global display toggle and
6 * skin selector stay consistent and are not duplicated across field packs.
7 *
8 * @package Booking Calendar
9 * @since 11.4.4
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Check whether the current user can edit global time-picker options.
18 *
19 * @return bool
20 */
21 function wpbc_bfb_time_picker__can_manage_global_options() {
22 return ( ! function_exists( 'wpbc_is_mu_user_can_be_here' ) || wpbc_is_mu_user_can_be_here( 'only_super_admin' ) );
23 }
24
25 /**
26 * Normalize a time-picker skin path or URL to the value stored in the database.
27 *
28 * @param string $skin_value Skin path or URL.
29 *
30 * @return string
31 */
32 function wpbc_bfb_time_picker__normalize_skin_value( $skin_value ) {
33
34 $skin_value = is_scalar( $skin_value ) ? (string) $skin_value : '';
35 $replace = array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL );
36 $upload_dir = wp_upload_dir();
37
38 if ( ! empty( $upload_dir['basedir'] ) ) {
39 $replace[] = $upload_dir['basedir'];
40 }
41 if ( ! empty( $upload_dir['baseurl'] ) ) {
42 $replace[] = $upload_dir['baseurl'];
43 }
44
45 return str_replace( $replace, '', $skin_value );
46 }
47
48 /**
49 * Resolve a stored time-picker skin path to its public URL.
50 *
51 * @param string $relative_skin Relative skin path.
52 *
53 * @return string
54 */
55 function wpbc_bfb_time_picker__get_skin_url( $relative_skin ) {
56
57 $relative_skin = wpbc_bfb_time_picker__normalize_skin_value( $relative_skin );
58 $upload_dir = wp_upload_dir();
59 $upload_url = ! empty( $upload_dir['baseurl'] ) ? $upload_dir['baseurl'] : '';
60
61 if ( 0 === strpos( $relative_skin, '/wpbc_time_picker_skins/' ) && ! empty( $upload_url ) ) {
62 return $upload_url . $relative_skin;
63 }
64
65 return WPBC_PLUGIN_URL . $relative_skin;
66 }
67
68 /**
69 * Get time-picker skins for the shared Inspector selectbox.
70 *
71 * @return array
72 */
73 function wpbc_bfb_time_picker__get_skin_options() {
74
75 $automatic_skin = '/css/time_picker_skins/form_style.css';
76 $options = array();
77 $upload_dir = wp_upload_dir();
78
79 if ( function_exists( 'wpbc_dir_list' ) ) {
80 $skin_directories = array( WPBC_PLUGIN_DIR . '/css/time_picker_skins/' );
81 if ( ! empty( $upload_dir['basedir'] ) ) {
82 $skin_directories[] = $upload_dir['basedir'] . '/wpbc_time_picker_skins/';
83 }
84
85 $files = wpbc_dir_list(
86 $skin_directories
87 );
88
89 foreach ( $files as $skin_file ) {
90 $relative_skin = wpbc_bfb_time_picker__normalize_skin_value( $skin_file[1] );
91 $options[ $relative_skin ] = array(
92 'title' => $skin_file[2],
93 'attr' => array(
94 'data-wpbc-time-picker-skin-url' => wpbc_bfb_time_picker__get_skin_url( $relative_skin ),
95 ),
96 );
97 }
98 }
99
100 // Keep the recommended option available even if a directory scan is filtered or unavailable.
101 if ( ! isset( $options[ $automatic_skin ] ) && file_exists( WPBC_PLUGIN_DIR . $automatic_skin ) ) {
102 $options[ $automatic_skin ] = array(
103 'title' => __( 'Automatic — Match Booking Form', 'booking' ),
104 'attr' => array(
105 'data-wpbc-time-picker-skin-url' => wpbc_bfb_time_picker__get_skin_url( $automatic_skin ),
106 ),
107 );
108 }
109
110 if ( isset( $options[ $automatic_skin ] ) ) {
111 $automatic_option = $options[ $automatic_skin ];
112 $automatic_option['title'] = __( 'Automatic — Match Booking Form', 'booking' );
113 unset( $options[ $automatic_skin ] );
114 $options = array_merge( array( $automatic_skin => $automatic_option ), $options );
115 }
116
117 $bundled_titles = array(
118 '/css/time_picker_skins/light__24_8.css' => __( 'Light', 'booking' ),
119 '/css/time_picker_skins/grey.css' => __( 'Grey', 'booking' ),
120 '/css/time_picker_skins/black.css' => __( 'Black', 'booking' ),
121 '/css/time_picker_skins/blue.css' => __( 'Blue', 'booking' ),
122 '/css/time_picker_skins/green.css' => __( 'Green', 'booking' ),
123 '/css/time_picker_skins/orange.css' => __( 'Orange', 'booking' ),
124 '/css/time_picker_skins/marine.css' => __( 'Marine', 'booking' ),
125 );
126 foreach ( $bundled_titles as $skin_path => $skin_title ) {
127 if ( isset( $options[ $skin_path ] ) ) {
128 $options[ $skin_path ]['title'] = $skin_title;
129 }
130 }
131
132 /**
133 * Filter time-picker skins displayed in Booking Form Builder time fields.
134 *
135 * @param array $options Time-picker skin options.
136 */
137 return apply_filters( 'wpbc_bfb_time_picker_skin_options', $options );
138 }
139
140 /**
141 * Render global time-picker display and skin controls in a time-field Inspector.
142 *
143 * @return void
144 */
145 function wpbc_bfb_time_picker__print_inspector_group() {
146
147 if ( ! wpbc_bfb_time_picker__can_manage_global_options() ) {
148 return;
149 }
150
151 $is_enabled = ( 'On' === get_bk_option( 'booking_timeslot_picker' ) );
152 $current_skin = wpbc_bfb_time_picker__normalize_skin_value( get_bk_option( 'booking_timeslot_picker_skin' ) );
153 $toggle_option = 'booking_timeslot_picker';
154 $skin_option = 'booking_timeslot_picker_skin';
155 $skin_select_id = 'wpbc_bfb__time_field__booking_timeslot_picker_skin';
156
157 ?>
158 <div class="inspector__row row__bordered wpbc_bfb__inspector_time_picker_appearance" data-wpbc-time-picker-appearance="display" style="align-items:flex-start;justify-content:space-between;">
159 <div class="inspector__control" style="flex:1 1 auto;">
160 <label class="inspector__label" for="wpbc_bfb__time_field__booking_timeslot_picker">
161 <strong><?php esc_html_e( 'Time Picker Display', 'booking' ); ?></strong>
162 </label>
163 <span class="wpbc_ui__toggle" style="margin-top:6px;">
164 <input id="wpbc_bfb__time_field__booking_timeslot_picker" type="checkbox" class="inspector__checkbox js-toggle-timeslot-picker" <?php checked( $is_enabled ); ?> />
165 <label class="wpbc_ui__toggle_icon" for="wpbc_bfb__time_field__booking_timeslot_picker" aria-hidden="true"></label>
166 <label class="wpbc_ui__toggle_label" for="wpbc_bfb__time_field__booking_timeslot_picker"><?php esc_html_e( 'Show time slots as clickable choices instead of a select box.', 'booking' ); ?></label>
167 </span>
168 <p class="wpbc_bfb__help" style="margin-top:6px;"><?php esc_html_e( 'This is a global option used by all compatible time fields.', 'booking' ); ?></p>
169 </div>
170 <a href="javascript:void(0);"
171 class="button button-secondary"
172 onclick="wpbc_save_option_from_element(this);"
173 data-wpbc-u-save-name="<?php echo esc_attr( $toggle_option ); ?>"
174 data-wpbc-u-save-value-from="#wpbc_bfb__time_field__booking_timeslot_picker"
175 data-wpbc-u-autosave-on-form-save="1"
176 data-wpbc-u-busy-text="<?php esc_attr_e( 'Saving', 'booking' ); ?>...">
177 <?php esc_html_e( 'Save Display', 'booking' ); ?>
178 </a>
179 </div>
180
181 <div class="inspector__row row__bordered js-time-picker-skin-row wpbc_bfb__inspector_time_picker_appearance" data-wpbc-time-picker-appearance="skin" style="align-items:flex-start;justify-content:space-between;<?php echo $is_enabled ? '' : 'display:none;'; ?>" <?php echo $is_enabled ? '' : 'hidden aria-hidden="true"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
182 <div class="inspector__control" style="flex:1 1 auto;">
183 <label for="<?php echo esc_attr( $skin_select_id ); ?>" class="inspector__label" style="display:block;margin:0 0 6px;">
184 <strong><?php esc_html_e( 'Time Slot Style', 'booking' ); ?></strong>
185 </label>
186 <div class="wpbc_ajx_toolbar wpbc_no_borders">
187 <div class="ui_container ui_container_small0">
188 <div class="ui_group">
189 <div class="ui_element ui_nowrap">
190 <?php
191 wpbc_flex_select(
192 array(
193 'id' => $skin_select_id,
194 'name' => $skin_option,
195 'label' => '',
196 'class' => 'js-wpbc-bfb-time-picker-skin',
197 'value' => $current_skin,
198 'disabled' => false,
199 'disabled_options' => array(),
200 'options' => wpbc_bfb_time_picker__get_skin_options(),
201 )
202 );
203 wpbc_smpl_form__ui__selectbox_prior_btn( $skin_select_id, false );
204 wpbc_smpl_form__ui__selectbox_next_btn( $skin_select_id, false );
205 ?>
206 </div>
207 </div>
208 </div>
209 </div>
210 <p class="wpbc_bfb__help" style="margin-top:6px;"><?php esc_html_e( 'Automatic follows the Booking Form Style and accent color. Other skins keep their own colors.', 'booking' ); ?></p>
211 </div>
212 <a href="javascript:void(0);"
213 class="button button-primary"
214 onclick="wpbc_save_option_from_element(this);"
215 data-wpbc-u-save-name="<?php echo esc_attr( $skin_option ); ?>"
216 data-wpbc-u-save-value-from="#<?php echo esc_attr( $skin_select_id ); ?>"
217 data-wpbc-u-save-callback="wpbc_bfb_time_picker_skin_control_saved"
218 data-wpbc-u-autosave-on-form-save="1"
219 data-wpbc-u-busy-text="<?php esc_attr_e( 'Saving', 'booking' ); ?>...">
220 <?php esc_html_e( 'Save Style', 'booking' ); ?>
221 </a>
222 </div>
223 <?php
224 }
225