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

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

72 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SendinblueList extends SendinblueClass
4 {
5 public function getListExternalSendingMethod(&$listId, $mailId, $createIfNotExists = true)
6 {
7 $brevoLists = $this->config->get('list_sendinblue', '[]');
8 $brevoLists = json_decode($brevoLists, true);
9
10 if (!empty($brevoLists[$mailId])) {
11 $listId = $brevoLists[$mailId];
12
13 return;
14 }
15
16 if (!$createIfNotExists) return;
17
18 $listId = $this->createList('list_for_acym_mail_'.$mailId);
19
20 $brevoLists[$mailId] = $listId;
21 $this->config->saveConfig(['list_sendinblue' => json_encode($brevoLists)]);
22 }
23
24 public function createList($name)
25 {
26 $data = [
27 'name' => $name,
28 'folderId' => intval($this->getFolderId()),
29 ];
30
31 $response = $this->callApiSendingMethod('contacts/lists', $data, $this->headers, 'POST');
32
33 if (!empty($response['message']) && $response['message'] === 'Folder ID does not exist') {
34 $this->config->saveConfig(['sendinblue_folder_id' => 0]);
35
36 return $this->createList($name);
37 }
38
39 return $response['id'];
40 }
41
42 public function getFolderId()
43 {
44 $folderId = $this->config->get('sendinblue_folder_id', 0);
45 if (!empty($folderId)) return $folderId;
46
47 $data = [
48 'name' => 'AcyMailing Integration',
49 ];
50
51 $response = $this->callApiSendingMethod('contacts/folders', $data, $this->headers, 'POST');
52
53 if (empty($response['id'])) return 0;
54
55 $this->config->saveConfig(['sendinblue_folder_id' => $response['id']]);
56
57 return $response['id'];
58 }
59
60 public function deleteList($mailId): bool
61 {
62 $listId = 0;
63 $this->getListExternalSendingMethod($listId, $mailId, false);
64
65 if (empty($listId)) return false;
66
67 $this->callApiSendingMethod(plgAcymSendinblue::SENDING_METHOD_API_URL.'contacts/lists/'.$listId, [], $this->headers, 'DELETE');
68
69 return true;
70 }
71 }
72