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 @@ + +authorize(true); + +//For sorting tags +function compare($X, $Y){ + return($Y['count'] - $X['count']); +} + +include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked() +include(SERVER_ROOT.'/sections/requests/functions.php'); + +include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class +$Text = new TEXT; + +// Similar artist map +include(SERVER_ROOT.'/classes/class_artist.php'); +include(SERVER_ROOT.'/classes/class_artists_similar.php'); + +$ArtistID = $_GET['id']; +if(!is_number($ArtistID)) { + print json_encode(array('status' => '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]'; } + +?> +
Name | @@ -47,7 +47,13 @@ | Tags | |
Featured | +/> | +||
Locked | checked="checked" }?>/> | diff --git a/sections/collages/edit_handle.php b/sections/collages/edit_handle.php index 78ebccbd..648b4cf0 100644 --- a/sections/collages/edit_handle.php +++ b/sections/collages/edit_handle.php @@ -26,7 +26,18 @@ $DB->query("UPDATE collages SET Description='".db_string($_POST['description'])."', TagList='$TagList' WHERE ID='$CollageID'"); -if (check_perms('site_collages_delete')) { +if (!check_perms('site_collages_delete') && ($CategoryID == 0 && $UserID == $LoggedUser['ID'] && check_perms('site_collages_renamepersonal'))) { + if(!stristr($_POST['name'], $LoggedUser['Username'])) { + error("Your personal collage's title must include your username."); + } +} + +if (isset($_POST['featured']) && $CategoryID == 0 && (($LoggedUser['ID'] == $UserID && check_perms('site_collages_personal')) || check_perms('site_collages_delete'))) { + $DB->query("UPDATE collages SET Featured=0 WHERE CategoryID=0 and UserID=$UserID"); + $DB->query("UPDATE collages SET Featured=1 WHERE ID=$CollageID"); +} + +if (check_perms('site_collages_delete') || ($CategoryID == 0 && $UserID == $LoggedUser['ID'] && check_perms('site_collages_renamepersonal'))) { $DB->query("UPDATE collages SET Name='".db_string($_POST['name'])."' WHERE ID='$CollageID'"); } diff --git a/sections/collages/index.php b/sections/collages/index.php index fee6a565..cbf9e2fe 100644 --- a/sections/collages/index.php +++ b/sections/collages/index.php @@ -65,14 +65,17 @@ if(!check_perms('site_collages_personal')) { error(403); } - $DB->query("SELECT ID FROM collages WHERE UserID='$LoggedUser[ID]' AND CategoryID='0' AND Deleted='0'"); - if($DB->record_count() > 0) { + + $DB->query("SELECT COUNT(ID) FROM collages WHERE UserID='$LoggedUser[ID]' AND CategoryID='0' AND Deleted='0'"); + list($CollageCount) = $DB->next_record(); + + if($CollageCount >= $LoggedUser['Permissions']['MaxCollages']) { list($CollageID) = $DB->next_record(); header('Location: collage.php?id='.$CollageID); die(); } - - $DB->query("INSERT INTO collages (Name, Description, CategoryID, UserID) VALUES ('$LoggedUser[Username]\'s personal collage', 'Personal collage for $LoggedUser[Username]. The first 5 albums will appear on his or her [url=http:\/\/".NONSSL_SITE_URL."\/user.php?id=$LoggedUser[ID]]profile[\/url].', '0', $LoggedUser[ID])"); + $NameStr = ($CollageCount > 0)?" no. " . ($CollageCount + 1):''; + $DB->query("INSERT INTO collages (Name, Description, CategoryID, UserID) VALUES ('$LoggedUser[Username]\'s personal collage$NameStr', 'Personal collage for $LoggedUser[Username]. The first 5 albums will appear on his or her [url=http:\/\/".NONSSL_SITE_URL."\/user.php?id=$LoggedUser[ID]]profile[\/url].', '0', $LoggedUser[ID])"); $CollageID = $DB->inserted_id(); header('Location: collage.php?id='.$CollageID); die(); diff --git a/sections/collages/new.php b/sections/collages/new.php index e6d0dfce..cbb6155c 100644 --- a/sections/collages/new.php +++ b/sections/collages/new.php @@ -1,25 +1,36 @@ show_header('Create a collage'); + +if (!check_perms('site_collages_renamepersonal')) { + $ChangeJS = 'OnChange="if ( this.options[this.selectedIndex].value == \'0\') { namebox.style.display = \'none\'; personal.style.display = \'inline\'; } else { namebox.style.display = \'inline\'; personal.style.display = \'none\'; }"'; +} ?>