PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
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 10.11 10.11.2 All 203 releases
booking / includes / _functions / versions.php

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

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