PluginProbe
Booking Calendar / 11.6
Booking Calendar v11.6
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 10.11 10.11.2 All 203 releases
booking / core / lib / wpbc-calendar-legend.php

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

339 lines 17.8 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
194
195 $items_arr = array( 'available' => array(
196 'title' => ( ! empty( $params['titles']['available'] ) ) ? $params['titles']['available'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_available' ) )
197 , 'text_for_day_cell' => $legend_arr['available'] // '<a>' . $params['text_for_day_cell'] . '</a>'.
198 , 'css_class' => '' // 'block_free datepick-days-cell'
199 )
200 , 'approved' => array(
201 'title' => ( ! empty( $params['titles']['approved'] ) ) ? $params['titles']['approved'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_approved' ) )
202 , 'text_for_day_cell' => $legend_arr['approved'] // $params['text_for_day_cell'].
203 , 'css_class' => '' //'block_booked date_approved'
204 )
205 , 'pending' => array(
206 'title' => ( ! empty( $params['titles']['pending'] ) ) ? $params['titles']['pending'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_pending' ) )
207 , 'text_for_day_cell' => $legend_arr['pending'] // $params['text_for_day_cell'].
208 , 'css_class' => '' //'block_pending date2approve'
209 )
210 , 'partially' => array(
211 'title' => ( ! empty( $params['titles']['partially'] ) )
212 ? $params['titles']['partially']
213 : (
214 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) ) )
215 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) )
216 : __( 'Partially booked', 'booking' )
217 )
218 , 'text_for_day_cell' => $my_partially
219 , 'css_class' => ''
220 )
221 , 'unavailable' => array( // FixIn: 9.9.0.5.
222 'title' => ( ! empty( $params['titles']['unavailable'] ) )
223 ? $params['titles']['unavailable']
224 : (
225 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) ) )
226 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) )
227 : __( 'Unavailable', 'booking' )
228 )
229 , 'text_for_day_cell' => $my_unavailable
230 , 'css_class' => '' //'datepick-days-cell datepick-unselectable date_user_unavailable'
231 )
232 , 'resource_unavailable' => array(
233 'title' => ( ! empty( $params['titles']['resource_unavailable'] ) ) ? $params['titles']['resource_unavailable'] : __( 'Resource unavailable days', 'booking' )
234 , 'text_for_day_cell' => $my_resource_unavailable
235 , 'css_class' => '' //'datepick-days-cell resource_unavailable date_user_unavailable'
236 )
237 );
238
239 $calendar_legend_html = '<div class="block_hints datepick ' . ( ( $params['is_vertical'] ) ? ' block_hints_vertical ' : '' ) . '">';
240
241 foreach ( $params['items'] as $item_name ) {
242
243 if ( ! empty( $items_arr[ $item_name ] ) ) {
244 $calendar_legend_html .= '<div class="wpdev_hint_with_text">'
245 . '<div class="' . $items_arr[ $item_name ]['css_class'] . '">' . $items_arr[ $item_name ]['text_for_day_cell'] . '</div>'
246 . '<div class="block_text">' . '- ' . '</div>'
247 . '<div class="block_text">' . esc_html( $items_arr[ $item_name ]['title'] ) . '</div>'
248 . '</div>';
249 }
250 }
251
252 $calendar_legend_html .= '</div>';
253
254 return $calendar_legend_html;
255 }
256
257 /**
258 * Replace [calendar_legend] shortcode to HTML content in booking form from Booking > Settings > Form page
259 *
260 * @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]...'
261 * @param int $resource_id - ID of booking resource Example: '4'
262 * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard'
263 *
264 * @return array|string|string[]
265 *
266 * Example of shortcode parameters:
267 * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"]
268 * [legend_items is_vertical="1"]
269 * [legend_items]
270 * [legend_items items="resource_unavailable,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"]
271 *
272 * PHP code example with escaping single and double quotes:
273 * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items'
274 . ' items="unavailable,available,pending,approved,partially"'
275 . ' titles="'
276 .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}'
277 .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
278 .'"'
279 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
280 . ' unavailable_day_cell_tag="a"'
281 .']' );
282 */
283 function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) {
284
285 // $legend__content_html = wpbc_get_calendar_legend();
286 //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form);
287
288 $pos = 0;
289
290 while ( false !== strpos( $return_form, '[legend_items ' ) ) {
291
292 $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos );
293
294 if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) {
295 $shortcode_params['text_for_day_cell'] = gmdate( 'd' );
296 }
297
298 $shortcode_titles_params = array();
299 if ( ! empty( $shortcode_params['titles'] ) ){
300 $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' );
301
302 foreach ( $shortcode_titles_params as $title_name => $title_val ) {
303 $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val );
304 }
305 }
306
307
308 $calendar_legend_html = wpbc_get_calendar_legend__content_html( array(
309 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false
310 , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) )
311 ? $shortcode_params['text_for_day_cell']
312 : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' ) )
313 , 'items' => ( ! empty( $shortcode_params['items'] ) )
314 ? explode( ',',$shortcode_params['items'] )
315 : array(
316 'available'
317 , 'approved'
318 , 'pending'
319 , 'partially'
320
321 )
322 , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) )
323 ? $shortcode_params['unavailable_day_cell_tag']
324 : 'span'
325 , 'resource_id' => absint( $resource_id )
326 , 'titles' => $shortcode_titles_params
327 ) );
328
329 $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) )
330 . $calendar_legend_html
331 . substr( $return_form, ( $shortcode_params['end'] + 1 ) );
332
333 $pos = $shortcode_params['end'];
334 }
335
336 return $return_form;
337 }
338 add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );
339