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

590 lines 20.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Configuration;
4
5 use AcyMailing\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 'acym-data-before' => 'jQuery.acymConfigSave();',
111 'data-task' => 'test',
112 ]
113 );
114 $toolbarHelper->addButton(
115 acym_translation('ACYM_SAVE'),
116 [
117 'acym-data-before' => 'jQuery.acymConfigSave();',
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',
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->handleDemoSite($formData);
311 $this->handleAcl($formData);
312 $this->handleSelect2Fields($formData);
313 $this->handleAcyChecker($formData);
314 $this->handleNewDkim($formData);
315 $this->handleEmails($formData);
316 $this->handleUnsubSurvey($formData);
317
318 acym_trigger('onBeforeSaveConfigFields', [&$formData]);
319
320 $licenseKeyBeforeSave = $this->config->get('license_key');
321
322 if ($this->config->save($formData)) {
323 $this->handleWebsiteLinking($formData, $licenseKeyBeforeSave);
324
325 acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'));
326 } else {
327 acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
328 }
329
330 $this->handleMultilingual($formData);
331
332 $this->config->load();
333 }
334
335 private function handleReplyTo(array &$formData): void
336 {
337 if ($formData['from_as_replyto'] == 1) {
338 if (isset($formData['from_name'])) {
339 $formData['replyto_name'] = $formData['from_name'];
340 }
341 $formData['replyto_email'] = $formData['from_email'];
342 }
343 }
344
345 private function handleWordWrap(array &$formData): void
346 {
347 if (empty($formData['mailer_wordwrap']) || $formData['mailer_wordwrap'] < 0) {
348 $formData['mailer_wordwrap'] = 0;
349 }
350
351 if ($formData['mailer_wordwrap'] > 998) {
352 $formData['mailer_wordwrap'] = 998;
353 }
354 }
355
356 private function handleDemoSite(array &$formData): void
357 {
358 }
359
360 private function handleAcl(array &$formData): void
361 {
362 if (ACYM_PRODUCTION) {
363 $aclPages = array_keys(acym_getPagesForAcl());
364 foreach ($aclPages as $page) {
365 if (empty($formData['acl_'.$page])) {
366 $formData['acl_'.$page] = ['all'];
367 }
368 }
369 }
370 }
371
372 private function handleSelect2Fields(array &$formData): void
373 {
374 $select2Fields = [
375 'regacy_lists',
376 'regacy_checkedlists',
377 'regacy_autolists',
378 'acy_notification_create',
379 'acy_notification_unsub',
380 'acy_notification_unsuball',
381 'acy_notification_subform',
382 'acy_notification_profile',
383 'acy_notification_confirm',
384 'wp_access',
385 'multilingual_languages',
386 'allowed_hosts',
387 'unsub_survey',
388 ];
389
390 foreach ($select2Fields as $oneField) {
391 if ($oneField === 'unsub_survey' && !empty($formData[$oneField])) {
392 $formData[$oneField] = json_encode($formData[$oneField]);
393 }
394 if (empty($formData[$oneField])) {
395 $formData[$oneField] = [];
396 }
397 }
398 }
399
400 private function handleAcyChecker(array &$formData): void
401 {
402 if (empty($formData['email_verification'])) {
403 return;
404 }
405
406 $disabledOptions = true;
407 $verificationOptions = [
408 'email_verification_non_existing',
409 'email_verification_disposable',
410 'email_verification_free',
411 'email_verification_role',
412 'email_verification_acceptall',
413 ];
414
415 foreach ($verificationOptions as $oneOption) {
416 if (!empty($formData[$oneOption])) {
417 $disabledOptions = false;
418 }
419 }
420
421 if ($disabledOptions) {
422 $formData['email_verification'] = false;
423 acym_enqueueMessage(acym_translation('ACYM_ACYCHECKER_AUTO_DISABLED'), 'info');
424 }
425 }
426
427 private function handleNewDkim(array &$formData): void
428 {
429 if (empty($formData['dkim'])) {
430 return;
431 }
432
433 $privateKey = $this->config->get('dkim_private');
434 $publicKey = $this->config->get('dkim_public');
435
436 if (!empty($formData['dkim_private']) || !empty($formData['dkim_public'])) {
437 return;
438 }
439
440 if (!isset($formData['dkim_private']) && !empty($privateKey) && !empty($publicKey)) {
441 return;
442 }
443
444 $newDkimKeys = UpdatemeHelper::call('public/dkim');
445 if (empty($newDkimKeys['private_key'])) {
446 return;
447 }
448
449 $formData['dkim_private'] = $newDkimKeys['private_key'];
450 $formData['dkim_public'] = $newDkimKeys['public_key'];
451 }
452
453 private function handleWebsiteLinking(array $formData, string $licenseKeyBeforeSave): void
454 {
455 $isLicenseKeyUpdated = isset($formData['license_key']) && $licenseKeyBeforeSave !== $formData['license_key'];
456
457 if ($isLicenseKeyUpdated && ACYM_PRODUCTION) {
458 if (!empty($formData['license_key'])) {
459 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe($formData['license_key']);
460
461 if (!empty($resultAttachLicenseOnUpdateMe['message'])) {
462 $this->displayMessage($resultAttachLicenseOnUpdateMe['message']);
463 }
464 } else {
465 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKeyBeforeSave);
466
467 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
468 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
469 }
470 }
471 }
472 }
473
474 private function handleMultilingual(array $formData): void
475 {
476 $removed = array_diff(
477 explode(',', acym_getVar('string', 'previous_multilingual_languages', '')),
478 $formData['multilingual_languages']
479 );
480
481 if (!empty($removed)) {
482 $mailClass = new MailClass();
483 $mailClass->deleteByTranslationLang($removed);
484 }
485 }
486
487 public function test(): void
488 {
489 $this->store();
490
491 $mailerHelper = new MailerHelper();
492 $addedName = $this->config->get('add_names', true) ? $mailerHelper->cleanText(acym_currentUserName()) : '';
493
494 $mailerHelper->AddAddress(acym_currentUserEmail(), $addedName);
495 $mailerHelper->Subject = 'Test e-mail from '.ACYM_LIVE;
496 $mailerHelper->Body = acym_translation('ACYM_TEST_EMAIL');
497 $mailerHelper->SMTPDebug = 1;
498 $mailerHelper->isTest = true;
499 if (acym_isDebug()) {
500 $mailerHelper->SMTPDebug = 2;
501 }
502
503 $mailerHelper->isHTML(false);
504 $result = $mailerHelper->send();
505
506 if (!$result) {
507 $sendingMethod = $this->config->get('mailer_method');
508
509 if ($sendingMethod === 'smtp') {
510 if ($this->config->get('smtp_secured') === 'ssl' && !function_exists('openssl_sign')) {
511 acym_enqueueMessage(acym_translation('ACYM_OPENSSL'), 'notice');
512 }
513
514 if (!$this->config->get('smtp_auth') && strlen($this->config->get('smtp_password')) > 1) {
515 acym_enqueueMessage(acym_translation('ACYM_ADVICE_SMTP_AUTH'), 'notice');
516 }
517
518 if ($this->config->get('smtp_port') && !in_array($this->config->get('smtp_port'), [25, 2525, 465, 587])) {
519 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_PORT', $this->config->get('smtp_port')), 'notice');
520 }
521 }
522
523 if (acym_isLocalWebsite() && in_array($sendingMethod, ['sendmail', 'qmail', 'mail'])) {
524 acym_enqueueMessage(acym_translation('ACYM_ADVICE_LOCALHOST'), 'notice');
525 }
526
527 $creditsLeft = 10000;
528 acym_trigger('onAcymCreditsLeft', [&$creditsLeft]);
529
530 $bounce = $this->config->get('bounce_email');
531 if (!empty($creditsLeft) && !empty($bounce) && !in_array($sendingMethod, ['smtp', 'elasticemail'])) {
532 acym_enqueueMessage(acym_translationSprintf('ACYM_ADVICE_BOUNCE', '<b>'.$bounce.'</b>'), 'notice');
533 }
534 }
535
536 $this->listing();
537 }
538
539 public function handleUnsubSurvey(array &$formData): void
540 {
541 if (isset($formData['unsub_survey'])) {
542 $unsubSurvey = json_decode($formData['unsub_survey'], true);
543 if (is_array($unsubSurvey)) {
544 foreach ($unsubSurvey as $key => $value) {
545 if (is_string($value)) {
546 $unsubSurvey[$key] = strip_tags($value);
547 }
548 }
549 $formData['unsub_survey'] = json_encode($unsubSurvey);
550 }
551 }
552
553 if (isset($formData['unsub_survey_translation'])) {
554 $unsubSurveyTranslation = json_decode($formData['unsub_survey_translation'], true);
555 if (is_array($unsubSurveyTranslation)) {
556 foreach ($unsubSurveyTranslation as $lang => $unsubSurvey) {
557 if (is_array($unsubSurvey) && isset($unsubSurvey['unsub_survey'])) {
558 foreach ($unsubSurvey['unsub_survey'] as $key => $value) {
559 if (is_string($value)) {
560 $unsubSurveyTranslation[$lang]['unsub_survey'][$key] = strip_tags($value);
561 }
562 }
563 }
564 }
565 $formData['unsub_survey_translation'] = json_encode($unsubSurveyTranslation);
566 }
567 }
568 }
569
570 private function resetQueueProcess(): void
571 {
572 if (!acym_level(ACYM_ESSENTIAL) && $this->config->get('queue_type', 'manual') !== 'manual') {
573 $this->config->save(['queue_type' => 'manual']);
574 }
575 }
576
577
578 public function addNewSml(): void
579 {
580 acym_trigger('onConfigurationAddSml');
581 $this->listing();
582 }
583
584 public function deleteSml(): void
585 {
586 acym_trigger('onConfigurationDeleteSml');
587 $this->listing();
588 }
589 }
590