PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.0.7
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.0.7
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-option-controller.php
superb-blocks / src / data / controllers Last commit date
class-cache-controller.php 2 years ago class-domainshift-controller.php 2 years ago class-key-controller.php 2 years ago class-log-controller.php 2 years ago class-option-controller.php 2 years ago class-rest-controller.php 2 years ago
class-option-controller.php
223 lines
1 <?php
2
3 namespace SuperbAddons\Data\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 use SuperbAddons\Config\Config;
8 use SuperbAddons\Data\Utils\KeyType;
9 use SuperbAddons\Data\Utils\OptionException;
10
11 class OptionController
12 {
13 private $current_keydomain_option = false;
14
15 public function __construct()
16 {
17 }
18
19 /* Domains */
20 public function GetPreferredDomain($refresh = false)
21 {
22 $current_option = self::GetKeyDomainOption($refresh);
23 return Config::API_DOMAINS[$current_option[KeyDomainOptionKey::DOMAIN]];
24 }
25
26 public function UpdateAPIDomain($domain)
27 {
28 $domain = absint($domain);
29 if ($domain < 0 || $domain >= count(Config::API_DOMAINS)) {
30 throw new OptionException(__("Invalid Domain Key. Option could not be updated.", 'superbaddons'));
31 }
32 $current_option = self::GetKeyDomainOption(true);
33 $current_option[KeyDomainOptionKey::DOMAIN] = $domain;
34 return update_option(Option::KEY_DOMAIN, $current_option);
35 }
36 /* */
37
38 /* Keys */
39 public function GetKey()
40 {
41 $current_option = self::GetKeyDomainOption();
42 return $current_option[KeyDomainOptionKey::KEY];
43 }
44
45 public function GetStamp()
46 {
47 $current_option = self::GetKeyDomainOption();
48 return $current_option[KeyDomainOptionKey::STAMP];
49 }
50
51 public function GetKeyType()
52 {
53 $current_option = self::GetKeyDomainOption();
54 return $current_option[KeyDomainOptionKey::KEYTYPE];
55 }
56
57 public function KeyIsActive()
58 {
59 $current_option = self::GetKeyDomainOption();
60 return $current_option[KeyDomainOptionKey::KEYACTIVE];
61 }
62
63 public function KeyIsExpired()
64 {
65 $current_option = self::GetKeyDomainOption();
66 return $current_option[KeyDomainOptionKey::KEYEXPIRED];
67 }
68
69 public function KeyIsVerified()
70 {
71 $current_option = self::GetKeyDomainOption();
72 if (!isset($current_option[KeyDomainOptionKey::STAMP]) || !isset($current_option[KeyDomainOptionKey::VERIFIED])) {
73 return false;
74 }
75 return !!$current_option[KeyDomainOptionKey::STAMP] && $current_option[KeyDomainOptionKey::VERIFIED];
76 }
77
78 public function SetKeyVerificationFailed()
79 {
80 $current_option = self::GetKeyDomainOption();
81 $current_option[KeyDomainOptionKey::VERIFIED] = false;
82 return update_option(Option::KEY_DOMAIN, $current_option);
83 }
84
85 public function HasRegisteredKey()
86 {
87 $current_option = self::GetKeyDomainOption();
88 return !!$current_option[KeyDomainOptionKey::KEY];
89 }
90
91 public function HasPremiumKey()
92 {
93 $current_option = self::GetKeyDomainOption();
94 return !!$current_option[KeyDomainOptionKey::KEY] && $current_option[KeyDomainOptionKey::KEYTYPE] === KeyType::PREMIUM;
95 }
96
97 public function UpdateKey($key, $stamp)
98 {
99 if (strlen($key) !== 23) {
100 throw new OptionException(__("Invalid License Key. Option could not be updated.", 'superbaddons'));
101 }
102 $current_option = self::GetKeyDomainOption(true);
103 $current_option[KeyDomainOptionKey::KEY] = $key;
104 if ($stamp > 0) {
105 $current_option[KeyDomainOptionKey::STAMP] = $stamp;
106 }
107 $current_option[KeyDomainOptionKey::VERIFIED] = true;
108 return update_option(Option::KEY_DOMAIN, $current_option);
109 }
110
111 public function UpdateKeyType($keytype, $active, $expired)
112 {
113 $current_option = self::GetKeyDomainOption(true);
114 $current_option[KeyDomainOptionKey::KEYTYPE] = $keytype;
115 $current_option[KeyDomainOptionKey::KEYACTIVE] = !!$active;
116 $current_option[KeyDomainOptionKey::KEYEXPIRED] = !!$expired;
117 return update_option(Option::KEY_DOMAIN, $current_option);
118 }
119
120 public function RemoveKey()
121 {
122 $current_option = self::GetKeyDomainOption(true);
123 $current_option[KeyDomainOptionKey::KEY] = false;
124 $current_option[KeyDomainOptionKey::KEYTYPE] = KeyType::FREE;
125 return update_option(Option::KEY_DOMAIN, $current_option);
126 }
127
128 private function GetKeyDomainOption($refresh = false)
129 {
130 if (!$this->current_keydomain_option || $refresh) {
131 $this->current_keydomain_option = get_option(Option::KEY_DOMAIN, array(KeyDomainOptionKey::DOMAIN => 0, KeyDomainOptionKey::KEY => false, KeyDomainOptionKey::KEYTYPE => KeyType::FREE, KeyDomainOptionKey::KEYEXPIRED => false, KeyDomainOptionKey::KEYACTIVE => true, KeyDomainOptionKey::STAMP => false, KeyDomainOptionKey::VERIFIED => false));
132 }
133 return $this->current_keydomain_option;
134 }
135
136 /* */
137
138 /* Cache */
139 public function GetCache($cache_option)
140 {
141 return get_option($cache_option, false);
142 }
143
144 public function SetCache($cache_option, $data)
145 {
146 if (!$cache_option) {
147 return false;
148 }
149 return update_option(
150 $cache_option,
151 array(
152 'last_update' => time(),
153 'data' => $data
154 ),
155 false
156 );
157 }
158
159 public function ClearCache($cache_option)
160 {
161 if (!$cache_option) {
162 return false;
163 }
164
165 // Return true if cache is already cleared
166 if (!$this->GetCache($cache_option)) return true;
167
168 return delete_option($cache_option);
169 }
170
171 public static function GetSettings()
172 {
173 return get_option(Option::SETTINGS, array(SettingsOptionKey::LOGS_ENABLED => true, SettingsOptionKey::LOG_SHARE_ENABLED => false));
174 }
175
176 public function SaveSettings($settings)
177 {
178 return update_option(Option::SETTINGS, $settings);
179 }
180
181 public static function GetCompatibilitySettings()
182 {
183 return get_option(Option::COMPATIBILITY_SETTINGS, array(CompatibilitySettingsOptionKey::SPECTRA_BLOCK_SPACING => true));
184 }
185
186 public function SaveCompatibilitySettings($compatibility_settings)
187 {
188 return update_option(Option::COMPATIBILITY_SETTINGS, $compatibility_settings);
189 }
190
191 /* */
192 }
193
194 class Option
195 {
196 const PREFIX = 'superbaddonslibrary_';
197 const KEY_DOMAIN = self::PREFIX . 'keydomain';
198 const SETTINGS = self::PREFIX . 'settings';
199 const COMPATIBILITY_SETTINGS = self::PREFIX . 'compatibilitysettings';
200 }
201
202 class KeyDomainOptionKey
203 {
204 const DOMAIN = 'spbdomain';
205 const KEY = 'spbkey';
206 const KEYTYPE = 'spbkeytype';
207 const KEYACTIVE = 'spbkeyactive';
208 const KEYEXPIRED = 'spbkeyexpired';
209 const STAMP = 'spbkeystamp';
210 const VERIFIED = 'spbkeyverified';
211 }
212
213 class SettingsOptionKey
214 {
215 const LOGS_ENABLED = 'spblogsenabled';
216 const LOG_SHARE_ENABLED = 'spblogshareenabled';
217 }
218
219 class CompatibilitySettingsOptionKey
220 {
221 const SPECTRA_BLOCK_SPACING = 'spbspectrablockspacing';
222 }
223