-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate_chat_logs.php
91 lines (63 loc) · 2.42 KB
/
generate_chat_logs.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
<?php
require('/var/www/html/config.php');
$mysqli = new mysqli($dbhost, $dbuser, $dbpasswd, $dbname);
//if ($purgeDelay < (time() - 3600) || !isset($purgeDelay)) {
// SQL Query to select messages for purge:
$sql = 'SELECT
userName,
channel AS channelID,
UNIX_TIMESTAMP(dateTime) AS timeStamp,
text,
dateTime
FROM
ajax_chat_messages
WHERE channel = 0
ORDER BY id';
$result = $mysqli->query($sql);
// Store result for logging:
$logMsg = '';
while($row = $result->fetch_assoc()) {
if ($row['username'] == 'HAL') { continue; }
$row['username'] = str_replace(" ","_",$row['username']);
$bbcode = array('[b]','[/b]','[i]','[/i]');
$replacements = array ('','','','');
$row['text'] = str_replace($bbcode,$replacements,$row['text']);
$bbcode = array ('/(\[url=)(.+)(\])(.+)(\[\/url\])/','/(\[color=)(.+)(\])(.+)(\[\/color\])/');
$replacements = array ('\\4','\\4');
$row['text'] = preg_replace($bbcode, $replacements, $row['text']);
$privmsg = ereg('/privmsg', $row['text']);
$join = ereg('/channelEnter', $row['text']);
$part = ereg('/channelLeave', $row['text']);
$logout = ereg('/logout', $row['text']);
$delete = ereg('/delete', $row['text']);
if (($privmsg == false) && ($join == false) && ($part == false) && ($logout == false) && ($delete == false) && ($row['channelID'] == 0)) {
$logMsg .= date('M d H:i:s', $row['timeStamp']). ' ';
if (ereg('/me', $row['text'])) {
$logMsg .= '* '.$row['userName'].' ';
$logMsg .= preg_replace("#^/me #","",$row['text'])."\n";
} else {
$logMsg .= '<'.$row['userName'].'> ';
$logMsg .= $row['text']."\n";
}
}
}
$result->close();
$mysqli->close();
// Files are rotated every week, labelled by week number, month, and year.
// File container where all messages are logged:
$fileContainer = '/var/www/stats.roleplaygateway.com/chat.log';
$fileDirectory = '/var/www/stats.roleplaygateway.com/';
// Check to make sure directory is writable:
if(is_writable($fileDirectory)) {
// Open the said file:
$filePointer = fopen($fileContainer,"w+");
// Write log messages to file:
fputs($filePointer,$logMsg);
// Close the open said file after writing:
fclose($filePointer);
} else {
die('cannot write to directory');
}
$purgeDelay = time();
//}
?>