PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.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 / front / FrontControllers / FronturlController.php

FronturlController.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.4, at front/FrontControllers/FronturlController.php

121 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\FrontControllers;
4
5 use AcyMailing\Classes\MailClass;
6 use AcyMailing\Classes\MailStatClass;
7 use AcyMailing\Classes\UrlClass;
8 use AcyMailing\Classes\UrlClickClass;
9 use AcyMailing\Classes\UserClass;
10 use AcyMailing\Classes\UserStatClass;
11 use AcyMailing\Core\AcymController;
12
13 class FronturlController extends AcymController
14 {
15 public function __construct()
16 {
17 parent::__construct();
18
19 $this->publicFrontTasks = [
20 'click',
21 ];
22 }
23
24 public function click(): void
25 {
26 $urlId = acym_getVar('int', 'urlid');
27 $mailId = acym_getVar('int', 'mailid');
28 $userId = acym_getVar('int', 'userid');
29
30 $urlClass = new UrlClass();
31 $urlObject = $urlClass->getOneUrlById($urlId);
32
33 if (empty($urlObject->id)) {
34 acym_raiseError(404, acym_translation('ACYM_PAGE_NOT_FOUND'));
35 }
36
37 $urlObject->url = preg_replace(
38 [
39 '#&idU=[0-9]+#i',
40 '#idU=[0-9]+&#i',
41 '#\?idU=[0-9]+#i',
42 ],
43 '',
44 $urlObject->url
45 );
46
47 $mailClass = new MailClass();
48 $mail = $mailClass->getOneById($mailId);
49
50 $userStatClass = new UserStatClass();
51 $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
52
53 // The mail has been deleted, or we didn't send this email to this user, or it's a bot
54 $delay = $this->config->get('tracking_delay', 0);
55 if (empty($mail) || empty($userStat) || acym_isRobot() || (!empty($delay) && acym_getTimeFromUTCDate($userStat->send_date) > time() - $delay)) {
56 acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId), '', 'message', false);
57 }
58
59 $urlClick = new \stdClass();
60 $urlClick->mail_id = $mailId;
61 $urlClick->url_id = $urlObject->id;
62 $urlClick->click = 1;
63 $urlClick->user_id = $userId;
64 $urlClick->date_click = acym_date('now', 'Y-m-d H:i:s', false);
65
66 $mailStatClass = new MailStatClass();
67 $urlClickClass = new UrlClickClass();
68 $urlClickClass->save($urlClick);
69
70 if (empty($userStat->open)) {
71 $userStatToInsert = new \stdClass();
72 $userStatToInsert->user_id = $userId;
73 $userStatToInsert->mail_id = $mailId;
74 $userStatToInsert->open = 1;
75 $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false);
76 $userStatClass->save($userStatToInsert);
77
78 $mailStat = new \stdClass();
79 $mailStat->mail_id = $mailId;
80 $mailStat->open_unique = 1;
81 $mailStat->open_total = 1;
82 $mailStatClass->save($mailStat);
83 }
84
85 $clickStats = $urlClickClass->getOneByMailIdAndUserId($mailId, $userId);
86 $mailStatClass->incrementClicks($mailId, $clickStats->click == 1);
87
88 $userClass = new UserClass();
89 $subscriber = $userClass->getOneById($userId);
90 if (!empty($subscriber)) {
91 $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s', false);
92 $subscriber->last_click_date = acym_date('now', 'Y-m-d H:i:s', false);
93 $userClass->triggers = false;
94 $userClass->sendConf = false;
95 $userClass->save($subscriber);
96 }
97
98 acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId), '', 'message', false);
99 }
100
101 private function resolveSubscriberTags(string $url, int $userId): string
102 {
103 if (!preg_match('#\{|%7B#i', $url)) {
104 return $url;
105 }
106
107 $userClass = new UserClass();
108 $subscriber = $userClass->identify(true, 'userid', 'userkey');
109
110 if (empty($subscriber) || (int)$subscriber->id !== $userId) {
111 return $url;
112 }
113
114 $tempEmail = new \stdClass();
115 $tempEmail->body = $url;
116 acym_trigger('replaceUserInformation', [&$tempEmail, &$subscriber, true]);
117
118 return $tempEmail->body;
119 }
120 }
121