| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: VikBooking |
| 4 | 4 | Plugin URI: https://vikwp.com/plugin/vikbooking |
| 5 | 5 | Description: Certified Booking Engine for Hotels and Accommodations. |
| 6 | -Version: 1.7.1 | |
| 6 | +Version: 1.8.16 | |
| 7 | 7 | Author: E4J s.r.l. |
| 8 | 8 | Author URI: https://vikwp.com |
| 9 | 9 | License: GPL2 |
| 10 | 10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| @@ -77,8 +77,9 @@ | ||
| 77 | 77 | add_action('plugins_loaded', array('VikBookingBuilder', 'setupOverridesManager')); |
| 78 | 78 | |
| 79 | 79 | // setup lite system |
| 80 | 80 | add_action('plugins_loaded', array('VikBookingLiteManager', 'setup')); |
| 81 | +add_action('plugins_loaded', array('VikChannelManagerLiteManager', 'setup')); | |
| 81 | 82 | |
| 82 | 83 | /** |
| 83 | 84 | * Added support for screen options. |
| 84 | 85 | * Parameters such as the list limit can be changed from there. |
| @@ -105,21 +106,8 @@ | ||
| 105 | 106 | { |
| 106 | 107 | // installer class will check the update status |
| 107 | 108 | VikBookingInstaller::update(); |
| 108 | 109 | |
| 109 | - /** | |
| 110 | - * | |
| 111 | - * Fires once the plugins have loaded. | |
| 112 | - * | |
| 113 | - * Language is loaded through the filter 'plugins_loaded' in order to avoid to load language | |
| 114 | - * before the correct one has been set by WordPress or by another third-party plugin. | |
| 115 | - * | |
| 116 | - * @link https://developer.wordpress.org/reference/hooks/plugins_loaded/ | |
| 117 | - * | |
| 118 | - * @since 1.4.2 | |
| 119 | - */ | |
| 120 | - VikBookingBuilder::loadLanguage(); | |
| 121 | - | |
| 122 | 110 | global $pagenow; |
| 123 | 111 | |
| 124 | 112 | $app = JFactory::getApplication(); |
| 125 | 113 | $input = $app->input; |
| @@ -161,8 +149,15 @@ | ||
| 161 | 149 | |
| 162 | 150 | // process the request and obtain the response |
| 163 | 151 | add_action('init', function() |
| 164 | 152 | { |
| 153 | + /** | |
| 154 | + * Language files should no longer be loaded during 'plugins_loaded'. | |
| 155 | + * | |
| 156 | + * @since 1.7.6 | |
| 157 | + */ | |
| 158 | + VikBookingBuilder::loadLanguage(); | |
| 159 | + | |
| 165 | 160 | $app = JFactory::getApplication(); |
| 166 | 161 | $input = $app->input; |
| 167 | 162 | |
| 168 | 163 | // if we are in the front-end, try to parse the URL to inject |
| @@ -220,8 +215,16 @@ | ||
| 220 | 215 | |
| 221 | 216 | // register widgets |
| 222 | 217 | add_action('widgets_init', array('VikBookingBuilder', 'setupWidgets')); |
| 223 | 218 | |
| 219 | +/** | |
| 220 | + * Load plugin language when registering the widgets as well. | |
| 221 | + * Since translations are now loaded at "init", they might not be available yet. | |
| 222 | + * | |
| 223 | + * @since 1.8.4 | |
| 224 | + */ | |
| 225 | +add_action('widgets_init', ['VikBookingBuilder', 'loadLanguage'], 1); | |
| 226 | + | |
| 224 | 227 | // handle shortcodes (SITE controller dispatcher) |
| 225 | 228 | add_shortcode('vikbooking', function($atts, $content = null) |
| 226 | 229 | { |
| 227 | 230 | $app = JFactory::getApplication(); |
| @@ -343,8 +346,18 @@ | ||
| 343 | 346 | VikBooking::getTracker(); |
| 344 | 347 | VikBooking::loadPreferredColorStyles(); |
| 345 | 348 | } |
| 346 | 349 | |
| 350 | + /** | |
| 351 | + * Prevent some pages from performing an auto-redirect when running | |
| 352 | + * the Bricks plugin preview. | |
| 353 | + * | |
| 354 | + * @since 1.7.7 | |
| 355 | + */ | |
| 356 | + if ($app->input->get('bricks') === 'run' && in_array($app->input->get('view'), ['tinyurl'])) | |
| 357 | + { | |
| 358 | + $app->input->set('view', ''); | |
| 359 | + } | |
| 347 | 360 | }); |
| 348 | 361 | |
| 349 | 362 | // instead using the default server timezone, try to use the one |
| 350 | 363 | // specified within the WordPress configuration |
| @@ -599,12 +612,53 @@ | ||
| 599 | 612 | VBOModelPayschedules::getInstance()->watch(); |
| 600 | 613 | }); |
| 601 | 614 | |
| 602 | 615 | /** |
| 616 | + * Action used to register a periodic performance cleaning check. | |
| 617 | + * This hook will be called by a scheduled event in WP-Cron. | |
| 618 | + * | |
| 619 | + * @since 1.7.2 | |
| 620 | + * @since 1.8.7 scheduled DAC expired passcodes cleaning. | |
| 621 | + */ | |
| 622 | +add_action('vikbooking_cron_performance_cleaner', function() | |
| 623 | +{ | |
| 624 | + // performance cleaning check | |
| 625 | + VBOPerformanceCleaner::runCheck(); | |
| 626 | + // clean up expired passcodes from smart locks | |
| 627 | + VBOFactory::getDoorAccessControl()->cleanExpiredPasscodes(); | |
| 628 | +}); | |
| 629 | + | |
| 630 | +/** | |
| 631 | + * Action used to register a periodic check of door-access-control framework. | |
| 632 | + * This hook will be called by a scheduled event in WP-Cron. | |
| 633 | + * | |
| 634 | + * @since 1.8.4 | |
| 635 | + * @since 1.8.6 added support to watch the devices first access. | |
| 636 | + */ | |
| 637 | +add_action('vikbooking_cron_door_access_control', function() | |
| 638 | +{ | |
| 639 | + // watch if any booking is approaching the check-in date | |
| 640 | + VBOFactory::getDoorAccessControl()->handleUpcomingArrivals(); | |
| 641 | + // watch if passcodes get used for the first time | |
| 642 | + VBOFactory::getDoorAccessControl()->watchFirstAccess(); | |
| 643 | +}); | |
| 644 | + | |
| 645 | +/** | |
| 646 | + * Action used to register a periodic database cleaning check. | |
| 647 | + * This hook will be called by a scheduled event in WP-Cron. | |
| 648 | + * | |
| 649 | + * @since 1.8.5 | |
| 650 | + */ | |
| 651 | +add_action('vikbooking_cron_db_optimization', ['VBOPerformanceCleaner', 'optimizeDatabase']); | |
| 652 | + | |
| 653 | +/** | |
| 603 | 654 | * Install the scheduling of the hook within WP-Cron needed |
| 604 | 655 | * to watch and process the automatic payments scheduled. |
| 605 | 656 | * |
| 606 | 657 | * @since 1.6.10 |
| 658 | + * @since 1.7.2 registered "vikbooking_cron_performance_cleaner". | |
| 659 | + * @since 1.8.4 registered "vikbooking_cron_door_access_control". | |
| 660 | + * @since 1.8.5 registered "vikbooking_cron_db_optimization". | |
| 607 | 661 | */ |
| 608 | 662 | add_action('plugins_loaded', function() |
| 609 | 663 | { |
| 610 | 664 | // make sure the cron event hasn't been yet scheduled. |
| @@ -613,8 +667,29 @@ | ||
| 613 | 667 | // schedule event starting from the current time for "every half hour" |
| 614 | 668 | // such interval will be installed by VikBookingCron::setup() |
| 615 | 669 | wp_schedule_event(time(), 'half_hour', 'vikbooking_cron_payments_scheduled'); |
| 616 | 670 | } |
| 671 | + | |
| 672 | + // make sure the cron event hasn't been yet scheduled. | |
| 673 | + if (!wp_next_scheduled('vikbooking_cron_performance_cleaner')) | |
| 674 | + { | |
| 675 | + // schedule event starting from the current time for "every week" | |
| 676 | + wp_schedule_event(time(), 'weekly', 'vikbooking_cron_performance_cleaner'); | |
| 677 | + } | |
| 678 | + | |
| 679 | + // make sure the cron event hasn't been yet scheduled. | |
| 680 | + if (!wp_next_scheduled('vikbooking_cron_door_access_control')) | |
| 681 | + { | |
| 682 | + // schedule event starting from the current time for "every hour" | |
| 683 | + wp_schedule_event(time(), 'hourly', 'vikbooking_cron_door_access_control'); | |
| 684 | + } | |
| 685 | + | |
| 686 | + // make sure the cron event hasn't been yet scheduled. | |
| 687 | + if (!wp_next_scheduled('vikbooking_cron_db_optimization')) | |
| 688 | + { | |
| 689 | + // schedule event starting from the current time for "every hour" | |
| 690 | + wp_schedule_event(time(), 'hourly', 'vikbooking_cron_db_optimization'); | |
| 691 | + } | |
| 617 | 692 | }, (PHP_INT_MAX - 1)); |
| 618 | 693 | |
| 619 | 694 | /** |
| 620 | 695 | * Filters the action links displayed for each plugin in the Plugins list table. |
| @@ -796,8 +871,46 @@ | ||
| 796 | 871 | <?php |
| 797 | 872 | }); |
| 798 | 873 | |
| 799 | 874 | /** |
| 875 | + * Detect outdated VCM versions. | |
| 876 | + * | |
| 877 | + * @since 1.8.13 | |
| 878 | + */ | |
| 879 | +add_action('admin_notices', function() | |
| 880 | +{ | |
| 881 | + global $pagenow; | |
| 882 | + | |
| 883 | + if (wp_doing_ajax()) | |
| 884 | + { | |
| 885 | + // nothing to check | |
| 886 | + return; | |
| 887 | + } | |
| 888 | + | |
| 889 | + $option = JFactory::getApplication()->input->get('option'); | |
| 890 | + $inPlugins = in_array($option, ['com_vikbooking', 'com_vikchannelmanager']); | |
| 891 | + | |
| 892 | + if (!$inPlugins && $pagenow != 'plugins.php') | |
| 893 | + { | |
| 894 | + // nothing to check | |
| 895 | + return; | |
| 896 | + } | |
| 897 | + | |
| 898 | + if (!defined('VIKCHANNELMANAGER_SOFTWARE_VERSION') || version_compare(VIKCHANNELMANAGER_SOFTWARE_VERSION, VIKCHANNELMANAGER_MINIMUM_VERSION, '>=')) | |
| 899 | + { | |
| 900 | + // check passed | |
| 901 | + return; | |
| 902 | + } | |
| 903 | + | |
| 904 | + echo JLayoutHelper::render( | |
| 905 | + 'html.vcm.version', | |
| 906 | + ['page' => $inPlugins ? preg_replace('/^com_/', '', $option) : $pagenow], | |
| 907 | + null, | |
| 908 | + ['component' => 'com_vikbooking'] | |
| 909 | + ); | |
| 910 | +}); | |
| 911 | + | |
| 912 | +/** | |
| 800 | 913 | * Downloads the RSS feeds after loading the dashboard of VikBooking. |
| 801 | 914 | * |
| 802 | 915 | * @since 1.3.9 |
| 803 | 916 | */ |
| @@ -869,8 +982,18 @@ | ||
| 869 | 982 | $input = $app->input; |
| 870 | 983 | |
| 871 | 984 | // make sure we are not inside Vik Booking |
| 872 | 985 | if ($input->get('option') == 'com_vikbooking' || $input->get('page') == 'vikbooking' || $input->get('action') == 'vikbooking') |
| 986 | + { | |
| 987 | + return; | |
| 988 | + } | |
| 989 | + | |
| 990 | + /** | |
| 991 | + * Avoid conflicts with third-party page-builder plugins that may simulate the front-end. | |
| 992 | + * | |
| 993 | + * @since 1.8.1 | |
| 994 | + */ | |
| 995 | + if (!$app->isClient('administrator')) | |
| 873 | 996 | { |
| 874 | 997 | return; |
| 875 | 998 | } |
| 876 | 999 | |