This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
userhistory.php
297 lines (186 loc) · 9.11 KB
/
userhistory.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
<?php
/*
+------------------------------------------------
| TBDev.net BitTorrent Tracker PHP
| =============================================
| by CoLdFuSiOn
| (c) 2003 - 2011 TBDev.Net
| http://www.tbdev.net
| =============================================
| svn: http://sourceforge.net/projects/tbdevnet/
| Licence Info: GPL
+------------------------------------------------
| $Date$
| $Revision$
| $Author$
| $URL$
+------------------------------------------------
*/
ob_start("ob_gzhandler");
require_once "include/bittorrent.php";
require_once "include/user_functions.php";
require_once "include/pager_functions.php";
require_once "include/html_functions.php";
require_once "include/bbcode_functions.php";
dbconn(false);
loggedinorreturn();
$lang = array_merge( load_language('global'), load_language('userhistory') );
$userid = (int)$_GET["id"];
if (!is_valid_id($userid)) stderr($lang['stderr_errorhead'], $lang['stderr_invalidid']);
if ($CURUSER['class']< UC_POWER_USER || ($CURUSER["id"] != $userid && $CURUSER['class'] < UC_MODERATOR))
stderr($lang['stderr_errorhead'], $lang['stderr_perms']);
$page = (isset($_GET['page'])?$_GET["page"]:''); // not used?
$action = (isset($_GET['action'])?$_GET["action"]:'');
//-------- Global variables
$perpage = 15;
$HTMLOUT = '';
//-------- Action: View posts
if ($action == "viewposts")
{
$select_is = "COUNT(DISTINCT p.id)";
$from_is = "posts AS p LEFT JOIN topics as t ON p.topicid = t.id LEFT JOIN forums AS f ON t.forumid = f.id";
$where_is = "p.userid = $userid AND f.minclassread <= " . $CURUSER['class'];
$order_is = "p.id DESC";
$query = "SELECT $select_is FROM $from_is WHERE $where_is";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or stderr($lang['stderr_errorhead'], $lang['top_noposts']);
$postcount = $arr[0];
//------ Make page menu
$pager = pager($perpage, $postcount, "userhistory.php?action=viewposts&id=$userid&");
//------ Get user data
$res = mysql_query("SELECT username, donor, warned, enabled FROM users WHERE id=$userid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 1)
{
$arr = mysql_fetch_assoc($res);
$uname = htmlsafechars( $arr['username'] );
$subject = "<a href='userdetails.php?id=$userid'><strong>$uname</strong></a>" . get_user_icons($arr, true);
}
else
$subject = $lang['posts_unknown'].'['.$userid.']';
//------ Get posts
$from_is = "posts AS p LEFT JOIN topics as t ON p.topicid = t.id LEFT JOIN forums AS f ON t.forumid = f.id LEFT JOIN users u ON p.editedby = u.id LEFT JOIN readposts as r ON p.topicid = r.topicid AND p.userid = r.userid";
$select_is = "f.id AS f_id, f.name, t.id AS t_id, t.subject, t.lastpost, r.lastpostread, p.*, u.username AS editname";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is {$pager['limit']}";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0) stderr($lang['stderr_errorhead'], $lang['top_noposts']);
$HTMLOUT .= "<h1>{$lang['top_posthfor']} $subject</h1>\n";
if ($postcount > $perpage)
$HTMLOUT .= $pager['pagertop'];
//------ Print table
$HTMLOUT .= begin_main_frame();
$HTMLOUT .= begin_frame();
while ($arr = mysql_fetch_assoc($res))
{
$postid = $arr['id'];
$posterid = $arr['userid'];
$topicid = $arr['t_id'];
$topicname = htmlsafechars( $arr['subject'] );
$forumid = $arr['f_id'];
$forumname = htmlsafechars( $arr['name'] );
$dt = (TIME_NOW - $TBDEV['readpost_expiry']);
$newposts = 0;
if ($arr['added'] > $dt)
$newposts = ($arr['lastpostread'] < $arr['lastpost']) && $CURUSER['id'] == $userid;
$added = get_date( $arr['added'],'');
$HTMLOUT .= "<div class='sub'>
<table border='0' cellspacing='0' cellpadding='0'>
<tr><td class='embedded'>
$added -- <b>{$lang['posts_forum']}: </b>
<a href='forums.php?action=viewforum&forumid=$forumid'>$forumname</a>
-- <b>{$lang['posts_topic']}: </b>
<a href='forums.php?action=viewtopic&topicid=$topicid'>$topicname</a>
-- <b>{$lang['posts_post']}: </b>
#<a href='forums.php?action=viewtopic&topicid=$topicid&page=p$postid#$postid'>$postid</a>" .
($newposts ? " <b>(<font color='red'>{$lang['posts_new']}</font>)</b>" : "") .
"</td></tr>
</table>
</div>\n";
$HTMLOUT .= begin_table(true);
$body = format_comment($arr['body']);
if (is_valid_id($arr['editedby']))
{
$body .= "<p><font size='1' class='small'>{$lang['posts_lasteditedby']} <a href='userdetails.php?id={$arr['editedby']}'><b>".htmlsafechars( $arr['editname'] )."</b></a> {$lang['posts_at']} ".get_date( $arr['editedat'],'')." GMT</font></p>\n";
}
$HTMLOUT .= "<tr valign='top'><td class='comment'>$body</td></tr>\n";
$HTMLOUT .= end_table();
}
$HTMLOUT .= end_frame();
$HTMLOUT .= end_main_frame();
if ($postcount > $perpage)
$HTMLOUT .= $pager['pagerbottom'];
print stdhead($lang['head_post']) . $HTMLOUT . stdfoot();
die;
}
//-------- Action: View comments
if ($action == "viewcomments")
{
$select_is = "COUNT(*)";
// LEFT due to orphan comments
$from_is = "comments AS c LEFT JOIN torrents as t
ON c.torrent = t.id";
$where_is = "c.user = $userid";
$order_is = "c.id DESC";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or stderr($lang['stderr_errorhead'], $lang['top_nocomms']);
$commentcount = $arr[0];
//------ Make page menu
$pager = pager($perpage, $commentcount, "userhistory.php?action=viewcomments&id=$userid&");
//------ Get user data
$res = mysql_query("SELECT username, donor, warned, enabled FROM users WHERE id=$userid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 1)
{
$arr = mysql_fetch_assoc($res);
$subject = "<a href='userdetails.php?id=$userid'><b>$arr[username]</b></a>" . get_user_icons($arr, true);
}
else
$subject = $lang['posts_unknown'].'['.$userid.']';
//------ Get comments
$select_is = "t.name, c.torrent AS t_id, c.id, c.added, c.text";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is {$pager['limit']}";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0) stderr($lang['stderr_errorhead'], $lang['top_nocomms']);
$HTMLOUT .= "<h1>{$lang['top_commhfor']} $subject</h1>\n";
if ($commentcount > $perpage)
$HTMLOUT .= $pager['pagertop'];
//------ Print table
$HTMLOUT .= begin_main_frame();
$HTMLOUT .= begin_frame();
while ($arr = mysql_fetch_assoc($res))
{
$commentid = $arr["id"];
$torrent = $arr["name"];
// make sure the line doesn't wrap
if (strlen($torrent) > 55) $torrent = substr($torrent,0,52) . "...";
$torrentid = $arr["t_id"];
//find the page; this code should probably be in details.php instead
$subres = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent = $torrentid AND id < $commentid")
or sqlerr(__FILE__, __LINE__);
$subrow = mysql_fetch_row($subres);
$count = $subrow[0];
$comm_page = floor($count/20);
$page_url = $comm_page?"&page=$comm_page":"";
$added = get_date( $arr['added'],'') . " (" . get_date( $arr['added'],'',0,1) . ")";
$HTMLOUT .= "<div class='sub'><table border='0' cellspacing='0' cellpadding='0'><tr><td class='embedded'>".
"$added --- <b>{$lang['posts_torrent']}: </b>".
($torrent?("<a href='details.php?id=$torrentid&tocomm=1'>$torrent</a>"):" [{$lang['posts_del']}] ").
" --- <b>{$lang['posts_comment']}: </b>#<a href='details.php?id=$torrentid&tocomm=1$page_url'>$commentid</a>
</td></tr></table></div>\n";
$HTMLOUT .= begin_table(true);
$body = format_comment($arr["text"]);
$HTMLOUT .= "<tr valign='top'><td class='comment'>$body</td></tr>\n";
$HTMLOUT .= end_table();
}
$HTMLOUT .= end_frame();
$HTMLOUT .= end_main_frame();
if ($commentcount > $perpage)
$HTMLOUT .= $pager['pagerbottom'];
print stdhead($lang['head_comm']) . $HTMLOUT . stdfoot();
die;
}
//-------- Handle unknown action
if ($action != "")
stderr($lang['stderr_histerrhead'], $lang['stderr_unknownact']);
//-------- Any other case
stderr($lang['stderr_histerrhead'], $lang['stderr_invalidq']);
?>