PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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 +37 -29 10.1.4 → 11.1.0 View file →
@@ -12,9 +12,13 @@
12 12
13 13 $this->table = 'history';
14 14 }
15 15
16 - public function insert($userId, $action, $data = [], $mailid = 0, $unsubscribe_reason = null)
16 + /**
17 + * Function insert to insert a line into the history...
18 + * User modification, user update, bounces... etc.
19 + */
20 + public function insert(int $userId, string $action, array $data = [], int $mailid = 0, $unsubscribe_reason = null): void
17 21 {
18 22 $currentUserid = acym_currentUserId();
19 23 if (!empty($currentUserid)) {
20 24 $data[] = acym_translation('EXECUTED_BY').'::'.$currentUserid.' ( '.acym_currentUserName().' )';
@@ -20,11 +24,12 @@
20 24 $data[] = acym_translation('EXECUTED_BY').'::'.$currentUserid.' ( '.acym_currentUserName().' )';
21 25 }
22 26 $history = new \stdClass();
23 27 $history->user_id = intval($userId);
24 - $history->action = strip_tags($action);
28 + $history->action = acym_stripTags($action);
25 29 $history->data = implode("\n", $data);
26 30 $history->unsubscribe_reason = $unsubscribe_reason;
31 + //Avoid a memory issue when the data is way too big.
27 32 if (strlen($history->data) > 100000) {
28 33 $history->data = substr($history->data, 0, 10000);
29 34 }
30 35
@@ -40,23 +45,26 @@
40 45
41 46 $date = $history->date;
42 47
43 48 $history->mail_id = $mailid;
44 - if ($this->config->get('anonymous_tracking', 0) == 0) {
45 - $history->ip = acym_getIP();
46 - }
49 + $history->ip = acym_getIP();
47 50
48 - if (!empty($_SERVER)) {
51 + if (!empty($_SERVER) && empty($this->config->get('anonymous_stats', 0))) {
49 52 $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 - }
53 + $vars = [
54 + 'HTTP_REFERER',
55 + 'HTTP_USER_AGENT',
56 + 'HTTP_HOST',
57 + 'SERVER_ADDR',
58 + 'REMOTE_ADDR',
59 + 'REQUEST_URI',
60 + 'QUERY_STRING',
61 + ];
55 62
56 63 foreach ($vars as $oneVar) {
57 - if (!empty($_SERVER[$oneVar])) {
58 - $source[] = $oneVar.'::'.strip_tags($_SERVER[$oneVar]);
64 + $remoteIp = acym_getVar('string', $oneVar, '', 'SERVER');
65 + if (!empty($remoteIp)) {
66 + $source[] = $oneVar.'::'.acym_stripTags($remoteIp);
59 67 }
60 68 }
61 69 $history->source = implode("\n", $source);
62 70 }
@@ -61,41 +69,41 @@
61 69 $history->source = implode("\n", $source);
62 70 }
63 71
64 72 try {
65 - $insertId = acym_insertObject('#__acym_history', $history);
73 + acym_insertObject('#__acym_history', $history);
66 74 } catch (\Exception $e) {
67 - $insertId = 0;
68 75 }
69 -
70 - return $insertId;
71 76 }
72 77
73 - public function alreadyExists($userId, $date)
78 + private function alreadyExists(int $userId, int $time): bool
74 79 {
75 - $result = acym_loadResult('SELECT user_id FROM #__acym_history WHERE user_id = '.intval($userId).' AND date = '.acym_escapeDB($date));
80 + $result = acym_loadResult('SELECT user_id FROM #__acym_history WHERE user_id = '.intval($userId).' AND date = '.intval($time));
76 81
77 82 return !empty($result);
78 83 }
79 84
80 - public function getHistoryOfOneById($id)
85 + /**
86 + * Get all history lines for one user order by date descending
87 + */
88 + public function getHistoryOfOneById(int $userId): array
81 89 {
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);
90 + return acym_loadObjectList(
91 + 'SELECT h.*, m.id, m.subject FROM #__acym_history AS h
92 + LEFT JOIN #__acym_mail AS m ON h.mail_id = m.id
93 + WHERE h.user_id = '.intval($userId).'
94 + ORDER BY h.date DESC'
95 + );
88 96 }
89 97
90 - public function getAllUnsubReasons()
98 + public function getAllUnsubReasons(): array
91 99 {
92 - $query = 'SELECT action, data, unsubscribe_reason FROM #__acym_history WHERE action = "unsubscribed" AND unsubscribe_reason != ""';
100 + $query = 'SELECT `action`, `data`, `unsubscribe_reason` FROM #__acym_history WHERE `action` = "unsubscribed" AND `unsubscribe_reason` != ""';
93 101
94 102 return acym_loadObjectList($query);
95 103 }
96 104
97 - public function getAllMainLanguageUnsubReasons()
105 + public function getAllMainLanguageUnsubReasons(): array
98 106 {
99 107 $allUnsubReasons = $this->config->get('unsub_survey', '{}');
100 108
101 109 return json_decode($allUnsubReasons, true);