2012-01-27 08:00:19 +00:00
|
|
|
<?
|
|
|
|
include(SERVER_ROOT.'/sections/torrents/functions.php');
|
|
|
|
|
2013-04-15 08:00:54 +00:00
|
|
|
if (!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') {
|
2012-11-02 08:00:18 +00:00
|
|
|
$OrderWay = 'asc';
|
|
|
|
} else {
|
|
|
|
$OrderWay = 'desc';
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
if (empty($_GET['order_by']) || !isset(TorrentSearch::$SortOrders[$_GET['order_by']])) {
|
|
|
|
$OrderBy = 'time';
|
2012-11-02 08:00:18 +00:00
|
|
|
} else {
|
2015-01-28 08:00:26 +00:00
|
|
|
$OrderBy = $_GET['order_by'];
|
2012-01-27 08:00:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
$GroupResults = !isset($_GET['group_results']) || $_GET['group_results'] != '0';
|
|
|
|
$Page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
|
|
|
|
$Search = new TorrentSearch($GroupResults, $OrderBy, $OrderWay, $Page, TORRENTS_PER_PAGE);
|
|
|
|
$Results = $Search->query($_GET);
|
|
|
|
$Groups = $Search->get_groups();
|
|
|
|
$NumResults = $Search->record_count();
|
2013-09-16 08:00:51 +00:00
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
if ($Results === false) {
|
|
|
|
json_die('error', 'Search returned an error. Make sure all parameters are valid and of the expected types.');
|
2012-11-02 08:00:18 +00:00
|
|
|
}
|
2013-10-11 08:01:04 +00:00
|
|
|
if ($NumResults == 0) {
|
2015-01-28 08:00:26 +00:00
|
|
|
json_die('success', array(
|
2013-05-14 08:00:34 +00:00
|
|
|
'results' => array(),
|
2015-01-28 08:00:26 +00:00
|
|
|
'youMightLike' => array() // This slow and broken feature has been removed
|
2013-05-14 08:00:34 +00:00
|
|
|
));
|
2012-01-27 08:00:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 08:00:08 +00:00
|
|
|
$Bookmarks = Bookmarks::all_bookmarks('torrent');
|
2012-01-27 08:00:19 +00:00
|
|
|
|
|
|
|
$JsonGroups = array();
|
2015-01-28 08:00:26 +00:00
|
|
|
foreach ($Results as $Key => $GroupID) {
|
2012-11-02 08:00:18 +00:00
|
|
|
$GroupInfo = $Groups[$GroupID];
|
|
|
|
if (empty($GroupInfo['Torrents'])) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-28 08:00:26 +00:00
|
|
|
$CategoryID = $GroupInfo['CategoryID'];
|
2012-11-02 08:00:18 +00:00
|
|
|
$GroupYear = $GroupInfo['Year'];
|
|
|
|
$ExtendedArtists = $GroupInfo['ExtendedArtists'];
|
|
|
|
$GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
|
|
|
|
$GroupName = $GroupInfo['Name'];
|
|
|
|
$GroupRecordLabel = $GroupInfo['RecordLabel'];
|
|
|
|
$ReleaseType = $GroupInfo['ReleaseType'];
|
|
|
|
if ($GroupResults) {
|
|
|
|
$Torrents = $GroupInfo['Torrents'];
|
|
|
|
$GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0;
|
|
|
|
foreach ($Torrents as $T) {
|
|
|
|
$GroupTime = max($GroupTime, strtotime($T['Time']));
|
2015-01-28 08:00:26 +00:00
|
|
|
$MaxSize = max($MaxSize, $T['Size']);
|
2012-11-02 08:00:18 +00:00
|
|
|
$TotalLeechers += $T['Leechers'];
|
|
|
|
$TotalSeeders += $T['Seeders'];
|
|
|
|
$TotalSnatched += $T['Snatched'];
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-28 08:00:26 +00:00
|
|
|
$TorrentID = $Key;
|
|
|
|
$Torrents = array($TorrentID => $GroupInfo['Torrents'][$TorrentID]);
|
2012-11-02 08:00:18 +00:00
|
|
|
}
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
$TagList = explode(' ', str_replace('_', '.', $GroupInfo['TagList']));
|
2013-04-19 08:00:55 +00:00
|
|
|
$JsonArtists = array();
|
2012-11-02 08:00:18 +00:00
|
|
|
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
|
|
|
|
unset($ExtendedArtists[2]);
|
|
|
|
unset($ExtendedArtists[3]);
|
2015-01-28 08:00:26 +00:00
|
|
|
$DisplayName = Artists::display_artists($ExtendedArtists, false, false, false);
|
2013-04-19 08:00:55 +00:00
|
|
|
foreach ($ExtendedArtists[1] as $Artist) {
|
|
|
|
$JsonArtists[] = array(
|
2015-01-28 08:00:26 +00:00
|
|
|
'id' => (int)$Artist['id'],
|
|
|
|
'name' => $Artist['name'],
|
|
|
|
'aliasid' => (int)$Artist['aliasid']);
|
2013-04-19 08:00:55 +00:00
|
|
|
}
|
2012-11-02 08:00:18 +00:00
|
|
|
} else {
|
2013-04-19 08:00:55 +00:00
|
|
|
$DisplayName = '';
|
2012-11-02 08:00:18 +00:00
|
|
|
}
|
2013-07-10 00:08:53 +00:00
|
|
|
if ($GroupResults && (count($Torrents) > 1 || isset($GroupedCategories[$CategoryID - 1]))) {
|
2012-01-27 08:00:19 +00:00
|
|
|
// These torrents are in a group
|
|
|
|
$LastRemasterYear = '-';
|
|
|
|
$LastRemasterTitle = '';
|
|
|
|
$LastRemasterRecordLabel = '';
|
|
|
|
$LastRemasterCatalogueNumber = '';
|
|
|
|
$LastMedia = '';
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-01-27 08:00:19 +00:00
|
|
|
$EditionID = 0;
|
|
|
|
unset($FirstUnknown);
|
|
|
|
|
|
|
|
$JsonTorrents = array();
|
2013-04-15 08:00:54 +00:00
|
|
|
foreach ($Torrents as $TorrentID => $Data) {
|
2012-02-09 08:00:20 +00:00
|
|
|
// All of the individual torrents in the group
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-01-27 08:00:19 +00:00
|
|
|
if ($Data['Remastered'] && !$Data['RemasterYear']) {
|
|
|
|
$FirstUnknown = !isset($FirstUnknown);
|
|
|
|
}
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2013-07-10 00:08:53 +00:00
|
|
|
if (isset($GroupedCategories[$CategoryID - 1])
|
2012-11-02 08:00:18 +00:00
|
|
|
&& ($Data['RemasterTitle'] != $LastRemasterTitle
|
|
|
|
|| $Data['RemasterYear'] != $LastRemasterYear
|
|
|
|
|| $Data['RemasterRecordLabel'] != $LastRemasterRecordLabel
|
|
|
|
|| $Data['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber)
|
|
|
|
|| $FirstUnknown
|
|
|
|
|| $Data['Media'] != $LastMedia) {
|
2012-01-27 08:00:19 +00:00
|
|
|
$EditionID++;
|
2013-04-24 08:00:23 +00:00
|
|
|
|
|
|
|
if ($Data['Remastered'] && $Data['RemasterYear'] != 0) {
|
|
|
|
|
|
|
|
$RemasterName = $Data['RemasterYear'];
|
2013-07-10 00:08:53 +00:00
|
|
|
$AddExtra = ' - ';
|
|
|
|
if ($Data['RemasterRecordLabel']) {
|
|
|
|
$RemasterName .= $AddExtra.display_str($Data['RemasterRecordLabel']);
|
|
|
|
$AddExtra = ' / ';
|
|
|
|
}
|
|
|
|
if ($Data['RemasterCatalogueNumber']) {
|
|
|
|
$RemasterName .= $AddExtra.display_str($Data['RemasterCatalogueNumber']);
|
|
|
|
$AddExtra = ' / ';
|
|
|
|
}
|
|
|
|
if ($Data['RemasterTitle']) {
|
|
|
|
$RemasterName .= $AddExtra.display_str($Data['RemasterTitle']);
|
|
|
|
$AddExtra = ' / ';
|
|
|
|
}
|
2013-04-24 08:00:23 +00:00
|
|
|
$RemasterName .= $AddExtra.display_str($Data['Media']);
|
|
|
|
} else {
|
2013-07-10 00:08:53 +00:00
|
|
|
$AddExtra = ' / ';
|
2013-04-24 08:00:23 +00:00
|
|
|
if (!$Data['Remastered']) {
|
2013-07-10 00:08:53 +00:00
|
|
|
$MasterName = 'Original Release';
|
|
|
|
if ($GroupRecordLabel) {
|
|
|
|
$MasterName .= $AddExtra.$GroupRecordLabel;
|
|
|
|
$AddExtra = ' / ';
|
|
|
|
}
|
|
|
|
if ($GroupCatalogueNumber) {
|
|
|
|
$MasterName .= $AddExtra.$GroupCatalogueNumber;
|
|
|
|
$AddExtra = ' / ';
|
|
|
|
}
|
2013-04-24 08:00:23 +00:00
|
|
|
} else {
|
2013-07-10 00:08:53 +00:00
|
|
|
$MasterName = 'Unknown Release(s)';
|
2013-04-24 08:00:23 +00:00
|
|
|
}
|
|
|
|
$MasterName .= $AddExtra.display_str($Data['Media']);
|
|
|
|
}
|
2012-01-27 08:00:19 +00:00
|
|
|
}
|
2012-02-09 08:00:20 +00:00
|
|
|
$LastRemasterTitle = $Data['RemasterTitle'];
|
|
|
|
$LastRemasterYear = $Data['RemasterYear'];
|
|
|
|
$LastRemasterRecordLabel = $Data['RemasterRecordLabel'];
|
|
|
|
$LastRemasterCatalogueNumber = $Data['RemasterCatalogueNumber'];
|
|
|
|
$LastMedia = $Data['Media'];
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-02-09 08:00:20 +00:00
|
|
|
$JsonTorrents[] = array(
|
2013-10-30 08:01:19 +00:00
|
|
|
'torrentId' => (int)$TorrentID,
|
|
|
|
'editionId' => (int)$EditionID,
|
2012-11-02 08:00:18 +00:00
|
|
|
'artists' => $JsonArtists,
|
2012-02-10 08:00:19 +00:00
|
|
|
'remastered' => $Data['Remastered'] == '1',
|
2013-10-30 08:01:19 +00:00
|
|
|
'remasterYear' => (int)$Data['RemasterYear'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'remasterCatalogueNumber' => $Data['RemasterCatalogueNumber'],
|
|
|
|
'remasterTitle' => $Data['RemasterTitle'],
|
|
|
|
'media' => $Data['Media'],
|
|
|
|
'encoding' => $Data['Encoding'],
|
|
|
|
'format' => $Data['Format'],
|
|
|
|
'hasLog' => $Data['HasLog'] == '1',
|
2013-10-30 08:01:19 +00:00
|
|
|
'logScore' => (int)$Data['LogScore'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'hasCue' => $Data['HasCue'] == '1',
|
|
|
|
'scene' => $Data['Scene'] == '1',
|
2013-09-08 08:00:57 +00:00
|
|
|
'vanityHouse' => $GroupInfo['VanityHouse'] == '1',
|
2013-10-30 08:01:19 +00:00
|
|
|
'fileCount' => (int)$Data['FileCount'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'time' => $Data['Time'],
|
2013-10-30 08:01:19 +00:00
|
|
|
'size' => (int)$Data['Size'],
|
|
|
|
'snatches' => (int)$Data['Snatched'],
|
|
|
|
'seeders' => (int)$Data['Seeders'],
|
|
|
|
'leechers' => (int)$Data['Leechers'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'isFreeleech' => $Data['FreeTorrent'] == '1',
|
|
|
|
'isNeutralLeech' => $Data['FreeTorrent'] == '2',
|
2012-10-16 08:00:18 +00:00
|
|
|
'isPersonalFreeleech' => $Data['PersonalFL'],
|
2012-10-31 08:00:17 +00:00
|
|
|
'canUseToken' => Torrents::can_use_token($Data),
|
|
|
|
'hasSnatched' => $Data['IsSnatched']
|
2012-02-09 08:00:20 +00:00
|
|
|
);
|
2012-01-27 08:00:19 +00:00
|
|
|
}
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-02-09 08:00:20 +00:00
|
|
|
$JsonGroups[] = array(
|
2013-10-30 08:01:19 +00:00
|
|
|
'groupId' => (int)$GroupID,
|
2012-02-09 08:00:20 +00:00
|
|
|
'groupName' => $GroupName,
|
2012-02-11 08:00:22 +00:00
|
|
|
'artist' => $DisplayName,
|
2013-06-12 08:00:46 +00:00
|
|
|
'cover' => $GroupInfo['WikiImage'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'tags' => $TagList,
|
|
|
|
'bookmarked' => in_array($GroupID, $Bookmarks),
|
2013-09-08 08:00:57 +00:00
|
|
|
'vanityHouse' => $GroupInfo['VanityHouse'] == '1',
|
2013-10-30 08:01:19 +00:00
|
|
|
'groupYear' => (int)$GroupYear,
|
2012-02-09 08:00:20 +00:00
|
|
|
'releaseType' => $ReleaseTypes[$ReleaseType],
|
2013-10-30 08:01:19 +00:00
|
|
|
'groupTime' => (string)$GroupTime,
|
|
|
|
'maxSize' => (int)$MaxSize,
|
|
|
|
'totalSnatched' => (int)$TotalSnatched,
|
|
|
|
'totalSeeders' => (int)$TotalSeeders,
|
|
|
|
'totalLeechers' => (int)$TotalLeechers,
|
2012-02-09 08:00:20 +00:00
|
|
|
'torrents' => $JsonTorrents
|
|
|
|
);
|
2013-04-15 08:00:54 +00:00
|
|
|
} else {
|
2012-02-09 08:00:20 +00:00
|
|
|
// Viewing a type that does not require grouping
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-01-27 08:00:19 +00:00
|
|
|
list($TorrentID, $Data) = each($Torrents);
|
2013-02-16 08:00:57 +00:00
|
|
|
|
2012-02-09 08:00:20 +00:00
|
|
|
$JsonGroups[] = array(
|
2013-10-30 08:01:19 +00:00
|
|
|
'groupId' => (int)$GroupID,
|
2012-02-09 08:00:20 +00:00
|
|
|
'groupName' => $GroupName,
|
2013-10-30 08:01:19 +00:00
|
|
|
'torrentId' => (int)$TorrentID,
|
2012-02-09 08:00:20 +00:00
|
|
|
'tags' => $TagList,
|
2013-07-10 00:08:53 +00:00
|
|
|
'category' => $Categories[$CategoryID - 1],
|
2013-10-30 08:01:19 +00:00
|
|
|
'fileCount' => (int)$Data['FileCount'],
|
|
|
|
'groupTime' => (string)strtotime($Data['Time']),
|
|
|
|
'size' => (int)$Data['Size'],
|
|
|
|
'snatches' => (int)$Data['Snatched'],
|
|
|
|
'seeders' => (int)$Data['Seeders'],
|
|
|
|
'leechers' => (int)$Data['Leechers'],
|
2012-02-09 08:00:20 +00:00
|
|
|
'isFreeleech' => $Data['FreeTorrent'] == '1',
|
|
|
|
'isNeutralLeech' => $Data['FreeTorrent'] == '2',
|
2012-10-16 08:00:18 +00:00
|
|
|
'isPersonalFreeleech' => $Data['PersonalFL'],
|
2012-10-31 08:00:17 +00:00
|
|
|
'canUseToken' => Torrents::can_use_token($Data),
|
|
|
|
'hasSnatched' => $Data['IsSnatched']
|
2012-02-09 08:00:20 +00:00
|
|
|
);
|
2012-01-27 08:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-28 08:00:26 +00:00
|
|
|
json_print('success', array(
|
|
|
|
'currentPage' => intval($Page),
|
|
|
|
'pages' => ceil($NumResults / TORRENTS_PER_PAGE),
|
|
|
|
'results' => $JsonGroups));
|