PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 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 All 37 releases
← All changes | libraries/update/license.php +229 -0 1.6.3 → 1.8.16 View file →
@@ -1,0 +1,229 @@
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 + * Returns the installation date of the plugin.
165 + *
166 + * @return string|null
167 + *
168 + * @since 1.8.8
169 + */
170 + public static function getInstallDate()
171 + {
172 + // fetch install date from database
173 + $date = get_option('vikbooking_install_date');
174 +
175 + if ($date) {
176 + return $date;
177 + }
178 +
179 + // Date not registered on database...
180 + // We can estimate the installation date fairly accurately by checking the creation
181 + // timestamp of the "vikbooking" folder in the WordPress uploads directory.
182 + $uploadsDir = wp_upload_dir();
183 +
184 + if (!is_array($uploadsDir) || empty($uploadsDir['basedir'])) {
185 + // uploads folder not configured
186 + return null;
187 + }
188 +
189 + // create path
190 + $path = JPath::clean($uploadsDir['basedir'] . '/vikbooking');
191 +
192 + // make sure the folder exists
193 + if (!JFolder::exists($path)) {
194 + // missing folder
195 + return null;
196 + }
197 +
198 + // read modify timestamp for uploads folder
199 + return date('Y-m-d H:i:s', filemtime($path));
200 + }
201 +
202 + /**
203 + * Registers some options upon installation of the plugin.
204 + *
205 + * @return void
206 + */
207 + public static function install()
208 + {
209 + update_option('vikbooking_license_key', '');
210 + update_option('vikbooking_license_expdate', 0);
211 + update_option('vikbooking_license_hash', '');
212 + update_option('vikbooking_hide_vcmad', 0);
213 + update_option('vikbooking_install_date', date('Y-m-d H:i:s'));
214 + }
215 +
216 + /**
217 + * Deletes all the options upon uninstallation of the plugin.
218 + *
219 + * @return void
220 + */
221 + public static function uninstall()
222 + {
223 + delete_option('vikbooking_license_key');
224 + delete_option('vikbooking_license_expdate');
225 + delete_option('vikbooking_license_hash');
226 + delete_option('vikbooking_hide_vcmad');
227 + delete_option('vikbooking_install_date');
228 + }
229 +}