← All changes
|
front/FrontControllers/FrontservicesController.php
+0
-80
11.0.2
→
11.1.1
View file →
| @@ -1,80 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\FrontControllers; | |
| 4 | - | |
| 5 | -use AcyMailing\Classes\HistoryClass; | |
| 6 | -use AcyMailing\Classes\UserClass; | |
| 7 | -use AcyMailing\Classes\UserStatClass; | |
| 8 | -use AcyMailing\Core\AcymController; | |
| 9 | - | |
| 10 | -class FrontservicesController extends AcymController | |
| 11 | -{ | |
| 12 | - public function __construct() | |
| 13 | - { | |
| 14 | - parent::__construct(); | |
| 15 | - acym_setNoTemplate(); | |
| 16 | - | |
| 17 | - $this->publicFrontTasks = [ | |
| 18 | - 'sendinblue', | |
| 19 | - ]; | |
| 20 | - } | |
| 21 | - | |
| 22 | - public function listing(): void | |
| 23 | - { | |
| 24 | - exit; | |
| 25 | - } | |
| 26 | - | |
| 27 | - public function sendinblue(): void | |
| 28 | - { | |
| 29 | - // Check security key | |
| 30 | - $securityKey = acym_getVar('string', 'seckey'); | |
| 31 | - $storedKey = $this->config->get('sendinblue_webhooks_seckey'); | |
| 32 | - if (empty($securityKey) || empty($storedKey) || !hash_equals((string)$storedKey, (string)$securityKey)) exit; | |
| 33 | - | |
| 34 | - // Check if sending method is sendinblue | |
| 35 | - $mailerMethod = $this->config->get('mailer_method'); | |
| 36 | - if (!in_array($mailerMethod, ['brevo-smtp', 'sendinblue'])) exit; | |
| 37 | - | |
| 38 | - // Get the data passed by Sendinblue | |
| 39 | - $data = acym_getJsonData(); | |
| 40 | - if (empty($data['email'])) exit; | |
| 41 | - | |
| 42 | - // Get the user from the email | |
| 43 | - $userClass = new UserClass(); | |
| 44 | - $user = $userClass->getOneByEmail($data['email']); | |
| 45 | - if (empty($user)) exit; | |
| 46 | - | |
| 47 | - $action = empty($data['event']) ? 'brevo' : $data['event']; | |
| 48 | - | |
| 49 | - // Get the related email id if there is one | |
| 50 | - $mailId = 0; | |
| 51 | - if (!empty($data['campaign name']) && strpos($data['campaign name'], 'AcyMailing Mail ') === 0) { | |
| 52 | - $mailId = preg_replace('#^AcyMailing Mail (\d+) \(.*$#Uis', '$1', $data['campaign name']); | |
| 53 | - | |
| 54 | - // Register the unsubscription on the email's stats | |
| 55 | - if (in_array($action, ['unsubscribe', 'spam'])) { | |
| 56 | - acym_query('UPDATE #__acym_user_stat SET unsubscribe = unsubscribe + 1 WHERE user_id = '.intval($user->id).' AND mail_id = '.intval($mailId)); | |
| 57 | - acym_query('UPDATE #__acym_mail_stat SET unsubscribe_total = unsubscribe_total + 1 WHERE mail_id = '.intval($mailId)); | |
| 58 | - acym_query('UPDATE #__acym_user_has_list SET status = 0 WHERE user_id = '.intval($user->id)); | |
| 59 | - } | |
| 60 | - | |
| 61 | - if ($action === 'hard_bounce') { | |
| 62 | - $userStatClass = new UserStatClass(); | |
| 63 | - $currentUserStats = $userStatClass->getOneByMailAndUserId($mailId, $user->id); | |
| 64 | - if ($currentUserStats->bounce < 1) { | |
| 65 | - acym_query('UPDATE #__acym_mail_stat SET bounce_unique = bounce_unique + 1 WHERE mail_id = '.intval($mailId)); | |
| 66 | - } | |
| 67 | - acym_query('UPDATE #__acym_user_stat SET bounce = bounce + 1 WHERE user_id = '.intval($user->id).' AND mail_id = '.intval($mailId)); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - | |
| 71 | - // If found, disable the user and add the reason in their history | |
| 72 | - $user->active = 0; | |
| 73 | - $userClass->save($user); | |
| 74 | - | |
| 75 | - $historyClass = new HistoryClass(); | |
| 76 | - $historyClass->insert($user->id, $action, ['Brevo'], $mailId); | |
| 77 | - | |
| 78 | - exit; | |
| 79 | - } | |
| 80 | -} | |