forked from NoahY/q2a-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-history-check.php
140 lines (112 loc) · 3.03 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
<?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'
);
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;
}
}