PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
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
← All changes | back/Controllers/Campaigns/Followup.php +0 -401 11.0.2 → 11.1.1 View file →
@@ -1,401 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Controllers\Campaigns;
4 -
5 -use AcyMailing\Classes\FollowupClass;
6 -use AcyMailing\Classes\MailClass;
7 -use AcyMailing\Classes\ListClass;
8 -use AcyMailing\Classes\SegmentClass;
9 -use AcyMailing\Helpers\WorkflowHelper;
10 -use stdClass;
11 -
12 -
13 -trait Followup
14 -{
15 - public function followup(): void
16 - {
17 - acym_setVar('layout', 'followup');
18 -
19 - $data = [
20 - 'campaign_type' => MailClass::TYPE_FOLLOWUP,
21 - 'element_to_display' => lcfirst(acym_translation('ACYM_FOLLOW_UP')),
22 - ];
23 - $this->getAllParamsRequest($data);
24 - $this->prepareEmailsListing($data, $data['campaign_type'], 'followup');
25 - $this->prepareToolbar($data);
26 - $this->prepareListingClasses($data);
27 - $this->prepareFollowupListing($data);
28 -
29 - parent::display($data);
30 - }
31 -
32 - private function prepareFollowupListing(array &$data): void
33 - {
34 - $followupClass = new FollowupClass();
35 - $triggers = [];
36 - acym_trigger('getFollowupTriggers', [&$triggers]);
37 - $data['allTriggers'] = $triggers;
38 -
39 - foreach ($data['allCampaigns'] as $key => $oneFollowup) {
40 - if (!empty($triggers[$oneFollowup->trigger])) {
41 - $oneFollowup->condition = json_decode($oneFollowup->condition, true);
42 - $data['allCampaigns'][$key]->condition = $followupClass->getConditionSummary($oneFollowup);
43 - $data['allCampaigns'][$key]->mail_ids = $followupClass->getEmailsByIds([$oneFollowup->id]);
44 - }
45 - }
46 - }
47 -
48 - public function deleteFollowup(): void
49 - {
50 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
51 - $ids = acym_getVar('array', 'elements_checked', []);
52 - $allChecked = acym_getVar('string', 'checkbox_all');
53 - $currentPage = explode('_', acym_getVar('string', 'page'));
54 - $pageNumber = $this->getVarFiltersListing('int', end($currentPage).'_pagination_page', 1);
55 -
56 - if (!empty($ids)) {
57 - $followupClass = new FollowupClass();
58 - $followupClass->delete($ids);
59 - if ($allChecked == 'on') {
60 - $this->setVarFiltersListing(end($currentPage).'_pagination_page', $pageNumber - 1);
61 - }
62 - }
63 -
64 - $this->listing();
65 - }
66 -
67 - public function followupTrigger(): void
68 - {
69 - acym_setVar('layout', 'followup_trigger');
70 -
71 - $id = acym_getVar('int', 'id', 0);
72 -
73 - if (!empty($id)) {
74 - $followupClass = new FollowupClass();
75 - $followup = $followupClass->getOneById($id);
76 - } else {
77 - $followup = new stdClass();
78 - }
79 -
80 - $this->setTaskListing('followup');
81 -
82 - $data = [
83 - 'workflowHelper' => new WorkflowHelper(),
84 - 'followup' => $followup,
85 - ];
86 -
87 - $linkId = empty($id) ? '' : '&id='.$id;
88 -
89 - $this->breadcrumb[empty($id) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink('campaigns&task=edit&step=followupTrigger'.$linkId);
90 -
91 - parent::display($data);
92 - }
93 -
94 - public function followupCondition(): void
95 - {
96 - acym_setVar('layout', 'followup_condition');
97 -
98 - $id = acym_getVar('int', 'id', 0);
99 - $trigger = acym_getVar('string', 'trigger', '');
100 -
101 - if (!empty($id)) {
102 - $followupClass = new FollowupClass();
103 - $followup = $followupClass->getOneById($id);
104 - } else {
105 - $followup = new stdClass();
106 - }
107 -
108 - if (empty($trigger) && empty($followup->trigger)) {
109 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
110 - $this->listing();
111 -
112 - return;
113 - }
114 -
115 - $listClass = new ListClass();
116 - $lists = $listClass->getAllForSelect(false);
117 -
118 - $segmentClass = new SegmentClass();
119 - $segments = $segmentClass->getAllForSelect(false);
120 -
121 - $statusArray = [
122 - 'is' => acym_strtolower(acym_translation('ACYM_IS')),
123 - 'is_not' => acym_strtolower(acym_translation('ACYM_IS_NOT')),
124 - ];
125 -
126 - $additionalCondition = [];
127 - acym_trigger('getAcymAdditionalConditionFollowup', [&$additionalCondition, empty($trigger) ? $followup->trigger : $trigger, $followup, $statusArray]);
128 -
129 - $actualTrigger = empty($trigger) ? $followup->trigger : $trigger;
130 -
131 - $data = [
132 - 'workflowHelper' => new WorkflowHelper(),
133 - 'followup' => $followup,
134 - 'additionalCondition' => $additionalCondition,
135 - 'trigger' => $actualTrigger,
136 - 'lists_multiselect' => '<span class="cell large-4 medium-6 acym__followup__condition__select__in-text">'.acym_selectMultiple(
137 - $lists,
138 - 'followup[condition][lists]',
139 - !empty($followup->condition) && !empty($followup->condition['lists']) ? $followup->condition['lists'] : [],
140 - ['class' => 'acym__select']
141 - ).'</span>',
142 - 'segments_multiselect' => '<span class="cell large-4 medium-6 acym__followup__condition__select__in-text">'.acym_selectMultiple(
143 - $segments,
144 - 'followup[condition][segments]',
145 - !empty($followup->condition) && !empty($followup->condition['segments']) ? $followup->condition['segments'] : [],
146 - ['class' => 'acym__select']
147 - ).'</span>',
148 - 'select_status_lists' => '<span class="cell xxlarge-1 medium-2 acym__followup__condition__select__in-text">'.acym_select(
149 - $statusArray,
150 - 'followup[condition][lists_status]',
151 - !empty($followup->condition) && !empty($followup->condition['lists_status']) ? $followup->condition['lists_status'] : '',
152 - ['class' => 'acym__select']
153 - ).'</span>',
154 - 'select_status_segments' => '<span class="cell xxlarge-1 medium-2 acym__followup__condition__select__in-text">'.acym_select(
155 - $statusArray,
156 - 'followup[condition][segments_status]',
157 - !empty($followup->condition) && !empty($followup->condition['segments_status']) ? $followup->condition['segments_status'] : '',
158 - ['class' => 'acym__select']
159 - ).'</span>',
160 - 'lists_subscribe_translation' => $actualTrigger == 'user_subscribe' ? 'ACYM_FOLLOW_UP_CONDITION_USER_SUBSCRIBING' : 'ACYM_FOLLOW_UP_CONDITION_USER_SUBSCRIBE',
161 - ];
162 -
163 - $linkId = empty($id) ? '&trigger='.$trigger : '&id='.$id;
164 -
165 - $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
166 - 'campaigns&task=edit&step=followupCondition'.$linkId
167 - );
168 -
169 - parent::display($data);
170 - }
171 -
172 - public function followupEmail(): void
173 - {
174 - acym_setVar('layout', 'followup_email');
175 -
176 - $id = acym_getVar('int', 'id', 0);
177 -
178 - if (empty($id)) {
179 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
180 - $this->listing();
181 -
182 - return;
183 - }
184 -
185 - $followupClass = new FollowupClass();
186 - $followup = $followupClass->getOneByIdWithMails($id);
187 -
188 - if (empty($followup)) {
189 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
190 - $this->listing();
191 -
192 - return;
193 - }
194 -
195 - $favoriteTemplate = $this->config->get('favorite_template', 0);
196 - $startFrom = empty($favoriteTemplate) ? '' : '&from='.$favoriteTemplate;
197 - $data = [
198 - 'workflowHelper' => new WorkflowHelper(),
199 - 'followup' => $followup,
200 - 'linkNewEmail' => acym_completeLink(
201 - 'mails&task=edit&step=editEmail&type=followup&followup_id='.$id.'&return='.urlencode(
202 - acym_completeLink('campaigns&task=edit&step=followupEmail&id='.$id)
203 - ).$startFrom,
204 - false,
205 - true
206 - ),
207 - ];
208 -
209 - $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
210 - 'campaigns&task=edit&step=followupEmail&id='.$followup->id
211 - );
212 -
213 - // Ask the user if he wants to add the new email to the queue for the users that already triggered the followup
214 - if (intval($followup->active) === 1) {
215 - $newlyCreatedEmail = acym_getVar('int', 'newEmailId');
216 - if (!empty($newlyCreatedEmail)) {
217 - $numberOfSubscribers = $followupClass->getNumberSubscribersByListId($followup->list_id, true);
218 - if (!empty($numberOfSubscribers)) {
219 - $message = '<span class="acym__followup__add_queue" data-acym-email-id="'.intval($newlyCreatedEmail).'">';
220 - $message .= acym_translationSprintf('ACYM_FOLLOWUP_ADD_QUEUE', $numberOfSubscribers);
221 - $message .= '</span>';
222 - acym_enqueueMessage($message, 'info', false);
223 - }
224 - }
225 - }
226 -
227 - parent::display($data);
228 - }
229 -
230 - public function followupDuplicateMail(): void
231 - {
232 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
233 -
234 - $mailId = acym_getVar('int', 'action_mail_id', 0);
235 - $id = acym_getVar('int', 'id', 0);
236 - $followupClass = new FollowupClass();
237 - if (!$followupClass->duplicateMail($mailId, $id)) {
238 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_DUPLICATE_MAIL'), 'error');
239 - }
240 -
241 - $this->followupEmail();
242 - }
243 -
244 - public function followupDeleteMail(): void
245 - {
246 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
247 -
248 - $mailId = acym_getVar('int', 'action_mail_id', 0);
249 - $followupClass = new FollowupClass();
250 - if (!$followupClass->deleteMail($mailId)) {
251 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_DELETE_MAIL'), 'error');
252 - }
253 -
254 - $step = acym_getVar('cmd', 'step', 'followupEmail');
255 - if (!in_array($step, ['followupEmail', 'followupSummary'], true)) {
256 - $step = 'followupEmail';
257 - }
258 - $this->$step();
259 - }
260 -
261 - public function followupDraft(): void
262 - {
263 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
264 -
265 - $this->followupFinalize(0);
266 - }
267 -
268 - public function followupActivate(): void
269 - {
270 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
271 -
272 - $this->followupFinalize(1);
273 - }
274 -
275 - public function followupFinalize(int $status): void
276 - {
277 - $followupId = acym_getVar('int', 'id', 0);
278 - $followupClass = new FollowupClass();
279 - $followup = $followupClass->getOneById($followupId);
280 - $followup->active = $status;
281 - $followupClass->save($followup);
282 -
283 - $this->followup();
284 - }
285 -
286 - public function saveFollowupCondition(): void
287 - {
288 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
289 -
290 - if (!acym_isAdmin() || !acym_isAllowed('campaigns')) {
291 - die('Access denied for follow-ups');
292 - }
293 -
294 - $id = acym_getVar('int', 'id', 0);
295 - $trigger = acym_getVar('string', 'trigger', '');
296 - $followupData = acym_getVar('array', 'followup', []);
297 -
298 - $followupClass = new FollowupClass();
299 -
300 - if (!empty($id)) {
301 - $followup = $followupClass->getOneById($id);
302 - $followup->condition = json_encode($followupData['condition']);
303 - } else {
304 - $followup = new stdClass();
305 - $followup->name = '';
306 - $followup->display_name = '';
307 - $followup->creation_date = gmdate('Y-m-d H:i:s', time());
308 - $followup->trigger = $trigger;
309 - $followup->condition = json_encode($followupData['condition']);
310 - $followup->active = 0;
311 - $followup->send_once = 1;
312 - }
313 -
314 - $followup->id = $followupClass->save($followup);
315 - if (empty($followup->id)) {
316 - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING').': '.acym_getDBError(), 'error');
317 - $this->listing();
318 -
319 - return;
320 - }
321 -
322 - acym_setVar('id', $followup->id);
323 -
324 - $this->edit();
325 - }
326 -
327 - public function saveFollowupEmail(bool $redirect = true): void
328 - {
329 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
330 -
331 - if (!acym_isAdmin() || !acym_isAllowed('campaigns')) {
332 - die('Access denied for follow-ups');
333 - }
334 -
335 - $id = acym_getVar('int', 'id', 0);
336 - $followupData = acym_getVar('array', 'followup', []);
337 - if (empty($id) || empty($followupData)) {
338 - return;
339 - }
340 -
341 - $followupClass = new FollowupClass();
342 - $followup = $followupClass->getOneById($id);
343 -
344 - if (empty($followup)) {
345 - return;
346 - }
347 -
348 - foreach ($followupData as $key => $data) {
349 - if (!isset($followup->$key)) continue;
350 - $followup->$key = $data;
351 - }
352 -
353 - $followup->id = $followupClass->save($followup);
354 - acym_setVar('id', $followup->id);
355 -
356 - if ($redirect) {
357 - $this->edit();
358 - }
359 - }
360 -
361 - public function followupSummary(): void
362 - {
363 - acym_setVar('layout', 'followup_summary');
364 -
365 - $id = acym_getVar('int', 'id', 0);
366 -
367 - if (empty($id)) {
368 - acym_enqueueMessage(acym_translation('ACYM_FOLLOWUP_NOT_FOUND'), 'error');
369 - $this->listing();
370 -
371 - return;
372 - }
373 -
374 - $followupClass = new FollowupClass();
375 - $followup = $followupClass->getOneByIdWithMails($id);
376 -
377 - $data = [
378 - 'workflowHelper' => new WorkflowHelper(),
379 - 'followup' => $followup,
380 - 'condition' => $followupClass->getConditionSummary($followup),
381 - ];
382 -
383 - $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
384 - 'campaigns&task=edit&step=followupCondition'.$followup->id
385 - );
386 -
387 - parent::display($data);
388 - }
389 -
390 - public function createNewFollowupMail(): void
391 - {
392 - $this->saveFollowupEmail(false);
393 - $linkNewEmail = acym_getVar('string', 'linkNewEmail', '');
394 -
395 - if (empty($linkNewEmail)) {
396 - $this->edit();
397 - } else {
398 - acym_redirect($linkNewEmail);
399 - }
400 - }
401 -}