ob_start("ob_gzhandler"); require_once("include/bittorrent.php"); dbconn(false); loggedinorreturn(); parked(); $records = array(); $cats = genrelist(); $searchstr = unesc($_GET["search"]); $cleansearchstr = searchfield($searchstr); if (empty($cleansearchstr)) unset($cleansearchstr); if(isset($_GET["sort"])) { $type = htmlspecialchars($_GET['sort']); $sort = htmlspecialchars($_GET['d']); if (!is_valid_type($type)) stderr( _("Error"), _("Invalid type")); if (!is_valid_sort($sort)) stderr( _("Error"), _("Invalid sort")); $orderby = "ORDER BY $type $sort"; } else $orderby = "ORDER BY torrents.inverted_timestamp"; $sql_force_index = ''; $addparam = ""; $wherea = array(); $wherecatina = array(); if ($_GET["incldead"] == 1) { $sql_force_index = ' FORCE INDEX(inverted_timestamp) '; $addparam .= "incldead=1&"; if (!isset($CURUSER) || get_user_class() < UC_ADMINISTRATOR) $wherea[] = "banned != 'yes'"; } elseif ($_GET["incldead"] == 2) { $addparam .= "incldead=2&"; $wherea[] = "visible = 'no'"; } else $wherea[] = "visible = 'yes'"; $category = (int) $_GET["cat"]; $all = (int) $_GET["all"]; 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( _("Error"), _("Invalid category ID") ); $wherecatina[] = $category; $addparam .= "cat=".$category."&"; } else { $all = True; foreach ($cats as $cat) { $all &= $_GET["c".$cat['id']]; if ($_GET["c".$cat['id']]) { $wherecatina[] = $cat['id']; $addparam .= "c".$cat['id']."=1&"; } } } if ($all) { $wherecatina = array(); $addparam = ""; } if (count($wherecatina) > 1) $wherecatin = implode(",",$wherecatina); elseif (count($wherecatina) == 1) $wherea[] = "category = ".$wherecatina[0]; $wherebase = $wherea; if (isset($cleansearchstr)) { $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")"; //$wherea[] = "0"; $addparam .= "search=" . urlencode($searchstr) . "&"; if(isset($_GET["sort"])) { $type = htmlspecialchars($_GET['sort']); $sort = htmlspecialchars($_GET['d']); if (!is_valid_type($type)) stderr( _("Error"), _("Invalid type")); if (!is_valid_sort($sort)) stderr( _("Error"), _("Invalid sort")); $orderby = "ORDER BY $type $sort"; } else $orderby = "ORDER BY torrents.id DESC"; } $where = implode(" AND ", $wherea); if ($wherecatin) $where .= ($where ? " AND " : "") . "category IN(" . $wherecatin . ")"; if ($where != "") $where = "WHERE ".$where; $res = mysql_query("SELECT COUNT(*) FROM torrents $where") or die(mysql_error()); $row = mysql_fetch_array($res); $count = $row[0]; if (!$count && isset($cleansearchstr)) { $wherea = $wherebase; if(isset($_GET["sort"])) { $type = $_GET['sort']; if (!is_valid_type($type)) { $msg = "Invalid type: ".$type." Username: ".$CURUSER['username']."(".$_SERVER['REMOTE_ADDR'].")"; new_msg($CURUSER['id'], $GLOBALS['settings']['admin_uid'], $msg); stderr( _("Error"), _("Invalid type")); } $sort = htmlspecialchars($_GET['d']); if (!is_valid_sort($sort)) { $msg = "Invalid sort: ".$sort." Username: ".$CURUSER['username']."(".$_SERVER['REMOTE_ADDR'].")"; new_msg($CURUSER['id'], $GLOBALS['settings']['admin_uid'], $msg); stderr( _("Error"), _("Invalid sort")); } $orderby = "ORDER BY $type $sort"; } else $orderby = "ORDER BY torrents.id DESC"; $searcha = explode(" ", $cleansearchstr); $sc = 0; foreach ($searcha as $searchss) { if (strlen($searchss) <= 1) continue; $sc++; if ($sc > 5) break; $ssa = array(); foreach (array("search_text", "ori_descr") as $sss) $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'"; $wherea[] = "(" . implode(" OR ", $ssa) . ")"; } if ($sc) { $where = implode(" AND ", $wherea); if ($where != "") $where = "WHERE $where"; $res = mysql_query("SELECT COUNT(*) FROM torrents $where"); $row = mysql_fetch_array($res); $count = $row[0]; } } $torrentsperpage = $CURUSER["torrentsperpage"]; if (!$torrentsperpage) $torrentsperpage = 15; list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam); $query = "SELECT users.username, users.anonymous, torrents.id, torrents.category, torrents.description, torrents.leechers, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, FLOOR( ( UNIX_TIMESTAMP() - UNIX_TIMESTAMP(torrents.added) ) / 3600 ) as time_alive, UNIX_TIMESTAMP(torrents.added) as utadded, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, IF(torrents.nfo <> '', 1, 0) as nfoav, IF(torrents.numratings < $minvotes, 0, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, categories.name AS cat_name, categories.image AS cat_pic, categories.stylesheet AS cat_stylesheet, categories.name AS cat_name, categories.image AS cat_pic, categories.stylesheet AS cat_stylesheet FROM torrents" .$sql_force_index." LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit "; $result = do_mysql_query($query) or die (mysql_error()); while ($record = mysql_fetch_assoc($result) ) { $records[] = $record; } if (isset($cleansearchstr)) stdhead( sprintf( _('Search results for "%s"'), $searchstr) ); else stdhead(); ?>