| @@ -11,56 +11,28 @@ | ||
| 11 | 11 | use AcyMailing\Types\StepsType; |
| 12 | 12 | |
| 13 | 13 | trait Walkthrough |
| 14 | 14 | { |
| 15 | - public function walkthrough(): bool | |
| 15 | + public function saveStepThankYou(): void | |
| 16 | 16 | { |
| 17 | - if ($this->config->get('walk_through', 0) != 1) { | |
| 18 | - return false; | |
| 19 | - } | |
| 17 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 20 | 18 | |
| 21 | - $walkthroughParams = json_decode($this->config->get('walkthrough_params', '[]'), true); | |
| 22 | - if (empty($walkthroughParams['step']) || !method_exists($this, $walkthroughParams['step'])) { | |
| 23 | - $this->stepThankYou(); | |
| 24 | - } else { | |
| 25 | - $this->{$walkthroughParams['step']}(); | |
| 19 | + if (!acym_isAllowed('configuration')) { | |
| 20 | + return; | |
| 26 | 21 | } |
| 27 | 22 | |
| 28 | - return true; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function stepThankYou(): void | |
| 32 | - { | |
| 33 | - acym_setVar('layout', 'step_thank_you'); | |
| 34 | - | |
| 35 | - $data = [ | |
| 36 | - 'level' => $this->config->get('level'), | |
| 37 | - ]; | |
| 38 | - | |
| 39 | - parent::display($data); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public function saveStepThankYou(): void | |
| 43 | - { | |
| 44 | 23 | $this->saveWalkthrough(['step' => 'stepSenderInformation']); |
| 45 | 24 | $this->stepSenderInformation(); |
| 46 | 25 | } |
| 47 | 26 | |
| 48 | - public function stepSenderInformation(): void | |
| 27 | + public function saveStepSenderInformation(): void | |
| 49 | 28 | { |
| 50 | - acym_setVar('layout', 'step_sender_information'); | |
| 29 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 51 | 30 | |
| 52 | - $data = [ | |
| 53 | - 'stepsType' => new StepsType(), | |
| 54 | - 'siteName' => $this->config->get('from_name', acym_getCMSConfig('sitename')), | |
| 55 | - 'userEmail' => $this->config->get('from_email', acym_currentUserEmail()), | |
| 56 | - ]; | |
| 31 | + if (!acym_isAllowed('configuration')) { | |
| 32 | + return; | |
| 33 | + } | |
| 57 | 34 | |
| 58 | - parent::display($data); | |
| 59 | - } | |
| 60 | - | |
| 61 | - public function saveStepSenderInformation(): void | |
| 62 | - { | |
| 63 | 35 | $newConfiguration = [ |
| 64 | 36 | 'from_name' => acym_getVar('string', 'from_name'), |
| 65 | 37 | 'from_email' => acym_getVar('string', 'from_email'), |
| 66 | 38 | ]; |
| @@ -71,42 +43,36 @@ | ||
| 71 | 43 | |
| 72 | 44 | return; |
| 73 | 45 | } |
| 74 | 46 | |
| 75 | - $this->config->save($newConfiguration); | |
| 47 | + $this->config->saveConfig($newConfiguration); | |
| 76 | 48 | |
| 77 | 49 | $this->saveWalkthrough(['step' => 'stepLicense']); |
| 78 | 50 | $this->stepLicense(); |
| 79 | 51 | } |
| 80 | 52 | |
| 81 | - public function stepLicense(): void | |
| 53 | + public function ajaxAttachLicense(): void | |
| 82 | 54 | { |
| 83 | - acym_setVar('layout', 'step_license'); | |
| 55 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 84 | 56 | |
| 85 | - $data = [ | |
| 86 | - 'stepsType' => new StepsType(), | |
| 87 | - 'level' => $this->config->get('level'), | |
| 88 | - ]; | |
| 57 | + if (!acym_isAllowed('configuration')) { | |
| 58 | + return; | |
| 59 | + } | |
| 89 | 60 | |
| 90 | - parent::display($data); | |
| 91 | - } | |
| 92 | - | |
| 93 | - public function ajaxAttachLicense(): void | |
| 94 | - { | |
| 95 | - acym_checkToken(); | |
| 96 | - | |
| 97 | 61 | $licenseKey = acym_getVar('string', 'licenseKey', ''); |
| 98 | 62 | if (empty($licenseKey)) { |
| 99 | 63 | acym_sendAjaxResponse(acym_translation('ACYM_LICENSE_NOT_FOUND'), [], false); |
| 100 | 64 | } |
| 101 | 65 | |
| 102 | - $this->config->save(['license_key' => $licenseKey]); | |
| 66 | + $this->config->saveConfig(['license_key' => $licenseKey]); | |
| 103 | 67 | |
| 104 | 68 | $configurationController = new ConfigurationController(); |
| 105 | 69 | $return = $configurationController->attachLicenseOnUpdateMe($licenseKey); |
| 106 | 70 | |
| 107 | 71 | if (empty($return['success'])) { |
| 108 | - $this->config->save(['license_key' => '']); | |
| 72 | + $this->config->saveConfig(['license_key' => '']); | |
| 73 | + } else { | |
| 74 | + UpdatemeHelper::getLicenseInfo(); | |
| 109 | 75 | } |
| 110 | 76 | |
| 111 | 77 | $originalMessage = $return['message']; |
| 112 | 78 | $return['message'] = $configurationController->displayMessage($originalMessage, true); |
| @@ -116,10 +82,14 @@ | ||
| 116 | 82 | } |
| 117 | 83 | |
| 118 | 84 | public function ajaxActivateCron(): void |
| 119 | 85 | { |
| 120 | - acym_checkToken(); | |
| 86 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 121 | 87 | |
| 88 | + if (!acym_isAllowed('configuration')) { | |
| 89 | + return; | |
| 90 | + } | |
| 91 | + | |
| 122 | 92 | $licenseKey = $this->config->get('license_key'); |
| 123 | 93 | if (empty($licenseKey)) { |
| 124 | 94 | acym_sendAjaxResponse(acym_translation('ACYM_LICENSE_NOT_FOUND'), [], false); |
| 125 | 95 | } |
| @@ -137,9 +107,9 @@ | ||
| 137 | 107 | $result['message'] = $configurationController->displayMessage($result['message'] ?? 'CRON_NOT_SAVED', true); |
| 138 | 108 | $success = !empty($result['success']); |
| 139 | 109 | |
| 140 | 110 | if ($success) { |
| 141 | - $this->config->save(['active_cron' => 1]); | |
| 111 | + $this->config->saveConfig(['active_cron' => 1]); | |
| 142 | 112 | } |
| 143 | 113 | |
| 144 | 114 | acym_sendAjaxResponse($result['message']['message'], [], $success); |
| 145 | 115 | } |
| @@ -145,14 +115,118 @@ | ||
| 145 | 115 | } |
| 146 | 116 | |
| 147 | 117 | public function saveStepLicense(): void |
| 148 | 118 | { |
| 119 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 120 | + | |
| 121 | + if (!acym_isAllowed('configuration')) { | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + | |
| 149 | 125 | $this->saveWalkthrough(['step' => 'stepFinal']); |
| 150 | 126 | $this->stepFinal(); |
| 151 | 127 | } |
| 152 | 128 | |
| 153 | - public function stepFinal(): void | |
| 129 | + public function startUsing(bool $campaigns = false): void | |
| 154 | 130 | { |
| 131 | + if (!$campaigns) { | |
| 132 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 133 | + } | |
| 134 | + | |
| 135 | + if (!acym_isAllowed('configuration')) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + | |
| 139 | + $this->config->saveConfig(['walk_through' => 0]); | |
| 140 | + $redirectUrl = $campaigns ? 'campaigns' : 'dashboard'; | |
| 141 | + | |
| 142 | + acym_redirect(acym_completeLink($redirectUrl, false, true)); | |
| 143 | + } | |
| 144 | + | |
| 145 | + public function tryEditor(): void | |
| 146 | + { | |
| 147 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 148 | + | |
| 149 | + if (!acym_isAllowed('configuration')) { | |
| 150 | + return; | |
| 151 | + } | |
| 152 | + | |
| 153 | + $this->saveWalkthrough(['step' => 'stepEditor']); | |
| 154 | + $this->stepEditor(); | |
| 155 | + } | |
| 156 | + | |
| 157 | + public function saveAjax(): void | |
| 158 | + { | |
| 159 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 160 | + | |
| 161 | + if (!acym_isAllowed('configuration') || $this->config->get('walk_through', 0) != 1) { | |
| 162 | + return; | |
| 163 | + } | |
| 164 | + | |
| 165 | + $mailController = new MailsController(); | |
| 166 | + $mailId = $mailController->store(true); | |
| 167 | + | |
| 168 | + if (!empty($mailId)) { | |
| 169 | + acym_sendAjaxResponse('', ['result' => $mailId]); | |
| 170 | + } else { | |
| 171 | + acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 175 | + private function walkthrough(): bool | |
| 176 | + { | |
| 177 | + if ($this->config->get('walk_through', 0) != 1 || !acym_isAllowed('configuration')) { | |
| 178 | + return false; | |
| 179 | + } | |
| 180 | + | |
| 181 | + $walkthroughParams = json_decode($this->config->get('walkthrough_params', '[]'), true); | |
| 182 | + if (empty($walkthroughParams['step']) || !method_exists($this, $walkthroughParams['step'])) { | |
| 183 | + $this->stepThankYou(); | |
| 184 | + } else { | |
| 185 | + $this->{$walkthroughParams['step']}(); | |
| 186 | + } | |
| 187 | + | |
| 188 | + return true; | |
| 189 | + } | |
| 190 | + | |
| 191 | + private function stepThankYou(): void | |
| 192 | + { | |
| 193 | + acym_setVar('layout', 'step_thank_you'); | |
| 194 | + | |
| 195 | + $data = [ | |
| 196 | + 'level' => $this->config->get('level'), | |
| 197 | + ]; | |
| 198 | + | |
| 199 | + parent::display($data); | |
| 200 | + } | |
| 201 | + | |
| 202 | + private function stepSenderInformation(): void | |
| 203 | + { | |
| 204 | + acym_setVar('layout', 'step_sender_information'); | |
| 205 | + | |
| 206 | + $data = [ | |
| 207 | + 'stepsType' => new StepsType(), | |
| 208 | + 'siteName' => $this->config->get('from_name', acym_getCMSConfig('sitename')), | |
| 209 | + 'userEmail' => $this->config->get('from_email', acym_currentUserEmail()), | |
| 210 | + ]; | |
| 211 | + | |
| 212 | + parent::display($data); | |
| 213 | + } | |
| 214 | + | |
| 215 | + private function stepLicense(): void | |
| 216 | + { | |
| 217 | + acym_setVar('layout', 'step_license'); | |
| 218 | + | |
| 219 | + $data = [ | |
| 220 | + 'stepsType' => new StepsType(), | |
| 221 | + 'level' => $this->config->get('level'), | |
| 222 | + ]; | |
| 223 | + | |
| 224 | + parent::display($data); | |
| 225 | + } | |
| 226 | + | |
| 227 | + private function stepFinal(): void | |
| 228 | + { | |
| 155 | 229 | $acyMailerApiKey = $this->config->get('acymailer_apikey'); |
| 156 | 230 | acym_setVar('layout', empty($acyMailerApiKey) ? 'step_final' : 'step_acymailer'); |
| 157 | 231 | |
| 158 | 232 | $data = [ |
| @@ -166,24 +240,10 @@ | ||
| 166 | 240 | |
| 167 | 241 | parent::display($data); |
| 168 | 242 | } |
| 169 | 243 | |
| 170 | - public function startUsing(bool $campaigns = false): void | |
| 244 | + private function stepEditor(): void | |
| 171 | 245 | { |
| 172 | - $this->config->save(['walk_through' => 0]); | |
| 173 | - $redirectUrl = $campaigns ? 'campaigns' : 'dashboard'; | |
| 174 | - | |
| 175 | - acym_redirect(acym_completeLink($redirectUrl, false, true)); | |
| 176 | - } | |
| 177 | - | |
| 178 | - public function tryEditor(): void | |
| 179 | - { | |
| 180 | - $this->saveWalkthrough(['step' => 'stepEditor']); | |
| 181 | - $this->stepEditor(); | |
| 182 | - } | |
| 183 | - | |
| 184 | - public function stepEditor(): void | |
| 185 | - { | |
| 186 | 246 | acym_setVar('layout', 'step_editor'); |
| 187 | 247 | |
| 188 | 248 | $mailClass = new MailClass(); |
| 189 | 249 | $mail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY)); |
| @@ -216,20 +276,8 @@ | ||
| 216 | 276 | |
| 217 | 277 | parent::display($data); |
| 218 | 278 | } |
| 219 | 279 | |
| 220 | - public function saveAjax(): void | |
| 221 | - { | |
| 222 | - $mailController = new MailsController(); | |
| 223 | - $mailId = $mailController->store(true); | |
| 224 | - | |
| 225 | - if (!empty($mailId)) { | |
| 226 | - acym_sendAjaxResponse('', ['result' => $mailId]); | |
| 227 | - } else { | |
| 228 | - acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false); | |
| 229 | - } | |
| 230 | - } | |
| 231 | - | |
| 232 | 280 | private function saveWalkthrough(array $params): void |
| 233 | 281 | { |
| 234 | 282 | $newParams = json_decode($this->config->get('walkthrough_params', '[]'), true); |
| 235 | 283 | foreach ($params as $key => $value) { |
| @@ -234,7 +282,7 @@ | ||
| 234 | 282 | $newParams = json_decode($this->config->get('walkthrough_params', '[]'), true); |
| 235 | 283 | foreach ($params as $key => $value) { |
| 236 | 284 | $newParams[$key] = $value; |
| 237 | 285 | } |
| 238 | - $this->config->save(['walkthrough_params' => json_encode($newParams)]); | |
| 286 | + $this->config->saveConfig(['walkthrough_params' => json_encode($newParams)]); | |
| 239 | 287 | } |
| 240 | 288 | } |