PluginProbe
Booking Calendar / 11.5
Booking Calendar v11.5
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 10.11.3 10.11.4 10.12.0 10.12.1 All 199 releases
booking / core / wpbc_functions.php

wpbc_functions.php in Booking Calendar 11.5, at core/wpbc_functions.php

1,801 lines 65.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Support Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 29.09.2015
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 /**
18 * Get Logo for conversation.
19 *
20 * @param string $svg_color - main color.
21 * @param string $svg_color_alt - alt color.
22 *
23 * @return void
24 */
25 function wpbc_get_svg_logo( $svg_color = '#000', $svg_color_alt = '#fff', $opacity = '0.1' ) {
26
27 // $svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="150 150 850 850">'
28 // . '<path style="fill:' . $svg_color . '" d="M224.3 117.81c0-7.62 6.18-13.8 13.8-13.8h104.13c7.62 0 13.8 6.18 13.8 13.8v239.06c-58.48 32.03-105.14 82.96-131.74 144.58V117.81z"/>'
29 // . '<path style="fill:' . $svg_color . ';" d="M224.3 620.3c0-152.27 123.43-275.7 275.7-275.7 69.48 0 132.95 25.7 181.43 68.11l-93.55 93.55c-24.31-18.76-54.79-29.92-87.88-29.92-79.51 0-143.96 64.45-143.96 143.96S420.49 764.26 500 764.26c33.09 0 63.57-11.16 87.88-29.92l93.55 93.55C632.95 870.3 569.48 896 500 896c-152.27 0-275.7-123.44-275.7-275.7z"/>'
30 // . '<path style="fill:' . $svg_color_alt . '" fill-opacity="' . $opacity . '" d="m681.43 827.89-93.55-93.55c34.11-26.33 56.08-67.62 56.08-114.04s-21.97-87.71-56.08-114.04l93.55-93.55c57.78 50.54 94.27 124.8 94.27 207.59s-36.49 157.05-94.27 207.59z"/>'
31 // . '</svg>';
32 //
33 //
34 // $svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" version="1.1" viewBox="0 0 600 600">
35 // <path id="O_Letter" d="M298.22 197.55c-92.32 0-167.15 77.82-167.15 173.81s74.84 173.82 167.15 173.82 167.15-77.82 167.15-173.82-74.84-173.81-167.15-173.81Zm0 264.53c-50.1 0-90.71-40.61-90.71-90.71s40.61-90.71 90.71-90.71 90.71 40.61 90.71 90.71-40.61 90.71-90.71 90.71Z" style="fill:' . $svg_color_alt . ';" fill-opacity="' . $opacity . '" />
36 // <path id="C_Letter" d="M363.75 434.1c-14.85 15.51-35.16 25.76-57.84 27.66-54.87 4.6-101.64-41.14-98.23-96.1 2.94-47.44 42.35-85.01 90.54-85.01 24.84 0 47.34 9.98 63.72 26.16 5.86 5.78 15.29 5.73 21.11-.09l35.14-35.14c5.69-5.69 5.9-14.87.43-20.77-30.41-32.83-73.1-53.26-120.4-53.26-92.32 0-167.15 77.82-167.15 173.81s74.84 173.82 167.15 173.82c48.49 0 92.15-21.47 122.68-55.76 5.29-5.94 5.02-14.97-.6-20.59l-35.05-35.05c-5.98-5.98-15.67-5.79-21.51.32Z" style="fill:' . $svg_color . ';"/>
37 // <path d="M130.69 357.28v2.59c0 .27.06.53.17.76a123.1 123.1 0 0 1-.17-3.35Zm4.51-50.82c12.34-39.07 38.32-70.02 77.79-97.04.92-.63 1.48-1.67 1.48-2.79V59.95c0-4.28-3.68-7.76-8.22-7.76h-3.76c-18.56 0-73.17 40.3-71.79 60.62l-.17 192.91c0 2.74 3.86 3.34 4.68.73Z" style="fill:' . $svg_color . ';"/>
38 // </svg>';
39 //
40 // $svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 600">
41 // <path d="M311.92 214.22c-92.32 0-167.15 77.82-167.15 173.81s74.84 173.82 167.15 173.82 167.15-77.82 167.15-173.82-74.84-173.81-167.15-173.81Zm0 264.53c-50.1 0-90.71-40.61-90.71-90.71s40.61-90.71 90.71-90.71 90.71 40.61 90.71 90.71-40.61 90.71-90.71 90.71Z" style="fill:' . $svg_color_alt . ';" fill-opacity="' . $opacity . '" />
42 // <path d="M377.45 450.77c-14.85 15.51-35.16 25.76-57.84 27.66-54.87 4.6-101.64-41.14-98.23-96.1 2.94-47.44 42.35-85.01 90.54-85.01 24.84 0 47.34 9.98 63.72 26.16 5.86 5.78 15.29 5.73 21.11-.09l35.14-35.14c5.69-5.69 5.9-14.87.43-20.77-30.41-32.83-73.1-53.26-120.4-53.26-92.32 0-167.15 77.82-167.15 173.81s74.84 173.82 167.15 173.82c48.49 0 92.15-21.47 122.68-55.76 5.29-5.94 5.02-14.97-.6-20.59l-35.05-35.05c-5.98-5.98-15.67-5.79-21.51.32Z" style="fill:' . $svg_color . ';"/>
43 // <path d="M149.45 318.12c12.34-39.07 38.32-70.02 77.79-97.04.92-.63 1.48-1.67 1.48-2.79V71.62c0-4.28-3.68-7.76-8.22-7.76h-3.76c-18.56 0-73.17 40.3-71.79 60.62l-.17 192.91c0 2.74 3.86 3.34 4.68.73Z" style="fill:' . $svg_color . ';"/>
44 // </svg>';
45 //
46 // $svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 550 550">
47 // <path d="M275 176.36c-92.32 0-167.15 77.82-167.15 173.81S182.69 523.99 275 523.99s167.15-77.82 167.15-173.82S367.31 176.36 275 176.36Zm0 264.53c-50.1 0-90.71-40.61-90.71-90.71s40.61-90.71 90.71-90.71 90.71 40.61 90.71 90.71-40.61 90.71-90.71 90.71Z" style="fill:#ffd25b"/>
48 // <path d="M340.53 412.91c-14.85 15.51-35.16 25.76-57.84 27.66-54.87 4.6-101.64-41.14-98.23-96.1 2.94-47.44 42.35-85.01 90.54-85.01 24.84 0 47.34 9.98 63.72 26.16 5.86 5.78 15.29 5.73 21.11-.09l35.14-35.14c5.69-5.69 5.9-14.87.43-20.77-30.41-32.83-73.1-53.26-120.4-53.26-92.32 0-167.15 77.82-167.15 173.81S182.69 523.99 275 523.99c48.49 0 92.15-21.47 122.68-55.76 5.29-5.94 5.02-14.97-.6-20.59l-35.05-35.05c-5.98-5.98-15.67-5.79-21.51.32Z" style="fill:#193db2"/>
49 // <path d="M112.53 280.27c12.34-39.07 38.32-70.02 77.79-97.04.92-.63 1.48-1.67 1.48-2.79V33.76c0-4.28-3.68-7.76-8.22-7.76h-3.76c-18.56 0-73.17 40.3-71.79 60.62l-.17 192.91c0 2.74 3.86 3.34 4.68.73Z" style="fill:#451fff"/>
50 // </svg>';
51
52 // FixIn: 10.11.3.3.
53 $svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 550 550">'
54 . '<path d="M275 162.36c-92.32 0-167.15 77.82-167.15 173.81S182.69 509.99 275 509.99s167.15-77.82 167.15-173.82S367.31 162.36 275 162.36Zm0 264.53c-50.1 0-90.71-40.61-90.71-90.71s40.61-90.71 90.71-90.71 90.71 40.61 90.71 90.71-40.61 90.71-90.71 90.71Z" style="fill:' . $svg_color_alt . ';" fill-opacity="' . $opacity . '" />'
55 . '<path d="M340.53 398.91c-14.85 15.51-35.16 25.76-57.84 27.66-54.87 4.6-101.64-41.14-98.23-96.1 2.94-47.44 42.35-85.01 90.54-85.01 24.84 0 47.34 9.98 63.72 26.16 5.86 5.78 15.29 5.73 21.11-.09l35.14-35.14c5.69-5.69 5.9-14.87.43-20.77-30.41-32.83-73.1-53.26-120.4-53.26-92.32 0-167.15 77.82-167.15 173.81S182.69 509.99 275 509.99c48.49 0 92.15-21.47 122.68-55.76 5.29-5.94 5.02-14.97-.6-20.59l-35.05-35.05c-5.98-5.98-15.67-5.79-21.51.32Z" style="fill:' . $svg_color . ';"/>'
56 . '<path d="M112.53 261.27c12.34-39.07 38.32-70.02 77.79-97.04.92-.63 1.48-1.67 1.48-2.79V14.76c0-4.28-3.68-7.76-8.22-7.76h-3.76c-18.56 0-73.17 40.3-71.79 60.62l-.17 192.91c0 2.74 3.86 3.34 4.68.73Z" style="fill:' . $svg_color . ';"/>'
57 . '</svg>';
58
59
60 return $svg_icon_integarted;
61 }
62
63
64 /**
65 * Get Logo for Background Image.
66 *
67 * @param string $svg_color - main color.
68 * @param string $svg_color_alt - alt color.
69 *
70 * @return void
71 */
72 function wpbc_get_svg_logo_for_background( $svg_color = '#000', $svg_color_alt = '#fff', $opacity = '0.2' ) {
73
74 $svg_icon_integarted = wpbc_get_svg_logo( $svg_color, $svg_color_alt, $opacity );
75
76 $svg_icon_integarted = sprintf( 'data:image/svg+xml;base64,%s', base64_encode( $svg_icon_integarted ) );
77
78 return $svg_icon_integarted;
79 }
80
81 /**
82 * Get Logo as HTML element.
83 *
84 * @param array $params - logo parameters.
85 *
86 * @return string
87 */
88 function wpbc_get_svg_logo_for_html( $params = array() ) {
89
90 // FixIn: 10.12.1.6.
91 $defaults = array(
92 'svg_color' => '#ccc',
93 'svg_color_alt' => '#aaa',
94 'opacity' => '0.4',
95 'style_default' => 'background-repeat: no-repeat; background-position: center; display: inline-block; vertical-align: top;',
96 'style_adjust' => 'background-size: 18px auto; width: 20px; height: 20px; margin-top: 6px;', // This parameters, the adjust size of the logo and position.
97 'css_class' => '',
98 );
99
100 $params = wp_parse_args( $params, $defaults );
101
102 $svg_logo_for_background = wpbc_get_svg_logo_for_background( $params['svg_color'], $params['svg_color_alt'], $params['opacity'] );
103
104 $svg_icon_integarted = '<i';
105 $svg_icon_integarted .= ' class="wpbc_svg_logo ' . esc_attr( $params['css_class'] ) . '"';
106 $svg_icon_integarted .= ' style="' . esc_attr( $params['style_default'] ) . esc_attr( $params['style_adjust'] );
107 $svg_icon_integarted .= 'background-image: url(\'' . esc_attr( $svg_logo_for_background ) . '\') !important;"';
108 $svg_icon_integarted .= '></i>';
109
110 return $svg_icon_integarted;
111 }
112
113 // <editor-fold defaultstate="collapsed" desc=" == Get html preview of shortcode for Edit pages == " >
114
115 /**
116 * Get html preview of shortcode for Edit pages in Elementor and at Block editors
117 *
118 * @param $shortcode_type
119 * @param $attr
120 *
121 * @return string
122 */
123 function wpbc_get_preview_for_shortcode( $shortcode_type, $attr ) {
124
125 // FixIn: 9.9.0.39.
126
127 return '<div style="border:2px dashed #ccc;text-align: center; padding:10px;display:flex;flex-flow:column wrap;justify-content: center;align-content: center;">
128 <div>WP Booking Calendar Shortcode</div>
129 <code>['.$shortcode_type.' ...]</code>
130 <div style="font-size:0.8em;">This is not a real preview. Publish the page to see it in action.</div>
131 </div>';
132 }
133 // </editor-fold>
134
135
136 // <editor-fold defaultstate="collapsed" desc=" == Calendar functions == " >
137
138 /**
139 * Get maximum visible days in calendar
140 *
141 * @return int
142 */
143 function wpbc_get_max_visible_days_in_calendar(){
144
145 // Number of months to scroll
146 $max_visible_days_in_calendar = get_bk_option( 'booking_max_monthes_in_calendar');
147
148 if ( false !== strpos( $max_visible_days_in_calendar, 'm' ) ) {
149 //$max_visible_days_in_calendar = intval( str_replace( 'm', '', $max_visible_days_in_calendar ) ) * 31 ; // FixIn: 9.6.1.1.
150 // FixIn: 10.0.0.26.
151 $diff_days = strtotime( '+' . intval( str_replace( 'm', '', $max_visible_days_in_calendar ) ) . ' months', strtotime( 'now' ) ) - strtotime( 'now' );
152 $max_visible_days_in_calendar = round( $diff_days / ( 60 * 60 * 24 ) ) + 1;
153 } else {
154 $max_visible_days_in_calendar = intval( str_replace( 'y', '', $max_visible_days_in_calendar ) ) * 365 + 15; // FixIn: 9.6.1.1.
155 }
156
157 return $max_visible_days_in_calendar;
158 }
159
160
161 /**
162 * Parse {calendar ....} option parameter in Calendar | Booking form shortcode
163 *
164 * @param $bk_options
165 *
166 * @return array|false
167 */
168 function wpbc_parse_calendar_options( $bk_options ) {
169
170 if ( empty( $bk_options ) ) {
171 return false;
172 }
173 /* $matches structure:
174 * Array
175 (
176 [0] => Array
177 (
178 [0] => {calendar months="6" months_num_in_row="2" width="341px" cell_height="48px"},
179 [1] => calendar
180 [2] => months="6" months_num_in_row="2" width="341px" cell_height="48px"
181 )
182
183 [1] => Array
184 (
185 [0] => {select-day condition="weekday" for="5" value="3"},
186 [1] => select-day
187 [2] => condition="weekday" for="5" value="3"
188 )
189 .....
190 )
191 */
192
193 $pattern_to_search='%\s*{([^\s]+)\s*([^}]+)\s*}\s*[,]?\s*%';
194
195 preg_match_all( $pattern_to_search, $bk_options, $matches, PREG_SET_ORDER );
196
197 foreach ( $matches as $value ) {
198 if ( $value[1] == 'calendar' ) {
199 $paramas = $value[2];
200 $paramas = trim( $paramas );
201 $paramas = explode( ' ', $paramas );
202 $options = array();
203 foreach ( $paramas as $vv ) {
204 if ( ! empty( $vv ) ) {
205 $vv = trim( $vv );
206 $vv = explode( '=', $vv );
207 if ( ( isset( $vv[0] ) ) && ( isset( $vv[1] ) ) ) {
208 $options[ $vv[0] ] = trim( $vv[1] );
209 }
210 }
211 }
212 if ( count( $options ) == 0 ) {
213 return false;
214 } else {
215 return $options;
216 }
217 }
218 }
219
220 return false; // We are not have the "calendar" options in the shortcode
221 }
222
223
224
225 /**
226 * Parse {calendar ....} option parameter in Calendar | Booking form shortcode
227 *
228 * @param $bk_options
229 *
230 * @return array|false
231 */
232 function wpbc_parse_calendar_options__aggregate_param( $bk_options ) { // FixIn: 9.8.15.10.
233
234 if ( empty( $bk_options ) ) {
235 return false;
236 }
237 /* $matches structure:
238 $matches = [
239 0 = [
240 0 = "{aggregate type=bookings_only}"
241 1 = "aggregate"
242 2 = "type=bookings_only"
243 ]
244 ]
245 */
246
247 $pattern_to_search='%\s*{([^\s]+)\s*([^}]+)\s*}\s*[,]?\s*%';
248
249 preg_match_all( $pattern_to_search, $bk_options, $matches, PREG_SET_ORDER );
250
251 foreach ( $matches as $value ) {
252 if ( $value[1] == 'aggregate' ) {
253 $paramas = $value[2];
254 $paramas = trim( $paramas );
255 $paramas = explode( ' ', $paramas );
256 $options = array();
257 foreach ( $paramas as $vv ) {
258 if ( ! empty( $vv ) ) {
259 $vv = trim( $vv );
260 $vv = explode( '=', $vv );
261 if ( ( isset( $vv[0] ) ) && ( isset( $vv[1] ) ) ) {
262 $options[ $vv[0] ] = trim( $vv[1] );
263 }
264 }
265 }
266 if ( count( $options ) == 0 ) {
267 return false;
268 } else {
269 return $options;
270 }
271 }
272 }
273
274 return false; // We are not have the "calendar" options in the shortcode
275 }
276
277
278 function wpbc_is_calendar_skin_legacy( $skin_name ){
279 $legacy_skins = array(
280 'black.css',
281 'multidays.css',
282 'premium-black.css',
283 'premium-light-noborder.css',
284 'premium-light.css',
285 'premium-marine.css',
286 'premium-steel-noborder.css',
287 'premium-steel.css',
288 'standard.css',
289 'traditional-light.css',
290 'traditional.css'
291 // FixIn: 10.7.1.5.
292 , 'traditional-times.css'
293 , 'black-2.css'
294 , 'green-01.css'
295 , 'light-01.css'
296 );
297
298 return in_array( $skin_name, $legacy_skins );
299 }
300
301
302 /**
303 * Get Legacy calendar skin
304 *
305 * @param $skin_name = 'Black-2'
306 * @param $skin_arr = ["24_9__dark_1.css", "/css/skins/blac...", "Black-2"]
307 *
308 * @return mixed
309 */
310 function wpbc_get_legacy_calendar_skin_name($skin_name, $skin_arr){
311
312 if (wpbc_is_calendar_skin_legacy($skin_arr[0]) ){
313 return __( 'Legacy', 'booking' ) . ': ' . $skin_name;
314 } else {
315 return $skin_name;
316 }
317 }
318
319 /**
320 * Get Calendar skin options for selectboxes
321 * @return void
322 */
323 function wpbc_get_calendar_skin_options( $url_prefix = '' ){
324 // Calendar Skin /////////////////////////////////////////////////////
325 $calendar_skins_options = array();
326 $legacy_calendar_skins_options = array();
327 // Skins in the Custom User folder (need to create it manually): http://example.com/wp-content/uploads/wpbc_skins/ ( This folder do not owerwrited during update of plugin )
328 $upload_dir = wp_upload_dir();
329 // FixIn: 8.9.4.8.
330 $files_in_folder = wpbc_dir_list( array( WPBC_PLUGIN_DIR . '/css/skins/' ) ); // Folders where to look about calendar skins
331 foreach ( $files_in_folder as $skin_file ) { // Example: $skin_file['/css/skins/standard.css'] => 'Standard';
332
333 //FixIn: 8.9.4.8 // FixIn: 9.1.2.10.
334 $skin_file[1] = str_replace( array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL , $upload_dir['basedir'] ), '', $skin_file[1] ); // Get relative path for calendar skin
335
336 if ( ! wpbc_is_calendar_skin_legacy( $skin_file[0] ) ) {
337 $calendar_skins_options[ $skin_file[1] ] = $skin_file[2];
338 } else {
339 $legacy_calendar_skins_options[ $skin_file[1] ] = wpbc_get_legacy_calendar_skin_name( $skin_file[2], $skin_file );
340 }
341 }
342
343 $calendar_skins_options_real = array();
344 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => false, 'title' => '&nbsp;' . __('Calendar Skins' ,'booking') );
345 foreach ( $calendar_skins_options as $s_key => $s_val ) {
346 $calendar_skins_options_real [ $url_prefix . $s_key ] = $s_val;
347 }
348 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => true );
349 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => false, 'title' => '&nbsp;' . __('Legacy Calendar Skins' ,'booking') );
350 foreach ( $legacy_calendar_skins_options as $s_key => $s_val ) {
351 $calendar_skins_options_real [ $url_prefix . $s_key ] = array( 'title' => $s_val, 'attr' => array( 'style' => 'color:#ccc;' ) );
352 }
353 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => true );
354 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => false, 'title' => '&nbsp;' . __('Custom Calendar Skins' ,'booking') );
355 $files_in_folder = wpbc_dir_list( array( $upload_dir['basedir'].'/wpbc_skins/' ) ); // Folders where to look about calendar skins
356 foreach ( $files_in_folder as $skin_file ) { // Example: $skin_file['/css/skins/standard.css'] => 'Standard';
357
358 //FixIn: 8.9.4.8 // FixIn: 9.1.2.10.
359 $skin_file[1] = str_replace( array( WPBC_PLUGIN_DIR, WPBC_PLUGIN_URL , $upload_dir['basedir'] ), '', $skin_file[1] ); // Get relative path for calendar skin
360
361 $calendar_skins_options_real[ $url_prefix . $skin_file[1] ] = $skin_file[2];
362
363 }
364
365 $calendar_skins_options_real[] = array( 'optgroup' => true, 'close' => true );
366
367 return $calendar_skins_options_real;
368 }
369
370
371 function wpbc_get_calendar_skin_options_with_legacy_sections(){
372
373 // FixIn: 10.3.0.5.
374 // Calendar Skin /////////////////////////////////////////////////////
375 $cal_arr = wpbc_get_calendar_skin_options( WPBC_PLUGIN_URL );
376
377 $upload_dir = wp_upload_dir(); // Check if this skin exist in the Custom User folder at the http://example.com/wp-content/uploads/wpbc_skins/
378 $custom_user_skin_folder = $upload_dir['basedir'];
379 $custom_user_skin_url = $upload_dir['baseurl'];
380
381 $transformed_cal_arr = array();
382 foreach ( $cal_arr as $calendar_skin_url => $calendar_name ) {
383 if ( false !== strpos( $calendar_skin_url, WPBC_PLUGIN_URL ) ) {
384
385 $relative_cal_skin_path = str_replace( WPBC_PLUGIN_URL, '', $calendar_skin_url );
386
387 if ( file_exists( $custom_user_skin_folder . $relative_cal_skin_path ) ) {
388 // Custom Skin
389 $transformed_cal_arr[ $custom_user_skin_url . $relative_cal_skin_path ] = $calendar_name;
390 } else {
391 // Plugin Usual Skins
392 $transformed_cal_arr[ WPBC_PLUGIN_URL . $relative_cal_skin_path ] = $calendar_name;
393 }
394 } else {
395 // OptGroups
396 $transformed_cal_arr[ $calendar_skin_url ] = $calendar_name;
397 }
398 }
399
400 return $transformed_cal_arr;
401 }
402 // </editor-fold>
403
404
405 // <editor-fold defaultstate="collapsed" desc=" == Files functions == " >
406
407 // Get array of images - icons inside of this directory
408 function wpbc_dir_list ($directories) {
409
410 // create an array to hold directory list
411 $results = array();
412
413 if (is_string($directories)) $directories = array($directories);
414 foreach ($directories as $dir) {
415 if ( is_dir( $dir ) ) {
416 $directory = $dir;
417 } else {
418 $directory = WPBC_PLUGIN_DIR . $dir;
419 }
420
421 if ( file_exists( $directory ) ) { //FixIn: 5.4.5
422 // create a handler for the directory
423 $handler = @opendir($directory);
424 if ($handler !== false) {
425 // keep going until all files in directory have been read
426 while ($file = readdir($handler)) {
427
428 // if $file isn't this directory or its parent,
429 // add it to the results array
430 if ($file != '.' && $file != '..' && ( strpos($file, '.css' ) !== false ) )
431 $results[] = array($file, /* WPBC_PLUGIN_URL .*/ $dir . $file, ucfirst(strtolower( str_replace('.css', '', $file))) );
432 }
433
434 // tidy up: close the handler
435 closedir($handler);
436 }
437 }
438 }
439 // done!
440 return $results;
441 }
442
443
444 /**
445 * Check if such file exist or not.
446 *
447 * @param string $path - relative path to file (relative to plugin folder).
448 * @return boolean true | false
449 */
450 function wpbc_is_file_exist( $path ) {
451
452 if ( file_exists( trailingslashit( WPBC_PLUGIN_DIR ) . ltrim( $path, '/\\' ) ) ) // check if this file exist
453 return true;
454 else
455 return false;
456 }
457
458
459 /**
460 * Count the number of bytes of a given string.
461 * Input string is expected to be ASCII or UTF-8 encoded.
462 * Warning: the function doesn't return the number of chars
463 * in the string, but the number of bytes.
464 * See http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
465 * for information on UTF-8.
466 *
467 * @param string $str The string to compute number of bytes
468 *
469 * @return The length in bytes of the given string.
470 */
471 function wpbc_get_bytes_from_str( $str ) {
472 // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
473 // Number of characters in string
474 $strlen_var = strlen( $str );
475
476 $d = 0; // string bytes counter
477
478 // Iterate over every character in the string, escaping with a slash or encoding to UTF-8 where necessary
479 for ( $c = 0; $c < $strlen_var; ++ $c ) {
480 $ord_var_c = ord( $str[$c] ); // FixIn: 2.0.17.1.
481 switch ( true ) {
482 case(($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): // characters U-00000000 - U-0000007F (same as ASCII)
483 $d ++;
484 break;
485 case(($ord_var_c & 0xE0) == 0xC0): // characters U-00000080 - U-000007FF, mask 110XXXXX
486 $d += 2;
487 break;
488 case(($ord_var_c & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX
489 $d += 3;
490 break;
491 case(($ord_var_c & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX
492 $d += 4;
493 break;
494 case(($ord_var_c & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX
495 $d += 5;
496 break;
497 case(($ord_var_c & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X
498 $d += 6;
499 break;
500 default:
501 $d ++;
502 }
503 }
504 return $d;
505 }
506
507
508 // </editor-fold>
509
510
511 // <editor-fold defaultstate="collapsed" desc=" == Can I Load JavaScript Files == " >
512
513 function wpbc_can_i_load_on__edit_new_post_page() {
514
515 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
516 return false;
517 }
518
519
520 $pages_where_load = array( 'post-new.php', 'page-new.php', 'post.php', 'page.php', 'widgets.php', 'customize.php' );
521 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
522 if ( ( in_array( basename( $_SERVER['PHP_SELF'] ), $pages_where_load ) )
523 || ( wpbc_is_setup_wizard_page() )
524 ) {
525 return true;
526 }
527
528 return false;
529 }
530
531
532 function wpbc_can_i_load_on__searchable_resources_page() {
533
534 if (
535 ( isset( $_REQUEST['page'] ) ) && ( $_REQUEST['page'] === 'wpbc-resources' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
536 && ( isset( $_REQUEST['tab'] ) ) && ( $_REQUEST['tab'] === 'searchable_resources' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
537 ) {
538 return true;
539 }
540
541 return false;
542 }
543
544
545 function wpbc_can_i_load_on__resources_page() {
546
547 if (
548 ( isset( $_REQUEST['page'] ) ) && ( $_REQUEST['page'] === 'wpbc-resources' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
549 ) {
550 return true;
551 }
552
553 return false;
554 }
555
556
557 /**
558 * Can I load scripts on this page for 'shortcode_config'
559 *
560 * @return bool
561 */
562 function wpbc_can_i_load_on_this_page__shortcode_config() {
563
564 if (
565 wpbc_can_i_load_on__edit_new_post_page()
566 || (
567 wpbc_can_i_load_on__resources_page()
568 && ( ! wpbc_can_i_load_on__searchable_resources_page() )
569 )
570 || wpbc_is_setup_wizard_page()
571 || wpbc_is_builder_booking_form_page()
572 // || wpbc_is_bookings_page() // FixIn: 10.6.6.2.
573 ){
574 return true;
575 } else {
576 return false;
577 }
578 }
579
580 /**
581 * Can I load scripts on this page? Loaded only at ../admin.php?page=wpbc-resources&tab=searchable_resources
582 *
583 * @return bool
584 */
585 function wpbc_can_i_load_on_this_page__modal_search_options() {
586
587 if ( wpbc_can_i_load_on__searchable_resources_page() ){
588 return true;
589 } else {
590 return false;
591 }
592 }
593
594 // </editor-fold>
595
596
597 // <editor-fold defaultstate="collapsed" desc=" == Footer == " >
598
599 function wpbc_show_booking_footer(){
600
601 $wpdev_copyright_adminpanel = get_bk_option( 'booking_wpdev_copyright_adminpanel' ); // check
602
603 $message = '';
604
605
606
607 if ( ( 'Off' !== $wpdev_copyright_adminpanel ) && ( ! wpbc_is_this_demo() ) ) {
608
609
610 /* translators: 1: ... */
611 $message .= sprintf( __( 'If you like %1$s please leave us a %2$s rating. A huge thank you in advance!', 'booking' )
612 , '<strong>Booking Calendar</strong> ' . esc_attr( WP_BK_VERSION_NUM )
613 , '<a href="https://wordpress.org/support/plugin/booking/reviews/#new-post" target="_blank" title="' . esc_attr__( 'Thanks :)', 'booking' ) . '">'
614 . '&#9733;&#9733;&#9733;&#9733;&#9733;'
615 . '</a>'
616 );
617 }
618
619
620 if ( ! empty( $message ) ) {
621
622 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
623 echo '<div id="wpbc-footer" style="position:absolute;bottom:40px;text-align:left;width:95%;font-size:0.9em;text-shadow:0 1px 0 #fff;margin:0;color:#888;">' . $message . '</div>';
624
625 ?>
626 <script type="text/javascript">
627 jQuery(document).ready(function () {
628 jQuery('#wpfooter').append(jQuery('#wpbc-footer'));
629 });
630 </script>
631 <?php
632 }
633 }
634
635 // </editor-fold>
636
637
638 // <editor-fold defaultstate="collapsed" desc=" == P a g i n a t i o n o f T a b l e L i s t i n g == " >
639
640 /**
641 * Show P a g i n a t i o n
642 *
643 * @param int $summ_number_of_items - total number of items
644 * @param int $active_page_num - number of activated page
645 * @param int $num_items_per_page - number of items per page
646 * @param array $only_these_parameters - array of keys to exclude from links
647 * @param string $url_sufix - usefule for anchor to HTML section with specific ID, Example: '#my_section'
648 */
649 function wpbc_show_pagination( $summ_number_of_items, $active_page_num, $num_items_per_page , $only_these_parameters = false, $url_sufix = '' ) {
650
651 if ( empty( $num_items_per_page ) ) {
652 $num_items_per_page = '10';
653 }
654
655 $pages_number = ceil( $summ_number_of_items / $num_items_per_page );
656 if ( $pages_number < 2 )
657 return;
658
659 //Fix: 5.1.4 - Just in case we are having tooo much resources, then we need to show all resources - and its empty string
660 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
661 if ( ( isset( $_REQUEST['wh_booking_type'] ) ) && ( strlen( wp_unslash( $_REQUEST['wh_booking_type'] ) ) > 1000 ) ) {
662 $_REQUEST['wh_booking_type'] = '';
663 }
664
665 // First parameter will overwriten by $_GET['page'] parameter
666 $bk_admin_url = wpbc_get_params_in_url( wpbc_get_bookings_url( false, false ), array('page_num'), $only_these_parameters );
667
668
669 ?>
670 <span class="wpdevelop wpbc-pagination">
671 <div class="container-fluid">
672 <div class="row">
673 <div class="col-sm-12 text-center control-group0">
674 <nav class="btn-toolbar">
675 <div class="btn-group wpbc-no-margin" style="float:none;">
676
677 <?php
678 if ( $pages_number > 1 ) { ?>
679 <a class="button button-secondary <?php
680 echo ( $active_page_num == 1 ) ? ' disabled' : ''; ?>"
681 href="<?php
682 echo esc_url( $bk_admin_url ); ?>&page_num=<?php
683 if ( $active_page_num == 1 ) {
684 echo esc_attr( $active_page_num );
685 } else {
686 echo esc_attr( $active_page_num - 1 );
687 }
688 echo esc_attr( $url_sufix );
689 ?>">
690 <?php
691 esc_html_e( 'Prev', 'booking' ); ?>
692 </a>
693 <?php
694 }
695
696 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
697 $num_closed_steps = 3;
698
699 for ( $pg_num = 1; $pg_num <= $pages_number; $pg_num++ ) {
700
701 if ( ! (
702 ( $pages_number > ( $num_closed_steps * 4) )
703 && ( $pg_num > $num_closed_steps )
704 && ( ( $pages_number - $pg_num + 1 ) > $num_closed_steps )
705 && ( abs( $active_page_num - $pg_num ) > $num_closed_steps )
706 ) ) {
707 ?> <a class="button button-secondary <?php if ($pg_num == $active_page_num ) echo ' active'; ?>"
708 href="<?php echo esc_url( $bk_admin_url ); ?>&page_num=<?php echo esc_attr( $pg_num );
709 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
710 echo $url_sufix; ?>">
711 <?php echo wp_kses_post( $pg_num ); ?>
712 </a><?php
713
714 if ( ( $pages_number > ( $num_closed_steps * 4) )
715 && ( ($pg_num+1) > $num_closed_steps )
716 && ( ( $pages_number - ( $pg_num + 1 ) ) > $num_closed_steps )
717 && ( abs($active_page_num - ( $pg_num + 1 ) ) > $num_closed_steps )
718 ) {
719 echo ' <a class="button button-secondary disabled" href="javascript:void(0);">...</a> ';
720 }
721 }
722 }
723
724 if ( $pages_number > 1 ) { ?>
725 <a class="button button-secondary <?php
726 echo ( $active_page_num == $pages_number ) ? ' disabled' : ''; ?>"
727 href="<?php
728 echo esc_url( $bk_admin_url ); ?>&page_num=<?php
729 if ( $active_page_num == $pages_number ) {
730 echo esc_attr( $active_page_num );
731 } else {
732 echo esc_attr( $active_page_num + 1 );
733 }
734 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
735 echo $url_sufix; ?>">
736 <?php
737 esc_html_e( 'Next', 'booking' ); ?>
738 </a>
739 <?php
740 }
741 ?>
742
743 </div>
744 </nav>
745 </div>
746 </div>
747 </div>
748 </span>
749 <?php
750 }
751
752 // </editor-fold>
753
754
755 // <editor-fold defaultstate="collapsed" desc=" == Number of New Bookings == " >
756
757 /**
758 * Reset Cache for getting Number of new bookings. After this operation, system will get number of new bookings from the DB.
759 *
760 * @return void
761 */
762 function wpbc_booking_cache__new_bookings__reset(){
763 update_bk_option( 'booking_cache__new_bookings__saved_date', '' );
764 }
765 add_action( 'wpbc_track_new_booking', 'wpbc_booking_cache__new_bookings__reset' );
766 add_action( 'wpbc_set_booking_pending', 'wpbc_booking_cache__new_bookings__reset' );
767 add_action( 'wpbc_set_booking_approved', 'wpbc_booking_cache__new_bookings__reset' );
768 add_action( 'wpbc_move_booking_to_trash', 'wpbc_booking_cache__new_bookings__reset' );
769 add_action( 'wpbc_restore_booking_from_trash', 'wpbc_booking_cache__new_bookings__reset' );
770 add_action( 'wpbc_delete_booking_completely', 'wpbc_booking_cache__new_bookings__reset' );
771 add_action( 'wpbc_set_booking_as_read', 'wpbc_booking_cache__new_bookings__reset' );
772 add_action( 'wpbc_set_booking_as_unread', 'wpbc_booking_cache__new_bookings__reset' );
773
774
775 /**
776 * Get number of new bookings
777 * @return false|int|mixed|null
778 */
779 function wpbc_db_get_number_new_bookings() {
780
781 $new_bookings__number = get_bk_option( 'booking_cache__new_bookings__number' );
782 $new_bookings__saved_date = get_bk_option( 'booking_cache__new_bookings__saved_date' );
783
784 $nowdate_str_ymdhis = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
785
786 if ( ! empty( $new_bookings__saved_date ) ) {
787
788 $is_expired = ( strtotime( $new_bookings__saved_date ) <= strtotime( '-10 minutes', strtotime( $nowdate_str_ymdhis ) ) );
789
790 if ( ! $is_expired ) {
791 return $new_bookings__number;
792 }
793 }
794
795 global $wpdb;
796
797 $trash_bookings = ' AND bk.trash != 1 '; // FixIn: 6.1.1.10 - check also below usage of {$trash_bookings} .
798 $sql_req = "SELECT bk.booking_id FROM {$wpdb->prefix}booking as bk WHERE bk.is_new = 1 {$trash_bookings} ";
799
800 $sql_req = apply_bk_filter( 'get_sql_for_checking_new_bookings', $sql_req );
801 $sql_req = apply_bk_filter( 'get_sql_for_checking_new_bookings_multiuser', $sql_req );
802 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
803 $bookings = $wpdb->get_results( $sql_req );
804 $bookings_count = count( $bookings );
805
806 update_bk_option( 'booking_cache__new_bookings__number', $bookings_count );
807 update_bk_option( 'booking_cache__new_bookings__saved_date', $nowdate_str_ymdhis );
808
809 return $bookings_count;
810 }
811
812
813 /**
814 * Update 'is_new' status of bookings in Database
815 *
816 * @param $id_of_new_bookings inr or comma seperated ID of bookings. Example: '1' | '3,5,7,9'
817 * @param $is_new '0' | '1'
818 * @param $user_id 'user_id'
819 *
820 */
821 function wpbc_db_update_number_new_bookings( $id_of_new_bookings, $is_new = '0', $user_id = 1 ) {
822
823 global $wpdb;
824
825 if ( count( $id_of_new_bookings ) > 0 ) {
826
827 $id_of_new_bookings = implode( ',', $id_of_new_bookings );
828 $id_of_new_bookings = wpbc_clean_like_string_for_db( $id_of_new_bookings );
829
830 // FixIn: 10.12.1.5.
831 if ( 'all' === $id_of_new_bookings ) {
832 $update_sql = "UPDATE {$wpdb->prefix}booking SET is_new = {$is_new} WHERE is_new != {$is_new} "; // FixIn: 8.2.1.18.
833
834 $update_sql = apply_bk_filter( 'update_sql_for_checking_new_bookings', $update_sql, 0, $user_id );
835 } else {
836 $update_sql = "UPDATE {$wpdb->prefix}booking SET is_new = {$is_new} WHERE booking_id IN ( {$id_of_new_bookings} ) ";
837 }
838
839 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
840 if ( false === $wpdb->query( $update_sql ) ) {
841 debuge_error( 'Error during updating status of bookings at DB', __FILE__, __LINE__ );
842 die();
843 }
844 }
845 }
846
847 // </editor-fold>
848
849
850 // <editor-fold defaultstate="collapsed" desc=" == User ID | Role - functions == " >
851
852 /**
853 * Check if Current User have specific Role
854 *
855 * @return bool Whether the current user has the given capability.
856 */
857 function wpbc_is_current_user_have_this_role( $user_role ) {
858
859 if ( $user_role == 'administrator' ) $user_role = 'activate_plugins';
860 if ( $user_role == 'editor' ) $user_role = 'publish_pages';
861 if ( $user_role == 'author' ) $user_role = 'publish_posts';
862 if ( $user_role == 'contributor' ) $user_role = 'edit_posts';
863 if ( $user_role == 'subscriber') $user_role = 'read';
864
865 return current_user_can( $user_role );
866 }
867
868
869 /**
870 * Get Current ID of user or get user ID of Forced log in user in Booking Calendar MultiUser version.
871 *
872 * @return int
873 */
874 function wpbc_get_current_user_id() { // FixIn: 9.2.4.1.
875
876 if ( function_exists( 'wpbc_mu__wp_get_current_user' ) ) {
877 $user = wpbc_mu__wp_get_current_user();
878 $user_bk_id = $user->ID;
879 } else {
880 $user_bk_id = get_current_user_id();
881 }
882
883 return $user_bk_id;
884 }
885
886
887 /**
888 * Get Current User Object or get User object of Forced log in user in Booking Calendar MultiUser version.
889 *
890 * @return stdClass|WP_User|null
891 */
892 function wpbc_get_current_user() { // FixIn: 9.2.4.1.
893
894 if ( function_exists( 'wpbc_mu__wp_get_current_user' ) ) {
895 $user = wpbc_mu__wp_get_current_user();
896 } else {
897 $user = wp_get_current_user();
898 }
899
900 return $user;
901 }
902
903 // </editor-fold>
904
905
906 // <editor-fold defaultstate="collapsed" desc=" == Messages for Admin panel == " >
907
908
909 /**
910 * Show "Saved Changes" message at the top of settings page.
911 *
912 */
913 function wpbc_show_changes_saved_message() {
914 wpbc_show_message ( __('Changes saved.','booking'), 5 );
915 }
916
917
918 /**
919 * Show Message at Top of Admin Pages
920 *
921 * @param type $message - mesage to show
922 * @param type $time_to_show - number of seconds to show, if 0 or skiped, then unlimited time.
923 * @param type $message_type - Default: updated { updated | error | notice }
924 */
925 function wpbc_show_message ( $message, $time_to_show , $message_type = 'updated') {
926
927 // Generate unique HTML ID for the message
928 $inner_message_id = intval( time() * wp_rand(10, 100) );
929
930 // Get formated HTML message
931 $notice = wpbc_get_formated_message( $message, $message_type, $inner_message_id );
932
933 // Get the time of message showing
934 $time_to_show = intval( $time_to_show ) * 1000;
935
936 // Show this Message
937 ?> <script type="text/javascript">
938 if ( jQuery('.wpbc_admin_message').length ) {
939 jQuery('.wpbc_admin_message').append( '<?php
940 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
941 echo $notice; ?>' );
942 <?php if ( $time_to_show > 0 ) { ?>
943 jQuery('#wpbc_inner_message_<?php echo esc_attr( $inner_message_id ); ?>').animate({opacity: 1},<?php echo esc_attr( $time_to_show ); ?>).fadeOut( 2000 );
944 <?php } ?>
945 }
946 </script> <?php
947 }
948
949
950 /**
951 * Escape and prepare message to show it
952 *
953 * @param type $message - message
954 * @param type $message_type - Default: updated { updated | error | notice }
955 * @param string $inner_message_id - ID of message DIV, can be skipped
956 * @return string
957 */
958 function wpbc_get_formated_message ( $message, $message_type = 'updated', $inner_message_id = '') {
959
960
961 // Recheck for any "lang" shortcodes for replacing to correct language
962 $message = wpbc_lang( $message );
963
964 // Escape any JavaScript from message
965 $notice = html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
966
967 $notice .= '<a class="close tooltip_left" rel="tooltip" title="'. esc_js(__("Hide",'booking')). '" data-dismiss="alert" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">&times;</a>';
968
969 if (! empty( $inner_message_id ))
970 $inner_message_id = 'id="wpbc_inner_message_'. $inner_message_id .'"';
971
972 $notice = '<div '.$inner_message_id.' class="wpbc_inner_message '. $message_type . '">' . $notice . '</div>';
973
974 return $notice;
975 }
976
977
978 /**
979 * Show system info in settings page
980 *
981 * @param string $message ...
982 * @param string $message_type 'info' | 'warning' | 'error'
983 * @param string $title __('Important!' ,'booking') | __('Note' ,'booking')
984 *
985 * Exmaple: wpbc_show_message_in_settings( __( 'Nothing Found', 'booking' ), 'warning', __('Important!' ,'booking') );
986 */
987 function wpbc_show_message_in_settings( $message, $message_type = 'info', $title = '' , $is_echo = true ) {
988
989 $message_content = '';
990
991 $message_content .= '<div class="clear"></div>';
992
993 $message_content .= '<div class="wpbc-settings-notice notice-' . $message_type . '" style="text-align:left;">';
994
995 if ( ! empty( $title ) )
996 $message_content .= '<strong>' . esc_js( $title ) . '</strong> ';
997
998 $message_content .= html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
999
1000 $message_content .= '</div>';
1001
1002 $message_content .= '<div class="clear"></div>';
1003
1004 if ( $is_echo ) {
1005 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1006 echo $message_content;
1007 } else {
1008 return $message_content;
1009 }
1010
1011 }
1012
1013 // </editor-fold>
1014
1015
1016 // <editor-fold defaultstate="collapsed" desc=" == Meta Boxes - Open/Close == " >
1017
1018 /**
1019 * Meta box section open tag
1020 *
1021 * @param string $metabox_id HTML ID of section
1022 * @param string $title Title in section
1023 * @param array $params [
1024 'is_section_visible_after_load' => true, // Default true - is this section Visible, after page loading or hidden - useful for Booking > Settings General page LEFT column sections
1025 'is_show_minimize' => true // Default true - is show minimize button at top right section
1026 ]
1027 *
1028 * @return void
1029 */
1030 function wpbc_open_meta_box_section( $metabox_id, $title, $params = array() ) {
1031
1032 $defaults = array(
1033 'is_section_visible_after_load' => true,
1034 'is_show_minimize' => true,
1035 'dismiss_button' => '',
1036 'css_class' => 'postbox'
1037 );
1038 $params = wp_parse_args( $params, $defaults );
1039
1040 $my_close_open_win_id = $metabox_id . '_metabox';
1041
1042 ?>
1043 <div class='meta-box'>
1044 <div id="<?php echo esc_attr( $my_close_open_win_id ); ?>"
1045 class="<?php echo esc_attr( $params['css_class'] ); ?> <?php
1046 if ( $params['is_show_minimize'] ) {
1047 if ( '1' == get_user_option( 'booking_win_' . $my_close_open_win_id ) ) {
1048 echo 'closed';
1049 }
1050 }
1051 ?>"
1052 style="<?php
1053
1054 $force_visible = false;
1055
1056 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
1057 $do_expand = ( ( isset( $_REQUEST['do_expand'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['do_expand'] ) ) : '' );
1058
1059 if ( $my_close_open_win_id === $do_expand ) {
1060 $force_visible = true;
1061 }
1062
1063 if ( ( ! $params['is_section_visible_after_load'] ) && ( ! $force_visible ) ) {
1064 echo 'display:none';
1065 }
1066 ?>"
1067 ><div class="postbox-header" style="display: flex;flex-flow: row nowrap;border-bottom: 1px solid #ccd0d4;">
1068 <h3 class='hndle' style="flex: 1 1 auto;border: none;">
1069 <span><?php
1070 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1071 echo $title;
1072 ?></span>
1073 <?php
1074 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1075 echo $params['dismiss_button'];
1076 ?>
1077 </h3>
1078 <?php if ( $params['is_show_minimize'] ) { ?>
1079 <div title="<?php esc_attr_e('Click to toggle','booking'); ?>" class="handlediv"
1080 onclick="javascript:wpbc_verify_window_opening(<?php echo esc_attr( wpbc_get_current_user_id() ); ?>, '<?php echo esc_attr( $my_close_open_win_id ); ?>');"
1081 ><br/></div>
1082 <?php } ?>
1083 </div>
1084 <div class="inside">
1085 <?php
1086 }
1087
1088
1089 function wpbc_close_meta_box_section() {
1090 ?>
1091 </div>
1092 </div>
1093 </div>
1094 <?php
1095 }
1096
1097 // </editor-fold>
1098
1099
1100 // <editor-fold defaultstate="collapsed" desc=" == Inline JavaScript to Footer page == " >
1101
1102 /**
1103 * Queue JavaScript for later output at footer
1104 *
1105 * @param string $code
1106 */
1107 function wpbc_enqueue_js( $code ) {
1108 global $wpbc_queued_js;
1109
1110 if ( empty( $wpbc_queued_js ) ) {
1111 $wpbc_queued_js = '';
1112 }
1113
1114 $wpbc_queued_js .= "\n" . $code . "\n";
1115 }
1116
1117
1118 /**
1119 * Output any queued javascript code in the footer.
1120 */
1121 function wpbc_print_js() {
1122
1123 global $wpbc_queued_js;
1124
1125 if ( ! empty( $wpbc_queued_js ) ) {
1126
1127 $wpbc_queued_js = wp_check_invalid_utf8( $wpbc_queued_js );
1128
1129 $wpbc_queued_js = wp_specialchars_decode( $wpbc_queued_js, ENT_COMPAT ); // Converts double quotes '&quot;' => '"'.
1130
1131 $wpbc_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $wpbc_queued_js );
1132 $wpbc_queued_js = str_replace( "\r", '', $wpbc_queued_js );
1133
1134 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1135 echo "<!-- WPBC JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) {" . $wpbc_queued_js . "});\n</script>\n<!-- End WPBC JavaScript -->\n";
1136
1137 $wpbc_queued_js = '';
1138 unset( $wpbc_queued_js );
1139 }
1140 }
1141
1142 // </editor-fold>
1143
1144
1145 // <editor-fold defaultstate="collapsed" desc=" == Support functions for MU version == " >
1146
1147 /**
1148 * Set active User Environment in MultiUser version, depend from owner of booking resource
1149 *
1150 * @param int $previous_active_user (default=-1) - blank parameter
1151 * @param int $bktype - booking resource ID for checking
1152 * @return int - ID of Previous Active User
1153 *
1154 * Usage:
1155 $previous_active_user = apply_bk_filter('wpbc_mu_set_environment_for_owner_of_resource', -1, $bktype );
1156
1157 */
1158 function wpbc_mu_set_environment_for_owner_of_resource( $previous_active_user = -1, $bktype = 1 ) {
1159
1160 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
1161 // Get the owner of this booking resource
1162 $user_bk_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $bktype );
1163
1164 $user = wpbc_get_current_user();
1165
1166 // Get possible other active user settings
1167 $previous_active_user = apply_bk_filter( 'get_client_side_active_params_of_user' );
1168
1169 // Set active user of that specific booking resource
1170 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_bk_id );
1171 }
1172
1173 return $previous_active_user;
1174 }
1175 add_bk_filter('wpbc_mu_set_environment_for_owner_of_resource', 'wpbc_mu_set_environment_for_owner_of_resource');
1176
1177
1178 /**
1179 * Set environment for this user in MU version
1180 *
1181 * @param int $previous_active_user - ID of user
1182 * Usage:
1183 make_bk_action('wpbc_mu_set_environment_for_user', $previous_active_user );
1184
1185 */
1186 function wpbc_mu_set_environment_for_user( $previous_active_user ) {
1187
1188 if ( $previous_active_user !== -1 ) {
1189
1190 // Reactivate the previous active user
1191 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $previous_active_user );
1192 }
1193 }
1194 add_bk_action('wpbc_mu_set_environment_for_user', 'wpbc_mu_set_environment_for_user');
1195
1196
1197 /**
1198 * Check if we have simulated user login in Booking Calendar MultiUser version
1199 * return user ID of regular simulated user or 0 if not simulated
1200 * @return int
1201 */
1202 function wpbc_mu__is_simulated_login_as_user(){
1203 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
1204
1205 $real_current_user_id = get_current_user_id(); // Is current user suer booking admin and if this user was simulated log in
1206 $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $real_current_user_id );
1207 if ( $is_user_super_admin ) {
1208
1209 $simulate_user_id = intval( get_option( 'booking_simulate_login_as_user' ) ); // Is user was simulated log in
1210
1211 if ( ( ! empty( $simulate_user_id ) ) && ( $simulate_user_id > 0 ) ) {
1212 return $simulate_user_id;
1213 }
1214 }
1215 }
1216 return 0;
1217 }
1218 // </editor-fold>
1219
1220
1221 // <editor-fold defaultstate="collapsed" desc=" == Currency functions (>=BS) == " >
1222
1223 /**
1224 * Format booking cost with a currency symbol.
1225 * In MultiUser version also checking about specific currency that belong to specific WordPress user.
1226 * This checking based on belonging specific booking resource to specific user.
1227 *
1228 * @param float $cost
1229 * @param int $booking_resource_id
1230 * @return string - $cost_to_show_with_currency
1231 */
1232 function wpbc_get_cost_with_currency_for_user( $cost, $booking_resource_id = 0 ){
1233
1234 if ( ( $cost === '' ) || ( ! class_exists( 'wpdev_bk_biz_s' ) ) ) {
1235 return '';
1236 }
1237
1238 if ( ! empty( $booking_resource_id ) ) {
1239 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
1240 } // MU
1241
1242 $cost_to_show_with_currency = wpbc_cost_show( $cost, array( 'currency' => wpbc_get_currency() ) );
1243
1244 if ( ! empty( $booking_resource_id ) ) {
1245 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
1246 } // MU
1247
1248 return $cost_to_show_with_currency;
1249 }
1250
1251
1252 /**
1253 * Get currency Symbol.
1254 * In MultiUser version also checking about specific currency that belong to specific WordPress user.
1255 * This checking based on belonging specific booking resource to specific user.
1256 *
1257 * @param int $booking_resource_id - ID of specific booking resource
1258 * @return string - currency symbol
1259 */
1260 function wpbc_get_currency_symbol_for_user( $booking_resource_id = 0 ){
1261
1262 if ( ! class_exists( 'wpdev_bk_biz_s' ) ) {
1263 return '';
1264 }
1265
1266 if ( ! empty( $booking_resource_id ) ) {
1267 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
1268 } // MU
1269
1270 $currency_symbol = wpbc_get_currency_symbol();
1271
1272 if ( ! empty( $booking_resource_id ) ) {
1273 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
1274 } // MU
1275
1276 return $currency_symbol;
1277 }
1278
1279 /**
1280 * Get Cost per period: DAY / NIGHT / FIXED / HOUR
1281 * In MultiUser version This checking based on belonging specific booking resource to specific user.
1282 *
1283 * @param int $booking_resource_id - ID of specific booking resource
1284 * @return string - cost per period
1285 */
1286 function wpbc_get_cost_per_period_for_user( $booking_resource_id = 0 ){ // FixIn: 10.0.0.14.
1287
1288 if ( ! class_exists( 'wpdev_bk_biz_s' ) ) {
1289 return '';
1290 }
1291
1292 if ( ! empty( $booking_resource_id ) ) {
1293 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
1294 } // MU
1295
1296 $cost_period = get_bk_option( 'booking_paypal_price_period' );
1297
1298 if ( ! empty( $booking_resource_id ) ) {
1299 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
1300 } // MU
1301
1302 return $cost_period;
1303 }
1304 // </editor-fold>
1305
1306
1307 // <editor-fold defaultstate="collapsed" desc=" == Approve | Pending functions == " >
1308
1309 /**
1310 * Check is this booking approved -- get booking dates in DB and check status
1311 *
1312 * @param $booking_id
1313 *
1314 * @return bool
1315 */
1316 function wpbc_is_booking_approved( $booking_id ) {
1317 // FixIn: 8.1.2.8.
1318
1319 $is_booking_approved = false;
1320
1321 global $wpdb;
1322
1323 $sql = $wpdb->prepare( "SELECT DISTINCT approved FROM {$wpdb->prefix}bookingdates WHERE booking_id = %d ORDER BY booking_date", $booking_id );
1324 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
1325 $dates_result = $wpdb->get_results( $sql );
1326
1327 foreach ( $dates_result as $my_date ) {
1328
1329 if ( 1 === intval( $my_date->approved ) ) {
1330 $is_booking_approved = true; // FixIn: 8.3.1.2.
1331 }
1332 }
1333
1334 return $is_booking_approved;
1335 }
1336
1337
1338 /**
1339 * Approve booking in DB (update booking dates in DB like approved = '1')
1340 *
1341 * @param $booking_id int | CSD e.g. 100 | '1,5,10'
1342 *
1343 * @return bool
1344 */
1345 function wpbc_db__booking_approve( $booking_id ) {
1346
1347 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check parameter if it number or comma separated list of numbers.
1348
1349 global $wpdb;
1350
1351 $update_sql = "UPDATE {$wpdb->prefix}bookingdates SET approved = '1' WHERE booking_id IN ({$booking_id});";
1352
1353 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
1354 if ( false === $wpdb->query( $update_sql ) ) {
1355 return false;
1356 }
1357
1358 // In case if the booking was in Trash, then restore it.
1359 // FixIn: 10.8.1.1.
1360
1361 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
1362 if ( false === $wpdb->query( "UPDATE {$wpdb->prefix}booking SET trash = 0 WHERE booking_id IN ({$booking_id})" ) ) {
1363 return false;
1364 }
1365
1366 return true;
1367 }
1368
1369
1370 /**
1371 * Approve specific booking and send email about this.
1372 *
1373 * @param int $booking_id - ID of booking
1374 * @param string $email_reason
1375 */
1376 function wpbc_auto_approve_booking( $booking_id, $email_reason = '' ) {
1377
1378 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers.
1379
1380 if ( is_numeric( $booking_id ) ) { // FixIn: 8.1.2.8.
1381 if ( ! wpbc_is_booking_approved( $booking_id ) ) {
1382 do_action( 'wpbc_booking_approved', $booking_id, 1 ); // FixIn: 8.7.6.1.
1383
1384 wpbc_send_email_approved( $booking_id, 1, $email_reason );
1385 }
1386 } else {
1387 $booking_id_arr = explode( ',', $booking_id );
1388 foreach ( $booking_id_arr as $bk_id ) {
1389 if ( ! wpbc_is_booking_approved( $bk_id ) ) {
1390 do_action( 'wpbc_booking_approved', $bk_id, 1 ); // FixIn: 8.7.6.1.
1391 wpbc_send_email_approved( $bk_id, 1, $email_reason );
1392 }
1393 }
1394 }
1395
1396 $db_result = wpbc_db__booking_approve( $booking_id );
1397
1398 if ( false === $db_result ) {
1399
1400 wpbc_redirect( site_url() );
1401 }
1402 }
1403
1404
1405 /**
1406 * Set as Pending specific booking and send email about this.
1407 *
1408 * @param int $booking_id - ID of booking
1409 * @param string $denyreason
1410 */
1411 function wpbc_auto_pending_booking( $booking_id, $denyreason = '' ) {
1412 // FixIn: 8.4.7.25.
1413
1414 global $wpdb;
1415
1416 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers.
1417
1418 if ( is_numeric( $booking_id ) ) { // FixIn: 8.1.2.8.
1419 if ( wpbc_is_booking_approved( $booking_id ) ) {
1420 wpbc_send_email_deny( $booking_id, 1, $denyreason );
1421 }
1422 } else {
1423 $booking_id_arr = explode( ',', $booking_id );
1424 foreach ( $booking_id_arr as $bk_id ) {
1425 if ( wpbc_is_booking_approved( $bk_id ) ) {
1426 wpbc_send_email_deny( $bk_id, 1, $denyreason );
1427 }
1428 }
1429 }
1430
1431 $update_sql = "UPDATE {$wpdb->prefix}bookingdates SET approved = '0' WHERE booking_id IN ({$booking_id});";
1432 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
1433 if ( false === $wpdb->query( $update_sql ) ) {
1434
1435 wpbc_redirect( site_url() );
1436 }
1437 }
1438
1439
1440 /**
1441 * Cancel (move to Trash) specific booking.
1442 *
1443 * @param int $booking_id - ID of booking
1444 * @param string $email_reason - reason of cancellation
1445 */
1446 function wpbc_auto_cancel_booking( $booking_id, $email_reason = '' ) {
1447 // FixIn: 8.4.7.25.
1448
1449 global $wpdb;
1450
1451 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers.
1452
1453 if ( empty( $email_reason ) ) { // FixIn: 8.4.7.25.
1454 // Get the reason of cancellation.
1455 $email_reason = __( 'Payment rejected', 'booking' );
1456 $auto_cancel_pending_unpaid_bk_is_send_email = get_bk_option( 'booking_auto_cancel_pending_unpaid_bk_is_send_email' );
1457 if ( 'On' === $auto_cancel_pending_unpaid_bk_is_send_email ) {
1458 $email_reason = get_bk_option( 'booking_auto_cancel_pending_unpaid_bk_email_reason' );
1459 }
1460 }
1461 // Send decline emails.
1462 wpbc_send_email_trash( $booking_id, 1, $email_reason );
1463 // FixIn: 10.12.1.5.
1464 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
1465 if ( false === $wpdb->query( "UPDATE {$wpdb->prefix}booking SET trash = 1 WHERE booking_id IN ({$booking_id})" ) ) {
1466
1467 wpbc_redirect( site_url() );
1468 }
1469 }
1470
1471
1472 // FixIn: 9.9.0.43.
1473
1474 /**
1475 * Auto approve booking and send email, after successful payment process
1476 *
1477 * It resolves issue in Booking Calendar MultiUser version for sending "regular email" to visitors, if was made booking for booking resource, that belong to regular user,
1478 * and was activated this option "Receive all payments only to Super Booking Admin account" at the WP Booking Calendar > Settings General page in "Multiuser Options" section
1479 *
1480 * @param $booking_id
1481 *
1482 * @return void
1483 */
1484 function wpbc_auto_approve_booking__after_payment( $booking_id ) {
1485 //-------------------------------------------------------------------------------------------------- // FixIn: 9.9.0.43.
1486 $is_force_again = false;
1487 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
1488
1489 list( $booking_hash, $booking_resource_id ) = wpbc_hash__get_booking_hash__resource_id( $booking_id );
1490
1491 $user_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $booking_resource_id );
1492
1493 $is_booking_resource_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_id );
1494
1495 if (
1496 ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) )
1497 && ( ! $is_booking_resource_user_super_admin )
1498 ) {
1499 // Finish "Super-User" forcing
1500 make_bk_action( 'finish_force_using_this_user' );
1501 //Reactivate data for "regular user
1502 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_id );
1503
1504 $is_force_again = true;
1505 }
1506 }
1507 // -------------------------------------------------------------------------------------------------
1508
1509 wpbc_auto_approve_booking( $booking_id );
1510
1511 if ( $is_force_again ) { // FixIn: 9.9.0.43.
1512 make_bk_action( 'make_force_using_this_user', - 999 ); // '-999' - This ID "by default" is the ID of super booking admin user
1513 }
1514 }
1515
1516
1517 /**
1518 * Auto cancel booking and send email, after successful payment process
1519 *
1520 * It resolves issue in Booking Calendar MultiUser version for sending "regular email" to visitors, if was made booking for booking resource, that belong to regular user,
1521 * and was activated this option "Receive all payments only to Super Booking Admin account" at the WP Booking Calendar > Settings General page in "Multiuser Options" section
1522 *
1523 * @param $booking_id
1524 *
1525 * @return void
1526 */
1527 function wpbc_auto_cancel_booking__after_payment( $booking_id ) {
1528 //-------------------------------------------------------------------------------------------------- // FixIn: 9.9.0.43.
1529 $is_force_again = false;
1530 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
1531
1532 list( $booking_hash, $booking_resource_id ) = wpbc_hash__get_booking_hash__resource_id( $booking_id );
1533
1534 $user_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $booking_resource_id );
1535
1536 $is_booking_resource_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_id );
1537
1538 if (
1539 ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) )
1540 && ( ! $is_booking_resource_user_super_admin )
1541 ) {
1542 // Finish "Super-User" forcing
1543 make_bk_action( 'finish_force_using_this_user' );
1544 //Reactivate data for "regular user
1545 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_id );
1546
1547 $is_force_again = true;
1548 }
1549 }
1550 // -------------------------------------------------------------------------------------------------
1551
1552 wpbc_auto_cancel_booking( $booking_id );
1553
1554 if ( $is_force_again ) { // FixIn: 9.9.0.43.
1555 make_bk_action( 'make_force_using_this_user', - 999 ); // '-999' - This ID "by default" is the ID of super booking admin user
1556 }
1557 }
1558 // </editor-fold>
1559
1560
1561 // <editor-fold defaultstate="collapsed" desc=" == Logs for Notes / remarks == " >
1562
1563 /**
1564 * Add Log info to Notes of bookings
1565 *
1566 * @param array | int $booking_id_arr
1567 * @param string $message
1568 */
1569 function wpbc_db__add_log_info( $booking_id_arr, $message ) {
1570
1571 if ( get_bk_option( 'booking_log_booking_actions' ) !== 'On' ) {
1572 return;
1573 }
1574
1575 $booking_id_arr = (array) $booking_id_arr;
1576
1577 $is_append = true;
1578 foreach ( $booking_id_arr as $booking_id ) {
1579 $date_time = date_i18n( '[Y-m-d H:i] ' );
1580 make_bk_action('wpdev_make_update_of_remark' , $booking_id , $date_time . $message , $is_append ); // FixIn: 9.1.2.14.
1581 }
1582 }
1583
1584 // </editor-fold>
1585
1586
1587 // <editor-fold defaultstate="collapsed" desc=" == CSV export support function == " >
1588
1589 /**
1590 * Get Path from request URL. E.g. 'my-category/file.csv' from url, like https://server.com/my-category/file.csv
1591 *
1592 * It can detect internal sub folder or WordPress, like http://server.com/my-website/
1593 *
1594 * @return false|string
1595 */
1596 function wpbc_get_request_url_path(){
1597
1598 $server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
1599 $my_parsed_url = wp_parse_url( $server_request_uri );
1600
1601 if ( false === $my_parsed_url ) { // seriously malformed URLs, wp_parse_url() may return FALSE.
1602 return false;
1603 }
1604
1605 $my_parsed_url_path = trim( $my_parsed_url['path'] );
1606 $my_parsed_url_path = trim( $my_parsed_url_path, '/' );
1607
1608
1609 // Check internal sub folder of WP, like http://server.com/my-website/[ ... LINK ...] // FixIn: 2.0.5.4.
1610 if ( function_exists( 'wp_parse_url' ) ) {
1611 $wp_home_server_url = wp_parse_url( home_url() );
1612 } else {
1613 $wp_home_server_url = @wp_parse_url( home_url() );
1614 }
1615
1616 if ( ( false !== $wp_home_server_url ) && ( ! empty( $wp_home_server_url['path'] ) ) ) { // seriously malformed URLs, wp_parse_url() may return FALSE.
1617
1618 $server_url_sufix = trim( $wp_home_server_url[ 'path' ] ); // [path] => /my-website
1619 $server_url_sufix = trim( $server_url_sufix, '/' ); // my-website
1620
1621 if ( ! empty( $server_url_sufix ) ) {
1622
1623 $check_sufix = substr( $my_parsed_url_path, 0, strlen( $server_url_sufix ) );
1624
1625 if ( $check_sufix === $server_url_sufix ) {
1626
1627 $my_parsed_url_path = substr( $my_parsed_url_path, strlen( $server_url_sufix ) );
1628
1629 $my_parsed_url_path = trim( $my_parsed_url_path, '/' );
1630 }
1631 }
1632 } //End FixIn: 2.0.5.4
1633
1634 return $my_parsed_url_path;
1635 }
1636
1637 // </editor-fold>
1638
1639
1640 // <editor-fold defaultstate="collapsed" desc=" == SKIP BLANK EMAIL == " >
1641
1642
1643 /**
1644 * Check if this email is NOT blank email to SKIP email sending -- from autofill fast booking creation at Booking > Add booking page.
1645 *
1646 * Currently, plugin use 'blank@wpbookingmanager.com' for all blank bookings, previously it was used 'admin@blank.com'
1647 *
1648 * @param $email_address
1649 * @param $email_content
1650 *
1651 * @return bool
1652 */
1653 function wpbc_is_not_blank_email( $email_address, $email_content ) {
1654
1655 // Previously: if ( ( strpos( $to, '@blank.com' ) === false ) && ( strpos( $replace['content'], 'admin@blank.com' ) === false ) ) { ->send(...) }
1656
1657 if (
1658 ( false === strpos( $email_address, '@blank.com' ) )
1659 && ( false === strpos( $email_content, 'admin@blank.com' ) )
1660 && ( false === strpos( $email_address, '@wpbookingmanager.com' ) )
1661 && ( false === strpos( $email_content, 'blank@wpbookingmanager.com' ) )
1662 ) {
1663 return true;
1664 }
1665
1666 return false;
1667 }
1668
1669 // </editor-fold>
1670
1671
1672 // <editor-fold defaultstate="collapsed" desc=" == PHP PERFORMANCE == " >
1673
1674
1675 /**
1676 * Start calculation of time for execution of specific part of CODE
1677 *
1678 * @param string $name name of section
1679 * @param array $php_performance
1680 *
1681 * @return array
1682 *
1683 * Example:
1684 *
1685 * $php_performance = wpbc_php_performance_START( 'emails_sending' , $php_performance );
1686 *
1687 * ... some code here ...
1688 *
1689 * $php_performance = wpbc_php_performance_END( 'emails_sending' , $php_performance );
1690 *
1691 * echo 'Time of execution: ' . $php_performancep['emails_sending']
1692 *
1693 */
1694 function wpbc_php_performance_START( $name, $php_performance ) {
1695
1696 if ( empty( $php_performance ) ) {
1697 $php_performance = array();
1698 }
1699
1700 $php_performance[ $name ] = microtime( true );
1701
1702 return $php_performance;
1703 }
1704
1705 /**
1706 * End calculation of time for execution of specific part of CODE
1707 *
1708 * @param string $name name of section
1709 * @param array $php_performance
1710 *
1711 * @return array
1712 *
1713 * Example:
1714 *
1715 * $php_performance = wpbc_php_performance_START( 'emails_sending' , $php_performance );
1716 *
1717 * ... some code here ...
1718 *
1719 * $php_performance = wpbc_php_performance_END( 'emails_sending' , $php_performance );
1720 *
1721 * echo 'Time of execution: ' . $php_performancep['emails_sending']
1722 *
1723 */
1724 function wpbc_php_performance_END( $name, $php_performance ) {
1725
1726 if ( empty( $php_performance ) ) {
1727 $php_performance = array();
1728 }
1729 if ( empty( $php_performance[ $name ] ) ) {
1730 $php_performance[ $name ] = microtime( true );
1731 }
1732
1733 $php_performance[ $name ] = microtime( true ) - $php_performance[ $name ];
1734
1735 return $php_performance;
1736 }
1737
1738 /**
1739 * Set maximum number of seconds for execution.
1740 *
1741 * @param $limit_in_seconds_int
1742 *
1743 * @return void
1744 */
1745 function wpbc_set_limit_php( $limit_in_seconds_int = 300 ) {
1746
1747 WPBC_Action_Scheduler_Compatibility::raise_memory_limit();
1748 WPBC_Action_Scheduler_Compatibility::raise_time_limit( $limit_in_seconds_int );
1749 }
1750
1751
1752 // </editor-fold>
1753
1754
1755
1756 /**
1757 * Temp fix of styles for edit specific season filter or rate.
1758 *
1759 * @return void
1760 */
1761 function wpbc_add_css_to_hide_seasons() {
1762
1763 // TODO: 2025-05-03 temp fix of view edit filter
1764 ?>
1765 <style tye="text/css">
1766 .wpdvlp-sub-tabs,
1767 #wpbc_dcoupons_table, #wpbc_discountcoupons,
1768 #bulk-action-selector-bottom,
1769 #toolbar_booking_resources,
1770 #toolbar_seasonfilters,
1771 #wpbc_seasonfilters,
1772 #wpbc_booking_resource_table{
1773 display: none !important;
1774 }
1775 .wpbc_round_white_panel {
1776 background: #fff;
1777 padding: 1px 20px 20px;
1778 border-radius: 10px
1779 }
1780 .header_for_cost_object_edit {
1781 font-size: 20px;
1782 padding: 0 0 15px;
1783 border-bottom: 2px solid #f2f2f2;
1784 margin: 15px 0;
1785 line-height: 1.5;
1786 display: flex;
1787 flex-flow: row nowrap;
1788 justify-content: space-between;
1789 align-items: flex-start;
1790 }
1791 .in_header_container_for_resource_title {
1792 color: #5379aa;
1793 margin-left: 0.3em;
1794 }
1795 .header_for_cost_object_edit__close i.wpbc_icn_close::before {
1796 font-size: 22px;
1797 }
1798 </style>
1799 <?php
1800 }
1801