PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.4
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.4
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Hooks / Handlers / EmailNotificationHandler.php

EmailNotificationHandler.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.4, at app/Hooks/Handlers/EmailNotificationHandler.php

295 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Hooks\Handlers;
4
5 use FluentSupport\App\App;
6 use FluentSupport\App\Services\EmailNotification\Settings;
7 use FluentSupport\App\Services\Emogrifier;
8 use FluentSupport\App\Services\Helper;
9 use FluentSupport\App\Services\Mailer;
10 use FluentSupport\Framework\Support\Arr;
11
12 class EmailNotificationHandler
13 {
14 public function ticketCreated($ticket, $customer)
15 {
16 $mailbox = $ticket->mailbox;
17
18 if (!$mailbox) {
19 return;
20 }
21
22 // Let's send welcome email to customer if enabled
23 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_created_email_to_customer');
24 if ($emailSettings && $emailSettings['status'] == 'yes') {
25 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
26 'customer' => $customer,
27 'business' => $mailbox,
28 'ticket' => $ticket
29 ]);
30
31 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
32 'customer' => $customer,
33 'business' => $mailbox,
34 'ticket' => $ticket,
35 'email_type' => 'ticket_created_email_to_customer'
36 ]);
37
38 $headers = $mailbox->getMailerHeader();
39 if ($ticket->message_id) {
40 // $headers[] = 'Message-ID: ' . $ticket->message_id;
41 }
42 Mailer::send($customer->email, $subject, $emailBody, $headers);
43 }
44
45 // let's send email to admin if enabled
46 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_created_email_to_admin');
47 if ($emailSettings && $emailSettings['status'] == 'yes' && is_email($mailbox->settings['admin_email_address'])) {
48
49 $mailTo = Arr::get($mailbox->settings, 'admin_email_address');
50 if(!$mailTo || !is_email($mailTo)) {
51 return;
52 }
53
54 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
55 'customer' => $customer,
56 'business' => $mailbox,
57 'ticket' => $ticket
58 ]);
59
60 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
61 'customer' => $customer,
62 'business' => $mailbox,
63 'ticket' => $ticket,
64 'email_type' => 'ticket_created_email_to_admin'
65 ]);
66
67 $headers = $mailbox->getMailerHeader();
68 if ($ticket->message_id) {
69 // $headers[] = 'Message-ID: ' . $ticket->message_id;
70 }
71 Mailer::send($mailTo, $subject, $emailBody, $headers);
72 }
73
74 }
75
76 public function agentReplied($response, $ticket, $agent)
77 {
78 $mailbox = $ticket->mailbox;
79
80
81 if (!$mailbox) {
82 return false;
83 }
84
85 // Let's send welcome email to customer if enabled
86 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_replied_by_agent_email_to_customer');
87
88
89 if ($emailSettings && $emailSettings['status'] == 'yes') {
90
91 $ticket->load('customer');
92 $customer = $ticket->customer;
93
94 if($customer->status == 'inactive') {
95 return false;
96 }
97
98 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
99 'customer' => $customer,
100 'business' => $mailbox,
101 'ticket' => $ticket,
102 'response' => $response,
103 'agent' => $agent
104 ]);
105
106 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
107 'customer' => $customer,
108 'business' => $mailbox,
109 'ticket' => $ticket,
110 'response' => $response,
111 'agent' => $agent,
112 'email_type' => 'ticket_replied_by_agent_email_to_customer'
113 ]);
114
115
116 $headers = $mailbox->getMailerHeader();
117
118 Mailer::send($customer->email, $subject, $emailBody, $headers);
119 }
120 }
121
122 public function closedByAgent($ticket, $agent)
123 {
124 $mailbox = $ticket->mailbox;
125 if (!$mailbox) {
126 return;
127 }
128
129 // Let's send welcome email to customer if enabled
130 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_closed_by_agent_email_to_customer');
131 if ($emailSettings && $emailSettings['status'] == 'yes') {
132
133 $ticket->load('customer');
134 $customer = $ticket->customer;
135
136 if($customer->status == 'inactive') {
137 return false;
138 }
139
140
141 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
142 'customer' => $customer,
143 'business' => $mailbox,
144 'ticket' => $ticket,
145 'agent' => $agent,
146 ]);
147
148 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
149 'customer' => $customer,
150 'business' => $mailbox,
151 'ticket' => $ticket,
152 'agent' => $agent,
153 'email_type' => 'ticket_closed_by_agent_email_to_customer'
154 ]);
155
156 $headers = $mailbox->getMailerHeader();
157 if ($ticket->message_id) {
158 // $headers[] = 'Message-ID: ' . $ticket->message_id;
159 }
160 Mailer::send($customer->email, $subject, $emailBody, $headers);
161 }
162 }
163
164 public function customerReplied($response, $ticket, $customer)
165 {
166 $mailbox = $ticket->mailbox;
167 if (!$mailbox) {
168 return;
169 }
170
171 // Let's send welcome email to customer if enabled
172 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_replied_by_customer_email_to_admin');
173 if ($emailSettings && $emailSettings['status'] == 'yes') {
174
175 $ticket->load('agent');
176 $agent = $ticket->agent;
177
178 $emailTo = $mailbox->settings['admin_email_address'];
179 if($agent) {
180 $emailTo = $agent->email;
181 }
182
183 if(!$emailTo || !is_email($emailTo)) {
184 return;
185 }
186
187 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
188 'customer' => $customer,
189 'business' => $mailbox,
190 'ticket' => $ticket,
191 'response' => $response,
192 'agent' => $agent
193 ]);
194
195 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
196 'customer' => $customer,
197 'business' => $mailbox,
198 'ticket' => $ticket,
199 'response' => $response,
200 'agent' => $agent,
201 'email_type' => 'ticket_replied_by_customer_email_to_admin'
202 ]);
203
204 $headers = $mailbox->getMailerHeader();
205 if ($ticket->message_id) {
206 // $headers[] = 'Message-ID: ' . $ticket->message_id;
207 }
208
209 Mailer::send($emailTo, $subject, $emailBody, $headers);
210 }
211 }
212
213 public function onAgentAssign($agent, $ticket)
214 {
215 $currentUser = Helper::getAgentByUserId();
216
217 if (!is_null($currentUser) && $currentUser->user_id == $agent->user_id){
218 return;
219 }
220
221 $mailbox = $ticket->mailbox;
222
223 if (!$mailbox) {
224 return;
225 }
226
227 // Let's send welcome email to customer if enabled
228 $emailSettings = (new Settings())->getBoxEmailSettings($mailbox, 'ticket_agent_on_change');
229
230 if ($emailSettings && $emailSettings['status'] == 'yes') {
231
232 if($agent) {
233 $emailTo = $agent->email;
234 }
235
236 if(!$emailTo || !is_email($emailTo)) {
237 return;
238 }
239
240 $subject = apply_filters('fluent_support/parse_smartcode_data', $emailSettings['email_subject'], [
241 'business' => $mailbox,
242 'ticket' => $ticket,
243 'agent' => $agent
244 ]);
245
246 $emailBody = $this->parseEmailBody($emailSettings['email_body'], [
247 'business' => $mailbox,
248 'ticket' => $ticket,
249 'agent' => $agent,
250 'email_type' => 'ticket_agent_on_change'
251 ]);
252
253 $headers = $mailbox->getMailerHeader();
254
255 Mailer::send($emailTo, $subject, $emailBody, $headers);
256 }
257 }
258
259 private function emailTemplateCss()
260 {
261 $app = App::getInstance();
262 return $app->view->make('emails.styles');
263 }
264
265 protected function parseEmailBody($emailBody, $data)
266 {
267 $data['email_body'] = apply_filters('fluent_support/parse_smartcode_data', $emailBody, $data);
268
269 $app = App::getInstance();
270
271 if (isset($data['business'])) {
272 $businessName = $data['business']->name;
273 } else {
274 $businessName = get_bloginfo('name');
275 }
276
277 $footerText = apply_filters('fluent_support/email_footer_credit', 'This email is a service from ' . $businessName . '. Support Plugin is Powered by <a href="https://fluentsupport.com/?utm_source=user&utm_medium=wp&utm_campaign=mail_footer" style="color:#9e9e9e;" target="_new">FluentSupport</a>.');
278
279 $data['email_footer'] = $footerText;
280
281 $emailTypeForCustomerFooter = ['ticket_created_email_to_customer', 'ticket_replied_by_agent_email_to_customer', 'ticket_closed_by_agent_email_to_customer'];
282
283 if (defined('FLUENTSUPPORTPRO') && in_array($data['email_type'], $emailTypeForCustomerFooter)
284 && !is_null($data['business']->email_footer)) {
285 $data['email_footer'] = apply_filters('fluent_support/parse_smartcode_data', $data['business']->email_footer, $data);
286 }
287
288 $emailBody = $app->view->make('emails.ticket_template', $data);
289 $emogrifier = new Emogrifier($emailBody, $this->emailTemplateCss());
290 $emogrifier->disableInvisibleNodeRemoval();
291 return $emogrifier->emogrify();
292 }
293
294 }
295