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/dynamics/forward/ForwardMailboxAction.php +0 -292 10.2.2 → 11.1.1 View file →
@@ -1,292 +1,0 @@
1 -<?php
2 -
3 -use AcyMailing\Classes\CampaignClass;
4 -use AcyMailing\Classes\ListClass;
5 -use AcyMailing\Classes\MailClass;
6 -use AcyMailing\Helpers\MailerHelper;
7 -
8 -trait ForwardMailboxAction
9 -{
10 - public function onAcymMailboxActionDefine(&$actions)
11 - {
12 - $listClass = new ListClass();
13 - $lists = $listClass->getAllWithIdName();
14 -
15 - $mailClass = new MailClass();
16 - $templates = $mailClass->getTemplatesForMailboxAction();
17 -
18 - $firstOption = new stdClass();
19 - $firstOption->id = 0;
20 - $firstOption->name = acym_translation('ACYM_CHOOSE_TEMPLATE');
21 - array_unshift($templates, $firstOption);
22 -
23 - $actions['forward_specific'] = new stdClass();
24 - $actions['forward_specific']->name = acym_translation('ACYM_FORWARD_EMAIL');
25 - $actions['forward_specific']->option = '<input type="text"
26 - name="acym_action[__num__][forward_specific][addresses]"
27 - placeholder="[email protected],[email protected]"><br />';
28 - $actions['forward_specific']->option .= acym_translationSprintf(
29 - 'ACYM_INCLUDE_IN_TEMPLATE',
30 - '<div class="intext_select_mailbox cell">'.acym_select(
31 - $templates,
32 - 'acym_action[__num__][forward_specific][template_id]',
33 - null,
34 - ['class' => 'acym__select'],
35 - 'id',
36 - 'name'
37 - ).'</div>'
38 - );
39 - $actions['forward_specific']->option .= acym_info('ACYM_INCLUDE_IN_TEMPLATE_DESC');
40 -
41 - $actions['forward_list'] = new stdClass();
42 - $actions['forward_list']->name = acym_translation('ACYM_FORWARD_TO_A_LIST');
43 - $actions['forward_list']->option = '<div class="intext_select_mailbox cell">';
44 - $actions['forward_list']->option .= acym_select(
45 - $lists,
46 - 'acym_action[__num__][forward_list][list_id]',
47 - null,
48 - ['class' => 'acym__select']
49 - );
50 - $actions['forward_list']->option .= '</div><br /><br />';
51 - $actions['forward_list']->option .= acym_translationSprintf(
52 - 'ACYM_INCLUDE_IN_TEMPLATE',
53 - '<div class="intext_select_mailbox cell">'.acym_select(
54 - $templates,
55 - 'acym_action[__num__][forward_list][template_id]',
56 - null,
57 - ['class' => 'acym__select'],
58 - 'id',
59 - 'name'
60 - ).'</div>'
61 - );
62 - $actions['forward_list']->option .= acym_info('ACYM_INCLUDE_IN_TEMPLATE_DESC');
63 - }
64 -
65 - public function onAcymMailboxActionSummaryListing(&$action, &$result)
66 - {
67 - if (!empty($action['forward_list'])) {
68 - $listClass = new ListClass();
69 - $list = $listClass->getOneById($action['forward_list']['list_id']);
70 -
71 - if (empty($list)) {
72 - return;
73 - }
74 -
75 - $result[] = acym_translationSprintf('ACYM_FORWARD_TO_A_LIST_X', $list->name);
76 - }
77 -
78 - if (!empty($action['forward_specific'])) {
79 - $result[] = acym_translationSprintf('ACYM_FORWARD_EMAIL_X', $action['forward_specific']['addresses']);
80 - }
81 - }
82 -
83 - public function onAcymMailboxAction_forward_specific(&$action, &$report, &$executedActions, $mailboxHelper)
84 - {
85 - $newMail = $this->prepareForward($action, $report, $executedActions, $mailboxHelper);
86 -
87 - if (empty($newMail)) {
88 - $report[] = [
89 - 'message' => acym_translation('ACYM_COULD_NOT_FORWARD_EMAIL'),
90 - 'success' => false,
91 - ];
92 -
93 - return;
94 - }
95 -
96 - $newMail->id = $this->saveNewMail($newMail);
97 -
98 - if (empty($newMail->id)) {
99 - return;
100 - }
101 -
102 - $receivers = explode(',', $action['addresses']);
103 - $mailerHelper = new MailerHelper();
104 - $mailerHelper->autoAddUser = true;
105 - $mailerHelper->isForward = true;
106 - $mailInfo = $newMail->subject.' ('.$newMail->id.')';
107 - foreach ($receivers as $oneReceiver) {
108 - if ($mailerHelper->sendOne($newMail->id, $oneReceiver)) {
109 - $report[] = [
110 - 'message' => acym_translationSprintf('ACYM_SEND_SUCCESS', $mailInfo, acym_escape($oneReceiver)),
111 - 'success' => true,
112 - ];
113 - } else {
114 - $report[] = [
115 - 'message' => acym_translationSprintf('ACYM_SEND_ERROR', $mailInfo, acym_escape($oneReceiver)),
116 - 'success' => false,
117 - ];
118 - }
119 - }
120 -
121 - $mailClass = new MailClass();
122 - $mailClass->delete($newMail->id);
123 - }
124 -
125 - public function onAcymMailboxAction_forward_list(&$action, &$report, &$executedActions, $mailboxHelper)
126 - {
127 - $newMail = $this->prepareForward($action, $report, $executedActions, $mailboxHelper);
128 -
129 - if (empty($newMail)) {
130 - $report[] = [
131 - 'message' => acym_translation('ACYM_COULD_NOT_FORWARD_EMAIL'),
132 - 'success' => false,
133 - ];
134 -
135 - return;
136 - }
137 -
138 - if (!empty($mailboxHelper->_message->fromaddress)) {
139 - $newMail->body = str_replace('{mailheader:from}', htmlspecialchars($mailboxHelper->_message->fromaddress, ENT_QUOTES, 'UTF-8'), $newMail->body);
140 - }
141 - if (!empty($mailboxHelper->_message->toaddress)) {
142 - $newMail->body = str_replace('{mailheader:to}', htmlspecialchars($mailboxHelper->_message->toaddress, ENT_QUOTES, 'UTF-8'), $newMail->body);
143 - }
144 -
145 - if (!empty($mailboxHelper->_message->ccaddress)) {
146 - $newMail->body = str_replace('{mailheader:cc}', htmlspecialchars($mailboxHelper->_message->ccaddress, ENT_QUOTES, 'UTF-8'), $newMail->body);
147 - }
148 -
149 - if (!empty($mailboxHelper->_message->Date)) {
150 - $newMail->body = str_replace('{mailheader:date}', date('d.m.Y H:i', strtotime($mailboxHelper->_message->Date)), $newMail->body);
151 - }
152 -
153 - $newMail->body = str_replace(
154 - [
155 - '{mailheader:from}',
156 - '{mailheader:to}',
157 - '{mailheader:cc}',
158 - '{mailheader:date}',
159 - ],
160 - '',
161 - $newMail->body
162 - );
163 -
164 - $newMail->id = $this->saveNewMail($newMail);
165 -
166 - if (!$newMail->id) {
167 - return;
168 - }
169 -
170 - $newCampaign = new stdClass();
171 - $newCampaign->mail_id = $newMail->id;
172 - $newCampaign->sending_date = acym_date('now', 'Y-m-d H:i:s', false);
173 - $newCampaign->sending_type = CampaignClass::SENDING_TYPE_NOW;
174 -
175 - $campaignClass = new CampaignClass();
176 - $newCampaign->id = $campaignClass->save($newCampaign);
177 -
178 - if (empty($newCampaign->id)) {
179 - $report[] = [
180 - 'message' => acym_translation('ACYM_COULD_NOT_CREATE_CAMPAIGN'),
181 - 'success' => false,
182 - ];
183 -
184 - return;
185 - }
186 -
187 - $listAssigned = $campaignClass->manageListsToCampaign([$action['list_id']], $newMail->id);
188 -
189 - if (!$listAssigned) {
190 - $report[] = [
191 - 'message' => acym_translation('ACYM_COULD_NOT_ASSIGN_LIST'),
192 - 'success' => false,
193 - ];
194 -
195 - return;
196 - }
197 -
198 - $statusSent = $campaignClass->send($newCampaign->id);
199 -
200 - if (!$statusSent) {
201 - $report[] = [
202 - 'message' => acym_translation('ACYM_COULD_NOT_SEND_CAMPAIGN'),
203 - 'success' => false,
204 - ];
205 - } else {
206 - $report[] = [
207 - 'message' => acym_translation('ACYM_CAMPAIGN_ADDED_QUEUE'),
208 - 'success' => true,
209 - ];
210 - }
211 - }
212 -
213 - private function prepareForward($action, &$report, &$executedActions, $mailboxHelper)
214 - {
215 - if (!isset($action['template_id'])) {
216 - $executedActions = false;
217 - $report[] = [
218 - 'message' => acym_translation('ACYM_COULD_NOT_FIND_TEMPLATE'),
219 - 'success' => false,
220 - ];
221 -
222 - return false;
223 - }
224 -
225 - $mailboxHelper->decodeMessage(true);
226 -
227 - $subject = $mailboxHelper->_message->subject;
228 -
229 - if (!empty($mailboxHelper->action->conditions['subject_remove'])) {
230 - if (!empty($mailboxHelper->action->conditions['subject_text'])) {
231 - $subject = str_replace($mailboxHelper->action->conditions['subject_text'], '', $mailboxHelper->_message->subject);
232 - } elseif (!empty($mailboxHelper->action->conditions['subject_regex'])) {
233 - $subject = preg_replace($mailboxHelper->action->conditions['subject_regex'], '', $mailboxHelper->_message->subject);
234 - }
235 - }
236 -
237 - $newMail = new stdClass();
238 - if (empty($action['template_id'])) {
239 - $newMail->name = acym_translationSprintf('ACYM_FORWARD_SUBJECT', $subject);
240 - $newMail->body = empty($mailboxHelper->_message->html) ? $mailboxHelper->_message->text : $mailboxHelper->_message->html;
241 - } else {
242 - $mailClass = new MailClass();
243 - $newMail = $mailClass->getOneById($action['template_id']);
244 -
245 - if (strpos($newMail->body, '{emailcontent}') === false) {
246 - $executedActions = false;
247 - $report[] = [
248 - 'message' => acym_translation('ACYM_TEMPLATE_DOES_NOT_CONTAIN_EMAILCONTENT'),
249 - 'success' => false,
250 - ];
251 -
252 - return false;
253 - } else {
254 - $content = empty($mailboxHelper->_message->html) ? $mailboxHelper->_message->text : $mailboxHelper->_message->html;
255 - $newMail->body = str_replace('{emailcontent}', $content, $newMail->body);
256 - }
257 - unset($newMail->id);
258 - }
259 -
260 - $newMail->subject = $subject;
261 - $newMail->type = mailClass::TYPE_MAILBOX_ACTION;
262 - $newMail->creation_date = acym_date('now', 'Y-m-d H:i:s', false);
263 -
264 - if (!empty($mailboxHelper->action->senderfrom)) {
265 - $newMail->from_email = $mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_email);
266 - $newMail->from_name = strip_tags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name));
267 - }
268 -
269 - if (!empty($mailboxHelper->action->senderto)) {
270 - $newMail->reply_to_email = $mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_email);
271 - $newMail->reply_to_name = strip_tags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name));
272 - }
273 -
274 - if (!empty($mailboxHelper->attachments)) {
275 - $newMail->attachments = $mailboxHelper->getAttachments();
276 - }
277 -
278 - return $newMail;
279 - }
280 -
281 - public function saveNewMail($newMail)
282 - {
283 - $mailClass = new MailClass();
284 - $newMail->id = $mailClass->save($newMail);
285 -
286 - if (empty($newMail->id)) {
287 - return false;
288 - }
289 -
290 - return $newMail->id;
291 - }
292 -}