| @@ -12,8 +12,12 @@ | ||
| 12 | 12 | |
| 13 | 13 | $this->table = 'history'; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + /** | |
| 17 | + * Function insert to insert a line into the history... | |
| 18 | + * User modification, user update, bounces... etc. | |
| 19 | + */ | |
| 16 | 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,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 | |
| @@ -42,15 +47,24 @@ | ||
| 42 | 47 | |
| 43 | 48 | $history->mail_id = $mailid; |
| 44 | 49 | $history->ip = acym_getIP(); |
| 45 | 50 | |
| 46 | - if (!empty($_SERVER)) { | |
| 51 | + if (!empty($_SERVER) && empty($this->config->get('anonymous_stats', 0))) { | |
| 47 | 52 | $source = []; |
| 48 | - $vars = ['HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_ADDR', 'REMOTE_ADDR', 'REQUEST_URI', 'QUERY_STRING']; | |
| 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 | + ]; | |
| 49 | 62 | |
| 50 | 63 | foreach ($vars as $oneVar) { |
| 51 | - if (!empty($_SERVER[$oneVar])) { | |
| 52 | - $source[] = $oneVar.'::'.strip_tags($_SERVER[$oneVar]); | |
| 64 | + $remoteIp = acym_getVar('string', $oneVar, '', 'SERVER'); | |
| 65 | + if (!empty($remoteIp)) { | |
| 66 | + $source[] = $oneVar.'::'.acym_stripTags($remoteIp); | |
| 53 | 67 | } |
| 54 | 68 | } |
| 55 | 69 | $history->source = implode("\n", $source); |
| 56 | 70 | } |
| @@ -67,16 +81,19 @@ | ||
| 67 | 81 | |
| 68 | 82 | return !empty($result); |
| 69 | 83 | } |
| 70 | 84 | |
| 71 | - public function getHistoryOfOneById(int $id): array | |
| 85 | + /** | |
| 86 | + * Get all history lines for one user order by date descending | |
| 87 | + */ | |
| 88 | + public function getHistoryOfOneById(int $userId): array | |
| 72 | 89 | { |
| 73 | - $query = 'SELECT h.*, m.id, m.subject FROM #__acym_'.$this->table.' AS h '; | |
| 74 | - $query .= 'LEFT JOIN #__acym_mail AS m ON h.mail_id = m.id '; | |
| 75 | - $query .= 'WHERE h.user_id = '.intval($id); | |
| 76 | - $query .= ' ORDER BY h.date DESC'; | |
| 77 | - | |
| 78 | - 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 | + ); | |
| 79 | 96 | } |
| 80 | 97 | |
| 81 | 98 | public function getAllUnsubReasons(): array |
| 82 | 99 | { |