PluginProbe
Booking Calendar / 11.0
Booking Calendar v11.0
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.0, at core/lib/wpbc-calendar-legend.php

333 lines 17.6 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_timeslot_day_bg_as_available = ( 'On' === get_bk_option( 'booking_timeslot_day_bg_as_available' ) ) ? ' wpbc_timeslot_day_bg_as_available' : '';
128 $booking_timeslot_day_bg_as_available .= ( 'Off' !== get_bk_option( 'booking_change_over_days_triangles' ) ) ? ' wpbc_change_over_triangle' : '';
129
130
131 $my_partially .= '<span class="' . $booking_timeslot_day_bg_as_available . '">';
132 $my_partially .= '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
133 $my_partially .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
134 if ( ( 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.
135 $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">';
136 } else {
137 $my_partially .= '<td class="datepick-days-cell date_available date2approve timespartly times_clock wpbc_calendar_legend_day_cell_height">';
138 }
139 $my_partially .= '<div class="wpbc-cell-box">';
140 $my_partially .= ' <div class="wpbc-diagonal-el">';
141 $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>';
142 $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>';
143 $my_partially .= ' </div>';
144 $my_partially .= ' <div class="date-cell-content">';
145 $my_partially .= ' <div class="date-content-top"><div class="wpbc_time_dots">·</div></div>';
146 $my_partially .= ' <a>' . esc_html( $params['text_for_day_cell'] ) . '</a>';
147 $my_partially .= ' <div class="date-content-bottom"></div>';
148 $my_partially .= ' </div>';
149 $my_partially .= '</div>';
150 $my_partially .= '</td></tr></tbody></table>';
151 $my_partially .= '</div>';
152 $my_partially .= '</span>';
153 }
154
155 // Unavailable.
156 if ( 1 ) {
157 $my_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
158 $my_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
159 $my_unavailable .= '<td class="datepick-days-cell datepick-unselectable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
160 $my_unavailable .= '<div class="wpbc-cell-box">';
161 $my_unavailable .= ' <div class="date-cell-content">';
162 $my_unavailable .= ' <div class="date-content-top"></div>';
163 $my_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
164 $my_unavailable .= ' <div class="date-content-bottom"></div>';
165 $my_unavailable .= ' </div>';
166 $my_unavailable .= '</div>';
167 $my_unavailable .= '</td></tr></tbody></table>';
168 $my_unavailable .= '</div>';
169 }
170
171 // Resource Unavailable.
172 if ( 1 ) {
173 $my_resource_unavailable = '<div class="datepick-inline wpbc_calendar_legend_table_width_height">'; // FixIn: 9.3.1.4.
174 $my_resource_unavailable .= '<table class="datepick wpbc_calendar" style=""><tbody><tr>';
175 $my_resource_unavailable .= '<td class="datepick-days-cell resource_unavailable date_user_unavailable wpbc_calendar_legend_day_cell_height">';
176 $my_resource_unavailable .= '<div class="wpbc-cell-box">';
177 $my_resource_unavailable .= ' <div class="date-cell-content">';
178 $my_resource_unavailable .= ' <div class="date-content-top"></div>';
179 $my_resource_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '</' . $params['unavailable_day_cell_tag'] . '>';
180 $my_resource_unavailable .= ' <div class="date-content-bottom"></div>';
181 $my_resource_unavailable .= ' </div>';
182 $my_resource_unavailable .= '</div>';
183 $my_resource_unavailable .= '</td></tr></tbody></table>';
184 $my_resource_unavailable .= '</div>';
185 }
186
187
188
189 $items_arr = array( 'available' => array(
190 'title' => ( ! empty( $params['titles']['available'] ) ) ? $params['titles']['available'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_available' ) )
191 , 'text_for_day_cell' => $legend_arr['available'] // '<a>' . $params['text_for_day_cell'] . '</a>'.
192 , 'css_class' => '' // 'block_free datepick-days-cell'
193 )
194 , 'approved' => array(
195 'title' => ( ! empty( $params['titles']['approved'] ) ) ? $params['titles']['approved'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_approved' ) )
196 , 'text_for_day_cell' => $legend_arr['approved'] // $params['text_for_day_cell'].
197 , 'css_class' => '' //'block_booked date_approved'
198 )
199 , 'pending' => array(
200 'title' => ( ! empty( $params['titles']['pending'] ) ) ? $params['titles']['pending'] : wpbc_lang( get_bk_option( 'booking_legend_text_for_item_pending' ) )
201 , 'text_for_day_cell' => $legend_arr['pending'] // $params['text_for_day_cell'].
202 , 'css_class' => '' //'block_pending date2approve'
203 )
204 , 'partially' => array(
205 'title' => ( ! empty( $params['titles']['partially'] ) )
206 ? $params['titles']['partially']
207 : (
208 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) ) ) )
209 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_partially' ) )
210 : __( 'Partially booked', 'booking' )
211 )
212 , 'text_for_day_cell' => $my_partially
213 , 'css_class' => ''
214 )
215 , 'unavailable' => array( // FixIn: 9.9.0.5.
216 'title' => ( ! empty( $params['titles']['unavailable'] ) )
217 ? $params['titles']['unavailable']
218 : (
219 ( ! empty ( wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) ) ) )
220 ? wpbc_lang( get_bk_option( 'booking_legend_text_for_item_unavailable' ) )
221 : __( 'Unavailable', 'booking' )
222 )
223 , 'text_for_day_cell' => $my_unavailable
224 , 'css_class' => '' //'datepick-days-cell datepick-unselectable date_user_unavailable'
225 )
226 , 'resource_unavailable' => array(
227 'title' => ( ! empty( $params['titles']['resource_unavailable'] ) ) ? $params['titles']['resource_unavailable'] : __( 'Resource unavailable days', 'booking' )
228 , 'text_for_day_cell' => $my_resource_unavailable
229 , 'css_class' => '' //'datepick-days-cell resource_unavailable date_user_unavailable'
230 )
231 );
232
233 $calendar_legend_html = '<div class="block_hints datepick ' . ( ( $params['is_vertical'] ) ? ' block_hints_vertical ' : '' ) . '">';
234
235 foreach ( $params['items'] as $item_name ) {
236
237 if ( ! empty( $items_arr[ $item_name ] ) ) {
238 $calendar_legend_html .= '<div class="wpdev_hint_with_text">'
239 . '<div class="' . $items_arr[ $item_name ]['css_class'] . '">' . $items_arr[ $item_name ]['text_for_day_cell'] . '</div>'
240 . '<div class="block_text">' . '- ' . '</div>'
241 . '<div class="block_text">' . esc_html( $items_arr[ $item_name ]['title'] ) . '</div>'
242 . '</div>';
243 }
244 }
245
246 $calendar_legend_html .= '</div>';
247
248 return $calendar_legend_html;
249 }
250
251 /**
252 * Replace [calendar_legend] shortcode to HTML content in booking form from Booking > Settings > Form page
253 *
254 * @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]...'
255 * @param int $resource_id - ID of booking resource Example: '4'
256 * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard'
257 *
258 * @return array|string|string[]
259 *
260 * Example of shortcode parameters:
261 * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"]
262 * [legend_items is_vertical="1"]
263 * [legend_items]
264 * [legend_items items="resource_unavailable,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"]
265 *
266 * PHP code example with escaping single and double quotes:
267 * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items'
268 . ' items="unavailable,available,pending,approved,partially"'
269 . ' titles="'
270 .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}'
271 .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
272 .'"'
273 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
274 . ' unavailable_day_cell_tag="a"'
275 .']' );
276 */
277 function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) {
278
279 // $legend__content_html = wpbc_get_calendar_legend();
280 //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form);
281
282 $pos = 0;
283
284 while ( false !== strpos( $return_form, '[legend_items ' ) ) {
285
286 $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos );
287
288 if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) {
289 $shortcode_params['text_for_day_cell'] = gmdate( 'd' );
290 }
291
292 $shortcode_titles_params = array();
293 if ( ! empty( $shortcode_params['titles'] ) ){
294 $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' );
295
296 foreach ( $shortcode_titles_params as $title_name => $title_val ) {
297 $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val );
298 }
299 }
300
301
302 $calendar_legend_html = wpbc_get_calendar_legend__content_html( array(
303 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false
304 , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) )
305 ? $shortcode_params['text_for_day_cell']
306 : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? '&nbsp;' : gmdate( 'd' ) )
307 , 'items' => ( ! empty( $shortcode_params['items'] ) )
308 ? explode( ',',$shortcode_params['items'] )
309 : array(
310 'available'
311 , 'approved'
312 , 'pending'
313 , 'partially'
314
315 )
316 , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) )
317 ? $shortcode_params['unavailable_day_cell_tag']
318 : 'span'
319 , 'resource_id' => absint( $resource_id )
320 , 'titles' => $shortcode_titles_params
321 ) );
322
323 $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) )
324 . $calendar_legend_html
325 . substr( $return_form, ( $shortcode_params['end'] + 1 ) );
326
327 $pos = $shortcode_params['end'];
328 }
329
330 return $return_form;
331 }
332 add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );
333