PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.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 / Mail.php

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

178 lines 5.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\Helpers\ExportHelper;
6 use AcyMailing\Helpers\MailerHelper;
7
8 trait Mail
9 {
10 public function ports(): void
11 {
12 $mailerHelper = new MailerHelper();
13
14 $tests = [
15 25 => 'smtp.sendgrid.com',
16 2525 => 'smtp.sendgrid.com',
17 587 => 'smtp.sendgrid.com',
18 465 => 'ssl://smtp.gmail.com',
19 ];
20
21 $response = [];
22 foreach ($tests as $port => $targetServer) {
23 if ($mailerHelper->isPortOpen($port, $targetServer)) {
24 $response[$port] = [
25 'open' => true,
26 'port' => $port,
27 'message' => acym_translationSprintf('ACYM_SMTP_AVAILABLE_PORT', $port),
28 ];
29 } else {
30 $response[$port] = [
31 'open' => false,
32 'port' => $port,
33 'message' => acym_translationSprintf('ACYM_SMTP_NOT_AVAILABLE_PORT', $port, $mailerHelper->portError),
34 ];
35 }
36 }
37
38 acym_sendAjaxResponse('', $response);
39 }
40
41 public function testCredentialsSendingMethod(): void
42 {
43 $sendingMethod = acym_getVar('string', 'sendingMethod', '');
44 $config = acym_getVar('array', 'config', []);
45
46 if (empty($sendingMethod) || empty($config)) acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false);
47 acym_trigger('onAcymTestCredentialSendingMethod', [$sendingMethod, $config]);
48 }
49
50 public function copySettingsSendingMethod(): void
51 {
52 $plugin = acym_getVar('string', 'plugin', '');
53 $method = acym_getVar('string', 'method', '');
54
55 if (empty($plugin) || empty($method)) {
56 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false);
57 }
58
59 $data = [];
60
61 if ($method === 'from_options') {
62 $wpMailSmtpSetting = acym_getCMSConfig('wp_mail_smtp', '');
63 if (!empty($wpMailSmtpSetting) && !empty($wpMailSmtpSetting['mail'])) {
64 $mailSettings = $wpMailSmtpSetting['mail'];
65
66 if (!empty($mailSettings['from_email']) && !empty($mailSettings['from_name'])) {
67 $data['from_email'] = $mailSettings['from_email'];
68 $data['from_name'] = $mailSettings['from_name'];
69 }
70 }
71 } else {
72 acym_trigger('onAcymGetSettingsSendingMethodFromPlugin', [&$data, $plugin, $method]);
73 }
74
75 if (empty($data)) {
76 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false);
77 }
78
79 acym_sendAjaxResponse('', $data);
80 }
81
82 public function synchronizeExistingUsers(): void
83 {
84 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
85
86 $sendingMethod = acym_getVar('string', 'sendingMethod', '');
87
88 if (empty($sendingMethod)) {
89 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false);
90 }
91
92 acym_trigger('onAcymSynchronizeExistingUsers', [$sendingMethod]);
93 }
94
95 public function downloadExportChangesFile(): void
96 {
97 $current = acym_getVar('boolean', 'export_changes_file_current', true);
98 $dateTime = $current ? 'now' : '1 month ago';
99
100 $exportHelper = new ExportHelper();
101
102 $filenameToSearch = $exportHelper->getExportChangesFileName(acym_date($dateTime, 'Y'), acym_date($dateTime, 'm'), false);
103
104 $exportFolder = acym_getLogPath();
105 $files = scandir($exportFolder);
106 if (empty($files)) {
107 acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info');
108 $this->listing();
109
110 return;
111 }
112
113 $filename = acym_getLogPath($filenameToSearch);
114
115 $zipFiles = [];
116
117 foreach ($files as $file) {
118 if (strpos($file, $filenameToSearch) === false) continue;
119 $zipFiles[] = [
120 'name' => $file,
121 'data' => acym_fileGetContent(acym_getLogPath($file)),
122 ];
123 }
124
125 if (empty($zipFiles)) {
126 acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info');
127 $this->listing();
128
129 return;
130 }
131
132 acym_createArchive($filename, $zipFiles);
133
134 if (ob_get_level()) {
135 ob_end_clean();
136 }
137 $exportHelper->setDownloadHeaders($filenameToSearch, 'zip');
138 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Downloading a file, better than WP functions for memory handling.
139 readfile($filename.'.zip');
140 acym_deleteFile($filename.'.zip');
141
142 exit;
143 }
144
145 public function loginForOAuth2Smtp(): void
146 {
147 $this->loginForOAuth2();
148 }
149
150 public function loginForOAuth2Bounce(): void
151 {
152 $this->loginForOAuth2(false);
153 }
154
155 public function logoutForOAuth2Smtp(): void
156 {
157 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
158
159 acym_trigger('onAcymOauthRevoke');
160
161 $this->listing();
162 }
163
164 public function logoutForOAuth2Bounce(): void
165 {
166 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
167
168 $this->config->saveConfig(
169 [
170 'bounce_refresh_token' => '',
171 'bounce_refresh_token_expiration' => '',
172 ]
173 );
174
175 $this->listing();
176 }
177 }
178