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 -107 10.10.2 → 11.1.1 View file →
@@ -1,107 +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(int $userId, string $action, array $data = [], int $mailid = 0, $unsubscribe_reason = null): void
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 - $history->ip = acym_getIP();
45 -
46 - if (!empty($_SERVER)) {
47 - $source = [];
48 - $vars = ['HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_ADDR', 'REMOTE_ADDR', 'REQUEST_URI', 'QUERY_STRING'];
49 -
50 - foreach ($vars as $oneVar) {
51 - if (!empty($_SERVER[$oneVar])) {
52 - $source[] = $oneVar.'::'.strip_tags($_SERVER[$oneVar]);
53 - }
54 - }
55 - $history->source = implode("\n", $source);
56 - }
57 -
58 - try {
59 - acym_insertObject('#__acym_history', $history);
60 - } catch (\Exception $e) {
61 - }
62 - }
63 -
64 - private function alreadyExists(int $userId, int $time): bool
65 - {
66 - $result = acym_loadResult('SELECT user_id FROM #__acym_history WHERE user_id = '.intval($userId).' AND date = '.intval($time));
67 -
68 - return !empty($result);
69 - }
70 -
71 - public function getHistoryOfOneById(int $id): array
72 - {
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);
79 - }
80 -
81 - public function getAllUnsubReasons(): array
82 - {
83 - $query = 'SELECT `action`, `data`, `unsubscribe_reason` FROM #__acym_history WHERE `action` = "unsubscribed" AND `unsubscribe_reason` != ""';
84 -
85 - return acym_loadObjectList($query);
86 - }
87 -
88 - public function getAllMainLanguageUnsubReasons(): array
89 - {
90 - $allUnsubReasons = $this->config->get('unsub_survey', '{}');
91 -
92 - return json_decode($allUnsubReasons, true);
93 - }
94 -
95 - public function getUnsubscribeReasonText($index)
96 - {
97 - $surveyAnswers = json_decode($this->config->get('unsub_survey'), true);
98 - if (is_numeric($index)) {
99 - $index = $index - 1;
100 - $reason = $surveyAnswers[$index] ?? $index;
101 - } else {
102 - $reason = $index;
103 - }
104 -
105 - return $reason;
106 - }
107 -}