PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / freemius / includes / entities / class-freemius-license.php
robin-image-optimizer / libs / factory / freemius / includes / entities Last commit date
class-freemius-entity.php 5 months ago class-freemius-license.php 5 months ago class-freemius-plugin.php 5 months ago class-freemius-scope.php 5 months ago class-freemius-site.php 5 months ago class-freemius-user.php 5 months ago index.php 6 months ago
class-freemius-license.php
350 lines
1 <?php
2
3 namespace WBCR\Factory_Freemius_Rio_600\Entities;
4
5 use stdClass;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * @version 1.0
13 */
14 class License extends Entity implements \WBCR\Factory_600\Premium\Interfaces\License {
15
16 /**
17 * @var number
18 */
19 public $plugin_id;
20
21 /**
22 * @var number
23 */
24 public $user_id;
25
26 /**
27 * @var number
28 */
29 public $plan_id;
30
31 /**
32 * @var string
33 */
34 public $plan_title;
35
36 /**
37 * @var string
38 */
39 public $billing_cycle;
40
41 /**
42 * @var number
43 */
44 public $pricing_id;
45
46 /**
47 * @var int|null
48 */
49 public $quota;
50
51 /**
52 * @var int
53 */
54 public $activated;
55
56 /**
57 * @var int
58 */
59 public $activated_local;
60
61 /**
62 * @var string
63 */
64 public $expiration;
65
66 /**
67 * @var string
68 */
69 public $secret_key;
70
71 /**
72 * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
73 * license.
74 */
75 public $is_free_localhost;
76
77 /**
78 * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
79 * block updates and support.
80 */
81 public $is_block_features;
82
83 /**
84 * @var bool
85 */
86 public $is_cancelled;
87
88 /**
89 * @param stdClass|bool $license
90 */
91 public function __construct( $license = false ) {
92 parent::__construct( $license );
93 }
94
95 /**
96 * Get entity type.
97 *
98 * @return string
99 */
100 public static function get_type() {
101 return 'license';
102 }
103
104 /**
105 * Example: #sk_f=>}-5vuHp$3*wPQHxd(AD3<);1&i
106 *
107 * @return string|null
108 */
109 public function get_key() {
110 return $this->secret_key;
111 }
112
113 /**
114 * Example: #sk_f=>}-5vuHp$3******d(AD3<);1&i
115 *
116 * @return mixed
117 */
118 public function get_hidden_key() {
119 return substr_replace( $this->get_key(), '******', 15, 6 );
120 }
121
122 /**
123 * @return string|null
124 */
125 public function get_plan() {
126 return $this->plan_title;
127 }
128
129 /**
130 * @return integer|null
131 */
132 public function get_plan_id() {
133 return $this->plan_id;
134 }
135
136 /**
137 * @return mixed
138 */
139 public function get_billing_cycle() {
140 return $this->billing_cycle;
141 }
142
143 /**
144 * @return int
145 */
146 public function get_sites_quota() {
147 return $this->quota;
148 }
149
150 /**
151 * @return int
152 */
153 public function get_count_active_sites() {
154 return $this->activated;
155 }
156
157 /**
158 * Check how many site activations left.
159 *
160 * @return int
161 * @since 1.0.5
162 */
163 public function get_site_activations_left() {
164 if ( ! $this->is_active() || $this->is_expired() ) {
165 return 0;
166 }
167
168 if ( $this->is_unlimited() ) {
169 return 999;
170 }
171
172 return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
173 }
174
175 /**
176 * @param string $format Return time in formats (time|days|date)
177 *
178 * @return float|int|string
179 */
180 public function get_expiration_time( $format = 'time' ) {
181 if ( $format == 'days' ) {
182 if ( $this->is_lifetime() ) {
183 return 999;
184 }
185
186 $remaining = strtotime( $this->expiration ) - date( 'U' );
187 $days_remaining = floor( $remaining / 86400 );
188
189 return $days_remaining;
190 } elseif ( $format == 'date' ) {
191 return date( 'Y-m-d', strtotime( $this->expiration ) );
192 }
193
194 return $this->expiration;
195 }
196
197 /**
198 * @param $actual_license_data
199 */
200 /*
201 public function sync( $actual_license_data ) {
202 $props = get_object_vars( $this );
203
204 foreach ( $props as $key => $def_value ) {
205 $this->{$key} = isset( $actual_license_data->{$key} ) ? $actual_license_data->{$key} : $def_value;
206 }
207 if ( isset( $actual_license_data->expiration ) and is_null( $actual_license_data->expiration ) ) {
208 $this->expiration = null;
209 }
210 }*/
211
212 /**
213 * Check if single site license.
214 *
215 * @return bool
216 * @since 1.1.8.1
217 */
218 public function is_single_site() {
219 return ( is_numeric( $this->quota ) && 1 == $this->quota );
220 }
221
222 /**
223 * @return bool
224 * @since 1.0.5
225 */
226 public function is_expired() {
227 return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < date( 'U' ) );
228 }
229
230 /**
231 * Check if license is not expired.
232 *
233 * @return bool
234 * @since 1.2.1
235 */
236 public function is_valid() {
237 return ! $this->is_expired();
238 }
239
240 /**
241 * @return bool
242 * @since 1.0.6
243 */
244 public function is_lifetime() {
245 return is_null( $this->expiration );
246 }
247
248 /**
249 * @return bool
250 * @since 1.2.0
251 */
252 public function is_unlimited() {
253 return is_null( $this->quota );
254 }
255
256 /**
257 * Check if license is fully utilized.
258 *
259 * @param bool|null $is_localhost
260 *
261 * @return bool
262 * @since 1.0.6
263 */
264 public function is_utilized( $is_localhost = null ) {
265 if ( is_null( $is_localhost ) ) {
266 $is_localhost = false; // была WP_FS__IS_LOCALHOST_FOR_SERVER
267 }
268
269 if ( $this->is_unlimited() ) {
270 return false;
271 }
272
273 return ! ( $this->is_free_localhost && $is_localhost ) && ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
274 }
275
276 /**
277 * Check if license can be activated.
278 *
279 * @param bool|null $is_localhost
280 *
281 * @return bool
282 * @since 2.0.0
283 */
284 public function can_activate( $is_localhost = null ) {
285 return ! $this->is_utilized( $is_localhost ) && $this->is_features_enabled();
286 }
287
288 /**
289 * Check if license can be activated on a given number of production and localhost sites.
290 *
291 * @param int $production_count
292 * @param int $localhost_count
293 *
294 * @return bool
295 * @since 2.0.0
296 */
297 // public function can_activate_bulk( $production_count, $localhost_count ) {
298 // if ( $this->is_unlimited() ) {
299 // return true;
300 // }
301
302 /**
303 * For simplicity, the logic will work as following: when given X sites to activate the license on, if it's
304 * possible to activate on ALL of them, do the activation. If it's not possible to activate on ALL of them,
305 * do NOT activate on any of them.
306 */
307 // return ( $this->quota >= $this->activated + $production_count + ( $this->is_free_localhost ? 0 : $this->activated_local + $localhost_count ) );
308 // }
309
310 /**
311 * @return bool
312 * @since 1.2.1
313 */
314 public function is_active() {
315 return ( ! $this->is_cancelled );
316 }
317
318 /**
319 * Check if license's plan features are enabled.
320 *
321 * - Either if plan not expired
322 * - If expired, based on the configuration to block features or not.
323 *
324 * @return bool
325 * @since 1.0.6
326 */
327 public function is_features_enabled() {
328 return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() );
329 }
330
331 /**
332 * Subscription considered to be new without any payments
333 * if the license expires in less than 24 hours
334 * from the license creation.
335 *
336 * @return bool
337 * @since 1.0.9
338 */
339 public function is_first_payment_pending() {
340 return ( 86400 >= strtotime( $this->expiration ) - strtotime( $this->created ) );
341 }
342
343 /**
344 * @return int
345 */
346 public function total_activations() {
347 return ( $this->activated + $this->activated_local );
348 }
349 }
350