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

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