PluginProbe
Booking Calendar / 10.11
Booking Calendar v10.11
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 10.11.3 10.11.4 All 201 releases
booking / core / wpbc_functions.php

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

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