PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Controllers / Configuration / License.php

License.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Controllers/Configuration/License.php

204 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Configuration;
4
5 use AcyMailing\Helpers\UpdatemeHelper;
6
7 trait License
8 {
9 public function unlinkLicense(): void
10 {
11 $config = acym_getVar('array', 'config', []);
12 $licenseKey = empty($config['license_key']) ? $this->config->get('license_key') : $config['license_key'];
13
14 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKey);
15
16 if ($resultUnlinkLicenseOnUpdateMe['success'] === true) {
17 $this->config->save(['license_key' => '']);
18 }
19
20 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
21 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
22 }
23
24 $this->listing();
25 }
26
27 public function attachLicense(): void
28 {
29
30 $config = acym_getVar('array', 'config', []);
31 if (empty($config['license_key'])) {
32 $this->displayMessage(acym_translation('ACYM_PLEASE_SET_A_LICENSE_KEY'));
33 $this->listing();
34
35 return;
36 }
37
38 $this->config->save(['license_key' => $config['license_key']]);
39
40 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe();
41
42 if ($resultAttachLicenseOnUpdateMe['success'] === false) {
43 $this->config->save(['license_key' => '']);
44 }
45
46 if (!empty($resultAttachLicenseOnUpdateMe['message'])) {
47 $this->displayMessage($resultAttachLicenseOnUpdateMe['message']);
48 }
49
50 $this->listing();
51 }
52
53 public function attachLicenseOnUpdateMe(?string $licenseKey = null): array
54 {
55
56 if (is_null($licenseKey)) {
57 $licenseKey = $this->config->get('license_key', '');
58 }
59
60 $return = [
61 'message' => '',
62 'success' => false,
63 ];
64
65 if (empty($licenseKey)) {
66 $return['message'] = 'LICENSE_NOT_FOUND';
67
68 return $return;
69 }
70
71 $data = [
72 'domain' => ACYM_LIVE,
73 'cms' => ACYM_CMS,
74 'version' => $this->config->get('version'),
75 ];
76
77 $resultAttach = UpdatemeHelper::call('api/websites/attach', 'POST', $data);
78
79 acym_checkVersion();
80
81 if (empty($resultAttach) || !$resultAttach['success']) {
82 return $return;
83 }
84
85 acym_trigger('onAcymAttachLicense', [&$licenseKey]);
86
87 return $resultAttach;
88 }
89
90 private function unlinkLicenseOnUpdateMe(?string $licenseKey = null): array
91 {
92 if (is_null($licenseKey)) {
93 $licenseKey = $this->config->get('license_key');
94 }
95
96 $return = [
97 'message' => '',
98 'success' => false,
99 ];
100
101 if (empty($licenseKey)) {
102 $return['message'] = 'LICENSE_NOT_FOUND';
103
104 return $return;
105 }
106
107 $this->deactivateCron(false, $licenseKey);
108
109 $data = [
110 'domain' => ACYM_LIVE,
111 ];
112
113 $resultUnlink = UpdatemeHelper::call('api/websites/unlink', 'POST', $data);
114
115 acym_checkVersion();
116
117 if (empty($resultUnlink) || !$resultUnlink['success']) {
118 return $return;
119 }
120
121 acym_trigger('onAcymDetachLicense');
122
123 return $resultUnlink;
124 }
125
126 public function activateCron(): void
127 {
128
129 $result = $this->modifyCron('activateCron');
130 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
131 $this->config->save(['active_cron' => 1]);
132 }
133
134 $this->listing();
135 }
136
137 public function deactivateCron(bool $listing = true, ?string $licenseKey = null): void
138 {
139
140 $result = $this->modifyCron('deactivateCron', $licenseKey);
141 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
142 $this->config->save(['active_cron' => 0]);
143 }
144
145 if ($listing) {
146 $this->listing();
147 }
148 }
149
150 public function modifyCron(string $functionToCall, ?string $licenseKey = null): array
151 {
152 if (is_null($licenseKey)) {
153 $config = acym_getVar('array', 'config', []);
154 $licenseKey = empty($config['license_key']) ? '' : $config['license_key'];
155 }
156
157 if (empty($licenseKey)) {
158 $this->displayMessage('LICENSE_NOT_FOUND');
159
160 return [];
161 }
162
163 $data = [
164 'domain' => ACYM_LIVE,
165 'cms' => ACYM_CMS,
166 'version' => $this->config->get('version'),
167 'level' => $this->config->get('level'),
168 'activate' => $functionToCall === 'activateCron',
169 'security_key' => $this->config->get('cron_key'),
170 ];
171
172 $result = UpdatemeHelper::call('api/crons/modify', 'POST', $data);
173
174 if (empty($result['success'])) {
175 $this->displayMessage(empty($result['message']) ? 'CRON_NOT_SAVED' : $result['message']);
176
177 return [];
178 }
179
180 return $result;
181 }
182
183 public function attachLicenseAcymailer(): void
184 {
185 $acyMailerLicenseKey = $this->config->get('acymailer_apikey');
186 $acyMailingKey = $this->config->get('license_key');
187 if (empty($acyMailerLicenseKey) && !empty($acyMailingKey)) {
188 acym_trigger('onAcymAttachLicense', [&$acyMailingKey]);
189 }
190
191 $this->config->load();
192 $acyMailerLicenseKey = $this->config->get('acymailer_apikey');
193
194 if (empty($acyMailerLicenseKey)) {
195 acym_enqueueMessage(acym_translation('ACYM_LICENCE_NO_SENDING_SERVICE'), 'error');
196 } else {
197 $this->config->save(['mailer_method' => 'acymailer']);
198 acym_enqueueMessage(acym_translation('ACYM_SENDING_SERVICE_ACTIVATED'), 'success', false);
199 }
200
201 $this->listing();
202 }
203 }
204