//~~~~~~~~~~~ Main collage page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
function compare($X, $Y){
return($Y['count'] - $X['count']);
}
include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
$CollageID = $_GET['id'];
if(!is_number($CollageID)) { error(0); }
$TokenTorrents = $Cache->get_value('users_tokens_'.$UserID);
if (empty($TokenTorrents)) {
$DB->query("SELECT TorrentID FROM users_freeleeches WHERE UserID=$UserID AND Expired=FALSE");
$TokenTorrents = $DB->collect('TorrentID');
$Cache->cache_value('users_tokens_'.$UserID, $TokenTorrents);
}
$Data = $Cache->get_value('collage_'.$CollageID);
if($Data) {
$Data = unserialize($Data);
list($K, list($Name, $Description, $CollageDataList, $TorrentList, $CommentList, $Deleted, $CollageCategoryID, $CreatorID)) = each($Data);
} else {
$DB->query("SELECT Name, Description, UserID, Deleted, CategoryID, Locked, MaxGroups, MaxGroupsPerUser FROM collages WHERE ID='$CollageID'");
if($DB->record_count() > 0) {
list($Name, $Description, $CreatorID, $Deleted, $CollageCategoryID, $Locked, $MaxGroups, $MaxGroupsPerUser) = $DB->next_record();
$TorrentList='';
$CollageList='';
} else {
$Deleted = '1';
}
}
if($Deleted == '1') {
header('Location: log.php?search=Collage+'.$CollageID);
die();
}
if($CollageCategoryID == 0 && !check_perms('site_collages_delete')) {
if(!check_perms('site_collages_personal') || $CreatorID!=$LoggedUser['ID']) {
$Locked = true;
}
}
//Handle subscriptions
if(($CollageSubscriptions = $Cache->get_value('collage_subs_user_'.$LoggedUser['ID'])) === FALSE) {
$DB->query("SELECT CollageID FROM users_collage_subs WHERE UserID = '$LoggedUser[ID]'");
$CollageSubscriptions = $DB->collect(0);
$Cache->cache_value('collage_subs_user_'.$LoggedUser['ID'],$CollageSubscriptions,0);
}
if(empty($CollageSubscriptions)) {
$CollageSubscriptions = array();
}
if(in_array($CollageID, $CollageSubscriptions)) {
$Cache->delete_value('collage_subs_user_new_'.$LoggedUser['ID']);
}
$DB->query("UPDATE users_collage_subs SET LastVisit=NOW() WHERE UserID = ".$LoggedUser['ID']." AND CollageID=$CollageID");
// Build the data for the collage and the torrent list
if(!is_array($TorrentList)) {
$DB->query("SELECT ct.GroupID,
tg.WikiImage,
tg.CategoryID,
um.ID,
um.Username
FROM collages_torrents AS ct
JOIN torrents_group AS tg ON tg.ID=ct.GroupID
LEFT JOIN users_main AS um ON um.ID=ct.UserID
WHERE ct.CollageID='$CollageID'
ORDER BY ct.Sort");
$GroupIDs = $DB->collect('GroupID');
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
if(count($GroupIDs)>0) {
$TorrentList = get_groups($GroupIDs);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
}
}
// Loop through the result set, building up $Collage and $TorrentTable
// Then we print them.
$Collage = array();
$TorrentTable = '';
$NumGroups = 0;
$NumGroupsByUser = 0;
$Artists = array();
$Tags = array();
$Users = array();
$Number = 0;
foreach ($TorrentList as $GroupID=>$Group) {
list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $GroupArtists, $ExtendedArtists) = array_values($Group);
list($GroupID2, $Image, $GroupCategoryID, $UserID, $Username) = array_values($CollageDataList[$GroupID]);
// Handle stats and stuff
$Number++;
$NumGroups++;
if($UserID == $LoggedUser['ID']) {
$NumGroupsByUser++;
}
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
$CountArtists = array_merge((array)$ExtendedArtists[1], (array)$ExtendedArtists[4], (array)$ExtendedArtists[5], (array)$ExtendedArtists[6]);
} else{
$CountArtists = $GroupArtists;
}
if($CountArtists) {
foreach($CountArtists as $Artist) {
if(!isset($Artists[$Artist['id']])) {
$Artists[$Artist['id']] = array('name'=>$Artist['name'], 'count'=>1);
} else {
$Artists[$Artist['id']]['count']++;
}
}
}
if($Username) {
if(!isset($Users[$UserID])) {
$Users[$UserID] = array('name'=>$Username, 'count'=>1);
} else {
$Users[$UserID]['count']++;
}
}
$TagList = explode(' ',str_replace('_','.',$TagList));
$TorrentTags = array();
foreach($TagList as $Tag) {
if(!isset($Tags[$Tag])) {
$Tags[$Tag] = array('name'=>$Tag, 'count'=>1);
} else {
$Tags[$Tag]['count']++;
}
$TorrentTags[]=''.$Tag.'';
}
$PrimaryTag = $TagList[0];
$TorrentTags = implode(', ', $TorrentTags);
$TorrentTags='
'.$TorrentTags.'
';
$DisplayName = $Number.' - ';
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5])|| !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
$DisplayName .= display_artists($ExtendedArtists);
} elseif(count($GroupArtists)>0) {
$DisplayName .= display_artists(array('1'=>$GroupArtists));
}
$DisplayName .= ''.$GroupName.'';
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
if($GroupVanityHouse) { $DisplayName .= ' [VH]'; }
// Start an output buffer, so we can store this output in $TorrentTable
ob_start();
if(count($Torrents)>1 || $GroupCategoryID==1) {
// Grouped torrents
$ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1);
?>
|
|
=$DisplayName?>
=$TorrentTags?>
|
$LastRemasterYear = '-';
$LastRemasterTitle = '';
$LastRemasterRecordLabel = '';
$LastRemasterCatalogueNumber = '';
$LastMedia = '';
$EditionID = 0;
unset($FirstUnknown);
foreach ($Torrents as $TorrentID => $Torrent) {
if ($Torrent['Remastered'] && !$Torrent['RemasterYear']) {
$FirstUnknown = !isset($FirstUnknown);
}
if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) {
$Torrent['PersonalFL'] = 1;
}
if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear ||
$Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) {
$EditionID++;
if($Torrent['Remastered'] && $Torrent['RemasterYear'] != 0) {
$RemasterName = $Torrent['RemasterYear'];
$AddExtra = " - ";
if($Torrent['RemasterRecordLabel']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterRecordLabel']); $AddExtra=' / '; }
if($Torrent['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterCatalogueNumber']); $AddExtra=' / '; }
if($Torrent['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterTitle']); $AddExtra=' / '; }
$RemasterName .= $AddExtra.display_str($Torrent['Media']);
?>
− =$RemasterName?> |
} else {
$AddExtra = " / ";
if (!$Torrent['Remastered']) {
$MasterName = "Original Release";
if($GroupRecordLabel) { $MasterName .= $AddExtra.$GroupRecordLabel; $AddExtra=' / '; }
if($GroupCatalogueNumber) { $MasterName .= $AddExtra.$GroupCatalogueNumber; $AddExtra=' / '; }
} else {
$MasterName = "Unknown Release(s)";
}
$MasterName .= $AddExtra.display_str($Torrent['Media']);
?>
− =$MasterName?> |
}
}
$LastRemasterTitle = $Torrent['RemasterTitle'];
$LastRemasterYear = $Torrent['RemasterYear'];
$LastRemasterRecordLabel = $Torrent['RemasterRecordLabel'];
$LastRemasterCatalogueNumber = $Torrent['RemasterCatalogueNumber'];
$LastMedia = $Torrent['Media'];
?>
[ DL
if (($LoggedUser['FLTokens'] > 0) && ($Torrent['Size'] < 1073741824)
&& !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?>
| FL
} ?>
| RP ]
» =torrent_info($Torrent)?>
|
=get_size($Torrent['Size'])?> |
=number_format($Torrent['Snatched'])?> |
>=number_format($Torrent['Seeders'])?> |
=number_format($Torrent['Leechers'])?> |
}
} else {
// Viewing a type that does not require grouping
list($TorrentID, $Torrent) = each($Torrents);
$DisplayName = ''.$GroupName.'';
if(!empty($Torrent['FreeTorrent'])) {
$DisplayName .=' Freeleech!';
} elseif(in_array($TorrentID, $TokenTorrents)) {
$DisplayName .= $AddExtra.'Personal Freeleech!';
}
?>
|
|
[ DL
if (($LoggedUser['FLTokens'] > 0) && ($Torrent['Size'] < 1073741824)
&& !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?>
| FL
} ?>
| RP]
=$DisplayName?>
=$TorrentTags?>
|
=get_size($Torrent['Size'])?> |
=number_format($Torrent['Snatched'])?> |
>=number_format($Torrent['Seeders'])?> |
=number_format($Torrent['Leechers'])?> |
}
$TorrentTable.=ob_get_clean();
// Album art
ob_start();
$DisplayName = '';
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5])|| !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
$DisplayName .= display_artists($ExtendedArtists, false);
} elseif(count($GroupArtists)>0) {
$DisplayName .= display_artists(array('1'=>$GroupArtists), false);
}
$DisplayName .= $GroupName;
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
?>
if($Image) {
if(check_perms('site_proxy_images')) {
$Image = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Image);
}
?>
} else { ?>
=$DisplayName?>
} ?>
$Collage[]=ob_get_clean();
}
if(($MaxGroups>0 && $NumGroups>=$MaxGroups) || ($MaxGroupsPerUser>0 && $NumGroupsByUser>=$MaxGroupsPerUser)) {
$Locked = true;
}
// Silly hack for people who are on the old setting
$CollageCovers = isset($LoggedUser['CollageCovers'])?$LoggedUser['CollageCovers']:25*(abs($LoggedUser['HideCollage'] - 1));
$CollagePages = array();
// Pad it out
if ($NumGroups > $CollageCovers) {
for ($i = $NumGroups + 1; $i <= ceil($NumGroups/$CollageCovers)*$CollageCovers; $i++) {
$Collage[] = '';
}
}
for ($i=0; $i < $NumGroups/$CollageCovers; $i++) {
$Groups = array_slice($Collage, $i*$CollageCovers, $CollageCovers);
$CollagePage = '';
foreach ($Groups as $Group) {
$CollagePage .= $Group;
}
$CollagePages[] = $CollagePage;
}
show_header($Name,'browse,collage,bbcode');
?>
=$Name?>
if($CollageCovers != 0) { ?>
Cover Art
$Page1 = array_slice($Collage, 0, $CollageCovers);
foreach($Page1 as $Group) {
echo $Group;
}?>
if ($NumGroups > $CollageCovers) { ?>
}
} ?>
|
|
Torrents |
Size |
|
|
|
=$TorrentTable?>
show_footer();
$Cache->cache_value('collage_'.$CollageID, serialize(array(array($Name, $Description, $CollageDataList, $TorrentList, $CommentList, $Deleted, $CollageCategoryID, $CreatorID, $Locked, $MaxGroups, $MaxGroupsPerUser))), 3600);
?>