PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.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 10.15.6, at core/lib/wpbc-calendar-legend.php

329 lines 17.4 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() {
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 ) );
39 }
40
41 return $calendar_legend_html;
42 }
43
44
45 function wpbc_get_calendar_legend__content_html( $params ) {
46
47 $defaults = array(
48 'is_vertical' => ( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true
49 , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' )
50 , 'items' => array(
51 'available'
52 , 'approved'
53 , 'pending'
54 , 'partially'
55 )
56 , 'unavailable_day_cell_tag' => 'span'
57 , 'titles' => array()
58 );
59 $params = wp_parse_args( $params, $defaults );
60
61 $legend_arr = array();
62
63 // Available.
64 if ( 1 ) {
65 $key = 'available';
66 $day_cell_tag = 'a';
67
68 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
69 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
70 $legend_arr[ $key ] .= '<td class="datepick-days-cell date_available wpbc_calendar_legend_day_cell_height">';
71 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
72 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
73 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
74 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
75 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
76 $legend_arr[ $key ] .= ' </div>';
77 $legend_arr[ $key ] .= '</div>';
78 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
79 $legend_arr[ $key ] .= '</div>';
80 }
81
82 // Pending.
83 if ( 1 ) {
84 $key = 'pending';
85 $day_cell_tag = 'span';
86
87 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
88 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
89 $legend_arr[ $key ] .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable full_day_booking date2approve wpbc_calendar_legend_day_cell_height">';
90 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
91 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
92 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
93 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
94 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
95 $legend_arr[ $key ] .= ' </div>';
96 $legend_arr[ $key ] .= '</div>';
97 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
98 $legend_arr[ $key ] .= '</div>';
99 }
100
101 // Approved.
102 if ( 1 ) {
103 $key = 'approved';
104 $day_cell_tag = 'span';
105
106 $legend_arr[ $key ] = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">';
107 $legend_arr[ $key ] .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
108 $legend_arr[ $key ] .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable full_day_booking date_approved wpbc_calendar_legend_day_cell_height">';
109 $legend_arr[ $key ] .= '<div class="wpbc-cell-box">';
110 $legend_arr[ $key ] .= ' <div class="date-cell-content">';
111 $legend_arr[ $key ] .= ' <div class="date-content-top"></div>';
112 $legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $day_cell_tag . '>';
113 $legend_arr[ $key ] .= ' <div class="date-content-bottom"></div>';
114 $legend_arr[ $key ] .= ' </div>';
115 $legend_arr[ $key ] .= '</div>';
116 $legend_arr[ $key ] .= '</td></tr></tbody></table>';
117 $legend_arr[ $key ] .= '</div>';
118 }
119
120
121 // Content for Partially booked item - "time slot" or "change over days".
122 if ( 1 ) {
123 $my_partially = '';
124
125 $booking_timeslot_day_bg_as_available = ( 'On' === get_bk_option( 'booking_timeslot_day_bg_as_available' ) ) ? ' wpbc_timeslot_day_bg_as_available' : '';
126 $booking_timeslot_day_bg_as_available .= ( 'Off' !== get_bk_option( 'booking_change_over_days_triangles' ) ) ? ' wpbc_change_over_triangle' : '';
127
128
129 $my_partially .= '<span class="' . $booking_timeslot_day_bg_as_available . '">';
130 $my_partially .= '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
131 $my_partially .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
132 if ( ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) && ( wpbc_is_booking_used_check_in_out_time() ) ) { // FixIn: 8.9.4.10.
133 $my_partially .= '<td class="datepick-days-cell date_available date_approved timespartly check_in_time check_in_time_date_approved wpbc_calendar_legend_day_cell_height">';
134 } else {
135 $my_partially .= '<td class="datepick-days-cell date_available date2approve timespartly times_clock wpbc_calendar_legend_day_cell_height">';
136 }
137 $my_partially .= '<div class="wpbc-cell-box">';
138 $my_partially .= ' <div class="wpbc-diagonal-el">';
139 $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>';
140 $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>';
141 $my_partially .= ' </div>';
142 $my_partially .= ' <div class="date-cell-content">';
143 $my_partially .= ' <div class="date-content-top"><div class="wpbc_time_dots">·</div></div>';
144 $my_partially .= ' <a>' . esc_html( $params['text_for_day_cell'] ) . '</a>';
145 $my_partially .= ' <div class="date-content-bottom"></div>';
146 $my_partially .= ' </div>';
147 $my_partially .= '</div>';
148 $my_partially .= '</td></tr></tbody></table>';
149 $my_partially .= '</div>';
150 $my_partially .= '</span>';
151 }
152
153 // Unavailable.
154 if ( 1 ) {
155 $my_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
156 $my_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
157 $my_unavailable .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
158 $my_unavailable .= '<div class="wpbc-cell-box">';
159 $my_unavailable .= ' <div class="date-cell-content">';
160 $my_unavailable .= ' <div class="date-content-top"></div>';
161 $my_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
162 $my_unavailable .= ' <div class="date-content-bottom"></div>';
163 $my_unavailable .= ' </div>';
164 $my_unavailable .= '</div>';
165 $my_unavailable .= '</td></tr></tbody></table>';
166 $my_unavailable .= '</div>';
167 }
168
169 // Resource Unavailable.
170 if ( 1 ) {
171 $my_resource_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
172 $my_resource_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
173 $my_resource_unavailable .= '<td class="datepick-days-cell resource_unavailable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
174 $my_resource_unavailable .= '<div class="wpbc-cell-box">';
175 $my_resource_unavailable .= ' <div class="date-cell-content">';
176 $my_resource_unavailable .= ' <div class="date-content-top"></div>';
177 $my_resource_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
178 $my_resource_unavailable .= ' <div class="date-content-bottom"></div>';
179 $my_resource_unavailable .= ' </div>';
180 $my_resource_unavailable .= '</div>';
181 $my_resource_unavailable .= '</td></tr></tbody></table>';
182 $my_resource_unavailable .= '</div>';
183 }
184
185
186
187 $items_arr = array( 'available' => array(
188 'title' => ( ! empty( $params['titles']['available'] ) ) ? $params['titles']['available'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_available' ) )
189 , 'text_for_day_cell' => $legend_arr['available'] // '<a>' . $params['text_for_day_cell'] . '</a>'.
190 , 'css_class' => '' // 'block_free datepick-days-cell'
191 )
192 , 'approved' => array(
193 'title' => ( ! empty( $params['titles']['approved'] ) ) ? $params['titles']['approved'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_approved' ) )
194 , 'text_for_day_cell' => $legend_arr['approved'] // $params['text_for_day_cell'].
195 , 'css_class' => '' //'block_booked date_approved'
196 )
197 , 'pending' => array(
198 'title' => ( ! empty( $params['titles']['pending'] ) ) ? $params['titles']['pending'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_pending' ) )
199 , 'text_for_day_cell' => $legend_arr['pending'] // $params['text_for_day_cell'].
200 , 'css_class' => '' //'block_pending date2approve'
201 )
202 , 'partially' => array(
203 'title' => ( ! empty( $params['titles']['partially'] ) )
204 ? $params['titles']['partially']
205 : (
206 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) ) )
207 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) )
208 : __( 'Partially booked', 'booking' )
209 )
210 , 'text_for_day_cell' => $my_partially
211 , 'css_class' => ''
212 )
213 , 'unavailable' => array( // FixIn: 9.9.0.5.
214 'title' => ( ! empty( $params['titles']['unavailable'] ) )
215 ? $params['titles']['unavailable']
216 : (
217 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) ) )
218 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) )
219 : __( 'Unavailable', 'booking' )
220 )
221 , 'text_for_day_cell' => $my_unavailable
222 , 'css_class' => '' //'datepick-days-cell datepick-unselectable date_user_unavailable'
223 )
224 , 'resource_unavailable' => array(
225 'title' => ( ! empty( $params['titles']['resource_unavailable'] ) ) ? $params['titles']['resource_unavailable'] : __( 'Resource unavailable days', 'booking' )
226 , 'text_for_day_cell' => $my_resource_unavailable
227 , 'css_class' => '' //'datepick-days-cell resource_unavailable date_user_unavailable'
228 )
229 );
230
231 $calendar_legend_html = '<div class="block_hints datepick ' . ( ( $params['is_vertical'] ) ? ' block_hints_vertical ' : '' ) . '">';
232
233 foreach ( $params['items'] as $item_name ) {
234
235 if ( ! empty( $items_arr[ $item_name ] ) ) {
236 $calendar_legend_html .= '<div class="wpdev_hint_with_text">'
237 . '<div class="' . $items_arr[ $item_name ]['css_class'] . '">' . $items_arr[ $item_name ]['text_for_day_cell'] . '</div>'
238 . '<div class="block_text">' . '- ' . '</div>'
239 . '<div class="block_text">' . esc_html( $items_arr[ $item_name ]['title'] ) . '</div>'
240 . '</div>';
241 }
242 }
243
244 $calendar_legend_html .= '</div>';
245
246 return $calendar_legend_html;
247 }
248
249 /**
250 * Replace [calendar_legend] shortcode to HTML content in booking form from Booking > Settings > Form page
251 *
252 * @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]...'
253 * @param int $resource_id - ID of booking resource Example: '4'
254 * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard'
255 *
256 * @return array|string|string[]
257 *
258 * Example of shortcode parameters:
259 * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"]
260 * [legend_items is_vertical="1"]
261 * [legend_items]
262 * [legend_items items="resource_unavailable,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"]
263 *
264 * PHP code example with escaping single and double quotes:
265 * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items'
266 . ' items="unavailable,available,pending,approved,partially"'
267 . ' titles="'
268 .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}'
269 .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
270 .'"'
271 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
272 . ' unavailable_day_cell_tag="a"'
273 .']' );
274 */
275 function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) {
276
277 // $legend__content_html = wpbc_get_calendar_legend();
278 //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form);
279
280 $pos = 0;
281
282 while ( false !== strpos( $return_form, '[legend_items ' ) ) {
283
284 $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos );
285
286 if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) {
287 $shortcode_params['text_for_day_cell'] = gmdate( 'd' );
288 }
289
290 $shortcode_titles_params = array();
291 if ( ! empty( $shortcode_params['titles'] ) ){
292 $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' );
293
294 foreach ( $shortcode_titles_params as $title_name => $title_val ) {
295 $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val );
296 }
297 }
298
299
300 $calendar_legend_html = wpbc_get_calendar_legend__content_html( array(
301 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false
302 , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) )
303 ? $shortcode_params['text_for_day_cell']
304 : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' ) )
305 , 'items' => ( ! empty( $shortcode_params['items'] ) )
306 ? explode( ',',$shortcode_params['items'] )
307 : array(
308 'available'
309 , 'approved'
310 , 'pending'
311 , 'partially'
312
313 )
314 , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) )
315 ? $shortcode_params['unavailable_day_cell_tag']
316 : 'span'
317 , 'titles' => $shortcode_titles_params
318 ) );
319
320 $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) )
321 . $calendar_legend_html
322 . substr( $return_form, ( $shortcode_params['end'] + 1 ) );
323
324 $pos = $shortcode_params['end'];
325 }
326
327 return $return_form;
328 }
329 add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );