PluginProbe
YayMail – WooCommerce Email Customizer / 3.4
YayMail – WooCommerce Email Customizer v3.4
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.4, at includes/License/License.php

137 lines 4.0 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 if ( empty( $response['is_server_error'] ) ) {
80 $this->remove();
81 }
82 }
83 $licensing_plugin->update_version_info();
84 return $response;
85 }
86
87 public function remove() {
88 $this->remove_license_key();
89 $this->remove_license_info();
90 }
91
92 public function is_active() {
93 return $this->license_key;
94 }
95
96 public function is_expired() {
97 if ( $this->is_active() ) {
98 $license_info = $this->get_license_info();
99 if ( 'lifetime' !== $license_info['expires'] ) {
100 if ( strtotime( $license_info['expires'] ) < time() ) {
101 return true;
102 }
103 }
104 }
105 return false;
106 }
107
108 public function format_license_key( $number_seperate = 8, $seperate = '-', $number_hidden = 20 ) {
109 $license_key = $this->license_key;
110 $license_key_length = strlen( $license_key );
111 if ( $license_key_length <= $number_hidden ) {
112 return $license_key;
113 }
114 for ( $i = $license_key_length - $number_hidden; $i < $license_key_length; $i++ ) {
115 $license_key[ $i ] = '*';
116 }
117 $formatted_license_key = '';
118 for ( $i = 0; $i < $license_key_length; $i++ ) {
119 $formatted_license_key .= $license_key[ $i ];
120 if ( 0 === ( ( $i + 1 ) % $number_seperate ) && $i + 1 >= $number_seperate && $i !== $license_key_length - 1 ) {
121 $formatted_license_key .= $seperate;
122 }
123 }
124 return $formatted_license_key;
125 }
126
127 public function get_renewal_url() {
128 $licensing_plugin = new LicensingPlugin( $this->slug );
129 $item_id = $licensing_plugin->get_option( 'item_id' );
130 return YAYCOMMERCE_SELLER_SITE_URL . 'checkout/?edd_license_key=' . $this->license_key . '&download_id=' . $item_id;
131 }
132
133 public function get_upgrade_url() {
134 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'] : '' );
135 }
136 }
137