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