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 / core / lib / wpbc-calendar-legend.php

wpbc-calendar-legend.php in Booking Calendar 11.9, at core/lib/wpbc-calendar-legend.php

381 lines 20.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 // FixIn: 9.4.3.6.
8
9
10 /**
11 * Get html content of " Calendar Legend Items " , based on General Settings configuration.
12 *
13 * @return string HTML content of legend items
14 */
15 function wpbc_get_calendar_legend( $resource_id = 0 ) {
16
17 $calendar_legend_html = '';
18
19 if ( get_bk_option( 'booking_is_show_legend' ) == 'On' ) {
20
21 $items_sort = array();
22
23 if ( 'On' == get_bk_option( 'booking_legend_is_show_item_available' ) ) { $items_sort[] = 'available'; }
24
25 if ( 'On' == get_bk_option( 'booking_legend_is_show_item_approved' ) ) { $items_sort[] = 'approved'; }
26
27 if ( 'On' == get_bk_option( 'booking_legend_is_show_item_pending' ) ) { $items_sort[] = 'pending'; }
28
29 if ( //FixIn: 10.1.5.5 ( class_exists( 'wpdev_bk_biz_s' ) ) &&
30 ( 'On' == get_bk_option( 'booking_legend_is_show_item_partially' ) ) ) { $items_sort[] = 'partially'; }
31
32 if ( 'On' == get_bk_option( 'booking_legend_is_show_item_unavailable' ) ) { $items_sort[] = 'unavailable'; } // FixIn: 9.9.0.5.
33
34 $calendar_legend_html = wpbc_get_calendar_legend__content_html( array(
35 'is_vertical' => ( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true
36 , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' )
37 , 'items' => $items_sort
38 , 'resource_id' => absint( $resource_id )
39 ) );
40 }
41
42 return $calendar_legend_html;
43 }
44
45
46 function wpbc_get_calendar_legend__content_html( $params ) {
47
48 $defaults = array(
49 'is_vertical' => ( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true
50 , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' )
51 , 'items' => array(
52 'available'
53 , 'approved'
54 , 'pending'
55 , 'partially'
56 )
57 , 'unavailable_day_cell_tag' => 'span'
58 , 'resource_id' => 0
59 , 'titles' => array()
60 );
61 $params = wp_parse_args( $params, $defaults );
62
63 $legend_arr = array();
64
65 // Available.
66 if ( 1 ) {
67 $key = 'available';
68 $day_cell_tag = 'a';
69
70 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
71 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
72 $legend_arr[ $key ] .= '<td class="datepick-days-cell date_available wpbc_calendar_legend_day_cell_height">';
73 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
74 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
75 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
76 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
77 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
78 $legend_arr[ $key ] .= ' </div>';
79 $legend_arr[ $key ] .= '</div>';
80 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
81 $legend_arr[ $key ] .= '</div>';
82 }
83
84 // Pending.
85 if ( 1 ) {
86 $key = 'pending';
87 $day_cell_tag = 'span';
88
89 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
90 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
91 $legend_arr[ $key ] .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable full_day_booking date2approve wpbc_calendar_legend_day_cell_height">';
92 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
93 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
94 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
95 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
96 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
97 $legend_arr[ $key ] .= ' </div>';
98 $legend_arr[ $key ] .= '</div>';
99 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
100 $legend_arr[ $key ] .= '</div>';
101 }
102
103 // Approved.
104 if ( 1 ) {
105 $key = 'approved';
106 $day_cell_tag = 'span';
107
108 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
109 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
110 $legend_arr[ $key ] .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable full_day_booking date_approved wpbc_calendar_legend_day_cell_height">';
111 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
112 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
113 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
114 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
115 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
116 $legend_arr[ $key ] .= ' </div>';
117 $legend_arr[ $key ] .= '</div>';
118 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
119 $legend_arr[ $key ] .= '</div>';
120 }
121
122
123 // Content for Partially booked item - "time slot" or "change over days".
124 if ( 1 ) {
125 $my_partially = '';
126
127 $booking_change_over_triangle = ( 'Off' !== get_bk_option( 'booking_change_over_days_triangles' ) ) ? ' wpbc_change_over_triangle' : '';
128
129
130 $my_partially .= '<span class="' . $booking_change_over_triangle . '">';
131 $my_partially .= '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
132 $my_partially .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
133 $is_change_over_legend = null;
134 if ( function_exists( 'wpbc_settings_calendar__preview_is_changeover_enabled' ) ) {
135 $is_change_over_legend = wpbc_settings_calendar__preview_is_changeover_enabled( $params['resource_id'], false );
136 }
137 if ( null === $is_change_over_legend ) {
138 $is_change_over_legend = ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) && ( wpbc_is_booking_used_check_in_out_time( false, $params['resource_id'] ) ); // FixIn: 8.9.4.10.
139 }
140 if ( $is_change_over_legend ) {
141 $my_partially .= '<td class="datepick-days-cell date_available date_approved timespartly check_in_time check_out_time check_in_time_date_approved check_out_time_date2approve wpbc_calendar_legend_day_cell_height">';
142 } else {
143 $my_partially .= '<td class="datepick-days-cell date_available date2approve timespartly times_clock wpbc_calendar_legend_day_cell_height">';
144 }
145 $my_partially .= '<div class="wpbc-cell-box">';
146 $my_partially .= ' <div class="wpbc-diagonal-el">';
147 $my_partially .= ' <div class="wpbc-co-out"><svg height="100%" width="100%" viewBox="0 0 100 100" preserveAspectRatio="none"><polygon points="0,0 0,99 99,0"></polygon><polygon points="0,0 0,100 49,100 49,0"></polygon></svg></div>';
148 $my_partially .= ' <div class="wpbc-co-in"><svg height="100%" width="100%" viewBox="0 0 98 98" preserveAspectRatio="none"><polygon points="0,99 99,99 99,0"></polygon><polygon points="50,98 98,98 98,0 50,0"></polygon></svg></div>';
149 $my_partially .= ' </div>';
150 $my_partially .= ' <div class="date-cell-content">';
151 $my_partially .= ' <div class="date-content-top"><div class="wpbc_time_dots">·</div></div>';
152 $my_partially .= ' <a>' . esc_html( $params['text_for_day_cell'] ) . '</a>';
153 $my_partially .= ' <div class="date-content-bottom"></div>';
154 $my_partially .= ' </div>';
155 $my_partially .= '</div>';
156 $my_partially .= '</td></tr></tbody></table>';
157 $my_partially .= '</div>';
158 $my_partially .= '</span>';
159 }
160
161 // Unavailable.
162 if ( 1 ) {
163 $my_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
164 $my_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
165 $my_unavailable .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
166 $my_unavailable .= '<div class="wpbc-cell-box">';
167 $my_unavailable .= ' <div class="date-cell-content">';
168 $my_unavailable .= ' <div class="date-content-top"></div>';
169 $my_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
170 $my_unavailable .= ' <div class="date-content-bottom"></div>';
171 $my_unavailable .= ' </div>';
172 $my_unavailable .= '</div>';
173 $my_unavailable .= '</td></tr></tbody></table>';
174 $my_unavailable .= '</div>';
175 }
176
177 // Resource Unavailable.
178 if ( 1 ) {
179 $my_resource_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
180 $my_resource_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
181 $my_resource_unavailable .= '<td class="datepick-days-cell resource_unavailable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
182 $my_resource_unavailable .= '<div class="wpbc-cell-box">';
183 $my_resource_unavailable .= ' <div class="date-cell-content">';
184 $my_resource_unavailable .= ' <div class="date-content-top"></div>';
185 $my_resource_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
186 $my_resource_unavailable .= ' <div class="date-content-bottom"></div>';
187 $my_resource_unavailable .= ' </div>';
188 $my_resource_unavailable .= '</div>';
189 $my_resource_unavailable .= '</td></tr></tbody></table>';
190 $my_resource_unavailable .= '</div>';
191 }
192
193 // Some Resources unavailable in an aggregate calendar.
194 if ( 1 ) {
195 $my_resources_partially_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
196 $my_resources_partially_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
197 $my_resources_partially_unavailable .= '<td class="datepick-days-cell date_available wpbc_resources_partially_unavailable wpbc_calendar_legend_day_cell_height">';
198 $my_resources_partially_unavailable .= '<div class="wpbc-cell-box">';
199 $my_resources_partially_unavailable .= ' <div class="date-cell-content">';
200 $my_resources_partially_unavailable .= ' <div class="date-content-top"></div>';
201 $my_resources_partially_unavailable .= ' <span>' . esc_html( $params['text_for_day_cell'] ) . '</span>';
202 $my_resources_partially_unavailable .= ' <div class="date-content-bottom"></div>';
203 $my_resources_partially_unavailable .= ' </div>';
204 $my_resources_partially_unavailable .= '</div>';
205 $my_resources_partially_unavailable .= '</td></tr></tbody></table>';
206 $my_resources_partially_unavailable .= '</div>';
207 }
208
209 // One or more Resources have bookings in an aggregate calendar.
210 if ( 1 ) {
211 $my_resources_have_bookings = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
212 $my_resources_have_bookings .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
213 $my_resources_have_bookings .= '<td class="datepick-days-cell date_available wpbc_resources_have_bookings wpbc_calendar_legend_day_cell_height">';
214 $my_resources_have_bookings .= '<div class="wpbc-cell-box">';
215 $my_resources_have_bookings .= ' <div class="date-cell-content">';
216 $my_resources_have_bookings .= ' <div class="date-content-top"></div>';
217 $my_resources_have_bookings .= ' <span>' . esc_html( $params['text_for_day_cell'] ) . '</span>';
218 $my_resources_have_bookings .= ' <div class="date-content-bottom"></div>';
219 $my_resources_have_bookings .= ' </div>';
220 $my_resources_have_bookings .= '</div>';
221 $my_resources_have_bookings .= '</td></tr></tbody></table>';
222 $my_resources_have_bookings .= '</div>';
223 }
224
225
226
227 $items_arr = array( 'available' => array(
228 'title' => ( ! empty( $params['titles']['available'] ) ) ? $params['titles']['available'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_available' ) )
229 , 'text_for_day_cell' => $legend_arr['available'] // '<a>' . $params['text_for_day_cell'] . '</a>'.
230 , 'css_class' => '' // 'block_free datepick-days-cell'
231 )
232 , 'approved' => array(
233 'title' => ( ! empty( $params['titles']['approved'] ) ) ? $params['titles']['approved'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_approved' ) )
234 , 'text_for_day_cell' => $legend_arr['approved'] // $params['text_for_day_cell'].
235 , 'css_class' => '' //'block_booked date_approved'
236 )
237 , 'pending' => array(
238 'title' => ( ! empty( $params['titles']['pending'] ) ) ? $params['titles']['pending'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_pending' ) )
239 , 'text_for_day_cell' => $legend_arr['pending'] // $params['text_for_day_cell'].
240 , 'css_class' => '' //'block_pending date2approve'
241 )
242 , 'partially' => array(
243 'title' => ( ! empty( $params['titles']['partially'] ) )
244 ? $params['titles']['partially']
245 : (
246 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) ) )
247 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) )
248 : __( 'Partially booked', 'booking' )
249 )
250 , 'text_for_day_cell' => $my_partially
251 , 'css_class' => ''
252 )
253 , 'unavailable' => array( // FixIn: 9.9.0.5.
254 'title' => ( ! empty( $params['titles']['unavailable'] ) )
255 ? $params['titles']['unavailable']
256 : (
257 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) ) )
258 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) )
259 : __( 'Unavailable', 'booking' )
260 )
261 , 'text_for_day_cell' => $my_unavailable
262 , 'css_class' => '' //'datepick-days-cell datepick-unselectable date_user_unavailable'
263 )
264 , 'resource_unavailable' => array(
265 'title' => ( ! empty( $params['titles']['resource_unavailable'] ) ) ? $params['titles']['resource_unavailable'] : __( 'Resource unavailable days', 'booking' )
266 , 'text_for_day_cell' => $my_resource_unavailable
267 , 'css_class' => '' //'datepick-days-cell resource_unavailable date_user_unavailable'
268 )
269 , 'resources_partially_unavailable' => array(
270 'title' => ( ! empty( $params['titles']['resources_partially_unavailable'] ) ) ? $params['titles']['resources_partially_unavailable'] : __( 'Some booking items unavailable', 'booking' )
271 , 'text_for_day_cell' => $my_resources_partially_unavailable
272 , 'css_class' => ''
273 )
274 , 'resources_have_bookings' => array(
275 'title' => ( ! empty( $params['titles']['resources_have_bookings'] ) ) ? $params['titles']['resources_have_bookings'] : __( 'Bookings exist for one or more booking items', 'booking' )
276 , 'text_for_day_cell' => $my_resources_have_bookings
277 , 'css_class' => ''
278 )
279 );
280
281 $calendar_legend_html = '<div class="block_hints datepick ' . ( ( $params['is_vertical'] ) ? ' block_hints_vertical ' : '' ) . '">';
282
283 foreach ( $params['items'] as $item_name ) {
284
285 if ( ! empty( $items_arr[ $item_name ] ) ) {
286 $calendar_legend_html .= '<div class="wpdev_hint_with_text">'
287 . '<div class="' . $items_arr[ $item_name ]['css_class'] . '">' . $items_arr[ $item_name ]['text_for_day_cell'] . '</div>'
288 . '<div class="block_text">' . '- ' . '</div>'
289 . '<div class="block_text">' . esc_html( $items_arr[ $item_name ]['title'] ) . '</div>'
290 . '</div>';
291 }
292 }
293
294 $calendar_legend_html .= '</div>';
295
296 return $calendar_legend_html;
297 }
298
299 /**
300 * Replace [calendar_legend] shortcode to HTML content in booking form from Booking > Settings > Form page
301 *
302 * @param string $return_form - HTML content of booking form Example: '[calendar] <div class="standard-form"><div class="form-hints-dev"><p>Dates: <span class="dates-hints-dev">[selected_short_dates_hint]</span>([days_number_hint]...'
303 * @param int $resource_id - ID of booking resource Example: '4'
304 * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard'
305 *
306 * @return array|string|string[]
307 *
308 * Example of shortcode parameters:
309 * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"]
310 * [legend_items is_vertical="1"]
311 * [legend_items]
312 * [legend_items items="resource_unavailable,resources_partially_unavailable,resources_have_bookings,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"]
313 *
314 * PHP code example with escaping single and double quotes:
315 * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items'
316 . ' items="unavailable,available,pending,approved,partially"'
317 . ' titles="'
318 .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}'
319 .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
320 .'"'
321 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
322 . ' unavailable_day_cell_tag="a"'
323 .']' );
324 */
325 function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) {
326
327 // $legend__content_html = wpbc_get_calendar_legend();
328 //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form);
329
330 $pos = 0;
331
332 while ( false !== strpos( $return_form, '[legend_items ' ) ) {
333
334 $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos );
335
336 if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) {
337 $shortcode_params['text_for_day_cell'] = gmdate( 'd' );
338 }
339
340 $shortcode_titles_params = array();
341 if ( ! empty( $shortcode_params['titles'] ) ){
342 $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' );
343
344 foreach ( $shortcode_titles_params as $title_name => $title_val ) {
345 $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val );
346 }
347 }
348
349
350 $calendar_legend_html = wpbc_get_calendar_legend__content_html( array(
351 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false
352 , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) )
353 ? $shortcode_params['text_for_day_cell']
354 : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' ) )
355 , 'items' => ( ! empty( $shortcode_params['items'] ) )
356 ? explode( ',',$shortcode_params['items'] )
357 : array(
358 'available'
359 , 'approved'
360 , 'pending'
361 , 'partially'
362
363 )
364 , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) )
365 ? $shortcode_params['unavailable_day_cell_tag']
366 : 'span'
367 , 'resource_id' => absint( $resource_id )
368 , 'titles' => $shortcode_titles_params
369 ) );
370
371 $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) )
372 . $calendar_legend_html
373 . substr( $return_form, ( $shortcode_params['end'] + 1 ) );
374
375 $pos = $shortcode_params['end'];
376 }
377
378 return $return_form;
379 }
380 add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );
381