PluginProbe
Booking Calendar / 11.5
Booking Calendar v11.5
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 / includes / _functions / versions.php

versions.php in Booking Calendar 11.5, at includes/_functions/versions.php

655 lines 21.9 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 Versions Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2024-09-03
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // =====================================================================================================================
18 // == Versions ==
19 // =====================================================================================================================
20
21 /**
22 * Check if this demo website
23 *
24 * @return bool
25 */
26 function wpbc_is_this_demo() {
27
28 // return true; //.
29
30 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
31 return false; // If this is Booking Calendar Free version, then it's not the demo.
32 }
33
34 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
35 if ( ( ( isset( $_SERVER['SCRIPT_FILENAME'] ) ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'wpbookingcalendar.com' ) !== false ) ) || ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( strpos( $_SERVER['HTTP_HOST'], 'wpbookingcalendar.com' ) !== false ) ) ) {
36 return true;
37 } else {
38 return false;
39 }
40 }
41
42
43 /**
44 * Check if this Beta Demo website
45 *
46 * @return bool
47 */
48 function wpbc_is_this_beta() {
49
50 $is_beta = ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) );
51
52 return $is_beta;
53 }
54
55
56 /** Get Warning Text for Demo websites */
57 function wpbc_get_warning_text_in_demo_mode() {
58 // return '<div class="wpbc-error-message wpbc_demo_test_version_warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>'; //Old Style
59 return '<div class="wpbc-settings-notice notice-warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>';
60 }
61
62
63 function wpbc_get_wpbc_versions_numbers() {
64
65 $version_numbers = array();
66
67 if ( defined( 'WP_BK_VERSION_NUM' ) ) {
68 $version_numbers [] = WP_BK_VERSION_NUM;
69 } else {
70 $version_numbers [] = ( defined( 'WPDEV_BK_VERSION' ) ) ? WPDEV_BK_VERSION : 'N/A';
71 }
72
73 if ( defined( 'WPBC_PRO_VERSION_NUM' ) ) {
74 if ( ( count( $version_numbers ) > 0 ) && ( $version_numbers[0] !== WPBC_PRO_VERSION_NUM ) ) {
75 $version_numbers [] = WPBC_PRO_VERSION_NUM;
76 }
77 }
78
79 $version_numbers_str = implode( ' | ', $version_numbers );
80
81 return $version_numbers_str;
82 }
83
84
85 /**
86 * Prevent the legacy Pro Simple booking form branch from requiring a removed Free file.
87 *
88 * Pro versions before 11.4 require `page-form-simple.php` only when the legacy
89 * `booking_is_use_simple_booking_form` option is enabled. Newer Free versions no longer contain that file. Because the
90 * Pro loader runs on `wpbc_loaded_php_files`, this check must happen immediately before that action is fired; waiting
91 * until `plugins_loaded` is too late and can result in a fatal `require_once` error. Other legacy Pro configurations
92 * remain loadable for the mixed-version compatibility layer.
93 *
94 * @return bool True when an incompatible Pro loader was removed, otherwise false.
95 */
96 function wpbc_prevent_incompatible_pro_version_loading() {
97
98 $pro_loader_priority = has_action( 'wpbc_loaded_php_files', 'wpbc_pro_load_php_files' );
99
100 if ( false === $pro_loader_priority ) {
101 return false;
102 }
103
104 $is_legacy_pro_version = (
105 ! defined( 'WPBC_PRO_VERSION_NUM' )
106 || version_compare( WPBC_PRO_VERSION_NUM, WP_BK_PRO_BFB_ONLY_VERSION, '<' )
107 );
108 $is_legacy_simple_form_enabled = ( 'On' === get_bk_option( 'booking_is_use_simple_booking_form' ) );
109 $is_legacy_simple_form_missing = ! file_exists( WPBC_PLUGIN_DIR . '/includes/page-form-simple/page-form-simple.php' );
110
111 if ( ! $is_legacy_pro_version || ! $is_legacy_simple_form_enabled || ! $is_legacy_simple_form_missing ) {
112 return false;
113 }
114
115 remove_action( 'wpbc_loaded_php_files', 'wpbc_pro_load_php_files', $pro_loader_priority );
116
117 if ( is_admin() ) {
118 add_action( 'admin_notices', 'wpbc_show_error__legacy_simple_form_pro_version' );
119 }
120
121 return true;
122 }
123
124
125 /**
126 * Show an actionable notice after the legacy Simple booking form Pro loader has been disabled.
127 *
128 * @return void
129 */
130 function wpbc_show_error__legacy_simple_form_pro_version() {
131
132 $pro_version = defined( 'WPBC_PRO_VERSION_NUM' ) ? WPBC_PRO_VERSION_NUM : __( 'unknown', 'booking' );
133
134 $message = sprintf(
135 /* translators: 1: Installed Pro version, 2: Installed Free version, 3: First Pro version without legacy form pages. */
136 __( 'Booking Calendar Pro %1$s cannot load because its legacy Simple booking form option is enabled, but Booking Calendar %2$s no longer contains that legacy settings module. Pro loading was stopped to prevent a fatal error. Update Booking Calendar Pro to version %3$s or newer; using matching Free and Pro versions is recommended.', 'booking' ),
137 '<strong>' . esc_html( $pro_version ) . '</strong>',
138 '<strong>' . esc_html( WP_BK_VERSION_NUM ) . '</strong>',
139 '<strong>' . esc_html( WP_BK_PRO_BFB_ONLY_VERSION ) . '</strong>'
140 );
141
142 echo '<div class="notice notice-error"><p>' . wp_kses_post( $message ) . '</p></div>';
143 }
144
145
146 function wpbc_get_version_type__and_mu(){
147 $version = 'free';
148 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
149 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
150 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
151 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
152 if ( class_exists('wpdev_bk_multiuser') ) $version = 'multiuser';
153 return $version;
154 }
155
156
157 function wpbc_get_plugin_version_type(){
158 $version = 'free';
159 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
160 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
161 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
162 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
163 return $version;
164 }
165
166
167 /**
168 * Get Title of the version type.
169 *
170 * @return string
171 */
172 function wpbc_get_plugin_version_title() {
173 $title = 'Free';
174 $version_type = wpbc_get_version_type__and_mu();
175 switch ( $version_type ) {
176 case 'personal':
177 $title = 'Personal';
178 break;
179 case 'biz_s':
180 $title = 'Business Small';
181 break;
182 case 'biz_m':
183 $title = 'Business Medium';
184 break;
185 case 'biz_l':
186 $title = 'Business Large';
187 break;
188 case 'multiuser':
189 $title = 'MultiUser';
190 break;
191 default:
192 $title = 'Free';
193 }
194
195 return $title;
196 }
197
198
199 /**
200 * Check if user accidentially update Booking Calendar Paid version to Free
201 *
202 * @return bool
203 */
204 function wpbc_is_updated_paid_to_free() {
205
206 if ( ( wpbc_is_table_exists('bookingtypes') ) && ( ! class_exists('wpdev_bk_personal') ) )
207 return true;
208 else
209 return false;
210 }
211
212
213 function wpbc_get_ver_sufix() {
214 if ( strpos( strtolower( WPDEV_BK_VERSION ), 'multisite' ) !== false ) {
215 $v_type = '-multi';
216 } else if ( strpos( strtolower( WPDEV_BK_VERSION ), 'develop' ) !== false ) {
217 $v_type = '-dev';
218 } else {
219 $v_type = '';
220 }
221 $v = '';
222 if ( class_exists( 'wpdev_bk_personal' ) ) {
223 $v = 'ps' . $v_type;
224 }
225 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
226 $v = 'bs' . $v_type;
227 }
228 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
229 $v = 'bm' . $v_type;
230 }
231 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
232 $v = 'bl' . $v_type;
233 }
234 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
235 $v = '';
236 }
237
238 return $v;
239 }
240
241
242 /**
243 * Is show upgrade link.
244 *
245 * @return bool
246 */
247 function wpbc_is_show_up() {
248
249 // $is_show_up = get_bk_option( 'booking_wpdev_copyright_adminpanel' );
250 // $is_show_up = ( ( 'Off' !== $is_show_up ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) );
251 // return $is_show_up;
252
253 $is_show_up = ( ( 'hide' !== get_bk_option( 'booking_menu_go_pro' ) ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) );
254
255 return $is_show_up;
256 }
257
258
259 /**
260 * Get Up link.
261 *
262 * @return string
263 */
264 function wpbc_up_link() {
265
266 if ( ! wpbc_is_this_demo() ) {
267 $v = wpbc_get_ver_sufix();
268 } else {
269 $v = '';
270 }
271
272 if ( empty( $v ) ) {
273 $v = 'features/';
274 } else {
275 $v = 'upgrade-' . $v . '/';
276 }
277
278 return 'https://wpbookingcalendar.com/' . $v;
279 }
280
281
282 /**
283 * Check if "Booking Manager" installed/activated and return version number
284 *
285 * @return string - 0 if not installed, otherwise version num
286 */
287 function wpbc_get_wpbm_version() {
288
289 if ( ! defined( 'WPBM_VERSION_NUM' ) ) {
290 return 0;
291 } else {
292 return WPBM_VERSION_NUM;
293 }
294 }
295
296
297 /**
298 * Get header info from this file, just for compatibility with WordPress 2.8 and older versions
299 *
300 * @param $file = WPBC_FILE
301 * @param $default_headers = array( 'Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path' )
302 * @param $context = 'plugin'
303 *
304 * @return array
305 *
306 * Example:
307 * $plugin_data = wpbc_file__read_header_info( WPBC_FILE , array( 'Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path' ) , 'plugin' );
308 */
309 function wpbc_file__read_header_info( $file, $default_headers, $context = '' ) {
310 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
311 $fp = fopen( $file, 'r' ); // We don't need to write to the file, so just open for reading.
312 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread
313 $file_data = fread( $fp, 8192 ); // Pull only the first 8kiB of the file in.
314 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
315 fclose( $fp ); // PHP will close file handle, but we are good citizens.
316
317 if ( $context != '' ) {
318 $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() );
319
320 $extra_headers = array_flip( $extra_headers );
321 foreach ( $extra_headers as $key => $value ) {
322 $extra_headers[ $key ] = $key;
323 }
324 $all_headers = array_merge( $extra_headers, $default_headers );
325 } else {
326 $all_headers = $default_headers;
327 }
328
329 foreach ( $all_headers as $field => $regex ) {
330 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
331 if ( !empty( ${$field} ) )
332 ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
333 else
334 ${$field} = '';
335 }
336
337 $file_data = compact( array_keys( $all_headers ) );
338
339 return $file_data;
340 }
341
342
343 function wpbc_get_json_property_from_meta( $property_key ) {
344
345 if ( ! defined( 'WPBC_PRO_FILE' ) ) {
346 return null;
347 }
348
349 $meta_file_path = plugin_dir_path( WPBC_PRO_FILE ) . 'meta.json';
350
351 if ( ( ! is_file( $meta_file_path ) ) || ( ! is_readable( $meta_file_path ) ) ) {
352 return null;
353 }
354
355 // Read the local plugin metadata directly, so hosts with FTP-based WP_Filesystem settings cannot fatal here.
356 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
357 $json_contents = file_get_contents( $meta_file_path );
358
359 if ( false === $json_contents || '' === trim( $json_contents ) ) {
360 return null;
361 }
362
363 $data = json_decode( $json_contents, true );
364
365 if ( ( json_last_error() !== JSON_ERROR_NONE ) || ( ! is_array( $data ) ) ) {
366 return null;
367 }
368
369 return array_key_exists( $property_key, $data ) ? $data[ $property_key ] : null;
370 }
371
372 /**
373 * Check if we need BLUR this section -- add CSS Class for specific versions
374 *
375 * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions.
376 *
377 * @param $versions_arr
378 *
379 * @return void
380 */
381 function wpbc_is_blured( $versions_arr ){
382
383 $ver = wpbc_get_version_type__and_mu();
384
385 $is_blured = false;
386
387 switch ( $ver ) {
388 case 'free':
389 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'f', $versions_arr ) ) ) ? true : $is_blured;
390 break;
391 case 'personal':
392 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'ps', $versions_arr ) ) ) ? true : $is_blured;
393 break;
394 case 'biz_s':
395 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bs', $versions_arr ) ) ) ? true : $is_blured;
396 break;
397 case 'biz_m':
398 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bm', $versions_arr ) ) ) ? true : $is_blured;
399 break;
400 case 'biz_l':
401 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bl', $versions_arr ) ) ) ? true : $is_blured;
402 break;
403 case 'multiuser':
404 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'mu', $versions_arr ) ) ) ? true : $is_blured;
405 break;
406 default:
407 // Default
408 }
409 return $is_blured;
410 }
411
412
413 /**
414 * Echo Blur CSS Class for specific versions
415 *
416 * Example: wpbc_echo_blur(array('free','ps')); // Echo blur in Free and Personal versions.
417 *
418 * @param $versions_arr
419 *
420 * @return void
421 */
422 function wpbc_echo_blur( $versions_arr ){
423
424 $is_blured = wpbc_is_blured( $versions_arr );
425
426 if ( $is_blured ) {
427 echo 'wpbc_blur';
428 }
429 }
430
431
432 /**
433 * Show Upgrade Widget
434 *
435 * @param $id
436 * @param $params
437 *
438 * @return string if upgrade panel hided than returned ''
439 *
440 *
441 * Example:
442 * wpbc_get_up_notice('booking_weekdays_conditions', array(
443 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
444 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
445 * 'versions' => 'Business Large, MultiUser versions',
446 * 'css' => 'transform: translate(0) translateY(120px);'
447 * ));
448 */
449 function wpbc_get__upgrade_notice__html_content( $id, $params ){
450
451 $defaults = array(
452 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
453 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
454 'versions' => 'Business Large, MultiUser versions',
455 'css' => 'transform: translate(0) translateY(120px);',
456 'dismiss_css_class' => '',
457 'html_dismiss_btn' => ''
458 );
459 $params = wp_parse_args( $params, $defaults );
460
461 ob_start();
462
463 ?><div id="upgrade_notice_<?php echo esc_attr( $id ); ?>"
464 class="wpbc_widget_content wpbc_upgrade_widget <?php echo esc_attr( str_replace( array('.','#'), '', $params['dismiss_css_class'] ) ); ?>"
465 style="<?php echo esc_attr( $params['css'] ); ?>">
466 <div class="ui_container ui_container_toolbar ui_container_small wpbc_upgrade_widget_container">
467 <div class="ui_group ui_group__upgrade">
468 <div class="wpbc_upgrade_note wpbc_upgrade_theme_green">
469 <div>
470 <?php
471 echo wp_kses_post( sprintf( 'This %s is available in the %s. %s'
472 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['feature_link']['relative_url'] . '">' . $params['feature_link']['title'] . '</a>'
473 , '<strong>' . $params['versions'] . '</strong>'
474 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['upgrade_link']['relative_url'] . '">' . $params['upgrade_link']['title'] . '</a>'
475 ) );
476 ?>
477 </div>
478 <?php
479 // Dismiss button
480 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
481 echo $params['html_dismiss_btn'];
482 ?>
483 </div>
484 </div>
485 </div>
486 </div><?php
487
488 $html = ob_get_clean();
489
490 return $html ;
491 }
492
493
494 /**
495 * Get for showing Upgrade Widget Content and CSS class if needed to blur real content. If
496 *
497 * @param $params = array(
498 * 'id' => $id . '_' . 'weekdays_conditions',
499 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
500 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
501 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
502 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
503 * 'versions' => 'Business Medium / Large, MultiUser versions',
504 * 'css' => 'transform: translate(0) translateY(120px);'
505 * )
506 *
507 * @return array(
508 * 'content' => $upgrade_panel_html,
509 * 'maybe_blur_css_class' => $blur_css_class
510 * )
511 *
512 * Example of usage:
513 *
514 * $upgrade_content_arr = wpbc_get_upgrade_widget( array(
515 * 'id' => $id . '_' . 'weekdays_conditions',
516 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
517 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
518 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
519 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
520 * 'versions' => 'Business Medium / Large, MultiUser versions',
521 * 'css' => 'transform: translate(0) translateY(120px);'
522 * ) );
523 *
524 * echo $upgrade_content_arr['content'];
525 *
526 * // ... In real content ...
527 * <div class=" wpbc_dismiss_weekdays_conditions <?php echo esc_attr( $upgrade_content_arr['maybe_blur_css_class'] ); ?>">
528 * ...
529 * </div>
530 */
531 function wpbc_get_upgrade_widget( $params ) {
532
533 $defaults = array(
534 'id' => 'wpbc_random_' . round( microtime( true ) * 1000 ), //$id . '_' . 'weekdays_conditions',
535 'blured_in_versions' => array( 'free', 'ps', 'bs', 'bm', 'bl', 'mu' ),
536 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
537 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
538 'versions' => 'Business Large, MultiUser versions',
539 'css' => 'transform: translate(0) translateY(120px);',
540 'dismiss_css_class' => '', //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions'
541 'no_dismiss' => false
542 );
543 $params = wp_parse_args( $params, $defaults );
544 $up_id = $params['id'];
545
546
547 $is_blured = wpbc_is_blured( $params['blured_in_versions'] );
548
549 $upgrade_panel_html = '';
550 $blur_css_class = '';
551
552 if ( $is_blured ) {
553
554 if ( $params['no_dismiss'] ) {
555 $is_upgrade_panel_visible = true;
556 $html_dismiss_btn = '';
557 } else {
558 // ---------------------------------------------------------------------------------------------------------
559 // Is dismissed ?
560 // ---------------------------------------------------------------------------------------------------------
561 ob_start();
562 $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array(
563 'title' => '<span aria-hidden="true" style="font-size: 28px;">&times;</span>',
564 'hint' => __( 'Dismiss', 'booking' ),
565 'class' => 'wpbc_panel_get_started_dismiss',
566 'css' => '',
567 'dismiss_css_class' => $params['dismiss_css_class']
568 ) );
569 $html_dismiss_btn = ob_get_clean();
570 }
571
572 // ---------------------------------------------------------------------------------------------------------
573 // Upgrade Widget
574 // ---------------------------------------------------------------------------------------------------------
575 if ( $is_upgrade_panel_visible ) {
576
577 $upgrade_panel_html = wpbc_get__upgrade_notice__html_content( $up_id, array(
578 'feature_link' => $params['feature_link'],
579 'upgrade_link' => $params['upgrade_link'],
580 'versions' => $params['versions'],
581 'css' => $params['css'],
582 'dismiss_css_class' => $params['dismiss_css_class'],
583 'html_dismiss_btn'=> $html_dismiss_btn
584 ) );
585 $blur_css_class = 'wpbc_blur';
586 } else {
587
588 ob_start();
589
590 ?><script type="text/javascript">
591 jQuery(document).ready(function(){
592 setTimeout(function(){
593 jQuery( '<?php echo esc_attr( $params['dismiss_css_class'] ); ?>' ).hide() ;
594 }, 100);
595 });
596 </script><?php
597
598 $upgrade_panel_html = ob_get_clean();
599 }
600 }
601
602 $upgrade_content_arr = array(
603 'content' => $upgrade_panel_html,
604 'maybe_blur_css_class' => $blur_css_class
605 );
606
607 return $upgrade_content_arr;
608
609 }
610
611
612 /**
613 * How old ago was installed plugin, based on first booking
614 *
615 * @return int if -1, then no bookings!
616 */
617 function wpbc_how_old_in_days() {
618
619 $how_old = wpbc_get_info__about_how_old();
620
621 if ( ! empty( $how_old ) ) {
622 return intval( $how_old['days'] );
623 } else {
624 // Unknown. Maybe no bookings
625 return -1;
626 }
627 }
628
629 /**
630 * Get date info about first booking.
631 * @return array|false
632 */
633 function wpbc_get_info__about_how_old() {
634 global $wpdb;
635
636 $sql = "SELECT modification_date FROM {$wpdb->prefix}booking as bk ORDER by booking_id LIMIT 0,1";
637 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
638 $res = $wpdb->get_results( $sql );
639
640 if ( ! empty( $res ) ) {
641
642 $first_booking_date = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s', strtotime( $res[0]->modification_date ) ), 'Y-m-d H:i:s' );
643
644 $dif_days = wpbc_get_difference_in_days( gmdate( 'Y-m-d 00:00:00', strtotime( 'now' ) ), gmdate( 'Y-m-d 00:00:00', strtotime( $res[0]->modification_date ) ) );
645
646 return array(
647 'date_ymd_his' => $res[0]->modification_date,
648 'date_echo' => $first_booking_date,
649 'days' => $dif_days
650 );
651 }
652
653 return false;
654 }
655