diff --git a/sections/ajax/artist.php b/sections/ajax/artist.php index a7b8a08e..2129b461 100644 --- a/sections/ajax/artist.php +++ b/sections/ajax/artist.php @@ -92,7 +92,7 @@ function compare($X, $Y){ FROM requests AS r LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID - WHERE ra.ArtistID = ".$ArtistID." + WHERE ra.ArtistID = '$ArtistID' AND r.TorrentID = 0 GROUP BY r.ID ORDER BY Votes DESC"); @@ -221,6 +221,31 @@ function compare($X, $Y){ $NumLeechers+=$Torrent['Leechers']; $NumSnatches+=$Torrent['Snatched']; } + foreach ($Torrents as $Torrent) { + $InnerTorrents[] = array( + 'id' => (int) $Torrent['ID'], + 'groupId' => (int) $Torrent['GroupID'], + 'media' => $Torrent['Media'], + 'format' => $Torrent['Format'], + 'encoding' => $Torrent['Encoding'], + 'remasterYear' => $Torrent['RemasterYear'], + 'remastered' => $Torrent['Remastered'] == 1, + 'remasterTitle' => $Torrent['RemasterTitle'], + 'remasterRecordLabel' => $Torrent['RemasterRecordLabel'], + 'scene' => $Torrent['Scene'] == 1, + 'hasLog' => $Torrent['HasLog'] == 1, + 'hasCue' => $Torrent['HasCue'] == 1, + 'logScore' => (int) $Torrent['LogScore'], + 'fileCount' => (int) $Torrent['FileCount'], + 'freeTorrent' => $Torrent['FreeTorrent'] == 1, + 'size' => (int) $Torrent['Size'], + 'leechers' => (int) $Torrent['Leechers'], + 'seeders' => (int) $Torrent['Seeders'], + 'snatched' => (int) $Torrent['Snatched'], + 'time' => $Torrent['Time'], + 'hasFile' => (int) $Torrent['HasFile'] + ); + } $JsonTorrents[] = array( 'groupId' => $GroupID, 'groupName' => $GroupName, @@ -228,6 +253,10 @@ function compare($X, $Y){ 'groupRecordLabel' => $GroupRecordLabel, 'groupCatalogueNumber' => $GroupCatalogueNumber, 'tags' => $TagList, + 'releaseType' => (int) $ReleaseType, + 'groupVanityHouse' => $GroupVanityHouse == 1, + 'hasBookmarked' => $hasBookmarked = has_bookmarked('torrent', $GroupID), + 'torrent' => $InnerTorrents, 'releaseType' => $ReleaseType, 'groupVanityHouse' => $GroupVanityHouse, 'hasBookmarked' => $hasBookmarked = has_bookmarked('torrent', $GroupID), @@ -256,6 +285,10 @@ function compare($X, $Y){ $SimilarArray = $DB->to_array(); foreach ($SimilarArray as $Similar) { $JsonSimilar[] = array( + 'artistId' => (int) $Similar['ArtistID'], + 'name' => $Similar['Name'], + 'score' => (int) $Similar['Score'], + 'similarId' => (int) $Similar['SimilarID'], 'artistId' => $Similar['ArtistID'], 'name' => $Similar['Name'], 'score' => $Similar['Score'], @@ -269,6 +302,13 @@ function compare($X, $Y){ foreach ($Requests as $Request) { list($RequestID, $CategoryID, $Title, $Year, $TimeAdded, $Votes, $Bounty) = $Request; $JsonRequests[] = array( + 'requestId' => (int) $RequestID, + 'categoryId' => (int) $CategoryID, + 'title' => $Title, + 'year' => $Year, + 'timeAdded' => $TimeAdded, + 'votes' => (int) $Votes, + 'bounty' => (int) $Bounty, 'requestId' => $RequestID, 'categoryId' => $CategoryID, 'title' => $Title, diff --git a/sections/ajax/better/index.php b/sections/ajax/better/index.php new file mode 100644 index 00000000..ca48fcf9 --- /dev/null +++ b/sections/ajax/better/index.php @@ -0,0 +1,38 @@ + 'failure')); + break; + } +} else { + print json_encode(array('status' => 'failure')); +} +?> diff --git a/sections/ajax/better/single.php b/sections/ajax/better/single.php new file mode 100644 index 00000000..4026661f --- /dev/null +++ b/sections/ajax/better/single.php @@ -0,0 +1,47 @@ +get_value('better_single_groupids')) === false) { + $DB->query("SELECT t.ID AS TorrentID, + t.GroupID AS GroupID + FROM xbt_files_users AS x + JOIN torrents AS t ON t.ID=x.fid + WHERE t.Format='FLAC' + GROUP BY x.fid + HAVING COUNT(x.uid) = 1 + ORDER BY t.LogScore DESC, t.Time ASC LIMIT 30"); + + $GroupIDs = $DB->to_array('GroupID'); + $Cache->cache_value('better_single_groupids', $GroupIDs, 30*60); +} + +$Results = get_groups(array_keys($GroupIDs)); + +$Results = $Results['matches']; + +$JsonResults = array(); +foreach ($Results as $GroupID=>$Group) { + list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $Artists) = array_values($Group); + $FlacID = $GroupIDs[$GroupID]['TorrentID']; + + $DisplayName = ''; + if(count($Artists)>0) { + $DisplayName = display_artists(array('1'=>$Artists)); + } + $DisplayName.=''.$GroupName.''; + if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; } + + $JsonResults[] = array( + 'torrentId' => $FlacID, + 'groupId' => $GroupID, + 'artist' => $Artists, + 'groupName' => $GroupName, + 'groupYear' => $GroupYear, + 'downloadUrl' => 'torrents.php?action=download&id='.$FlacID.'&authkey='.$LoggedUser['AuthKey'].'&torrent_pass='.$LoggedUser['torrent_pass'] + ); +} + +print json_encode( + array( + 'status' => 'success', + 'response' => $JsonResults + ) +); \ No newline at end of file diff --git a/sections/ajax/better/transcode.php b/sections/ajax/better/transcode.php new file mode 100644 index 00000000..02743e3e --- /dev/null +++ b/sections/ajax/better/transcode.php @@ -0,0 +1,111 @@ + 3) { error(0); } + +$Options = array('v0','v2','320'); + +if ($_GET['type'] == 3) { + $List = "!(v0 | v2 | 320)"; +} else { + $List = '!'.$Options[$_GET['type']]; + if($_GET['type'] == 0) { + $_GET['type'] = '0'; + } else { + $_GET['type'] = display_str($_GET['type']); + } +} + +$Query = '@format FLAC @encoding '.$List; + +if(!empty($_GET['search'])) { + $Query.=' @(groupname,artistname,yearfulltext) '.$SS->EscapeString($_GET['search']); +} + +$SS->SetFilter('logscore', array(100)); +$SS->SetSortMode(SPH_SORT_EXTENDED, "@random"); +$SS->limit(0, TORRENTS_PER_PAGE); + +$SS->set_index(SPHINX_INDEX.' delta'); + +$Results = $SS->search($Query, '', 0, array(), '', ''); + +if(count($Results) == 0) { error('No results found!'); } +/* +// If some were fetched from memcached, get their artists +if(!empty($Results['matches'])) { // Fetch the artists for groups + $GroupIDs = array_keys($Results['matches']); + $Artists = get_artists($GroupIDs); + foreach($Artists as $GroupID=>$Data) { + if(!empty($Data[1])) { + $Results['matches'][$GroupID]['Artists']=$Data[1]; // Only use main artists + } + ksort($Results['matches'][$GroupID]); + } +} +*/ + // These ones were not found in the cache, run SQL +if(!empty($Results['notfound'])) { + $SQLResults = get_groups($Results['notfound']); + + if(is_array($SQLResults['notfound'])) { // Something wasn't found in the db, remove it from results + reset($SQLResults['notfound']); + foreach($SQLResults['notfound'] as $ID) { + unset($SQLResults['matches'][$ID]); + unset($Results['matches'][$ID]); + } + } + + // Merge SQL results with memcached results + foreach($SQLResults['matches'] as $ID=>$SQLResult) { + $Results['matches'][$ID] = array_merge($Results['matches'][$ID], $SQLResult); + ksort($Results['matches'][$ID]); + } +} + +$Results = $Results['matches']; + +$JsonResults = array(); +foreach($Results as $GroupID=>$Data) { +$Debug->log_var($Data); + list($Artists, $GroupCatalogueNumber, $ExtendedArtists, $GroupID2, $GroupName, $GroupRecordLabel, $ReleaseType, $TagList, $Torrents, $GroupVanityHouse, $GroupYear, $CategoryID, $FreeTorrent, $HasCue, $HasLog, $TotalLeechers, $LogScore, $ReleaseType, $ReleaseType, $TotalSeeders, $MaxSize, $TotalSnatched, $GroupTime) = array_values($Data); + + $DisplayName = ''; + if(count($Artists)>0) { + $DisplayName = display_artists(array('1'=>$Artists)); + } + $DisplayName.=''.$GroupName.''; + if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; } + + $MissingEncodings = array('V0 (VBR)'=>1, 'V2 (VBR)'=>1, '320'=>1); + $FlacID = 0; + + foreach($Torrents as $Torrent) { + if(!empty($MissingEncodings[$Torrent['Encoding']])) { + $MissingEncodings[$Torrent['Encoding']] = 0; + } elseif($Torrent['Format'] == 'FLAC' && $FlacID == 0) { + $FlacID = $Torrent['ID']; + } + } + + if($_GET['type'] == '3' && in_array(0, $MissingEncodings)) { + continue; + } + + $JsonResults[] = array( + 'torrentId' => $TorrentID, + 'groupId' => $GroupID, + 'artist' => $DisplayName, + 'groupName' => $GroupName, + 'groupYear' => $GroupYear, + 'missingV2' => $MissingEncodings['V2 (VBR)'] == 0, + 'missingV0' => $MissingEncodings['V0 (VBR)'] == 0, + 'missing320' => $MissingEncodings['320'] == 0, + 'downloadUrl' => 'torrents.php?action=download&id='.$FlacID.'&authkey='.$LoggedUser['AuthKey'].'&torrent_pass='.$LoggedUser['torrent_pass'] + ); +} + +print json_encode( + array( + 'status' => 'success', + 'response' => $JsonResults + ) +); diff --git a/sections/ajax/bookmarks/artists.php b/sections/ajax/bookmarks/artists.php new file mode 100644 index 00000000..c8b6efad --- /dev/null +++ b/sections/ajax/bookmarks/artists.php @@ -0,0 +1,60 @@ + 'failure' + ) + ); + die(); + } + $UserID = $_GET['userid']; + $Sneaky = ($UserID != $LoggedUser['ID']); + if(!is_number($UserID)) { + print + json_encode( + array( + 'status' => 'failure' + ) + ); + die(); + } + $DB->query("SELECT Username FROM users_main WHERE ID='$UserID'"); + list($Username) = $DB->next_record(); +} else { + $UserID = $LoggedUser['ID']; +} + +$Sneaky = ($UserID != $LoggedUser['ID']); + +//$ArtistList = all_bookmarks('artist', $UserID); + +$DB->query('SELECT ag.ArtistID, ag.Name + FROM bookmarks_artists AS ba + INNER JOIN artists_group AS ag ON ba.ArtistID = ag.ArtistID + WHERE ba.UserID = '.$UserID); + +$ArtistList = $DB->to_array(); + +$JsonArtists = array(); +foreach($ArtistList as $Artist) { + list($ArtistID, $Name) = $Artist; + $JsonArtists[] = array( + 'artistId' => (int) $ArtistID, + 'artistName' => $Name + ); +} + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'artists' => $JsonArtists + ) + ) + ); + +?> diff --git a/sections/ajax/bookmarks/index.php b/sections/ajax/bookmarks/index.php new file mode 100644 index 00000000..39d3c49d --- /dev/null +++ b/sections/ajax/bookmarks/index.php @@ -0,0 +1,35 @@ + 'failure' + ) + ); + die(); +} + +?> diff --git a/sections/ajax/bookmarks/torrents.php b/sections/ajax/bookmarks/torrents.php new file mode 100644 index 00000000..1d794322 --- /dev/null +++ b/sections/ajax/bookmarks/torrents.php @@ -0,0 +1,246 @@ +query("SELECT Username FROM users_main WHERE ID='$UserID'"); + list($Username) = $DB->next_record(); +} else { + $UserID = $LoggedUser['ID']; +} + +$Sneaky = ($UserID != $LoggedUser['ID']); + +$Data = $Cache->get_value('bookmarks_torrent_'.$UserID.'_full'); + +if($Data) { + $Data = unserialize($Data); + list($K, list($TorrentList, $CollageDataList)) = each($Data); +} else { + // Build the data for the collage and the torrent list + $DB->query("SELECT + bt.GroupID, + tg.WikiImage, + tg.CategoryID, + bt.Time + FROM bookmarks_torrents AS bt + JOIN torrents_group AS tg ON tg.ID=bt.GroupID + WHERE bt.UserID='$UserID' + ORDER BY bt.Time"); + + $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(); + } +} + +$Title = ($Sneaky)?"$Username's bookmarked torrents":'Your bookmarked torrents'; + + +// Loop through the result set, building up $Collage and $TorrentTable +// Then we print them. +$Collage = array(); +$TorrentTable = ''; + +$NumGroups = 0; +$Artists = array(); +$Tags = array(); + +foreach ($TorrentList as $GroupID=>$Group) { + list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $GroupArtists) = array_values($Group); + list($GroupID2, $Image, $GroupCategoryID, $AddedTime) = array_values($CollageDataList[$GroupID]); + + // Handle stats and stuff + $NumGroups++; + + if($GroupArtists) { + foreach($GroupArtists as $Artist) { + if(!isset($Artists[$Artist['id']])) { + $Artists[$Artist['id']] = array('name'=>$Artist['name'], 'count'=>1); + } else { + $Artists[$Artist['id']]['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 = ''; + if(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); + $LastRemasterYear = '-'; + $LastRemasterTitle = ''; + $LastRemasterRecordLabel = ''; + $LastRemasterCatalogueNumber = ''; + $LastMedia = ''; + + $EditionID = 0; + unset($FirstUnknown); + + foreach ($Torrents as $TorrentID => $Torrent) { + + if ($Torrent['Remastered'] && !$Torrent['RemasterYear']) { + $FirstUnknown = !isset($FirstUnknown); + } + + 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']); + + } 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']); + } + } + $LastRemasterTitle = $Torrent['RemasterTitle']; + $LastRemasterYear = $Torrent['RemasterYear']; + $LastRemasterRecordLabel = $Torrent['RemasterRecordLabel']; + $LastRemasterCatalogueNumber = $Torrent['RemasterCatalogueNumber']; + $LastMedia = $Torrent['Media']; + } + } else { + // Viewing a type that does not require grouping + + list($TorrentID, $Torrent) = each($Torrents); + + $DisplayName = ''.$GroupName.''; + + if(!empty($Torrent['FreeTorrent'])) { + $DisplayName .=' Freeleech!'; + } + } + $TorrentTable.=ob_get_clean(); + + // Album art + + ob_start(); + + $DisplayName = ''; + if(!empty($GroupArtists)) { + $DisplayName.= display_artists(array('1'=>$GroupArtists), false); + } + $DisplayName .= $GroupName; + if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';} + $Collage[]=ob_get_clean(); + +} + +uasort($Tags, 'compare'); +$i = 0; +foreach ($Tags as $TagName => $Tag) { + $i++; + if($i>5) { break; } +uasort($Artists, 'compare'); +$i = 0; +foreach ($Artists as $ID => $Artist) { + $i++; + if($i>10) { break; } +} +} + +$JsonBookmarks = array(); +foreach ($TorrentList as $Torrent) { + $JsonTorrents = array(); + foreach ($Torrent['Torrents'] as $GroupTorrents) { + $JsonTorrents[] = array( + 'id' => (int) $GroupTorrents['ID'], + 'groupId' => (int) $GroupTorrents['GroupID'], + 'media' => $GroupTorrents['Media'], + 'format' => $GroupTorrents['Format'], + 'encoding' => $GroupTorrents['Encoding'], + 'remasterYear' => $GroupTorrents['RemasterYear'], + 'remastered' => $GroupTorrents['Remastered'] == 1, + 'remasterTitle' => $GroupTorrents['RemasterTitle'], + 'remasterRecordLabel' => $GroupTorrents['RemasterRecordLabel'], + 'remasterCatalogueNumber' => $GroupTorrents['RemasterCatalogueNumber'], + 'scene' => $GroupTorrents['Scene'] == 1, + 'hasLog' => $GroupTorrents['HasLog'] == 1, + 'hasCue' => $GroupTorrents['HasCue'] == 1, + 'logScore' => (float) $GroupTorrents['LogScore'], + 'fileCount' => (int) $GroupTorrents['FileCount'], + 'freeTorrent' => $GroupTorrents['FreeTorrent'] == 1, + 'size' => (float) $GroupTorrents['Size'], + 'leechers' => (int) $GroupTorrents['Leechers'], + 'seeders' => (int) $GroupTorrents['Seeders'], + 'snatched' => (int) $GroupTorrents['Snatched'], + 'time' => $GroupTorrents['Time'], + 'hasFile' => (int) $GroupTorrents['HasFile'] + ); + } + $JsonBookmarks[] = array( + 'id' => (int) $Torrent['ID'], + 'name' => $Torrent['Name'], + 'year' => $Torrent['Year'], + 'recordLabel' => $Torrent['RecordLabel'], + 'catalogueNumber' => $Torrent['CatalogueNumber'], + 'tagList' => $Torrent['TagList'], + 'releaseType' => $Torrent['ReleaseType'], + 'vanityHouse' => $Torrent['VanityHouse'] == 1, + 'torrents' => $JsonTorrents + ); +} + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'bookmarks' => $JsonBookmarks + ) + ) + ); +?> diff --git a/sections/ajax/index.php b/sections/ajax/index.php index e4c2f1ce..026e1844 100644 --- a/sections/ajax/index.php +++ b/sections/ajax/index.php @@ -47,6 +47,8 @@ case 'top10': require(SERVER_ROOT.'/sections/ajax/top10/index.php'); break; + case 'bookmarks': + require(SERVER_ROOT.'/sections/ajax/bookmarks/index.php'); case 'artist': require(SERVER_ROOT.'/sections/ajax/artist.php'); break; @@ -71,6 +73,9 @@ case 'notifications': require(SERVER_ROOT.'/sections/ajax/notifications.php'); break; + case 'better': + require(SERVER_ROOT.'/sections/ajax/better/index.php'); + break; default: // If they're screwing around with the query string print json_encode(array('status' => 'failure')); diff --git a/sections/register/index.php b/sections/register/index.php index c98b4bad..12a2946b 100644 --- a/sections/register/index.php +++ b/sections/register/index.php @@ -93,7 +93,6 @@ $DB->query("SELECT ID FROM stylesheets WHERE `Default`='1'"); list($StyleID) = $DB->next_record(); - update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass)); $AuthKey = make_secret(); $DB->query("INSERT INTO users_info (UserID,StyleID,AuthKey, Inviter, JoinDate) VALUES ('$UserID','$StyleID','".db_string($AuthKey)."', '$InviterID', '".sqltime()."')"); @@ -186,6 +185,7 @@ $TPL->set('SITE_URL',SITE_URL); send_email($_REQUEST['email'],'New account confirmation at '.SITE_NAME,$TPL->get(),'noreply'); + update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass)); $Sent=1; } diff --git a/sections/reportsv2/takeresolve.php b/sections/reportsv2/takeresolve.php index 1d49d0b2..86432f22 100644 --- a/sections/reportsv2/takeresolve.php +++ b/sections/reportsv2/takeresolve.php @@ -257,7 +257,7 @@ $PM .= "\nMessage from ".$LoggedUser['Username'].": ".$PMMessage; } - $PM .= "\n\nReport was handled by ".$LoggedUser['Username']."."; + $PM .= "\n\nReport was handled by [user]".$LoggedUser['Username']."[/user]."; send_pm($UploaderID, 0, db_string($Escaped['raw_name']), db_string($PM)); } diff --git a/sections/userhistory/email_history2.php b/sections/userhistory/email_history2.php index b62173f6..70ee22bd 100644 --- a/sections/userhistory/email_history2.php +++ b/sections/userhistory/email_history2.php @@ -173,11 +173,11 @@ - () [S]
+ () [S] [WI]
- () [S]
+ () [S] [WI]
@@ -192,7 +192,7 @@ - () [S]
+ () [S] [WI]
@@ -229,7 +229,7 @@ - () [S]
+ () [S] [WI]
@@ -248,7 +248,7 @@ - () [S]
+ () [S] [WI]
@@ -287,7 +287,7 @@ - () [S]
+ () [S] [WI]
@@ -305,7 +305,7 @@ - () [S]
+ () [S] [WI]