-
Notifications
You must be signed in to change notification settings - Fork 4
/
search.php
251 lines (230 loc) · 9.25 KB
/
search.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
<?php
/**
**********************
** BTManager v3.0.2 **
**********************
** http://www.btmanager.org/
** https://github.com/blackheart1/BTManager3.0.2
** http://demo.btmanager.org/index.php
** Licence Info: GPL
** Copyright (C) 2018
** Formerly Known As phpMyBitTorrent
** Created By Antonio Anzivino (aka DJ Echelon)
** And Joe Robertson (aka joeroberts/Black_Heart)
** Project Leaders: Black_Heart, Thor.
** File search.php 2018-09-22 00:00:00 Thor
**
** CHANGES
**
** 2018-09-22 - Updated Masthead, Github, !defined('IN_BTM')
**/
if (defined('IN_BTM'))
{
require_once($_SERVER['DOCUMENT_ROOT'].'/security.php');
die ("Error 404 - Page Not Found");
}
define("IN_BTM",true);
require_once("common.php");
include_once 'include/function_posting.php';
include_once 'include/class.bbcode.php';
require_once("include/torrent_functions.php");
$template = new Template();
$user->set_lang('torrent',$user->ulanguage);
$search = utf8_normalize_nfc(request_var('search', '',true));
$orderby = request_var('sort', '0');
$ordertype = request_var('type', '');
$dead = request_var('incldead', '');
$page = request_var('page', '1');
$cat = request_var('cats', array(''));
$catmain = request_var('catmain', array());
set_site_var($user->lang['SEARCH'] . '-' . $search);
$cats2 = genrelist2();
$wherecatina = array();
$catmain = '1';
$catmid = false;
$catval ='';
foreach($cats2 as $cat3)
{
$cat_var = request_var('cats' . $cat3['id'], array('0'));
if(isset($cat_var))
{
foreach($cat_var as $v)
{
$catval .= '&cats' . $cat3['id'] . '[]=' .$v ;
array_push($wherecatina,$v);
}
$catmid = true;
}
}
include('actb.php');
pmbt_include_templ('blocks/search_block.php', 'cats_var');
#VARIABLE PARSING
$cat = (isset($cat)) ? intval($cat) : 0;
$orderby = (isset($orderby)) ? intval($orderby) : -1;
if (!isset($ordertype) OR $ordertype != "ASC") $ordertype = "DESC";
if(!isset($dead))$dead = false;
if (!isset($page) OR !is_numeric($page) OR $page < 1) $page = 1;
$from = ($page - 1) * $torrent_per_page;
//die(print_r($wherecatina));
$search = $db->sql_escape(unesc($search));
$catmain = implode("', '",$wherecatina);
$banwhere = "".$db_prefix."_torrents.banned = 'no' ";
$passwhere = "AND ".$db_prefix."_torrents.password IS NULL ";
if ($user->moderator) $banwhere = "".$db_prefix."_torrents.banned IN ('no','yes') ";
if ($user->premium) $passwhere = "";
$totsql = "SELECT COUNT(*) as tot FROM ".$db_prefix."_torrents WHERE ".$banwhere.$passwhere." ";
$sql = "SELECT
".$db_prefix."_torrents.*,
IF(".$db_prefix."_torrents.numratings < '$minvotes', NULL, ROUND(".$db_prefix."_torrents.ratingsum / ".$db_prefix."_torrents.numratings, 1)) AS rating,
".$db_prefix."_categories.name AS cat_name,
".$db_prefix."_categories.image AS cat_pic,
".$db_prefix."_categories.parent_id AS parent_id,
U.username,
U.username,IF(U.name IS NULL, U.username, U.name) as user_name,
U.level as user_level,
U.can_do as can_do,
L.group_colour AS color,
L.group_name AS lname
FROM ".$db_prefix."_torrents
LEFT JOIN ".$db_prefix."_categories ON category = ".$db_prefix."_categories.id
LEFT JOIN ".$db_prefix."_users U ON ".$db_prefix."_torrents.owner = U.id
LEFT JOIN
".$db_prefix."_level_settings L ON L.group_id = U.can_do
WHERE ".$banwhere.$passwhere." ";
if (!empty($search) AND $search != '') {
$search1 = $db->sql_escape(str_replace(" ",".",$search));
$search2 = $db->sql_escape(str_replace(" ","-",$search));
$search3 =$db->sql_escape( str_replace(" ","_",$search));
$totsql .= 'AND (search_text LIKE "%'.$db->sql_escape($search).'%"
OR search_text LIKE "%'.$search1.'%"
OR search_text LIKE "%'.$search2.'%"
OR search_text LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search3.'%")
';
$sql .= ' AND (search_text LIKE "%'.$db->sql_escape($search).'%"
OR search_text LIKE "%'.$search1.'%"
OR search_text LIKE "%'.$search2.'%"
OR search_text LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.name LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.descr LIKE "%'.$search3.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$db->sql_escape($search).'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search1.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search2.'%"
OR '.$db_prefix.'_torrents.filename LIKE "%'.$search3.'%")
';
}
if (!$dead == 'true') {
$sql .= "AND visible = 'yes' ";
$totsql .= "AND visible = 'yes' ";
}
if ($cat > 0){
$sql .= "AND ".$db_prefix."_torrents.category = '".$cat."' ";
$totsql .= "AND ".$db_prefix."_torrents.category = '".$cat."' ";
}
if($catmain){
$sql .= "AND ".$db_prefix."_torrents.category IN ('".$catmain."') ";
$totsql .= "AND ".$db_prefix."_torrents.category IN ('".$catmain."') ";
}
switch ($orderby) {
case 0: {
$sql .= "ORDER BY ".$db_prefix."_torrents.added ".$ordertype;
break;
}
case 1: {
$sql .= "ORDER BY ".$db_prefix."_torrents.seeders ".$ordertype;
break;
}
case 2: {
$sql .= "ORDER BY ".$db_prefix."_torrents.leechers ".$ordertype;
break;
}
case 3: {
$sql .= "ORDER BY ".$db_prefix."_torrents.tot_peer ".$ordertype;
break;
}
case 4: {
$sql .= "ORDER BY ".$db_prefix."_torrents.downloaded ".$ordertype;
break;
}
case 5: {
$sql .= "ORDER BY ".$db_prefix."_torrents.ratingsum ".$ordertype;
break;
}
case 6: {
$sql .= "ORDER BY ".$db_prefix."_torrents.name ".$ordertype;
break;
}
case 7: {
$sql .= "ORDER BY ".$db_prefix."_torrents.size ".$ordertype;
break;
}
case 8: {
$sql .= "ORDER BY ".$db_prefix."_torrents.numfiles ".$ordertype;
break;
}
default: {
$sql .= "ORDER BY ".$db_prefix."_torrents.id ".$ordertype;
}
}
$sql .= " LIMIT ".intval($from).", ".intval($torrent_per_page).";";
//die($sql);
$res = $db->sql_query($sql) or btsqlerror($sql);
$totres = $db->sql_query($totsql)or btsqlerror($totsql);
if (isset($orderby))
{
$sort1= "&orderby=".$orderby."&ordertype=".$ordertype;
$sort2= "?orderby=".$orderby."&ordertype=".$ordertype;
}
else
{
$sort1="";
$sort2="";
}
$t_sort = array('i','a','b','c','d','e','f','g','h');
$t_type = array('asc'=>'desc','desc'=>'asc','DESC'=>'asc');
list ($tot) = $db->fetch_array($totres);
$db->sql_freeresult($totres);
if ($db->sql_numrows($res) > 0) {
$page_link = $sort1;
if($search) $page_link = '&search=' . $search;
$template->assign_vars(array(
'PAGE_LINK' => $page_link,
'S_TORRENTS' => true,
'T_SORT' => $t_sort[$orderby],
'T_SHORT' => $t_type[$ordertype],
'T_SEARCH' => stripslashes($search),
'TINCDEAD' => ($dead == 'true')? true : false,
));
$pages = ceil($tot / $torrent_per_page);
generate_torrentpager('search.php?search=' . $search . '&page=', $page, $pages, $catval , $sort1 , $sort2 );
get_tor_vars($res);
}
else
{
$template->assign_vars(array(
'S_TORRENTS' => false,
));
}
$template->assign_vars(array(
'HIT_COUNT' => ($user->admin) ? false : true,
));
echo $template->fetch('torrents_body.html');
close_out();
?>