PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.2
Tiered Pricing Table for WooCommerce v2.3.2
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / freemius / includes / entities / class-fs-plugin-license.php

class-fs-plugin-license.php in Tiered Pricing Table for WooCommerce 2.3.2, at freemius/includes/entities/class-fs-plugin-license.php

291 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
79 * license.
80 */
81 public $is_free_localhost;
82 /**
83 * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
84 * block updates and support.
85 */
86 public $is_block_features;
87 /**
88 * @var bool
89 */
90 public $is_cancelled;
91
92 #endregion Properties
93
94 /**
95 * @param stdClass|bool $license
96 */
97 function __construct( $license = false ) {
98 parent::__construct( $license );
99 }
100
101 /**
102 * Get entity type.
103 *
104 * @return string
105 */
106 static function get_type() {
107 return 'license';
108 }
109
110 /**
111 * Check how many site activations left.
112 *
113 * @author Vova Feldman (@svovaf)
114 * @since 1.0.5
115 *
116 * @return int
117 */
118 function left() {
119 if ( ! $this->is_features_enabled() ) {
120 return 0;
121 }
122
123 if ( $this->is_unlimited() ) {
124 return 999;
125 }
126
127 return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
128 }
129
130 /**
131 * Check if single site license.
132 *
133 * @author Vova Feldman (@svovaf)
134 * @since 1.1.8.1
135 *
136 * @return bool
137 */
138 function is_single_site() {
139 return ( is_numeric( $this->quota ) && 1 == $this->quota );
140 }
141
142 /**
143 * @author Vova Feldman (@svovaf)
144 * @since 1.0.5
145 *
146 * @return bool
147 */
148 function is_expired() {
149 return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
150 }
151
152 /**
153 * Check if license is not expired.
154 *
155 * @author Vova Feldman (@svovaf)
156 * @since 1.2.1
157 *
158 * @return bool
159 */
160 function is_valid() {
161 return ! $this->is_expired();
162 }
163
164 /**
165 * @author Vova Feldman (@svovaf)
166 * @since 1.0.6
167 *
168 * @return bool
169 */
170 function is_lifetime() {
171 return is_null( $this->expiration );
172 }
173
174 /**
175 * @author Vova Feldman (@svovaf)
176 * @since 1.2.0
177 *
178 * @return bool
179 */
180 function is_unlimited() {
181 return is_null( $this->quota );
182 }
183
184 /**
185 * Check if license is fully utilized.
186 *
187 * @author Vova Feldman (@svovaf)
188 * @since 1.0.6
189 *
190 * @param bool|null $is_localhost
191 *
192 * @return bool
193 */
194 function is_utilized( $is_localhost = null ) {
195 if ( is_null( $is_localhost ) ) {
196 $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
197 }
198
199 if ( $this->is_unlimited() ) {
200 return false;
201 }
202
203 return ! ( $this->is_free_localhost && $is_localhost ) &&
204 ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
205 }
206
207 /**
208 * Check if license can be activated.
209 *
210 * @author Vova Feldman (@svovaf)
211 * @since 2.0.0
212 *
213 * @param bool|null $is_localhost
214 *
215 * @return bool
216 */
217 function can_activate( $is_localhost = null ) {
218 return ! $this->is_utilized( $is_localhost ) && $this->is_features_enabled();
219 }
220
221 /**
222 * Check if license can be activated on a given number of production and localhost sites.
223 *
224 * @author Vova Feldman (@svovaf)
225 * @since 2.0.0
226 *
227 * @param int $production_count
228 * @param int $localhost_count
229 *
230 * @return bool
231 */
232 function can_activate_bulk( $production_count, $localhost_count ) {
233 if ( $this->is_unlimited() ) {
234 return true;
235 }
236
237 /**
238 * For simplicity, the logic will work as following: when given X sites to activate the license on, if it's
239 * possible to activate on ALL of them, do the activation. If it's not possible to activate on ALL of them,
240 * do NOT activate on any of them.
241 */
242 return ( $this->quota >= $this->activated + $production_count + ( $this->is_free_localhost ? 0 : $this->activated_local + $localhost_count ) );
243 }
244
245 /**
246 * @author Vova Feldman (@svovaf)
247 * @since 1.2.1
248 *
249 * @return bool
250 */
251 function is_active() {
252 return ( ! $this->is_cancelled );
253 }
254
255 /**
256 * Check if license's plan features are enabled.
257 *
258 * - Either if plan not expired
259 * - If expired, based on the configuration to block features or not.
260 *
261 * @author Vova Feldman (@svovaf)
262 * @since 1.0.6
263 *
264 * @return bool
265 */
266 function is_features_enabled() {
267 return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() );
268 }
269
270 /**
271 * Subscription considered to be new without any payments
272 * if the license expires in less than 24 hours
273 * from the license creation.
274 *
275 * @author Vova Feldman (@svovaf)
276 * @since 1.0.9
277 *
278 * @return bool
279 */
280 function is_first_payment_pending() {
281 return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
282 }
283
284 /**
285 * @return int
286 */
287 function total_activations() {
288 return ( $this->activated + $this->activated_local );
289 }
290 }
291