| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require ($root_path . 'include/config.php'); |
|---|
| 4 |
require ($root_path . 'include/functions_torrenttable.php'); |
|---|
| 5 |
require ($root_path . 'include/functions_selects.php'); |
|---|
| 6 |
require ($root_path . 'include/functions_search.php'); |
|---|
| 7 |
|
|---|
| 8 |
function _build_where ( $wherea ) { |
|---|
| 9 |
$where = ''; |
|---|
| 10 |
foreach ( $wherea AS $key => $vals ) { |
|---|
| 11 |
if ( is_array($vals) ) { |
|---|
| 12 |
foreach ( $vals AS $_null => $val ) { |
|---|
| 13 |
$where .= ( $where ? ' AND ' : '' ) . $key . ' ' . $val; |
|---|
| 14 |
} |
|---|
| 15 |
} |
|---|
| 16 |
else { |
|---|
| 17 |
$where .= ( $where ? ' AND ' : '' ) . $key . ' ' . $vals; |
|---|
| 18 |
} |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
return $where; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
if ( empty($_REQUEST['cat']) && !empty($_REQUEST['uri']) ) { |
|---|
| 25 |
$seo->get_id_from_uri($session_cid); |
|---|
| 26 |
if ( $session_cid == 0 ) { |
|---|
| 27 |
header('HTTP/1.1 404 Not Found'); |
|---|
| 28 |
trigger_error('HTTP/1.1 404 Not Found'); |
|---|
| 29 |
} else { |
|---|
| 30 |
$_REQUEST['cat'] = $_GET['cat'] = (int) $session_cid; |
|---|
| 31 |
} |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
$userdata = session_pagestart($user_ip); |
|---|
| 35 |
init_userprefs($userdata); |
|---|
| 36 |
|
|---|
| 37 |
parked(); |
|---|
| 38 |
|
|---|
| 39 |
$cats = $cache->obtain_cats(); |
|---|
| 40 |
|
|---|
| 41 |
$searchstr = request_var('search', ''); |
|---|
| 42 |
$category = request_var('cat', 0); |
|---|
| 43 |
$all = request_var('all', 0); |
|---|
| 44 |
$search_in = request_var('search_in', 0); |
|---|
| 45 |
$incldead = request_var('incldead', 0); |
|---|
| 46 |
$sort = request_var('sort', ''); |
|---|
| 47 |
$type = request_var('type',''); |
|---|
| 48 |
$search_id = request_var('search_id', ''); |
|---|
| 49 |
$page = request_var('page', 0); |
|---|
| 50 |
$count = 0; |
|---|
| 51 |
$addparam = array(); |
|---|
| 52 |
$wherea = array(); |
|---|
| 53 |
$wherecatina = array(); |
|---|
| 54 |
$not_in_cats = array(); |
|---|
| 55 |
$search_ids = array(); |
|---|
| 56 |
$back_url = array(); |
|---|
| 57 |
$current_time = time(); |
|---|
| 58 |
$current_cat_name = '';</span> |
|---|
| 59 |
<span class="code-lang"> |
|---|
| 60 |
if ($sort && $type) { |
|---|
| 61 |
$column = ''; |
|---|
| 62 |
$ascdesc = ''; |
|---|
| 63 |
switch($type) { |
|---|
| 64 |
case 'asc': $ascdesc = 'ASC'; break; |
|---|
| 65 |
case 'desc': $ascdesc = 'DESC'; break; |
|---|
| 66 |
default: $ascdesc = 'DESC'; break; |
|---|
| 67 |
} |
|---|
| 68 |
switch($sort) { |
|---|
| 69 |
case '1': $column = 't.name'; break; |
|---|
| 70 |
case '2': $column = 't.numfiles'; break; |
|---|
| 71 |
case '3': $column = 't.comments'; break; |
|---|
| 72 |
case '4': |
|---|
| 73 |
$column = 'IF(t.numratings < ' . $config['minvotes'] . ', 0, ROUND(t.ratingsum / t.numratings, 1)) ' . $ascdesc; |
|---|
| 74 |
$column .= ', t.numratings ' . $ascdesc; |
|---|
| 75 |
$column .= ', t.ctime'; |
|---|
| 76 |
break; |
|---|
| 77 |
case '5': $column = 't.ctime'; break; |
|---|
| 78 |
case '7': $column = 't.size'; break; |
|---|
| 79 |
case '8': $column = 't.completed'; break; |
|---|
| 80 |
case '9': $column = 't.seeders'; break; |
|---|
| 81 |
case '10': $column = 't.leechers'; break; |
|---|
| 82 |
case '11': $column = 'u.name'; break; |
|---|
| 83 |
default: $column = 't.ctime'; break; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
$orderby = $column . ' ' . $ascdesc; |
|---|
| 87 |
$addparam[] = 'sort=' . $sort; |
|---|
| 88 |
$addparam[] = 'type=' . $type; |
|---|
| 89 |
} |
|---|
| 90 |
else { |
|---|
| 91 |
$orderby = 't.ctime DESC'; |
|---|
| 92 |
|
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 96 |
$wherea['t.moderated'][] = ' = 1'; |
|---|
| 97 |
$wherea['t.banned'][] = ' = 0'; |
|---|
| 98 |
$wherea['t.hidden'][] = ' = 0'; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
switch ( $incldead ) { |
|---|
| 102 |
|
|---|
| 103 |
case 1: |
|---|
| 104 |
$addparam[] = 'incldead=1'; |
|---|
| 105 |
break; |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
case 2: |
|---|
| 109 |
$addparam[] = 'incldead=2'; |
|---|
| 110 |
$wherea['t.visible'][] = ' = 0'; |
|---|
| 111 |
break; |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
case 3: |
|---|
| 115 |
case 9: |
|---|
| 116 |
case 10: |
|---|
| 117 |
$free = ( $incldead == 3 ? 1 : ( $incldead == 9 ? 2 : 4 ) ); |
|---|
| 118 |
$addparam[] = 'incldead=' . $incldead; |
|---|
| 119 |
$wherea['t.free'][] = ' = ' . $free; |
|---|
| 120 |
$wherea['t.visible'][] = ' = 1'; |
|---|
| 121 |
break; |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
case 4: |
|---|
| 125 |
$addparam[] = 'incldead=4'; |
|---|
| 126 |
$wherea['t.seeders'][] = ' = 0'; |
|---|
| 127 |
$wherea['t.leechers'][] = '> 0'; |
|---|
| 128 |
break; |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
case 5: |
|---|
| 132 |
$addparam[] = 'incldead=5'; |
|---|
| 133 |
$wherea['t.owner'][] = ' = ' . $userdata['uid']; |
|---|
| 134 |
unset($wherea['t.moderated']); |
|---|
| 135 |
break; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
case 6: |
|---|
| 139 |
if ( $userdata['hiddentorrents'] || $userdata['class'] >= UC_MODERATOR ) { |
|---|
| 140 |
$addparam[] = 'incldead=6'; |
|---|
| 141 |
$wherea['t.hidden'][] = ' = 1'; |
|---|
| 142 |
} |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
case 7: |
|---|
| 147 |
if ( $userdata['class'] >= UC_MODERATOR ) { |
|---|
| 148 |
$addparam[] = 'incldead=7'; |
|---|
| 149 |
$wherea['t.banned'][] = ' = 1'; |
|---|
| 150 |
} |
|---|
| 151 |
break; |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
case 8: |
|---|
| 155 |
if ( $userdata['class'] >= UC_MODERATOR ) { |
|---|
| 156 |
$addparam[] = 'incldead=8'; |
|---|
| 157 |
$wherea['t.moderated'][] = ' = 0'; |
|---|
| 158 |
} |
|---|
| 159 |
break; |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
default: |
|---|
| 163 |
|
|---|
| 164 |
break; |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
if ( !$all ) { |
|---|
| 168 |
if ( !$_GET && strpos($userdata['notifs'], '[cat') !== false ) { |
|---|
| 169 |
$all = true; |
|---|
| 170 |
foreach ( $cats AS $cat_id => $cat_ary ) { |
|---|
| 171 |
$all &= $cat_id; |
|---|
| 172 |
if ( strpos($userdata['notifs'], '[cat' . $cat_id . ']') !== false ) { |
|---|
| 173 |
$wherecatina[] = $cat_id; |
|---|
| 174 |
$addparam[] = 'c' . $cat_id . '=1'; |
|---|
| 175 |
} |
|---|
| 176 |
} |
|---|
| 177 |
} |
|---|
| 178 |
elseif ( $category ) { |
|---|
| 179 |
$wherecatina[] = $category; |
|---|
| 180 |
$addparam[] = 'cat=' . $category; |
|---|
| 181 |
} |
|---|
| 182 |
else { |
|---|
| 183 |
$all = true; |
|---|
| 184 |
foreach ( $cats AS $cat_id => $cat_ary ) { |
|---|
| 185 |
$all &= request_var('c' . $cat_id, 0); |
|---|
| 186 |
if ( isset($_GET['c' . $cat_id]) ) { |
|---|
| 187 |
$wherecatina[] = $cat_id; |
|---|
| 188 |
$addparam[] = 'c' . $cat_id . '=1'; |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
} |
|---|
| 193 |
elseif ( $all ) { |
|---|
| 194 |
$wherecatina = array(); |
|---|
| 195 |
$addparam = array(); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
if ( sizeof($wherecatina) && sizeof($wherecatina) != sizeof($cats) ) { |
|---|
| 199 |
$new_wherecatina = array(); |
|---|
| 200 |
foreach ( $wherecatina AS $_null => $_val ) { |
|---|
| 201 |
if ( isset($cats[$_val]) ) { |
|---|
| 202 |
if ( $cats[$_val]['cat_parent'] ) { |
|---|
| 203 |
$new_wherecatina[] = $_val; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
else { |
|---|
| 207 |
foreach ( $cats AS $_key => $_ary ) { |
|---|
| 208 |
if ( $_ary['cat_parent'] == $_val ) { |
|---|
| 209 |
$new_wherecatina[] = $_key; |
|---|
| 210 |
} |
|---|
| 211 |
} |
|---|
| 212 |
$new_wherecatina[] = $_val; |
|---|
| 213 |
} |
|---|
| 214 |
} |
|---|
| 215 |
} |
|---|
| 216 |
$wherecatina = $new_wherecatina; |
|---|
| 217 |
if ( sizeof($wherecatina) ) { |
|---|
| 218 |
$wherea['t.category'][] = ' IN (' . implode(', ', $wherecatina) . ')'; |
|---|
| 219 |
} |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
if ( sizeof($cats) ) { |
|---|
| 223 |
$catsperrow = 5; |
|---|
| 224 |
$cats_split_row = $catsperrow - 1; |
|---|
| 225 |
$row = 0; |
|---|
| 226 |
$col = 0; |
|---|
| 227 |
|
|---|
| 228 |
$sql = 'SELECT * FROM ' . CATEGORIES_TABLE . ' ORDER BY cat_parent_id, name'; |
|---|
| 229 |
$result = $db->sql_query($sql, 3600); |
|---|
| 230 |
|
|---|
| 231 |
while( $row = $db->sql_fetchrow($result) ){ |
|---|
| 232 |
$parent_cat_id = ( $row['cat_parent_id'] ? $row['cat_parent_id'] : $row['id'] ); |
|---|
| 233 |
$_cats[$parent_cat_id][$row['id']] = $row; |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
foreach ( $_cats AS $cat_id => $cat_ary ) { |
|---|
| 237 |
$count = sizeof($cat_ary) - 1; |
|---|
| 238 |
|
|---|
| 239 |
if ( ( $cat_ary[$cat_id]['anonymous_view'] && !$userdata['session_logged_in'] ) || $userdata['session_logged_in'] ) { |
|---|
| 240 |
|
|---|
| 241 |
if (!$col) { |
|---|
| 242 |
$template->assign_block_vars('cats_row', array()); |
|---|
| 243 |
} |
|---|
| 244 |
$checked_sub_cats = array_keys($cat_ary); |
|---|
| 245 |
|
|---|
| 246 |
if ( strpos($userdata['notifs'], '[ex]') !== false ) { |
|---|
| 247 |
$open_subcats = ( sizeof($wherecatina) ? array_intersect($checked_sub_cats, $wherecatina) : array() ); |
|---|
| 248 |
$open_subcats = ( sizeof($open_subcats) ? true : false ); |
|---|
| 249 |
} |
|---|
| 250 |
else { |
|---|
| 251 |
$open_subcats = false; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
$seo->set_cat_url($cat_id, $cat_ary[$cat_id]['name']); |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
if ( $category == $cat_id ) { |
|---|
| 259 |
$current_cat_name = $cat_ary[$cat_id]['name']; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
$template->assign_block_vars('cats_row.cats_col', array( |
|---|
| 263 |
'U_CAT' => append_sid($root_path . 'browse.php?cat=' . $cat_id), |
|---|
| 264 |
'CAT_ID' => $cat_id, |
|---|
| 265 |
'CAT_NAME' => $cat_ary[$cat_id]['name'], |
|---|
| 266 |
'CHECKED' => ( in_array($cat_id, $wherecatina) ? ' checked="checked"' : ''), |
|---|
| 267 |
'SHOW_SUBCATS' => ( $count ? true : false ), |
|---|
| 268 |
'OPEN_SUBCATS' => $open_subcats |
|---|
| 269 |
)); |
|---|
| 270 |
if ( $col == $cats_split_row ) { |
|---|
| 271 |
$col = 0; |
|---|
| 272 |
$row++; |
|---|
| 273 |
} |
|---|
| 274 |
else { |
|---|
| 275 |
$col++; |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
$parent_cat_name = $cat_ary[$cat_id]['name']; |
|---|
| 279 |
|
|---|
| 280 |
unset($cat_ary[$cat_id]); |
|---|
| 281 |
if ( $count ) { |
|---|
| 282 |
|
|---|
| 283 |
foreach( $cat_ary AS $key => $sub_ary ) { |
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
$seo->set_cat_url($key, $sub_ary['name']); |
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
if ( $category == $key ) { |
|---|
| 290 |
$current_cat_name = $parent_cat_name . ' --> ' . $sub_ary['name']; |
|---|
| 291 |
} |
|---|
| 292 |
|
|---|
| 293 |
$template->assign_block_vars('cats_row.cats_col.subcats_row', array( |
|---|
| 294 |
'U_CAT' => append_sid($root_path . 'browse.php?cat=' . $key), |
|---|
| 295 |
'CAT_ID' => $key, |
|---|
| 296 |
'CAT_NAME' => $sub_ary['name'], |
|---|
| 297 |
'CHECKED' => ( in_array($key, $wherecatina) ? ' checked="checked"' : '') |
|---|
| 298 |
)); |
|---|
| 299 |
} |
|---|
| 300 |
} |
|---|
| 301 |
} |
|---|
| 302 |
else { |
|---|
| 303 |
$not_in_cats = array_merge(array_keys($cat_ary), $not_in_cats); |
|---|
| 304 |
} |
|---|
| 305 |
} |
|---|
| 306 |
if ( $col ) { |
|---|
| 307 |
$template->assign_block_vars('cats_row.colspan', array( |
|---|
| 308 |
'CATS_COLSPAN' => ( $catsperrow - $col ) ) |
|---|
| 309 |
); |
|---|
| 310 |
} |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
if ( sizeof($not_in_cats) ) { |
|---|
| 314 |
$wherea['t.category'][] = ' NOT IN (' . implode(', ', $not_in_cats) . ')'; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
if ( $searchstr && defined('SPHINX_SEARCH') ) { |
|---|
| 318 |
require($root_path . 'include/search/sphinx/sphinxapi.php'); |
|---|
| 319 |
|
|---|
| 320 |
$cl = new SphinxClient(); |
|---|
| 321 |
$cl->SetServer( "localhost", 3312 ); |
|---|
| 322 |
|
|---|
| 323 |
switch ( $search_in ) { |
|---|
| 324 |
default: |
|---|
| 325 |
$query = '@(name,filename)'; |
|---|
| 326 |
$cl->SetFieldWeights(array('name' => 100, 'tag_name' => 50, 'descr' => 20, 'filename' => 10)); |
|---|
| 327 |
break; |
|---|
| 328 |
|
|---|
| 329 |
case 2: |
|---|
| 330 |
$query = '@(descr,name)'; |
|---|
| 331 |
$cl->SetFieldWeights(array('descr' => 100, 'name' => 20, 'tag_name' => 20, 'filename' => 10)); |
|---|
| 332 |
break; |
|---|
| 333 |
|
|---|
| 334 |
case 3: |
|---|
| 335 |
$query = '@tag_name'; |
|---|
| 336 |
$cl->SetFieldWeights(array('name' => 0, 'descr' => 0, 'filename' => 0, 'tag_name' => 10000)); |
|---|
| 337 |
break; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
$cl->SetMatchMode(SPH_MATCH_EXTENDED2); |
|---|
| 341 |
$cl->SetSortMode(SPH_SORT_RELEVANCE); |
|---|
| 342 |
$cl->SetLimits(0, 10000, 10000); |
|---|
| 343 |
|
|---|
| 344 |
$punct = array('+',',','.','-','"','\'','&','!','?',':',';','#','~','=','/','^','(',')','_','<','>'); |
|---|
| 345 |
$clSearchstr = str_replace($punct, ' ', $searchstr); |
|---|
| 346 |
$result = $cl->Query($query . ' ' . $clSearchstr); |
|---|
| 347 |
|
|---|
| 348 |
if ( !empty($result['matches']) ) { |
|---|
| 349 |
$search_ids = array_keys($result['matches']); |
|---|
| 350 |
$wherea['t.fid'][] = ' IN (' . implode(', ', $search_ids) . ')'; |
|---|
| 351 |
$addparam[] = 'search=' . urlencode($searchstr); |
|---|
| 352 |
$addparam[] = 'search_in=' . $search_in; |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
if ( !$sort ) { |
|---|
| 356 |
$orderby = 'FIELD(`fid`, ' . implode(',',$search_ids) . ')'; |
|---|
| 357 |
} |
|---|
| 358 |
} |
|---|
| 359 |
else { |
|---|
| 360 |
|
|---|
| 361 |
if ( $searchstr || $search_id ) { |
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
if ( $config['search_flood_interval'] && !$search_id ) { |
|---|
| 365 |
$where_sql = ( $userdata['uid'] == ANONYMOUS ) ? "se.session_ip = '$user_ip'" : 'se.session_user_id = ' . $userdata['uid']; |
|---|
| 366 |
$sql = 'SELECT MAX(sr.search_time) AS last_search_time |
|---|
| 367 |
FROM ' . SEARCH_TABLE . ' sr, ' . SESSIONS_TABLE . " se |
|---|
| 368 |
WHERE sr.session_id = se.session_id |
|---|
| 369 |
AND $where_sql"; |
|---|
| 370 |
$result = $db->sql_query($sql); |
|---|
| 371 |
|
|---|
| 372 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 373 |
if ( $row['last_search_time'] > 0 && ( $current_time - $row['last_search_time']) < $config['search_flood_interval'] ) |
|---|
| 374 |
{ |
|---|
| 375 |
$wait_time = $config['search_flood_interval'] - ( $current_time - $row['last_search_time'] ); |
|---|
| 376 |
trigger_error(sprintf($lang['search_flood_error'], $wait_time)); |
|---|
| 377 |
} |
|---|
| 378 |
} |
|---|
| 379 |
} |
|---|
| 380 |
|
|---|
| 381 |
if ( !$search_id ) { |
|---|
| 382 |
|
|---|
| 383 |
$add_where = array(); |
|---|
| 384 |
if ( sizeof($wherea) ) { |
|---|
| 385 |
foreach ( $wherea AS $key => $vals ) { |
|---|
| 386 |
foreach ( $vals AS $_null => $val ) { |
|---|
| 387 |
$add_where[] = $key . ' ' . $val; |
|---|
| 388 |
} |
|---|
| 389 |
} |
|---|
| 390 |
} |
|---|
| 391 |
|
|---|
| 392 |
switch ( $search_in ) { |
|---|
| 393 |
case 3: |
|---|
| 394 |
$where_search = 'tg.tag_name'; |
|---|
| 395 |
$sql = 'SELECT t.fid AS id FROM ' . TORRENTS_TABLE . ' t LEFT JOIN ' . TAGS_TABLE . ' tg ON (t.fid = tg.tag_for_id)'; |
|---|
| 396 |
$add_where[] = 'tg.tag_type = ' . TYPE_TORRENT; |
|---|
| 397 |
$strict = true; |
|---|
| 398 |
$searchstr = rawurldecode($searchstr); |
|---|
| 399 |
|
|---|
| 400 |
break; |
|---|
| 401 |
|
|---|
| 402 |
case 2: |
|---|
| 403 |
$where_search = 't.descr'; |
|---|
| 404 |
$sql = 'SELECT t.fid AS id FROM ' . TORRENTS_TABLE . ' t'; |
|---|
| 405 |
$strict = false; |
|---|
| 406 |
break; |
|---|
| 407 |
|
|---|
| 408 |
default: |
|---|
| 409 |
$where_search = 't.name'; |
|---|
| 410 |
$sql = 'SELECT t.fid AS id FROM ' . TORRENTS_TABLE . ' t'; |
|---|
| 411 |
$strict = false; |
|---|
| 412 |
break; |
|---|
| 413 |
} |
|---|
| 414 |
|
|---|
| 415 |
$search_ids = search_text_in_db($searchstr, $sql, $where_search, $add_where, $strict); |
|---|
| 416 |
|
|---|
| 417 |
if ( sizeof($search_ids) ) { |
|---|
| 418 |
$wherea['t.fid'][] = ' IN (' . implode(', ', $search_ids) . ')'; |
|---|
| 419 |
} |
|---|
| 420 |
} |
|---|
| 421 |
else { |
|---|
| 422 |
$sql = 'SELECT search_array |
|---|
| 423 |
FROM ' . SEARCH_TABLE . ' sr, ' . SESSIONS_TABLE . " se |
|---|
| 424 |
WHERE sr.session_id = se.session_id |
|---|
| 425 |
AND search_id = '" . $db->sql_escape($search_id) . "'"; |
|---|
| 426 |
$result = $db->sql_query($sql); |
|---|
| 427 |
$search_ids = ( $row = $db->sql_fetchrow($result) ) ? unserialize($row['search_array']) : array(); |
|---|
| 428 |
|
|---|
| 429 |
if ( sizeof($search_ids) ) { |
|---|
| 430 |
$wherea['t.fid'][] = ' IN (' . implode(', ', $search_ids) . ')'; |
|---|
| 431 |
} |
|---|
| 432 |
$addparam[] = 'search=' . urlencode($searchstr); |
|---|
| 433 |
$addparam[] = 'search_id=' . $search_id; |
|---|
| 434 |
} |
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
if ( !$search_id ) { |
|---|
| 438 |
$search_id = md5(dss_rand()); |
|---|
| 439 |
$result_array = serialize($search_ids); |
|---|
| 440 |
|
|---|
| 441 |
$sql = "UPDATE " . SEARCH_TABLE . " |
|---|
| 442 |
SET search_id = '" . $db->sql_escape($search_id) . "', search_time = " . $current_time . ", search_array = '" . $db->sql_escape($result_array) . "' |
|---|
| 443 |
WHERE session_id = '" . $userdata['session_id'] . "'"; |
|---|
| 444 |
$db->sql_query($sql); |
|---|
| 445 |
|
|---|
| 446 |
if ( !$db->sql_affectedrows() ) { |
|---|
| 447 |
$sql = 'INSERT INTO ' . SEARCH_TABLE . ' (search_id, session_id, search_time, search_array) VALUES(\'' . $db->sql_escape($search_id) . '\', \'' . $userdata['session_id'] . '\', ' . $current_time . ', \'' . $db->sql_escape($result_array) . '\')'; |
|---|
| 448 |
$db->sql_query($sql); |
|---|
| 449 |
} |
|---|
| 450 |
|
|---|
| 451 |
if ( sizeof($search_ids) ) { |
|---|
| 452 |
$wherea['t.fid'][] = ' IN (' . implode(', ', $search_ids) . ')'; |
|---|
| 453 |
} |
|---|
| 454 |
$addparam[] = 'search=' . urlencode($searchstr); |
|---|
| 455 |
$addparam[] = 'search_id=' . $search_id; |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
} |
|---|
| 459 |
} |
|---|
| 460 |
$count = sizeof($search_ids); |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
require_once($root_path . 'include/class.tags.php'); |
|---|
| 464 |
$tags = tags::tag_cloud_for_cat($wherecatina); |
|---|
| 465 |
$show_tags_cloud = sizeof($tags);</span> |
|---|
| 466 |
<span class="code-lang"> |
|---|
| 467 |
foreach ( $tags AS $_null => $tag_ary ) { |
|---|
| 468 |
$template->assign_block_vars('tags_row', array( |
|---|
| 469 |
'TAG_NAME' => $tag_ary['tag_name'], |
|---|
| 470 |
'TAG_SIZE' => $tag_ary['size'], |
|---|
| 471 |
'U_TAG' => append_sid($root_path . 'browse.php?search_in=3&search=' . $tag_ary['enc_tag_name']), |
|---|
| 472 |
)); |
|---|
| 473 |
} |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
$where = _build_where($wherea); |
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
if ( !$searchstr ) {</span> |
|---|
| 481 |
<span class="code-keyword"> $sql_array['SELECT'] = 'COUNT(*) AS count'; |
|---|
| 482 |
$sql_array['FROM'] = array(TORRENTS_TABLE => 't'); |
|---|
| 483 |
$sql_array['WHERE'] = $where; |
|---|
| 484 |
|
|---|
| 485 |
$sql = $db->sql_build_query('SELECT', $sql_array); |
|---|
| 486 |
|
|---|
| 487 |
$result = $db->sql_query($sql); |
|---|
| 488 |
$count = ( $row = $db->sql_fetchrow($result) ) ? $row['count'] : 0; |
|---|
| 489 |
} |
|---|
| 490 |
$torrentsperpage = ( $userdata['torrentsperpage'] ? $userdata['torrentsperpage'] : 40 );</span> |
|---|
| 491 |
<span class="code-lang"> |
|---|
| 492 |
if ( $count ) { |
|---|
| 493 |
$wherea['t.owner'][] = ' = u.uid'; |
|---|
| 494 |
$back_url = $addparam; |
|---|
| 495 |
|
|---|
| 496 |
$where = _build_where($wherea); |
|---|
| 497 |
|
|---|
| 498 |
$addparam = ( $addparam ? implode('&', $addparam) . '&' : '' ); |
|---|
| 499 |
|
|---|
| 500 |
list($pagertop, $pagerbottom, $offset, $limit) = pager($torrentsperpage, $count, 'browse.php?' . $addparam); |
|---|
| 501 |
|
|---|
| 502 |
$sql_array['SELECT'] = 't.fid, t.category, t.leechers, t.seeders, t.name, t.completed, t.free, t.size, t.ctime, t.comments, t.numfiles, t.owner, t.hidden, t.numratings, t.ratingsum, t.banned, t.hidden, t.moderated, u.privacy, u.parked, u.name AS username, u.title, u.class, u.donor, u.name_append, u.enabled, u.warneduntil, u.uid'; |
|---|
| 503 |
$sql_array['FROM'] = array(TORRENTS_TABLE => 't', USERS_TABLE => 'u'); |
|---|
| 504 |
$sql_array['WHERE'] = $where; |
|---|
| 505 |
$sql_array['ORDER_BY'] = $orderby; |
|---|
| 506 |
|
|---|
| 507 |
$sql = $db->sql_build_query('SELECT', $sql_array); |
|---|
| 508 |
$result = $db->sql_query_limit($sql, $limit, $offset); |
|---|
| 509 |
} |
|---|
| 510 |
else { |
|---|
| 511 |
unset($result); |
|---|
| 512 |
} |
|---|
| 513 |
|
|---|
| 514 |
$incldead_ary = array(</span> |
|---|
| 515 |
<span class="code-lang"> 0 => $lang['include_dead'], |
|---|
| 516 |
1 => $lang['active'], |
|---|
| 517 |
2 => $lang['only_dead'], |
|---|
| 518 |
3 => $lang['free'], |
|---|
| 519 |
9 => $lang['free_silver'], |
|---|
| 520 |
10 => $lang['free_bronze'], |
|---|
| 521 |
4 => $lang['without_seed'] |
|---|
| 522 |
); |
|---|
| 523 |
|
|---|
| 524 |
if ( $userdata['class'] >= $config['min_class_allow_upload'] && $userdata['session_logged_in'] ) { |
|---|
| 525 |
$incldead_ary[5] = $lang['my_torrents']; |
|---|
| 526 |
} |
|---|
| 527 |
|
|---|
| 528 |
if ( $userdata['hiddentorrents'] || $userdata['class'] >= UC_MODERATOR ) { |
|---|
| 529 |
$incldead_ary[6] = $lang['only_hidden']; |
|---|
| 530 |
} |
|---|
| 531 |
|
|---|
| 532 |
if ( $userdata['class'] >= UC_MODERATOR ) { |
|---|
| 533 |
$incldead_ary[7] = $lang['only_banned']; |
|---|
| 534 |
$incldead_ary[8] = $lang['only_not_moderated']; |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
$incldead_select = '<select name="incldead">';</span> |
|---|
| 538 |
<span class="code-lang">foreach ( $incldead_ary AS $_key => $_val ) { |
|---|
| 539 |
$incldead_select .= '<option value="' . $_key . '"' . ( $incldead == $_key ? ' selected="selected"' : '' ) . '>' . $_val . '</option>'; |
|---|
| 540 |
} |
|---|
| 541 |
$incldead_select .= '</select>'; |
|---|
| 542 |
|
|---|
| 543 |
$search_in_ary = array(1 => $lang['name'], 2 => $lang['description'], 3 => $lang['tags']); |
|---|
| 544 |
$search_in_select = '<select name="search_in">';</span> |
|---|
| 545 |
<span class="code-lang">foreach ( $search_in_ary AS $_key => $_val ) { |
|---|
| 546 |
$search_in_select .= '<option value="' . $_key . '"' . ( $search_in === $_key ? ' selected="selected"' : '' ) . '>' . $_val . '</option>'; |
|---|
| 547 |
} |
|---|
| 548 |
$search_in_select .= '</select>';</span> |
|---|
| 549 |
<span class="code-lang"> |
|---|
| 550 |
if ( $page ) { |
|---|
| 551 |
$back_url[] = 'page=' . $page; |
|---|
| 552 |
} |
|---|
| 553 |
|
|---|
| 554 |
if ( sizeof($back_url) ) { |
|---|
| 555 |
$back_link = ''; |
|---|
| 556 |
$back_link_params = $back_url; |
|---|
| 557 |
|
|---|
| 558 |
foreach ( $back_url AS $_null => $value ) { |
|---|
| 559 |
list($param, $val) = explode('=', $value); |
|---|
| 560 |
$back_link .= ( $back_link ? '&' : '' ) . $param . '=' . urlencode($val); |
|---|
| 561 |
} |
|---|
| 562 |
$back_link = base64_encode($back_link); |
|---|
| 563 |
} |
|---|
| 564 |
else { |
|---|
| 565 |
$back_link = ''; |
|---|
| 566 |
} |
|---|
| 567 |
|
|---|
| 568 |
$ary = array();</span> |
|---|
| 569 |
<span class="code-lang"> |
|---|
| 570 |
if ( $count ) { |
|---|
| 571 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 572 |
$ary[] = $row; |
|---|
| 573 |
} |
|---|
| 574 |
torrenttable($ary); |
|---|
| 575 |
} |
|---|
| 576 |
|
|---|
| 577 |
$template->assign_vars(array(</span> |
|---|
| 578 |
<span class="code-lang"> 'S_BROWSE_ACTION' => append_sid($root_path . 'browse.php'), |
|---|
| 579 |
'U_SHOW_ALL' => append_sid($root_path . 'browse.php?all=1'), |
|---|
| 580 |
'INCLDEAD_SELECT' => $incldead_select, |
|---|
| 581 |
'SEARCH_IN_SELECT' => $search_in_select, |
|---|
| 582 |
'SEARCH_STRING' => $searchstr, |
|---|
| 583 |
'SEARCH_RESULTS' => sprintf($lang['search_results'], $searchstr), |
|---|
| 584 |
'PAGERBOTTOM' => ( isset($pagerbottom) ? $pagerbottom : '' ), |
|---|
| 585 |
'PAGERTOP' => ( isset($pagertop) ? $pagertop : '' ), |
|---|
| 586 |
'BACK_LINK' => $back_link, |
|---|
| 587 |
|
|---|
| 588 |
'FOUND' => sizeof($ary), |
|---|
| 589 |
|
|---|
| 590 |
'SHOW_TAGS_CLOUD' => $show_tags_cloud, |
|---|
| 591 |
)); |
|---|
| 592 |
|
|---|
| 593 |
if ( $searchstr ) { |
|---|
| 594 |
stdhead(sprintf($lang['search_results'], $searchstr), false); |
|---|
| 595 |
} |
|---|
| 596 |
else { |
|---|
| 597 |
$page_title = $lang['browse'] . ( $current_cat_name ? ' "' . $current_cat_name . '"' : '' ); |
|---|
| 598 |
stdhead($page_title, false); |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
$template->set_filenames(array(</span> |
|---|
| 602 |
<span class="code-lang"> 'body' => 'browse.html' |
|---|
| 603 |
)); |
|---|
| 604 |
stdfoot(); |
|---|
| 605 |
?> |
|---|
| 606 |
|
|---|