PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.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 / Dashboard / Walkthrough.php

Walkthrough.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Controllers/Dashboard/Walkthrough.php

241 lines 7.2 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\Dashboard;
4
5 use AcyMailing\Classes\MailClass;
6 use AcyMailing\Controllers\ConfigurationController;
7 use AcyMailing\Controllers\MailsController;
8 use AcyMailing\Helpers\EditorHelper;
9 use AcyMailing\Helpers\UpdateHelper;
10 use AcyMailing\Helpers\UpdatemeHelper;
11 use AcyMailing\Types\StepsType;
12
13 trait Walkthrough
14 {
15 public function walkthrough(): bool
16 {
17 if ($this->config->get('walk_through', 0) != 1) {
18 return false;
19 }
20
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']}();
26 }
27
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 $this->saveWalkthrough(['step' => 'stepSenderInformation']);
45 $this->stepSenderInformation();
46 }
47
48 public function stepSenderInformation(): void
49 {
50 acym_setVar('layout', 'step_sender_information');
51
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 ];
57
58 parent::display($data);
59 }
60
61 public function saveStepSenderInformation(): void
62 {
63 $newConfiguration = [
64 'from_name' => acym_getVar('string', 'from_name'),
65 'from_email' => acym_getVar('string', 'from_email'),
66 ];
67
68 if (empty($newConfiguration['from_name']) || empty($newConfiguration['from_email'])) {
69 acym_enqueueMessage(acym_translation('ACYM_FILL_ALL_INFORMATION'), 'error');
70 $this->stepSenderInformation();
71
72 return;
73 }
74
75 $this->config->save($newConfiguration);
76
77 $this->saveWalkthrough(['step' => 'stepLicense']);
78 $this->stepLicense();
79 }
80
81 public function stepLicense(): void
82 {
83 acym_setVar('layout', 'step_license');
84
85 $data = [
86 'stepsType' => new StepsType(),
87 'level' => $this->config->get('level'),
88 ];
89
90 parent::display($data);
91 }
92
93 public function ajaxAttachLicense(): void
94 {
95 acym_checkToken();
96
97 $licenseKey = acym_getVar('string', 'licenseKey', '');
98 if (empty($licenseKey)) {
99 acym_sendAjaxResponse(acym_translation('ACYM_LICENSE_NOT_FOUND'), [], false);
100 }
101
102 $this->config->save(['license_key' => $licenseKey]);
103
104 $configurationController = new ConfigurationController();
105 $return = $configurationController->attachLicenseOnUpdateMe($licenseKey);
106
107 if (empty($return['success'])) {
108 $this->config->save(['license_key' => '']);
109 }
110
111 $originalMessage = $return['message'];
112 $return['message'] = $configurationController->displayMessage($originalMessage, true);
113 $ajaxSuccess = !empty($return['message']['type']) && $return['message']['type'] !== 'error';
114
115 acym_sendAjaxResponse($return['message']['message'] ?? $originalMessage, [], $ajaxSuccess);
116 }
117
118 public function ajaxActivateCron(): void
119 {
120 acym_checkToken();
121
122 $licenseKey = $this->config->get('license_key');
123 if (empty($licenseKey)) {
124 acym_sendAjaxResponse(acym_translation('ACYM_LICENSE_NOT_FOUND'), [], false);
125 }
126
127 $data = [
128 'domain' => ACYM_LIVE,
129 'cms' => ACYM_CMS,
130 'version' => $this->config->get('version', ''),
131 'level' => $this->config->get('level', ''),
132 'activate' => true,
133 ];
134 $result = UpdatemeHelper::call('api/crons/modify', 'POST', $data);
135
136 $configurationController = new ConfigurationController();
137 $result['message'] = $configurationController->displayMessage($result['message'] ?? 'CRON_NOT_SAVED', true);
138 $success = !empty($result['success']);
139
140 if ($success) {
141 $this->config->save(['active_cron' => 1]);
142 }
143
144 acym_sendAjaxResponse($result['message']['message'], [], $success);
145 }
146
147 public function saveStepLicense(): void
148 {
149 $this->saveWalkthrough(['step' => 'stepFinal']);
150 $this->stepFinal();
151 }
152
153 public function stepFinal(): void
154 {
155 $acyMailerApiKey = $this->config->get('acymailer_apikey');
156 acym_setVar('layout', empty($acyMailerApiKey) ? 'step_final' : 'step_acymailer');
157
158 $data = [
159 'stepsType' => new StepsType(),
160 'pricingPage' => ACYM_ACYMAILING_WEBSITE.'pricing',
161 ];
162
163 if (!empty($acyMailerApiKey)) {
164 $data['suggestedDomain'] = acym_getDomain($this->config->get('from_email', acym_currentUserEmail()));
165 }
166
167 parent::display($data);
168 }
169
170 public function startUsing(bool $campaigns = false): void
171 {
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 acym_setVar('layout', 'step_editor');
187
188 $mailClass = new MailClass();
189 $mail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY));
190
191 if (empty($mail)) {
192 $updateHelper = new UpdateHelper();
193 $updateHelper->installNotifications();
194 $mail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY));
195 if (empty($mail)) {
196 $this->startUsing(true);
197
198 return;
199 }
200 }
201
202 $editorHelper = new EditorHelper();
203 $editorHelper->content = $mail->body;
204 $editorHelper->autoSave = '';
205 $editorHelper->settings = $mail->settings;
206 $editorHelper->stylesheet = $mail->stylesheet ?? '';
207 $editorHelper->editor = 'acyEditor';
208 $editorHelper->mailId = $mail->id;
209 $editorHelper->walkThrough = true;
210
211 $data = [
212 'mail' => $mail,
213 'social_icons' => $this->config->get('social_icons', '{}'),
214 'editor' => $editorHelper,
215 ];
216
217 parent::display($data);
218 }
219
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 private function saveWalkthrough(array $params): void
233 {
234 $newParams = json_decode($this->config->get('walkthrough_params', '[]'), true);
235 foreach ($params as $key => $value) {
236 $newParams[$key] = $value;
237 }
238 $this->config->save(['walkthrough_params' => json_encode($newParams)]);
239 }
240 }
241