| @@ -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.6.5 | |
| 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(); |
| @@ -269,8 +272,31 @@ | ||
| 269 | 272 | { |
| 270 | 273 | $input->def($k, $args->get($k)); |
| 271 | 274 | } |
| 272 | 275 | |
| 276 | + /** | |
| 277 | + * When saving a shortcode block through Gutenberg, | |
| 278 | + * WordPress tries to reach the page to check what happens. | |
| 279 | + * Some views of VikBooking may immediately redirect the users to | |
| 280 | + * another page URI. | |
| 281 | + * This redirect breaks the request made by WordPress for the | |
| 282 | + * validation of the page, which follows the new location. | |
| 283 | + * The code below prevents the execution of the controller | |
| 284 | + * in case the URI matches the REST API end-point. | |
| 285 | + * | |
| 286 | + * @since 1.7 | |
| 287 | + */ | |
| 288 | + $rest_prefix = trailingslashit(rest_get_url_prefix()); | |
| 289 | + $is_rest_api = strpos($input->server->getString('REQUEST_URI', ''), $rest_prefix) !== false | |
| 290 | + || JUri::getInstance($input->server->getString('REQUEST_URI', ''))->hasVar('rest_route') | |
| 291 | + || strpos($input->server->getString('REQUEST_URI', ''), '/wp-admin/') !== false; | |
| 292 | + | |
| 293 | + if ($is_rest_api && in_array($input->get('view'), ['tinyurl'])) | |
| 294 | + { | |
| 295 | + // return an empty string to prevent any redirects | |
| 296 | + return ''; | |
| 297 | + } | |
| 298 | + | |
| 273 | 299 | // dispatch the controller |
| 274 | 300 | return VikBookingBody::getHtml(true); |
| 275 | 301 | }); |
| 276 | 302 | |
| @@ -320,8 +346,18 @@ | ||
| 320 | 346 | VikBooking::getTracker(); |
| 321 | 347 | VikBooking::loadPreferredColorStyles(); |
| 322 | 348 | } |
| 323 | 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 | + } | |
| 324 | 360 | }); |
| 325 | 361 | |
| 326 | 362 | // instead using the default server timezone, try to use the one |
| 327 | 363 | // specified within the WordPress configuration |
| @@ -518,9 +554,8 @@ | ||
| 518 | 554 | * @todo should we restrict these filters to the post managements pages only? |
| 519 | 555 | */ |
| 520 | 556 | |
| 521 | 557 | VikBookingLoader::import('system.mce'); |
| 522 | - VikBookingLoader::import('system.gutenberg'); | |
| 523 | 558 | |
| 524 | 559 | // add new buttons |
| 525 | 560 | add_filter('mce_buttons', array('VikBookingTinyMCE', 'addShortcodesButton')); |
| 526 | 561 | |
| @@ -525,12 +560,17 @@ | ||
| 525 | 560 | add_filter('mce_buttons', array('VikBookingTinyMCE', 'addShortcodesButton')); |
| 526 | 561 | |
| 527 | 562 | // load the button handlers |
| 528 | 563 | add_filter('mce_external_plugins', array('VikBookingTinyMCE', 'registerShortcodesScript')); |
| 564 | +} | |
| 529 | 565 | |
| 530 | - // add support for Gutenberg shortcode block | |
| 531 | - add_action('init', array('VikBookingGutenberg', 'registerShortcodesScript')); | |
| 532 | -} | |
| 566 | +/** | |
| 567 | + * Always load the Gutenberg shortcodes block to support the preview rendering. | |
| 568 | + * | |
| 569 | + * @since 1.6.7 | |
| 570 | + */ | |
| 571 | +VikBookingLoader::import('system.gutenberg'); | |
| 572 | +add_action('init', ['VikBookingGutenberg', 'registerShortcodesScript']); | |
| 533 | 573 | |
| 534 | 574 | /** |
| 535 | 575 | * Dispatch the uninstallation of VikBooking |
| 536 | 576 | * every time a new blog (multisite) is deleted. |
| @@ -560,8 +600,99 @@ | ||
| 560 | 600 | */ |
| 561 | 601 | add_action('plugins_loaded', array('VikBookingCron', 'setup'), (PHP_INT_MAX - 1)); |
| 562 | 602 | |
| 563 | 603 | /** |
| 604 | + * Action used to register a periodic check of the automatic payments scheduled. | |
| 605 | + * This hook will be called by a scheduled event in WP-Cron. | |
| 606 | + * | |
| 607 | + * @since 1.6.10 | |
| 608 | + */ | |
| 609 | +add_action('vikbooking_cron_payments_scheduled', function() | |
| 610 | +{ | |
| 611 | + // watch the automatic payments scheduled, if any | |
| 612 | + VBOModelPayschedules::getInstance()->watch(); | |
| 613 | +}); | |
| 614 | + | |
| 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 | +/** | |
| 654 | + * Install the scheduling of the hook within WP-Cron needed | |
| 655 | + * to watch and process the automatic payments scheduled. | |
| 656 | + * | |
| 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". | |
| 661 | + */ | |
| 662 | +add_action('plugins_loaded', function() | |
| 663 | +{ | |
| 664 | + // make sure the cron event hasn't been yet scheduled. | |
| 665 | + if (!wp_next_scheduled('vikbooking_cron_payments_scheduled')) | |
| 666 | + { | |
| 667 | + // schedule event starting from the current time for "every half hour" | |
| 668 | + // such interval will be installed by VikBookingCron::setup() | |
| 669 | + wp_schedule_event(time(), 'half_hour', 'vikbooking_cron_payments_scheduled'); | |
| 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 | + } | |
| 692 | +}, (PHP_INT_MAX - 1)); | |
| 693 | + | |
| 694 | +/** | |
| 564 | 695 | * Filters the action links displayed for each plugin in the Plugins list table. |
| 565 | 696 | * Hook used to filter the "deactivation" link and ask a feedback every time that |
| 566 | 697 | * button is clicked. |
| 567 | 698 | * |
| @@ -740,8 +871,46 @@ | ||
| 740 | 871 | <?php |
| 741 | 872 | }); |
| 742 | 873 | |
| 743 | 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 | +/** | |
| 744 | 913 | * Downloads the RSS feeds after loading the dashboard of VikBooking. |
| 745 | 914 | * |
| 746 | 915 | * @since 1.3.9 |
| 747 | 916 | */ |
| @@ -818,8 +987,18 @@ | ||
| 818 | 987 | return; |
| 819 | 988 | } |
| 820 | 989 | |
| 821 | 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')) | |
| 996 | + { | |
| 997 | + return; | |
| 998 | + } | |
| 999 | + | |
| 1000 | + /** | |
| 822 | 1001 | * Let third party plugins stop Vik Booking from loading assets on other wp-admin pages. |
| 823 | 1002 | * |
| 824 | 1003 | * @since 1.6.1 |
| 825 | 1004 | */ |
| @@ -848,33 +1027,13 @@ | ||
| 848 | 1027 | JHtml::fetch('behavior.core'); |
| 849 | 1028 | }); |
| 850 | 1029 | |
| 851 | 1030 | /** |
| 852 | - * Fixed issue with wptexturize() function, which might convert special characters contained | |
| 853 | - * within <script> tags into their corresponding HTML entities (e.g. "&" became "&"). | |
| 1031 | + * Prevent WordPress Themes from running wptexturize() that may erroneously | |
| 1032 | + * detect HTML tags among raw JavaScript code, by encoding ampersand symbols. | |
| 854 | 1033 | * |
| 855 | - * @since 1.6.3 | |
| 1034 | + * @since 1.6.9 | |
| 856 | 1035 | */ |
| 857 | -add_filter('the_content', function($content) | |
| 1036 | +add_filter('run_wptexturize', function($run_texturize) | |
| 858 | 1037 | { |
| 859 | - // look for any script tags | |
| 860 | - if (preg_match_all("/<script(?:.*?)>(?:.*?)<\/script>/s", $content, $matches)) | |
| 861 | - { | |
| 862 | - // scan all the scripts | |
| 863 | - foreach ($matches[0] as $script) | |
| 864 | - { | |
| 865 | - // make sure the script contains "&" | |
| 866 | - if (strpos($script, '&') === false) | |
| 867 | - { | |
| 868 | - continue; | |
| 869 | - } | |
| 870 | - | |
| 871 | - // fix the script by reverting the plain "&" | |
| 872 | - $fixedScript = str_replace('&', '&', $script); | |
| 873 | - | |
| 874 | - // replace the bugged script from the content with the fixed one | |
| 875 | - $content = str_replace($script, $fixedScript, $content); | |
| 876 | - } | |
| 877 | - } | |
| 878 | - | |
| 879 | - return $content; | |
| 1038 | + return is_admin() ? $run_texturize : false; | |
| 880 | 1039 | }, PHP_INT_MAX); |