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

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