|
1 <?php |
|
2 |
|
3 $stats_anonymize_list = array(); |
|
4 |
|
5 eb_hook('startup_early', 'stats_core_cache_anons();'); |
|
6 |
|
7 function stats_core_cache_anons() |
|
8 { |
|
9 global $stats_anonymize_list; |
|
10 if ( $q = eb_mysql_query('SELECT nick FROM stats_anon;') ) |
|
11 { |
|
12 while ( $row = mysql_fetch_assoc($q) ) |
|
13 { |
|
14 $stats_anonymize_list[] = $row['nick']; |
|
15 } |
|
16 } |
|
17 } |
|
18 |
|
19 function stats_log_message($channel, $nick, $timestamp) |
|
20 { |
|
21 // anonymize message? |
|
22 global $stats_anonymize_list; |
|
23 if ( in_array($nick, $stats_anonymize_list) ) |
|
24 { |
|
25 $nick = 'Anonymous'; |
|
26 } |
|
27 |
|
28 $channel = db_escape($channel); |
|
29 $nick = db_escape($nick); |
|
30 $sql = 'INSERT INTO stats_messages(channel, nick, time) ' . "VALUES('$channel', '$nick', " . intval($timestamp) . ");"; |
|
31 eb_mysql_query($sql); |
|
32 } |
|
33 |
|
34 function stats_anonymize_user_now($nick) |
|
35 { |
|
36 global $stats_anonymize_list; |
|
37 // anonymize list is cached in RAM |
|
38 if ( in_array($nick, $stats_anonymize_list) ) |
|
39 { |
|
40 return false; |
|
41 } |
|
42 |
|
43 $stats_anonymize_list[] = $nick; |
|
44 |
|
45 $nick = db_escape($nick); |
|
46 eb_mysql_query("INSERT INTO stats_anon(nick) VALUES('$nick');"); |
|
47 |
|
48 return true; |
|
49 } |
|
50 |
|
51 function stats_anonymize_user_past($nick) |
|
52 { |
|
53 global $stats_anonymize_list; |
|
54 if ( !in_array($nick, $stats_anonymize_list) ) |
|
55 { |
|
56 return false; |
|
57 } |
|
58 |
|
59 $nick = db_escape($nick); |
|
60 eb_mysql_query("UPDATE stats_messages SET nick = 'Anonymous' WHERE nick = '$nick';"); |
|
61 return true; |
|
62 } |
|
63 |
|
64 function stats_denonymize_user($nick) |
|
65 { |
|
66 global $stats_anonymize_list; |
|
67 if ( !in_array($nick, $stats_anonymize_list) ) |
|
68 { |
|
69 return false; |
|
70 } |
|
71 |
|
72 $nick = db_escape($nick); |
|
73 eb_mysql_query("DELETE FROM stats_anon WHERE nick = '$nick';"); |
|
74 |
|
75 unset($stats_anonymize_list[ array_search($nick, $stats_anonymize_list) ]); |
|
76 return true; |
|
77 } |
|
78 |
|
79 function stats_del_user($chan, $nick) |
|
80 { |
|
81 $chan = db_escape($chan); |
|
82 $nick = db_escape($nick); |
|
83 eb_mysql_query("DELETE FROM stats_messages WHERE channel = '$chan' AND nick = '$nick';"); |
|
84 } |
|
85 |