PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.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.10.2, at back/Controllers/Configuration/License.php

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