PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
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 / dynamics / sendinblue / plugin.php

plugin.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at back/dynamics/sendinblue/plugin.php

189 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\MailClass;
4 use AcyMailing\Core\AcymPlugin;
5
6 class plgAcymSendinblue extends AcymPlugin
7 {
8 const SENDING_METHOD_ID = 'sendinblue';
9 const SENDING_METHOD_NAME = 'Brevo';
10 const SENDING_METHOD_API_URL = 'https://api.brevo.com/v3/';
11
12 private SendinblueCredentials $credentials;
13 private SendinblueIntegration $integration;
14 private SendinblueTransactional $transactional;
15 private SendinblueCampaign $campaign;
16 private SendinblueList $list;
17 private SendinblueUsers $users;
18 private SendinblueSender $sender;
19 private SendinblueWebhooks $webhooks;
20
21 public function __construct()
22 {
23 parent::__construct();
24 $this->pluginDescription->name = self::SENDING_METHOD_NAME;
25
26 include_once __DIR__.DS.'sendinblue.php';
27 include_once __DIR__.DS.'credentials.php';
28 include_once __DIR__.DS.'integration.php';
29 include_once __DIR__.DS.'transactional.php';
30 include_once __DIR__.DS.'campaign.php';
31 include_once __DIR__.DS.'list.php';
32 include_once __DIR__.DS.'users.php';
33 include_once __DIR__.DS.'sender.php';
34 include_once __DIR__.DS.'webhooks.php';
35
36 $this->credentials = new SendinblueCredentials($this);
37 $headers = $this->credentials->getHeadersSendingMethod(self::SENDING_METHOD_ID);
38
39 $this->integration = new SendinblueIntegration($this);
40 $this->transactional = new SendinblueTransactional($this, $headers);
41 $this->list = new SendinblueList($this, $headers);
42 $this->users = new SendinblueUsers($this, $headers, $this->list);
43 $this->sender = new SendinblueSender($this, $headers);
44 $this->campaign = new SendinblueCampaign($this, $headers, $this->sender, $this->users, $this->list);
45 $this->webhooks = new SendinblueWebhooks($this, $headers);
46 }
47
48 public function onAcymGetSendingMethods(&$data, $isMailer = false)
49 {
50 if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) return;
51
52 $data['sendingMethods'][self::SENDING_METHOD_ID] = [
53 'name' => $this->pluginDescription->name.' ('.acym_translation('ACYM_DEPRECATED').')',
54 'image' => ACYM_IMAGES.'mailers/brevo.png',
55 'recommended' => false,
56 ];
57 }
58
59 public function onAcymGetSendingMethodsHtmlSetting(&$data)
60 {
61 $this->credentials->getSendingMethodsHtmlSetting($data);
62 }
63
64 public function onAcymTestCredentialSendingMethod($sendingMethod, $credentials)
65 {
66 $this->credentials->testCredentialSendingMethod($sendingMethod, $credentials);
67 }
68
69 public function onAcymSendEmail(&$response, $mailerHelper, $to, $from, $reply_to, $bcc = [], $attachments = [], $sendingMethodListParams = [])
70 {
71 $this->transactional->sendTransactionalEmail(
72 $response,
73 $mailerHelper->externalMailer,
74 $to,
75 $mailerHelper->Subject,
76 $from,
77 $reply_to,
78 $mailerHelper->Body,
79 $bcc,
80 $attachments
81 );
82 }
83
84 public function onAcymGetCreditRemainingSendingMethod(&$html, $reloading = false)
85 {
86 $this->credentials->getCreditRemainingSendingMethod($html);
87 }
88
89 public function onAcymGetSettingsSendingMethodFromPlugin(&$data, $plugin, $method)
90 {
91 $this->integration->getSettingsSendingMethodFromPlugin($data, $plugin, $method);
92 }
93
94 public function onAcymProcessQueueExternalSendingCampaign(&$externalSending, $transactional = false)
95 {
96 if ($this->config->get('mailer_method') == self::SENDING_METHOD_ID && !$transactional) $externalSending = true;
97 }
98
99 public function onAcymInitExternalSendingMethodBeforeSend(&$listId, $mailId)
100 {
101 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return;
102
103 $this->list->getListExternalSendingMethod($listId, $mailId);
104 $this->users->createAttribute($mailId);
105 }
106
107 public function onAcymRegisterReceiverContentAndList(&$result, $subjectContent, $htmlContent, $receiverEmail, $mailId, &$warnings)
108 {
109 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return;
110
111 $result = $this->users->addUserToList($receiverEmail, $mailId, $warnings);
112 if ($result) {
113 // The API returns null every time so we have no clue if this went well
114 $this->users->addAttributeToUser($receiverEmail, $subjectContent, $htmlContent, $mailId);
115 }
116 }
117
118 public function onAcymAfterUserModify($user, &$oldUser)
119 {
120 $this->users->createUser($user);
121 }
122
123 public function onAcymAfterUserCreate($user)
124 {
125 $this->users->createUser($user);
126 }
127
128 public function onAcymUserImport($users)
129 {
130 $this->users->importUsers($users);
131 }
132
133 public function onAcymBeforeUserDelete($users)
134 {
135 $this->users->deleteUsers($users);
136 }
137
138 public function onAcymSendCampaignOnExternalSendingMethod($mailId, $content): bool
139 {
140 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return true;
141
142 $mailClass = new MailClass();
143 $mail = $mailClass->getOneById($mailId, true);
144
145 if (empty($mail)) return false;
146
147 $this->campaign->createNewCampaign($mail, $content);
148 $this->webhooks->addWebhooks();
149
150 return true;
151 }
152
153 public function onAcymAfterCMSUserImport($source)
154 {
155 $this->users->createFromImportedSource($source);
156 }
157
158 public function onAcymAfterDatabaseUserImport($source)
159 {
160 $this->users->createFromImportedSource($source);
161 }
162
163 public function onAcymCleanDataExternalSendingMethod(): bool
164 {
165 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return true;
166
167 return $this->campaign->cleanCampaigns();
168 }
169
170 public function onAcymSynchronizeExistingUsers($sendingMethod)
171 {
172 if ($sendingMethod !== self::SENDING_METHOD_ID) return;
173
174 $this->users->synchronizeExistingUsers();
175 }
176
177 public function onAcymResendCampaign($mailId)
178 {
179 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return;
180 $this->users->removeUserFromList($mailId);
181 }
182
183 public function onAcymSendingMethodOptions(&$data)
184 {
185 $data['embedImage'][self::SENDING_METHOD_ID] = false;
186 $data['embedAttachment'][self::SENDING_METHOD_ID] = false;
187 }
188 }
189