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

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

188 lines 6.2 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 $this->users->addAttributeToUser($receiverEmail, $subjectContent, $htmlContent, $mailId);
114 }
115 }
116
117 public function onAcymAfterUserModify($user, &$oldUser)
118 {
119 $this->users->createUser($user);
120 }
121
122 public function onAcymAfterUserCreate($user)
123 {
124 $this->users->createUser($user);
125 }
126
127 public function onAcymUserImport($users)
128 {
129 $this->users->importUsers($users);
130 }
131
132 public function onAcymBeforeUserDelete($users)
133 {
134 $this->users->deleteUsers($users);
135 }
136
137 public function onAcymSendCampaignOnExternalSendingMethod($mailId, $content): bool
138 {
139 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return true;
140
141 $mailClass = new MailClass();
142 $mail = $mailClass->getOneById($mailId, true);
143
144 if (empty($mail)) return false;
145
146 $this->campaign->createNewCampaign($mail, $content);
147 $this->webhooks->addWebhooks();
148
149 return true;
150 }
151
152 public function onAcymAfterCMSUserImport($source)
153 {
154 $this->users->createFromImportedSource($source);
155 }
156
157 public function onAcymAfterDatabaseUserImport($source)
158 {
159 $this->users->createFromImportedSource($source);
160 }
161
162 public function onAcymCleanDataExternalSendingMethod(): bool
163 {
164 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return true;
165
166 return $this->campaign->cleanCampaigns();
167 }
168
169 public function onAcymSynchronizeExistingUsers($sendingMethod)
170 {
171 if ($sendingMethod !== self::SENDING_METHOD_ID) return;
172
173 $this->users->synchronizeExistingUsers();
174 }
175
176 public function onAcymResendCampaign($mailId)
177 {
178 if ($this->config->get('mailer_method') != self::SENDING_METHOD_ID) return;
179 $this->users->removeUserFromList($mailId);
180 }
181
182 public function onAcymSendingMethodOptions(&$data)
183 {
184 $data['embedImage'][self::SENDING_METHOD_ID] = false;
185 $data['embedAttachment'][self::SENDING_METHOD_ID] = false;
186 }
187 }
188