PluginProbe
Booking Calendar / 11.0
Booking Calendar v11.0
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 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / _functions / versions.php

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

572 lines 18.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 * 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 ( ( ! is_file( $meta_file_path ) ) || ( ! is_readable( $meta_file_path ) ) ) {
269 return null;
270 }
271
272 // Read the local plugin metadata directly, so hosts with FTP-based WP_Filesystem settings cannot fatal here.
273 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
274 $json_contents = file_get_contents( $meta_file_path );
275
276 if ( false === $json_contents || '' === trim( $json_contents ) ) {
277 return null;
278 }
279
280 $data = json_decode( $json_contents, true );
281
282 if ( ( json_last_error() !== JSON_ERROR_NONE ) || ( ! is_array( $data ) ) ) {
283 return null;
284 }
285
286 return array_key_exists( $property_key, $data ) ? $data[ $property_key ] : null;
287 }
288
289 /**
290 * Check if we need BLUR this section -- add CSS Class for specific versions
291 *
292 * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions.
293 *
294 * @param $versions_arr
295 *
296 * @return void
297 */
298 function wpbc_is_blured( $versions_arr ){
299
300 $ver = wpbc_get_version_type__and_mu();
301
302 $is_blured = false;
303
304 switch ( $ver ) {
305 case 'free':
306 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'f', $versions_arr ) ) ) ? true : $is_blured;
307 break;
308 case 'personal':
309 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'ps', $versions_arr ) ) ) ? true : $is_blured;
310 break;
311 case 'biz_s':
312 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bs', $versions_arr ) ) ) ? true : $is_blured;
313 break;
314 case 'biz_m':
315 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bm', $versions_arr ) ) ) ? true : $is_blured;
316 break;
317 case 'biz_l':
318 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bl', $versions_arr ) ) ) ? true : $is_blured;
319 break;
320 case 'multiuser':
321 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'mu', $versions_arr ) ) ) ? true : $is_blured;
322 break;
323 default:
324 // Default
325 }
326 return $is_blured;
327 }
328
329
330 /**
331 * Echo Blur CSS Class for specific versions
332 *
333 * Example: wpbc_echo_blur(array('free','ps')); // Echo blur in Free and Personal versions.
334 *
335 * @param $versions_arr
336 *
337 * @return void
338 */
339 function wpbc_echo_blur( $versions_arr ){
340
341 $is_blured = wpbc_is_blured( $versions_arr );
342
343 if ( $is_blured ) {
344 echo 'wpbc_blur';
345 }
346 }
347
348
349 /**
350 * Show Upgrade Widget
351 *
352 * @param $id
353 * @param $params
354 *
355 * @return string if upgrade panel hided than returned ''
356 *
357 *
358 * Example:
359 * wpbc_get_up_notice('booking_weekdays_conditions', array(
360 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
361 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
362 * 'versions' => 'Business Large, MultiUser versions',
363 * 'css' => 'transform: translate(0) translateY(120px);'
364 * ));
365 */
366 function wpbc_get__upgrade_notice__html_content( $id, $params ){
367
368 $defaults = array(
369 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
370 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
371 'versions' => 'Business Large, MultiUser versions',
372 'css' => 'transform: translate(0) translateY(120px);',
373 'dismiss_css_class' => '',
374 'html_dismiss_btn' => ''
375 );
376 $params = wp_parse_args( $params, $defaults );
377
378 ob_start();
379
380 ?><div id="upgrade_notice_<?php echo esc_attr( $id ); ?>"
381 class="wpbc_widget_content wpbc_upgrade_widget <?php echo esc_attr( str_replace( array('.','#'), '', $params['dismiss_css_class'] ) ); ?>"
382 style="<?php echo esc_attr( $params['css'] ); ?>">
383 <div class="ui_container ui_container_toolbar ui_container_small wpbc_upgrade_widget_container">
384 <div class="ui_group ui_group__upgrade">
385 <div class="wpbc_upgrade_note wpbc_upgrade_theme_green">
386 <div>
387 <?php
388 echo wp_kses_post( sprintf( 'This %s is available in the %s. %s'
389 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['feature_link']['relative_url'] . '">' . $params['feature_link']['title'] . '</a>'
390 , '<strong>' . $params['versions'] . '</strong>'
391 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['upgrade_link']['relative_url'] . '">' . $params['upgrade_link']['title'] . '</a>'
392 ) );
393 ?>
394 </div>
395 <?php
396 // Dismiss button
397 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
398 echo $params['html_dismiss_btn'];
399 ?>
400 </div>
401 </div>
402 </div>
403 </div><?php
404
405 $html = ob_get_clean();
406
407 return $html ;
408 }
409
410
411 /**
412 * Get for showing Upgrade Widget Content and CSS class if needed to blur real content. If
413 *
414 * @param $params = array(
415 * 'id' => $id . '_' . 'weekdays_conditions',
416 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
417 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
418 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
419 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
420 * 'versions' => 'Business Medium / Large, MultiUser versions',
421 * 'css' => 'transform: translate(0) translateY(120px);'
422 * )
423 *
424 * @return array(
425 * 'content' => $upgrade_panel_html,
426 * 'maybe_blur_css_class' => $blur_css_class
427 * )
428 *
429 * Example of usage:
430 *
431 * $upgrade_content_arr = wpbc_get_upgrade_widget( array(
432 * 'id' => $id . '_' . 'weekdays_conditions',
433 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
434 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
435 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
436 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
437 * 'versions' => 'Business Medium / Large, MultiUser versions',
438 * 'css' => 'transform: translate(0) translateY(120px);'
439 * ) );
440 *
441 * echo $upgrade_content_arr['content'];
442 *
443 * // ... In real content ...
444 * <div class=" wpbc_dismiss_weekdays_conditions <?php echo esc_attr( $upgrade_content_arr['maybe_blur_css_class'] ); ?>">
445 * ...
446 * </div>
447 */
448 function wpbc_get_upgrade_widget( $params ) {
449
450 $defaults = array(
451 'id' => 'wpbc_random_' . round( microtime( true ) * 1000 ), //$id . '_' . 'weekdays_conditions',
452 'blured_in_versions' => array( 'free', 'ps', 'bs', 'bm', 'bl', 'mu' ),
453 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
454 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
455 'versions' => 'Business Large, MultiUser versions',
456 'css' => 'transform: translate(0) translateY(120px);',
457 'dismiss_css_class' => '', //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions'
458 'no_dismiss' => false
459 );
460 $params = wp_parse_args( $params, $defaults );
461 $up_id = $params['id'];
462
463
464 $is_blured = wpbc_is_blured( $params['blured_in_versions'] );
465
466 $upgrade_panel_html = '';
467 $blur_css_class = '';
468
469 if ( $is_blured ) {
470
471 if ( $params['no_dismiss'] ) {
472 $is_upgrade_panel_visible = true;
473 $html_dismiss_btn = '';
474 } else {
475 // ---------------------------------------------------------------------------------------------------------
476 // Is dismissed ?
477 // ---------------------------------------------------------------------------------------------------------
478 ob_start();
479 $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array(
480 'title' => '<span aria-hidden="true" style="font-size: 28px;">&times;</span>',
481 'hint' => __( 'Dismiss', 'booking' ),
482 'class' => 'wpbc_panel_get_started_dismiss',
483 'css' => '',
484 'dismiss_css_class' => $params['dismiss_css_class']
485 ) );
486 $html_dismiss_btn = ob_get_clean();
487 }
488
489 // ---------------------------------------------------------------------------------------------------------
490 // Upgrade Widget
491 // ---------------------------------------------------------------------------------------------------------
492 if ( $is_upgrade_panel_visible ) {
493
494 $upgrade_panel_html = wpbc_get__upgrade_notice__html_content( $up_id, array(
495 'feature_link' => $params['feature_link'],
496 'upgrade_link' => $params['upgrade_link'],
497 'versions' => $params['versions'],
498 'css' => $params['css'],
499 'dismiss_css_class' => $params['dismiss_css_class'],
500 'html_dismiss_btn'=> $html_dismiss_btn
501 ) );
502 $blur_css_class = 'wpbc_blur';
503 } else {
504
505 ob_start();
506
507 ?><script type="text/javascript">
508 jQuery(document).ready(function(){
509 setTimeout(function(){
510 jQuery( '<?php echo esc_attr( $params['dismiss_css_class'] ); ?>' ).hide() ;
511 }, 100);
512 });
513 </script><?php
514
515 $upgrade_panel_html = ob_get_clean();
516 }
517 }
518
519 $upgrade_content_arr = array(
520 'content' => $upgrade_panel_html,
521 'maybe_blur_css_class' => $blur_css_class
522 );
523
524 return $upgrade_content_arr;
525
526 }
527
528
529 /**
530 * How old ago was installed plugin, based on first booking
531 *
532 * @return int if -1, then no bookings!
533 */
534 function wpbc_how_old_in_days() {
535
536 $how_old = wpbc_get_info__about_how_old();
537
538 if ( ! empty( $how_old ) ) {
539 return intval( $how_old['days'] );
540 } else {
541 // Unknown. Maybe no bookings
542 return -1;
543 }
544 }
545
546 /**
547 * Get date info about first booking.
548 * @return array|false
549 */
550 function wpbc_get_info__about_how_old() {
551 global $wpdb;
552
553 $sql = "SELECT modification_date FROM {$wpdb->prefix}booking as bk ORDER by booking_id LIMIT 0,1";
554 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
555 $res = $wpdb->get_results( $sql );
556
557 if ( ! empty( $res ) ) {
558
559 $first_booking_date = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s', strtotime( $res[0]->modification_date ) ), 'Y-m-d H:i:s' );
560
561 $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 ) ) );
562
563 return array(
564 'date_ymd_his' => $res[0]->modification_date,
565 'date_echo' => $first_booking_date,
566 'days' => $dif_days
567 );
568 }
569
570 return false;
571 }
572