diff --git a/classes/script_start.php b/classes/script_start.php index 44bb9521..5d9b1052 100644 --- a/classes/script_start.php +++ b/classes/script_start.php @@ -414,8 +414,10 @@ function get_permissions_for_user($UserID, $CustomPermissions = false) { $CustomPerms = array(); } + $MaxCollages = $Permissions['Permissions']['MaxCollages'] + $DonorPerms['Permissions']['MaxCollages'] + $ArtistPerms['Permissions']['MaxCollages'] + $CustomPerms['MaxCollages']; + //Combine the permissions - return array_merge($Permissions['Permissions'], $DonorPerms['Permissions'], $ArtistPerms['Permissions'], $CustomPerms); + return array_merge($Permissions['Permissions'], $DonorPerms['Permissions'], $ArtistPerms['Permissions'], $CustomPerms, array('MaxCollages' => $MaxCollages)); } // This function is slow. Don't call it unless somebody's logging in. @@ -574,11 +576,11 @@ function enforce_login() { // Make sure $_GET['auth'] is the same as the user's authorization key // Should be used for any user action that relies solely on GET. -function authorize() { +function authorize($Ajax = false) { global $LoggedUser; if(empty($_REQUEST['auth']) || $_REQUEST['auth'] != $LoggedUser['AuthKey']) { send_irc("PRIVMSG ".LAB_CHAN." :".$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI']." coming from ".$_SERVER['HTTP_REFERER']); - error('Invalid authorization key. Go back, refresh, and try again.'); + error('Invalid authorization key. Go back, refresh, and try again.', $Ajax); return false; } return true; diff --git a/design/privateheader.php b/design/privateheader.php index bb2b5a4e..45a0e756 100644 --- a/design/privateheader.php +++ b/design/privateheader.php @@ -240,6 +240,23 @@ } } +// Collage subscriptions +if(check_perms('site_collages_subscribe')) { + $NewCollages = $Cache->get_value('collage_subs_user_new_'.$LoggedUser['ID']); + if($NewCollages === FALSE) { + $DB->query("SELECT COUNT(DISTINCT s.CollageID) + FROM users_collage_subs as s + JOIN collages as c ON s.CollageID = c.ID + JOIN collages_torrents as ct on ct.CollageID = c.ID + WHERE s.UserID = ".$LoggedUser['ID']." AND ct.AddedOn > s.LastVisit AND c.Deleted = '0'"); + list($NewCollages) = $DB->next_record(); + $Cache->cache_value('collage_subs_user_new_'.$LoggedUser['ID'], $NewCollages, 0); + } + if ($NewCollages > 0) { + $Alerts[] = ''.'You have '.$NewCollages.(($NewCollages > 1) ? ' new collage updates' : ' new collage update').''; + } +} + if (check_perms('users_mod')) { $ModBar[] = ''.'Toolbox'.''; diff --git a/gazelle.sql b/gazelle.sql index 84a558d8..b6f71e1a 100644 --- a/gazelle.sql +++ b/gazelle.sql @@ -138,6 +138,7 @@ CREATE TABLE `collages` ( `TagList` varchar(500) NOT NULL DEFAULT '', `MaxGroups` int(10) NOT NULL DEFAULT '0', `MaxGroupsPerUser` int(10) NOT NULL DEFAULT '0', + `Featured` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `Name` (`Name`), KEY `UserID` (`UserID`), diff --git a/sections/ajax/artist.php b/sections/ajax/artist.php new file mode 100644 index 00000000..a7b8a08e --- /dev/null +++ b/sections/ajax/artist.php @@ -0,0 +1,324 @@ + 'failure')); +} + +if (empty($ArtistID)) { + if (!empty($_GET['artistname'])) { + $Name = db_string(trim($_GET['artistname'])); + $DB->query("SELECT ArtistID FROM artists_alias WHERE Name LIKE '$Name'"); + if (!(list($ArtistID) = $DB->next_record(MYSQLI_NUM, false))) { + //if (list($ID) = $DB->next_record(MYSQLI_NUM, false)) { + print json_encode(array('status' => 'failure')); + die(); + } + // If we get here, we got the ID! + } +} + +if(!empty($_GET['revisionid'])) { // if they're viewing an old revision + $RevisionID=$_GET['revisionid']; + if(!is_number($RevisionID)){ error(0); } + $Data = $Cache->get_value("artist_$ArtistID"."_revision_$RevisionID"); +} else { // viewing the live version + $Data = $Cache->get_value('artist_'.$ArtistID); + $RevisionID = false; +} +if($Data) { + $Data = unserialize($Data); + list($K, list($Name, $Image, $Body, $NumSimilar, $SimilarArray, $TorrentList, $Importances)) = each($Data); + +} else { + if ($RevisionID) { + $sql = "SELECT + a.Name, + wiki.Image, + wiki.body, + a.VanityHouse + FROM wiki_artists AS wiki + LEFT JOIN artists_group AS a ON wiki.RevisionID=a.RevisionID + WHERE wiki.RevisionID='$RevisionID' "; + } else { + $sql = "SELECT + a.Name, + wiki.Image, + wiki.body, + a.VanityHouse + FROM artists_group AS a + LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID=a.RevisionID + WHERE a.ArtistID='$ArtistID' "; + } + $sql .= " GROUP BY a.ArtistID"; + $DB->query($sql); + + if($DB->record_count()==0) { + print json_encode(array('status' => 'failure')); + } + + list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(0)); +} + +ob_start(); + +// Requests +$Requests = $Cache->get_value('artists_requests_'.$ArtistID); +if(!is_array($Requests)) { + $DB->query("SELECT + r.ID, + r.CategoryID, + r.Title, + r.Year, + r.TimeAdded, + COUNT(rv.UserID) AS Votes, + SUM(rv.Bounty) AS Bounty + 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." + AND r.TorrentID = 0 + GROUP BY r.ID + ORDER BY Votes DESC"); + + if($DB->record_count() > 0) { + $Requests = $DB->to_array(); + } else { + $Requests = array(); + } + $Cache->cache_value('artists_requests_'.$ArtistID, $Requests); +} +$NumRequests = count($Requests); + +$LastReleaseType = 0; +if(empty($Importances) || empty($TorrentList)) { + $DB->query("SELECT + DISTINCT ta.GroupID, ta.Importance, tg.VanityHouse + FROM torrents_artists AS ta + JOIN torrents_group AS tg ON tg.ID=ta.GroupID + WHERE ta.ArtistID='$ArtistID' + ORDER BY ta.Importance, tg.ReleaseType ASC, tg.Year DESC, tg.Name DESC"); + + $GroupIDs = $DB->collect('GroupID'); + $Importances = $DB->to_array('GroupID', MYSQLI_BOTH, false); + if(count($GroupIDs)>0) { + $TorrentList = get_groups($GroupIDs, true,true); + $TorrentList = $TorrentList['matches']; + } else { + $TorrentList = array(); + } +} +$NumGroups = count($TorrentList); + +//Get list of used release types +$UsedReleases = array(); +foreach($TorrentList as $GroupID=>$Group) { + if($Importances[$GroupID]['Importance'] == '2') { + $TorrentList[$GroupID]['ReleaseType'] = 1024; + $GuestAlbums = true; + } + if($Importances[$GroupID]['Importance'] == '3') { + $TorrentList[$GroupID]['ReleaseType'] = 1023; + $RemixerAlbums = true; + } + if(!in_array($TorrentList[$GroupID]['ReleaseType'], $UsedReleases)) { + $UsedReleases[] = $TorrentList[$GroupID]['ReleaseType']; + } +} + +if(!empty($GuestAlbums)) { + $ReleaseTypes[1024] = "Guest Appearance"; +} +if(!empty($RemixerAlbums)) { + $ReleaseTypes[1023] = "Remixed By"; +} + + +reset($TorrentList); + +$JsonTorrents = array(); +foreach ($TorrentList as $GroupID=>$Group) { + list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $Artists) = array_values($Group); + $GroupVanityHouse = $Importances[$GroupID]['VanityHouse']; + + $TagList = explode(' ',str_replace('_','.',$TagList)); + + // $Tags array is for the sidebar on the right + foreach($TagList as $Tag) { + if(!isset($Tags[$Tag])) { + $Tags[$Tag] = array('name'=>$Tag, 'count'=>1); + } else { + $Tags[$Tag]['count']++; + } + } + + + + $DisplayName =''.$GroupName.''; + if(check_perms('users_mod')) { + $DisplayName .= ' [Fix]'; + } + + if (($ReleaseType == 1023) || ($ReleaseType == 1024)) { + $DisplayName = display_artists(array(1 => $Artists), true, true).$DisplayName; + } + + if($GroupYear>0) { $DisplayName = $GroupYear. ' - '.$DisplayName; } + + if($GroupVanityHouse) { $DisplayName .= ' [VH]'; } + +?> + + +
+ +
+ + + + + + + $Torrent) { + $NumTorrents++; + + if ($Torrent['Remastered'] && !$Torrent['RemasterYear']) { + $FirstUnknown = !isset($FirstUnknown); + } + + $Torrent['Seeders'] = (int)$Torrent['Seeders']; + $Torrent['Leechers'] = (int)$Torrent['Leechers']; + $Torrent['Snatched'] = (int)$Torrent['Snatched']; + + $NumSeeders+=$Torrent['Seeders']; + $NumLeechers+=$Torrent['Leechers']; + $NumSnatches+=$Torrent['Snatched']; + } + $JsonTorrents[] = array( + 'groupId' => $GroupID, + 'groupName' => $GroupName, + 'groupYear' => $GroupYear, + 'groupRecordLabel' => $GroupRecordLabel, + 'groupCatalogueNumber' => $GroupCatalogueNumber, + 'tags' => $TagList, + 'releaseType' => $ReleaseType, + 'groupVanityHouse' => $GroupVanityHouse, + 'hasBookmarked' => $hasBookmarked = has_bookmarked('torrent', $GroupID), + 'torrent' => array_values($Torrents) + ); +} + +$TorrentDisplayList = ob_get_clean(); + +$JsonSimilar = array(); +if(empty($SimilarArray)) { + $DB->query(" + SELECT + s2.ArtistID, + a.Name, + ass.Score, + ass.SimilarID + FROM artists_similar AS s1 + JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID AND s1.ArtistID!=s2.ArtistID + JOIN artists_similar_scores AS ass ON ass.SimilarID=s1.SimilarID + JOIN artists_group AS a ON a.ArtistID=s2.ArtistID + WHERE s1.ArtistID='$ArtistID' + ORDER BY ass.Score DESC + LIMIT 30 + "); + $SimilarArray = $DB->to_array(); + foreach ($SimilarArray as $Similar) { + $JsonSimilar[] = array( + 'artistId' => $Similar['ArtistID'], + 'name' => $Similar['Name'], + 'score' => $Similar['Score'], + 'similarId' => $Similar['SimilarID'] + ); + } + $NumSimilar = count($SimilarArray); +} + +$JsonRequests = array(); +foreach ($Requests as $Request) { + list($RequestID, $CategoryID, $Title, $Year, $TimeAdded, $Votes, $Bounty) = $Request; + $JsonRequests[] = array( + 'requestId' => $RequestID, + 'categoryId' => $CategoryID, + 'title' => $Title, + 'year' => $Year, + 'timeAdded' => $TimeAdded, + 'votes' => $Votes, + 'bounty' => $Bounty + ); +} + +//notifications disabled by default +$notificationsEnabled = False; +if (check_perms('site_torrents_notify')) { + if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) { + $DB->query("SELECT ID, Artists FROM users_notify_filters WHERE UserID='$LoggedUser[ID]' AND Label='Artist notifications' LIMIT 1"); + $Notify = $DB->next_record(MYSQLI_ASSOC, false); + $Cache->cache_value('notify_artists_'.$LoggedUser['ID'], $Notify, 0); + } + if (stripos($Notify['Artists'], '|'.$Name.'|') === false) { + $notificationsEnabled = False; + } else { + $notificationsEnabled = True; + } +} + + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'id' => $ArtistID, + 'name' => $Name, + 'notificationsEnabled' => $notificationsEnabled, + 'hasBookmarked' => has_bookmarked('artist', $ArtistID), + 'image' => $Image, + 'body' => $Text->full_format($Body), + 'vanityHouse' => $VanityHouseArtist, + 'tags' => array_values($Tags), + 'similarArtists' => $JsonSimilar, + 'statistics' => array( + 'numGroups' => $NumGroups, + 'numTorrents' => $NumTorrents, + 'numSeeders' => $NumSeeders, + 'numLeechers' => $NumLeechers, + 'numSnatches' => $NumSnatches + ), + 'torrentgroup' => $JsonTorrents, + 'requests' => $JsonRequests + ) + ) + ) +?> diff --git a/sections/ajax/inbox/inbox.php b/sections/ajax/inbox/inbox.php new file mode 100644 index 00000000..e5987a97 --- /dev/null +++ b/sections/ajax/inbox/inbox.php @@ -0,0 +1,112 @@ + 'failure' + ) + ); + die(); +} + +list($Page,$Limit) = page_limit(MESSAGES_PER_PAGE); + +$Sort = empty($_GET['sort']) || $_GET['sort'] != "unread" ? "Date DESC" : "cu.Unread = '1' DESC, DATE DESC"; + +$sql = "SELECT + SQL_CALC_FOUND_ROWS + c.ID, + c.Subject, + cu.Unread, + cu.Sticky, + cu.ForwardedTo, + um2.Username AS ForwardedName, + cu2.UserID, + um.Username, + ui.Donor, + ui.Warned, + um.Enabled,"; +$sql .= ($Section == 'sentbox')? ' cu.SentDate ' : ' cu.ReceivedDate '; +$sql .= "AS Date + FROM pm_conversations AS c + LEFT JOIN pm_conversations_users AS cu ON cu.ConvID=c.ID AND cu.UserID='$UserID' + LEFT JOIN pm_conversations_users AS cu2 ON cu2.ConvID=c.ID AND cu2.UserID!='$UserID' AND cu2.ForwardedTo=0 + LEFT JOIN users_main AS um ON um.ID=cu2.UserID + LEFT JOIN users_info AS ui ON ui.UserID=um.ID + LEFT JOIN users_main AS um2 ON um2.ID=cu.ForwardedTo"; + +if(!empty($_GET['search']) && $_GET['searchtype'] == "message") { + $sql .= " JOIN pm_messages AS m ON c.ID=m.ConvID"; +} +$sql .= " WHERE "; +if(!empty($_GET['search'])) { + $Search = db_string($_GET['search']); + if($_GET['searchtype'] == "user") { + $sql .= "um.Username LIKE '".$Search."' AND "; + } elseif($_GET['searchtype'] == "subject") { + $Words = explode(' ', $Search); + $sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND "; + } elseif($_GET['searchtype'] == "message") { + $Words = explode(' ', $Search); + $sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND "; + } +} +$sql .= ($Section == 'sentbox')? ' cu.InSentbox' : ' cu.InInbox'; +$sql .="='1'"; + +$sql .=" GROUP BY c.ID + ORDER BY cu.Sticky, ".$Sort." LIMIT $Limit"; +$Results = $DB->query($sql); +$DB->query('SELECT FOUND_ROWS()'); +list($NumResults) = $DB->next_record(); +$DB->set_query_id($Results); + +$CurURL = get_url(array('sort')); +if(empty($CurURL)) { + $CurURL = "inbox.php?"; +} else { + $CurURL = "inbox.php?".$CurURL."&"; +} + +$Pages=get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9); + +$JsonMessages = array(); +while(list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $ForwardedName, $SenderID, $Username, $Donor, $Warned, $Enabled, $Date) = $DB->next_record()) { + $JsonMessage = array( + 'convId' => $ConvID, + 'subject' => $Subject, + 'unread' => $Unread, + 'sticky' => $Sticky, + 'forwardedId' => $ForwardedID, + 'forwardedName' => $ForwardedName, + 'senderId' => $SenderID, + 'username' => $Username, + 'donor' => $Donor, + 'warned' => $Warned, + 'enabled' => ($Enabled == 2 ? false : true), + 'date' => $Date + ); + $JsonMessages[] = $JsonMessage; +} + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'currentPage' => $Page, + 'pages' => ceil($NumResults/MESSAGES_PER_PAGE), + 'messages' => $JsonMessages + ) + ) + ); +?> \ No newline at end of file diff --git a/sections/ajax/inbox/index.php b/sections/ajax/inbox/index.php new file mode 100644 index 00000000..1ce1e1b6 --- /dev/null +++ b/sections/ajax/inbox/index.php @@ -0,0 +1,14 @@ + 'failure')); + die(); +} + +?> \ No newline at end of file diff --git a/sections/ajax/inbox/viewconv.php b/sections/ajax/inbox/viewconv.php new file mode 100644 index 00000000..e889714e --- /dev/null +++ b/sections/ajax/inbox/viewconv.php @@ -0,0 +1,91 @@ + 'failure')); + die(); +} + + + +$UserID = $LoggedUser['ID']; +$DB->query("SELECT InInbox, InSentbox FROM pm_conversations_users WHERE UserID='$UserID' AND ConvID='$ConvID'"); +if($DB->record_count() == 0) { + print json_encode(array('status' => 'failure')); + die(); +} +list($InInbox, $InSentbox) = $DB->next_record(); + + + + +if (!$InInbox && !$InSentbox) { + print json_encode(array('status' => 'failure')); + die(); +} + +// Get information on the conversation +$DB->query("SELECT + c.Subject, + cu.Sticky, + cu.UnRead, + cu.ForwardedTo, + um.Username + FROM pm_conversations AS c + JOIN pm_conversations_users AS cu ON c.ID=cu.ConvID + LEFT JOIN users_main AS um ON um.ID=cu.ForwardedTo + WHERE c.ID='$ConvID' AND UserID='$UserID'"); +list($Subject, $Sticky, $UnRead, $ForwardedID, $ForwardedName) = $DB->next_record(); + +$DB->query("SELECT UserID, Username, PermissionID, Enabled, Donor, Warned + FROM pm_messages AS pm + JOIN users_info AS ui ON ui.UserID=pm.SenderID + JOIN users_main AS um ON um.ID=pm.SenderID + WHERE pm.ConvID='$ConvID'"); + +while(list($PMUserID, $Username, $PermissionID, $Enabled, $Donor, $Warned) = $DB->next_record()) { + $PMUserID = (int)$PMUserID; + $Users[$PMUserID]['UserStr'] = format_username($PMUserID, $Username, $Donor, $Warned, $Enabled == 2 ? false : true, $PermissionID); + $Users[$PMUserID]['Username'] = $Username; +} +$Users[0]['UserStr'] = 'System'; // in case it's a message from the system +$Users[0]['Username'] = 'System'; + + + +if($UnRead=='1') { + + $DB->query("UPDATE pm_conversations_users SET UnRead='0' WHERE ConvID='$ConvID' AND UserID='$UserID'"); + // Clear the caches of the inbox and sentbox + $Cache->decrement('inbox_new_'.$UserID); +} + +// Get messages +$DB->query("SELECT SentDate, SenderID, Body, ID FROM pm_messages AS m WHERE ConvID='$ConvID' ORDER BY ID"); + +$JsonMessages = array(); +while(list($SentDate, $SenderID, $Body, $MessageID) = $DB->next_record()) { + $JsonMessage = array( + 'messageId' => $MessageID, + 'senderId' => $SenderID, + 'senderName' => $Users[(int)$SenderID]['Username'], + 'sentDate' => $SentDate, + 'body' => $Text->full_format($Body) + ); + $JsonMessages[] = $JsonMessage; +} + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'convId' => $ConvID, + 'subject' => $Subject.($ForwardedID > 0 ? ' (Forwarded to '.$ForwardedName.')':''), + 'sticky' => $Sticky, + 'messages' => $JsonMessages + ) + ) + ); \ No newline at end of file diff --git a/sections/ajax/index.php b/sections/ajax/index.php index 85350a8a..eac474f2 100644 --- a/sections/ajax/index.php +++ b/sections/ajax/index.php @@ -10,6 +10,8 @@ enforce_login(); +header('Content-Type: application/json; charset=utf-8'); + switch ($_GET['action']){ // things that (may be) used on the site case 'upload_section': @@ -39,6 +41,18 @@ case 'top10': require(SERVER_ROOT.'/sections/ajax/top10/index.php'); break; + case 'artist': + require(SERVER_ROOT.'/sections/ajax/artist.php'); + break; + case 'inbox': + require(SERVER_ROOT.'/sections/ajax/inbox/index.php'); + break; + case 'subscriptions': + require(SERVER_ROOT.'/sections/ajax/subscriptions.php'); + break; + case 'index': + require(SERVER_ROOT.'/sections/ajax/info.php'); + break; default: // If they're screwing around with the query string error(403); diff --git a/sections/ajax/info.php b/sections/ajax/info.php new file mode 100644 index 00000000..ffa9507d --- /dev/null +++ b/sections/ajax/info.php @@ -0,0 +1,59 @@ +get_value('user_info_heavy_'.$UserID); + + $DB->query("SELECT + m.Username, + m.torrent_pass, + i.AuthKey, + Uploaded AS BytesUploaded, + Downloaded AS BytesDownloaded, + RequiredRatio, + p.Level AS Class + FROM users_main AS m + INNER JOIN users_info AS i ON i.UserID=m.ID + LEFT JOIN permissions AS p ON p.ID=m.PermissionID + WHERE m.ID='$UserID'"); + + list($Username,$torrent_pass,$AuthKey,$Uploaded,$Downloaded,$RequiredRatio,$Class) = $DB->next_record(MYSQLI_NUM, array(9,11)); + +//calculate ratio --Gwindow +//returns 0 for DNE and -1 for infiinity, because we dont want strings being returned for a numeric value in our java + if($Uploaded == 0 && $Downloaded == 0) { + $Ratio = '0'; + } elseif($Downloaded == 0) { + $Ratio = '-1';} + else { +$Ratio = number_format(max($Uploaded/$Downloaded-0.005,0), 2); //Subtract .005 to floor to 2 decimals +} + + + +print json_encode( + array( + 'status' => 'success', + 'response' => array( + 'username' => $Username, + 'id' => $UserID, + 'authkey'=>$AuthKey, + 'passkey'=>$torrent_pass, + 'userstats' => array( + 'uploaded' => $Uploaded, + 'downloaded' => $Downloaded, + 'ratio' => $Ratio, + 'requiredratio' => $RequiredRatio, + //'class' => $Class + 'class' => $ClassLevels[$Class]['Name'] + ), + ) + ) +); + + +?> diff --git a/sections/ajax/subscriptions.php b/sections/ajax/subscriptions.php new file mode 100644 index 00000000..3df1b345 --- /dev/null +++ b/sections/ajax/subscriptions.php @@ -0,0 +1,121 @@ + 'failure' + ) + ); +} + +include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class +$Text = new TEXT; + +if (isset($LoggedUser['PostsPerPage'])) { + $PerPage = $LoggedUser['PostsPerPage']; +} else { + $PerPage = POSTS_PER_PAGE; +} +list($Page,$Limit) = page_limit($PerPage); + +if($LoggedUser['CustomForums']) { + unset($LoggedUser['CustomForums']['']); + $RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0)); + $PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1)); +} + +$ShowUnread = (!isset($_GET['showunread']) && !isset($HeavyInfo['SubscriptionsUnread']) || isset($HeavyInfo['SubscriptionsUnread']) && !!$HeavyInfo['SubscriptionsUnread'] || isset($_GET['showunread']) && !!$_GET['showunread']); +$ShowCollapsed = (!isset($_GET['collapse']) && !isset($HeavyInfo['SubscriptionsCollapse']) || isset($HeavyInfo['SubscriptionsCollapse']) && !!$HeavyInfo['SubscriptionsCollapse'] || isset($_GET['collapse']) && !!$_GET['collapse']); +$sql = 'SELECT + SQL_CALC_FOUND_ROWS + MAX(p.ID) AS ID + FROM forums_posts AS p + LEFT JOIN forums_topics AS t ON t.ID = p.TopicID + JOIN users_subscriptions AS s ON s.TopicID = t.ID + LEFT JOIN forums AS f ON f.ID = t.ForumID + LEFT JOIN forums_last_read_topics AS l ON p.TopicID = l.TopicID AND l.UserID = s.UserID + WHERE s.UserID = '.$LoggedUser['ID'].' + AND p.ID <= IFNULL(l.PostID,t.LastPostID) + AND ((f.MinClassRead <= '.$LoggedUser['Class']; +if(!empty($RestrictedForums)) { + $sql.=' AND f.ID NOT IN (\''.$RestrictedForums.'\')'; +} +$sql .= ')'; +if(!empty($PermittedForums)) { + $sql.=' OR f.ID IN (\''.$PermittedForums.'\')'; +} +$sql .= ')'; +if($ShowUnread) { + $sql .= ' + AND IF(l.PostID IS NULL OR (t.IsLocked = \'1\' && t.IsSticky = \'0\'), t.LastPostID, l.PostID) < t.LastPostID'; +} +$sql .= ' + GROUP BY t.ID + ORDER BY t.LastPostID DESC + LIMIT '.$Limit; +$PostIDs = $DB->query($sql); +$DB->query('SELECT FOUND_ROWS()'); +list($NumResults) = $DB->next_record(); + +if($NumResults > $PerPage*($Page-1)) { + $DB->set_query_id($PostIDs); + $PostIDs = $DB->collect('ID'); + $sql = 'SELECT + f.ID AS ForumID, + f.Name AS ForumName, + p.TopicID, + t.Title, + p.Body, + t.LastPostID, + t.IsLocked, + t.IsSticky, + p.ID, + um.ID, + um.Username, + ui.Avatar, + p.EditedUserID, + p.EditedTime, + ed.Username AS EditedUsername + FROM forums_posts AS p + LEFT JOIN forums_topics AS t ON t.ID = p.TopicID + LEFT JOIN forums AS f ON f.ID = t.ForumID + LEFT JOIN users_main AS um ON um.ID = p.AuthorID + LEFT JOIN users_info AS ui ON ui.UserID = um.ID + LEFT JOIN users_main AS ed ON ed.ID = um.ID + WHERE p.ID IN ('.implode(',',$PostIDs).') + ORDER BY f.Name ASC, t.LastPostID DESC'; + $DB->query($sql); +} + +$JsonPosts = array(); +while(list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()){ + $JsonPost = array( + 'forumId' => $ForumID, + 'forumName' => $ForumName, + 'threadId' => $TopicID, + 'threadTitle' => $ThreadTitle, + 'postId' => $PostID, + 'lastPostId' => $LastPostID, + 'locked' => $Locked, + 'new' => ($PostID<$LastPostID && !$Locked) + ); + $JsonPosts[] = $JsonPost; +} + +print + json_encode( + array( + 'status' => 'success', + 'response' => array( + 'posts' => $JsonPosts + ) + ) + ); +?> diff --git a/sections/ajax/top10/torrents.php b/sections/ajax/top10/torrents.php index f8990ea8..4ed66e76 100644 --- a/sections/ajax/top10/torrents.php +++ b/sections/ajax/top10/torrents.php @@ -165,7 +165,10 @@ function generate_torrent_json($Caption, $Tag, $Details, $Limit) { 'torrentId' => $TorrentID, 'groupId' => $GroupID, 'artist' => $TruncArtist, + 'groupName' => $GroupName, + 'groupCategory' => $GroupCategoryID, 'groupYear' => $GroupYear, + 'remasterTitle' => $RemasterTitle, 'format' => $Format, 'encoding' => $Encoding, 'hasLog' => $HasLog, @@ -176,7 +179,8 @@ function generate_torrent_json($Caption, $Tag, $Details, $Limit) { 'tags' => $TagList, 'snatched' => $Snatched, 'seeders' => $Seeders, - 'leechers' => $Leechers + 'leechers' => $Leechers, + 'data' => $Data ); } diff --git a/sections/artist/artist.php b/sections/artist/artist.php index ddebfc1f..cf975cb1 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -60,6 +60,13 @@ function compare($X, $Y){ list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(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); +} + //----------------- Build list and get stats ob_start(); @@ -332,7 +339,12 @@ function compare($X, $Y){ - [] + [ + 0) && ($Torrent['Size'] < 1073741824) + && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> + FL | + + ]   »  diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index 2ea27eb0..db94bfce 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -46,6 +46,13 @@ function compare($X, $Y){ } } +$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); +} + $Title = ($Sneaky)?"$Username's bookmarked torrents":'Your bookmarked torrents'; show_header($Title, 'browse'); @@ -185,8 +192,12 @@ function compare($X, $Y){ ?> - - [DL] + [ + 0) && ($Torrent['Size'] < 1073741824) + && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> + FL | + + DL]   »  @@ -206,6 +217,8 @@ function compare($X, $Y){ if(!empty($Torrent['FreeTorrent'])) { $DisplayName .=' Freeleech!'; + } elseif(in_array($TorrentID, $TokenTorrents)) { + $DisplayName .= 'Personal Freeleech!'; } ?> @@ -216,7 +229,12 @@ function compare($X, $Y){ - [DL + [ + 0) && ($Torrent['Size'] < 1073741824) + && !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?> + FL | + + DL | RP] diff --git a/sections/collages/add_torrent.php b/sections/collages/add_torrent.php index 631619b2..23ac3c9d 100644 --- a/sections/collages/add_torrent.php +++ b/sections/collages/add_torrent.php @@ -51,15 +51,20 @@ $DB->query("SELECT GroupID FROM collages_torrents WHERE CollageID='$CollageID' AND GroupID='$GroupID'"); if($DB->record_count() == 0) { $DB->query("INSERT IGNORE INTO collages_torrents - (CollageID, GroupID, UserID, Sort) + (CollageID, GroupID, UserID, Sort, AddedOn) VALUES - ('$CollageID', '$GroupID', '$LoggedUser[ID]', '$Sort')"); + ('$CollageID', '$GroupID', '$LoggedUser[ID]', '$Sort', NOW())"); $DB->query("UPDATE collages SET NumTorrents=NumTorrents+1 WHERE ID='$CollageID'"); $Cache->delete_value('collage_'.$CollageID); $Cache->delete_value('torrents_details_'.$GroupID); $Cache->delete_value('torrent_collages_'.$GroupID); + + $DB->query("SELECT UserID FROM users_collage_subs WHERE CollageID=$CollageID"); + while (list($CacheUserID) = $DB->next_record()) { + $Cache->delete_value('collage_subs_user_new_'.$CacheUserID); + } } else { error('Torrent already in collage!'); } diff --git a/sections/collages/browse.php b/sections/collages/browse.php index 396df1b0..cac78a5b 100644 --- a/sections/collages/browse.php +++ b/sections/collages/browse.php @@ -67,23 +67,25 @@ $BookmarkJoin = ''; } -$SQL = "SELECT SQL_CALC_FOUND_ROWS - c.ID, - c.Name, +$BaseSQL = $SQL = "SELECT SQL_CALC_FOUND_ROWS + c.ID, + c.Name, c.NumTorrents, c.TagList, c.CategoryID, c.UserID, - um.Username - FROM collages AS c + um.Username + FROM collages AS c $BookmarkJoin - LEFT JOIN users_main AS um ON um.ID=c.UserID + LEFT JOIN users_main AS um ON um.ID=c.UserID WHERE Deleted = '0'"; if ($BookmarkView) { $SQL .= " AND bc.UserID = '" . $LoggedUser['ID'] . "'"; } + + if(!empty($Search)) { $SQL .= " AND $Type LIKE '%"; $SQL .= implode("%' AND $Type LIKE '%", $Words); @@ -126,6 +128,11 @@ $SQL.=" AND CategoryID IN(".db_string(implode(',',$Categories)).")"; } +if ($_GET['action'] == 'mine') { + $SQL = $BaseSQL; + $SQL .= " AND c.UserID='".$LoggedUser['ID']."' AND c.CategoryID=0"; +} + $SQL.=" ORDER BY $Order $Way LIMIT $Limit "; $DB->query($SQL); $Collages = $DB->to_array(); @@ -140,42 +147,6 @@

