PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.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
← All changes | back/dynamics/acymailer/plugin.php +0 -1222 10.11.1 → 11.1.1 View file →
@@ -1,1222 +1,0 @@
1 -<?php
2 -
3 -use AcyMailing\Classes\MailClass;
4 -use AcyMailing\Classes\QueueClass;
5 -use AcyMailing\Core\AcymPlugin;
6 -
7 -class plgAcymAcymailer extends AcymPlugin
8 -{
9 - const SENDING_METHOD_ID = 'acymailer';
10 - const SENDING_METHOD_NAME = 'AcyMailing sending service';
11 - const SENDING_METHOD_API_URL = 'https://api.acymailer.com/';
12 - const CREDITS_RELOAD_DELAY = 900;
13 - const TRANSLATIONS = [
14 - 0 => 'ACYM_ERROR_SEE_LOGS',
15 - 1 => 'ACYM_PLEASE_INSTALL_LATEST_VERSION',
16 - 2 => 'ACYM_EMAIL_SEND_FAIL_SEE_LOGS',
17 - 3 => 'ACYM_DOMAIN_NOT_ATTACHED_TO_THE_SITE',
18 - 4 => 'ACYM_NOT_ALLOWED_TO_DELETE_THIS_DOMAIN',
19 - 5 => 'ACYM_DOMAIN_DOES_NOT_EXIST',
20 - 6 => 'ACYM_DOMAIN_STATUS_SUCCESSFULLY_OBTAINED',
21 - 7 => 'ACYM_AN_ERROR_RELATED_TO_THE_REMAINING_CREDITS_OCCURRED',
22 - 8 => 'ACYM_LICENSE_EXPIRED',
23 - 9 => 'ACYM_IDENTITY_CREATED',
24 - 10 => 'ACYM_DOMAIN_ALREADY_EXISTS_FOR_THIS_WEBSITE',
25 - 11 => 'ACYM_DOMAIN_ALREADY_EXISTS_AND_DOES_NOT_BELONG_TO_YOU',
26 - 12 => 'ACYM_NO_DOMAINS_TO_CHECK',
27 - 13 => 'ACYM_DOMAINS_VERIFIED',
28 - 14 => 'ACYM_ERROR_WHILE_CHECKING_DOMAINS',
29 - 15 => 'ACYM_BLOCKED_LICENSE',
30 - 16 => 'ACYM_MISSING_EMAIL',
31 - 17 => 'ACYM_MISSING_ARGUMENTS',
32 - 18 => 'ACYM_NO_CREDITS_LEFT',
33 - 19 => 'ACYM_MISSING_API_KEY',
34 - 20 => 'ACYM_DOMAIN_NOT_FOUND',
35 - 21 => 'ACYM_LICENSE_NOT_FOUND',
36 - 22 => 'ACYM_EMAIL_SENT',
37 - 23 => 'ACYM_INVALID_API_KEY',
38 - 24 => 'ACYM_LICENSE_BLOCKED',
39 - 25 => 'ACYM_SEE_LOGS_FILE',
40 - 26 => 'ACYM_SERVICE_TEMPORARY_UNAVAILABLE',
41 - 27 => 'ACYM_DOMAIN_ONLY_ON_ONE_LICENSE',
42 - 28 => 'ACYM_EMAIL_UNDER_VERIFICATION',
43 - 29 => 'ACYM_DOMAIN_BLOCKED',
44 - 30 => 'ACYM_DOMAIN_UNDER_REVIEW',
45 - ];
46 -
47 - private array $errorCodes = [0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30];
48 - private array $cnameErrors = [];
49 -
50 - public function __construct()
51 - {
52 - parent::__construct();
53 - $this->pluginDescription->name = self::SENDING_METHOD_NAME;
54 - }
55 -
56 - protected function callApiSendingMethod(string $url, array $data = [], array $headers = [], string $type = 'GET', array $authentication = [], bool $dataDecoded = false): array
57 - {
58 - if (strpos($url, self::SENDING_METHOD_API_URL) === false) {
59 - $url = self::SENDING_METHOD_API_URL.'api/'.$url;
60 - }
61 -
62 - $defaultHeaders = [
63 - 'accept' => 'application/json',
64 - 'content-type' => 'application/json',
65 - 'API-KEY' => $this->config->get(self::SENDING_METHOD_ID.'_apikey', ''),
66 - 'Version' => $this->config->get('version'),
67 - ];
68 -
69 - foreach ($defaultHeaders as $key => $value) {
70 - if (!isset($headers[$key])) {
71 - $headers[$key] = $value;
72 - }
73 - }
74 -
75 - $result = parent::callApiSendingMethod($url, $data, $headers, $type, $authentication, $dataDecoded);
76 - if (!empty($result['error_curl'])) {
77 - $result['message'] = $result['error_curl'];
78 - $this->errors[] = $result['error_curl'];
79 - $this->errorCallback();
80 - } else {
81 - $result['message'] = $this->translate($result);
82 - }
83 -
84 - return $result;
85 - }
86 -
87 - public function onAcymGetSendingMethods(&$data, $isMailer = false)
88 - {
89 - $data['sendingMethods'][self::SENDING_METHOD_ID] = [
90 - 'name' => $this->pluginDescription->name,
91 - 'image' => ACYM_IMAGES.'mailers/'.self::SENDING_METHOD_ID.'.png',
92 - 'recommended' => true,
93 - 'image_class' => '',
94 - ];
95 - }
96 -
97 - public function onAcymAttachedLicenseOption()
98 - {
99 - $licenseKey = $this->config->get('license_key');
100 - $acyMailerKey = $this->config->get('acymailer_apikey');
101 - $mailerMethod = $this->config->get('mailer_method');
102 -
103 - if (empty($licenseKey) || empty($acyMailerKey) || $mailerMethod === self::SENDING_METHOD_ID) {
104 - return;
105 - }
106 - ?>
107 - <div class="grid-x grid-margin-x margin-top-1" id="activate_ass_method_notice">
108 - <label class="cell medium-7 acym_vcenter">
109 - <i class="acymicon-info-circle" id="acymailer_info_icon"></i>
110 - <?php echo acym_translation('ACYM_ACTIVATE_ACYMAILER'); ?>
111 - </label>
112 - <button type="button"
113 - id="acym__configuration__activate__acymailer"
114 - class="cell shrink button margin-bottom-0">
115 - <?php echo acym_translation('ACYM_SEE_THE_SENDING_METHOD'); ?>
116 - </button>
117 - </div>
118 - <?php
119 - }
120 -
121 - public function onAcymGetSendingMethodsHtmlSetting(&$data)
122 - {
123 - $licenseKey = $this->config->get('license_key');
124 - $acyMailerKey = $this->config->get('acymailer_apikey');
125 - $domains = $this->config->get(self::SENDING_METHOD_ID.'_domains', []);
126 - $domainsWaiting = [];
127 - if (!empty($domains)) {
128 - $domains = json_decode($domains, true);
129 - $domainsWaiting = array_filter($domains, function ($domain) {
130 - return $domain['status'] !== 'SUCCESS';
131 - });
132 - }
133 -
134 - $unverifiedDomains = $this->getDomainsUnVerified();
135 -
136 - ob_start();
137 - ?>
138 - <div class="send_settings cell grid-x acym_vcenter" id="<?php echo self::SENDING_METHOD_ID; ?>_settings">
139 - <div class="cell grid-x acym__sending__methods__one__settings <?php echo empty($data['step']) ? 'xlarge-10 xxlarge-8' : ''; ?>">
140 - <?php if (!acym_level(ACYM_ESSENTIAL) && empty($data['step'])) { ?>
141 - <div class="acym_vcenter acym__config__acymailer__warning margin-top-1 cell grid-x large-8 xlarge-6 xxlarge-5">
142 - <label for="acym__configuration__license-key" class="cell">
143 - <?php echo acym_translation('ACYM_YOUR_LICENSE_KEY'); ?>
144 - </label>
145 - <input type="text" name="config[license_key]" id="acym__configuration__license-key" class="cell auto" value="<?php echo acym_escape($licenseKey); ?>">
146 - <button type="button"
147 - id="acym__configuration__button__license"
148 - class="cell shrink medium-3 button margin-top-1 medium-margin-top-0 medium-margin-left-1"
149 - data-acym-linked="<?php echo empty($licenseKey) ? 0 : 1; ?>">
150 - <?php echo acym_translation(empty($licenseKey) ? 'ACYM_ATTACH_MY_LICENSE' : 'ACYM_UNLINK_MY_LICENSE'); ?>
151 - </button>
152 - </div>
153 - <?php }
154 - if (empty($licenseKey)) { ?>
155 - <div class="cell acym_vcenter acym__config__acymailer__warning margin-top-1">
156 - <i class="acymicon-exclamation-triangle acym__color__orange"></i>
157 - <span class="margin-right-1">
158 - <?php
159 - $pricingPage = ACYM_ACYMAILING_WEBSITE.'pricing?utm_source=acymailing_plugin&utm_medium=sendingmethod&utm_campaign=purchase';
160 - echo acym_translation(acym_level(ACYM_ESSENTIAL) ? 'ACYM_NO_LICENSE' : 'ACYM_NO_LICENSE_STARTER');
161 - ?>
162 - <a target="_blank" href="<?php echo $pricingPage; ?>"><?php echo acym_translation('ACYM_GET_A_LICENSE'); ?></a>
163 - </span>
164 - </div>
165 - <?php } elseif (empty($acyMailerKey)) { ?>
166 - <div class="cell acym_vcenter acym__config__acymailer__warning margin-top-1">
167 - <i class="acymicon-exclamation-triangle acym__color__orange"></i>
168 - <span>
169 - <?php
170 - $subscriptionsPage = ACYM_ACYMAILING_WEBSITE.'account/license?utm_source=acymailing_plugin&utm_medium=sendingmethod&utm_campaign=purchase';
171 - echo acym_translation('ACYM_API_KEY_NOT_ALLOWING_METHOD');
172 - ?>
173 - <a target="_blank" href="<?php echo $subscriptionsPage; ?>"><?php echo acym_translation('ACYM_SWITCH_MY_LICENSE'); ?></a>
174 - </span>
175 - </div>
176 -
177 - <div class="acym__configuration__acymailer__check-license cell grid-x">
178 - <div class="cell"><?php echo acym_translation('ACYM_CHECK_SENDING_SERVICE_LICENSE'); ?></div>
179 - <button
180 - data-task="attachLicenseAcymailer"
181 - id="acym__configuration__acymailer__verify-license"
182 - class="cell medium-shrink button margin-left-0 margin-top-1 acy_button_submit">
183 - <?php echo acym_translation('ACYM_CHECK_LICENSE'); ?>
184 - </button>
185 - </div>
186 - <?php } else { ?>
187 - <div class="cell grid-x">
188 - <?php if (!empty($domainsWaiting)) { ?>
189 - <div class="cell <?php echo empty($data['step']) ? 'large-8' : ''; ?> grid-x acym_vcenter acym__config__acymailer__warning">
190 - <i class="cell small-2 margin-right-0 acymicon-access-time acym__color__orange"></i>
191 - <div class="cell small-10 grid-x">
192 - <span class="cell"><?php echo acym_translation('ACYM_DOMAINS_WAITING_VALIDATION_ADD_CNAME'); ?></span>
193 - <a href="<?php echo ACYM_DOCUMENTATION; ?>external-sending-method/acymailing-sending-service#how-to-add-the-dns-entries-on-my-server"
194 - target="_blank"
195 - class="cell">
196 - <?php echo acym_translation('ACYM_CHECK_THIS_TUTORIAL'); ?>
197 - </a>
198 - </div>
199 - </div>
200 - <div class="cell <?php echo empty($data['step']) ? 'large-4' : ''; ?> margin-top-1 margin-bottom-1">
201 - <button id="acym__config__acymailer__update-domain-status"
202 - type="button"
203 - class="button button-secondary float-right"
204 - sending-method-id="<?php echo self::SENDING_METHOD_ID; ?>">
205 - <i class="acymicon-autorenew"></i><?php echo acym_translation('ACYM_UPDATE_DOMAIN_STATUS'); ?>
206 - </button>
207 - </div>
208 - <?php } ?>
209 - </div>
210 - <div class="grid-x acym__listing cell">
211 - <div class="grid-x cell acym__listing__header">
212 - <div class="grid-x medium-auto small-11 cell acym__listing__header__title__container">
213 - <div class="cell small-8 medium-auto acym__listing__header__title">
214 - <?php echo acym_translation('ACYM_DOMAIN_NAME'); ?>
215 - </div>
216 - <div class="cell hide-for-small-only medium-2 acym__listing__header__title text-center">
217 - <?php echo acym_translation('ACYM_STATUS'); ?>
218 - </div>
219 - <div class="cell hide-for-small-only medium-2 acym__listing__header__title text-center">
220 - <?php echo acym_translation('ACYM_BOUNCE_RATE').acym_info(['textShownInTooltip' => 'ACYM_BOUNCE_RATE_DESC']); ?>
221 - </div>
222 - <div class="cell hide-for-small-only medium-2 acym__listing__header__title text-center">
223 - <?php echo acym_translation('ACYM_COMPLAINT_RATE').acym_info(['textShownInTooltip' => 'ACYM_COMPLAINT_RATE_DESC']); ?>
224 - </div>
225 - <div class="cell small-4 medium-2 acym__listing__header__title text-center">
226 - <?php echo acym_translation('ACYM_ACTIONS'); ?>
227 - </div>
228 - </div>
229 - </div>
230 - <?php if (empty($domains)) { ?>
231 - <div class="grid-x cell margin-top-1 align-center">
232 - <?php echo acym_translation('ACYM_NO_DOMAINS_YET'); ?>
233 - </div>
234 - <?php } else {
235 - foreach ($domains as &$domain) {
236 - $isValid = true;
237 - foreach ($domain['CnameRecords'] as $i => $cnameRecord) {
238 - $domain['CnameRecords'][$i]['isValid'] = $this->checkCnameEntry($cnameRecord['name'], $cnameRecord['value']);
239 - $isValid = $isValid && $domain['CnameRecords'][$i]['isValid'];
240 - $domain['CnameRecords'][$i]['tooltipMessages'] = $this->cnameErrors;
241 - $this->cnameErrors = [];
242 - }
243 -
244 - if (!$isValid && $domain['status'] === 'SUCCESS') {
245 - $domain['status'] = 'PENDING';
246 - $this->config->saveConfig([self::SENDING_METHOD_ID.'_domains' => json_encode($domains)]);
247 - }
248 -
249 - $bounceRateParams = $this->getRateColor(
250 - empty($domain['bounce_rate']) ? 0 : $domain['bounce_rate'],
251 - empty($domain['allowed_bounce_rate']) ? 0 : $domain['allowed_bounce_rate'],
252 - empty($domain['warning_bounce_rate']) ? 0 : $domain['warning_bounce_rate']
253 - );
254 - $complaintRateParams = $this->getRateColor(
255 - empty($domain['complaint_rate']) ? 0 : $domain['complaint_rate'],
256 - empty($domain['allowed_complaint_rate']) ? 0 : $domain['allowed_complaint_rate'],
257 - empty($domain['warning_complaint_rate']) ? 0 : $domain['warning_complaint_rate']
258 - );
259 - ?>
260 - <div acym-data-domain="<?php echo $domain['domain']; ?>" class="grid-x cell align-middle acym__listing__row">
261 - <div class="cell small-6 medium-auto grid-x acym__listing__title__container">
262 - <?php echo acym_escape($domain['domain']); ?>
263 - </div>
264 - <div class="cell small-1 medium-2 grid-x acym__listing__title__container align-center">
265 - <?php
266 - switch ($domain['status']) {
267 - case 'SUCCESS':
268 - $iconClass = 'acymicon-check-circle acym__color__green';
269 - $tooltipText = acym_translation('ACYM_VALIDATED');
270 - break;
271 - case 'FAILED':
272 - $iconClass = 'acymicon-close acym__color__red notValidated';
273 - $tooltipText = acym_translation('ACYM_APPROVAL_FAILED');
274 - break;
275 - default:
276 - $iconClass = 'acymicon-access-time acym__color__orange notValidated';
277 - $tooltipText = acym_translation('ACYM_A_CNAME_MISSING');
278 - }
279 -
280 - echo acym_tooltip(
281 - [
282 - 'hoveredText' => '<i class="acym__config__acymailer__status__icon '.$iconClass.'"></i>',
283 - 'textShownInTooltip' => $tooltipText,
284 - ]
285 - );
286 - ?>
287 - </div>
288 - <div class="cell hide-for-small-only medium-2 grid-x acym__listing__title__container align-center <?php echo $bounceRateParams['color']; ?>">
289 - <?php echo empty($domain['bounce_rate']) ? '-' : round($domain['bounce_rate'], 2).'%';
290 - echo $bounceRateParams['icon'];
291 - ?>
292 - </div>
293 - <div class="cell hide-for-small-only medium-2 grid-x acym__listing__title__container align-center <?php echo $complaintRateParams['color']; ?>">
294 - <?php echo empty($domain['complaint_rate']) ? '-' : round($domain['complaint_rate'], 2).'%';
295 - echo $complaintRateParams['icon'];
296 - ?>
297 - </div>
298 - <div class="cell small-4 medium-2 grid-x margin-left-1 medium-margin-left-0 acym__listing__title__container align-center">
299 - <?php ob_start(); ?>
300 - <div class="cell grid-x acym__config__acymailer__cname__modal">
301 - <h6 class="cell text-center margin-top-2 margin-bottom-1"><?php echo acym_translation('ACYM_DNS_ENTRIES'); ?></h6>
302 - <div class="grid-x cell align-center margin-top-1 margin-bottom-2 acym_vcenter">
303 - <p class="cell shrink"><?php echo acym_translation('ACYM_DO_NOT_KNOW_HOW_DO_IT'); ?> </p>
304 - <a href="<?php echo ACYM_DOCUMENTATION; ?>external-sending-method/acymailing-sending-service#how-to-add-the-dns-entries-on-my-server"
305 - class="cell shrink acym__config__acymailer__cname__modal__link"
306 - target="_blank">
307 - <?php echo acym_translation('ACYM_STEP_BY_STEP_GUIDE'); ?>
308 - </a>
309 - </div>
310 - <div class="grid-x acym__listing cell">
311 - <div class="grid-x acym__listing cell">
312 - <div class="cell grid-x grid-margin-x margin-left-0 padding-bottom-1 acym__listing__header">
313 - <div class="cell small-10 hide-for-medium acym__listing__header__title">
314 - <?php echo acym_translation('ACYM_NAME').' / '.acym_translation('ACYM_VALUE'); ?>
315 - </div>
316 - <div class="cell small-5 show-for-medium acym__listing__header__title">
317 - <?php echo acym_translation('ACYM_NAME'); ?>
318 - </div>
319 - <div class="cell small-5 show-for-medium acym__listing__header__title">
320 - <?php echo acym_translation('ACYM_VALUE'); ?>
321 - </div>
322 - <div class="cell small-2 acym__listing__header__title text-center">
323 - <?php echo acym_translation('ACYM_STATUS'); ?>
324 - </div>
325 - </div>
326 - <?php
327 - foreach ($domain['CnameRecords'] as $cnameRecord) {
328 - if ($cnameRecord['isValid']) {
329 - $cnameStatus = '<i class="acym__config__acymailer__status__icon acymicon-check-circle acym__color__green"></i>';
330 - } else {
331 - $cnameStatus = acym_tooltip(
332 - [
333 - 'hoveredText' => '<i class="acym__config__acymailer__status__icon acymicon-close acym__color__red"></i>',
334 - 'textShownInTooltip' => implode('<br/>', $cnameRecord['tooltipMessages']),
335 - ]
336 - );
337 - }
338 - ?>
339 - <div class="cell grid-x grid-margin-x margin-left-0 align-middle acym__listing__row">
340 - <div class="cell small-11 medium-5 cname-name">
341 - <?php echo $cnameRecord['name']; ?>
342 - </div>
343 - <div class="cell small-1 hide-for-medium cname-value">
344 - <?php echo $cnameStatus; ?>
345 - </div>
346 - <div class="cell small-11 medium-5 cname-value">
347 - <?php echo $cnameRecord['value']; ?>
348 - </div>
349 - <div class="cell medium-2 show-for-medium text-center">
350 - <?php echo $cnameStatus; ?>
351 - </div>
352 - </div>
353 - <?php } ?>
354 - </div>
355 - </div>
356 - </div>
357 - <?php
358 - $modalContent = ob_get_clean();
359 - $buttonModal = acym_tooltip(
360 - [
361 - 'hoveredText' => '<i class="acymicon-cogs acym__config__acymailer__domain--settings cursor-pointer acym__color__blue" acym-data-domain="'.$domain['domain'].'"></i>',
362 - 'textShownInTooltip' => acym_translation('ACYM_SHOW_DNS_SETTINGS'),
363 - ]
364 - );
365 - echo acym_modal(
366 - $buttonModal,
367 - $modalContent,
368 - null,
369 - [],
370 - [],
371 - true,
372 - true,
373 - 'acym__config__acymailer__cname__modal__container'
374 - );
375 -
376 - echo acym_tooltip(
377 - [
378 - 'hoveredText' => '<i class="acymicon-delete acym__config__acymailer__domain--delete cursor-pointer" acym-data-domain="'.acym_escape(
379 - $domain['domain']
380 - ).'"></i>',
381 - 'textShownInTooltip' => acym_translation('ACYM_DELETE'),
382 - ]
383 - );
384 - ?>
385 - </div>
386 - </div>
387 - <?php
388 - }
389 - }
390 - ?>
391 - </div>
392 - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings padding-top-1">
393 - <div class="cell grid-x">
394 - <div class="cell small-7 medium-4 large-3 margin-next-1">
395 - <input id="<?php echo self::SENDING_METHOD_ID; ?>_domain"
396 - class="cell medium-6 large-4 xlarge-3"
397 - type="text"
398 - autocomplete="off"
399 - value="">
400 - <span id="<?php echo self::SENDING_METHOD_ID; ?>_domain_error" class="medium-6 large-4 xlarge-3"></span>
401 - <?php
402 - if (!empty($unverifiedDomains)) { ?>
403 - <span id="acym__acymailer__unverifiedDomains">
404 - <?php foreach ($unverifiedDomains as $oneDomain) { ?>
405 - <span class="acym__acymailer__oneSuggestion"><?php echo $oneDomain; ?></span>
406 - <?php } ?>
407 - </span>
408 - <?php } ?>
409 - </div>
410 - <div id="acym__configuration__sending__method_addDomain_submit" class="cell grid-x small-4 medium-6 large-8 acym_vcenter">
411 - <button type="button"
412 - id="acym__configuration__sending__method-addDomain"
413 - class="cell shrink button button-secondary">
414 - <?php echo acym_translation('ACYM_ADD_A_DOMAIN'); ?>
415 - </button>
416 - <i class="margin-left-1 acym_vcenter acymicon-circle-o-notch acymicon-spin is-hidden"
417 - id="acym__configuration__sending__method_add_domain-wait"></i>
418 - <div class="cell shrink grid-x acym_vcenter" id="acym__configuration__acymailer__add__error">
419 - <i class="acymicon-close acym__color__red cell shrink"></i>
420 - <span class="cell shrink" id="acym__configuration__acymailer__add__error__message"></span>
421 - </div>
422 - </div>
423 - </div>
424 - </div>
425 - <?php if (!$this->isLogFileEmpty()) { ?>
426 - <div class="cell grid-x acym__sending__methods__log">
427 - <?php
428 - echo acym_modal(
429 - acym_translation('ACYM_REPORT_SEE'),
430 - '',
431 - null,
432 - [],
433 - [
434 - 'class' => 'button',
435 - 'data-ajax' => 'true',
436 - 'data-iframe' => '&ctrl=configuration&task=seeLogs&filename='.$this->logFilename,
437 - ]
438 - );
439 - ?>
440 - </div>
441 - <?php } ?>
442 - <?php } ?>
443 - </div>
444 - </div>
445 - <?php
446 - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean();
447 - }
448 -
449 - public function onAcymTestCredentialSendingMethod($sendingMethod, $credentials)
450 - {
451 - if ($sendingMethod !== self::SENDING_METHOD_ID) return;
452 -
453 - if (empty($credentials[self::SENDING_METHOD_ID.'_apikey'])) {
454 - acym_sendAjaxResponse(acym_translation('ACYM_MISSING_API_KEY'), [], false);
455 - }
456 -
457 - $response = $this->callApiSendingMethod(
458 - 'get_credits',
459 - [],
460 - [
461 - 'API-KEY' => $credentials[self::SENDING_METHOD_ID.'_apikey'],
462 - ]
463 - );
464 -
465 - if (empty($response)) {
466 - $errorMsg = acym_translation('ACYM_NO_ANSWER');
467 - acym_sendAjaxResponse(acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $errorMsg), [], false);
468 - } elseif (!empty($response['error_curl'])) {
469 - acym_sendAjaxResponse(acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $response['error_curl']), [], false);
470 - } elseif (!empty($response['message']) && $response['message'] == 'Invalid private key') {
471 - acym_sendAjaxResponse(acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY'), [], false);
472 - } elseif (!empty($response['message']) && !$this->checkSuccessCode($this->responseCode)) {
473 - if ($this->responseCode === 401) {
474 - acym_sendAjaxResponse(
475 - acym_translationSprintf(
476 - 'ACYM_SENDING_METHOD_ERROR_WHILE_ACTION',
477 - self::SENDING_METHOD_NAME,
478 - acym_translation('ACYM_GETTING_REMAINING_CREDITS'),
479 - $response['message']
480 - ),
481 - [],
482 - false
483 - );
484 - }
485 - acym_sendAjaxResponse($response['message'], [], false);
486 - } else {
487 - acym_sendAjaxResponse(acym_translation('ACYM_API_KEY_CORRECT'));
488 - }
489 - }
490 -
491 - public function onAcymSendEmail(&$response, $mailerHelper, $to, $from, $replyTo, $bcc = [], $attachments = [], $sendingMethodListParams = [])
492 - {
493 - if ($mailerHelper->externalMailer !== self::SENDING_METHOD_ID) {
494 - return;
495 - }
496 -
497 - $apikey = $this->config->get(self::SENDING_METHOD_ID.'_apikey');
498 - if (empty($apikey)) {
499 - $mailerHelper->failedCounting = false;
500 - $response['error'] = true;
501 - $response['message'] = acym_translation('ACYM_MISSING_API_KEY');
502 -
503 - return;
504 - }
505 -
506 - if ($this->isUnsubscribeLinkMissing($mailerHelper)) {
507 - $mailerHelper->failedCounting = false;
508 - $response['error'] = true;
509 - $response['message'] = acym_translation('ACYM_MISSING_UNSUBSCRIBE_LINK');
510 -
511 - return;
512 - }
513 -
514 - $domainsUsed = [
515 - acym_getDomain($from['email']),
516 - acym_getDomain($replyTo['email']),
517 - ];
518 - $bounceAddress = $this->getBounceAddress($mailerHelper);
519 - if (!empty($bounceAddress)) {
520 - $domainsUsed[] = acym_getDomain($bounceAddress);
521 - }
522 -
523 - $domainsUsed = array_unique($domainsUsed);
524 -
525 - $verifiedDomains = $this->getVerifiedDomains();
526 -
527 - $unverifiedDomains = array_diff($domainsUsed, $verifiedDomains);
528 - if (!empty($unverifiedDomains)) {
529 - $mailerHelper->failedCounting = false;
530 - $response['error'] = true;
531 - $response['message'] = acym_translationSprintf('ACYM_UNVERIFIED_DOMAINS_PREVENTING_EMAILS_FROM_BEING_SENT_X', implode(', ', $unverifiedDomains));
532 -
533 - return;
534 - }
535 -
536 - $recipients = [];
537 - if (!empty($mailerHelper->cc) || !empty($mailerHelper->bcc)) {
538 - $recipients[] = $to['email'];
539 - $recipients = array_merge($recipients, array_column($mailerHelper->cc, 0), array_column($mailerHelper->bcc, 0));
540 - $mailerHelper->cc = [];
541 - $mailerHelper->bcc = [];
542 - }
543 -
544 - $responseMailer = $this->callApiSendingMethod(
545 - 'send',
546 - [
547 - 'email' => $mailerHelper->getSentMIMEMessage(),
548 - 'domainsUsed' => $domainsUsed,
549 - 'isTransactional' => $mailerHelper->isTransactional,
550 - 'isOneTimeMail' => $mailerHelper->isOneTimeMail,
551 - 'recipients' => $recipients,
552 - ],
553 - [],
554 - 'POST'
555 - );
556 -
557 - if (!empty($responseMailer['logs'])) {
558 - acym_logError($responseMailer['logs'], self::SENDING_METHOD_ID);
559 - }
560 -
561 - if (!empty($responseMailer['error_curl'])) {
562 - $mailerHelper->failedCounting = false;
563 - $response['error'] = true;
564 - $response['message'] = acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $responseMailer['error_curl']);
565 - } elseif (!$this->checkSuccessCode($this->responseCode)) {
566 - $response['error'] = true;
567 - $response['message'] = $this->translate($responseMailer);
568 -
569 - if ($response['message'] === acym_translation('ACYM_NO_CREDITS_LEFT')) {
570 - $response['message'] = acym_translation('ACYM_NOT_ENOUGH_CREDITS').' : ';
571 - $response['message'] .= '<a target="_blank" class="acym__color__blue" href="'.ACYM_ACYMAILING_WEBSITE.'">';
572 - $response['message'] .= acym_translation('ACYM_GET_MORE_CREDITS');
573 - $response['message'] .= '</a>';
574 - }
575 -
576 - if (!empty($responseMailer['code']) && in_array($responseMailer['code'], [18, 26, 28])) {
577 - $mailerHelper->failedCounting = false;
578 - }
579 -
580 - if ($responseMailer['code'] == 26) {
581 - $queueClass = new QueueClass();
582 - $queueClass->delayAll(24);
583 - }
584 - } else {
585 - $response['error'] = false;
586 - }
587 - }
588 -
589 - public function replaceUserInformation(object &$email, ?object &$user, bool $send = true): void
590 - {
591 - if (empty($email->externalMailer) || $email->externalMailer !== self::SENDING_METHOD_ID) return;
592 -
593 - $bounceAddress = $this->getBounceAddress($email);
594 -
595 - if (!empty($bounceAddress) && method_exists($email, 'addCustomHeader')) {
596 - $email->addCustomHeader('Return-Path', $bounceAddress);
597 - }
598 - }
599 -
600 - public function ajaxCheckDomain()
601 - {
602 - $sendingMethod = acym_getVar('string', 'sendingMethod', '');
603 - if ($sendingMethod != self::SENDING_METHOD_ID) {
604 - acym_sendAjaxResponse();
605 - }
606 -
607 - $domains = json_decode($this->config->get(self::SENDING_METHOD_ID.'_domains', '[]'), true);
608 - if (empty($domains)) {
609 - acym_sendAjaxResponse();
610 - }
611 -
612 - $remainingDomains = $this->checkDomainsDNS($domains);
613 - if (empty($remainingDomains)) {
614 - acym_sendAjaxResponse('', ['domains' => $domains]);
615 - }
616 -
617 - $preparedDomains = array_map(
618 - function ($domain) {
619 - return $domain['domain'];
620 - },
621 - $remainingDomains
622 - );
623 -
624 - $responseApi = $this->callApiSendingMethod(
625 - 'getDomainStatus',
626 - ['domains' => $preparedDomains],
627 - [],
628 - 'POST'
629 - );
630 -
631 - if (empty($responseApi)) {
632 - acym_sendAjaxResponse('', ['domains' => $domains]);
633 - }
634 -
635 - if (!$this->checkSuccessCode($this->responseCode)) {
636 - acym_sendAjaxResponse(acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE').': '.$responseApi['message'], ['domains' => $domains], false);
637 - }
638 -
639 - $errorDomains = [];
640 - foreach ($domains as $key => $oneDomain) {
641 - $domainName = $oneDomain['domain'];
642 - if (!array_key_exists($domainName, $responseApi['data']) || !is_array($responseApi['data'][$domainName])) {
643 - $errorDomains[] = acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE').': '.$responseApi['data'][$domainName].': '.$domainName;
644 - continue;
645 - }
646 -
647 - if (!isset($responseApi['data'][$domainName]['code'])) {
648 - $domains[$key] = array_merge($domains[$key], $responseApi['data'][$domainName]);
649 - continue;
650 - }
651 -
652 - if (!empty(self::TRANSLATIONS[$responseApi['data'][$domainName]['code']])) {
653 - $message = self::TRANSLATIONS[$responseApi['data'][$domainName]['code']];
654 - } else {
655 - if (empty($responseApi['data'][$domainName]['message'])) {
656 - $message = 'ACYM_DOMAIN_DEFAULT_ERROR';
657 - } else {
658 - $message = $this->displayMessage($responseApi['data'][$domainName]['message']);
659 - }
660 - }
661 - acym_enqueueMessage(
662 - acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE').': '.acym_translationSprintf(
663 - $message,
664 - $domainName
665 - ),
666 - 'error'
667 - );
668 - }
669 -
670 - $this->config->saveConfig([self::SENDING_METHOD_ID.'_domains' => json_encode($domains)]);
671 -
672 - if (!empty($errorDomains)) {
673 - acym_sendAjaxResponse(implode(', ', $errorDomains), [], false);
674 - }
675 -
676 - acym_sendAjaxResponse('', ['domains' => $domains]);
677 - }
678 -
679 - public function onAcymDeleteDomain()
680 - {
681 - $oneDomain = acym_getVar('string', 'oneDomain', '');
682 -
683 - if (empty($oneDomain)) {
684 - return;
685 - }
686 -
687 - $apikey = $this->config->get(self::SENDING_METHOD_ID.'_apikey');
688 - if (empty($apikey)) {
689 - acym_sendAjaxResponse(acym_translation('ACYM_MISSING_API_KEY'), [], false);
690 - }
691 -
692 - $responseApi = $this->callApiSendingMethod(
693 - 'deleteDomainIdentity',
694 - ['domain' => $oneDomain, 'siteUrl' => acym_baseURI()],
695 - [],
696 - 'POST'
697 - );
698 -
699 - if (!empty($responseApi['error_curl'])) {
700 - $message = acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $responseApi['error_curl']);
701 - acym_sendAjaxResponse($message, [], false);
702 - } elseif (!empty($responseApi['message']) && $responseApi['message'] === 'Invalid private key') {
703 - acym_sendAjaxResponse(acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY'), [], false);
704 - } elseif (!$this->checkSuccessCode($this->responseCode) && (empty($responseApi['code']) || !in_array($responseApi['code'], [5, 4, 3]))) {
705 -
706 - $message = acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE').': '.$this->translate($responseApi);
707 - if (!empty($responseApi['logs'])) {
708 - acym_logError($responseApi['logs'], self::SENDING_METHOD_ID);
709 - }
710 -
711 - acym_sendAjaxResponse($message, [], false);
712 - } else {
713 - $field = self::SENDING_METHOD_ID.'_domains';
714 - $domains = json_decode($this->config->get($field, '[]'), true);
715 - $domains = array_filter($domains, function ($domain) use ($oneDomain) {
716 - return $domain['domain'] !== $oneDomain;
717 - });
718 -
719 - $this->config->saveConfig([$field => json_encode($domains)]);
720 -
721 - acym_sendAjaxResponse();
722 - }
723 - }
724 -
725 - public function ajaxAddDomain(): void
726 - {
727 - $oneDomain = acym_getVar('string', 'oneDomain', '');
728 -
729 - $this->config->saveConfig(['mailer_method' => self::SENDING_METHOD_ID]);
730 -
731 - if (empty($oneDomain)) {
732 - acym_sendAjaxResponse(acym_translation('ACYM_MISSING_DOMAIN'), [], false);
733 - }
734 -
735 - $oneDomain = acym_strtolower($oneDomain);
736 -
737 - $apikey = $this->config->get(self::SENDING_METHOD_ID.'_apikey');
738 - if (empty($apikey)) {
739 - acym_sendAjaxResponse(acym_translation('ACYM_MISSING_API_KEY'), [], false);
740 - }
741 -
742 - $domainValidation = preg_match('/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/u', $oneDomain);
743 - if (!$domainValidation) {
744 - $message = acym_translationSprintf('ACYM_THE_DOMAIN_X_IS_NOT_VALID', $oneDomain);
745 - acym_sendAjaxResponse($message, ['type' => 'DOMAIN_VALIDATION'], false);
746 - }
747 -
748 - $field = self::SENDING_METHOD_ID.'_domains';
749 - $domains = $this->config->get($field, []);
750 -
751 - if (!empty($domains)) {
752 - $domains = @json_decode($domains, true);
753 - }
754 -
755 - if (!empty($domains[$oneDomain])) {
756 - acym_sendAjaxResponse(acym_translation('ACYM_DOMAIN_ALREADY_SENT'), [], false);
757 - }
758 -
759 - $responseApi = $this->callApiSendingMethod(
760 - 'createDomainIdentity',
761 - ['domain' => $oneDomain, 'siteUrl' => acym_baseURI()],
762 - [],
763 - 'POST'
764 - );
765 -
766 - if (!empty($responseApi['error_curl'])) {
767 - $message = acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $responseApi['error_curl']);
768 - acym_sendAjaxResponse($message, [], false);
769 - } elseif (!empty($responseApi['message']) && $responseApi['message'] === 'Invalid API-KEY') {
770 - acym_sendAjaxResponse(acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY'), [], false);
771 - } elseif (!$this->checkSuccessCode($this->responseCode)) {
772 - if (empty($responseApi['code']) || empty(self::TRANSLATIONS[$responseApi['code']])) {
773 - $errorCodeTranslationKey = empty($responseApi['message']) ? 'ACYM_DOMAIN_DEFAULT_ERROR' : $this->displayMessage($responseApi['message']);
774 - } else {
775 - $errorCodeTranslationKey = self::TRANSLATIONS[$responseApi['code']];
776 - }
777 - $message = acym_translationSprintf($errorCodeTranslationKey, $oneDomain);
778 - acym_sendAjaxResponse($message, [], false);
779 - } elseif ($this->responseCode === 201) {
780 - $domains[$oneDomain] = [
781 - 'domain' => $oneDomain,
782 - 'CnameRecords' => $responseApi['cnameRecords'],
783 - 'status' => 'PENDING',
784 - ];
785 - $this->config->saveConfig([$field => json_encode($domains)]);
786 - acym_sendAjaxResponse($this->translate($responseApi), ['cnameRecords' => $responseApi['cnameRecords']]);
787 - } else {
788 - $cnameRecords = $responseApi['data'][$oneDomain]['cnameRecords'];
789 - $status = $responseApi['data'][$oneDomain]['status'];
790 - $domains[$oneDomain] = [
791 - 'domain' => $oneDomain,
792 - 'CnameRecords' => $cnameRecords,
793 - 'status' => $status,
794 - ];
795 - $this->config->saveConfig([$field => json_encode($domains)]);
796 -
797 - acym_sendAjaxResponse(
798 - $this->translate($responseApi),
799 - ['cnameRecords' => $cnameRecords, 'alreadyVerified' => $status === 'SUCCESS']
800 - );
801 - }
802 - }
803 -
804 - public function onAcymDisplayPage()
805 - {
806 - if (intval($this->config->get('walk_through', 0)) === 1) {
807 - return;
808 - }
809 -
810 - $unverifiedDomains = $this->getDomainsUnVerified();
811 -
812 - if (!empty($unverifiedDomains)) {
813 - $message = acym_translationSprintf('ACYM_UNVERIFIED_DOMAINS_PREVENTING_EMAILS_FROM_BEING_SENT_X', implode(', ', $unverifiedDomains));
814 - $notification = [
815 - 'name' => 'unverified_domains',
816 - 'removable' => 0,
817 - ];
818 -
819 - if (acym_getVar('string', 'page') === 'acymailing_dashboard' || acym_getVar('string', 'ctrl') === 'dashboard') {
820 - acym_enqueueMessage($message, 'warning', false, [$notification], false);
821 - } else {
822 - acym_enqueueMessage($message, 'warning', true, [$notification]);
823 - }
824 - } else {
825 - acym_removeDashboardNotification('unverified_domains');
826 - }
827 - }
828 -
829 - public function onAcymGetCreditRemainingSendingMethod(&$html, $reloading = false)
830 - {
831 - $sendingMethod = $this->config->get('mailer_method', '');
832 - if (empty($sendingMethod) || $sendingMethod != self::SENDING_METHOD_ID) return;
833 -
834 - $apiKey = $this->config->get(self::SENDING_METHOD_ID.'_apikey', '');
835 - if (empty($apiKey)) return;
836 -
837 - $response = $this->getRemainingCredits($reloading);
838 -
839 - if (!isset($response['remaining_credits'])) {
840 - if (empty($this->translate($response))) {
841 - $html = acym_translation('ACYM_ERROR_CONTACT_ACYMAILING');
842 - } else {
843 - $html = acym_translationSprintf(
844 - 'ACYM_SENDING_METHOD_ERROR_WHILE_ACTION',
845 - self::SENDING_METHOD_NAME,
846 - acym_translation('ACYM_GETTING_REMAINING_CREDITS'),
847 - $this->translate($response)
848 - );
849 - }
850 -
851 - return;
852 - }
853 -
854 - $unityTranslation = 'ACYM_CREDITS_REMAINING';
855 - $creditsShowed = $response['remaining_credits'];
856 -
857 - if (!empty($response['is_multisite'])) {
858 - $fromEmail = $this->config->get('from_email', '');
859 - $domain = explode('@', $fromEmail)[1];
860 -
861 - if (empty($domain) || empty($response['domains'][$domain])) {
862 - $html = acym_translation('ACYM_DOMAIN_FROM_EMAIL_NOT_VALID_ASS');
863 - } else {
864 - $domainData = $response['domains'][$domain];
865 - if ($domainData['is_limited']) {
866 - $creditsShowed = $domainData['remaining_credits'];
867 - } else {
868 - $creditsShowed = $domainData['credits_used'];
869 - $unityTranslation = 'ACYM_CREDITS_USED';
870 - }
871 - }
872 - }
873 -
874 - if (empty($creditsShowed)) {
875 - $creditsShowed = '0';
876 - }
877 - $html = acym_translationSprintf(
878 - 'ACYM_SENDING_METHOD_X_UNITY',
879 - self::SENDING_METHOD_NAME,
880 - acym_tooltip(
881 - [
882 - 'hoveredText' => $creditsShowed,
883 - 'textShownInTooltip' => acym_translation('ACYM_GET_MORE_CREDITS'),
884 - 'classContainer' => 'credits_remaining',
885 - 'link' => ACYM_ACYMAILING_WEBSITE,
886 - ]
887 - ),
888 - '<span class="acym_not_bold">'.acym_translation($unityTranslation).'</span>'
889 - );
890 - }
891 -
892 - public function onAcymCreditsLeft(&$creditsLeft)
893 - {
894 - $sendingMethod = $this->config->get('mailer_method', '');
895 - if (empty($sendingMethod) || $sendingMethod != self::SENDING_METHOD_ID) return;
896 -
897 - $apiKey = $this->config->get(self::SENDING_METHOD_ID.'_apikey', '');
898 - if (empty($apiKey)) {
899 - $creditsLeft = 0;
900 -
901 - return;
902 - }
903 -
904 - $credits = $this->getRemainingCredits(true);
905 - if (empty($credits['remaining_credits'])) {
906 - $creditsLeft = 0;
907 - } else {
908 - $creditsLeft = (int)$credits['remaining_credits'];
909 - }
910 - }
911 -
912 - public function onAcymAttachLicense($licenseKey)
913 - {
914 - if (empty($licenseKey)) {
915 - return;
916 - }
917 -
918 - $response = $this->callApiSendingMethod(self::SENDING_METHOD_API_URL.'public/licenses/'.$licenseKey);
919 -
920 - if (!empty($response['id'])) {
921 - $this->config->saveConfig([self::SENDING_METHOD_ID.'_apikey' => $response['id']]);
922 - }
923 - }
924 -
925 - public function onAcymDetachLicense()
926 - {
927 - $this->config->saveConfig([self::SENDING_METHOD_ID.'_apikey' => '']);
928 - }
929 -
930 - public function onAcymCampaignSummary(&$data)
931 - {
932 - if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) {
933 - return;
934 - }
935 -
936 - $mail = $data['mailClass']->getOneById($data['mailId']);
937 - if (empty($mail->body) || !$this->isContainingUnsubscribeLink($mail->body)) {
938 - $data['notAllowedSendingError'] = acym_translation('ACYM_UNSUB_LINK');
939 - }
940 -
941 - $unverifiedDomains = $this->getDomainsUnVerified();
942 - if (!empty($unverifiedDomains)) {
943 - $data['notAllowedSendingError'] = acym_translationSprintf(
944 - 'ACYM_UNVERIFIED_DOMAINS_PREVENTING_EMAILS_FROM_BEING_SENT_X',
945 - implode(', ', $unverifiedDomains)
946 - );
947 - }
948 - }
949 -
950 - private function getDomainsUnVerified(): array
951 - {
952 - if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) {
953 - return [];
954 - }
955 -
956 - $allDomains = [];
957 -
958 - $allDomains[] = acym_getDomain($this->config->get('from_email'));
959 - if ($this->config->get('from_as_replyto') === '0') {
960 - $allDomains[] = acym_getDomain($this->config->get('replyto_email'));
961 - }
962 -
963 - if ($this->config->get('multilingual') === '1') {
964 - $senderInfoTranslation = $this->config->get('sender_info_translation');
965 - if (!empty($senderInfoTranslation)) {
966 - $senderInfoTranslation = json_decode($senderInfoTranslation, true);
967 - foreach ($senderInfoTranslation as $oneSenderInfo) {
968 - $allDomains[] = acym_getDomain($oneSenderInfo['from_email']);
969 - $allDomains[] = acym_getDomain($oneSenderInfo['replyto_email']);
970 - }
971 - }
972 - }
973 -
974 - $allDomains[] = acym_getDomain($this->config->get('bounce_email'));
975 - $allDomains = array_filter(array_unique($allDomains));
976 -
977 - $verifiedDomains = $this->getVerifiedDomains();
978 -
979 - return array_diff($allDomains, $verifiedDomains);
980 - }
981 -
982 - private function getRateColor($rate, $allowedRate, $warningRate): array
983 - {
984 - if (empty($rate) || empty($allowedRate) || empty($warningRate)) {
985 - return ['color' => '', 'icon' => ''];
986 - }
987 -
988 - if ($rate > $allowedRate) {
989 - return [
990 - 'color' => 'acym__color__red',
991 - 'icon' => acym_tooltip(
992 - [
993 - 'hoveredText' => '<i class="acym__config__acymailer__rate-status__icon acymicon-close acym__color__red"></i>',
994 - 'textShownInTooltip' => acym_translation('ACYM_RATE_BLOCKED'),
995 - ]
996 - ),
997 - ];
998 - } elseif ($rate >= $warningRate) {
999 - return [
1000 - 'color' => 'acym__color__orange',
1001 - 'icon' => acym_tooltip(
1002 - [
1003 - 'hoveredText' => '<i class="acym__config__acymailer__rate-status__icon acymicon-exclamation-triangle acym__color__orange"></i>',
1004 - 'textShownInTooltip' => acym_translation('ACYM_RATE_WARNING'),
1005 - ]
1006 - ),
1007 - ];
1008 - }
1009 -
1010 - return ['color' => '', 'icon' => ''];
1011 - }
1012 -
1013 - private function updateDomainRates($domainsRates)
1014 - {
1015 - $domains = $this->config->get(self::SENDING_METHOD_ID.'_domains', []);
1016 -
1017 - if (empty($domains)) {
1018 - return;
1019 - }
1020 -
1021 - $domains = @json_decode($domains, true);
1022 -
1023 - foreach ($domainsRates as $oneDomain => $oneRate) {
1024 - if (empty($domains[$oneDomain])) continue;
1025 - foreach ($oneRate as $rateKey => $rateValue) {
1026 - $domains[$oneDomain][$rateKey] = $rateValue;
1027 - }
1028 - }
1029 -
1030 - $this->config->saveConfig([self::SENDING_METHOD_ID.'_domains' => json_encode($domains)]);
1031 - }
1032 -
1033 - private function getVerifiedDomains(): array
1034 - {
1035 - $verifiedDomains = [];
1036 - $domainStatuses = json_decode($this->config->get(self::SENDING_METHOD_ID.'_domains', '[]'), true);
1037 - if (!empty($domainStatuses)) {
1038 - foreach ($domainStatuses as $domain => $info) {
1039 - if ($info['status'] === 'SUCCESS') {
1040 - $verifiedDomains[] = $domain;
1041 - }
1042 - }
1043 - }
1044 -
1045 - return $verifiedDomains;
1046 - }
1047 -
1048 - private function displayMessage($message): string
1049 - {
1050 - $correspondances = [
1051 - 'AlreadyExistsException' => 'ACYM_DOMAIN_X_ALREADY_EXIST',
1052 - 'TooManyRequestsException' => 'ACYM_DOMAIN_TO_MANY_REQUEST',
1053 - 'NotFoundException' => 'ACYM_DOMAIN_NOT_FOUND',
1054 - 'NotExistException' => 'ACYM_CANT_DELETE_DOMAIN',
1055 - ];
1056 -
1057 - if (empty($message) || empty($correspondances[$message])) {
1058 - return 'ACYM_DOMAIN_DEFAULT_ERROR';
1059 - }
1060 -
1061 - return $correspondances[$message];
1062 - }
1063 -
1064 - private function getRemainingCredits($forceReload = false)
1065 - {
1066 - $time = time();
1067 - $lastCheck = $this->config->get(self::SENDING_METHOD_ID.'_last_credits_check', 0);
1068 - $lastDetails = $this->config->get(self::SENDING_METHOD_ID.'_credits_details', []);
1069 -
1070 - if (!$forceReload && !empty($lastDetails) && $lastCheck > $time - self::CREDITS_RELOAD_DELAY) {
1071 - return json_decode($lastDetails, true);
1072 - }
1073 -
1074 - $response = $this->callApiSendingMethod('get_credits');
1075 -
1076 - $this->config->saveConfig([
1077 - self::SENDING_METHOD_ID.'_credits_details' => json_encode($response),
1078 - self::SENDING_METHOD_ID.'_last_credits_check' => $time,
1079 - ]);
1080 -
1081 - if (!empty($response['domains'])) {
1082 - $this->updateDomainRates($response['domains']);
1083 - }
1084 -
1085 - return $response;
1086 - }
1087 -
1088 - private function checkSuccessCode($responseCode): bool
1089 - {
1090 - return in_array($responseCode, [200, 201]);
1091 - }
1092 -
1093 - private function translate($response)
1094 - {
1095 - if (!isset($response['code']) && empty($response['message'])) {
1096 - return '';
1097 - }
1098 -
1099 - $correspondence = '';
1100 - $messageData = [];
1101 -
1102 -
1103 - if (isset($response['code']) && !empty(self::TRANSLATIONS[$response['code']])) {
1104 - $correspondence = self::TRANSLATIONS[$response['code']];
1105 - }
1106 -
1107 - if (!empty($response['messageData'])) {
1108 - $messageData = $response['messageData'];
1109 - }
1110 -
1111 - if (empty($correspondence)) {
1112 - if (empty($messageData)) {
1113 - return $response['message'];
1114 - }
1115 -
1116 - return acym_translationVsprintf($response['message'], $messageData, false);
1117 - }
1118 -
1119 - if (empty($messageData)) {
1120 - $finalMessage = acym_translation($correspondence);
1121 - } else {
1122 - $finalMessage = acym_translationVsprintf($correspondence, $messageData);
1123 - }
1124 -
1125 - if (in_array($response['code'], $this->errorCodes)) {
1126 - $this->errors[] = $finalMessage;
1127 - $this->errorCallback();
1128 - }
1129 -
1130 - return $finalMessage;
1131 - }
1132 -
1133 - private function isUnsubscribeLinkMissing($mailerHelper): bool
1134 - {
1135 - if ($mailerHelper->isTest || $mailerHelper->isForward || $mailerHelper->isSpamTest || empty($mailerHelper->mail)) {
1136 - return false;
1137 - }
1138 -
1139 - if (in_array($mailerHelper->mail->type, MailClass::TYPES_TRANSACTIONAL) || $mailerHelper->mail->type === MailClass::TYPE_AUTOMATION) {
1140 - return false;
1141 - }
1142 -
1143 - return !$this->isContainingUnsubscribeLink($mailerHelper->mail->body);
1144 - }
1145 -
1146 - private function isContainingUnsubscribeLink(string $text): bool
1147 - {
1148 - return strpos($text, '{unsubscribe}') !== false
1149 - || strpos($text, '{unsubscribeall}') !== false
1150 - || strpos($text, 'task=unsubscribe') !== false
1151 - || strpos($text, 'frontusers/unsubscribe') !== false
1152 - || strpos($text, '{direct_unsubscribe') !== false;
1153 - }
1154 -
1155 - private function checkDomainsDNS($domains): array
1156 - {
1157 - $remainingDomains = [];
1158 - foreach ($domains as $oneDomain) {
1159 - if (empty($oneDomain['CnameRecords'])) {
1160 - $remainingDomains[] = $oneDomain;
1161 - continue;
1162 - }
1163 -
1164 - foreach ($oneDomain['CnameRecords'] as $oneRecord) {
1165 - if (!$this->checkCnameEntry($oneRecord['name'], $oneRecord['value'])) {
1166 - $domainPosition = strpos($oneRecord['name'], '_domainkey') + 11;
1167 - $domainName = substr($oneRecord['name'], $domainPosition);
1168 - acym_sendAjaxResponse(acym_translation('ACYM_A_CNAME_MISSING'), ['domain' => $domainName], false);
1169 - }
1170 - }
1171 -
1172 - $remainingDomains[] = $oneDomain;
1173 - }
1174 -
1175 - return $remainingDomains;
1176 - }
1177 -
1178 - private function checkCnameEntry(string $entryName, string $entryValue): bool
1179 - {
1180 - $domainPosition = strpos($entryName, '_domainkey') + 11;
1181 - $domainName = substr($entryName, $domainPosition);
1182 -
1183 - $dnsEntries = @dns_get_record($entryName, DNS_CNAME);
1184 -
1185 - if (empty($dnsEntries)) {
1186 - $entryName = substr($entryName, 0, $domainPosition);
1187 - $doubleDomainEntry = $entryName.'.'.$domainName;
1188 -
1189 - $dnsEntries = @dns_get_record($doubleDomainEntry, DNS_CNAME);
1190 - if (!empty($dnsEntries)) {
1191 - $this->cnameErrors[] = acym_translationSprintf('ACYM_ACYMAILER_MALFORMED_CNAME', $doubleDomainEntry);
1192 - $this->cnameErrors[] = acym_translationSprintf('ACYM_ACYMAILER_CNAME_TRY_WITHOUT_DOMAIN', $entryName, $entryValue);
1193 - } else {
1194 - $this->cnameErrors[] = acym_translation('ACYM_WALK_ACYMAILER_STATUS_WAIT');
1195 - }
1196 -
1197 - return false;
1198 - }
1199 -
1200 - if (!is_array($dnsEntries)) {
1201 - $dnsEntries = [$dnsEntries];
1202 - }
1203 -
1204 - foreach ($dnsEntries as $oneEntry) {
1205 - if ($oneEntry['type'] !== 'CNAME' || $oneEntry['host'] !== $entryName) {
1206 - continue;
1207 - }
1208 -
1209 - if (rtrim($oneEntry['target'], '.') === rtrim($entryValue, '.')) {
1210 - return true;
1211 - }
1212 -
1213 - $this->cnameErrors[] = acym_translationSprintf('ACYM_DOMAIN_CHECK_INCORRECT_VALUE', $entryName, $domainName);
1214 -
1215 - return false;
1216 - }
1217 -
1218 - $this->cnameErrors[] = acym_translation('ACYM_DNS_NOT_CNAME');
1219 -
1220 - return false;
1221 - }
1222 -}