PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.3
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.3
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 / CampaignsController.php

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

229 lines 7.7 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;
4
5 use AcyMailing\Classes\CampaignClass;
6 use AcyMailing\Classes\HistoryClass;
7 use AcyMailing\Classes\MailClass;
8 use AcyMailing\Classes\ListClass;
9 use AcyMailing\Classes\UserClass;
10 use AcyMailing\Helpers\MailerHelper;
11 use AcyMailing\Core\AcymController;
12 use AcyMailing\Controllers\Campaigns\Actions;
13 use AcyMailing\Controllers\Campaigns\AutoCampaigns;
14 use AcyMailing\Controllers\Campaigns\Edition;
15 use AcyMailing\Controllers\Campaigns\Followup;
16 use AcyMailing\Controllers\Campaigns\ListEmails;
17 use AcyMailing\Controllers\Campaigns\Listing;
18 use AcyMailing\Controllers\Campaigns\Tests;
19
20 class CampaignsController extends AcymController
21 {
22 use Listing;
23 use Followup;
24 use ListEmails;
25 use AutoCampaigns;
26 use Edition;
27 use Actions;
28 use Tests;
29
30 const TASK_TYPE_CAMPAIGN = 'campaigns';
31 const TASK_TYPE_CAMPAIGN_AUTO = 'campaigns_auto';
32 const TASK_TYPE_WELCOME = 'welcome';
33 const TASK_TYPE_UNSUBSCRIBE = 'unsubscribe';
34 const TASK_TYPE_FOLLOWUP = 'followup';
35 const TASK_TYPE_SPECIFIC_LISTING = 'specificListing';
36 const TASK_TYPE_MAILBOX_ACTION = 'mailbox_action';
37
38 const TASKS_TO_REMEMBER_FOR_LISTING = [
39 '',
40 self::TASK_TYPE_CAMPAIGN,
41 self::TASK_TYPE_CAMPAIGN_AUTO,
42 self::TASK_TYPE_WELCOME,
43 self::TASK_TYPE_UNSUBSCRIBE,
44 self::TASK_TYPE_FOLLOWUP,
45 self::TASK_TYPE_SPECIFIC_LISTING,
46 self::TASK_TYPE_MAILBOX_ACTION,
47 ];
48
49 const CAMPAIGN_TYPE_TO_TASK = [
50 'now' => self::TASK_TYPE_CAMPAIGN,
51 'scheduled' => self::TASK_TYPE_CAMPAIGN,
52 'auto' => self::TASK_TYPE_CAMPAIGN_AUTO,
53 'followup' => self::TASK_TYPE_FOLLOWUP,
54 'welcome' => self::TASK_TYPE_WELCOME,
55 'unsubscribe' => self::TASK_TYPE_UNSUBSCRIBE,
56 'birthday' => self::TASK_TYPE_SPECIFIC_LISTING,
57 'woocommerce_cart' => self::TASK_TYPE_SPECIFIC_LISTING,
58 ];
59
60 private string $stepContainerClass = '';
61
62 public function __construct()
63 {
64 parent::__construct();
65
66 $this->defaulttask = 'campaigns';
67 $this->breadcrumb[acym_translation('ACYM_EMAILS')] = acym_completeLink('campaigns');
68 $this->loadScripts = [
69 'recipients' => ['vue-applications' => ['entity_select']],
70 'segment' => ['datepicker', 'vue-applications' => ['modal_users_summary']],
71 'send_settings' => ['datepicker'],
72 'summary' => ['vue-applications' => ['modal_users_summary']],
73 ];
74
75 if (acym_isAdmin()) {
76 $this->stepContainerClass = 'xxlarge-9';
77 }
78
79 acym_setVar('edition', '1');
80 acym_header('X-XSS-Protection:0');
81 $this->storeRedirectListing();
82 }
83
84 public function ajaxCountNumberOfRecipients(): void
85 {
86 $listsSelected = acym_getVar('array', 'listsSelected', []);
87 if (empty($listsSelected)) {
88 acym_sendAjaxResponse('', ['recipients' => 0]);
89 }
90
91 $listClass = new ListClass();
92 acym_sendAjaxResponse('', ['recipients' => $listClass->getTotalSubCount($listsSelected)]);
93 }
94
95 public function deleteAttachmentAjax(): void
96 {
97 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
98
99 $mailId = acym_getVar('int', 'mail', 0);
100 $attachmentId = acym_getVar('int', 'id', 0);
101
102 if (!empty($mailId) && $attachmentId >= 0) {
103 $mailClass = new MailClass();
104
105 if (!$mailClass->hasUserAccess($mailId, true)) {
106 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false);
107 }
108
109 if ($mailClass->deleteOneAttachment($mailId, $attachmentId)) {
110 acym_sendAjaxResponse(acym_translation('ACYM_ATTACHMENT_WELL_DELETED'));
111 }
112 }
113
114 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false);
115 }
116
117 public function test(): void
118 {
119 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
120
121 $campaignId = acym_getVar('int', 'campaignId', 0);
122 $specificMailId = acym_getVar('int', 'mailId', 0);
123
124 $campaignClass = new CampaignClass();
125 $campaign = $campaignClass->getOneById($campaignId);
126
127 if (empty($campaign)) {
128 acym_sendAjaxResponse(acym_translation('ACYM_CAMPAIGN_NOT_FOUND'), [], false);
129 }
130
131 if (!$campaignClass->hasUserAccess($campaignId)) {
132 acym_sendAjaxResponse(acym_translation('ACYM_ACCESS_DENIED'), [], false);
133 }
134
135 $mailClassAccess = new MailClass();
136 if (!empty($specificMailId) && $mailClassAccess->getMainMailId($specificMailId) !== (int)$campaign->mail_id) {
137 acym_sendAjaxResponse(acym_translation('ACYM_ACCESS_DENIED'), [], false);
138 }
139
140 $mailerHelper = new MailerHelper();
141 $mailerHelper->report = false;
142 if (!empty($specificMailId)) {
143 $mailerHelper->isAbTest = $campaignClass->isAbTestMail($specificMailId);
144 }
145
146 $report = [];
147 $success = true;
148 $testNote = acym_getVar('string', 'test_note', '');
149
150 $userClass = new UserClass();
151 $mailClass = new mailClass();
152 $translatedMails = [];
153 if (acym_isMultilingual()) {
154 $translatedMails = $mailClass->getTranslationsById($campaign->mail_id, true, true);
155 }
156
157 $rawTestEmails = explode(',', acym_getVar('string', 'test_emails'));
158 $testEmails = [];
159 foreach ($rawTestEmails as $email) {
160 $email = trim($email);
161 if (acym_isValidEmail($email) || is_numeric($email)) {
162 $testEmails[] = $email;
163 }
164 }
165
166 if (empty($testEmails)) {
167 acym_sendAjaxResponse(acym_translation('ACYM_NO_VALID_TEST_EMAILS'), [], false);
168
169 return;
170 }
171
172 $historyClass = new HistoryClass();
173
174 foreach ($testEmails as $oneAddress) {
175 if (is_numeric($oneAddress)) {
176 $receiver = $userClass->getOneById($oneAddress);
177 } else {
178 $receiver = $userClass->getOneByEmail($oneAddress, true);
179 }
180
181 $mailId = $specificMailId;
182 if (empty($mailId)) {
183 if (acym_isMultilingual()) {
184 $mailId = empty($receiver) || empty($translatedMails[$receiver->language]) ? $campaign->mail_id : $translatedMails[$receiver->language]->id;
185 } else {
186 $mailId = $campaign->mail_id;
187 }
188 }
189
190 $options = [
191 'isTest' => true,
192 'testNote' => $testNote,
193 ];
194 if ($mailerHelper->sendOne($mailId, $receiver, $options)) {
195 $historyClass->insert($receiver->id, 'test_sent', [], $mailId);
196 } else {
197 $success = false;
198 }
199
200 if (!empty($mailerHelper->reportMessage)) {
201 $report[] = $mailerHelper->reportMessage;
202 }
203 }
204
205 acym_sendAjaxResponse(implode('<br/>', $report), [], $success);
206 }
207
208 public function saveAjax(): void
209 {
210 $result = $this->saveEditEmail(true);
211 if (!empty($result)) {
212 acym_sendAjaxResponse('', ['result' => $result]);
213 } else {
214 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
215 }
216 }
217
218 public function saveAsTmplAjax(): void
219 {
220 if (!acym_isAdmin() || (!acym_isAllowed('campaigns') && !acym_isAllowed('mails'))) {
221 die('Access denied');
222 }
223
224 $mailController = new MailsController();
225 $mailId = $mailController->store(true);
226 acym_sendAjaxResponse(!empty($mailId) ? '' : acym_translation('ACYM_ERROR_SAVING'), ['result' => $mailId], !empty($mailId));
227 }
228 }
229