PluginProbe
YayMail – WooCommerce Email Customizer / 3.2.2
YayMail – WooCommerce Email Customizer v3.2.2
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / includes / License / License.php

License.php in YayMail – WooCommerce Email Customizer 3.2.2, at includes/License/License.php

132 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\License;
4
5 use YayMail\License\LicenseAPI;
6 use YayMail\License\LicenseHandler;
7 use YayMail\License\LicensingPlugin;
8
9 defined( 'ABSPATH' ) || exit;
10
11
12 class License {
13
14 protected $slug = null;
15 protected $license_key = null;
16 protected $license_info = null;
17 protected static $instance = null;
18
19 public function __construct( $plugin_slug ) {
20 $this->slug = $plugin_slug;
21 $this->license_key = $this->get_license_key();
22 $this->license_info = $this->get_license_info();
23 }
24
25 public function update_license_info( $license_info ) {
26 unset( $license_info['success'] );
27 // $license_info['expires'] = '2020-06-30 23:59:59';
28 update_option( $this->slug . '_license_info', $license_info );
29 }
30
31 public function update_license_key( $license_key ) {
32 update_option( $this->slug . '_license_key', $license_key );
33 }
34
35 public function get_license_key() {
36 return get_option( $this->slug . '_license_key' );
37 }
38
39 public function get_license_info() {
40 $default_info = array(
41 'expires' => 'Not updated',
42 );
43 $info = get_option( $this->slug . '_license_info' );
44 $info = is_string( $info ) ? \json_decode( $info, true ) : $info;
45 return $info ? $info : $default_info;
46 }
47
48 public function remove_license_key() {
49 delete_option( $this->slug . '_license_key' );
50 }
51
52 public function remove_license_info() {
53 delete_option( $this->slug . '_license_info' );
54 }
55
56 public function activate( $license_key ) {
57 $licensing_plugin = new LicensingPlugin( $this->slug );
58 $item_id = $licensing_plugin->get_option( 'item_id' );
59 $activate_response = LicenseAPI::activate_license( $item_id, $license_key );
60 if ( $activate_response['success'] ) {
61 $this->update_license_key( $license_key );
62 $this->update_license_info( $activate_response );
63 $this->license_key = $license_key;
64 }
65 $licensing_plugin->update_version_info();
66 return $activate_response;
67 }
68
69 public function update() {
70 $licensing_plugin = new LicensingPlugin( $this->slug );
71 $item_id = $licensing_plugin->get_option( 'item_id' );
72
73 $license_key = $this->get_license_key();
74
75 $response = LicenseAPI::check_license( $item_id, $license_key );
76 if ( $response['success'] ) {
77 $this->update_license_info( $response );
78 } else {
79 $this->remove_license_key();
80 $this->remove_license_info();
81 }
82 $licensing_plugin->update_version_info();
83 return $response;
84 }
85
86 public function remove() {
87 $this->remove_license_key();
88 $this->remove_license_info();
89 }
90
91 public function is_active() {
92 return $this->license_key;
93 }
94
95 public function is_expired() {
96 if ( $this->is_active() ) {
97 $license_info = $this->get_license_info();
98 if ( 'lifetime' !== $license_info['expires'] ) {
99 if ( strtotime( $license_info['expires'] ) < time() ) {
100 return true;
101 }
102 }
103 }
104 return false;
105 }
106
107 public function format_license_key( $number_seperate = 8, $seperate = '-', $number_hidden = 20 ) {
108 $license_key = $this->license_key;
109 $license_key_length = strlen( $license_key );
110 if ( $license_key_length <= $number_hidden ) {
111 return $license_key;
112 }
113 for ( $i = $license_key_length - $number_hidden; $i < $license_key_length; $i++ ) {
114 $license_key[ $i ] = '*';
115 }
116 $formatted_license_key = '';
117 for ( $i = 0; $i < $license_key_length; $i++ ) {
118 $formatted_license_key .= $license_key[ $i ];
119 if ( 0 === ( ( $i + 1 ) % $number_seperate ) && $i + 1 >= $number_seperate && $i !== $license_key_length - 1 ) {
120 $formatted_license_key .= $seperate;
121 }
122 }
123 return $formatted_license_key;
124 }
125
126 public function get_renewal_url() {
127 $licensing_plugin = new LicensingPlugin( $this->slug );
128 $item_id = $licensing_plugin->get_option( 'item_id' );
129 return YAYCOMMERCE_SELLER_SITE_URL . 'checkout/?edd_license_key=' . $this->license_key . '&download_id=' . $item_id;
130 }
131 }
132