This repository has been archived by the owner on Jan 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
/
friends.php
356 lines (303 loc) · 13.6 KB
/
friends.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
parked();
function purge_neighbors_cache()
{
global $CURUSER;
$cachefile = "cache/" . get_langfolder_cookie() . "/neighbors/" . $CURUSER['id'] . ".html";
if (file_exists($cachefile))
unlink($cachefile);
}
//make_folder("cache/" , get_langfolder_cookie());
//make_folder("cache/" , get_langfolder_cookie() . "/neighbors");
$userid = $CURUSER['id'];
$action = $_GET['action'];
if (!is_valid_id($userid))
stderr($lang_friends['std_error'], $lang_friends['std_invalid_id']."$userid.");
$user = $CURUSER;
// action: add -------------------------------------------------------------
if ($action == 'add')
{
$targetid = $_GET['targetid'];
$type = $_GET['type'];
if (!is_valid_id($targetid))
stderr($lang_friends['std_error'], $lang_friends['std_invalid_id']."$targetid.");
if ($type == 'friend')
{
$table_is = $frag = 'friends';
$field_is = 'friendid';
}
elseif ($type == 'block')
{
$table_is = $frag = 'blocks';
$field_is = 'blockid';
}
else
stderr($lang_friends['std_error'], $lang_friends['std_unknown_type']."$type");
$r = sql_query("SELECT id FROM $table_is WHERE userid=$userid AND $field_is=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($r) == 1)
stderr($lang_friends['std_error'], $lang_friends['std_user_id'].$targetid.$lang_friends['std_already_in'].$table_is.$lang_friends['std_list']);
sql_query("INSERT INTO $table_is VALUES (0,$userid, $targetid)") or sqlerr(__FILE__, __LINE__);
purge_neighbors_cache();
header("Location: " . get_protocol_prefix() . "$BASEURL/friends.php?id=$userid#$frag");
die;
}
// action: delete ----------------------------------------------------------
if ($action == 'delete')
{
$targetid = $_GET['targetid'];
$sure = $_GET['sure'];
$type = $_GET['type'];
if ($type == 'friend')
$typename = $lang_friends['text_friend'];
else $typename = $lang_friends['text_block'];
if (!is_valid_id($targetid))
stderr($lang_friends['std_error'], $lang_friends['std_invalid_id']."$userid.");
if (!$sure)
stderr($lang_friends['std_delete'].$type, $lang_friends['std_delete_note'].$typename.$lang_friends['std_click'].
"<a href=?id=$userid&action=delete&type=$type&targetid=$targetid&sure=1>".$lang_friends['std_here_if_sure'],false);
if ($type == 'friend')
{
sql_query("DELETE FROM friends WHERE userid=$userid AND friendid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr($lang_friends['std_error'], $lang_friends['std_no_friend_found']."$targetid");
$frag = "friends";
}
elseif ($type == 'block')
{
sql_query("DELETE FROM blocks WHERE userid=$userid AND blockid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr($lang_friends['std_error'], $lang_friends['std_no_block_found']."$targetid");
$frag = "blocks";
}
else
stderr($lang_friends['std_error'], $lang_friends['std_unknown_type']."$type");
purge_neighbors_cache();
header("Location: " . get_protocol_prefix() . "$BASEURL/friends.php?id=$userid#$frag");
die;
}
// main body -----------------------------------------------------------------
stdhead($lang_friends['head_personal_lists_for']. $user['username']);
print("<p><table class=main border=0 cellspacing=0 cellpadding=0>".
"<tr><td class=embedded><h1 style='margin:0px'> " . $lang_friends['text_personallist'] . " ".get_username($user[id])."</h1></td></tr></table></p>\n");
//Start: Friends
print("<table class=main width=737 border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>");
print("<br />");
print("<h2 align=left><a name=\"friends\">" . $lang_friends['text_friendlist'] . "</a></h2>\n");
print("<table width=737 border=1 cellspacing=0 cellpadding=5><tr class=tablea><td>");
$i = 0;
unset($friend_id_arr);
$res = sql_query("SELECT f.friendid as id, u.last_access, u.class, u.avatar, u.title FROM friends AS f LEFT JOIN users as u ON f.friendid = u.id WHERE userid=$userid ORDER BY id") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
$friends = $lang_friends['text_friends_empty'];
else
while ($friend = mysql_fetch_array($res))
{
$friend_id_arr[] = $friend["id"];
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"],false,true,true);
$body1 = get_username($friend["id"]) .
" ($title)<br /><br />".$lang_friends['text_last_seen_on']. gettime($friend['last_access'],true, false);
$body2 = "<a href=friends.php?id=$userid&action=delete&type=friend&targetid=" . $friend['id'] . ">".$lang_friends['text_remove_from_friends']."</a>".
"<br /><br /><a href=sendmessage.php?receiver=" . $friend['id'] . ">".$lang_friends['text_send_pm']."</a>";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = "pic/default_avatar.png";
if ($i % 2 == 0)
print("<table width=100% style='padding: 0px'><tr><td class=bottom style='padding: 5px' width=50% align=center>");
else
print("<td class=bottom style='padding: 5px' width=50% align=center class=tablea>");
print("<table class=main width=100% height=75px class=tablea>");
print("<tr valign=top class=tableb><td width=75 align=center style='padding: 0px'>" .
($avatar ? "<div style='width:75px;height:75px;overflow: hidden'><img width=75px src=\"$avatar\"></div>" : ""). "</td><td>\n");
print("<table class=main>");
print("<tr><td class=embedded style='padding: 5px' width=80%>$body1</td>\n");
print("<td class=embedded style='padding: 5px' width=20%>$body2</td></tr>\n");
print("</table>");
print("</td></tr>");
print("</td></tr></table>\n");
if ($i % 2 == 1)
print("</td></tr></table>\n");
else
print("</td>\n");
$i++;
}
if ($i % 2 == 1)
print("<td class=bottom width=50%> </td></tr></table>\n");
print($friends);
print("</td></tr></table><br />\n");
//End: Friends
//Start: Neighbors
/*
print("<table class=main width=737 border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>");
print("<br />");
print("<h2 align=left><a name=\"friendsadded\">".$lang_friends['text_neighbors']."</a></h2>\n");
print("<table width=737 border=1 cellspacing=0 cellpadding=5><tr class=tablea><td>");
$i = 0;
$cachefile = "cache/" . get_langfolder_cookie() . "/neighbors/" . $CURUSER['id'] . ".html";
$cachetime = 24 * 60 * 60; // 1 day
if (file_exists($cachefile) && (time() - $cachetime< filemtime($cachefile)))
{
include($cachefile);
}
else
{
ob_start(); // start the output buffer
$user_snatched = sql_query("SELECT * FROM snatched WHERE userid = $CURUSER[id]") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($user_snatched) == 0)
$neighbors_info = $lang_friends['text_neighbors_empty'];
else
{
while ($user_snatched_arr = mysql_fetch_array($user_snatched))
{
$torrent_2_user_value = get_torrent_2_user_value($user_snatched_arr);
$user_snatched_res_target = sql_query("SELECT * FROM snatched WHERE torrentid = " . $user_snatched_arr['torrentid'] . " AND userid != " . $user_snatched_arr['userid']) or sqlerr(__FILE__, __LINE__); //
if(mysql_num_rows($user_snatched_res_target)>0) // have other peole snatched this torrent
{
while($user_snatched_arr_target = mysql_fetch_array($user_snatched_res_target)) // find target user's current analyzing torrent's snatch info
{
$torrent_2_user_value_target = get_torrent_2_user_value($user_snatched_arr_target); //get this torrent to target user's value
if(!isset($other_user_2_curuser_value[$user_snatched_arr_target['userid']])) // first, set to 0
$other_user_2_curuser_value[$user_snatched_arr_target['userid']] = 0.0;
$other_user_2_curuser_value[$user_snatched_arr_target['userid']] += $torrent_2_user_value_target * $torrent_2_user_value;
}
}
}
arsort($other_user_2_curuser_value,SORT_NUMERIC);
$counter = 0;
$total_user = count($other_user_2_curuser_value);
while(1)
{
list($other_user_2_curuser_value_key, $other_user_2_curuser_value_val) = each($other_user_2_curuser_value);
//print(" userid: " . $other_user_2_curuser_value_key . " value: " . $other_user_2_curuser_value_val . "<br />");
$neighbors_res = sql_query("SELECT * FROM users WHERE id = " . intval($other_user_2_curuser_value_key)) or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($neighbors_res) == 1)
{
$neighbors_arr = mysql_fetch_array($neighbors_res) or sqlerr(__FILE__, __LINE__);
if($neighbors_arr['enabled'] == 'yes')
{
$title = $neighbors_arr["title"];
if (!$title)
$title = get_user_class_name($neighbors_arr["class"],false,true,true);
$body1 = get_username($neighbors_arr["id"]) .
" ($title)<br /><br />".$lang_friends['text_last_seen_on']. gettime($neighbors_arr['last_access'], true, false);
$body2 = ((empty($friend_id_arr)||(!in_array($neighbors_arr["id"],$friend_id_arr))) ? "<a href=friends.php?id=$userid&action=add&type=friend&targetid=" . $neighbors_arr['id'] . ">".$lang_friends['text_add_to_friends']."</a>" : "<a href=friends.php?id=$userid&action=delete&type=friend&targetid=" . $neighbors_arr['id'] . ">".$lang_friends['text_remove_from_friends']."</a>") .
"<br /><br /><a href=sendmessage.php?receiver=" . $neighbors_arr['id'] . ">".$lang_friends['text_send_pm']."</a>";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($neighbors_arr["avatar"]) : "");
if (!$avatar)
$avatar = "pic/default_avatar.png";
if ($i % 2 == 0)
print("<table width=100% style='padding: 0px'><tr><td class=bottom style='padding: 5px' width=50% align=center>");
else
print("<td class=bottom style='padding: 5px' width=50% align=center>");
print("<table class=main width=100% height=75px>");
print("<tr valign=top><td width=75 align=center style='padding: 0px'>" .
($avatar ? "<div style='width:75px;height:75px;overflow: hidden'><img width=75px src=\"$avatar\"></div>" : ""). "</td><td>\n");
print("<table class=main>");
print("<tr><td class=embedded style='padding: 5px' width=80%>$body1</td>\n");
print("<td class=embedded style='padding: 5px' width=20%>$body2</td></tr>\n");
print("</table>");
print("</td></tr>");
print("</td></tr></table>\n");
if ($i % 2 == 1)
print("</td></tr></table>\n");
else
print("</td>\n");
$i++;
$counter++;
}
}
$total_user--;
if($counter == 20 || $total_user<=0) break; //only the largest 20
}
}
if ($i % 2 == 1)
print("<td class=bottom width=50%> </td></tr></table>\n");
print($neighbors_info);
print("</td></tr></table></table><br />\n");
// CACHE END //////////////////////////////////////////////////
// open the cache file for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
/////////////////////////////////////////////////////////
}
if(mysql_num_rows($friendadd) == 0)
$friendsno = $lang_friends['text_friends_empty'];
else
while ($friend = mysql_fetch_array($friendadd))
{
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"],false,true,true);
$body1 = get_username($friend["fuid"]) .
" ($title)<br /><br />".$lang_friends['text_last_seen_on']. $friend['last_access'] .
"<br />(" . get_elapsed_time(strtotime($friend[last_access])) . $lang_friends['text_ago'].")";
$body2 = "<a href=friends.php?id=$userid&action=add&type=friend&targetid=" . $friend['fuid'] . ">".$lang_friends['text_add_to_friends']."</a>".
"<br /><br /><a href=sendmessage.php?receiver=" . $friend['fuid'] . ">".$lang_friends['text_send_pm']."</a>";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = "pic/default_avatar.png";
if ($i % 2 == 0)
print("<table width=100% style='padding: 0px'><tr><td class=bottom style='padding: 5px' width=50% align=center>");
else
print("<td class=bottom style='padding: 5px' width=50% align=center class=tablea>");
print("<table class=main width=100% height=75px class=tablea>");
print("<tr valign=top class=tableb><td width=75 align=center style='padding: 0px'>" .
($avatar ? "<div style='width:75px;height:75px;overflow: hidden'><img width=75px src=\"$avatar\"></div>" : ""). "</td><td>\n");
print("<table class=main>");
print("<tr><td class=embedded style='padding: 5px' width=80%>$body1</td>\n");
print("<td class=embedded style='padding: 5px' width=20%>$body2</td></tr>\n");
print("</table>");
print("</td></tr>");
print("</td></tr></table>\n");
if ($i % 2 == 1)
print("</td></tr></table>\n");
else
print("</td>\n");
$i++;
}
if ($i % 2 == 1)
print("<td class=bottom width=50%> </td></tr></table>\n");
print($neighbors_info);
print("</td></tr></table></table><br />\n");
*/
//End: Neighbors
$res = sql_query("SELECT blockid as id FROM blocks WHERE userid=$userid ORDER BY id") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
$blocks = $lang_friends['text_blocklist_empty'];
else
{
$i = 0;
$blocks = "<table width=100% cellspacing=0 cellpadding=0>";
while ($block = mysql_fetch_array($res))
{
if ($i % 6 == 0)
$blocks .= "<tr>";
$blocks .= "<td style='border: none; padding: 4px; spacing: 0px;'>[<font class=small><a href=friends.php?id=$userid&action=delete&type=block&targetid=" .
$block['id'] . ">D</a></font>] " . get_username($block["id"]) . "</td>";
if ($i % 6 == 5)
$blocks .= "</tr>";
$i++;
}
$blocks .= "</table>\n";
}
print("<br /><br />");
print("<table class=main width=737 border=0 cellspacing=0 cellpadding=5><tr><td class=embedded>");
print("<h2 align=left><a name=\"blocks\">".$lang_friends['text_blocked_users']."</a></h2></td></tr>");
print("<tr class=tableb><td style='padding: 10px;'>");
print($blocks);
print("</td></tr></table>\n");
print("</td></tr></table>\n");
if (get_user_class() >= $viewuserlist_class)
print("<p><a href=users.php><b>".$lang_friends['text_find_user']."</b></a></p>");
stdfoot();
?>