Browse collages

-
@@ -228,11 +199,50 @@ - +
@@ -219,6 +220,9 @@ function check_paranoia_here($Setting) {
  • Required ratio:
  • + + 0) && ($OwnProfile || check_perms('users_mod'))) { ?> +
  • Tokens:
  • @@ -664,9 +668,11 @@ function check_paranoia_here($Setting) { query("SELECT ID, Name FROM collages WHERE UserID='$UserID' AND CategoryID='0' AND Deleted='0'"); -list($CollageID, $Name) = $DB->next_record(); -if($CollageID) { +$DB->query("SELECT ID, Name FROM collages WHERE UserID='$UserID' AND CategoryID='0' AND Deleted='0' ORDER BY Featured DESC, Name ASC"); +$Collages = $DB->to_array(); +$FirstCol = true; +foreach ($Collages as $CollageInfo) { + list($CollageID, $CName) = $CollageInfo; $DB->query("SELECT ct.GroupID, tg.WikiImage, tg.CategoryID @@ -675,12 +681,18 @@ function check_paranoia_here($Setting) { WHERE ct.CollageID='$CollageID' ORDER BY ct.Sort LIMIT 5"); $Collage = $DB->to_array(); - ?> - - + + >
    - see full
    + + - see full + + + + +
    - + query("UPDATE users_collage_subs SET LastVisit = NOW() WHERE UserID = ".$LoggedUser['ID']); +$Cache->delete_value('collage_subs_user_new_'.$LoggedUser['ID']); +header('Location: userhistory.php?action=subscribed_collages'); +?> diff --git a/sections/userhistory/collage_subscribe.php b/sections/userhistory/collage_subscribe.php new file mode 100644 index 00000000..eab4fc3e --- /dev/null +++ b/sections/userhistory/collage_subscribe.php @@ -0,0 +1,23 @@ +get_value('collage_subs_user_'.$LoggedUser['ID'])) { + $DB->query('SELECT CollageID FROM users_collage_subs WHERE UserID = '.db_string($LoggedUser['ID'])); + $UserSubscriptions = $DB->collect(0); + $Cache->cache_value('collage_subs_user_'.$LoggedUser['ID'],$UserSubscriptions,0); +} + +if(($Key = array_search($_GET['collageid'],$UserSubscriptions)) !== FALSE) { + $DB->query('DELETE FROM users_collage_subs WHERE UserID = '.db_string($LoggedUser['ID']).' AND CollageID = '.db_string($_GET['collageid'])); + unset($UserSubscriptions[$Key]); +} else { + $DB->query("INSERT IGNORE INTO users_collage_subs (UserID, CollageID, LastVisit) VALUES ($LoggedUser[ID], ".db_string($_GET['collageid']).", NOW())"); + array_push($UserSubscriptions, $_GET['collageid']); +} +$Cache->replace_value('collage_subs_user_'.$LoggedUser['ID'], $UserSubscriptions, 0); +$Cache->delete_value('collage_subs_user_new_'.$LoggedUser['ID']); diff --git a/sections/userhistory/index.php b/sections/userhistory/index.php index a8e2d8fd..0eb7cd6e 100644 --- a/sections/userhistory/index.php +++ b/sections/userhistory/index.php @@ -52,7 +52,19 @@ case 'catchup': require('catchup.php'); break; + case 'collage_subscribe': + require('collage_subscribe.php'); + break; + case 'subscribed_collages': + require('subscribed_collages.php'); + break; + case 'catchup_collages': + require('catchup_collages.php'); + break; + case 'token_history': + require('token_history.php'); + break; default: //You trying to mess with me query string? To the home page with you! header('Location: index.php'); diff --git a/sections/userhistory/subscribed_collages.php b/sections/userhistory/subscribed_collages.php new file mode 100644 index 00000000..b744e591 --- /dev/null +++ b/sections/userhistory/subscribed_collages.php @@ -0,0 +1,299 @@ + s.LastVisit + GROUP BY c.ID"; +} else { + $sql = "SELECT c.ID, + c.Name, + c.NumTorrents, + s.LastVisit + FROM collages AS c + JOIN users_collage_subs AS s ON s.CollageID = c.ID + LEFT JOIN collages_torrents AS ct ON ct.CollageID = c.ID + WHERE s.UserID = ".$LoggedUser['ID']." AND c.Deleted='0' + GROUP BY c.ID"; +} + +$DB->query($sql); +$NumResults = $DB->record_count(); +$CollageSubs = $DB->to_array(); +?> +
    +

    Subscribed collages

    + + + +
    + No subscribed collages +
    +query("SELECT ct.GroupID, + tg.WikiImage, + tg.CategoryID + FROM collages_torrents AS ct + JOIN torrents_group AS tg ON ct.GroupID = tg.ID + WHERE ct.CollageID = $CollageID + AND ct.AddedOn > '$LastVisit' + ORDER BY ct.AddedOn"); + $NewTorrentCount = $DB->record_count(); + //$NewTorrents = $DB->to_array(); + //$Artists = get_artists($GroupID); + + $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(); + } + + $Artists = get_artists($GroupIDs); + $Number = 0; + + // foreach ($NewTorrents as $TorrentGroup) { + // list($GroupID, $GroupName, $GroupYear, $ReleaseType, $RecordLabel, $CatalogueNumber, $WikiImage) = $TorrentGroup; + // $DisplayName = display_artists($Artists[$GroupID]); + // $AltName=$GroupName; + foreach ($TorrentList as $GroupID => $Group) { + list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $GroupArtists) = array_values($Group); + list($GroupID2, $Image, $GroupCategoryID) = array_values($CollageDataList[$GroupID]); + + unset($DisplayName); + + $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.'
    '; + + 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) { +?> + + +
    + +
    + + + + + <?=$AltName?> + + <?=$Categories[$GroupCategoryID-1]?> + + + + + + + + + $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) { + if($Torrent['Remastered'] && $Torrent['RemasterYear'] != 0) { + + $EditionID++; + + $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']); + +?> + + + + + + + + + + + + [DL] + +   »  + + + + > + + +'.$GroupName.''; + + if(!empty($Torrent['FreeTorrent'])) { + $DisplayName .=' Freeleech!'; + } +?> + + + +
    +
    + + + + [DL + | RP] + + + + + + + > + + + + + + + + + +
    + + ( new torrent) +   + +    [Unsubscribe] + +
    + + + + + + + + + + + + + + +
    TorrentsSizeSnatchesSeedersLeechers
    + + +
    + diff --git a/sections/userhistory/token_history.php b/sections/userhistory/token_history.php index cb9dc538..1fa4c7b7 100644 --- a/sections/userhistory/token_history.php +++ b/sections/userhistory/token_history.php @@ -29,7 +29,7 @@ if (!is_number($UserID) || !is_number($TorrentID)) { error(403); } $DB->query("SELECT info_hash FROM torrents where ID = $TorrentID"); - if (list($InfoHash) = $DB->next_record()) { + if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, FALSE)) { $DB->query("UPDATE users_freeleeches SET Expired=TRUE WHERE UserID=$UserID AND TorrentID=$TorrentID"); $Cache->delete_value('users_tokens_'.$UserID); update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID)); diff --git a/static/functions/collage.js b/static/functions/collage.js index 78630140..84860d3e 100644 --- a/static/functions/collage.js +++ b/static/functions/collage.js @@ -18,4 +18,17 @@ function Cancel() { } } document.getElementById("choices").raw().value = ""; +} + +function CollageSubscribe(collageid) { + ajax.get("userhistory.php?action=collage_subscribe&collageid=" + collageid + "&auth=" + authkey, function() { + var subscribeLink = $("#subscribelink" + collageid).raw(); + if(subscribeLink) { + if(subscribeLink.firstChild.nodeValue.substr(1,1) == 'U') { + subscribeLink.firstChild.nodeValue = "[Subscribe]"; + } else { + subscribeLink.firstChild.nodeValue = "[Unsubscribe]"; + } + } + }); } \ No newline at end of file