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

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