PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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
acymailing / back / Controllers / CampaignsController.php

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

252 lines 8.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 cancelDashboardAndGetCampaignsAjax()
84 {
85 $campaignId = acym_getVar('int', 'campaignId');
86 $campaignClass = new CampaignClass();
87
88 if (empty($campaignId)) {
89 acym_sendAjaxResponse(acym_translation('ACYM_CAMPAIGN_NOT_FOUND'), [], false);
90 }
91
92 $campaign = new \stdClass();
93 $campaign->id = $campaignId;
94 $campaign->active = 0;
95 $campaign->draft = 1;
96
97 $campaignId = $campaignClass->save($campaign);
98 if (empty($campaignId)) {
99 acym_sendAjaxResponse(acym_translation('ACYM_CAMPAIGN_CANT_BE_SAVED'), [], false);
100 }
101
102 $campaigns = $campaignClass->getCampaignForDashboard();
103
104 if (empty($campaigns)) {
105 $result = '<h1 class="acym__dashboard__active-campaigns__none">'.acym_translation('ACYM_NONE_OF_YOUR_CAMPAIGN_SCHEDULED_GO_SCHEDULE_ONE').'</h1>';
106 acym_sendAjaxResponse('', ['content' => $result]);
107 }
108
109 $result = '';
110
111 foreach ($campaigns as $campaign) {
112 $result .= '<div class="cell grid-x acym__dashboard__active-campaigns__one-campaign">
113 <a class="acym__dashboard__active-campaigns__one-campaign__title medium-4 small-12" href="'.acym_completeLink(
114 'campaigns&task=edit&step=editEmail&id='
115 ).$campaign->id.'">'.$campaign->name.'</a>
116 <div class="acym__dashboard__active-campaigns__one-campaign__state medium-2 small-12 acym__background-color__blue text-center"><span>'.acym_translation(
117 'ACYM_SCHEDULED'
118 ).' : '.acym_getDate($campaign->sending_date, 'ACYM_DATE_FORMAT_LC3').'</span></div>
119 <div class="medium-6 small-12"><p id="'.$campaign->id.'" class="acym__dashboard__active-campaigns__one-campaign__action acym__color__dark-gray">'.acym_translation(
120 'ACYM_CANCEL_SCHEDULING'
121 ).'</p></div>
122 </div>
123 <hr class="cell small-12">';
124 }
125
126 acym_sendAjaxResponse('', ['content' => $result]);
127 }
128
129 public function ajaxCountNumberOfRecipients(): void
130 {
131 $listsSelected = acym_getVar('array', 'listsSelected', []);
132 if (empty($listsSelected)) {
133 acym_sendAjaxResponse('', ['recipients' => 0]);
134 }
135
136 $listClass = new ListClass();
137 acym_sendAjaxResponse('', ['recipients' => $listClass->getTotalSubCount($listsSelected)]);
138 }
139
140 public function deleteAttachmentAjax()
141 {
142 $mailId = acym_getVar('int', 'mail', 0);
143 $attachmentId = acym_getVar('int', 'id', 0);
144
145 if (!empty($mailId) && $attachmentId >= 0) {
146 $mailClass = new MailClass();
147
148 if (!$mailClass->hasUserAccess($mailId)) {
149 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false);
150 }
151
152 if ($mailClass->deleteOneAttachment($mailId, $attachmentId)) {
153 acym_sendAjaxResponse(acym_translation('ACYM_ATTACHMENT_WELL_DELETED'));
154 }
155 }
156
157 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false);
158 }
159
160 public function test()
161 {
162 $campaignId = acym_getVar('int', 'campaignId', 0);
163
164 $campaignClass = new CampaignClass();
165 $campaign = $campaignClass->getOneById($campaignId);
166
167 if (empty($campaign)) {
168 acym_sendAjaxResponse(acym_translation('ACYM_CAMPAIGN_NOT_FOUND'), [], false);
169 }
170
171 $mailerHelper = new MailerHelper();
172 $mailerHelper->autoAddUser = true;
173 $mailerHelper->report = false;
174
175 $report = [];
176 $success = true;
177 $testNote = acym_getVar('string', 'test_note', '');
178
179 $userClass = new UserClass();
180 $mailClass = new mailClass();
181 $translatedMails = [];
182 if (acym_isMultilingual()) {
183 $translatedMails = $mailClass->getTranslationsById($campaign->mail_id, true, true);
184 }
185 $testEmails = explode(',', acym_getVar('string', 'test_emails'));
186 foreach ($testEmails as $oneAddress) {
187 if (acym_isMultilingual()) {
188 $user = $userClass->getOneById($oneAddress);
189 if (empty($user)) {
190 $user = $userClass->getOneByEmail($oneAddress);
191 }
192 if (empty($user)) {
193 $mailId = $campaign->mail_id;
194 } else {
195 $mailId = empty($translatedMails[$user->language]) ? $campaign->mail_id : $translatedMails[$user->language]->id;
196 }
197 } else {
198 $mailId = $campaign->mail_id;
199 }
200
201 $options = [
202 'isTest' => true,
203 'testNote' => $testNote,
204 ];
205 if (!$mailerHelper->sendOne($mailId, $oneAddress, $options)) {
206 $success = false;
207 }
208
209 if (!empty($mailerHelper->reportMessage)) {
210 $report[] = $mailerHelper->reportMessage;
211 }
212 }
213
214 acym_sendAjaxResponse(implode('<br/>', $report), [], $success);
215 }
216
217 public function saveAjax()
218 {
219 $result = $this->saveEditEmail(true);
220 if ($result) {
221 acym_sendAjaxResponse('', ['result' => $result]);
222 } else {
223 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
224 }
225 }
226
227 public function saveAsTmplAjax()
228 {
229 if (!acym_isAdmin()) {
230 die('Access denied');
231 }
232
233 $mailController = new MailsController();
234 $isWellSaved = $mailController->store(true);
235 acym_sendAjaxResponse($isWellSaved ? '' : acym_translation('ACYM_ERROR_SAVING'), ['result' => $isWellSaved], $isWellSaved);
236 }
237
238 public function searchTestReceiversAjax()
239 {
240 $search = acym_getVar('string', 'search', '');
241 $userClass = new UserClass();
242 $users = $userClass->getUsersLikeEmail($search);
243
244 $return = [];
245 foreach ($users as $oneUser) {
246 $return[] = [$oneUser->id, $oneUser->email];
247 }
248 echo json_encode($return);
249 exit;
250 }
251 }
252