PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.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.10.2, at back/Controllers/Dashboard/Walkthrough.php

243 lines 7.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\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->saveConfig($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->saveConfig(['license_key' => $licenseKey]);
103
104 $configurationController = new ConfigurationController();
105 $return = $configurationController->attachLicenseOnUpdateMe($licenseKey);
106
107 if (empty($return['success'])) {
108 $this->config->saveConfig(['license_key' => '']);
109 } else {
110 UpdatemeHelper::getLicenseInfo();
111 }
112
113 $originalMessage = $return['message'];
114 $return['message'] = $configurationController->displayMessage($originalMessage, true);
115 $ajaxSuccess = !empty($return['message']['type']) && $return['message']['type'] !== 'error';
116
117 acym_sendAjaxResponse($return['message']['message'] ?? $originalMessage, [], $ajaxSuccess);
118 }
119
120 public function ajaxActivateCron(): void
121 {
122 acym_checkToken();
123
124 $licenseKey = $this->config->get('license_key');
125 if (empty($licenseKey)) {
126 acym_sendAjaxResponse(acym_translation('ACYM_LICENSE_NOT_FOUND'), [], false);
127 }
128
129 $data = [
130 'domain' => ACYM_LIVE,
131 'cms' => ACYM_CMS,
132 'version' => $this->config->get('version', ''),
133 'level' => $this->config->get('level', ''),
134 'activate' => true,
135 ];
136 $result = UpdatemeHelper::call('api/crons/modify', 'POST', $data);
137
138 $configurationController = new ConfigurationController();
139 $result['message'] = $configurationController->displayMessage($result['message'] ?? 'CRON_NOT_SAVED', true);
140 $success = !empty($result['success']);
141
142 if ($success) {
143 $this->config->saveConfig(['active_cron' => 1]);
144 }
145
146 acym_sendAjaxResponse($result['message']['message'], [], $success);
147 }
148
149 public function saveStepLicense(): void
150 {
151 $this->saveWalkthrough(['step' => 'stepFinal']);
152 $this->stepFinal();
153 }
154
155 public function stepFinal(): void
156 {
157 $acyMailerApiKey = $this->config->get('acymailer_apikey');
158 acym_setVar('layout', empty($acyMailerApiKey) ? 'step_final' : 'step_acymailer');
159
160 $data = [
161 'stepsType' => new StepsType(),
162 'pricingPage' => ACYM_ACYMAILING_WEBSITE.'pricing',
163 ];
164
165 if (!empty($acyMailerApiKey)) {
166 $data['suggestedDomain'] = acym_getDomain($this->config->get('from_email', acym_currentUserEmail()));
167 }
168
169 parent::display($data);
170 }
171
172 public function startUsing(bool $campaigns = false): void
173 {
174 $this->config->saveConfig(['walk_through' => 0]);
175 $redirectUrl = $campaigns ? 'campaigns' : 'dashboard';
176
177 acym_redirect(acym_completeLink($redirectUrl, false, true));
178 }
179
180 public function tryEditor(): void
181 {
182 $this->saveWalkthrough(['step' => 'stepEditor']);
183 $this->stepEditor();
184 }
185
186 public function stepEditor(): void
187 {
188 acym_setVar('layout', 'step_editor');
189
190 $mailClass = new MailClass();
191 $mail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY));
192
193 if (empty($mail)) {
194 $updateHelper = new UpdateHelper();
195 $updateHelper->installNotifications();
196 $mail = $mailClass->getOneByName(acym_translation(UpdateHelper::FIRST_EMAIL_NAME_KEY));
197 if (empty($mail)) {
198 $this->startUsing(true);
199
200 return;
201 }
202 }
203
204 $editorHelper = new EditorHelper();
205 $editorHelper->content = $mail->body;
206 $editorHelper->autoSave = '';
207 $editorHelper->settings = $mail->settings;
208 $editorHelper->stylesheet = $mail->stylesheet ?? '';
209 $editorHelper->editor = 'acyEditor';
210 $editorHelper->mailId = $mail->id;
211 $editorHelper->walkThrough = true;
212
213 $data = [
214 'mail' => $mail,
215 'social_icons' => $this->config->get('social_icons', '{}'),
216 'editor' => $editorHelper,
217 ];
218
219 parent::display($data);
220 }
221
222 public function saveAjax(): void
223 {
224 $mailController = new MailsController();
225 $mailId = $mailController->store(true);
226
227 if (!empty($mailId)) {
228 acym_sendAjaxResponse('', ['result' => $mailId]);
229 } else {
230 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
231 }
232 }
233
234 private function saveWalkthrough(array $params): void
235 {
236 $newParams = json_decode($this->config->get('walkthrough_params', '[]'), true);
237 foreach ($params as $key => $value) {
238 $newParams[$key] = $value;
239 }
240 $this->config->saveConfig(['walkthrough_params' => json_encode($newParams)]);
241 }
242 }
243