PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / libraries / lite / manager.php

manager.php in VikBooking Hotel Booking Engine & PMS trunk, at libraries/lite/manager.php

155 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking - Libraries
4 * @subpackage lite
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2022 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Manager class used to setup the LITE version of the plugin.
16 *
17 * @since 1.5.11
18 */
19 abstract class VikBookingLiteManager
20 {
21 /**
22 * Flag used to avoid initializing the setup more than once.
23 *
24 * @var boolean
25 */
26 private static $setup = false;
27
28 /**
29 * Accessor used to start the setup.
30 *
31 * @param mixed $helper The implementor instance or a static class.
32 *
33 * @return void
34 */
35 final public static function setup($helper = null)
36 {
37 if (!static::$setup && !static::guessPro())
38 {
39 if (!$helper)
40 {
41 // use the default implementor
42 VikBookingLoader::import('lite.helper');
43 $helper = new VikBookingLiteHelper();
44 }
45
46 // set up only once and in case of missing PRO version
47 static::$setup = static::doSetup($helper);
48 }
49 }
50
51 /**
52 * Helper method used to assume whether the PRO version is
53 * installed or not, because it is not enough to check whether
54 * a PRO license is registered. In example, we cannot automatically
55 * re-enable the LITE restrictions after a PRO license expires.
56 *
57 * @return boolean
58 */
59 public static function guessPro()
60 {
61 // immediately check whether we have a valid PRO license
62 if (VikBookingLicense::isPro())
63 {
64 // in case of downgrade to the free version, display system message
65 if (!JFile::exists(VBO_ADMIN_PATH . '/payments/paypal.php'))
66 {
67 $app = JFactory::getApplication();
68
69 if ($app->input->getString('view') != 'getpro')
70 {
71 // display system message
72 $app->enqueueMessage(
73 sprintf(
74 __('Your Pro version of Vik Booking was downgraded to the Free version after the update. Please visit the <a href="%s">Go to Pro</a> page to restore your Pro settings and complete the update process.', 'vikbooking'),
75 'admin.php?page=vikbooking&view=getpro'
76 ),
77 'warning'
78 );
79 }
80 }
81
82 return true;
83 }
84
85 // Missing PRO license or expired... First make sure the
86 // license key was specified.
87 if (!VikBookingLicense::getKey())
88 {
89 // missing license key, never allow usage of PRO features
90 return false;
91 }
92
93 // Check whether the PRO license was ever installed, which
94 // can be easily done by looking for the PayPal integration.
95 return JFile::exists(VBO_ADMIN_PATH . '/payments/paypal.php');
96 }
97
98 /**
99 * Setup implementor.
100 *
101 * @param mixed $helper The implementor instance or a static class.
102 *
103 * @return boolean
104 */
105 protected static function doSetup($helper)
106 {
107 /**
108 * Filters which capabilities a role has.
109 *
110 * @since 2.0.0
111 *
112 * @param bool[] $capabilities Array of key/value pairs where keys represent a capability name and boolean values
113 * represent whether the role has that capability.
114 * @param string $cap Capability name.
115 * @param string $name Role name.
116 */
117 add_filter('role_has_cap', array($helper, 'restrictCapabilities'));
118
119 /**
120 * Dynamically filter a user's capabilities.
121 *
122 * @since 2.0.0
123 * @since 3.7.0 Added the `$user` parameter.
124 *
125 * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name
126 * and boolean values represent whether the user has that capability.
127 * @param string[] $caps Required primitive capabilities for the requested capability.
128 * @param array $args Arguments that accompany the requested capability check.
129 * @param WP_User $user The user object.
130 */
131 add_filter('user_has_cap', array($helper, 'restrictCapabilities'));
132
133 /**
134 * Fires before the controller of VikBooking is dispatched.
135 * Useful to require libraries and to check user global permissions.
136 *
137 * @since 1.0
138 */
139 add_action('vikbooking_before_dispatch', array($helper, 'disableSetNewRatesTask'));
140 add_action('vikbooking_before_dispatch', array($helper, 'displayBanners'));
141 add_action('vikbooking_before_dispatch', array($helper, 'hideProFeatures'));
142 add_action('vikbooking_before_dispatch', array($helper, 'disableEditBusyRoomFeatures'));
143 add_action('vikbooking_before_dispatch', array($helper, 'listenTosFieldSavingTask'));
144
145 /**
146 * Fires after the controller displays the view.
147 *
148 * @param JView $view The view instance.
149 *
150 * @since 1.0
151 */
152 add_action('vikbooking_after_display_customf', array($helper, 'displayTosFieldManagementForm'));
153 }
154 }
155