| @@ -1,137 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Controllers\Configuration; | |
| 4 | - | |
| 5 | -use AcyMailing\Helpers\ExportHelper; | |
| 6 | - | |
| 7 | -trait Mail | |
| 8 | -{ | |
| 9 | - public function ports() | |
| 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() | |
| 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() | |
| 46 | - { | |
| 47 | - $plugin = acym_getVar('string', 'plugin', ''); | |
| 48 | - $method = acym_getVar('string', 'method', ''); | |
| 49 | - | |
| 50 | - if (empty($plugin) || empty($method)) acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false); | |
| 51 | - | |
| 52 | - $data = []; | |
| 53 | - | |
| 54 | - if ($method == 'from_options') { | |
| 55 | - $wpMailSmtpSetting = get_option('wp_mail_smtp', ''); | |
| 56 | - if (!empty($wpMailSmtpSetting) && !empty($wpMailSmtpSetting['mail'])) { | |
| 57 | - $mailSettings = $wpMailSmtpSetting['mail']; | |
| 58 | - | |
| 59 | - if (!empty($mailSettings['from_email']) && !empty($mailSettings['from_name'])) { | |
| 60 | - $data['from_email'] = $mailSettings['from_email']; | |
| 61 | - $data['from_name'] = $mailSettings['from_name']; | |
| 62 | - } | |
| 63 | - } | |
| 64 | - } else { | |
| 65 | - acym_trigger('onAcymGetSettingsSendingMethodFromPlugin', [&$data, $plugin, $method]); | |
| 66 | - } | |
| 67 | - | |
| 68 | - if (empty($data)) acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false); | |
| 69 | - | |
| 70 | - acym_sendAjaxResponse('', $data); | |
| 71 | - } | |
| 72 | - | |
| 73 | - public function synchronizeExistingUsers() | |
| 74 | - { | |
| 75 | - $sendingMethod = acym_getVar('string', 'sendingMethod', ''); | |
| 76 | - | |
| 77 | - if (empty($sendingMethod)) acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_FIND_SENDING_METHOD'), [], false); | |
| 78 | - acym_trigger('onAcymSynchronizeExistingUsers', [$sendingMethod]); | |
| 79 | - } | |
| 80 | - | |
| 81 | - public function downloadExportChangesFile() | |
| 82 | - { | |
| 83 | - $current = acym_getVar('boolean', 'export_changes_file_current', true); | |
| 84 | - $dateTime = $current ? 'now' : '1 month ago'; | |
| 85 | - | |
| 86 | - $exportHelper = new ExportHelper(); | |
| 87 | - | |
| 88 | - $filenameToSearch = $exportHelper->getExportChangesFileName(acym_date($dateTime, 'Y'), acym_date($dateTime, 'm'), false); | |
| 89 | - | |
| 90 | - $exportFolder = acym_getLogPath(''); | |
| 91 | - $files = scandir($exportFolder); | |
| 92 | - if (empty($files)) { | |
| 93 | - acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info'); | |
| 94 | - $this->listing(); | |
| 95 | - | |
| 96 | - return; | |
| 97 | - } | |
| 98 | - | |
| 99 | - $filename = acym_getLogPath($filenameToSearch); | |
| 100 | - | |
| 101 | - $zipFiles = []; | |
| 102 | - | |
| 103 | - foreach ($files as $file) { | |
| 104 | - if (strpos($file, $filenameToSearch) === false) continue; | |
| 105 | - $zipFiles[] = [ | |
| 106 | - 'name' => $file, | |
| 107 | - 'data' => acym_fileGetContent(acym_getLogPath($file)), | |
| 108 | - ]; | |
| 109 | - } | |
| 110 | - | |
| 111 | - if (empty($zipFiles)) { | |
| 112 | - acym_enqueueMessage(acym_translation('ACYM_NO_FILE_TO_EXPORT'), 'info'); | |
| 113 | - $this->listing(); | |
| 114 | - | |
| 115 | - return; | |
| 116 | - } | |
| 117 | - | |
| 118 | - acym_createArchive($filename, $zipFiles); | |
| 119 | - | |
| 120 | - if (ACYM_CMS === 'wordpress') @ob_get_clean(); | |
| 121 | - $exportHelper->setDownloadHeaders($filenameToSearch, 'zip'); | |
| 122 | - readfile($filename.'.zip'); | |
| 123 | - acym_deleteFile($filename.'.zip'); | |
| 124 | - | |
| 125 | - exit; | |
| 126 | - } | |
| 127 | - | |
| 128 | - public function loginForOAuth2Bounce() | |
| 129 | - { | |
| 130 | - $this->loginForOAuth2(false); | |
| 131 | - } | |
| 132 | - | |
| 133 | - public function loginForOAuth2Smtp() | |
| 134 | - { | |
| 135 | - $this->loginForOAuth2(); | |
| 136 | - } | |
| 137 | -} | |