PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.0
Code Manager v1.0.0
1.0.49 1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / includes / entities / class-fs-plugin-license.php
code-manager / freemius / includes / entities Last commit date
class-fs-affiliate-terms.php 5 years ago class-fs-affiliate.php 5 years ago class-fs-billing.php 5 years ago class-fs-entity.php 5 years ago class-fs-payment.php 5 years ago class-fs-plugin-info.php 5 years ago class-fs-plugin-license.php 5 years ago class-fs-plugin-plan.php 5 years ago class-fs-plugin-tag.php 5 years ago class-fs-plugin.php 5 years ago class-fs-pricing.php 5 years ago class-fs-scope-entity.php 5 years ago class-fs-site.php 5 years ago class-fs-subscription.php 5 years ago class-fs-user.php 5 years ago index.php 5 years ago
class-fs-plugin-license.php
324 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 1.0.5
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Class FS_Plugin_License
15 */
16 class FS_Plugin_License extends FS_Entity {
17
18 #region Properties
19
20 /**
21 * @var number
22 */
23 public $plugin_id;
24 /**
25 * @var number
26 */
27 public $user_id;
28 /**
29 * @var number
30 */
31 public $plan_id;
32 /**
33 * @author Leo Fajardo (@leorw)
34 * @since 2.3.0
35 *
36 * @var string
37 */
38 public $parent_plan_name;
39 /**
40 * @author Leo Fajardo (@leorw)
41 * @since 2.3.0
42 *
43 * @var string
44 */
45 public $parent_plan_title;
46 /**
47 * @author Leo Fajardo (@leorw)
48 * @since 2.3.0
49 *
50 * @var number
51 */
52 public $parent_license_id;
53 /**
54 * @var number
55 */
56 public $pricing_id;
57 /**
58 * @var int|null
59 */
60 public $quota;
61 /**
62 * @var int
63 */
64 public $activated;
65 /**
66 * @var int
67 */
68 public $activated_local;
69 /**
70 * @var string
71 */
72 public $expiration;
73 /**
74 * @var string
75 */
76 public $secret_key;
77 /**
78 * @var bool
79 */
80 public $is_whitelabeled;
81 /**
82 * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
83 * license.
84 */
85 public $is_free_localhost;
86 /**
87 * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
88 * block updates and support.
89 */
90 public $is_block_features;
91 /**
92 * @var bool
93 */
94 public $is_cancelled;
95
96 #endregion Properties
97
98 /**
99 * @param stdClass|bool $license
100 */
101 function __construct( $license = false ) {
102 parent::__construct( $license );
103 }
104
105 /**
106 * Get entity type.
107 *
108 * @return string
109 */
110 static function get_type() {
111 return 'license';
112 }
113
114 /**
115 * Check how many site activations left.
116 *
117 * @author Vova Feldman (@svovaf)
118 * @since 1.0.5
119 *
120 * @return int
121 */
122 function left() {
123 if ( ! $this->is_features_enabled() ) {
124 return 0;
125 }
126
127 if ( $this->is_unlimited() ) {
128 return 999;
129 }
130
131 return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
132 }
133
134 /**
135 * Check if single site license.
136 *
137 * @author Vova Feldman (@svovaf)
138 * @since 1.1.8.1
139 *
140 * @return bool
141 */
142 function is_single_site() {
143 return ( is_numeric( $this->quota ) && 1 == $this->quota );
144 }
145
146 /**
147 * @author Vova Feldman (@svovaf)
148 * @since 1.0.5
149 *
150 * @return bool
151 */
152 function is_expired() {
153 return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
154 }
155
156 /**
157 * Check if license is not expired.
158 *
159 * @author Vova Feldman (@svovaf)
160 * @since 1.2.1
161 *
162 * @return bool
163 */
164 function is_valid() {
165 return ! $this->is_expired();
166 }
167
168 /**
169 * @author Vova Feldman (@svovaf)
170 * @since 1.0.6
171 *
172 * @return bool
173 */
174 function is_lifetime() {
175 return is_null( $this->expiration );
176 }
177
178 /**
179 * @author Vova Feldman (@svovaf)
180 * @since 1.2.0
181 *
182 * @return bool
183 */
184 function is_unlimited() {
185 return is_null( $this->quota );
186 }
187
188 /**
189 * Check if license is fully utilized.
190 *
191 * @author Vova Feldman (@svovaf)
192 * @since 1.0.6
193 *
194 * @param bool|null $is_localhost
195 *
196 * @return bool
197 */
198 function is_utilized( $is_localhost = null ) {
199 if ( is_null( $is_localhost ) ) {
200 $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
201 }
202
203 if ( $this->is_unlimited() ) {
204 return false;
205 }
206
207 return ! ( $this->is_free_localhost && $is_localhost ) &&
208 ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
209 }
210
211 /**
212 * Check if license can be activated.
213 *
214 * @author Vova Feldman (@svovaf)
215 * @since 2.0.0
216 *
217 * @param bool|null $is_localhost
218 *
219 * @return bool
220 */
221 function can_activate( $is_localhost = null ) {
222 return ! $this->is_utilized( $is_localhost ) && $this->is_features_enabled();
223 }
224
225 /**
226 * Check if license can be activated on a given number of production and localhost sites.
227 *
228 * @author Vova Feldman (@svovaf)
229 * @since 2.0.0
230 *
231 * @param int $production_count
232 * @param int $localhost_count
233 *
234 * @return bool
235 */
236 function can_activate_bulk( $production_count, $localhost_count ) {
237 if ( $this->is_unlimited() ) {
238 return true;
239 }
240
241 /**
242 * For simplicity, the logic will work as following: when given X sites to activate the license on, if it's
243 * possible to activate on ALL of them, do the activation. If it's not possible to activate on ALL of them,
244 * do NOT activate on any of them.
245 */
246 return ( $this->quota >= $this->activated + $production_count + ( $this->is_free_localhost ? 0 : $this->activated_local + $localhost_count ) );
247 }
248
249 /**
250 * @author Vova Feldman (@svovaf)
251 * @since 1.2.1
252 *
253 * @return bool
254 */
255 function is_active() {
256 return ( ! $this->is_cancelled );
257 }
258
259 /**
260 * Check if license's plan features are enabled.
261 *
262 * - Either if plan not expired
263 * - If expired, based on the configuration to block features or not.
264 *
265 * @author Vova Feldman (@svovaf)
266 * @since 1.0.6
267 *
268 * @return bool
269 */
270 function is_features_enabled() {
271 return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() );
272 }
273
274 /**
275 * Subscription considered to be new without any payments
276 * if the license expires in less than 24 hours
277 * from the license creation.
278 *
279 * @author Vova Feldman (@svovaf)
280 * @since 1.0.9
281 *
282 * @return bool
283 */
284 function is_first_payment_pending() {
285 return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
286 }
287
288 /**
289 * @return int
290 */
291 function total_activations() {
292 return ( $this->activated + $this->activated_local );
293 }
294
295 /**
296 * @author Vova Feldman (@svovaf)
297 * @since 2.3.1
298 *
299 * @return string
300 */
301 function get_html_escaped_masked_secret_key() {
302 return self::mask_secret_key_for_html( $this->secret_key );
303 }
304
305 /**
306 * @author Vova Feldman (@svovaf)
307 * @since 2.3.1
308 *
309 * @param string $secret_key
310 *
311 * @return string
312 */
313 static function mask_secret_key_for_html( $secret_key ) {
314 return (
315 // Initial 6 chars - sk_ABC
316 htmlspecialchars( substr( $secret_key, 0, 6 ) ) .
317 // Masking
318 str_pad( '', ( strlen( $secret_key ) - 9 ) * 6, '&bull;' ) .
319 // Last 3 chars.
320 htmlspecialchars( substr( $secret_key, - 3 ) )
321 );
322 }
323 }
324