PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 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 All 205 releases
booking / includes / _functions / versions.php

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

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