| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers\Configuration; |
| 4 |
|
| 5 |
use AcyMailing\Helpers\ExportHelper; |
| 6 |
|
| 7 |
trait Mail |
| 8 |
{ |
| 9 |
public function ports(): void |
| 10 |
{ |
| 11 |
if (!function_exists('fsockopen')) { |
| 12 |
echo '<span style="color:red">'.acym_translation('ACYM_FSOCKOPEN').'</span>'; |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
$tests = [ |
| 17 |
25 => 'smtp.sendgrid.com', |
| 18 |
2525 => 'smtp.sendgrid.com', |
| 19 |
587 => 'smtp.sendgrid.com', |
| 20 |
465 => 'ssl://smtp.gmail.com', |
| 21 |
]; |
| 22 |
|
| 23 |
foreach ($tests as $port => $server) { |
| 24 |
$fp = @fsockopen($server, $port, $errno, $errstr, 5); |
| 25 |
if ($fp) { |
| 26 |
echo '<span style="color:#3dea91">'.acym_translationSprintf('ACYM_SMTP_AVAILABLE_PORT', $port).'</span><br />'; |
| 27 |
fclose($fp); |
| 28 |
} else { |
| 29 |
echo '<span style="color:#ff5259">'.acym_translationSprintf('ACYM_SMTP_NOT_AVAILABLE_PORT', $port, $errno.' - '.acym_utf8Encode($errstr)).'</span><br />'; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
exit; |
| 34 |
} |
| 35 |
|
| 36 |
public function testCredentialsSendingMethod(): void |
| 37 |
{ |
| 38 |
$sendingMethod = acym_getVar('string', 'sendingMethod', ''); |
| 39 |
$config = acym_getVar('array', 'config', []); |
| 40 |
|
| 41 |
if (empty($sendingMethod) || empty($config)) acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false); |
| 42 |
acym_trigger('onAcymTestCredentialSendingMethod', [$sendingMethod, $config]); |
| 43 |
} |
| 44 |
|
| 45 |
public function copySettingsSendingMethod(): void |
| 46 |
{ |
| 47 |
$plugin = acym_getVar('string', 'plugin', ''); |
| 48 |
$method = acym_getVar('string', 'method', ''); |
| 49 |
|
| 50 |
if (empty($plugin) || empty($method)) { |
| 51 |
acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false); |
| 52 |
} |
| 53 |
|
| 54 |
$data = []; |
| 55 |
|
| 56 |
if ($method === 'from_options') { |
| 57 |
$wpMailSmtpSetting = acym_getCMSConfig('wp_mail_smtp', ''); |
| 58 |
if (!empty($wpMailSmtpSetting) && !empty($wpMailSmtpSetting['mail'])) { |
| 59 |
$mailSettings = $wpMailSmtpSetting['mail']; |
| 60 |
|
| 61 |
if (!empty($mailSettings['from_email']) && !empty($mailSettings['from_name'])) { |
| 62 |
$data['from_email'] = $mailSettings['from_email']; |
| 63 |
$data['from_name'] = $mailSettings['from_name']; |
| 64 |
} |
| 65 |
} |
| 66 |
} else { |
| 67 |
acym_trigger('onAcymGetSettingsSendingMethodFromPlugin', [&$data, $plugin, $method]); |
| 68 |
} |
| 69 |
|
| 70 |
if (empty($data)) { |
| 71 |
acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false); |
| 72 |
} |
| 73 |
|
| 74 |
acym_sendAjaxResponse('', $data); |
| 75 |
} |
| 76 |
|
| 77 |
public function synchronizeExistingUsers(): void |
| 78 |
{ |
| 79 |
$sendingMethod = acym_getVar('string', 'sendingMethod', ''); |
| 80 |
|
| 81 |
if (empty($sendingMethod)) { |
| 82 |
acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false); |
| 83 |
} |
| 84 |
|
| 85 |
acym_trigger('onAcymSynchronizeExistingUsers', [$sendingMethod]); |
| 86 |
} |
| 87 |
|
| 88 |
public function downloadExportChangesFile(): void |
| 89 |
{ |
| 90 |
$current = acym_getVar('boolean', 'export_changes_file_current', true); |
| 91 |
$dateTime = $current ? 'now' : '1 month ago'; |
| 92 |
|
| 93 |
$exportHelper = new ExportHelper(); |
| 94 |
|
| 95 |
$filenameToSearch = $exportHelper->getExportChangesFileName(acym_date($dateTime, 'Y'), acym_date($dateTime, 'm'), false); |
| 96 |
|
| 97 |
$exportFolder = acym_getLogPath(); |
| 98 |
$files = scandir($exportFolder); |
| 99 |
if (empty($files)) { |
| 100 |
acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info'); |
| 101 |
$this->listing(); |
| 102 |
|
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
$filename = acym_getLogPath($filenameToSearch); |
| 107 |
|
| 108 |
$zipFiles = []; |
| 109 |
|
| 110 |
foreach ($files as $file) { |
| 111 |
if (strpos($file, $filenameToSearch) === false) continue; |
| 112 |
$zipFiles[] = [ |
| 113 |
'name' => $file, |
| 114 |
'data' => acym_fileGetContent(acym_getLogPath($file)), |
| 115 |
]; |
| 116 |
} |
| 117 |
|
| 118 |
if (empty($zipFiles)) { |
| 119 |
acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info'); |
| 120 |
$this->listing(); |
| 121 |
|
| 122 |
return; |
| 123 |
} |
| 124 |
|
| 125 |
acym_createArchive($filename, $zipFiles); |
| 126 |
|
| 127 |
if (ACYM_CMS === 'wordpress') @ob_get_clean(); |
| 128 |
$exportHelper->setDownloadHeaders($filenameToSearch, 'zip'); |
| 129 |
readfile($filename.'.zip'); |
| 130 |
acym_deleteFile($filename.'.zip'); |
| 131 |
|
| 132 |
exit; |
| 133 |
} |
| 134 |
|
| 135 |
public function loginForOAuth2Smtp(): void |
| 136 |
{ |
| 137 |
$this->loginForOAuth2(); |
| 138 |
} |
| 139 |
|
| 140 |
public function loginForOAuth2Bounce(): void |
| 141 |
{ |
| 142 |
$this->loginForOAuth2(false); |
| 143 |
} |
| 144 |
|
| 145 |
public function logoutForOAuth2Smtp(): void |
| 146 |
{ |
| 147 |
acym_trigger('onAcymOauthRevoke'); |
| 148 |
|
| 149 |
$this->listing(); |
| 150 |
} |
| 151 |
|
| 152 |
public function logoutForOAuth2Bounce(): void |
| 153 |
{ |
| 154 |
$this->config->save( |
| 155 |
[ |
| 156 |
'bounce_refresh_token' => '', |
| 157 |
'bounce_refresh_token_expiration' => '', |
| 158 |
] |
| 159 |
); |
| 160 |
|
| 161 |
$this->listing(); |
| 162 |
} |
| 163 |
} |
| 164 |
|