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 / Listing.php

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

634 lines 21.5 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\Classes\FieldClass;
6 use AcyMailing\Classes\ListClass;
7 use AcyMailing\Classes\MailClass;
8 use AcyMailing\Helpers\EncodingHelper;
9 use AcyMailing\Helpers\MailerHelper;
10 use AcyMailing\Helpers\TabHelper;
11 use AcyMailing\Helpers\ToolbarHelper;
12 use AcyMailing\Helpers\UpdatemeHelper;
13 use AcyMailing\Core\AcymPlugin;
14 use AcyMailing\Types\AclType;
15 use AcyMailing\Types\DelayType;
16 use AcyMailing\Types\FailActionType;
17
18 trait Listing
19 {
20 public function listing(): void
21 {
22 acym_setVar('layout', 'listing');
23
24 $this->handleOauthAuthentication();
25
26 $data = [];
27 $data['tab'] = new TabHelper();
28 $this->prepareLanguages($data);
29 $this->prepareLists($data);
30 $this->prepareNotifications($data);
31 $this->prepareAcl($data);
32 $this->prepareClass($data);
33 $this->prepareDataTab($data);
34 $this->prepareSecurity($data);
35 $this->checkConfigMail();
36 $this->prepareToolbar($data);
37 $this->prepareHoursMinutes($data);
38 $this->resetQueueProcess();
39
40 if ($data['wp_mail_smtp_installed']) {
41 $pluginClass = new AcymPlugin();
42 $data['button_copy_settings_from'] = $pluginClass->getCopySettingsButton($data, 'from_options', 'wp_mail_smtp');
43 }
44
45 $this->prepareMailSettings($data);
46 $this->prepareMultilingualOption($data);
47
48 $this->loadSurveyAnswers($data);
49
50 parent::display($data);
51 }
52
53 private function checkConfigMail(): void
54 {
55 $queueType = $this->config->get('queue_type');
56 $batchesNumber = $this->config->get('queue_batch_auto', 1);
57 $emailsPerBatch = $this->config->get('queue_nbmail_auto', 70);
58 $cronFrequency = $this->config->get('cron_frequency', 900);
59 if ($queueType !== 'manual') {
60 if (($batchesNumber > 1 || $cronFrequency < 900) && !function_exists('curl_multi_exec')) {
61 $notification = [
62 'name' => 'curl_multi_exec',
63 'removable' => 0,
64 ];
65 acym_enqueueMessage(acym_translation('ACYM_NEED_CURL_MULTI'), 'error', true, [$notification]);
66 } elseif ($batchesNumber <= 1 && $cronFrequency >= 900) {
67 acym_removeDashboardNotification('curl_multi_exec');
68 }
69
70 $remindme = json_decode($this->config->get('remindme', '[]'), true);
71 if (!in_array('sendoverload', $remindme) && ($batchesNumber > 4 || $emailsPerBatch > 300 || $cronFrequency < 300)) {
72 $text = acym_translation('ACYM_SEND_CONFIGURATION_WARNING');
73 $text .= '<p class="acym__do__not__remindme" title="sendoverload">'.acym_translation('ACYM_DO_NOT_REMIND_ME').'</p>';
74 $notification = [
75 'name' => 'sendoverload',
76 'removable' => 1,
77 ];
78 acym_enqueueMessage($text, 'warning', true, [$notification]);
79 } else {
80 acym_removeDashboardNotification('sendoverload');
81 }
82 }
83 }
84
85 private function prepareMailSettings(array &$data): void
86 {
87 $data['sendingMethodsType'] = [
88 'server' => acym_translation('ACYM_USING_YOUR_SERVER'),
89 'external' => acym_translation('ACYM_USING_AN_EXTERNAL_SERVER'),
90 ];
91
92 $data['sendingMethods'] = [];
93 acym_trigger('onAcymGetSendingMethods', [&$data]);
94 acym_trigger('onAcymGetSendingMethodsSelected', [&$data]);
95
96 $data['sendingMethodsHtmlSettings'] = [];
97 acym_trigger('onAcymGetSendingMethodsHtmlSetting', [&$data]);
98
99 $data['embedImage'] = [];
100 $data['embedAttachment'] = [];
101 acym_trigger('onAcymSendingMethodOptions', [&$data]);
102 }
103
104 public function prepareToolbar(array &$data): void
105 {
106 $toolbarHelper = new ToolbarHelper();
107 $toolbarHelper->addButton(
108 acym_translation('ACYM_SEND_TEST'),
109 [
110 'data-before-action' => 'configSave',
111 'data-task' => 'test',
112 ]
113 );
114 $toolbarHelper->addButton(
115 acym_translation('ACYM_SAVE'),
116 [
117 'data-before-action' => 'configSave',
118 'data-task' => 'save',
119 ],
120 '',
121 true
122 );
123
124 $data['toolbar'] = $toolbarHelper;
125 }
126
127 private function prepareClass(array &$data): void
128 {
129 $data['typeDelay'] = new DelayType();
130 $data['failaction'] = new FailActionType();
131 $data['encodingHelper'] = new EncodingHelper();
132 }
133
134 private function prepareLanguages(array &$data): void
135 {
136 $langs = acym_getLanguages();
137 $data['languages'] = [];
138
139 foreach ($langs as $lang => $obj) {
140 if ($lang === 'xx-XX') continue;
141
142 $oneLanguage = new \stdClass();
143 $oneLanguage->language = $lang;
144 $oneLanguage->name = $obj->name;
145
146 $linkEdit = acym_completeLink('language&task=displayLanguage&code='.$lang, true);
147 $icon = $obj->exists ? 'edit' : 'add';
148 $idModalLanguage = 'acym_modal_language_'.$lang;
149 $oneLanguage->edit = acym_modal(
150 '<i class="acymicon-'.$icon.' cursor-pointer acym__color__blue" data-open="'.$idModalLanguage.'" data-ajax="false" data-iframe="'.$linkEdit.'" data-iframe-class="acym__iframe_language" id="image'.$lang.'"></i>',
151 '', //<iframe src="'.$linkEdit.'"></iframe>
152 $idModalLanguage,
153 ['data-reveal-larger' => true],
154 [],
155 false
156 );
157
158 $data['languages'][] = $oneLanguage;
159 }
160
161 usort(
162 $data['languages'],
163 function ($a, $b) {
164 return strtolower($a->name) > strtolower($b->name) ? 1 : -1;
165 }
166 );
167
168
169 $data['content_translation'] = acym_getTranslationTools();
170
171 $data['user_languages'] = array_merge(
172 [
173 (object)['language' => 'current_language', 'name' => acym_translation('ACYM_BROWSING_LANGUAGE')],
174 ],
175 $data['languages']
176 );
177 }
178
179 private function prepareLists(array &$data): void
180 {
181 $listClass = new ListClass();
182 try {
183 $lists = $listClass->getAllWithoutManagement();
184 } catch (\Exception $exception) {
185 $lists = [];
186 }
187 foreach ($lists as $i => $oneList) {
188 if ($oneList->active == 0) {
189 unset($lists[$i]);
190 }
191 }
192 $data['lists'] = $lists;
193 }
194
195 private function prepareNotifications(array &$data): void
196 {
197 $data['notifications'] = [
198 'acy_notification_create' => [
199 'label' => 'ACYM_NOTIFICATION_CREATE',
200 'tooltip' => '',
201 ],
202 'acy_notification_unsub' => [
203 'label' => 'ACYM_NOTIFICATION_UNSUB',
204 'tooltip' => '',
205 ],
206 'acy_notification_unsuball' => [
207 'label' => 'ACYM_NOTIFICATION_UNSUBALL',
208 'tooltip' => '',
209 ],
210 'acy_notification_subform' => [
211 'label' => 'ACYM_NOTIFICATION_SUBFORM',
212 'tooltip' => '',
213 ],
214 'acy_notification_profile' => [
215 'label' => 'ACYM_NOTIFICATION_PROFILE',
216 'tooltip' => '',
217 ],
218 'acy_notification_confirm' => [
219 'label' => 'ACYM_NOTIFICATION_CONFIRM',
220 'tooltip' => '',
221 ],
222 ];
223 }
224
225 private function prepareAcl(array &$data): void
226 {
227 $data['acl'] = acym_cmsPermission();
228 $data['acl_advanced'] = acym_getPagesForAcl();
229 $data['aclType'] = new AclType();
230 }
231
232 private function prepareSecurity(array &$data): void
233 {
234 $data['wp_mail_smtp_installed'] = ACYM_CMS === 'wordpress' && acym_isExtensionActive('wp-mail-smtp/wp_mail_smtp.php');
235 $data['acychecker_installed'] = acym_isAcyCheckerInstalled();
236 $data['acychecker_get_link'] = ACYM_ACYCHECKER_WEBSITE.'?utm_source=acymailing_plugin&utm_campaign=get_acychecker&utm_medium=button_configuration_security';
237
238 $data['level'] = acym_level(ACYM_ESSENTIAL);
239 $data['labelDropdownCaptcha'] = acym_translation('ACYM_CONFIGURATION_CAPTCHA');
240
241 $captchaOptions = array_replace(
242 [
243 'none' => acym_translation('ACYM_NONE'),
244 'acym_hcaptcha' => acym_translation('ACYM_HCAPTCHA'),
245 'acym_ireCaptcha' => acym_translation('ACYM_CAPTCHA_INVISIBLE'),
246 'acym_reCaptcha_v3' => acym_translation('ACYM_CAPTCHA_V3'),
247 ],
248 acym_getCmsCaptcha()
249 );
250
251 $data['captchaOptions'] = $captchaOptions;
252
253 if (!acym_level(ACYM_ESSENTIAL)) {
254 $data['labelDropdownCaptcha'] .= ' '.acym_translation('ACYM_PRO_VERSION_ONLY');
255 $data['captchaOptions'] = [];
256 }
257 }
258
259 private function prepareDataTab(array &$data): void
260 {
261 $fieldClass = new FieldClass();
262 $data['fields'] = $fieldClass->getAll();
263
264 $data['export_data_changes_fields'] = $this->config->get('export_data_changes_fields', []);
265 if (!is_array($data['export_data_changes_fields'])) {
266 $data['export_data_changes_fields'] = explode(',', $data['export_data_changes_fields']);
267 }
268 }
269
270 private function prepareHoursMinutes(array &$data): void
271 {
272 $listHours = [];
273 for ($i = 0; $i < 24; $i++) {
274 $value = $i < 10 ? '0'.$i : $i;
275 $listHours[] = acym_selectOption($value, $value);
276 }
277 $listMinutes = [];
278 for ($i = 0; $i < 60; $i += 5) {
279 $value = $i < 10 ? '0'.$i : $i;
280 $listMinutes[] = acym_selectOption($value, $value);
281 }
282 $listAllMinutes = [];
283 for ($i = 0; $i < 60; $i++) {
284 $value = $i < 10 ? '0'.$i : $i;
285 $listAllMinutes[] = acym_selectOption($value, $value);
286 }
287 $data['listHours'] = $listHours;
288 $data['listMinutes'] = $listMinutes;
289 $data['listAllMinutes'] = $listAllMinutes;
290 }
291
292 private function handleEmails(array &$formData): void
293 {
294 $formData['from_email'] = acym_strtolower($formData['from_email']);
295 $formData['replyto_email'] = acym_strtolower($formData['replyto_email']);
296 $formData['bounce_email'] = acym_strtolower($formData['bounce_email']);
297 }
298
299 public function store(): void
300 {
301 acym_checkToken();
302
303 $formData = acym_getVar('array', 'config', []);
304 if (empty($formData)) {
305 return;
306 }
307
308 $this->handleReplyTo($formData);
309 $this->handleWordWrap($formData);
310 $this->handleQueueSettings($formData);
311 $this->handleDemoSite($formData);
312 $this->handleAcl($formData);
313 $this->handleSelect2Fields($formData);
314 $this->handleAcyChecker($formData);
315 $this->handleNewDkim($formData);
316 $this->handleEmails($formData);
317 $this->handleUnsubSurvey($formData);
318
319 acym_trigger('onBeforeSaveConfigFields', [&$formData]);
320
321 $licenseKeyBeforeSave = $this->config->get('license_key');
322
323 if ($this->config->saveConfig($formData)) {
324 $this->handleWebsiteLinking($formData, $licenseKeyBeforeSave);
325
326 acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'));
327 } else {
328 acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
329 }
330
331 $this->handleMultilingual($formData);
332
333 $this->config->load();
334 }
335
336 private function handleReplyTo(array &$formData): void
337 {
338 if ($formData['from_as_replyto'] == 1) {
339 if (isset($formData['from_name'])) {
340 $formData['replyto_name'] = $formData['from_name'];
341 }
342 $formData['replyto_email'] = $formData['from_email'];
343 }
344 }
345
346 private function handleWordWrap(array &$formData): void
347 {
348 if (empty($formData['mailer_wordwrap']) || $formData['mailer_wordwrap'] < 0) {
349 $formData['mailer_wordwrap'] = 0;
350 }
351
352 if ($formData['mailer_wordwrap'] > 998) {
353 $formData['mailer_wordwrap'] = 998;
354 }
355 }
356
357 private function handleQueueSettings(array &$formData): void
358 {
359 $currentTaskId = (int)$this->config->get('scheduled_task_id');
360 $frequency = (int)$formData['cron_frequency'];
361
362 if (
363 !acym_level(ACYM_ESSENTIAL)
364 || $formData['queue_type'] === 'manual'
365 || empty($frequency)
366 || $frequency === 900
367 || !acym_isLicenseValidWeekly()
368 ) {
369 acym_deleteScheduledTask(
370 [
371 'taskId' => $currentTaskId,
372 'type' => 'plg_task_requests_task_get',
373 'name' => self::CRON_TASK_NAME,
374 ]
375 );
376 $formData['scheduled_task_id'] = 0;
377
378 return;
379 }
380
381 $taskId = acym_scheduleTask(
382 [
383 'title' => 'AcyMailing – Automated tasks',
384 'type' => 'plg_task_requests_task_get',
385 'frequencyInMinutes' => $frequency / 60,
386 'name' => self::CRON_TASK_NAME,
387 'taskFrequency' => 'every_minute',
388 'taskId' => $currentTaskId,
389 'config' => $formData
390 ]
391 );
392
393 if (!empty($taskId) && ACYM_CMS === 'joomla') {
394 $formData['scheduled_task_id'] = $taskId;
395 }
396 }
397
398 private function handleDemoSite(array &$formData): void
399 {
400 }
401
402 private function handleAcl(array &$formData): void
403 {
404 if (ACYM_PRODUCTION) {
405 $aclPages = array_keys(acym_getPagesForAcl());
406 foreach ($aclPages as $page) {
407 if (empty($formData['acl_'.$page])) {
408 $formData['acl_'.$page] = [ACYM_ADMIN_GROUP];
409 }
410 }
411 }
412 }
413
414 private function handleSelect2Fields(array &$formData): void
415 {
416 $select2Fields = [
417 'regacy_lists',
418 'regacy_checkedlists',
419 'regacy_autolists',
420 'acy_notification_create',
421 'acy_notification_unsub',
422 'acy_notification_unsuball',
423 'acy_notification_subform',
424 'acy_notification_profile',
425 'acy_notification_confirm',
426 'wp_access',
427 'multilingual_languages',
428 'allowed_hosts',
429 'unsub_survey',
430 ];
431
432 foreach ($select2Fields as $oneField) {
433 if ($oneField === 'unsub_survey' && !empty($formData[$oneField])) {
434 $formData[$oneField] = json_encode($formData[$oneField]);
435 }
436 if (empty($formData[$oneField])) {
437 $formData[$oneField] = [];
438 }
439 }
440 }
441
442 private function handleAcyChecker(array &$formData): void
443 {
444 if (empty($formData['email_verification'])) {
445 return;
446 }
447
448 $disabledOptions = true;
449 $verificationOptions = [
450 'email_verification_non_existing',
451 'email_verification_disposable',
452 'email_verification_free',
453 'email_verification_role',
454 'email_verification_acceptall',
455 ];
456
457 foreach ($verificationOptions as $oneOption) {
458 if (!empty($formData[$oneOption])) {
459 $disabledOptions = false;
460 }
461 }
462
463 if ($disabledOptions) {
464 $formData['email_verification'] = false;
465 acym_enqueueMessage(acym_translation('ACYM_ACYCHECKER_AUTO_DISABLED'), 'info');
466 }
467 }
468
469 private function handleNewDkim(array &$formData): void
470 {
471 if (empty($formData['dkim'])) {
472 return;
473 }
474
475 $privateKey = $this->config->get('dkim_private');
476 $publicKey = $this->config->get('dkim_public');
477
478 if (!empty($formData['dkim_private']) || !empty($formData['dkim_public'])) {
479 return;
480 }
481
482 if (!isset($formData['dkim_private']) && !empty($privateKey) && !empty($publicKey)) {
483 return;
484 }
485
486 $newDkimKeys = UpdatemeHelper::call('public/dkim');
487 if (empty($newDkimKeys['private_key'])) {
488 return;
489 }
490
491 $formData['dkim_private'] = $newDkimKeys['private_key'];
492 $formData['dkim_public'] = $newDkimKeys['public_key'];
493 }
494
495 private function handleWebsiteLinking(array $formData, string $licenseKeyBeforeSave): void
496 {
497 $isLicenseKeyUpdated = isset($formData['license_key']) && $licenseKeyBeforeSave !== $formData['license_key'];
498
499 if ($isLicenseKeyUpdated && ACYM_PRODUCTION) {
500 if (!empty($formData['license_key'])) {
501 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe($formData['license_key']);
502
503 if (!empty($resultAttachLicenseOnUpdateMe['message'])) {
504 $this->displayMessage($resultAttachLicenseOnUpdateMe['message']);
505 }
506 } else {
507 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKeyBeforeSave);
508
509 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
510 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
511 }
512 }
513
514 UpdatemeHelper::getLicenseInfo();
515 }
516 }
517
518 private function handleMultilingual(array $formData): void
519 {
520 $removed = array_diff(
521 explode(',', acym_getVar('string', 'previous_multilingual_languages', '')),
522 $formData['multilingual_languages']
523 );
524
525 if (!empty($removed)) {
526 $mailClass = new MailClass();
527 $mailClass->deleteByTranslationLang($removed);
528 }
529 }
530
531 public function test(): void
532 {
533 $this->store();
534
535 $mailerHelper = new MailerHelper();
536 $addedName = $this->config->get('add_names', true) ? $mailerHelper->cleanText(acym_currentUserName()) : '';
537
538 $mailerHelper->AddAddress(acym_currentUserEmail(), $addedName);
539 $mailerHelper->Subject = 'Test e-mail from '.ACYM_LIVE;
540 $mailerHelper->Body = acym_translation('ACYM_TEST_EMAIL');
541 $mailerHelper->SMTPDebug = 1;
542 $mailerHelper->isTest = true;
543 if (acym_isDebug()) {
544 $mailerHelper->SMTPDebug = 2;
545 }
546
547 $mailerHelper->isHTML(false);
548 $result = $mailerHelper->send();
549
550 if (!$result) {
551 $sendingMethod = $this->config->get('mailer_method');
552
553 if ($sendingMethod === 'smtp') {
554 if ($this->config->get('smtp_secured') === 'ssl' && !function_exists('openssl_sign')) {
555 acym_enqueueMessage(acym_translation('ACYM_OPENSSL'), 'notice');
556 }
557
558 if (!$this->config->get('smtp_auth') && strlen($this->config->get('smtp_password')) > 1) {
559 acym_enqueueMessage(acym_translation('ACYM_ADVICE_SMTP_AUTH'), 'notice');
560 }
561
562 if ($this->config->get('smtp_port') && !in_array($this->config->get('smtp_port'), [25, 2525, 465, 587])) {
563 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_PORT', $this->config->get('smtp_port')), 'notice');
564 }
565 }
566
567 if (acym_isLocalWebsite() && in_array($sendingMethod, ['sendmail', 'qmail', 'mail'])) {
568 acym_enqueueMessage(acym_translation('ACYM_ADVICE_LOCALHOST'), 'notice');
569 }
570
571 $creditsLeft = 10000;
572 acym_trigger('onAcymCreditsLeft', [&$creditsLeft]);
573
574 $bounce = $this->config->get('bounce_email');
575 if (!empty($creditsLeft) && !empty($bounce) && !in_array($sendingMethod, ['smtp', 'elasticemail'])) {
576 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_BOUNCE', '<b>'.$bounce.'</b>'), 'notice');
577 }
578 }
579
580 $this->listing();
581 }
582
583 public function handleUnsubSurvey(array &$formData): void
584 {
585 if (isset($formData['unsub_survey'])) {
586 $unsubSurvey = json_decode($formData['unsub_survey'], true);
587 if (is_array($unsubSurvey)) {
588 foreach ($unsubSurvey as $key => $value) {
589 if (is_string($value)) {
590 $unsubSurvey[$key] = strip_tags($value);
591 }
592 }
593 $formData['unsub_survey'] = json_encode($unsubSurvey);
594 }
595 }
596
597 if (isset($formData['unsub_survey_translation'])) {
598 $unsubSurveyTranslation = json_decode($formData['unsub_survey_translation'], true);
599 if (is_array($unsubSurveyTranslation)) {
600 foreach ($unsubSurveyTranslation as $lang => $unsubSurvey) {
601 if (is_array($unsubSurvey) && isset($unsubSurvey['unsub_survey'])) {
602 foreach ($unsubSurvey['unsub_survey'] as $key => $value) {
603 if (is_string($value)) {
604 $unsubSurveyTranslation[$lang]['unsub_survey'][$key] = strip_tags($value);
605 }
606 }
607 }
608 }
609 $formData['unsub_survey_translation'] = json_encode($unsubSurveyTranslation);
610 }
611 }
612 }
613
614 private function resetQueueProcess(): void
615 {
616 if (!acym_level(ACYM_ESSENTIAL) && $this->config->get('queue_type', 'manual') !== 'manual') {
617 $this->config->saveConfig(['queue_type' => 'manual']);
618 }
619 }
620
621
622 public function addNewSml(): void
623 {
624 acym_trigger('onConfigurationAddSml');
625 $this->listing();
626 }
627
628 public function deleteSml(): void
629 {
630 acym_trigger('onConfigurationDeleteSml');
631 $this->listing();
632 }
633 }
634