| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -17,50 +17,129 @@ | ||
| 17 | 17 | // ===================================================================================================================== |
| 18 | 18 | // == Versions == |
| 19 | 19 | // ===================================================================================================================== |
| 20 | 20 | |
| 21 | -/** | |
| 22 | - * Check if this demo website | |
| 23 | - * | |
| 24 | - * @return bool | |
| 25 | - */ | |
| 26 | -function wpbc_is_this_demo() { | |
| 21 | +/** | |
| 22 | + * Check whether the site is a managed public Booking Calendar live demo. | |
| 23 | + * | |
| 24 | + * This compatibility helper delegates to the shared environment policy so | |
| 25 | + * legacy consumers and newer capability checks cannot classify the same host | |
| 26 | + * differently. | |
| 27 | + * | |
| 28 | + * @return bool True for a managed public live demo. | |
| 29 | + */ | |
| 30 | +function wpbc_is_this_demo() { | |
| 31 | + return WPBC_Environment_Policy::is_live_demo(); | |
| 32 | +} | |
| 27 | 33 | |
| 28 | - // return false; //. | |
| 29 | 34 | |
| 30 | - if ( ! class_exists( 'wpdev_bk_personal' ) ) { | |
| 31 | - return false; // If this is Booking Calendar Free version, then it's not the demo. | |
| 32 | - } | |
| 35 | +/** | |
| 36 | + * Determine whether the current request uses the local beta hostname. | |
| 37 | + * | |
| 38 | + * The comparison intentionally ignores a port and one trailing DNS dot. It | |
| 39 | + * does not classify beta subdomains or path names as the trusted beta host. | |
| 40 | + * | |
| 41 | + * @return bool True only for an HTTP Host whose normalized hostname is `beta`. | |
| 42 | + */ | |
| 43 | +function wpbc_is_this_beta() { | |
| 44 | + $http_host = isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : ''; | |
| 45 | + $http_host = wp_parse_url( 'http://' . ltrim( strtolower( $http_host ), '/' ), PHP_URL_HOST ); | |
| 46 | + $is_beta = is_string( $http_host ) && ( 'beta' === rtrim( $http_host, '.' ) ); | |
| 47 | + | |
| 48 | + return $is_beta; | |
| 49 | +} | |
| 33 | 50 | |
| 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 | - } | |
| 51 | + | |
| 52 | +/** Get Warning Text for Demo websites */ | |
| 53 | +function wpbc_get_warning_text_in_demo_mode() { | |
| 54 | + // 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 | |
| 55 | + return '<div class="wpbc-settings-notice notice-warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>'; | |
| 40 | 56 | } |
| 41 | 57 | |
| 42 | 58 | |
| 43 | -/** | |
| 44 | - * Check if this Beta Demo website | |
| 45 | - * | |
| 46 | - * @return bool | |
| 47 | - */ | |
| 48 | -function wpbc_is_this_beta() { | |
| 59 | +function wpbc_get_wpbc_versions_numbers() { | |
| 49 | 60 | |
| 50 | - $is_beta = ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ); | |
| 61 | + $version_numbers = array(); | |
| 51 | 62 | |
| 52 | - return $is_beta; | |
| 53 | -} | |
| 63 | + if ( defined( 'WP_BK_VERSION_NUM' ) ) { | |
| 64 | + $version_numbers [] = WP_BK_VERSION_NUM; | |
| 65 | + } else { | |
| 66 | + $version_numbers [] = ( defined( 'WPDEV_BK_VERSION' ) ) ? WPDEV_BK_VERSION : 'N/A'; | |
| 67 | + } | |
| 54 | 68 | |
| 69 | + if ( defined( 'WPBC_PRO_VERSION_NUM' ) ) { | |
| 70 | + if ( ( count( $version_numbers ) > 0 ) && ( $version_numbers[0] !== WPBC_PRO_VERSION_NUM ) ) { | |
| 71 | + $version_numbers [] = WPBC_PRO_VERSION_NUM; | |
| 72 | + } | |
| 73 | + } | |
| 55 | 74 | |
| 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 | -} | |
| 75 | + $version_numbers_str = implode( ' | ', $version_numbers ); | |
| 61 | 76 | |
| 77 | + return $version_numbers_str; | |
| 78 | +} | |
| 79 | + | |
| 80 | + | |
| 81 | +/** | |
| 82 | + * Prevent the legacy Pro Simple booking form branch from requiring a removed Free file. | |
| 83 | + * | |
| 84 | + * Pro versions before 11.4 require `page-form-simple.php` only when the legacy | |
| 85 | + * `booking_is_use_simple_booking_form` option is enabled. Newer Free versions no longer contain that file. Because the | |
| 86 | + * Pro loader runs on `wpbc_loaded_php_files`, this check must happen immediately before that action is fired; waiting | |
| 87 | + * until `plugins_loaded` is too late and can result in a fatal `require_once` error. Other legacy Pro configurations | |
| 88 | + * remain loadable for the mixed-version compatibility layer. | |
| 89 | + * | |
| 90 | + * @return bool True when an incompatible Pro loader was removed, otherwise false. | |
| 91 | + */ | |
| 92 | +function wpbc_prevent_incompatible_pro_version_loading() { | |
| 93 | + | |
| 94 | + $pro_loader_priority = has_action( 'wpbc_loaded_php_files', 'wpbc_pro_load_php_files' ); | |
| 95 | + | |
| 96 | + if ( false === $pro_loader_priority ) { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + $is_legacy_pro_version = ( | |
| 101 | + ! defined( 'WPBC_PRO_VERSION_NUM' ) | |
| 102 | + || version_compare( WPBC_PRO_VERSION_NUM, WP_BK_PRO_BFB_ONLY_VERSION, '<' ) | |
| 103 | + ); | |
| 104 | + $is_legacy_simple_form_enabled = ( 'On' === get_bk_option( 'booking_is_use_simple_booking_form' ) ); | |
| 105 | + $is_legacy_simple_form_missing = ! file_exists( WPBC_PLUGIN_DIR . '/includes/page-form-simple/page-form-simple.php' ); | |
| 106 | + | |
| 107 | + if ( ! $is_legacy_pro_version || ! $is_legacy_simple_form_enabled || ! $is_legacy_simple_form_missing ) { | |
| 108 | + return false; | |
| 109 | + } | |
| 110 | + | |
| 111 | + remove_action( 'wpbc_loaded_php_files', 'wpbc_pro_load_php_files', $pro_loader_priority ); | |
| 112 | + | |
| 113 | + if ( is_admin() ) { | |
| 114 | + add_action( 'admin_notices', 'wpbc_show_error__legacy_simple_form_pro_version' ); | |
| 115 | + } | |
| 116 | + | |
| 117 | + return true; | |
| 118 | +} | |
| 119 | + | |
| 120 | + | |
| 121 | +/** | |
| 122 | + * Show an actionable notice after the legacy Simple booking form Pro loader has been disabled. | |
| 123 | + * | |
| 124 | + * @return void | |
| 125 | + */ | |
| 126 | +function wpbc_show_error__legacy_simple_form_pro_version() { | |
| 127 | + | |
| 128 | + $pro_version = defined( 'WPBC_PRO_VERSION_NUM' ) ? WPBC_PRO_VERSION_NUM : __( 'unknown', 'booking' ); | |
| 129 | + | |
| 130 | + $message = sprintf( | |
| 131 | + /* translators: 1: Installed Pro version, 2: Installed Free version, 3: First Pro version without legacy form pages. */ | |
| 132 | + __( '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' ), | |
| 133 | + '<strong>' . esc_html( $pro_version ) . '</strong>', | |
| 134 | + '<strong>' . esc_html( WP_BK_VERSION_NUM ) . '</strong>', | |
| 135 | + '<strong>' . esc_html( WP_BK_PRO_BFB_ONLY_VERSION ) . '</strong>' | |
| 136 | + ); | |
| 137 | + | |
| 138 | + echo '<div class="notice notice-error"><p>' . wp_kses_post( $message ) . '</p></div>'; | |
| 139 | +} | |
| 62 | 140 | |
| 141 | + | |
| 63 | 142 | function wpbc_get_version_type__and_mu(){ |
| 64 | 143 | $version = 'free'; |
| 65 | 144 | if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal'; |
| 66 | 145 | if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s'; |
| @@ -81,8 +160,40 @@ | ||
| 81 | 160 | } |
| 82 | 161 | |
| 83 | 162 | |
| 84 | 163 | /** |
| 164 | + * Get Title of the version type. | |
| 165 | + * | |
| 166 | + * @return string | |
| 167 | + */ | |
| 168 | +function wpbc_get_plugin_version_title() { | |
| 169 | + $title = 'Free'; | |
| 170 | + $version_type = wpbc_get_version_type__and_mu(); | |
| 171 | + switch ( $version_type ) { | |
| 172 | + case 'personal': | |
| 173 | + $title = 'Personal'; | |
| 174 | + break; | |
| 175 | + case 'biz_s': | |
| 176 | + $title = 'Business Small'; | |
| 177 | + break; | |
| 178 | + case 'biz_m': | |
| 179 | + $title = 'Business Medium'; | |
| 180 | + break; | |
| 181 | + case 'biz_l': | |
| 182 | + $title = 'Business Large'; | |
| 183 | + break; | |
| 184 | + case 'multiuser': | |
| 185 | + $title = 'MultiUser'; | |
| 186 | + break; | |
| 187 | + default: | |
| 188 | + $title = 'Free'; | |
| 189 | + } | |
| 190 | + | |
| 191 | + return $title; | |
| 192 | +} | |
| 193 | + | |
| 194 | + | |
| 195 | +/** | |
| 85 | 196 | * Check if user accidentially update Booking Calendar Paid version to Free |
| 86 | 197 | * |
| 87 | 198 | * @return bool |
| 88 | 199 | */ |
| @@ -95,30 +206,89 @@ | ||
| 95 | 206 | } |
| 96 | 207 | |
| 97 | 208 | |
| 98 | 209 | function wpbc_get_ver_sufix() { |
| 99 | - if( strpos( strtolower(WPDEV_BK_VERSION) , 'multisite') !== false ) { | |
| 210 | + if ( strpos( strtolower( WPDEV_BK_VERSION ), 'multisite' ) !== false ) { | |
| 100 | 211 | $v_type = '-multi'; |
| 101 | - } else if( strpos( strtolower(WPDEV_BK_VERSION) , 'develop') !== false ) { | |
| 212 | + } else if ( strpos( strtolower( WPDEV_BK_VERSION ), 'develop' ) !== false ) { | |
| 102 | 213 | $v_type = '-dev'; |
| 103 | 214 | } else { |
| 104 | 215 | $v_type = ''; |
| 105 | 216 | } |
| 106 | 217 | $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 ; | |
| 218 | + if ( class_exists( 'wpdev_bk_personal' ) ) { | |
| 219 | + $v = 'ps' . $v_type; | |
| 220 | + } | |
| 221 | + if ( class_exists( 'wpdev_bk_biz_s' ) ) { | |
| 222 | + $v = 'bs' . $v_type; | |
| 223 | + } | |
| 224 | + if ( class_exists( 'wpdev_bk_biz_m' ) ) { | |
| 225 | + $v = 'bm' . $v_type; | |
| 226 | + } | |
| 227 | + if ( class_exists( 'wpdev_bk_biz_l' ) ) { | |
| 228 | + $v = 'bl' . $v_type; | |
| 229 | + } | |
| 230 | + if ( class_exists( 'wpdev_bk_multiuser' ) ) { | |
| 231 | + $v = ''; | |
| 232 | + } | |
| 233 | + | |
| 234 | + return $v; | |
| 113 | 235 | } |
| 114 | 236 | |
| 115 | 237 | |
| 238 | +/** | |
| 239 | + * Is show upgrade link. | |
| 240 | + * | |
| 241 | + * @return bool | |
| 242 | + */ | |
| 243 | +function wpbc_is_show_up() { | |
| 244 | + | |
| 245 | + // $is_show_up = get_bk_option( 'booking_wpdev_copyright_adminpanel' ); | |
| 246 | + // $is_show_up = ( ( 'Off' !== $is_show_up ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) ); | |
| 247 | + // return $is_show_up; | |
| 248 | + | |
| 249 | + $is_show_up = ( ( 'hide' !== get_bk_option( 'booking_menu_go_pro' ) ) && ( ! class_exists( 'wpdev_bk_multiuser' ) ) ); | |
| 250 | + | |
| 251 | + return $is_show_up; | |
| 252 | +} | |
| 253 | + | |
| 254 | + | |
| 255 | +/** | |
| 256 | + * Check whether Free-edition upgrade navigation may be shown. | |
| 257 | + * | |
| 258 | + * This combines the existing administrator preference and MultiUser policy | |
| 259 | + * with the product-edition check used by Free-only upgrade actions. | |
| 260 | + * | |
| 261 | + * @since 11.8.0 | |
| 262 | + * | |
| 263 | + * @return bool True when Free-edition upgrade navigation may be rendered. | |
| 264 | + */ | |
| 265 | +function wpbc_is_show_free_upgrade() { | |
| 266 | + | |
| 267 | + return wpbc_is_show_up() && ! class_exists( 'wpdev_bk_personal' ); | |
| 268 | +} | |
| 269 | + | |
| 270 | + | |
| 271 | +/** | |
| 272 | + * Get Up link. | |
| 273 | + * | |
| 274 | + * @return string | |
| 275 | + */ | |
| 116 | 276 | 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 . '/' ) ; | |
| 277 | + | |
| 278 | + if ( ! wpbc_is_this_demo() ) { | |
| 279 | + $v = wpbc_get_ver_sufix(); | |
| 280 | + } else { | |
| 281 | + $v = ''; | |
| 282 | + } | |
| 283 | + | |
| 284 | + if ( empty( $v ) ) { | |
| 285 | + $v = 'features/'; | |
| 286 | + } else { | |
| 287 | + $v = 'upgrade-' . $v . '/'; | |
| 288 | + } | |
| 289 | + | |
| 290 | + return 'https://wpbookingcalendar.com/' . $v; | |
| 121 | 291 | } |
| 122 | 292 | |
| 123 | 293 | |
| 124 | 294 | /** |
| @@ -181,8 +351,37 @@ | ||
| 181 | 351 | return $file_data; |
| 182 | 352 | } |
| 183 | 353 | |
| 184 | 354 | |
| 355 | +function wpbc_get_json_property_from_meta( $property_key ) { | |
| 356 | + | |
| 357 | + if ( ! defined( 'WPBC_PRO_FILE' ) ) { | |
| 358 | + return null; | |
| 359 | + } | |
| 360 | + | |
| 361 | + $meta_file_path = plugin_dir_path( WPBC_PRO_FILE ) . 'meta.json'; | |
| 362 | + | |
| 363 | + if ( ( ! is_file( $meta_file_path ) ) || ( ! is_readable( $meta_file_path ) ) ) { | |
| 364 | + return null; | |
| 365 | + } | |
| 366 | + | |
| 367 | + // Read the local plugin metadata directly, so hosts with FTP-based WP_Filesystem settings cannot fatal here. | |
| 368 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 369 | + $json_contents = file_get_contents( $meta_file_path ); | |
| 370 | + | |
| 371 | + if ( false === $json_contents || '' === trim( $json_contents ) ) { | |
| 372 | + return null; | |
| 373 | + } | |
| 374 | + | |
| 375 | + $data = json_decode( $json_contents, true ); | |
| 376 | + | |
| 377 | + if ( ( json_last_error() !== JSON_ERROR_NONE ) || ( ! is_array( $data ) ) ) { | |
| 378 | + return null; | |
| 379 | + } | |
| 380 | + | |
| 381 | + return array_key_exists( $property_key, $data ) ? $data[ $property_key ] : null; | |
| 382 | +} | |
| 383 | + | |
| 185 | 384 | /** |
| 186 | 385 | * Check if we need BLUR this section -- add CSS Class for specific versions |
| 187 | 386 | * |
| 188 | 387 | * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions. |
| @@ -349,9 +548,10 @@ | ||
| 349 | 548 | 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ), |
| 350 | 549 | 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ), |
| 351 | 550 | 'versions' => 'Business Large, MultiUser versions', |
| 352 | 551 | 'css' => 'transform: translate(0) translateY(120px);', |
| 353 | - 'dismiss_css_class' => '' //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions' | |
| 552 | + 'dismiss_css_class' => '', //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions' | |
| 553 | + 'no_dismiss' => false | |
| 354 | 554 | ); |
| 355 | 555 | $params = wp_parse_args( $params, $defaults ); |
| 356 | 556 | $up_id = $params['id']; |
| 357 | 557 | |
| @@ -362,20 +562,25 @@ | ||
| 362 | 562 | $blur_css_class = ''; |
| 363 | 563 | |
| 364 | 564 | if ( $is_blured ) { |
| 365 | 565 | |
| 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;">×</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(); | |
| 566 | + if ( $params['no_dismiss'] ) { | |
| 567 | + $is_upgrade_panel_visible = true; | |
| 568 | + $html_dismiss_btn = ''; | |
| 569 | + } else { | |
| 570 | + // --------------------------------------------------------------------------------------------------------- | |
| 571 | + // Is dismissed ? | |
| 572 | + // --------------------------------------------------------------------------------------------------------- | |
| 573 | + ob_start(); | |
| 574 | + $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array( | |
| 575 | + 'title' => '<span aria-hidden="true" style="font-size: 28px;">×</span>', | |
| 576 | + 'hint' => __( 'Dismiss', 'booking' ), | |
| 577 | + 'class' => 'wpbc_panel_get_started_dismiss', | |
| 578 | + 'css' => '', | |
| 579 | + 'dismiss_css_class' => $params['dismiss_css_class'] | |
| 580 | + ) ); | |
| 581 | + $html_dismiss_btn = ob_get_clean(); | |
| 582 | + } | |
| 378 | 583 | |
| 379 | 584 | // --------------------------------------------------------------------------------------------------------- |
| 380 | 585 | // Upgrade Widget |
| 381 | 586 | // --------------------------------------------------------------------------------------------------------- |
| @@ -440,9 +645,9 @@ | ||
| 440 | 645 | function wpbc_get_info__about_how_old() { |
| 441 | 646 | global $wpdb; |
| 442 | 647 | |
| 443 | 648 | $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 | |
| 649 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 445 | 650 | $res = $wpdb->get_results( $sql ); |
| 446 | 651 | |
| 447 | 652 | if ( ! empty( $res ) ) { |
| 448 | 653 | |