/freemius/includes/entities/class-fs-plugin-license.php

  1. <?php 
  2. /** 
  3. * @package Freemius 
  4. * @copyright Copyright (c) 2015, Freemius, Inc. 
  5. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License 
  6. * @since 1.0.5 
  7. */ 
  8.  
  9. if ( ! defined( 'ABSPATH' ) ) { 
  10. exit; 
  11.  
  12. class FS_Plugin_License extends FS_Entity { 
  13.  
  14. #region Properties 
  15.  
  16. /** 
  17. * @var number 
  18. */ 
  19. public $plugin_id; 
  20. /** 
  21. * @var number 
  22. */ 
  23. public $user_id; 
  24. /** 
  25. * @var number 
  26. */ 
  27. public $plan_id; 
  28. /** 
  29. * @var number 
  30. */ 
  31. public $pricing_id; 
  32. /** 
  33. * @var int|null 
  34. */ 
  35. public $quota; 
  36. /** 
  37. * @var int 
  38. */ 
  39. public $activated; 
  40. /** 
  41. * @var int 
  42. */ 
  43. public $activated_local; 
  44. /** 
  45. * @var string 
  46. */ 
  47. public $expiration; 
  48. /** 
  49. * @var string 
  50. */ 
  51. public $secret_key; 
  52. /** 
  53. * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same 
  54. * license. 
  55. */ 
  56. public $is_free_localhost; 
  57. /** 
  58. * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only 
  59. * block updates and support. 
  60. */ 
  61. public $is_block_features; 
  62. /** 
  63. * @var bool 
  64. */ 
  65. public $is_cancelled; 
  66.  
  67. #endregion Properties 
  68.  
  69. /** 
  70. * @param stdClass|bool $license 
  71. */ 
  72. function __construct( $license = false ) { 
  73. parent::__construct( $license ); 
  74.  
  75. static function get_type() { 
  76. return 'license'; 
  77.  
  78. /** 
  79. * Check how many site activations left. 
  80. * 
  81. * @author Vova Feldman (@svovaf) 
  82. * @since 1.0.5 
  83. * 
  84. * @return int 
  85. */ 
  86. function left() { 
  87. if ( ! $this->is_active() || $this->is_expired() ) { 
  88. return 0; 
  89.  
  90. if ( $this->is_unlimited() ) { 
  91. return 999; 
  92.  
  93. return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) ); 
  94.  
  95. /** 
  96. * Check if single site license. 
  97. * 
  98. * @author Vova Feldman (@svovaf) 
  99. * @since 1.1.8.1 
  100. * 
  101. * @return bool 
  102. */ 
  103. function is_single_site() { 
  104. return ( is_numeric( $this->quota ) && 1 == $this->quota ); 
  105.  
  106. /** 
  107. * @author Vova Feldman (@svovaf) 
  108. * @since 1.0.5 
  109. * 
  110. * @return bool 
  111. */ 
  112. function is_expired() { 
  113. return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME ); 
  114.  
  115. /** 
  116. * Check if license is not expired. 
  117. * 
  118. * @author Vova Feldman (@svovaf) 
  119. * @since 1.2.1 
  120. * 
  121. * @return bool 
  122. */ 
  123. function is_valid() { 
  124. return ! $this->is_expired(); 
  125.  
  126. /** 
  127. * @author Vova Feldman (@svovaf) 
  128. * @since 1.0.6 
  129. * 
  130. * @return bool 
  131. */ 
  132. function is_lifetime() { 
  133. return is_null( $this->expiration ); 
  134.  
  135. /** 
  136. * @author Vova Feldman (@svovaf) 
  137. * @since 1.2.0 
  138. * 
  139. * @return bool 
  140. */ 
  141. function is_unlimited() { 
  142. return is_null( $this->quota ); 
  143.  
  144. /** 
  145. * Check if license is fully utilized. 
  146. * 
  147. * @author Vova Feldman (@svovaf) 
  148. * @since 1.0.6 
  149. * 
  150. * @param bool $is_localhost 
  151. * 
  152. * @return bool 
  153. */ 
  154. function is_utilized( $is_localhost = null ) { 
  155. if ( is_null( $is_localhost ) ) { 
  156. $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER; 
  157.  
  158. if ( $this->is_unlimited() ) { 
  159. return false; 
  160.  
  161. return ! ( $this->is_free_localhost && $is_localhost ) && 
  162. ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) ); 
  163.  
  164. /** 
  165. * @author Vova Feldman (@svovaf) 
  166. * @since 1.2.1 
  167. * 
  168. * @return bool 
  169. */ 
  170. function is_active() { 
  171. return ( ! $this->is_cancelled ); 
  172.  
  173. /** 
  174. * Check if license's plan features are enabled. 
  175. * 
  176. * - Either if plan not expired 
  177. * - If expired, based on the configuration to block features or not. 
  178. * 
  179. * @author Vova Feldman (@svovaf) 
  180. * @since 1.0.6 
  181. * 
  182. * @return bool 
  183. */ 
  184. function is_features_enabled() { 
  185. return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() ); 
  186.  
  187. /** 
  188. * Subscription considered to be new without any payments 
  189. * if the license expires in less than 24 hours 
  190. * from the license creation. 
  191. * 
  192. * @author Vova Feldman (@svovaf) 
  193. * @since 1.0.9 
  194. * 
  195. * @return bool 
  196. */ 
  197. function is_first_payment_pending() { 
  198. return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) ); 
.