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 @@
+
+//Include all the basic stuff...
+
+enforce_login();
+if(isset($_GET['method'])) {
+ switch($_GET['method']) {
+ case 'transcode':
+ include(SERVER_ROOT.'/sections/ajax/better/transcode.php');
+ break;
+ case 'single':
+ include(SERVER_ROOT.'/sections/ajax/better/single.php');
+ break;
+ case 'snatch':
+ include(SERVER_ROOT.'/sections/ajax/better/snatch.php');
+ break;
+ case 'artistless':
+ include(SERVER_ROOT.'/sections/ajax/better/artistless.php');
+ break;
+ case 'tags':
+ include(SERVER_ROOT.'/sections/ajax/better/tags.php');
+ break;
+ case 'folders':
+ include(SERVER_ROOT.'/sections/ajax/better/folders.php');
+ break;
+ case 'files':
+ include(SERVER_ROOT.'/sections/ajax/better/files.php');
+ break;
+ case 'upload':
+ include(SERVER_ROOT.'/sections/ajax/better/upload.php');
+ break;
+ default:
+ print json_encode(array('status' => '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 @@
+
+if(($GroupIDs = $Cache->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 @@
+
+if(!isset($_GET['type']) || !is_number($_GET['type']) || $_GET['type'] > 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 @@
+
+
+if(!empty($_GET['userid'])) {
+ if(!check_perms('users_override_paranoia')) {
+ print
+ json_encode(
+ array(
+ 'status' => '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 @@
+
+authorize(true);
+include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
+// Number of users per page
+define('BOOKMARKS_PER_PAGE', '20');
+
+if (empty($_REQUEST['type'])) { $_REQUEST['type'] = 'torrents'; }
+switch ($_REQUEST['type']) {
+ case 'torrents':
+ require(SERVER_ROOT.'/sections/ajax/bookmarks/torrents.php');
+ break;
+ case 'artists':
+ require(SERVER_ROOT.'/sections/ajax/bookmarks/artists.php');
+ break;
+ case 'collages':
+ $_GET['bookmarks'] = 1;
+ require(SERVER_ROOT.'/sections/ajax/collages/browse.php');
+ break;
+ case 'requests':
+ include(SERVER_ROOT.'/sections/requests/functions.php');
+ $_GET['type'] = 'bookmarks';
+ require(SERVER_ROOT.'/sections/ajax/requests/requests.php');
+ break;
+ default:
+ print
+ json_encode(
+ array(
+ 'status' => '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 @@
+
+ini_set('memory_limit', -1);
+//~~~~~~~~~~~ Main bookmarks page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+authorize(true);
+
+function compare($X, $Y){
+ return($Y['count'] - $X['count']);
+}
+
+if(!empty($_GET['userid'])) {
+ if(!check_perms('users_override_paranoia')) {
+ error(403);
+ }
+ $UserID = $_GET['userid'];
+ if(!is_number($UserID)) { error(404); }
+ $DB->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='