PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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 / campaign.php

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

93 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SendinblueCampaign extends SendinblueClass
4 {
5 var $sender;
6 var $user;
7 var $list;
8 var $headers;
9
10 public function __construct(&$plugin, $headers, $sender, $user, $list)
11 {
12 parent::__construct($plugin, $headers);
13 $this->sender = $sender;
14 $this->user = $user;
15 $this->list = $list;
16 }
17
18 public function createNewCampaign($mail, $content)
19 {
20 $listIdBrevo = 0;
21 $this->list->getListExternalSendingMethod($listIdBrevo, $mail->id);
22
23 $subjectAttribute = $this->user->getSubjectAttributeName($mail->id);
24 $contentAttribute = $this->user->getAttributeName($mail->id);
25
26 if (strpos($content, 'acym__wysid__template') === false || strpos($content, '<body') === false) {
27 $commonContent = '<html>{% autoescape off %}{{ contact.'.$contentAttribute.' }}{% endautoescape %}</html>';
28 } else {
29 $commonContent = preg_replace('#<title>(.*)</title>#Uis', '<title>{{ contact.'.$subjectAttribute.' }}</title>', $content);
30 $commonContent = preg_replace('#(<body[^>]*>).*</body>#Uis', '$1{% autoescape off %}{{ contact.'.$contentAttribute.' }}{% endautoescape %}</body>', $commonContent);
31 }
32
33 $data = [
34 'sender' => $this->sender->getSender($mail),
35 'name' => 'AcyMailing Mail '.$mail->id.' ('.$mail->subject.')',
36 'htmlContent' => $commonContent,
37 'scheduledAt' => date('c', time() + 60),
38 'subject' => '{{ contact.'.$this->user->getSubjectAttributeName($mail->id).' }}',
39 'replyTo' => $this->sender->getReplyToEmail($mail),
40 'recipients' => [
41 'listIds' => [$listIdBrevo],
42 ],
43 'footer' => '<span style="display: none !important;">{'.acym_translation('ACYM_UNSUBSCRIBE').'}</span>',
44 'inlineImageActivation' => !empty($this->config->get('embed_images', 0)),
45 ];
46
47 $this->callApiSendingMethod('emailCampaigns', $data, $this->headers, 'POST');
48 }
49
50 public function cleanCampaigns(): bool
51 {
52 $cleanFrequency = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_clean_frequency', 2592000);
53 $lastClean = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_last_clean', 0);
54
55 $time = time();
56
57 if (!empty($lastClean) && $lastClean < ($time + $cleanFrequency)) return true;
58
59 $response = $this->callApiSendingMethod(
60 plgAcymSendinblue::SENDING_METHOD_API_URL.'emailCampaigns?status=sent&limit=500&offset=0&sort=desc',
61 [],
62 $this->headers
63 );
64
65 if (empty($response['campaigns'])) return true;
66
67 $startSendDate = date('c', $time - $cleanFrequency);
68
69 foreach ($response['campaigns'] as $campaign) {
70 $sendDate = strtotime($campaign['sentDate']);
71 if ($sendDate > $startSendDate) continue;
72
73 preg_match('#AcyMailing Mail ([0-9]+)#is', $campaign['name'], $match);
74 if (empty($match)) continue;
75
76 $id = intval($match[1]);
77
78 if (empty($id)) continue;
79
80 $this->user->deleteAttribute($id);
81 $this->list->deleteList($id);
82 $this->deleteCampaign($campaign['id']);
83 }
84
85 return true;
86 }
87
88 public function deleteCampaign($brevoCampaignId)
89 {
90 $this->callApiSendingMethod(plgAcymSendinblue::SENDING_METHOD_API_URL.'emailCampaigns/'.$brevoCampaignId, [], $this->headers, 'DELETE');
91 }
92 }
93