PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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
← All changes | back/Controllers/Configuration/License.php +39 -10 10.2.2 → 11.1.0 View file →
@@ -7,8 +7,10 @@
7 7 trait License
8 8 {
9 9 public function unlinkLicense(): void
10 10 {
11 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
12 +
11 13 $config = acym_getVar('array', 'config', []);
12 14 $licenseKey = empty($config['license_key']) ? $this->config->get('license_key') : $config['license_key'];
13 15
14 16 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKey);
@@ -13,9 +15,10 @@
13 15
14 16 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKey);
15 17
16 18 if ($resultUnlinkLicenseOnUpdateMe['success'] === true) {
17 - $this->config->save(['license_key' => '']);
19 + $this->config->saveConfig(['license_key' => '']);
20 + UpdatemeHelper::getLicenseInfo();
18 21 }
19 22
20 23 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
21 24 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
@@ -20,14 +23,17 @@
20 23 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
21 24 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
22 25 }
23 26
27 + //Display the configuration
24 28 $this->listing();
25 29 }
26 30
27 31 public function attachLicense(): void
28 32 {
33 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
29 34
35 +
30 36 $config = acym_getVar('array', 'config', []);
31 37 if (empty($config['license_key'])) {
32 38 $this->displayMessage(acym_translation('ACYM_PLEASE_SET_A_LICENSE_KEY'));
33 39 $this->listing();
@@ -34,14 +40,18 @@
34 40
35 41 return;
36 42 }
37 43
38 - $this->config->save(['license_key' => $config['license_key']]);
44 + //We save the license key
45 + $this->config->saveConfig(['license_key' => $config['license_key']]);
39 46
47 + //We call updateme to attach the website to the license
40 48 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe();
41 49
42 50 if ($resultAttachLicenseOnUpdateMe['success'] === false) {
43 - $this->config->save(['license_key' => '']);
51 + $this->config->saveConfig(['license_key' => '']);
52 + } else {
53 + UpdatemeHelper::getLicenseInfo();
44 54 }
45 55
46 56 if (!empty($resultAttachLicenseOnUpdateMe['message'])) {
47 57 $this->displayMessage($resultAttachLicenseOnUpdateMe['message']);
@@ -52,8 +62,9 @@
52 62
53 63 public function attachLicenseOnUpdateMe(?string $licenseKey = null): array
54 64 {
55 65
66 + //We get the license key saved
56 67 if (is_null($licenseKey)) {
57 68 $licenseKey = $this->config->get('license_key', '');
58 69 }
59 70
@@ -75,10 +86,10 @@
75 86 ];
76 87
77 88 $resultAttach = UpdatemeHelper::call('api/websites/attach', 'POST', $data);
78 89
79 - acym_checkVersion();
80 -
90 + // If it's not the result well formatted => don't save the license key and out
91 + // If there is an error when the website has been attached => don't save the license key in the configuration
81 92 if (empty($resultAttach) || !$resultAttach['success']) {
82 93 return $return;
83 94 }
84 95
@@ -88,8 +99,9 @@
88 99 }
89 100
90 101 private function unlinkLicenseOnUpdateMe(?string $licenseKey = null): array
91 102 {
103 + //We get the license key saved
92 104 if (is_null($licenseKey)) {
93 105 $licenseKey = $this->config->get('license_key');
94 106 }
95 107
@@ -103,8 +115,9 @@
103 115
104 116 return $return;
105 117 }
106 118
119 + //First let's deactivate the cron
107 120 $this->deactivateCron(false, $licenseKey);
108 121
109 122 $data = [
110 123 'domain' => ACYM_LIVE,
@@ -109,12 +122,12 @@
109 122 $data = [
110 123 'domain' => ACYM_LIVE,
111 124 ];
112 125
126 + //Call updateme to unlink the license from this website
113 127 $resultUnlink = UpdatemeHelper::call('api/websites/unlink', 'POST', $data);
114 128
115 - acym_checkVersion();
116 -
129 + //If it's not the result well formated => out
117 130 if (empty($resultUnlink) || !$resultUnlink['success']) {
118 131 return $return;
119 132 }
120 133
@@ -124,23 +137,33 @@
124 137 }
125 138
126 139 public function activateCron(): void
127 140 {
141 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
128 142
143 +
129 144 $result = $this->modifyCron('activateCron');
145 + //If everything went ok we save config with an active_cron to true
130 146 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
131 - $this->config->save(['active_cron' => 1]);
147 + $this->config->saveConfig(['active_cron' => 1]);
132 148 }
133 149
134 150 $this->listing();
135 151 }
136 152
153 + //The listing parameter allows us to know if we need to display the listing or not
137 154 public function deactivateCron(bool $listing = true, ?string $licenseKey = null): void
138 155 {
156 + // Called as a task (no argument) → require a CSRF token. Internal calls (e.g. unlinkLicense) are already token-checked.
157 + if (func_num_args() === 0) {
158 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
159 + }
139 160
161 +
140 162 $result = $this->modifyCron('deactivateCron', $licenseKey);
163 + //If everything went ok we save config with an active_cron to false
141 164 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
142 - $this->config->save(['active_cron' => 0]);
165 + $this->config->saveConfig(['active_cron' => 0]);
143 166 }
144 167
145 168 if ($listing) {
146 169 $this->listing();
@@ -146,8 +169,9 @@
146 169 $this->listing();
147 170 }
148 171 }
149 172
173 + //The listing parameter allows us to know if we need to display the listing or not
150 174 public function modifyCron(string $functionToCall, ?string $licenseKey = null): array
151 175 {
152 176 if (is_null($licenseKey)) {
153 177 $config = acym_getVar('array', 'config', []);
@@ -153,8 +177,9 @@
153 177 $config = acym_getVar('array', 'config', []);
154 178 $licenseKey = empty($config['license_key']) ? '' : $config['license_key'];
155 179 }
156 180
181 + //If the license is not set => out
157 182 if (empty($licenseKey)) {
158 183 $this->displayMessage('LICENSE_NOT_FOUND');
159 184
160 185 return [];
@@ -168,10 +193,12 @@
168 193 'activate' => $functionToCall === 'activateCron',
169 194 'security_key' => $this->config->get('cron_key'),
170 195 ];
171 196
197 + //We call updateme to activate/deactivate the cron
172 198 $result = UpdatemeHelper::call('api/crons/modify', 'POST', $data);
173 199
200 + //If it's not the result well formated => out
174 201 if (empty($result['success'])) {
175 202 $this->displayMessage(empty($result['message']) ? 'CRON_NOT_SAVED' : $result['message']);
176 203
177 204 return [];
@@ -181,8 +208,10 @@
181 208 }
182 209
183 210 public function attachLicenseAcymailer(): void
184 211 {
212 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
213 +
185 214 $acyMailerLicenseKey = $this->config->get('acymailer_apikey');
186 215 $acyMailingKey = $this->config->get('license_key');
187 216 if (empty($acyMailerLicenseKey) && !empty($acyMailingKey)) {
188 217 acym_trigger('onAcymAttachLicense', [&$acyMailingKey]);
@@ -193,9 +222,9 @@
193 222
194 223 if (empty($acyMailerLicenseKey)) {
195 224 acym_enqueueMessage(acym_translation('ACYM_LICENCE_NO_SENDING_SERVICE'), 'error');
196 225 } else {
197 - $this->config->save(['mailer_method' => 'acymailer']);
226 + $this->config->saveConfig(['mailer_method' => 'acymailer']);
198 227 acym_enqueueMessage(acym_translation('ACYM_SENDING_SERVICE_ACTIVATED'), 'success', false);
199 228 }
200 229
201 230 $this->listing();