PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.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 10.15.7, at includes/_functions/versions.php

580 lines 18.6 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_version_type__and_mu(){
64 $version = 'free';
65 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
66 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
67 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
68 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
69 if ( class_exists('wpdev_bk_multiuser') ) $version = 'multiuser';
70 return $version;
71 }
72
73
74 function wpbc_get_plugin_version_type(){
75 $version = 'free';
76 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
77 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
78 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
79 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
80 return $version;
81 }
82
83
84 /**
85 * Get Title of the version type.
86 *
87 * @return string
88 */
89 function wpbc_get_plugin_version_title() {
90 $title = 'Free';
91 $version_type = wpbc_get_version_type__and_mu();
92 switch ( $version_type ) {
93 case 'personal':
94 $title = 'Personal';
95 break;
96 case 'biz_s':
97 $title = 'Business Small';
98 break;
99 case 'biz_m':
100 $title = 'Business Medium';
101 break;
102 case 'biz_l':
103 $title = 'Business Large';
104 break;
105 case 'multiuser':
106 $title = 'MultiUser';
107 break;
108 default:
109 $title = 'Free';
110 }
111
112 return $title;
113 }
114
115
116 /**
117 * Check if user accidentially update Booking Calendar Paid version to Free
118 *
119 * @return bool
120 */
121 function wpbc_is_updated_paid_to_free() {
122
123 if ( ( wpbc_is_table_exists('bookingtypes') ) && ( ! class_exists('wpdev_bk_personal') ) )
124 return true;
125 else
126 return false;
127 }
128
129
130 function wpbc_get_ver_sufix() {
131 if ( strpos( strtolower( WPDEV_BK_VERSION ), 'multisite' ) !== false ) {
132 $v_type = '-multi';
133 } else if ( strpos( strtolower( WPDEV_BK_VERSION ), 'develop' ) !== false ) {
134 $v_type = '-dev';
135 } else {
136 $v_type = '';
137 }
138 $v = '';
139 if ( class_exists( 'wpdev_bk_personal' ) ) {
140 $v = 'ps' . $v_type;
141 }
142 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
143 $v = 'bs' . $v_type;
144 }
145 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
146 $v = 'bm' . $v_type;
147 }
148 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
149 $v = 'bl' . $v_type;
150 }
151 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
152 $v = '';
153 }
154
155 return $v;
156 }
157
158
159 /**
160 * Is show upgrade link.
161 *
162 * @return bool
163 */
164 function wpbc_is_show_up() {
165
166 // $is_show_up = get_bk_option( 'booking_wpdev_copyright_adminpanel' );
167 // $is_show_up = ( ( 'Off' !== $is_show_up ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) );
168 // return $is_show_up;
169
170 $is_show_up = ( ( 'hide' !== get_bk_option( 'booking_menu_go_pro' ) ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) );
171
172 return $is_show_up;
173 }
174
175
176 /**
177 * Get Up link.
178 *
179 * @return string
180 */
181 function wpbc_up_link() {
182
183 if ( ! wpbc_is_this_demo() ) {
184 $v = wpbc_get_ver_sufix();
185 } else {
186 $v = '';
187 }
188
189 if ( empty( $v ) ) {
190 $v = 'features/';
191 } else {
192 $v = 'upgrade-' . $v . '/';
193 }
194
195 return 'https://wpbookingcalendar.com/' . $v;
196 }
197
198
199 /**
200 * Check if "Booking Manager" installed/activated and return version number
201 *
202 * @return string - 0 if not installed, otherwise version num
203 */
204 function wpbc_get_wpbm_version() {
205
206 if ( ! defined( 'WPBM_VERSION_NUM' ) ) {
207 return 0;
208 } else {
209 return WPBM_VERSION_NUM;
210 }
211 }
212
213
214 /**
215 * Get header info from this file, just for compatibility with WordPress 2.8 and older versions
216 *
217 * @param $file = WPBC_FILE
218 * @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' )
219 * @param $context = 'plugin'
220 *
221 * @return array
222 *
223 * Example:
224 * $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' );
225 */
226 function wpbc_file__read_header_info( $file, $default_headers, $context = '' ) {
227 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
228 $fp = fopen( $file, 'r' ); // We don't need to write to the file, so just open for reading.
229 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread
230 $file_data = fread( $fp, 8192 ); // Pull only the first 8kiB of the file in.
231 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
232 fclose( $fp ); // PHP will close file handle, but we are good citizens.
233
234 if ( $context != '' ) {
235 $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() );
236
237 $extra_headers = array_flip( $extra_headers );
238 foreach ( $extra_headers as $key => $value ) {
239 $extra_headers[ $key ] = $key;
240 }
241 $all_headers = array_merge( $extra_headers, $default_headers );
242 } else {
243 $all_headers = $default_headers;
244 }
245
246 foreach ( $all_headers as $field => $regex ) {
247 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
248 if ( !empty( ${$field} ) )
249 ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
250 else
251 ${$field} = '';
252 }
253
254 $file_data = compact( array_keys( $all_headers ) );
255
256 return $file_data;
257 }
258
259
260 function wpbc_get_json_property_from_meta( $property_key ) {
261
262 if ( ! defined( 'WPBC_PRO_FILE' ) ) {
263 return null;
264 }
265
266 $meta_file_path = plugin_dir_path( WPBC_PRO_FILE ) . 'meta.json';
267
268 if ( ! file_exists( $meta_file_path ) ) {
269 return null;
270 }
271
272 global $wp_filesystem;
273
274 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
275 require_once ABSPATH . 'wp-admin/includes/file.php';
276 }
277
278 if ( empty( $wp_filesystem ) ) {
279 WP_Filesystem();
280 }
281
282 $json_contents = $wp_filesystem->get_contents( $meta_file_path );
283
284 if ( empty( $json_contents ) ) {
285 return null;
286 }
287
288 $data = json_decode( $json_contents, true );
289
290 if ( json_last_error() !== JSON_ERROR_NONE ) {
291 return null;
292 }
293
294 return isset( $data[ $property_key ] ) ? $data[ $property_key ] : null;
295 }
296
297 /**
298 * Check if we need BLUR this section -- add CSS Class for specific versions
299 *
300 * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions.
301 *
302 * @param $versions_arr
303 *
304 * @return void
305 */
306 function wpbc_is_blured( $versions_arr ){
307
308 $ver = wpbc_get_version_type__and_mu();
309
310 $is_blured = false;
311
312 switch ( $ver ) {
313 case 'free':
314 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'f', $versions_arr ) ) ) ? true : $is_blured;
315 break;
316 case 'personal':
317 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'ps', $versions_arr ) ) ) ? true : $is_blured;
318 break;
319 case 'biz_s':
320 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bs', $versions_arr ) ) ) ? true : $is_blured;
321 break;
322 case 'biz_m':
323 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bm', $versions_arr ) ) ) ? true : $is_blured;
324 break;
325 case 'biz_l':
326 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bl', $versions_arr ) ) ) ? true : $is_blured;
327 break;
328 case 'multiuser':
329 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'mu', $versions_arr ) ) ) ? true : $is_blured;
330 break;
331 default:
332 // Default
333 }
334 return $is_blured;
335 }
336
337
338 /**
339 * Echo Blur CSS Class for specific versions
340 *
341 * Example: wpbc_echo_blur(array('free','ps')); // Echo blur in Free and Personal versions.
342 *
343 * @param $versions_arr
344 *
345 * @return void
346 */
347 function wpbc_echo_blur( $versions_arr ){
348
349 $is_blured = wpbc_is_blured( $versions_arr );
350
351 if ( $is_blured ) {
352 echo 'wpbc_blur';
353 }
354 }
355
356
357 /**
358 * Show Upgrade Widget
359 *
360 * @param $id
361 * @param $params
362 *
363 * @return string if upgrade panel hided than returned ''
364 *
365 *
366 * Example:
367 * wpbc_get_up_notice('booking_weekdays_conditions', array(
368 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
369 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
370 * 'versions' => 'Business Large, MultiUser versions',
371 * 'css' => 'transform: translate(0) translateY(120px);'
372 * ));
373 */
374 function wpbc_get__upgrade_notice__html_content( $id, $params ){
375
376 $defaults = array(
377 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
378 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
379 'versions' => 'Business Large, MultiUser versions',
380 'css' => 'transform: translate(0) translateY(120px);',
381 'dismiss_css_class' => '',
382 'html_dismiss_btn' => ''
383 );
384 $params = wp_parse_args( $params, $defaults );
385
386 ob_start();
387
388 ?><div id="upgrade_notice_<?php echo esc_attr( $id ); ?>"
389 class="wpbc_widget_content wpbc_upgrade_widget <?php echo esc_attr( str_replace( array('.','#'), '', $params['dismiss_css_class'] ) ); ?>"
390 style="<?php echo esc_attr( $params['css'] ); ?>">
391 <div class="ui_container ui_container_toolbar ui_container_small wpbc_upgrade_widget_container">
392 <div class="ui_group ui_group__upgrade">
393 <div class="wpbc_upgrade_note wpbc_upgrade_theme_green">
394 <div>
395 <?php
396 echo wp_kses_post( sprintf( 'This %s is available in the %s. %s'
397 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['feature_link']['relative_url'] . '">' . $params['feature_link']['title'] . '</a>'
398 , '<strong>' . $params['versions'] . '</strong>'
399 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['upgrade_link']['relative_url'] . '">' . $params['upgrade_link']['title'] . '</a>'
400 ) );
401 ?>
402 </div>
403 <?php
404 // Dismiss button
405 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
406 echo $params['html_dismiss_btn'];
407 ?>
408 </div>
409 </div>
410 </div>
411 </div><?php
412
413 $html = ob_get_clean();
414
415 return $html ;
416 }
417
418
419 /**
420 * Get for showing Upgrade Widget Content and CSS class if needed to blur real content. If
421 *
422 * @param $params = array(
423 * 'id' => $id . '_' . 'weekdays_conditions',
424 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
425 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
426 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
427 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
428 * 'versions' => 'Business Medium / Large, MultiUser versions',
429 * 'css' => 'transform: translate(0) translateY(120px);'
430 * )
431 *
432 * @return array(
433 * 'content' => $upgrade_panel_html,
434 * 'maybe_blur_css_class' => $blur_css_class
435 * )
436 *
437 * Example of usage:
438 *
439 * $upgrade_content_arr = wpbc_get_upgrade_widget( array(
440 * 'id' => $id . '_' . 'weekdays_conditions',
441 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
442 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
443 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
444 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
445 * 'versions' => 'Business Medium / Large, MultiUser versions',
446 * 'css' => 'transform: translate(0) translateY(120px);'
447 * ) );
448 *
449 * echo $upgrade_content_arr['content'];
450 *
451 * // ... In real content ...
452 * <div class=" wpbc_dismiss_weekdays_conditions <?php echo esc_attr( $upgrade_content_arr['maybe_blur_css_class'] ); ?>">
453 * ...
454 * </div>
455 */
456 function wpbc_get_upgrade_widget( $params ) {
457
458 $defaults = array(
459 'id' => 'wpbc_random_' . round( microtime( true ) * 1000 ), //$id . '_' . 'weekdays_conditions',
460 'blured_in_versions' => array( 'free', 'ps', 'bs', 'bm', 'bl', 'mu' ),
461 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
462 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
463 'versions' => 'Business Large, MultiUser versions',
464 'css' => 'transform: translate(0) translateY(120px);',
465 'dismiss_css_class' => '', //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions'
466 'no_dismiss' => false
467 );
468 $params = wp_parse_args( $params, $defaults );
469 $up_id = $params['id'];
470
471
472 $is_blured = wpbc_is_blured( $params['blured_in_versions'] );
473
474 $upgrade_panel_html = '';
475 $blur_css_class = '';
476
477 if ( $is_blured ) {
478
479 if ( $params['no_dismiss'] ) {
480 $is_upgrade_panel_visible = true;
481 $html_dismiss_btn = '';
482 } else {
483 // ---------------------------------------------------------------------------------------------------------
484 // Is dismissed ?
485 // ---------------------------------------------------------------------------------------------------------
486 ob_start();
487 $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array(
488 'title' => '<span aria-hidden="true" style="font-size: 28px;">&times;</span>',
489 'hint' => __( 'Dismiss', 'booking' ),
490 'class' => 'wpbc_panel_get_started_dismiss',
491 'css' => '',
492 'dismiss_css_class' => $params['dismiss_css_class']
493 ) );
494 $html_dismiss_btn = ob_get_clean();
495 }
496
497 // ---------------------------------------------------------------------------------------------------------
498 // Upgrade Widget
499 // ---------------------------------------------------------------------------------------------------------
500 if ( $is_upgrade_panel_visible ) {
501
502 $upgrade_panel_html = wpbc_get__upgrade_notice__html_content( $up_id, array(
503 'feature_link' => $params['feature_link'],
504 'upgrade_link' => $params['upgrade_link'],
505 'versions' => $params['versions'],
506 'css' => $params['css'],
507 'dismiss_css_class' => $params['dismiss_css_class'],
508 'html_dismiss_btn'=> $html_dismiss_btn
509 ) );
510 $blur_css_class = 'wpbc_blur';
511 } else {
512
513 ob_start();
514
515 ?><script type="text/javascript">
516 jQuery(document).ready(function(){
517 setTimeout(function(){
518 jQuery( '<?php echo esc_attr( $params['dismiss_css_class'] ); ?>' ).hide() ;
519 }, 100);
520 });
521 </script><?php
522
523 $upgrade_panel_html = ob_get_clean();
524 }
525 }
526
527 $upgrade_content_arr = array(
528 'content' => $upgrade_panel_html,
529 'maybe_blur_css_class' => $blur_css_class
530 );
531
532 return $upgrade_content_arr;
533
534 }
535
536
537 /**
538 * How old ago was installed plugin, based on first booking
539 *
540 * @return int if -1, then no bookings!
541 */
542 function wpbc_how_old_in_days() {
543
544 $how_old = wpbc_get_info__about_how_old();
545
546 if ( ! empty( $how_old ) ) {
547 return intval( $how_old['days'] );
548 } else {
549 // Unknown. Maybe no bookings
550 return -1;
551 }
552 }
553
554 /**
555 * Get date info about first booking.
556 * @return array|false
557 */
558 function wpbc_get_info__about_how_old() {
559 global $wpdb;
560
561 $sql = "SELECT modification_date FROM {$wpdb->prefix}booking as bk ORDER by booking_id LIMIT 0,1";
562 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
563 $res = $wpdb->get_results( $sql );
564
565 if ( ! empty( $res ) ) {
566
567 $first_booking_date = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s', strtotime( $res[0]->modification_date ) ), 'Y-m-d H:i:s' );
568
569 $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 ) ) );
570
571 return array(
572 'date_ymd_his' => $res[0]->modification_date,
573 'date_echo' => $first_booking_date,
574 'days' => $dif_days
575 );
576 }
577
578 return false;
579 }
580