$SphQL->where('userid', $_GET['requestor']); } else { error(404); } } if (isset($_GET['year'])) { if (is_number($_GET['year']) || $_GET['year'] === '0') { $SphQL->where('year', $_GET['year']); } else { error(404); } } if (!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { $Page = $_GET['page']; $Offset = ($Page - 1) * REQUESTS_PER_PAGE; $SphQL->limit($Offset, REQUESTS_PER_PAGE, $Offset + REQUESTS_PER_PAGE); } else { $Page = 1; $SphQL->limit(0, REQUESTS_PER_PAGE, REQUESTS_PER_PAGE); } $SphQLResult = $SphQL->query(); $NumResults = (int) $SphQLResult->get_meta('total_found'); if ($NumResults > 0) { $SphRequests = $SphQLResult->to_array('id'); if ($OrderBy === 'random') { $NumResults = count($SphRequests); } if ($NumResults > REQUESTS_PER_PAGE) { if (($Page - 1) * REQUESTS_PER_PAGE > $NumResults) { $Page = 0; }
case 3: // Free or neutral leech $SphQL->where('freetorrent', 0, true); $SphQLTor->where('freetorrent', 0, true); break; } } if (!empty($_GET['filter_cat'])) { $SphQL->where('categoryid', array_keys($_GET['filter_cat'])); } /** End building search query **/ /** Run search query and collect results **/ if (isset($Random) && $GroupResults) { // ORDER BY RAND() can't be used together with GROUP BY, so we need some special tactics $Page = 1; $SphQL->limit(0, 5 * TORRENTS_PER_PAGE, 5 * TORRENTS_PER_PAGE); $SphQLResult = $SphQL->query(); $TotalCount = $SphQLResult->get_meta('total_found'); $Results = $SphQLResult->to_array('groupid'); $GroupIDs = array_keys($Results); $GroupCount = count($GroupIDs); while ($SphQLResult->get_meta('total') < $TotalCount && $GroupCount < TORRENTS_PER_PAGE) { // Make sure we get TORRENTS_PER_PAGE results, or all of them if there are less than TORRENTS_PER_PAGE hits $SphQL->where('groupid', $GroupIDs, true); $SphQLResult = $SphQL->query(); if (!$SphQLResult->has_results()) { break; } $Results += $SphQLResult->to_array('groupid'); $GroupIDs = array_keys($Results); $GroupCount = count($GroupIDs);