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

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

169 lines 5.0 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 $sendingMethod = acym_getVar('string', 'sendingMethod', '');
85
86 if (empty($sendingMethod)) {
87 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false);
88 }
89
90 acym_trigger('onAcymSynchronizeExistingUsers', [$sendingMethod]);
91 }
92
93 public function downloadExportChangesFile(): void
94 {
95 $current = acym_getVar('boolean', 'export_changes_file_current', true);
96 $dateTime = $current ? 'now' : '1 month ago';
97
98 $exportHelper = new ExportHelper();
99
100 $filenameToSearch = $exportHelper->getExportChangesFileName(acym_date($dateTime, 'Y'), acym_date($dateTime, 'm'), false);
101
102 $exportFolder = acym_getLogPath();
103 $files = scandir($exportFolder);
104 if (empty($files)) {
105 acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info');
106 $this->listing();
107
108 return;
109 }
110
111 $filename = acym_getLogPath($filenameToSearch);
112
113 $zipFiles = [];
114
115 foreach ($files as $file) {
116 if (strpos($file, $filenameToSearch) === false) continue;
117 $zipFiles[] = [
118 'name' => $file,
119 'data' => acym_fileGetContent(acym_getLogPath($file)),
120 ];
121 }
122
123 if (empty($zipFiles)) {
124 acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info');
125 $this->listing();
126
127 return;
128 }
129
130 acym_createArchive($filename, $zipFiles);
131
132 if (ACYM_CMS === 'wordpress') @ob_get_clean();
133 $exportHelper->setDownloadHeaders($filenameToSearch, 'zip');
134 readfile($filename.'.zip');
135 acym_deleteFile($filename.'.zip');
136
137 exit;
138 }
139
140 public function loginForOAuth2Smtp(): void
141 {
142 $this->loginForOAuth2();
143 }
144
145 public function loginForOAuth2Bounce(): void
146 {
147 $this->loginForOAuth2(false);
148 }
149
150 public function logoutForOAuth2Smtp(): void
151 {
152 acym_trigger('onAcymOauthRevoke');
153
154 $this->listing();
155 }
156
157 public function logoutForOAuth2Bounce(): void
158 {
159 $this->config->saveConfig(
160 [
161 'bounce_refresh_token' => '',
162 'bounce_refresh_token_expiration' => '',
163 ]
164 );
165
166 $this->listing();
167 }
168 }
169