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 / wpbc_functions.php

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

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