PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
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.8, at includes/_functions/versions.php

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