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