PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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
acymailing / front / FrontControllers / FrontstatsController.php

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

105 lines 3.3 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\Browser;
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()
23 {
24 $mailId = acym_getVar('int', 'id');
25 $userId = acym_getVar('int', 'userid');
26
27
28 if (!empty($mailId) && !empty($userId) && !acym_isRobot()) {
29 $userStatClass = new UserStatClass();
30 $userStat = $userStatClass->getOneByMailAndUserId($mailId, $userId);
31 if (!empty($userStat)) {
32 $openUnique = 1;
33 if ($userStat->open > 0) {
34 $openUnique = 0;
35 }
36
37 $mailStat = [
38 'mail_id' => $mailId,
39 'open_unique' => $openUnique,
40 'open_total' => 1,
41 ];
42
43 $mailStatClass = new MailStatClass();
44 $mailStatClass->save($mailStat);
45
46 $device = '';
47 $openedWith = '';
48 if (isset($_SERVER['HTTP_USER_AGENT'])) {
49 $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
50 $allDevices = array_merge(UserStatClass::DESKTOP_DEVICES, UserStatClass::MOBILE_DEVICES);
51
52 foreach ($allDevices as $oneDeviceKey => $oneDevice) {
53 if (preg_match('/'.$oneDeviceKey.'/', $userAgent)) {
54 $device = $oneDeviceKey;
55 break;
56 }
57 }
58
59 $browser = new Browser($userAgent);
60 $openedWith = $browser->getBrowser();
61 }
62
63 $userStatToInsert = [];
64 $userStatToInsert['user_id'] = $userId;
65 $userStatToInsert['mail_id'] = $mailId;
66 $userStatToInsert['open'] = 1;
67 $userStatToInsert['open_date'] = acym_date('now', 'Y-m-d H:i:s');
68 $userStatToInsert['device'] = $device;
69 $userStatToInsert['opened_with'] = $openedWith;
70
71 $userStatClass->save($userStatToInsert);
72
73 $userClass = new UserClass();
74 $subscriber = $userClass->getOneById($userId);
75 if (!empty($subscriber)) {
76 $subscriber->last_open_date = acym_date('now', 'Y-m-d H:i:s');
77 $userClass->triggers = false;
78 $userClass->sendConf = false;
79 $userClass->save($subscriber);
80 }
81 }
82 }
83
84 acym_noCache();
85
86 ob_end_clean();
87
88 $picture = ACYM_MEDIA_RELATIVE.'images/editor/statpicture.png';
89
90 $picture = ltrim(str_replace(['\\', '/'], DS, $picture), DS);
91
92 $imagename = ACYM_ROOT.$picture;
93 $handle = fopen($imagename, 'r');
94 if (!$handle) {
95 exit;
96 }
97
98 acym_header('Content-type: image/png');
99 $contents = fread($handle, filesize($imagename));
100 fclose($handle);
101 echo $contents;
102 exit;
103 }
104 }
105