forked from svivian/q2a-user-activity-plus
-
Notifications
You must be signed in to change notification settings - Fork 3
/
qa-history-check.php
182 lines (147 loc) · 4.17 KB
/
qa-history-check.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
class history_check {
// main event processing function
function process_event($event, $userid, $handle, $cookieid, $params) {
if(!qa_opt('event_logger_to_database')) return;
$twoway = array(
'a_select',
'a_unselect',
'q_vote_up',
'a_vote_up',
'q_vote_down',
'a_vote_down',
'q_vote_nil',
'a_vote_nil',
'q_flag',
'a_flag',
'c_flag',
'q_unflag',
'a_unflag',
'c_unflag',
'u_edit',
'u_level',
'u_block',
'u_unblock',
);
$special = array(
'a_post',
'c_post'
);
//$undo = array('a_unselect', 'q_vote_nil', 'a_vote_nil','q_unflag', 'a_unflag', 'c_unflag');
/*
if(in_array($event, $undo)) {
$uid = qa_db_read_one_value(
qa_db_query_sub(
'SELECT userid FROM ^posts WHERE postid=#',
$params['postid']
),
true
);
$events = array(
'a_unselect' => "'in_a_select'",
'q_vote_nil' => "'in_q_vote_up','in_q_vote_down'",
'a_vote_nil' => "'in_a_vote_up','in_a_vote_down'",
'q_unflag' => "'in_q_flag'",
'a_unflag' => "'in_a_flag'",
'c_unflag' => "'in_c_flag'"
);
foreach($events as $out => $in) {
if($out == $event) {
$eventa = qa_db_read_one_assoc(
qa_db_query_sub(
'SELECT * FROM ^eventlog WHERE datetime=(SELECT MAX(datetime) FROM ^eventlog AS e2 WHERE event IN ('.$in.') AND params LIKE $ AND userid=#)',
'%postid='.$params['postid'].'%',$uid
),
true
);
qa_db_query_sub(
'DELETE FROM ^eventlog WHERE event=$ AND params=$ AND datetime=$ AND userid=$',
$eventa['event'],$eventa['params'],$eventa['datetime'],$eventa['userid']
);
}
}
}
*/
if(in_array($event, $twoway)) {
if(strpos($event,'u_') === 0) {
$uid = $params['userid'];
}
else {
$uid = qa_db_read_one_value(
qa_db_query_sub(
'SELECT userid FROM ^posts WHERE postid=#',
$params['postid']
),
true
);
}
if($uid != $userid) {
$ohandle = $this->getHandleFromId($uid);
$oevent = 'in_'.$event;
$paramstring='';
foreach ($params as $key => $value)
$paramstring.=(strlen($paramstring) ? "\t" : '').$key.'='.$this->value_to_text($value);
qa_db_query_sub(
'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
'VALUES (NOW(), $, $, $, #, $, $)',
qa_remote_ip_address(), $uid, $ohandle, $cookieid, $oevent, $paramstring
);
}
}
// comments and answers
if(in_array($event,$special)) {
$pid = qa_db_read_one_value(
qa_db_query_sub(
'SELECT userid FROM ^posts WHERE postid=#',
$params['parentid']
),
true
);
if($pid != $userid) {
$ohandle = $this->getHandleFromId($pid);
switch($event) {
case 'a_post':
$oevent = 'in_a_question';
break;
case 'c_post':
if ($params['parenttype'] == 'Q')
$oevent = 'in_c_question';
else
$oevent = 'in_c_answer';
break;
}
$paramstring='';
foreach ($params as $key => $value)
$paramstring.=(strlen($paramstring) ? "\t" : '').$key.'='.$this->value_to_text($value);
qa_db_query_sub(
'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
'VALUES (NOW(), $, $, $, #, $, $)',
qa_remote_ip_address(), $pid, $ohandle, $cookieid, $oevent, $paramstring
);
}
}
}
// worker functions
function value_to_text($value)
{
if (is_array($value))
$text='array('.count($value).')';
elseif (strlen($value)>40)
$text=substr($value, 0, 38).'...';
else
$text=$value;
return strtr($text, "\t\n\r", ' ');
}
function getHandleFromId($userid) {
require_once QA_INCLUDE_DIR.'qa-app-users.php';
if (QA_FINAL_EXTERNAL_USERS) {
$publictohandle=qa_get_public_from_userids(array($userid));
$handle=@$publictohandle[$userid];
}
else {
$user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
$handle = @$user['handle'];
}
return $handle;
}
}