PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.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 / Bounces / Listing.php

Listing.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.2, at back/Controllers/Bounces/Listing.php

275 lines 9.3 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\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 // When one of the raw of the listing is moved we set the ordering
84 public function ajaxSetOrdering(): void
85 {
86 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
87
88 $order = json_decode(acym_getVar('string', 'order'), true);
89 if (empty($order)) {
90 $order = [];
91 }
92
93 $i = 1;
94 $error = false;
95 foreach ($order as $rule) {
96 $query = 'UPDATE #__acym_rule SET `ordering` = '.intval($i).' WHERE `id` = '.intval($rule);
97 $error = acym_query($query) < 0 || $error;
98 $i++;
99 }
100
101 acym_sendAjaxResponse('', [], !$error);
102 }
103
104 // Click on the button Run Bounce Handling
105 public function test(): void
106 {
107 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
108
109 $ruleClass = new RuleClass();
110
111 if ($ruleClass->getOrderingNumber() < 1) {
112 acym_enqueueMessage(acym_translation('ACYM_NO_RULES'), 'error');
113
114 $this->listing();
115
116 return;
117 }
118
119 acym_increasePerf();
120 $bounceHelper = new BounceHelper();
121 $bounceHelper->report = true;
122
123 if ($bounceHelper->init() && $bounceHelper->connect()) {
124 $this->runBounce = true;
125 } else {
126 $errors = $bounceHelper->getErrors();
127 if (!empty($errors)) {
128 acym_enqueueMessage($errors, 'error');
129 $errorString = implode(' ', $errors);
130 $port = $this->config->get('bounce_port');
131 if (preg_match('#certificate#i', $errorString) && !$this->config->get('bounce_certif', false)) {
132 //Self signed certificate issue
133 acym_enqueueMessage(acym_translationSprintf('ACYM_YOU_MAY_TURN_ON_OPTION', '<i>'.acym_translation('ACYM_SELF_SIGNED_CERTIFICATE').'</i>'), 'warning');
134 } elseif (!empty($port) && !in_array($port, ['993', '143', '110'])) {
135 //Not the right port... ?
136 acym_enqueueMessage(acym_translation('ACYM_BOUNCE_WRONG_PORT'), 'warning');
137 }
138 }
139 }
140
141 $this->listing();
142 }
143
144 // Process bounce handling after clicking on the button Run Bounce Handling
145 public function process(): void
146 {
147 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
148
149 acym_increasePerf();
150
151 $bounceHelper = new BounceHelper();
152 $bounceHelper->report = true;
153 if (!$bounceHelper->init()) {
154 return;
155 }
156 if (!$bounceHelper->connect()) {
157 acym_display($bounceHelper->getErrors(), 'error');
158
159 return;
160 }
161 ?>
162 <html>
163 <head>
164 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
165 <title><?php echo esc_html(acym_translation('ACYM_BOUNCE_PROCESS')); ?></title>
166 <style>
167 body{
168 font-size: 12px;
169 font-family: Arial, Helvetica, sans-serif;
170 padding-top: 30px;
171 }
172 </style>
173 </head>
174 <body>
175 <?php
176 acym_display(acym_translationSprintf('ACYM_BOUNCE_CONNECT_SUCC', $this->config->get('bounce_username')), 'success');
177 $nbMessages = $bounceHelper->getNBMessages();
178 $nbMessagesReport = acym_translationSprintf('ACYM_NB_MAIL_MAILBOX', $nbMessages);
179 acym_display($nbMessagesReport, 'info');
180
181 //that should not happen as we check it before anyway...
182 if (empty($nbMessages)) {
183 exit;
184 }
185
186 $bounceHelper->handleMessages();
187
188 //Load the cron class to save the report if there is one
189 $cronHelper = new CronHelper();
190 $cronHelper->saveReport([$nbMessagesReport], $bounceHelper->messages);
191
192 if ($this->config->get('bounce_max', 0) != 0 && $nbMessages > $this->config->get('bounce_max', 0)) {
193 //We still have some messages...
194 $url = acym_completeLink('bounces&task=process&continuebounce=1', true, true).'&'.acym_getFormToken();
195 if (acym_getVar('int', 'continuebounce')) {
196 //We already started the bounce handling and we should resume it until the end...
197 echo '<script type="text/javascript">document.location.href = '.json_encode($url).';</script>';
198 } else {
199 //We should propose to the user to resume the bounce process until the end...
200 echo '<div style="padding:20px;"><a href="'.esc_url($url).'">'.esc_html(acym_translation('ACYM_CLICK_HANDLE_ALL_BOUNCES')).'</a></div>';
201 }
202 }
203
204 //We need to finish the current page properly
205 echo '</body></html>';
206 while ($bounceHelper->obend-- > 0) {
207 ob_start();
208 }
209 exit;
210 }
211
212 // Click on the button Reset to default rules
213 public function reinstall(): void
214 {
215 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
216
217 $ruleClass = new RuleClass();
218 $ruleClass->cleanTable();
219
220 $updateHelper = new UpdateHelper();
221 $updateHelper->installBounceRules();
222
223 $this->listing();
224 }
225
226 // Click on the button configuration
227 public function config(): void
228 {
229 acym_redirect(acym_completeLink('configuration', false, true));
230 }
231
232 public function delete(): void
233 {
234 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
235
236 $rulesSelected = acym_getVar('array', 'elements_checked', []);
237
238 if (in_array(RuleClass::FINAL_RULE_ID, $rulesSelected)) {
239 acym_enqueueMessage(acym_translation('ACYM_CANNOT_DELETE_FINAL_RULE'), 'error');
240
241 $key = array_search(RuleClass::FINAL_RULE_ID, $rulesSelected);
242 if ($key !== false) {
243 unset($rulesSelected[$key]);
244 }
245 }
246
247 $ruleClass = new RuleClass();
248 $ruleClass->delete($rulesSelected);
249
250 $this->listing();
251 }
252
253 public function setInactive(): void
254 {
255 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
256
257 $rulesSelected = acym_getVar('array', 'elements_checked', []);
258 $ruleClass = new RuleClass();
259 $ruleClass->setInactive($rulesSelected);
260
261 $this->listing();
262 }
263
264 public function setActive(): void
265 {
266 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
267
268 $rulesSelected = acym_getVar('array', 'elements_checked', []);
269 $ruleClass = new RuleClass();
270 $ruleClass->setActive($rulesSelected);
271
272 $this->listing();
273 }
274 }
275