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/FrontstatsController.php +31 -22 10.11.1 → 11.1.0 View file →
@@ -35,17 +35,11 @@
35 35
36 36 $statsPicture = ACYM_MEDIA_RELATIVE.'images/editor/statpicture.png';
37 37 $statsPicture = ACYM_ROOT.ltrim(str_replace(['\\', '/'], DS, $statsPicture), DS);
38 38
39 - $handle = fopen($statsPicture, 'r');
40 - if (!$handle) {
41 - exit;
42 - }
43 -
44 39 acym_header('Content-type: image/png');
45 - $contents = fread($handle, filesize($statsPicture));
46 - fclose($handle);
47 - echo $contents;
40 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Efficient and less memory usage.
41 + readfile($statsPicture);
48 42 exit;
49 43 }
50 44
51 45 private function recordOpen(int $mailId, int $userId): void
@@ -52,43 +46,58 @@
52 46 {
53 47 $userStatClass = new UserStatClass();
54 48 $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
55 49
50 + // Ignore opens within X seconds following the email sending to prevent bots from impacting statistics
56 51 $delay = $this->config->get('tracking_delay', 0);
57 52 if (empty($userStat) || acym_isRobot() || (!empty($delay) && acym_getTimeFromUTCDate($userStat->send_date) > time() - $delay)) {
58 53 return;
59 54 }
60 55
56 + $anonymousStats = !empty($this->config->get('anonymous_stats', 0));
57 +
61 58 $mailStat = new \stdClass();
62 59 $mailStat->mail_id = $mailId;
63 - $mailStat->open_unique = $userStat->open > 0 ? 0 : 1;
64 60 $mailStat->open_total = 1;
61 + $mailStat->open_unique = $anonymousStats ? 1 : ($userStat->open > 0 ? 0 : 1);
65 62
66 63 $mailStatClass = new MailStatClass();
67 64 $mailStatClass->save($mailStat);
68 65
69 - $userStatToInsert = new \stdClass();
70 - $userStatToInsert->user_id = $userId;
71 - $userStatToInsert->mail_id = $mailId;
72 - $userStatToInsert->open = 1;
73 - $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false);
74 - $userStatToInsert->device = '';
75 - $userStatToInsert->opened_with = '';
66 + $openDate = acym_date('now', 'Y-m-d H:i:s', false);
76 67
77 - if (isset($_SERVER['HTTP_USER_AGENT'])) {
68 + $device = '';
69 + $openedWith = '';
70 + $userAgent = acym_getVar('string', 'HTTP_USER_AGENT', null, 'SERVER');
71 + if (!empty($userAgent)) {
78 72 $browserDetection = new BrowserDetection();
79 - $openingInformation = $browserDetection->getAll($_SERVER['HTTP_USER_AGENT']);
73 + $openingInformation = $browserDetection->getAll($userAgent);
80 74
81 - $userStatToInsert->device = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name'];
82 - $userStatToInsert->opened_with = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name'];
75 + $device = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name'];
76 + $openedWith = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name'];
83 77 }
84 78
85 - $userStatClass->save($userStatToInsert);
79 + if ($anonymousStats) {
80 + $mailStatClass->incrementDetail($mailId, 'device', $device);
81 + $mailStatClass->incrementDetail($mailId, 'client', $openedWith);
82 + $mailStatClass->incrementDetail($mailId, 'open_time', acym_date('now', 'Y-m-d H', false).':00:00');
83 + } else {
84 + $userStatToInsert = new \stdClass();
85 + $userStatToInsert->user_id = $userId;
86 + $userStatToInsert->mail_id = $mailId;
87 + $userStatToInsert->open = 1;
88 + $userStatToInsert->open_date = $openDate;
89 + $userStatToInsert->device = $device;
90 + $userStatToInsert->opened_with = $openedWith;
91 + $userStatClass->save($userStatToInsert);
92 + }
86 93
94 + UserStatClass::triggerActivity('user_open', $userId, $mailId);
95 +
87 96 $userClass = new UserClass();
88 97 $subscriber = $userClass->getOneById($userId);
89 98 if (!empty($subscriber)) {
90 - $subscriber->last_open_date = $userStatToInsert->open_date;
99 + $subscriber->last_open_date = $openDate;
91 100 $userClass->triggers = false;
92 101 $userClass->sendConf = false;
93 102 $userClass->save($subscriber);
94 103 }