PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
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 / FrontstatsController.php

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

96 lines 3.0 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\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 $handle = fopen($statsPicture, 'r');
40 if (!$handle) {
41 exit;
42 }
43
44 acym_header('Content-type: image/png');
45 $contents = fread($handle, filesize($statsPicture));
46 fclose($handle);
47 echo $contents;
48 exit;
49 }
50
51 private function recordOpen(int $mailId, int $userId): void
52 {
53 $userStatClass = new UserStatClass();
54 $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
55
56 if (empty($userStat) || acym_getTimeFromUTCDate($userStat->send_date) > time() - 20) {
57 return;
58 }
59
60 $mailStat = new \stdClass();
61 $mailStat->mail_id = $mailId;
62 $mailStat->open_unique = $userStat->open > 0 ? 0 : 1;
63 $mailStat->open_total = 1;
64
65 $mailStatClass = new MailStatClass();
66 $mailStatClass->save($mailStat);
67
68 $userStatToInsert = new \stdClass();
69 $userStatToInsert->user_id = $userId;
70 $userStatToInsert->mail_id = $mailId;
71 $userStatToInsert->open = 1;
72 $userStatToInsert->open_date = acym_date('now', 'Y-m-d H:i:s', false);
73 $userStatToInsert->device = '';
74 $userStatToInsert->opened_with = '';
75
76 if (isset($_SERVER['HTTP_USER_AGENT'])) {
77 $browserDetection = new BrowserDetection();
78 $openingInformation = $browserDetection->getAll($_SERVER['HTTP_USER_AGENT']);
79
80 $userStatToInsert->device = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name'];
81 $userStatToInsert->opened_with = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name'];
82 }
83
84 $userStatClass->save($userStatToInsert);
85
86 $userClass = new UserClass();
87 $subscriber = $userClass->getOneById($userId);
88 if (!empty($subscriber)) {
89 $subscriber->last_open_date = $userStatToInsert->open_date;
90 $userClass->triggers = false;
91 $userClass->sendConf = false;
92 $userClass->save($subscriber);
93 }
94 }
95 }
96