forked from CSS-Tricks/Chat2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README for Whispering.txt
125 lines (91 loc) · 1.89 KB
/
README for Whispering.txt
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
-----------
Add Whispering in Chat v2, by Christian Mehler
--------------
Changes to chat.js:
function Chat (filetxt, user) {
file = filetxt;
usernameid = user;
this.init = chatInit;
this.update = updateChat;
this.send = sendChat;
this.getState = getStateOfChat;
this.trim = trimstr;
this.getUsers = getuserlist;
}
function updateChat(){
$.ajax({
type: "GET",
url: "update.php",
data: {
'state': state,
'file' : file,
'nickname': usernameid
},
dataType: "json",
...
function getuserlist(room, username) {
roomid = room;
usernameid = username;
$.ajax({
type: "GET",
url: "userlist.php",
data: {
'room' : room,
'username': username,
'current' : numOfUsers
},
dataType: "json",
cache: false,
success: function(data) {
if (numOfUsers != data.numOfUsers) {
numOfUsers = data.numOfUsers;
var list = "
Current Chatters
";
for (var i = 0; i < data.userlist.length; i++) {
list += '
'+ data.userlist[i] +"
";
}
$('#userlist').html($("
"+ list +"
"));
}
setTimeout('getuserlist(roomid, usernameid)', 1);
},
});
}
function wisper(to)
{
$('#sendie').val('@'+to+' '+$('#sendie').val());
}
---------
Changes to process.php (other saving):
---------
fwrite(fopen($file, 'a'), $nickname . "~\t~" . $message = str_replace("\n", " ", $message) . "\n");
---------
Changes to update.php
---------
- at the beginning add
$nickname = htmlentities(strip_tags($_GET['nickname']), ENT_QUOTES);
-later
...
if ($state == $count) {
$log['state'] = $state;
$log['t'] = "continue";
} else {
$text= array();
$log['state'] = $state + getlines(getfile($file)) - $state;
foreach (getfile($file) as $line_num => $line) {
if ($line_num >= $state) {
$line = explode("~\t~", $line);
if(substr($line[1], 0, 1)!='@')
$text[] = ''.$line[0].''.$line[1];
elseif($line[0]==$nickname || substr($line[1], 0, strlen('@'.$nickname))=='@'.$nickname)
$text[] = ''.$line[0].' '.$line[1].'';
}
$log['text'] = $text;
}
}
echo json_encode($log);
?>