</div> </div> <?php } //polls(); ?> </div> <div class="main_column"> <?php $Recommend = $Cache->get_value('recommend'); $Recommend_artists = $Cache->get_value('recommend_artists'); if (!is_array($Recommend) || !is_array($Recommend_artists)) { $DB->query("\n\t\tSELECT\n\t\t\ttr.GroupID,\n\t\t\ttr.UserID,\n\t\t\tu.Username,\n\t\t\ttg.Name,\n\t\t\ttg.TagList\n\t\tFROM torrents_recommended AS tr\n\t\t\tJOIN torrents_group AS tg ON tg.ID = tr.GroupID\n\t\t\tLEFT JOIN users_main AS u ON u.ID = tr.UserID\n\t\tORDER BY tr.Time DESC\n\t\tLIMIT 10"); $Recommend = $DB->to_array(); $Cache->cache_value('recommend', $Recommend, 1209600); $Recommend_artists = Artists::get_artists($DB->collect('GroupID')); $Cache->cache_value('recommend_artists', $Recommend_artists, 1209600); } if (count($Recommend) >= 4) { $Cache->increment('usage_index'); ?> <div class="box" id="recommended"> <div class="head colhead_dark"> <strong>Latest Vanity House additions</strong> <a href="#" onclick="$('#vanityhouse').gtoggle(); this.innerHTML = (this.innerHTML == 'Hide' ? 'Show' : 'Hide'); return false;" class="brackets">Show</a> </div> <table class="torrent_table hidden" id="vanityhouse"> <?php foreach ($Recommend as $Recommendations) { list($GroupID, $UserID, $Username, $GroupName, $TagList) = $Recommendations;
</a> </td> <?php } ?> </tr> </table> <?php } } if (check_paranoia_here('uploads')) { $RecentUploads = $Cache->get_value("recent_uploads_{$UserID}"); if ($RecentUploads === false) { $DB->query("\n\t\t\tSELECT\n\t\t\t\tg.ID,\n\t\t\t\tg.Name,\n\t\t\t\tg.WikiImage\n\t\t\tFROM torrents_group AS g\n\t\t\t\tINNER JOIN torrents AS t ON t.GroupID = g.ID\n\t\t\tWHERE t.UserID = '{$UserID}'\n\t\t\t\tAND g.CategoryID = '1'\n\t\t\t\tAND g.WikiImage != ''\n\t\t\tGROUP BY g.ID\n\t\t\tORDER BY t.Time DESC\n\t\t\tLIMIT 5"); $RecentUploads = $DB->to_array(); $Artists = Artists::get_artists($DB->collect('ID')); foreach ($RecentUploads as $Key => $UploadInfo) { $RecentUploads[$Key]['Artist'] = Artists::display_artists($Artists[$UploadInfo['ID']], false, true); } $Cache->cache_value("recent_uploads_{$UserID}", $RecentUploads, 0); //inf cache } if (!empty($RecentUploads)) { ?> <table class="layout recent" id="recent_uploads" cellpadding="0" cellspacing="0" border="0"> <tr class="colhead"> <td colspan="5"> Recent Uploads </td> </tr> <tr>
/** * Function to get data and torrents for an array of GroupIDs. Order of keys doesn't matter * * @param array $GroupIDs * @param boolean $Return if false, nothing is returned. For priming cache. * @param boolean $GetArtists if true, each group will contain the result of * Artists::get_artists($GroupID), in result[$GroupID]['ExtendedArtists'] * @param boolean $Torrents if true, each group contains a list of torrents, in result[$GroupID]['Torrents'] * * @return array each row of the following format: * GroupID => ( * ID * Name * Year * RecordLabel * CatalogueNumber * TagList * ReleaseType * VanityHouse * WikiImage * CategoryID * Torrents => { * ID => { * GroupID, Media, Format, Encoding, RemasterYear, Remastered, * RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, Scene, * HasLog, HasCue, LogScore, FileCount, FreeTorrent, Size, Leechers, * Seeders, Snatched, Time, HasFile, PersonalFL, IsSnatched * } * } * Artists => { * { * id, name, aliasid // Only main artists * } * } * ExtendedArtists => { * [1-6] => { // See documentation on Artists::get_artists * id, name, aliasid * } * } * Flags => { * IsSnatched * } */ public static function get_groups($GroupIDs, $Return = true, $GetArtists = true, $Torrents = true) { $Found = $NotFound = array_fill_keys($GroupIDs, false); $Key = $Torrents ? 'torrent_group_' : 'torrent_group_light_'; foreach ($GroupIDs as $i => $GroupID) { if (!is_number($GroupID)) { unset($GroupIDs[$i], $Found[$GroupID], $NotFound[$GroupID]); continue; } $Data = G::$Cache->get_value($Key . $GroupID, true); if (!empty($Data) && is_array($Data) && $Data['ver'] == CACHE::GROUP_VERSION) { unset($NotFound[$GroupID]); $Found[$GroupID] = $Data['d']; } } // Make sure there's something in $GroupIDs, otherwise the SQL will break if (count($GroupIDs) === 0) { return array(); } /* Changing any of these attributes returned will cause very large, very dramatic site-wide chaos. Do not change what is returned or the order thereof without updating: torrents, artists, collages, bookmarks, better, the front page, and anywhere else the get_groups function is used. Update self::array_group(), too */ if (count($NotFound) > 0) { $IDs = implode(',', array_keys($NotFound)); $NotFound = array(); $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\t\tSELECT\n\t\t\t\t\tID, Name, Year, RecordLabel, CatalogueNumber, TagList, ReleaseType, VanityHouse, WikiImage, CategoryID\n\t\t\t\tFROM torrents_group\n\t\t\t\tWHERE ID IN ({$IDs})"); while ($Group = G::$DB->next_record(MYSQLI_ASSOC, true)) { $NotFound[$Group['ID']] = $Group; $NotFound[$Group['ID']]['Torrents'] = array(); $NotFound[$Group['ID']]['Artists'] = array(); } G::$DB->set_query_id($QueryID); if ($Torrents) { $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tID, GroupID, Media, Format, Encoding, RemasterYear, Remastered, RemasterTitle,\n\t\t\t\t\t\tRemasterRecordLabel, RemasterCatalogueNumber, Scene, HasLog, HasCue, LogScore,\n\t\t\t\t\t\tFileCount, FreeTorrent, Size, Leechers, Seeders, Snatched, Time, ID AS HasFile\n\t\t\t\t\tFROM torrents\n\t\t\t\t\tWHERE GroupID IN ({$IDs})\n\t\t\t\t\tORDER BY GroupID, Remastered, (RemasterYear != 0) DESC, RemasterYear, RemasterTitle,\n\t\t\t\t\t\t\tRemasterRecordLabel, RemasterCatalogueNumber, Media, Format, Encoding, ID"); while ($Torrent = G::$DB->next_record(MYSQLI_ASSOC, true)) { $NotFound[$Torrent['GroupID']]['Torrents'][$Torrent['ID']] = $Torrent; } G::$DB->set_query_id($QueryID); } foreach ($NotFound as $GroupID => $GroupInfo) { G::$Cache->cache_value($Key . $GroupID, array('ver' => CACHE::GROUP_VERSION, 'd' => $GroupInfo), 0); } $Found = $NotFound + $Found; } // Filter out orphans (elements that are == false) $Found = array_filter($Found); if ($GetArtists) { $Artists = Artists::get_artists($GroupIDs); } else { $Artists = array(); } if ($Return) { // If we're interested in the data, and not just caching it foreach ($Artists as $GroupID => $Data) { if (!isset($Found[$GroupID])) { continue; } if (array_key_exists(1, $Data) || array_key_exists(4, $Data) || array_key_exists(6, $Data)) { $Found[$GroupID]['Artists'] = isset($Data[1]) ? $Data[1] : null; // Only use main artists (legacy) // TODO: find a better solution than this crap / rewrite the artist system for ($i = 1; $i <= 7; $i++) { $Found[$GroupID]['ExtendedArtists'][$i] = isset($Data[$i]) ? $Data[$i] : null; } } else { $Found[$GroupID]['ExtendedArtists'] = false; } } // Fetch all user specific torrent properties if ($Torrents) { foreach ($Found as &$Group) { $Group['Flags'] = array('IsSnatched' => false); if (!empty($Group['Torrents'])) { foreach ($Group['Torrents'] as &$Torrent) { self::torrent_properties($Torrent, $Group['Flags']); } } } } return $Found; } }
break; case 'seeding': if (!check_paranoia('seeding', $User['Paranoia'], $UserClass, $UserID)) { error(403); } $SQL = "\n\t\t\t\t\tJOIN xbt_files_users AS xfu ON t.ID = xfu.fid\n\t\t\t\tWHERE xfu.uid = '{$UserID}'\n\t\t\t\t\tAND xfu.remaining = 0"; $Month = "FROM_UNIXTIME(xfu.mtime)"; break; default: error(0); } } $DownloadsQ = $DB->query("\n\tSELECT\n\t\tt.ID AS TorrentID,\n\t\tDATE_FORMAT({$Month}, '%Y - %m') AS Month,\n\t\tt.GroupID,\n\t\tt.Media,\n\t\tt.Format,\n\t\tt.Encoding,\n\t\tIF(t.RemasterYear = 0, tg.Year, t.RemasterYear) AS Year,\n\t\ttg.Name,\n\t\tt.Size\n\tFROM torrents AS t\n\t\tJOIN torrents_group AS tg ON t.GroupID = tg.ID\n\t{$SQL}\n\tGROUP BY TorrentID"); $Collector = new TorrentsDL($DownloadsQ, "{$Username}'s " . ucfirst($_GET['type'])); while (list($Downloads, $GroupIDs) = $Collector->get_downloads('TorrentID')) { $Artists = Artists::get_artists($GroupIDs); $TorrentIDs = array_keys($GroupIDs); $TorrentFilesQ = $DB->query(' SELECT TorrentID, File FROM torrents_files WHERE TorrentID IN (' . implode(',', $TorrentIDs) . ')', false); if (is_int($TorrentFilesQ)) { // Query failed. Let's not create a broken zip archive foreach ($TorrentIDs as $TorrentID) { $Download =& $Downloads[$TorrentID]; $Download['Artist'] = Artists::display_artists($Artists[$Download['GroupID']], false, true, false); $Collector->fail_file($Download); } continue; } while (list($TorrentID, $TorrentFile) = $DB->next_record(MYSQLI_NUM, false)) {
//Everything is legit, let's just confim they're not retarded if (empty($_POST['confirm'])) { $DB->query("\n\t\tSELECT Name\n\t\tFROM torrents_group\n\t\tWHERE ID = {$OldGroupID}"); if (!$DB->has_results()) { //Trying to move to an empty group? I think not! set_message('The destination torrent group does not exist!'); header('Location: ' . $_SERVER['HTTP_REFERER']); die; } list($Name) = $DB->next_record(); $DB->query("\n\t\tSELECT CategoryID, Name\n\t\tFROM torrents_group\n\t\tWHERE ID = {$GroupID}"); list($CategoryID, $NewName) = $DB->next_record(); if ($Categories[$CategoryID - 1] != 'Music') { error('Destination torrent group must be in the "Music" category.'); } $Artists = Artists::get_artists(array($OldGroupID, $GroupID)); View::show_header(); ?> <div class="thin"> <div class="header"> <h2>Torrent Group ID Change Confirmation</h2> </div> <div class="box pad"> <form class="confirm_form" name="torrent_group" action="torrents.php" method="post"> <input type="hidden" name="action" value="editgroupid" /> <input type="hidden" name="auth" value="<?php echo $LoggedUser['AuthKey']; ?> " /> <input type="hidden" name="confirm" value="true" /> <input type="hidden" name="torrentid" value="<?php
if ($NewGroupID == $GroupID) { error('Old group ID is the same as new group ID!'); } $DB->query("\n\tSELECT CategoryID, Name\n\tFROM torrents_group\n\tWHERE ID = '{$NewGroupID}'"); if (!$DB->has_results()) { error('Target group does not exist.'); } list($CategoryID, $NewName) = $DB->next_record(); if ($Categories[$CategoryID - 1] != 'Music') { error('Only music groups can be merged.'); } $DB->query("\n\tSELECT Name\n\tFROM torrents_group\n\tWHERE ID = {$GroupID}"); list($Name) = $DB->next_record(); // Everything is legit, let's just confim they're not retarded if (empty($_POST['confirm'])) { $Artists = Artists::get_artists(array($GroupID, $NewGroupID)); View::show_header(); ?> <div class="center thin"> <div class="header"> <h2>Merge Confirm!</h2> </div> <div class="box pad"> <form class="confirm_form" name="torrent_group" action="torrents.php" method="post"> <input type="hidden" name="action" value="merge" /> <input type="hidden" name="auth" value="<?php echo $LoggedUser['AuthKey']; ?> " /> <input type="hidden" name="confirm" value="true" /> <input type="hidden" name="groupid" value="<?php
function generate_torrent_table($Caption, $Tag, $Details, $Limit) { global $LoggedUser, $Categories, $ReleaseTypes, $GroupBy; ?> <h3>Top <?php echo "{$Limit} {$Caption}"; if (empty($_GET['advanced'])) { ?> <small class="top10_quantity_links"> <?php switch ($Limit) { case 100: ?> - <a href="top10.php?details=<?php echo $Tag; ?> " class="brackets">Top 10</a> - <span class="brackets">Top 100</span> - <a href="top10.php?type=torrents&limit=250&details=<?php echo $Tag; ?> " class="brackets">Top 250</a> <?php break; case 250: ?> - <a href="top10.php?details=<?php echo $Tag; ?> " class="brackets">Top 10</a> - <a href="top10.php?type=torrents&limit=100&details=<?php echo $Tag; ?> " class="brackets">Top 100</a> - <span class="brackets">Top 250</span> <?php break; default: ?> - <span class="brackets">Top 10</span> - <a href="top10.php?type=torrents&limit=100&details=<?php echo $Tag; ?> " class="brackets">Top 100</a> - <a href="top10.php?type=torrents&limit=250&details=<?php echo $Tag; ?> " class="brackets">Top 250</a> <?php } ?> </small> <?php } ?> </h3> <table class="torrent_table cats numbering border"> <tr class="colhead"> <td class="center" style="width: 15px;"></td> <td class="cats_col"></td> <td>Name</td> <td style="text-align: right;">Size</td> <td style="text-align: right;">Data</td> <td style="text-align: right;" class="sign snatches"><img src="static/styles/<?php echo $LoggedUser['StyleName']; ?> /images/snatched.png" alt="Snatches" title="Snatches" class="tooltip" /></td> <td style="text-align: right;" class="sign seeders"><img src="static/styles/<?php echo $LoggedUser['StyleName']; ?> /images/seeders.png" alt="Seeders" title="Seeders" class="tooltip" /></td> <td style="text-align: right;" class="sign leechers"><img src="static/styles/<?php echo $LoggedUser['StyleName']; ?> /images/leechers.png" alt="Leechers" title="Leechers" class="tooltip" /></td> <td style="text-align: right;">Peers</td> </tr> <?php // Server is already processing a top10 query. Starting another one will make things slow if ($Details === false) { ?> <tr class="rowb"> <td colspan="9" class="center"> Server is busy processing another top list request. Please try again in a minute. </td> </tr> </table><br /> <?php return; } // in the unlikely event that query finds 0 rows... if (empty($Details)) { ?> <tr class="rowb"> <td colspan="9" class="center"> Found no torrents matching the criteria. </td> </tr> </table><br /> <?php return; } $Rank = 0; foreach ($Details as $Detail) { $GroupIDs[] = $Detail[1]; } $Artists = Artists::get_artists($GroupIDs); foreach ($Details as $Detail) { list($TorrentID, $GroupID, $GroupName, $GroupCategoryID, $WikiImage, $TagsList, $Format, $Encoding, $Media, $Scene, $HasLog, $HasCue, $LogScore, $Year, $GroupYear, $RemasterTitle, $Snatched, $Seeders, $Leechers, $Data, $ReleaseType, $Size) = $Detail; $IsBookmarked = Bookmarks::has_bookmarked('torrent', $GroupID); $IsSnatched = Torrents::has_snatched($TorrentID); // highlight every other row $Rank++; $Highlight = $Rank % 2 ? 'a' : 'b'; // generate torrent's title $DisplayName = ''; if (!empty($Artists[$GroupID])) { $DisplayName = Artists::display_artists($Artists[$GroupID], true, true); } $DisplayName .= "<a href=\"torrents.php?id={$GroupID}&torrentid={$TorrentID}\" class=\"tooltip\" title=\"View torrent\" dir=\"ltr\">{$GroupName}</a>"; if ($GroupCategoryID == 1 && $GroupYear > 0) { $DisplayName .= " [{$GroupYear}]"; } if ($GroupCategoryID == 1 && $ReleaseType > 0) { $DisplayName .= ' [' . $ReleaseTypes[$ReleaseType] . ']'; } // append extra info to torrent title $ExtraInfo = ''; $AddExtra = ''; if (empty($GroupBy)) { if ($Format) { $ExtraInfo .= $Format; $AddExtra = ' / '; } if ($Encoding) { $ExtraInfo .= $AddExtra . $Encoding; $AddExtra = ' / '; } // "FLAC / Lossless / Log (100%) / Cue / CD"; if ($HasLog) { $ExtraInfo .= $AddExtra . 'Log (' . $LogScore . '%)'; $AddExtra = ' / '; } if ($HasCue) { $ExtraInfo .= $AddExtra . 'Cue'; $AddExtra = ' / '; } if ($Media) { $ExtraInfo .= $AddExtra . $Media; $AddExtra = ' / '; } if ($Scene) { $ExtraInfo .= $AddExtra . 'Scene'; $AddExtra = ' / '; } if ($Year > 0) { $ExtraInfo .= $AddExtra . $Year; $AddExtra = ' '; } if ($RemasterTitle) { $ExtraInfo .= $AddExtra . $RemasterTitle; } if ($IsSnatched) { if ($GroupCategoryID == 1) { $ExtraInfo .= ' / '; } $ExtraInfo .= Format::torrent_label('Snatched!'); } if ($ExtraInfo != '') { $ExtraInfo = "- [{$ExtraInfo}]"; } } $TorrentTags = new Tags($TagsList); //Get report info, use the cache if available, if not, add to it. $Reported = false; $Reports = Torrents::get_reports($TorrentID); if (count($Reports) > 0) { $Reported = true; } // print row ?> <tr class="torrent row<?php echo $Highlight . ($IsBookmarked ? ' bookmarked' : '') . ($IsSnatched ? ' snatched_torrent' : ''); ?> "> <td style="padding: 8px; text-align: center;"><strong><?php echo $Rank; ?> </strong></td> <td class="center cats_col"><div title="<?php echo $TorrentTags->title(); ?> " class="tooltip <?php echo Format::css_category($GroupCategoryID); ?> <?php echo $TorrentTags->css_name(); ?> "></div></td> <td class="big_info"> <?php if ($LoggedUser['CoverArt']) { ?> <div class="group_image float_left clear"> <?php ImageTools::cover_thumb($WikiImage, $GroupCategoryID); ?> </div> <?php } ?> <div class="group_info clear"> <span><a href="torrents.php?action=download&id=<?php echo $TorrentID; ?> &authkey=<?php echo $LoggedUser['AuthKey']; ?> &torrent_pass=<?php echo $LoggedUser['torrent_pass']; ?> " title="Download" class="brackets tooltip">DL</a></span> <strong><?php echo $DisplayName; ?> </strong> <?php echo $ExtraInfo; if ($Reported) { ?> - <strong class="torrent_label tl_reported">Reported</strong><?php } if ($IsBookmarked) { ?> <span class="remove_bookmark float_right"> <a href="#" id="bookmarklink_torrent_<?php echo $GroupID; ?> " class="bookmarklink_torrent_<?php echo $GroupID; ?> brackets" onclick="Unbookmark('torrent', <?php echo $GroupID; ?> , 'Bookmark'); return false;">Remove bookmark</a> </span> <?php } else { ?> <span class="add_bookmark float_right"> <a href="#" id="bookmarklink_torrent_<?php echo $GroupID; ?> " class="bookmarklink_torrent_<?php echo $GroupID; ?> brackets" onclick="Bookmark('torrent', <?php echo $GroupID; ?> , 'Remove bookmark'); return false;">Bookmark</a> </span> <?php } ?> <div class="tags"><?php echo $TorrentTags->format(); ?> </div> </div> </td> <td class="number_column nobr"><?php echo Format::get_size($Size); ?> </td> <td class="number_column nobr"><?php echo Format::get_size($Data); ?> </td> <td class="number_column"><?php echo number_format((double) $Snatched); ?> </td> <td class="number_column"><?php echo number_format((double) $Seeders); ?> </td> <td class="number_column"><?php echo number_format((double) $Leechers); ?> </td> <td class="number_column"><?php echo number_format($Seeders + $Leechers); ?> </td> </tr> <?php } //foreach ($Details as $Detail) ?> </table><br /> <?php }
/** * Convenience function for get_artists, when you just need one group. * * @param int $GroupID * @return array - see get_artists */ public static function get_artist($GroupID) { $Results = Artists::get_artists(array($GroupID)); return $Results[$GroupID]; }