PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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
← All changes | front/FrontControllers/FronturlController.php +69 -31 10.2.2 → 11.1.0 View file →
@@ -35,11 +35,11 @@
35 35 }
36 36
37 37 $urlObject->url = preg_replace(
38 38 [
39 - '#&idU=[0-9]+#Ui',
40 - '#idU=[0-9]+&#Ui',
41 - '#\?idU=[0-9]+#Ui',
39 + '#&idU=[0-9]+#i',
40 + '#idU=[0-9]+&#i',
41 + '#\?idU=[0-9]+#i',
42 42 ],
43 43 '',
44 44 $urlObject->url
45 45 );
@@ -49,52 +49,90 @@
49 49
50 50 $userStatClass = new UserStatClass();
51 51 $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
52 52
53 - if (empty($mail) || empty($userStat) || acym_isRobot()) {
54 - acym_redirect($urlObject->url);
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);
55 57 }
56 58
57 - $urlClick = [
58 - 'mail_id' => $mailId,
59 - 'url_id' => $urlObject->id,
60 - 'click' => 1,
61 - 'user_id' => $userId,
62 - 'date_click' => acym_date('now', 'Y-m-d H:i:s'),
63 - ];
59 + $anonymousStats = !empty($this->config->get('anonymous_stats', 0));
64 60
61 + $urlClick = new \stdClass();
62 + $urlClick->mail_id = $mailId;
63 + $urlClick->url_id = $urlObject->id;
64 + $urlClick->click = 1;
65 + $urlClick->user_id = $anonymousStats ? 0 : $userId;
66 + $urlClick->date_click = acym_date('now', 'Y-m-d H:i:s', false);
67 +
65 68 $mailStatClass = new MailStatClass();
66 69 $urlClickClass = new UrlClickClass();
67 70 $urlClickClass->save($urlClick);
68 71
69 - if (empty($userStat->open)) {
70 - $userStatToInsert = [];
71 - $userStatToInsert['user_id'] = $userId;
72 - $userStatToInsert['mail_id'] = $mailId;
73 - $userStatToInsert['open'] = 1;
74 - $userStatToInsert['open_date'] = acym_date('now', 'Y-m-d H:i:s');
75 - $userStatClass->save($userStatToInsert);
72 + UserStatClass::triggerActivity('user_click', $userId, $mailId);
76 73
77 - $mailStatToInsert = [
78 - 'mail_id' => $mailId,
79 - 'open_unique' => 1,
80 - 'open_total' => 1,
81 - ];
82 - $mailStatClass->save($mailStatToInsert);
74 + if (!$anonymousStats) {
75 + if (empty($userStat->open)) {
76 + $userStatToInsert = new \stdClass();
77 + $userStatToInsert->user_id = $userId;
78 + $userStatToInsert->mail_id = $mailId;
79 + $userStatToInsert->open = 1;
80 + $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false);
81 + $userStatClass->save($userStatToInsert);
82 +
83 + $mailStat = new \stdClass();
84 + $mailStat->mail_id = $mailId;
85 + $mailStat->open_unique = 1;
86 + $mailStat->open_total = 1;
87 + $mailStatClass->save($mailStat);
88 +
89 + UserStatClass::triggerActivity('user_open', $userId, $mailId);
90 + }
91 +
92 + $clickStats = $urlClickClass->getOneByMailIdAndUserId($mailId, $userId);
93 + $mailStatClass->incrementClicks($mailId, $clickStats->click == 1);
94 + } else {
95 + $mailStatClass->incrementClicks($mailId, true);
96 +
97 + // Anonymous mode tracks totals only and keeps no per-recipient open state, so this is not deduplicated.
98 + $mailStat = new \stdClass();
99 + $mailStat->mail_id = $mailId;
100 + $mailStat->open_unique = 1;
101 + $mailStat->open_total = 1;
102 + $mailStatClass->save($mailStat);
103 + $mailStatClass->incrementDetail($mailId, 'open_time', acym_date('now', 'Y-m-d H', false).':00:00');
83 104 }
84 105
85 - $clickStats = $urlClickClass->getOneByMailIdAndUserId($mailId, $userId);
86 - $mailStatClass->incrementClicks($mailId, $clickStats->click == 1);
87 -
88 106 $userClass = new UserClass();
89 107 $subscriber = $userClass->getOneById($userId);
90 108 if (!empty($subscriber)) {
91 - $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s');
92 - $subscriber->last_click_date = acym_date('now', 'Y-m-d H:i:s');
109 + $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s', false);
110 + $subscriber->last_click_date = acym_date('now', 'Y-m-d H:i:s', false);
93 111 $userClass->triggers = false;
94 112 $userClass->sendConf = false;
95 113 $userClass->save($subscriber);
96 114 }
97 115
98 - acym_redirect($urlObject->url);
116 + acym_redirect($this->resolveSubscriberTags($urlObject->url, $userId), '', 'message', false);
117 + }
118 +
119 + private function resolveSubscriberTags(string $url, int $userId): string
120 + {
121 + if (!preg_match('#\{|%7B#i', $url)) {
122 + return $url;
123 + }
124 +
125 + $userClass = new UserClass();
126 + $subscriber = $userClass->identify(true, 'userid', 'userkey');
127 +
128 + if (empty($subscriber) || (int)$subscriber->id !== $userId) {
129 + return $url;
130 + }
131 +
132 + $tempEmail = new \stdClass();
133 + $tempEmail->body = $url;
134 + acym_trigger('replaceUserInformation', [&$tempEmail, &$subscriber, true]);
135 +
136 + return $tempEmail->body;
99 137 }
100 138 }