PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
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 +0 -92 11.0.1 → 11.1.1 View file →
@@ -1,92 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\FrontControllers;
4 -
5 -use AcyMailing\Classes\MailStatClass;
6 -use AcyMailing\Classes\UserClass;
7 -use AcyMailing\Classes\UserStatClass;
8 -use AcyMailing\Core\AcymController;
9 -use AcyMailing\Libraries\Browser\BrowserDetection;
10 -
11 -class FrontstatsController extends AcymController
12 -{
13 - public function __construct()
14 - {
15 - parent::__construct();
16 -
17 - $this->publicFrontTasks = [
18 - 'openStats',
19 - ];
20 - }
21 -
22 - public function openStats(): void
23 - {
24 - $mailId = acym_getVar('int', 'id');
25 - $userId = acym_getVar('int', 'userid');
26 -
27 - if (!empty($mailId) && !empty($userId) && !acym_isRobot()) {
28 - $this->recordOpen($mailId, $userId);
29 - }
30 -
31 - acym_noCache();
32 - if (ob_get_level() > 0) {
33 - ob_end_clean();
34 - }
35 -
36 - $statsPicture = ACYM_MEDIA_RELATIVE.'images/editor/statpicture.png';
37 - $statsPicture = ACYM_ROOT.ltrim(str_replace(['\\', '/'], DS, $statsPicture), DS);
38 -
39 - acym_header('Content-type: image/png');
40 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Efficient and less memory usage.
41 - readfile($statsPicture);
42 - exit;
43 - }
44 -
45 - private function recordOpen(int $mailId, int $userId): void
46 - {
47 - $userStatClass = new UserStatClass();
48 - $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
49 -
50 - // Ignore opens within X seconds following the email sending to prevent bots from impacting statistics
51 - $delay = $this->config->get('tracking_delay', 0);
52 - if (empty($userStat) || acym_isRobot() || (!empty($delay) && acym_getTimeFromUTCDate($userStat->send_date) > time() - $delay)) {
53 - return;
54 - }
55 -
56 - $mailStat = new \stdClass();
57 - $mailStat->mail_id = $mailId;
58 - $mailStat->open_unique = $userStat->open > 0 ? 0 : 1;
59 - $mailStat->open_total = 1;
60 -
61 - $mailStatClass = new MailStatClass();
62 - $mailStatClass->save($mailStat);
63 -
64 - $userStatToInsert = new \stdClass();
65 - $userStatToInsert->user_id = $userId;
66 - $userStatToInsert->mail_id = $mailId;
67 - $userStatToInsert->open = 1;
68 - $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false);
69 - $userStatToInsert->device = '';
70 - $userStatToInsert->opened_with = '';
71 -
72 - $userAgent = acym_getVar('string', 'HTTP_USER_AGENT', null, 'SERVER');
73 - if (!empty($userAgent)) {
74 - $browserDetection = new BrowserDetection();
75 - $openingInformation = $browserDetection->getAll($userAgent);
76 -
77 - $userStatToInsert->device = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name'];
78 - $userStatToInsert->opened_with = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name'];
79 - }
80 -
81 - $userStatClass->save($userStatToInsert);
82 -
83 - $userClass = new UserClass();
84 - $subscriber = $userClass->getOneById($userId);
85 - if (!empty($subscriber)) {
86 - $subscriber->last_open_date = $userStatToInsert->open_date;
87 - $userClass->triggers = false;
88 - $userClass->sendConf = false;
89 - $userClass->save($subscriber);
90 - }
91 - }
92 -}