forked from Bigjoos/U-232-V3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowse.php
344 lines (342 loc) · 12.9 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
<?php
/**
* https://github.com/Bigjoos/
* Licence Info: GPL
* Copyright (C) 2010 U-232 v.3
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless, putyn.
*
*/
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 (INCL_DIR.'function_subcat.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',
'browse'
)
);
$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 = '';
$cats = genrelist2();
if (isset($_GET["search"])) {
$searchstr = sqlesc($_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 torrents.".$column." ".$ascdesc;
$pagerlink = "sort=".intval($_GET['sort'])."&type=".$linkascdesc."&";
} else {
$orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
$pagerlink = "";
}
$wherea = array();
$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) {
$wherea[] = "free >= '1'";
$addparam.= "only_free=1&";
}
$category = (isset($_GET["cat"])) ? (int)$_GET["cat"] : false;
$all = isset($_GET["all"]) ? $_GET["all"] : false;
if (!$all) {
if (!$_GET && $CURUSER["notifs"]) {
$i = 0;
foreach ($cats as $cat) {
$subcats = $cat['subcategory'];
if (count($subcats) > 0) {
foreach ($subcats as $subcat) {
if (strpos($CURUSER["notifs"], "[cat{$subcat['id']}]") !== false) {
$wherecatina[] = $subcat['id'];
$addparam.= "cats$cat[tabletype][]=$subcat[id]&";
}
}
}
if (count($subcats) > 0) {
foreach ($subcats as $subcat) {
if (in_array($subcat['id'], $wherecatina)) {
$cats[$i]['checked'] = true;
} else {
$cats[$i]['checked'] = false;
break;
}
}
}
$i++;
}
} elseif ($_GET) {
$i = 0;
if (count($cats) > 0);
foreach ($cats as $cat) {
$categoriesarray = isset($_GET["cats".$cat['tabletype']]) && is_array($_GET["cats".$cat['tabletype']]) ? $_GET["cats".$cat['tabletype']] : array();
if (count($categoriesarray) > 0) {
foreach ($categoriesarray as $category) {
if (!is_valid_id($category)) stderr("Browse Error", "Not valid browse category");
$wherecatina[] = $category;
$addparam.= "cats$cat[tabletype][]=$category&";
}
}
$subcats = $cat['subcategory'];
if (count($subcats) > 0) {
foreach ($subcats as $subcat) {
if (in_array($subcat['id'], $wherecatina)) {
$cats[$i]['checked'] = true;
} else {
$cats[$i]['checked'] = false;
break;
}
}
}
$i++;
}
if (isset($_GET['cat'])) {
$getcategory = 0 + $_GET['cat'];
if (!is_valid_id($getcategory)) stderr("Browse Error", "Not valid browse category");
if (count($cats) > 0);
foreach ($cats as $cat) {
$subcats = $cat['subcategory'];
if (count($subcats) > 0) {
foreach ($subcats as $subcat) {
if ($subcat['id'] == $getcategory) {
$wherecatina[] = $getcategory;
$addparam.= "cats$cat[tabletype][]=$getcategory&";
break;
}
}
}
if ($subcat['id'] == $getcategory) break;
}
}
}
} else {
$i = 0;
if (count($cats) > 0);
foreach ($cats as $cat) {
$subcats = $cat['subcategory'];
if (count($subcats) > 0) {
$cats[$i]['checked'] = true;
}
$i++;
}
}
if (count($wherecatina) > 1) $wherea[] = 'category IN ('.join(', ', $wherecatina).') ';
elseif (count($wherecatina) == 1) $wherea[] = 'category ='.$wherecatina[0];
if (isset($cleansearchstr)) {
$orderby = 'ORDER BY id DESC';
$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) : '';
$res = sql_query("SELECT COUNT(id) FROM torrents $where") or sqlerr(__FILE__, __LINE__);
$row = mysqli_fetch_row($res);
$count = $row[0];
$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, 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($res);
}
if (isset($cleansearchstr)) $title = "{$lang['browse_search']}\"$searchstr\"";
else $title = '';
$HTMLOUT.= "<div class='article' align='center'>";
if ($CURUSER['viewscloud'] === "yes") {
$HTMLOUT.= "<div id='wrapper1' style='width:80%;border:1px solid black;background-color:pink;' align='center'>";
//== print out the tag cloud
$HTMLOUT.= cloud()."
</div>";
}
//== clear new tag manually
if ($CURUSER['clear_new_tag_manually'] == 'yes') {
$new_button = "<a href='?clear_new=1'><input type='submit' value='{$lang['clear_new_btn']}' class='btn' /></a>";
} else {
//== clear new tag automatically
sql_query("UPDATE users SET last_browse=".TIME_NOW." where id=".sqlesc($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 /><br />
<form method='get' action='browse.php'>";
$cattable = categories_table($cats, $wherecatina, "browse.php");
$HTMLOUT.= ($cattable);
$HTMLOUT.= "<br /><table width='75%' class='main' border='0' cellspacing='0' cellpadding='0'>
<tr><td class='embedded'>";
$HTMLOUT.= "<p align='center'>
{$lang['search_search']}
<input type='text' name='search' size='40' value='".(isset($cleansearchstr) ? $cleansearchstr : '')."' />";
$selected = (isset($_GET["incldead"])) ? (int)$_GET["incldead"] : "";
//=== only free option :o)
$only_free = ((isset($_GET['only_free'])) ? intval($_GET['only_free']) : '');
//=== 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 ';
$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;
$HTMLOUT.= "<input type='submit' value='{$lang['search_search_btn']}' class='btn' />";
$HTMLOUT.= "</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";
}
}
$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);
?>