PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.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 / Listing.php

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

640 lines 21.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\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 $aclPermissions = acym_cmsPermission();
405 if (ACYM_PRODUCTION && !empty($aclPermissions)) {
406 $aclPages = array_keys(acym_getPagesForAcl());
407 foreach ($aclPages as $page) {
408 if (empty($formData['acl_'.$page])) {
409 $formData['acl_'.$page] = [ACYM_ADMIN_GROUP];
410 }
411 }
412 }
413 }
414
415 private function handleSelect2Fields(array &$formData): void
416 {
417 $select2Fields = [
418 'regacy_lists',
419 'regacy_checkedlists',
420 'regacy_autolists',
421 'acy_notification_create',
422 'acy_notification_unsub',
423 'acy_notification_unsuball',
424 'acy_notification_subform',
425 'acy_notification_profile',
426 'acy_notification_confirm',
427 'multilingual_languages',
428 'allowed_hosts',
429 'unsub_survey',
430 ];
431
432 $aclPermissions = acym_cmsPermission();
433 if (!empty($aclPermissions)) {
434 $select2Fields[] = 'wp_access';
435 }
436
437 foreach ($select2Fields as $oneField) {
438 if ($oneField === 'unsub_survey' && !empty($formData[$oneField])) {
439 $formData[$oneField] = json_encode($formData[$oneField]);
440 }
441
442 if (empty($formData[$oneField])) {
443 $formData[$oneField] = [];
444 }
445 }
446 }
447
448 private function handleAcyChecker(array &$formData): void
449 {
450 if (empty($formData['email_verification'])) {
451 return;
452 }
453
454 $disabledOptions = true;
455 $verificationOptions = [
456 'email_verification_non_existing',
457 'email_verification_disposable',
458 'email_verification_free',
459 'email_verification_role',
460 'email_verification_acceptall',
461 ];
462
463 foreach ($verificationOptions as $oneOption) {
464 if (!empty($formData[$oneOption])) {
465 $disabledOptions = false;
466 }
467 }
468
469 if ($disabledOptions) {
470 $formData['email_verification'] = false;
471 acym_enqueueMessage(acym_translation('ACYM_ACYCHECKER_AUTO_DISABLED'), 'info');
472 }
473 }
474
475 private function handleNewDkim(array &$formData): void
476 {
477 if (empty($formData['dkim'])) {
478 return;
479 }
480
481 $privateKey = $this->config->get('dkim_private');
482 $publicKey = $this->config->get('dkim_public');
483
484 if (!empty($formData['dkim_private']) || !empty($formData['dkim_public'])) {
485 return;
486 }
487
488 if (!isset($formData['dkim_private']) && !empty($privateKey) && !empty($publicKey)) {
489 return;
490 }
491
492 $newDkimKeys = UpdatemeHelper::call('public/dkim');
493 if (empty($newDkimKeys['private_key'])) {
494 return;
495 }
496
497 $formData['dkim_private'] = $newDkimKeys['private_key'];
498 $formData['dkim_public'] = $newDkimKeys['public_key'];
499 }
500
501 private function handleWebsiteLinking(array $formData, string $licenseKeyBeforeSave): void
502 {
503 $isLicenseKeyUpdated = isset($formData['license_key']) && $licenseKeyBeforeSave !== $formData['license_key'];
504
505 if ($isLicenseKeyUpdated && ACYM_PRODUCTION) {
506 if (!empty($formData['license_key'])) {
507 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe($formData['license_key']);
508
509 if (!empty($resultAttachLicenseOnUpdateMe['message'])) {
510 $this->displayMessage($resultAttachLicenseOnUpdateMe['message']);
511 }
512 } else {
513 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKeyBeforeSave);
514
515 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
516 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
517 }
518 }
519
520 UpdatemeHelper::getLicenseInfo();
521 }
522 }
523
524 private function handleMultilingual(array $formData): void
525 {
526 $removed = array_diff(
527 explode(',', acym_getVar('string', 'previous_multilingual_languages', '')),
528 $formData['multilingual_languages']
529 );
530
531 if (!empty($removed)) {
532 $mailClass = new MailClass();
533 $mailClass->deleteByTranslationLang($removed);
534 }
535 }
536
537 public function test(): void
538 {
539 $this->store();
540
541 $mailerHelper = new MailerHelper();
542 $addedName = $this->config->get('add_names', true) ? $mailerHelper->cleanText(acym_currentUserName()) : '';
543
544 $mailerHelper->AddAddress(acym_currentUserEmail(), $addedName);
545 $mailerHelper->Subject = 'Test e-mail from '.ACYM_LIVE;
546 $mailerHelper->Body = acym_translation('ACYM_TEST_EMAIL');
547 $mailerHelper->SMTPDebug = 1;
548 $mailerHelper->isTest = true;
549 if (acym_isDebug()) {
550 $mailerHelper->SMTPDebug = 2;
551 }
552
553 $mailerHelper->isHTML(false);
554 $result = $mailerHelper->send();
555
556 if (!$result) {
557 $sendingMethod = $this->config->get('mailer_method');
558
559 if ($sendingMethod === 'smtp') {
560 if ($this->config->get('smtp_secured') === 'ssl' && !function_exists('openssl_sign')) {
561 acym_enqueueMessage(acym_translation('ACYM_OPENSSL'), 'notice');
562 }
563
564 if (!$this->config->get('smtp_auth') && strlen($this->config->get('smtp_password')) > 1) {
565 acym_enqueueMessage(acym_translation('ACYM_ADVICE_SMTP_AUTH'), 'notice');
566 }
567
568 if ($this->config->get('smtp_port') && !in_array($this->config->get('smtp_port'), [25, 2525, 465, 587])) {
569 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_PORT', $this->config->get('smtp_port')), 'notice');
570 }
571 }
572
573 if (acym_isLocalWebsite() && in_array($sendingMethod, ['sendmail', 'qmail', 'mail'])) {
574 acym_enqueueMessage(acym_translation('ACYM_ADVICE_LOCALHOST'), 'notice');
575 }
576
577 $creditsLeft = 10000;
578 acym_trigger('onAcymCreditsLeft', [&$creditsLeft]);
579
580 $bounce = $this->config->get('bounce_email');
581 if (!empty($creditsLeft) && !empty($bounce) && !in_array($sendingMethod, ['smtp', 'elasticemail'])) {
582 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_BOUNCE', '<b>'.$bounce.'</b>'), 'notice');
583 }
584 }
585
586 $this->listing();
587 }
588
589 public function handleUnsubSurvey(array &$formData): void
590 {
591 if (isset($formData['unsub_survey'])) {
592 $unsubSurvey = json_decode($formData['unsub_survey'], true);
593 if (is_array($unsubSurvey)) {
594 foreach ($unsubSurvey as $key => $value) {
595 if (is_string($value)) {
596 $unsubSurvey[$key] = strip_tags($value);
597 }
598 }
599 $formData['unsub_survey'] = json_encode($unsubSurvey);
600 }
601 }
602
603 if (isset($formData['unsub_survey_translation'])) {
604 $unsubSurveyTranslation = json_decode($formData['unsub_survey_translation'], true);
605 if (is_array($unsubSurveyTranslation)) {
606 foreach ($unsubSurveyTranslation as $lang => $unsubSurvey) {
607 if (is_array($unsubSurvey) && isset($unsubSurvey['unsub_survey'])) {
608 foreach ($unsubSurvey['unsub_survey'] as $key => $value) {
609 if (is_string($value)) {
610 $unsubSurveyTranslation[$lang]['unsub_survey'][$key] = strip_tags($value);
611 }
612 }
613 }
614 }
615 $formData['unsub_survey_translation'] = json_encode($unsubSurveyTranslation);
616 }
617 }
618 }
619
620 private function resetQueueProcess(): void
621 {
622 if (!acym_level(ACYM_ESSENTIAL) && $this->config->get('queue_type', 'manual') !== 'manual') {
623 $this->config->saveConfig(['queue_type' => 'manual']);
624 }
625 }
626
627
628 public function addNewSml(): void
629 {
630 acym_trigger('onConfigurationAddSml');
631 $this->listing();
632 }
633
634 public function deleteSml(): void
635 {
636 acym_trigger('onConfigurationDeleteSml');
637 $this->listing();
638 }
639 }
640