| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers\Bounces; |
| 4 |
|
| 5 |
use AcyMailing\Classes\ListClass; |
| 6 |
use AcyMailing\Classes\RuleClass; |
| 7 |
use AcyMailing\Helpers\BounceHelper; |
| 8 |
use AcyMailing\Helpers\CronHelper; |
| 9 |
use AcyMailing\Helpers\ToolbarHelper; |
| 10 |
use AcyMailing\Helpers\UpdateHelper; |
| 11 |
use AcyMailing\Helpers\WorkflowHelper; |
| 12 |
|
| 13 |
trait Listing |
| 14 |
{ |
| 15 |
public function listing(): void |
| 16 |
{ |
| 17 |
$this->storeRedirectListing(true); |
| 18 |
} |
| 19 |
|
| 20 |
public function prepareToolbar(array &$data, string $element = 'bounces'): void |
| 21 |
{ |
| 22 |
$toolbarHelper = new ToolbarHelper(); |
| 23 |
if ($element === 'bounces') { |
| 24 |
$toolbarHelper->addButton( |
| 25 |
'ACYM_CONFIGURE', |
| 26 |
[ |
| 27 |
'data-task' => 'config', |
| 28 |
'id' => 'acym__bounce__button__config', |
| 29 |
'type' => 'button', |
| 30 |
], |
| 31 |
'settings' |
| 32 |
); |
| 33 |
$toolbarHelper->addButton( |
| 34 |
'ACYM_RESET_DEFAULT_RULES', |
| 35 |
[ |
| 36 |
'data-task' => 'reinstall', |
| 37 |
'type' => 'button', |
| 38 |
'data-confirmation-message' => 'ACYM_ARE_YOU_SURE', |
| 39 |
], |
| 40 |
'repeat' |
| 41 |
); |
| 42 |
$toolbarHelper->addButton('ACYM_RUN_BOUNCE_HANDLING', ['data-task' => 'test'], 'play_arrow'); |
| 43 |
$toolbarHelper->addButton('ACYM_CREATE', ['data-task' => 'rule', 'type' => 'submit'], 'add', true); |
| 44 |
|
| 45 |
|
| 46 |
$remindMe = json_decode($this->config->get('remindme', '[]'), true); |
| 47 |
$messageIdentifier = 'bounce_rules_'.UpdateHelper::BOUNCE_VERSION; |
| 48 |
|
| 49 |
if (!in_array($messageIdentifier, $remindMe) && $this->config->get('bounceVersion', 0) < UpdateHelper::BOUNCE_VERSION) { |
| 50 |
$message = acym_translation('ACYM_NEW_BOUNCE_RULES'); |
| 51 |
$message .= '<a href="#" class="acym__do__not__remindme acym__do__not__remindme__info" title="'.$messageIdentifier.'">'; |
| 52 |
$message .= acym_translation('ACYM_DO_NOT_REMIND_ME'); |
| 53 |
$message .= '</a>'; |
| 54 |
|
| 55 |
acym_enqueueMessage($message, 'info', false); |
| 56 |
} |
| 57 |
} else { |
| 58 |
$toolbarHelper = new ToolbarHelper(); |
| 59 |
$toolbarHelper->addSearchBar($data['search'], 'mailboxes_search', 'ACYM_SEARCH'); |
| 60 |
$toolbarHelper->addButton(acym_translation('ACYM_CREATE'), ['data-task' => 'mailboxAction'], 'add', true); |
| 61 |
$data['toolbar'] = $toolbarHelper; |
| 62 |
} |
| 63 |
|
| 64 |
$data['toolbar'] = $toolbarHelper; |
| 65 |
} |
| 66 |
|
| 67 |
public function bounces(): void |
| 68 |
{ |
| 69 |
$data = []; |
| 70 |
|
| 71 |
|
| 72 |
$data['workflowHelper'] = new WorkflowHelper(); |
| 73 |
if (!acym_level(ACYM_ENTERPRISE)) { |
| 74 |
acym_setVar('layout', 'splashscreen'); |
| 75 |
$data['isEnterprise'] = false; |
| 76 |
} |
| 77 |
|
| 78 |
$this->prepareToolbar($data); |
| 79 |
|
| 80 |
parent::display($data); |
| 81 |
} |
| 82 |
|
| 83 |
public function ajaxSetOrdering(): void |
| 84 |
{ |
| 85 |
$order = json_decode(acym_getVar('string', 'order')); |
| 86 |
$i = 1; |
| 87 |
$error = false; |
| 88 |
foreach ($order as $rule) { |
| 89 |
$query = 'UPDATE #__acym_rule SET `ordering` = '.intval($i).' WHERE `id` = '.intval($rule); |
| 90 |
$error = acym_query($query) < 0 || $error; |
| 91 |
$i++; |
| 92 |
} |
| 93 |
|
| 94 |
acym_sendAjaxResponse('', [], !$error); |
| 95 |
} |
| 96 |
|
| 97 |
public function test(): void |
| 98 |
{ |
| 99 |
$ruleClass = new RuleClass(); |
| 100 |
|
| 101 |
if ($ruleClass->getOrderingNumber() < 1) { |
| 102 |
acym_enqueueMessage(acym_translation('ACYM_NO_RULES'), 'error'); |
| 103 |
|
| 104 |
$this->listing(); |
| 105 |
|
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
acym_increasePerf(); |
| 110 |
$bounceHelper = new BounceHelper(); |
| 111 |
$bounceHelper->report = true; |
| 112 |
|
| 113 |
if ($bounceHelper->init() && $bounceHelper->connect()) { |
| 114 |
$this->runBounce = true; |
| 115 |
} else { |
| 116 |
$errors = $bounceHelper->getErrors(); |
| 117 |
if (!empty($errors)) { |
| 118 |
acym_enqueueMessage($errors, 'error'); |
| 119 |
$errorString = implode(' ', $errors); |
| 120 |
$port = $this->config->get('bounce_port'); |
| 121 |
if (preg_match('#certificate#i', $errorString) && !$this->config->get('bounce_certif', false)) { |
| 122 |
acym_enqueueMessage(acym_translationSprintf('ACYM_YOU_MAY_TURN_ON_OPTION', '<i>'.acym_translation('ACYM_SELF_SIGNED_CERTIFICATE').'</i>'), 'warning'); |
| 123 |
} elseif (!empty($port) && !in_array($port, ['993', '143', '110'])) { |
| 124 |
acym_enqueueMessage(acym_translation('ACYM_BOUNCE_WRONG_PORT'), 'warning'); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
$this->listing(); |
| 130 |
} |
| 131 |
|
| 132 |
public function process(): void |
| 133 |
{ |
| 134 |
acym_increasePerf(); |
| 135 |
|
| 136 |
$bounceHelper = new BounceHelper(); |
| 137 |
$bounceHelper->report = true; |
| 138 |
if (!$bounceHelper->init()) { |
| 139 |
return; |
| 140 |
} |
| 141 |
if (!$bounceHelper->connect()) { |
| 142 |
acym_display($bounceHelper->getErrors(), 'error'); |
| 143 |
|
| 144 |
return; |
| 145 |
} |
| 146 |
$disp = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n"; |
| 147 |
$disp .= '<title>'.addslashes(acym_translation('ACYM_BOUNCE_PROCESS')).'</title>'."\n"; |
| 148 |
$disp .= "<style>body{font-size:12px;font-family: Arial,Helvetica,sans-serif;padding-top:30px;}</style>\n</head>\n<body>"; |
| 149 |
echo $disp; |
| 150 |
|
| 151 |
acym_display(acym_translationSprintf('ACYM_BOUNCE_CONNECT_SUCC', $this->config->get('bounce_username')), 'success'); |
| 152 |
$nbMessages = $bounceHelper->getNBMessages(); |
| 153 |
$nbMessagesReport = acym_translationSprintf('ACYM_NB_MAIL_MAILBOX', $nbMessages); |
| 154 |
acym_display($nbMessagesReport, 'info'); |
| 155 |
|
| 156 |
if (empty($nbMessages)) { |
| 157 |
exit; |
| 158 |
} |
| 159 |
|
| 160 |
$bounceHelper->handleMessages(); |
| 161 |
|
| 162 |
$cronHelper = new CronHelper(); |
| 163 |
$cronHelper->saveReport([$nbMessagesReport], $bounceHelper->messages); |
| 164 |
|
| 165 |
if ($this->config->get('bounce_max', 0) != 0 && $nbMessages > $this->config->get('bounce_max', 0)) { |
| 166 |
$url = acym_completeLink('bounces&task=process&continuebounce=1', true, true); |
| 167 |
if (acym_getVar('int', 'continuebounce')) { |
| 168 |
echo '<script type="text/javascript">document.location.href=\''.$url.'\';</script>'; |
| 169 |
} else { |
| 170 |
echo '<div style="padding:20px;"><a href="'.$url.'">'.acym_translation('ACYM_CLICK_HANDLE_ALL_BOUNCES').'</a></div>'; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
echo '</body></html>'; |
| 175 |
while ($bounceHelper->obend-- > 0) { |
| 176 |
ob_start(); |
| 177 |
} |
| 178 |
exit; |
| 179 |
} |
| 180 |
|
| 181 |
public function reinstall(): void |
| 182 |
{ |
| 183 |
$ruleClass = new RuleClass(); |
| 184 |
$ruleClass->cleanTable(); |
| 185 |
|
| 186 |
$updateHelper = new UpdateHelper(); |
| 187 |
$updateHelper->installBounceRules(); |
| 188 |
|
| 189 |
$this->listing(); |
| 190 |
} |
| 191 |
|
| 192 |
public function config(): void |
| 193 |
{ |
| 194 |
acym_redirect(acym_completeLink('configuration', false, true)); |
| 195 |
} |
| 196 |
|
| 197 |
public function delete(): void |
| 198 |
{ |
| 199 |
$rulesSelected = acym_getVar('array', 'elements_checked'); |
| 200 |
|
| 201 |
if (in_array(RuleClass::FINAL_RULE_ID, $rulesSelected)) { |
| 202 |
acym_enqueueMessage(acym_translation('ACYM_CANNOT_DELETE_FINAL_RULE'), 'error'); |
| 203 |
|
| 204 |
$key = array_search(RuleClass::FINAL_RULE_ID, $rulesSelected); |
| 205 |
if ($key !== false) { |
| 206 |
unset($rulesSelected[$key]); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
$ruleClass = new RuleClass(); |
| 211 |
$ruleClass->delete($rulesSelected); |
| 212 |
|
| 213 |
$this->listing(); |
| 214 |
} |
| 215 |
|
| 216 |
public function setInactive(): void |
| 217 |
{ |
| 218 |
$rulesSelected = acym_getVar('array', 'elements_checked'); |
| 219 |
$ruleClass = new RuleClass(); |
| 220 |
$ruleClass->setInactive($rulesSelected); |
| 221 |
|
| 222 |
$this->listing(); |
| 223 |
} |
| 224 |
|
| 225 |
public function setActive(): void |
| 226 |
{ |
| 227 |
$rulesSelected = acym_getVar('array', 'elements_checked'); |
| 228 |
$ruleClass = new RuleClass(); |
| 229 |
$ruleClass->setActive($rulesSelected); |
| 230 |
|
| 231 |
$this->listing(); |
| 232 |
} |
| 233 |
} |
| 234 |
|