| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers; |
| 4 |
|
| 5 |
use AcyMailing\Controllers\Configuration\Language; |
| 6 |
use AcyMailing\Core\AcymController; |
| 7 |
use AcyMailing\Controllers\Configuration\Listing; |
| 8 |
use AcyMailing\Controllers\Configuration\Security; |
| 9 |
use AcyMailing\Controllers\Configuration\Mail; |
| 10 |
use AcyMailing\Controllers\Configuration\Queue; |
| 11 |
use AcyMailing\Controllers\Configuration\Subscription; |
| 12 |
use AcyMailing\Controllers\Configuration\License; |
| 13 |
|
| 14 |
class ConfigurationController extends AcymController |
| 15 |
{ |
| 16 |
use Listing; |
| 17 |
use Security; |
| 18 |
use Mail; |
| 19 |
use Queue; |
| 20 |
use Subscription; |
| 21 |
use License; |
| 22 |
use Language; |
| 23 |
|
| 24 |
const CRON_TASK_NAME = 'acymailing_automated_tasks_cron_task'; |
| 25 |
|
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
parent::__construct(); |
| 29 |
$this->breadcrumb[acym_translation('ACYM_CONFIGURATION')] = acym_completeLink('configuration'); |
| 30 |
|
| 31 |
$this->loadScripts = [ |
| 32 |
'listing' => [ |
| 33 |
'colorpicker', |
| 34 |
], |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
public function getOption(): void |
| 39 |
{ |
| 40 |
acym_checkToken(); |
| 41 |
|
| 42 |
$field = acym_getVar('string', 'field', ''); |
| 43 |
|
| 44 |
$allowedFields = [ |
| 45 |
'level', |
| 46 |
'unsplash_key', |
| 47 |
'giphy_key', |
| 48 |
]; |
| 49 |
|
| 50 |
if (acym_isAdmin()) { |
| 51 |
$allowedFields[] = 'save_thumbnail'; |
| 52 |
} |
| 53 |
|
| 54 |
if (!in_array($field, $allowedFields)) { |
| 55 |
acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_LOAD_INFORMATION'), [], false); |
| 56 |
} |
| 57 |
|
| 58 |
$res = $this->config->get($field); |
| 59 |
|
| 60 |
if (intval($res) !== 0 && empty($res)) { |
| 61 |
acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_LOAD_INFORMATION'), [], false); |
| 62 |
} else { |
| 63 |
acym_sendAjaxResponse('', ['value' => $res]); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public function displayMessage(string $message, bool $ajax = false): array |
| 68 |
{ |
| 69 |
$correspondences = [ |
| 70 |
'WEBSITE_NOT_FOUND' => ['message' => 'ACYM_WEBSITE_NOT_FOUND', 'type' => 'error'], |
| 71 |
'LICENSE_NOT_FOUND' => ['message' => 'ACYM_LICENSE_NOT_FOUND', 'type' => 'error'], |
| 72 |
'WELL_ATTACH' => ['message' => 'ACYM_LICENSE_WELL_ATTACH', 'type' => 'info'], |
| 73 |
'ISSUE_WHILE_ATTACH' => ['message' => 'ACYM_ISSUE_WHILE_ATTACHING_LICENSE', 'type' => 'error'], |
| 74 |
'ALREADY_ATTACH' => ['message' => 'ACYM_WEBSITE_ALREADY_ATTACHED', 'type' => 'info'], |
| 75 |
'LICENSES_DONT_MATCH' => ['message' => 'ACYM_CANT_UNLINK_WEBSITE_LICENSE_DONT_MATCH', 'type' => 'error'], |
| 76 |
'MAX_SITES_ATTACH' => ['message' => 'ACYM_REACHED_MAX_SITES_ATTACHED', 'type' => 'error'], |
| 77 |
'SITE_NOT_FOUND' => ['message' => 'ACYM_ISSUE_WHILE_ATTACHING_LICENSE', 'type' => 'error'], |
| 78 |
'UNLINK_SUCCESSFUL' => ['message' => 'ACYM_LICENSE_UNLINK_SUCCESSFUL', 'type' => 'info'], |
| 79 |
'UNLINK_FAILED' => ['message' => 'ACYM_ERROR_WHILE_UNLINK_LICENSE', 'type' => 'error'], |
| 80 |
'CRON_WELL_ACTIVATED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_WELL_ACTIVATED', 'type' => 'info'], |
| 81 |
'CRON_WELL_DEACTIVATED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_WELL_DEACTIVATED', 'type' => 'info'], |
| 82 |
'CRON_NOT_SAVED' => ['message' => 'ACYM_AUTOMATIC_SEND_PROCESS_NOT_ENABLED', 'type' => 'error'], |
| 83 |
]; |
| 84 |
|
| 85 |
if (!$ajax) { |
| 86 |
if (empty($message) || empty($correspondences[$message])) { |
| 87 |
acym_enqueueMessage(acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE'), 'error'); |
| 88 |
|
| 89 |
if (!empty($message)) { |
| 90 |
$notification = [ |
| 91 |
'name' => 'curl_error', |
| 92 |
'removable' => 1, |
| 93 |
]; |
| 94 |
acym_enqueueMessage(acym_translationSprintf('ACYM_CURL_ERROR_MESSAGE', $message), 'error', true, [$notification]); |
| 95 |
} |
| 96 |
|
| 97 |
return []; |
| 98 |
} |
| 99 |
|
| 100 |
acym_enqueueMessage(acym_translation($correspondences[$message]['message']), $correspondences[$message]['type']); |
| 101 |
|
| 102 |
return $correspondences[$message]['type'] === 'info' ? $correspondences[$message] : []; |
| 103 |
} else { |
| 104 |
if (empty($message) || empty($correspondences[$message])) { |
| 105 |
$response = ['message' => acym_translation('ACYM_ERROR_ON_CALL_ACYBA_WEBSITE'), 'type' => 'error']; |
| 106 |
|
| 107 |
if (!empty($message)) $response['message'] = acym_translationSprintf('ACYM_CURL_ERROR_MESSAGE', $message); |
| 108 |
|
| 109 |
return $response; |
| 110 |
} |
| 111 |
|
| 112 |
$response = $correspondences[$message]; |
| 113 |
$response['message'] = acym_translation($response['message']); |
| 114 |
|
| 115 |
return $response; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
public function seeLogs(): void |
| 120 |
{ |
| 121 |
$filename = acym_getVar('string', 'filename', ''); |
| 122 |
|
| 123 |
if (empty($filename) || !acym_fileNameValid($filename)) { |
| 124 |
echo acym_translation('ACYM_FILENAME_EMPTY_OR_NOT_VALID'); |
| 125 |
exit; |
| 126 |
} |
| 127 |
|
| 128 |
$reportPath = acym_getLogPath($filename); |
| 129 |
|
| 130 |
if (!file_exists($reportPath)) { |
| 131 |
echo acym_translation('ACYM_EXIST_LOG'); |
| 132 |
exit; |
| 133 |
} |
| 134 |
|
| 135 |
if (ACYM_CMS === 'wordpress') @ob_get_clean(); |
| 136 |
|
| 137 |
$final = acym_fileGetContent($reportPath); |
| 138 |
echo nl2br($final); |
| 139 |
|
| 140 |
exit; |
| 141 |
} |
| 142 |
|
| 143 |
private function loginForOAuth2(bool $isSmtp = true): void |
| 144 |
{ |
| 145 |
$this->store(); |
| 146 |
|
| 147 |
$redirectUrl = ''; |
| 148 |
acym_trigger('onAcymOauthAuthenticate', [&$redirectUrl, $isSmtp]); |
| 149 |
|
| 150 |
if (empty($redirectUrl)) { |
| 151 |
$this->listing(); |
| 152 |
|
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
acym_redirect($redirectUrl); |
| 157 |
} |
| 158 |
|
| 159 |
public function handleOauthAuthentication(): void |
| 160 |
{ |
| 161 |
$code = acym_getVar('string', 'code'); |
| 162 |
|
| 163 |
if (empty($code)) { |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
$isSmtp = acym_getVar('string', 'auth_type', 'smtp') === 'smtp'; |
| 168 |
acym_trigger('onAcymOauthCredentialsCreation', [$isSmtp, $code]); |
| 169 |
} |
| 170 |
} |
| 171 |
|