PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.2
YayMail – WooCommerce Email Customizer v4.3.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 / src / License / License.php

License.php in YayMail – WooCommerce Email Customizer 4.3.2, at src/License/License.php

138 lines 4.7 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 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * License
9 *
10 * @package License
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 = [
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 LicenseHandler::remove_site_plugin_check();
66 $licensing_plugin->update_version_info();
67 return $activate_response;
68 }
69
70 public function update() {
71 $licensing_plugin = new LicensingPlugin( $this->slug );
72 $item_id = $licensing_plugin->get_option( 'item_id' );
73
74 $license_key = $this->get_license_key();
75
76 $response = LicenseAPI::check_license( $item_id, $license_key );
77 if ( $response['success'] ) {
78 $this->update_license_info( $response );
79 } elseif ( empty( $response['is_server_error'] ) ) {
80 $this->remove();
81 }
82 LicenseHandler::remove_site_plugin_check();
83 $licensing_plugin->update_version_info();
84 return $response;
85 }
86
87 public function remove() {
88 LicenseHandler::remove_site_plugin_check();
89 $this->remove_license_key();
90 $this->remove_license_info();
91 }
92
93 public function is_active() {
94 return $this->license_key;
95 }
96
97 public function is_expired() {
98 if ( $this->is_active() ) {
99 $license_info = $this->get_license_info();
100 if ( 'lifetime' !== $license_info['expires'] ) {
101 if ( strtotime( $license_info['expires'] ) < time() ) {
102 return true;
103 }
104 }
105 }
106 return false;
107 }
108
109 public function format_license_key( $number_seperate = 8, $seperate = '-', $number_hidden = 20 ) {
110 $license_key = $this->license_key;
111 $license_key_length = strlen( $license_key );
112 if ( $license_key_length <= $number_hidden ) {
113 return $license_key;
114 }
115 for ( $i = $license_key_length - $number_hidden; $i < $license_key_length; $i++ ) {
116 $license_key[ $i ] = '*';
117 }
118 $formatted_license_key = '';
119 for ( $i = 0; $i < $license_key_length; $i++ ) {
120 $formatted_license_key .= $license_key[ $i ];
121 if ( 0 === ( ( $i + 1 ) % $number_seperate ) && $i + 1 >= $number_seperate && $i !== $license_key_length - 1 ) {
122 $formatted_license_key .= $seperate;
123 }
124 }
125 return $formatted_license_key;
126 }
127
128 public function get_renewal_url() {
129 $licensing_plugin = new LicensingPlugin( $this->slug );
130 $item_id = $licensing_plugin->get_option( 'item_id' );
131 return YAYCOMMERCE_SELLER_SITE_URL . 'checkout/?edd_license_key=' . $this->license_key . '&download_id=' . $item_id;
132 }
133
134 public function get_upgrade_url() {
135 return YAYCOMMERCE_SELLER_SITE_URL . 'checkout/purchase-history/?view=upgrades&action=manage_licenses&payment_id=' . ( isset( $this->license_info['payment_id'] ) ? $this->license_info['payment_id'] : '' );
136 }
137 }
138