PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.6.1
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.6.1
4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / data / controllers / class-key-controller.php
superb-blocks / src / data / controllers Last commit date
class-cache-controller.php 10 months ago class-css-controller.php 10 months ago class-domainshift-controller.php 10 months ago class-key-controller.php 10 months ago class-log-controller.php 10 months ago class-option-controller.php 10 months ago class-rest-controller.php 10 months ago
class-key-controller.php
202 lines
1 <?php
2
3 namespace SuperbAddons\Data\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 use Exception;
8 use SuperbAddons\Data\Controllers\OptionController;
9 use SuperbAddons\Data\Utils\KeyException;
10 use SuperbAddons\Data\Utils\KeyType;
11 use SuperbAddons\Data\Utils\OptionException;
12
13 class KeyController
14 {
15 const ENDPOINT_BASE = 'addons-status/';
16
17 public static function RegisterKey($key, $is_registration = false)
18 {
19 try {
20 $is_valid = strlen($key) === 23 && preg_match('/^[A-Z0-9]{5}(-[A-Z0-9]{5}){3}$/', $key);
21 if (!$is_valid) {
22 throw new KeyException(esc_html__("Invalid License Key. Please check that the license key was entered correctly.", "superb-blocks"));
23 }
24
25 $option_controller = new OptionController();
26 $stamp = $option_controller->GetStamp();
27 $response = DomainShiftController::RemoteGet(self::ENDPOINT_BASE . 'keys?' . ($is_registration ? "registration=true" : "revalidate=true") . '&key=' . $key . '&dm=' . urlencode(home_url()) . '&stamp=' . absint($stamp));
28 $response_code = wp_remote_retrieve_response_code($response);
29 if (!is_array($response) || is_wp_error($response) || $response_code !== 200) {
30 if ($response_code === 404) {
31 throw new KeyException(esc_html__("License key could not be validated. Please check that the license key was entered correctly.", "superb-blocks"), true, $response_code);
32 } else {
33 throw new KeyException(esc_html__("Unable to validate license key. Please contact support for assistance.", "superb-blocks"), false, $response_code);
34 }
35 }
36
37 $data = json_decode($response['body']);
38 if (!isset($data->level) || !isset($data->active) || !$data->active || !isset($data->expired) || !isset($data->verification) || !$data->verification || !isset($data->verification->exceeded) || !isset($data->verification->verified) || !isset($data->verification->stamp)) {
39 throw new KeyException(esc_html__("License key not currently active. Please contact support for assistance.", "superb-blocks"));
40 }
41
42 if ($data->verification->exceeded) {
43 throw new KeyException(esc_html__("You have already used up all your domain activations for this license key.", "superb-blocks"));
44 }
45
46 if ((!$data->verification->verified || !$data->verification->stamp) && $data->active && !$data->expired) {
47 throw new KeyException(esc_html__("License key verification could not complete. Please contact support for assistance.", "superb-blocks"));
48 }
49
50 if ($data->expired && $data->level !== KeyType::STANDARD) {
51 throw new KeyException(esc_html__("License key has expired. Please renew your subscription to re-activate your license.", "superb-blocks"));
52 }
53
54 try {
55 $option_controller->UpdateKey($key, $data->verification->stamp);
56 self::UpdateKeyType($data->level, $data->active, $data->expired, $data->exceeded);
57 return array("type" => $data->level, "active" => $data->active, "expired" => $data->expired, "verified" => $data->verification->verified, "exceeded" => $data->exceeded);
58 } catch (OptionException $o_ex) {
59 self::RemoveKey($key, $data->verification->stamp);
60 throw new KeyException(esc_html__("Unable to store license in WordPress. If the problem persists, please contact support.", "superb-blocks"));
61 }
62 } catch (KeyException $k_ex) {
63 throw $k_ex;
64 } catch (Exception $ex) {
65 LogController::HandleException($ex);
66 throw new KeyException(esc_html__("Internal Error Occurred During License Key Registration", "superb-blocks"));
67 }
68 }
69
70 public static function RemoveKey($request_key = false, $request_stamp = false)
71 {
72 $option_controller = new OptionController();
73 try {
74 $stamp = $request_stamp ? $request_stamp : $option_controller->GetStamp();
75 $key = $request_key ? $request_key : $option_controller->GetKey();
76 $response = DomainShiftController::RemoteGet(self::ENDPOINT_BASE . 'keys/remove?key=' . $key . '&dm=' . urlencode(home_url()) . '&stamp=' . absint($stamp));
77 $response_code = wp_remote_retrieve_response_code($response);
78 if (!is_array($response) || is_wp_error($response) || $response_code !== 200) {
79 throw new Exception(esc_html__("License key removal record not received.", "superb-blocks"), $response_code);
80 }
81 } catch (Exception $ex) {
82 LogController::HandleException($ex);
83 }
84 return $option_controller->RemoveKey();
85 }
86
87 public static function GetUpdatedLicenseKeyInformation()
88 {
89 try {
90 $option_controller = new OptionController();
91 if ($option_controller->HasRegisteredKey()) {
92 $key = $option_controller->GetKey();
93 return KeyController::RegisterKey($key);
94 }
95 return array("type" => KeyType::FREE, "active" => true, "expired" => false, "verified" => true, "exceeded" => false);
96 } catch (KeyException $k_ex) {
97 throw $k_ex;
98 } catch (Exception $ex) {
99 LogController::HandleException($ex);
100 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
101 }
102 }
103
104 public static function HasRegisteredKey()
105 {
106 $option_controller = new OptionController();
107 return $option_controller->HasRegisteredKey();
108 }
109
110 public static function HasValidStandardKey()
111 {
112 $option_controller = new OptionController();
113 $has_standard = $option_controller->HasStandardKey();
114 $is_active = $option_controller->KeyIsActive();
115 $is_verified = $option_controller->KeyIsVerified();
116 $is_exceeded = $option_controller->KeyIsExceeded();
117 return $has_standard && $is_active && $is_verified && !$is_exceeded;
118 }
119
120 public static function HasValidPremiumKey()
121 {
122 $option_controller = new OptionController();
123 $has_premium = $option_controller->HasPremiumKey();
124 $is_expired = $option_controller->KeyIsExpired();
125 $is_active = $option_controller->KeyIsActive();
126 $is_verified = $option_controller->KeyIsVerified();
127 $is_exceeded = $option_controller->KeyIsExceeded();
128 return $has_premium && !$is_expired && $is_active && $is_verified && !$is_exceeded;
129 }
130
131 public static function HasValidKey()
132 {
133 $option_controller = new OptionController();
134 $has_key = $option_controller->HasRegisteredKey();
135 if (!$has_key) {
136 return false;
137 }
138 $is_expired = !$option_controller->HasStandardKey() && $option_controller->KeyIsExpired();
139 $is_active = $option_controller->KeyIsActive();
140 $is_verified = $option_controller->KeyIsVerified();
141 $is_exceeded = $option_controller->KeyIsExceeded();
142 return !$is_expired && $is_active && $is_verified && !$is_exceeded;
143 }
144
145 public static function GetKeyTypeLabel($keytype)
146 {
147 switch ($keytype) {
148 case KeyType::PREMIUM:
149 return __("Premium License", "superb-blocks");
150 case KeyType::STANDARD:
151 return __("Theme License", "superb-blocks");
152 case KeyType::ADDONS:
153 return __("Addons License", "superb-blocks");
154 case KeyType::FREE_PLUS:
155 return __("Free+ License", "superb-blocks");
156 case KeyType::FREE:
157 default:
158 return __("Free License", "superb-blocks");
159 }
160 }
161
162 public static function GetCurrentKeyTypeLabel()
163 {
164 $option_controller = new OptionController();
165
166 if (!self::HasValidKey()) {
167 return self::GetKeyTypeLabel(KeyType::FREE);
168 }
169
170 return self::GetKeyTypeLabel($option_controller->GetKeyType());
171 }
172
173 public static function VerificationFailed()
174 {
175 $option_controller = new OptionController();
176 return $option_controller->SetKeyVerificationFailed();
177 }
178
179 public static function GetKeyStatus()
180 {
181 $option_controller = new OptionController();
182 return array("type" => $option_controller->GetKeyType(), "active" => $option_controller->KeyIsActive(), "expired" => $option_controller->KeyIsExpired(), "verified" => $option_controller->KeyIsVerified(), "exceeded" => $option_controller->KeyIsExceeded());
183 }
184
185 public static function UpdateKeyType($keytype, $active, $expired, $exceeded)
186 {
187 $option_controller = new OptionController();
188 switch ($keytype) {
189 case KeyType::PREMIUM:
190 case KeyType::STANDARD:
191 case KeyType::ADDONS:
192 case KeyType::FREE_PLUS:
193 // Accepted key types
194 break;
195 default:
196 $keytype = KeyType::FREE;
197 break;
198 }
199 return $option_controller->UpdateKeyType($keytype, $active, $expired, $exceeded);
200 }
201 }
202