PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.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 10.3.0 10.4.0 All 60 releases
acymailing / back / Controllers / CampaignsController.php

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

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