PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
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 / update / license.php

license.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at libraries/update/license.php

189 lines 3.7 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 update
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2018 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 * Class used to handle the software license.
16 *
17 * @since 1.0
18 */
19 class VikBookingLicense
20 {
21 /**
22 * Gets the current License Key.
23 *
24 * @return string
25 */
26 public static function getKey()
27 {
28 return get_option('vikbooking_license_key', '');
29 }
30
31 /**
32 * Updates the current License Key.
33 *
34 * @param string $key
35 *
36 * @return void
37 */
38 public static function setKey($key)
39 {
40 /**
41 * In case of multi-site, update the option on all the network sites.
42 *
43 * @since 1.4.0
44 */
45 JFactory::getApplication()->set('vikbooking_license_key', (string) $key, $network = true);
46 }
47
48 /**
49 * Gets the current License Expiration Timestamp.
50 *
51 * @return int
52 */
53 public static function getExpirationDate()
54 {
55 return (int)get_option('vikbooking_license_expdate', 0);
56 }
57
58 /**
59 * Updates the current License Expiration Timestamp.
60 *
61 * @param int $time
62 *
63 * @return void
64 */
65 public static function setExpirationDate($time)
66 {
67 /**
68 * In case of multi-site, update the option on all the network sites.
69 *
70 * @since 1.4.0
71 */
72 JFactory::getApplication()->set('vikbooking_license_expdate', (int) $time, $network = true);
73 }
74
75 /**
76 * Checks whether the software version is Pro.
77 *
78 * @return boolean
79 */
80 public static function isPro()
81 {
82 return (strlen(self::getKey()) && (!self::isExpired() || self::hasVcm()));
83 }
84
85 /**
86 * Checks whether the VCM plugin is installed.
87 *
88 * @return boolean
89 */
90 public static function hasVcm()
91 {
92 return is_dir(VCM_SITE_PATH);
93 }
94
95 /**
96 * Checks whether the ad for VCM was hid.
97 *
98 * @return boolean
99 */
100 public static function hideVcmAd()
101 {
102 $hide = (int) get_option('vikbooking_hide_vcmad', 0);
103 return ($hide > 0);
104 }
105
106 /**
107 * Updates the value for the ad of VCM.
108 *
109 * @param boolean true for showing the ad (0), false otherwise (1).
110 *
111 * @return void
112 */
113 public static function setVcmAd($value)
114 {
115 /**
116 * In case of multi-site, update the option on all the network sites.
117 *
118 * @since 1.4.0
119 */
120 JFactory::getApplication()->set('vikbooking_hide_vcmad', (int) !$value, $network = true);
121 }
122
123 /**
124 * Checks whether the License Key is expired.
125 *
126 * @return boolean
127 */
128 public static function isExpired()
129 {
130 return (strlen(self::getKey()) && self::getExpirationDate() < time());
131 }
132
133 /**
134 * Gets the current License Hash.
135 *
136 * @return string
137 */
138 public static function getHash()
139 {
140 $hash = get_option('vikbooking_license_hash', '');
141
142 if (empty($hash))
143 {
144 $hash = self::setHash();
145 }
146
147 return $hash;
148 }
149
150 /**
151 * Sets and returns the License Hash.
152 *
153 * @return string
154 */
155 public static function setHash()
156 {
157 $hash = md5(JUri::root() . uniqid());
158 update_option('vikbooking_license_hash', $hash);
159
160 return $hash;
161 }
162
163 /**
164 * Registers some options upon installation of the plugin.
165 *
166 * @return void
167 */
168 public static function install()
169 {
170 update_option('vikbooking_license_key', '');
171 update_option('vikbooking_license_expdate', 0);
172 update_option('vikbooking_license_hash', '');
173 update_option('vikbooking_hide_vcmad', 0);
174 }
175
176 /**
177 * Deletes all the options upon uninstallation of the plugin.
178 *
179 * @return void
180 */
181 public static function uninstall()
182 {
183 delete_option('vikbooking_license_key');
184 delete_option('vikbooking_license_expdate');
185 delete_option('vikbooking_license_hash');
186 delete_option('vikbooking_hide_vcmad');
187 }
188 }
189