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 | back/Classes/HistoryClass.php +0 -116 10.2.2 → 11.1.1 View file →
@@ -1,116 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Classes;
4 -
5 -use AcyMailing\Core\AcymClass;
6 -
7 -class HistoryClass extends AcymClass
8 -{
9 - public function __construct()
10 - {
11 - parent::__construct();
12 -
13 - $this->table = 'history';
14 - }
15 -
16 - public function insert($userId, $action, $data = [], $mailid = 0, $unsubscribe_reason = null)
17 - {
18 - $currentUserid = acym_currentUserId();
19 - if (!empty($currentUserid)) {
20 - $data[] = acym_translation('EXECUTED_BY').'::'.$currentUserid.' ( '.acym_currentUserName().' )';
21 - }
22 - $history = new \stdClass();
23 - $history->user_id = intval($userId);
24 - $history->action = strip_tags($action);
25 - $history->data = implode("\n", $data);
26 - $history->unsubscribe_reason = $unsubscribe_reason;
27 - if (strlen($history->data) > 100000) {
28 - $history->data = substr($history->data, 0, 10000);
29 - }
30 -
31 - static $date = null;
32 - if (empty($date)) {
33 - $date = time();
34 - }
35 -
36 - $history->date = ++$date;
37 - while ($this->alreadyExists($history->user_id, $history->date)) {
38 - $history->date++;
39 - }
40 -
41 - $date = $history->date;
42 -
43 - $history->mail_id = $mailid;
44 - if ($this->config->get('anonymous_tracking', 0) == 0) {
45 - $history->ip = acym_getIP();
46 - }
47 -
48 - if (!empty($_SERVER)) {
49 - $source = [];
50 - if ($this->config->get('anonymous_tracking', 0) == 0) {
51 - $vars = ['HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_ADDR', 'REMOTE_ADDR', 'REQUEST_URI', 'QUERY_STRING'];
52 - } else {
53 - $vars = ['HTTP_REFERER', 'HTTP_HOST', 'SERVER_ADDR', 'REQUEST_URI', 'QUERY_STRING'];
54 - }
55 -
56 - foreach ($vars as $oneVar) {
57 - if (!empty($_SERVER[$oneVar])) {
58 - $source[] = $oneVar.'::'.strip_tags($_SERVER[$oneVar]);
59 - }
60 - }
61 - $history->source = implode("\n", $source);
62 - }
63 -
64 - try {
65 - $insertId = acym_insertObject('#__acym_history', $history);
66 - } catch (\Exception $e) {
67 - $insertId = 0;
68 - }
69 -
70 - return $insertId;
71 - }
72 -
73 - public function alreadyExists($userId, $date)
74 - {
75 - $result = acym_loadResult('SELECT user_id FROM #__acym_history WHERE user_id = '.intval($userId).' AND date = '.acym_escapeDB($date));
76 -
77 - return !empty($result);
78 - }
79 -
80 - public function getHistoryOfOneById($id)
81 - {
82 - $query = 'SELECT h.*, m.id, m.subject FROM #__acym_'.$this->table.' AS h ';
83 - $query .= 'LEFT JOIN #__acym_mail AS m ON h.mail_id = m.id ';
84 - $query .= 'WHERE h.user_id = '.intval($id);
85 - $query .= ' ORDER BY h.date DESC';
86 -
87 - return acym_loadObjectList($query);
88 - }
89 -
90 - public function getAllUnsubReasons()
91 - {
92 - $query = 'SELECT action, data, unsubscribe_reason FROM #__acym_history WHERE action = "unsubscribed" AND unsubscribe_reason != ""';
93 -
94 - return acym_loadObjectList($query);
95 - }
96 -
97 - public function getAllMainLanguageUnsubReasons()
98 - {
99 - $allUnsubReasons = $this->config->get('unsub_survey', '{}');
100 -
101 - return json_decode($allUnsubReasons, true);
102 - }
103 -
104 - public function getUnsubscribeReasonText($index)
105 - {
106 - $surveyAnswers = json_decode($this->config->get('unsub_survey'), true);
107 - if (is_numeric($index)) {
108 - $index = $index - 1;
109 - $reason = $surveyAnswers[$index] ?? $index;
110 - } else {
111 - $reason = $index;
112 - }
113 -
114 - return $reason;
115 - }
116 -}