-
Notifications
You must be signed in to change notification settings - Fork 28
/
browse.php
407 lines (404 loc) · 17.6 KB
/
browse.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
/**
|--------------------------------------------------------------------------|
| https://github.com/Bigjoos/ |
|--------------------------------------------------------------------------|
| Licence Info: GPL |
|--------------------------------------------------------------------------|
| Copyright (C) 2010 U-232 V4 |
|--------------------------------------------------------------------------|
| A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon. |
|--------------------------------------------------------------------------|
| Project Leaders: Mindless,putyn. |
|--------------------------------------------------------------------------|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( U | - | 2 | 3 | 2 )-( S | o | u | r | c | e )-( C | o | d | e )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
*/
require_once (dirname(__FILE__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'bittorrent.php');
require_once (INCL_DIR . 'user_functions.php');
require_once INCL_DIR . 'torrenttable_functions.php';
require_once INCL_DIR . 'pager_functions.php';
require_once (INCL_DIR . 'searchcloud_functions.php');
require_once (CLASS_DIR . 'class_user_options.php');
require_once (CLASS_DIR . 'class_user_options_2.php');
dbconn(false);
loggedinorreturn();
if (isset($_GET['clear_new']) && $_GET['clear_new'] == 1) {
sql_query("UPDATE users SET last_browse=" . TIME_NOW . " WHERE id=" . sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
$mc1->begin_transaction('MyUser_' . $CURUSER['id']);
$mc1->update_row(false, array(
'last_browse' => TIME_NOW
));
$mc1->commit_transaction($INSTALLER09['expires']['curuser']);
$mc1->begin_transaction('user' . $CURUSER['id']);
$mc1->update_row(false, array(
'last_browse' => TIME_NOW
));
$mc1->commit_transaction($INSTALLER09['expires']['user_cache']);
header("Location: {$INSTALLER09['baseurl']}/browse.php");
}
$stdfoot = array(
/** include js **/
'js' => array(
'java_klappe',
'wz_tooltip'
)
);
$stdhead = array(
/** include css **/
'css' => array(
'browse'
)
);
$lang = array_merge(load_language('global') , load_language('browse') , load_language('torrenttable_functions'));
if (function_exists('parked')) parked();
$HTMLOUT = $searchin = $select_searchin = $where = $addparam = $new_button = $search_help_boolean = $vip_box = $only_free = '';
$HTMLOUT .='<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function(){
$("#help_open").click(function(){
$("#help").slideToggle("slow", function() {
});
});
})
/*]]>*/
</script>';
$search_help_boolean = '<table border="0" cellspacing="0" cellpadding="0" style="max-width:600px;" align="center">
<tr>
<td class="two"><div id="help" style="display:none"><h1>The boolean search supports the following operators:</h1>
<span style="font-weight: bold;">+</span> A leading plus sign indicates that this word must be present.<br /><br />
<span style="font-weight: bold;">-</span> A leading minus sign indicates that this word must not be present.<br /><br />
By default (when neither + nor - is specified) the word is optional, but results that contain it are rated higher. <br /><br />
<span style="font-weight: bold;">*</span> The asterisk serves as the wildcard operator. Unlike the other operators, it should be appended to the word to be affected. Words match if they begin with the word preceding the * operator.<br /><br />
<span style="font-weight: bold;">> <</span> These two operators are used to change a word\'s contribution to the relevance value that is assigned to a word. The > operator increases the contribution and the < operator decreases it.<br /><br />
<span style="font-weight: bold;">~</span> A leading tilde acts as a negation operator, causing the word\'s contribution to the words\'s relevance to be negative. A row containing such a word is rated lower than others, but is not excluded altogether, as it would be with the - operator.<br /><br />
<span style="font-weight: bold;">" "</span> A phrase that is enclosed within double quotes return only results that contain the phrase literally, as it was typed. <br /><br />
<span style="font-weight: bold;">( )</span> Parentheses group words into subexpressions. Parenthesized groups can be nested.<br /><br /></div></td>
</tr></table>';
$cats = genrelist();
if (isset($_GET["search"])) {
$searchstr = unesc($_GET["search"]);
$cleansearchstr = searchfield($searchstr);
if (empty($cleansearchstr)) unset($cleansearchstr);
}
$valid_searchin = array(
'title' => array(
'name'
) ,
'descr' => array(
'descr'
) ,
'genre' => array(
'newgenre'
) ,
'all' => array(
'name',
'newgenre',
'descr'
)
);
if (isset($_GET['searchin']) && isset($valid_searchin[$_GET['searchin']])) {
$searchin = $valid_searchin[$_GET['searchin']];
$select_searchin = $_GET['searchin'];
$addparam.= sprintf('search=%s&searchin=%s&', $searchstr, $select_searchin);
}
if (isset($_GET['sort']) && isset($_GET['type'])) {
$column = $ascdesc = '';
$_valid_sort = array(
'id',
'name',
'numfiles',
'comments',
'added',
'size',
'times_completed',
'seeders',
'leechers',
'owner'
);
$column = isset($_GET['sort']) && isset($_valid_sort[(int)$_GET['sort']]) ? $_valid_sort[(int)$_GET['sort']] : $_valid_sort[0];
switch (htmlsafechars($_GET['type'])) {
case 'asc':
$ascdesc = "ASC";
$linkascdesc = "asc";
break;
case 'desc':
$ascdesc = "DESC";
$linkascdesc = "desc";
break;
default:
$ascdesc = "DESC";
$linkascdesc = "desc";
break;
}
$orderby = "ORDER BY {$column} " . $ascdesc;
$pagerlink = "sort=" . intval($_GET['sort']) . "&type={$linkascdesc}&";
} else {
$orderby = "ORDER BY sticky ASC, id DESC";
$pagerlink = "";
}
$wherea = $wherecatina = array();
if (isset($_GET["incldead"]) && $_GET["incldead"] == 1) {
$addparam.= "incldead=1&";
if (!isset($CURUSER) || $CURUSER["class"] < UC_ADMINISTRATOR) $wherea[] = "banned != 'yes'";
} else {
if (isset($_GET["incldead"]) && $_GET["incldead"] == 2) {
$addparam.= "incldead=2&";
$wherea[] = "visible = 'no'";
} else $wherea[] = "visible = 'yes'";
}
//=== added an only free torrents option \\o\o/o//
if (isset($_GET['only_free']) && $_GET['only_free'] == 1) {
if (XBT_TRACKER == true ? $wherea[] = "freetorrent >= '1'" : $wherea[] = "free >= '1'");
//$wherea[] = "free >= '1'";
$addparam.= "only_free=1&";
}
//=== added an only VIP torrents option - TheGene
if (isset($_GET['vip']) && $_GET['vip'] == 1) {
$wherea[] = "vip = '1'";
$addparam.= "vip=1&";
}
$category = (isset($_GET["cat"])) ? (int)$_GET["cat"] : false;
$all = isset($_GET["all"]) ? $_GET["all"] : false;
if (!$all) {
if (!$_GET && $CURUSER["notifs"]) {
$all = true;
foreach ($cats as $cat) {
$all&= $cat['id'];
if (strpos($CURUSER["notifs"], "[cat" . $cat['id'] . "]") !== false) {
$wherecatina[] = $cat['id'];
$addparam.= "c{$cat['id']}=1&";
}
}
} elseif ($category) {
if (!is_valid_id($category)) stderr("{$lang['browse_error']}", "{$lang['browse_invalid_cat']}");
$wherecatina[] = $category;
$addparam.= "cat=$category&";
} else {
$all = true;
foreach ($cats as $cat) {
$all&= isset($_GET["c{$cat['id']}"]);
if (isset($_GET["c{$cat['id']}"])) {
$wherecatina[] = $cat['id'];
$addparam.= "c{$cat['id']}=1&";
}
}
}
}
if ($all) {
$wherecatina = array();
$addparam = "";
}
if (count($wherecatina) > 1) $wherea[] = 'category IN (' . join(', ', $wherecatina) . ') ';
elseif (count($wherecatina) == 1) $wherea[] = 'category =' . $wherecatina[0];
if (isset($cleansearchstr)) {
//== boolean search by djgrr
if ($searchstr != '') {
$addparam.= 'search=' . rawurlencode($searchstr) . '&searchin='.htmlsafechars($_GET['searchin']).'&incldead='.intval($_GET['incldead']).'&';
$searchstring = str_replace(array(
'_',
'.',
'-'
) , ' ', $searchstr);
$s = array(
'*',
'?',
'.',
'-',
' '
);
$r = array(
'%',
'_',
'_',
'_',
'_'
);
if (preg_match('/^\"(.+)\"$/i', $searchstring, $matches)) $wherea[] = '`name` LIKE ' . sqlesc('%' . str_replace($s, $r, $matches[1]) . '%');
elseif (strpos($searchstr, '*') !== false || strpos($searchstr, '?') !== false) $wherea[] = '`name` LIKE ' . sqlesc(str_replace($s, $r, $searchstr));
elseif (preg_match('/^[A-Za-z0-9][a-zA-Z0-9()._-]+-[A-Za-z0-9_]*[A-Za-z0-9]$/iD', $searchstr)) $wherea[] = '`name` = ' . sqlesc($searchstr);
else $wherea[] = 'MATCH (`search_text`, `descr`) AGAINST (' . sqlesc($searchstr) . ' IN BOOLEAN MODE)';
//......
$searcha = explode(' ', $cleansearchstr);
//==Memcache search cloud by putyn
searchcloud_insert($cleansearchstr);
//==
foreach ($searcha as $foo) {
foreach ($searchin as $boo) $searchincrt[] = sprintf('%s LIKE \'%s\'', $boo, '%' . $foo . '%');
}
$wherea[] = '( ' . join(' OR ', $searchincrt) . ' )';
}
}
$where = count($wherea) ? 'WHERE ' . join(' AND ', $wherea) : '';
$where_key = 'where::' . sha1($where);
if (($count = $mc1->get_value($where_key)) === false) {
$res = sql_query("SELECT COUNT(id) FROM torrents $where") or sqlerr(__FILE__, __LINE__);
$row = mysqli_fetch_row($res);
$count = (int)$row[0];
$mc1->cache_value($where_key, $count, $INSTALLER09['expires']['browse_where']);
}
$torrentsperpage = $CURUSER["torrentsperpage"];
if (!$torrentsperpage) $torrentsperpage = 15;
if ($count) {
if ($addparam != "") {
if ($pagerlink != "") {
if ($addparam{strlen($addparam) - 1} != ";") { // & = &
$addparam = $addparam . "&" . $pagerlink;
} else {
$addparam = $addparam . $pagerlink;
}
}
} else {
$addparam = $pagerlink;
}
$pager = pager($torrentsperpage, $count, "browse.php?" . $addparam);
$query = "SELECT id, search_text, category, leechers, seeders, bump, release_group, subs, name, times_completed, size, added, poster, descr, type, free, freetorrent, silver, comments, numfiles, filename, anonymous, sticky, nuked, vip, nukereason, newgenre, description, owner, username, youtube, checked_by, IF(nfo <> '', 1, 0) as nfoav," . "IF(num_ratings < {$INSTALLER09['minvotes']}, NULL, ROUND(rating_sum / num_ratings, 1)) AS rating " . "FROM torrents {$where} {$orderby} {$pager['limit']}";
$res = sql_query($query) or sqlerr(__FILE__, __LINE__);
} else {
unset($query);
}
if (isset($cleansearchstr)) $title = "{$lang['browse_search']} $searchstr";
else $title = '';
$HTMLOUT.= "<div class='article' align='center'>";
if ($CURUSER['opt1'] & user_options::VIEWSCLOUD) {
$HTMLOUT.= "<div id='wrapper' style='width:80%;border:1px solid black;background-color:pink;'>";
//print out the tag cloud
$HTMLOUT.= cloud() . "
</div>";
}
$HTMLOUT.= "<br /><br />
<form method='get' action='browse.php'>
<table class='bottom'>
<tr>
<td class='bottom'>
<table class='bottom'>
<tr>";
$i = 0;
foreach ($cats as $cat) {
$HTMLOUT.= ($i && $i % $INSTALLER09['catsperrow'] == 0) ? "</tr><tr>" : "";
$HTMLOUT.= "<td class='bottom' style=\"padding-bottom: 2px;padding-left: 7px\">
<input name='c" . (int)$cat['id'] . "' class=\"styled\" type=\"checkbox\" " . (in_array($cat['id'], $wherecatina) ? "checked='checked' " : "") . "value='1' /><a class='catlink' href='browse.php?cat=" . (int)$cat['id'] . "'> " . (($CURUSER['opt2'] & user_options_2::BROWSE_ICONS) ? "<img src='{$INSTALLER09['pic_base_url']}caticons/{$CURUSER['categorie_icon']}/" . htmlsafechars($cat['image']) . "' alt='" . htmlsafechars($cat['name']) . "' title='" . htmlsafechars($cat['name']) . "' />" : "" . htmlsafechars($cat['name']) . "") . "</a></td>\n";
$i++;
}
$alllink = "<div align='left'> </div>";
$ncats = count($cats);
$nrows = ceil($ncats / $INSTALLER09['catsperrow']);
$lastrowcols = $ncats % $INSTALLER09['catsperrow'];
if ($lastrowcols != 0) {
if ($INSTALLER09['catsperrow'] - $lastrowcols != 1) {
$HTMLOUT.= "<td class='bottom' rowspan='" . ($INSTALLER09['catsperrow'] - $lastrowcols - 1) . "'> </td>";
}
$HTMLOUT.= "<td class='bottom' style=\"padding-left: 5px\">$alllink</td>\n";
}
$HTMLOUT.= "</tr>
</table>
</td>
<td class='bottom'>
<table class='main'>
<tr><td> </td>";
if ($ncats % $INSTALLER09['catsperrow'] == 0) {
$HTMLOUT.= "<td class='bottom' style='padding-left: 15px' rowspan='$nrows' valign='middle' align='right'>$alllink</td>\n";
}
$HTMLOUT.= "</tr>
</table>
</td>
</tr>
</table><br />";
//== clear new tag manually
if ($CURUSER['opt1'] & user_options::CLEAR_NEW_TAG_MANUALLY) {
$new_button = "<a href='?clear_new=1'><input type='submit' value='clear new tag' class='button' /></a><br />";
} else {
//== clear new tag automatically
sql_query("UPDATE users SET last_browse=" . TIME_NOW . " where id=" . $CURUSER['id']);
$mc1->begin_transaction('MyUser_' . $CURUSER['id']);
$mc1->update_row(false, array(
'last_browse' => TIME_NOW
));
$mc1->commit_transaction($INSTALLER09['expires']['curuser']);
$mc1->begin_transaction('user' . $CURUSER['id']);
$mc1->update_row(false, array(
'last_browse' => TIME_NOW
));
$mc1->commit_transaction($INSTALLER09['expires']['user_cache']);
}
$HTMLOUT.= "<br />
<table width='1000' class='main' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='colhead' colspan='2' align='center'>Torrent search
<a class='altlink' title='Open/Close Boolean Search Help' id='help_open' style='font-weight:bold;cursor:help;'>Search help</a></td>
</tr>
<tr>
<td class='two' colspan='2'>".$search_help_boolean."</td>
</tr>
<tr><td class='embedded'><br />
<input type='text' name='search' size='40' value='' />";
//=== only free option :o)
$only_free = ((isset($_GET['only_free'])) ? intval($_GET['only_free']) : '');
//=== only vip option
$vip = ((isset($_GET['vip'])) ? intval($_GET['vip']) : '');
//=== checkbox for only free torrents
$only_free_box = '<input type="checkbox" name="only_free" value="1"'.(isset($_GET['only_free']) ? ' checked="checked"' : '').' /> Only Free Torrents ';
//=== checkbox for only VIP torrents
$vip_box = '<input type="checkbox" name="vip" value="1"'.(isset($_GET['vip']) ? ' checked="checked"' : '').' /> VIP torrents ';
$selected = (isset($_GET["incldead"])) ? (int)$_GET["incldead"] : "";
$deadcheck = "";
$deadcheck.= " in: <select name='incldead'>
<option value='0'>{$lang['browse_active']}</option>
<option value='1'" . ($selected == 1 ? " selected='selected'" : "") . ">{$lang['browse_inc_dead']}</option>
<option value='2'" . ($selected == 2 ? " selected='selected'" : "") . ">{$lang['browse_dead']}</option>
</select>";
$searchin = ' by: <select name="searchin">';
foreach (array(
'title' => 'Name',
'descr' => 'Description',
'genre' => 'Genre',
'all' => 'All'
) as $k => $v) $searchin.= '<option value="' . $k . '" ' . ($select_searchin == $k ? 'selected=\'selected\'' : '') . '>' . $v . '</option>';
$searchin.= '</select>';
$HTMLOUT.= $searchin . ' ' . $deadcheck . ' ' . $only_free_box.''.$vip_box;
$HTMLOUT.= "<p align='center'><input type='submit' value='{$lang['search_search_btn']}' class='btn' /></p>
</td></tr></table></form><br />";
$HTMLOUT.= "{$new_button}";
if (isset($cleansearchstr)) {
$HTMLOUT.= "<h2>{$lang['browse_search']} " . htmlsafechars($searchstr, ENT_QUOTES) . "</h2>\n";
}
if ($count) {
$HTMLOUT.= $pager['pagertop'];
$HTMLOUT.= "<br />";
$HTMLOUT.= torrenttable($res);
$HTMLOUT.= $pager['pagerbottom'];
} else {
if (isset($cleansearchstr)) {
$HTMLOUT.= "<h2>{$lang['browse_not_found']}</h2>\n";
$HTMLOUT.= "<p>{$lang['browse_tryagain']}</p>\n";
} else {
$HTMLOUT.= "<h2>{$lang['browse_nothing']}</h2>\n";
$HTMLOUT.= "<p>{$lang['browse_sorry']}(</p>\n";
}
}
$HTMLOUT.= "</div>";
$ip = getip();
//== Start ip logger - Melvinmeow, Mindless, pdq
$no_log_ip = ($CURUSER['perms'] & bt_options::PERMS_NO_IP);
if ($no_log_ip) {
$ip = '127.0.0.1';
}
if (!$no_log_ip) {
$userid = (int)$CURUSER['id'];
$added = TIME_NOW;
$res = sql_query("SELECT * FROM ips WHERE ip = " . sqlesc($ip) . " AND userid = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0) {
sql_query("INSERT INTO ips (userid, ip, lastbrowse, type) VALUES (" . sqlesc($userid) . ", " . sqlesc($ip) . ", $added, 'Browse')") or sqlerr(__FILE__, __LINE__);
$mc1->delete_value('ip_history_' . $userid);
} else {
sql_query("UPDATE ips SET lastbrowse = $added WHERE ip=" . sqlesc($ip) . " AND userid = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
$mc1->delete_value('ip_history_' . $userid);
}
}
//== End Ip logger
echo stdhead($title, true, $stdhead) . $HTMLOUT . stdfoot($stdfoot);
?>