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

659 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 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 * Get Up link.
265 *
266 * @return string
267 */
268 function wpbc_up_link() {
269
270 if ( ! wpbc_is_this_demo() ) {
271 $v = wpbc_get_ver_sufix();
272 } else {
273 $v = '';
274 }
275
276 if ( empty( $v ) ) {
277 $v = 'features/';
278 } else {
279 $v = 'upgrade-' . $v . '/';
280 }
281
282 return 'https://wpbookingcalendar.com/' . $v;
283 }
284
285
286 /**
287 * Check if "Booking Manager" installed/activated and return version number
288 *
289 * @return string - 0 if not installed, otherwise version num
290 */
291 function wpbc_get_wpbm_version() {
292
293 if ( ! defined( 'WPBM_VERSION_NUM' ) ) {
294 return 0;
295 } else {
296 return WPBM_VERSION_NUM;
297 }
298 }
299
300
301 /**
302 * Get header info from this file, just for compatibility with WordPress 2.8 and older versions
303 *
304 * @param $file = WPBC_FILE
305 * @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' )
306 * @param $context = 'plugin'
307 *
308 * @return array
309 *
310 * Example:
311 * $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' );
312 */
313 function wpbc_file__read_header_info( $file, $default_headers, $context = '' ) {
314 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
315 $fp = fopen( $file, 'r' ); // We don't need to write to the file, so just open for reading.
316 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread
317 $file_data = fread( $fp, 8192 ); // Pull only the first 8kiB of the file in.
318 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
319 fclose( $fp ); // PHP will close file handle, but we are good citizens.
320
321 if ( $context != '' ) {
322 $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() );
323
324 $extra_headers = array_flip( $extra_headers );
325 foreach ( $extra_headers as $key => $value ) {
326 $extra_headers[ $key ] = $key;
327 }
328 $all_headers = array_merge( $extra_headers, $default_headers );
329 } else {
330 $all_headers = $default_headers;
331 }
332
333 foreach ( $all_headers as $field => $regex ) {
334 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
335 if ( !empty( ${$field} ) )
336 ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
337 else
338 ${$field} = '';
339 }
340
341 $file_data = compact( array_keys( $all_headers ) );
342
343 return $file_data;
344 }
345
346
347 function wpbc_get_json_property_from_meta( $property_key ) {
348
349 if ( ! defined( 'WPBC_PRO_FILE' ) ) {
350 return null;
351 }
352
353 $meta_file_path = plugin_dir_path( WPBC_PRO_FILE ) . 'meta.json';
354
355 if ( ( ! is_file( $meta_file_path ) ) || ( ! is_readable( $meta_file_path ) ) ) {
356 return null;
357 }
358
359 // Read the local plugin metadata directly, so hosts with FTP-based WP_Filesystem settings cannot fatal here.
360 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
361 $json_contents = file_get_contents( $meta_file_path );
362
363 if ( false === $json_contents || '' === trim( $json_contents ) ) {
364 return null;
365 }
366
367 $data = json_decode( $json_contents, true );
368
369 if ( ( json_last_error() !== JSON_ERROR_NONE ) || ( ! is_array( $data ) ) ) {
370 return null;
371 }
372
373 return array_key_exists( $property_key, $data ) ? $data[ $property_key ] : null;
374 }
375
376 /**
377 * Check if we need BLUR this section -- add CSS Class for specific versions
378 *
379 * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions.
380 *
381 * @param $versions_arr
382 *
383 * @return void
384 */
385 function wpbc_is_blured( $versions_arr ){
386
387 $ver = wpbc_get_version_type__and_mu();
388
389 $is_blured = false;
390
391 switch ( $ver ) {
392 case 'free':
393 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'f', $versions_arr ) ) ) ? true : $is_blured;
394 break;
395 case 'personal':
396 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'ps', $versions_arr ) ) ) ? true : $is_blured;
397 break;
398 case 'biz_s':
399 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bs', $versions_arr ) ) ) ? true : $is_blured;
400 break;
401 case 'biz_m':
402 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bm', $versions_arr ) ) ) ? true : $is_blured;
403 break;
404 case 'biz_l':
405 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bl', $versions_arr ) ) ) ? true : $is_blured;
406 break;
407 case 'multiuser':
408 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'mu', $versions_arr ) ) ) ? true : $is_blured;
409 break;
410 default:
411 // Default
412 }
413 return $is_blured;
414 }
415
416
417 /**
418 * Echo Blur CSS Class for specific versions
419 *
420 * Example: wpbc_echo_blur(array('free','ps')); // Echo blur in Free and Personal versions.
421 *
422 * @param $versions_arr
423 *
424 * @return void
425 */
426 function wpbc_echo_blur( $versions_arr ){
427
428 $is_blured = wpbc_is_blured( $versions_arr );
429
430 if ( $is_blured ) {
431 echo 'wpbc_blur';
432 }
433 }
434
435
436 /**
437 * Show Upgrade Widget
438 *
439 * @param $id
440 * @param $params
441 *
442 * @return string if upgrade panel hided than returned ''
443 *
444 *
445 * Example:
446 * wpbc_get_up_notice('booking_weekdays_conditions', array(
447 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
448 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
449 * 'versions' => 'Business Large, MultiUser versions',
450 * 'css' => 'transform: translate(0) translateY(120px);'
451 * ));
452 */
453 function wpbc_get__upgrade_notice__html_content( $id, $params ){
454
455 $defaults = array(
456 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
457 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
458 'versions' => 'Business Large, MultiUser versions',
459 'css' => 'transform: translate(0) translateY(120px);',
460 'dismiss_css_class' => '',
461 'html_dismiss_btn' => ''
462 );
463 $params = wp_parse_args( $params, $defaults );
464
465 ob_start();
466
467 ?><div id="upgrade_notice_<?php echo esc_attr( $id ); ?>"
468 class="wpbc_widget_content wpbc_upgrade_widget <?php echo esc_attr( str_replace( array('.','#'), '', $params['dismiss_css_class'] ) ); ?>"
469 style="<?php echo esc_attr( $params['css'] ); ?>">
470 <div class="ui_container ui_container_toolbar ui_container_small wpbc_upgrade_widget_container">
471 <div class="ui_group ui_group__upgrade">
472 <div class="wpbc_upgrade_note wpbc_upgrade_theme_green">
473 <div>
474 <?php
475 echo wp_kses_post( sprintf( 'This %s is available in the %s. %s'
476 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['feature_link']['relative_url'] . '">' . $params['feature_link']['title'] . '</a>'
477 , '<strong>' . $params['versions'] . '</strong>'
478 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['upgrade_link']['relative_url'] . '">' . $params['upgrade_link']['title'] . '</a>'
479 ) );
480 ?>
481 </div>
482 <?php
483 // Dismiss button
484 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
485 echo $params['html_dismiss_btn'];
486 ?>
487 </div>
488 </div>
489 </div>
490 </div><?php
491
492 $html = ob_get_clean();
493
494 return $html ;
495 }
496
497
498 /**
499 * Get for showing Upgrade Widget Content and CSS class if needed to blur real content. If
500 *
501 * @param $params = array(
502 * 'id' => $id . '_' . 'weekdays_conditions',
503 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
504 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
505 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
506 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
507 * 'versions' => 'Business Medium / Large, MultiUser versions',
508 * 'css' => 'transform: translate(0) translateY(120px);'
509 * )
510 *
511 * @return array(
512 * 'content' => $upgrade_panel_html,
513 * 'maybe_blur_css_class' => $blur_css_class
514 * )
515 *
516 * Example of usage:
517 *
518 * $upgrade_content_arr = wpbc_get_upgrade_widget( array(
519 * 'id' => $id . '_' . 'weekdays_conditions',
520 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
521 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
522 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
523 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
524 * 'versions' => 'Business Medium / Large, MultiUser versions',
525 * 'css' => 'transform: translate(0) translateY(120px);'
526 * ) );
527 *
528 * echo $upgrade_content_arr['content'];
529 *
530 * // ... In real content ...
531 * <div class=" wpbc_dismiss_weekdays_conditions <?php echo esc_attr( $upgrade_content_arr['maybe_blur_css_class'] ); ?>">
532 * ...
533 * </div>
534 */
535 function wpbc_get_upgrade_widget( $params ) {
536
537 $defaults = array(
538 'id' => 'wpbc_random_' . round( microtime( true ) * 1000 ), //$id . '_' . 'weekdays_conditions',
539 'blured_in_versions' => array( 'free', 'ps', 'bs', 'bm', 'bl', 'mu' ),
540 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
541 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
542 'versions' => 'Business Large, MultiUser versions',
543 'css' => 'transform: translate(0) translateY(120px);',
544 'dismiss_css_class' => '', //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions'
545 'no_dismiss' => false
546 );
547 $params = wp_parse_args( $params, $defaults );
548 $up_id = $params['id'];
549
550
551 $is_blured = wpbc_is_blured( $params['blured_in_versions'] );
552
553 $upgrade_panel_html = '';
554 $blur_css_class = '';
555
556 if ( $is_blured ) {
557
558 if ( $params['no_dismiss'] ) {
559 $is_upgrade_panel_visible = true;
560 $html_dismiss_btn = '';
561 } else {
562 // ---------------------------------------------------------------------------------------------------------
563 // Is dismissed ?
564 // ---------------------------------------------------------------------------------------------------------
565 ob_start();
566 $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array(
567 'title' => '<span aria-hidden="true" style="font-size: 28px;">&times;</span>',
568 'hint' => __( 'Dismiss', 'booking' ),
569 'class' => 'wpbc_panel_get_started_dismiss',
570 'css' => '',
571 'dismiss_css_class' => $params['dismiss_css_class']
572 ) );
573 $html_dismiss_btn = ob_get_clean();
574 }
575
576 // ---------------------------------------------------------------------------------------------------------
577 // Upgrade Widget
578 // ---------------------------------------------------------------------------------------------------------
579 if ( $is_upgrade_panel_visible ) {
580
581 $upgrade_panel_html = wpbc_get__upgrade_notice__html_content( $up_id, array(
582 'feature_link' => $params['feature_link'],
583 'upgrade_link' => $params['upgrade_link'],
584 'versions' => $params['versions'],
585 'css' => $params['css'],
586 'dismiss_css_class' => $params['dismiss_css_class'],
587 'html_dismiss_btn'=> $html_dismiss_btn
588 ) );
589 $blur_css_class = 'wpbc_blur';
590 } else {
591
592 ob_start();
593
594 ?><script type="text/javascript">
595 jQuery(document).ready(function(){
596 setTimeout(function(){
597 jQuery( '<?php echo esc_attr( $params['dismiss_css_class'] ); ?>' ).hide() ;
598 }, 100);
599 });
600 </script><?php
601
602 $upgrade_panel_html = ob_get_clean();
603 }
604 }
605
606 $upgrade_content_arr = array(
607 'content' => $upgrade_panel_html,
608 'maybe_blur_css_class' => $blur_css_class
609 );
610
611 return $upgrade_content_arr;
612
613 }
614
615
616 /**
617 * How old ago was installed plugin, based on first booking
618 *
619 * @return int if -1, then no bookings!
620 */
621 function wpbc_how_old_in_days() {
622
623 $how_old = wpbc_get_info__about_how_old();
624
625 if ( ! empty( $how_old ) ) {
626 return intval( $how_old['days'] );
627 } else {
628 // Unknown. Maybe no bookings
629 return -1;
630 }
631 }
632
633 /**
634 * Get date info about first booking.
635 * @return array|false
636 */
637 function wpbc_get_info__about_how_old() {
638 global $wpdb;
639
640 $sql = "SELECT modification_date FROM {$wpdb->prefix}booking as bk ORDER by booking_id LIMIT 0,1";
641 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
642 $res = $wpdb->get_results( $sql );
643
644 if ( ! empty( $res ) ) {
645
646 $first_booking_date = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s', strtotime( $res[0]->modification_date ) ), 'Y-m-d H:i:s' );
647
648 $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 ) ) );
649
650 return array(
651 'date_ymd_his' => $res[0]->modification_date,
652 'date_echo' => $first_booking_date,
653 'days' => $dif_days
654 );
655 }
656
657 return false;
658 }
659