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 -96 10.11.1 → 11.1.1 View file →
@@ -1,96 +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 - $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 - $delay = $this->config->get('tracking_delay', 0);
57 - if (empty($userStat) || acym_isRobot() || (!empty($delay) && acym_getTimeFromUTCDate($userStat->send_date) > time() - $delay)) {
58 - return;
59 - }
60 -
61 - $mailStat = new \stdClass();
62 - $mailStat->mail_id = $mailId;
63 - $mailStat->open_unique = $userStat->open > 0 ? 0 : 1;
64 - $mailStat->open_total = 1;
65 -
66 - $mailStatClass = new MailStatClass();
67 - $mailStatClass->save($mailStat);
68 -
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 = '';
76 -
77 - if (isset($_SERVER['HTTP_USER_AGENT'])) {
78 - $browserDetection = new BrowserDetection();
79 - $openingInformation = $browserDetection->getAll($_SERVER['HTTP_USER_AGENT']);
80 -
81 - $userStatToInsert->device = $openingInformation['os_name'] === 'unknown' ? '' : $openingInformation['os_name'];
82 - $userStatToInsert->opened_with = $openingInformation['browser_name'] === 'unknown' ? '' : $openingInformation['browser_name'];
83 - }
84 -
85 - $userStatClass->save($userStatToInsert);
86 -
87 - $userClass = new UserClass();
88 - $subscriber = $userClass->getOneById($userId);
89 - if (!empty($subscriber)) {
90 - $subscriber->last_open_date = $userStatToInsert->open_date;
91 - $userClass->triggers = false;
92 - $userClass->sendConf = false;
93 - $userClass->save($subscriber);
94 - }
95 - }
96 -}