Gazelle/sections/ajax/request.php

229 lines
7.9 KiB
PHP
Raw Normal View History

2012-01-28 08:00:29 +00:00
<?
$RequestTax = 0.1;
// Minimum and default amount of upload to remove from the user when they vote.
// Also change in static/functions/requests.js
2013-04-19 08:00:55 +00:00
$MinimumVote = 20 * 1024 * 1024;
2012-01-28 08:00:29 +00:00
/*
* This is the page that displays the request to the end user after being created.
*/
include(SERVER_ROOT.'/sections/requests/functions.php');
2013-04-19 08:00:55 +00:00
// Bookmarks::has_bookmarked()
2012-01-28 08:00:29 +00:00
include(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
2013-05-05 08:00:31 +00:00
if (empty($_GET['id']) || !is_number($_GET['id'])) {
2013-04-24 08:00:23 +00:00
json_die("failure");
2012-01-28 08:00:29 +00:00
}
$RequestID = $_GET['id'];
//First things first, lets get the data for the request.
2013-02-22 08:00:24 +00:00
$Request = Requests::get_requests(array($RequestID));
2012-01-28 08:00:29 +00:00
$Request = $Request['matches'][$RequestID];
2013-05-05 08:00:31 +00:00
if (empty($Request)) {
2013-04-24 08:00:23 +00:00
json_die("failure");
2012-01-28 08:00:29 +00:00
}
list($RequestID, $RequestorID, $RequestorName, $TimeAdded, $LastVote, $CategoryID, $Title, $Year, $Image, $Description, $CatalogueNumber, $ReleaseType,
$BitrateList, $FormatList, $MediaList, $LogCue, $FillerID, $FillerName, $TorrentID, $TimeFilled) = $Request;
//Convenience variables
$IsFilled = !empty($TorrentID);
$CanVote = (empty($TorrentID) && check_perms('site_vote'));
2013-04-15 08:00:54 +00:00
if ($CategoryID == 0) {
$CategoryName = 'Unknown';
2012-01-28 08:00:29 +00:00
} else {
$CategoryName = $Categories[$CategoryID - 1];
}
//Do we need to get artists?
2013-04-15 08:00:54 +00:00
if ($CategoryName == 'Music') {
2012-01-28 08:00:29 +00:00
$ArtistForm = get_request_artists($RequestID);
2012-10-11 08:00:15 +00:00
$ArtistName = Artists::display_artists($ArtistForm, false, true);
$ArtistLink = Artists::display_artists($ArtistForm, true, true);
2013-02-22 08:00:24 +00:00
2013-04-15 08:00:54 +00:00
if ($IsFilled) {
$DisplayLink = $ArtistLink."<a href=\"torrents.php?torrentid=".$TorrentID."\">".$Title."</a> [$Year]";
2012-01-28 08:00:29 +00:00
} else {
2013-04-15 08:00:54 +00:00
$DisplayLink = $ArtistLink.$Title." [$Year]";
2012-01-28 08:00:29 +00:00
}
2013-04-15 08:00:54 +00:00
$FullName = $ArtistName.$Title." [$Year]";
2013-02-22 08:00:24 +00:00
2013-04-15 08:00:54 +00:00
if ($BitrateList != '') {
$BitrateString = implode(', ', explode('|', $BitrateList));
$FormatString = implode(', ', explode('|', $FormatList));
$MediaString = implode(', ', explode('|', $MediaList));
2012-01-28 08:00:29 +00:00
} else {
2013-04-15 08:00:54 +00:00
$BitrateString = 'Unknown, please read the description.';
$FormatString = 'Unknown, please read the description.';
$MediaString = 'Unknown, please read the description.';
2012-01-28 08:00:29 +00:00
}
2013-02-22 08:00:24 +00:00
2013-04-15 08:00:54 +00:00
if (empty($ReleaseType)) {
$ReleaseName = 'Unknown';
2012-01-28 08:00:29 +00:00
} else {
$ReleaseName = $ReleaseTypes[$ReleaseType];
}
2013-02-22 08:00:24 +00:00
2013-04-15 08:00:54 +00:00
} elseif ($CategoryName == 'Audiobooks' || $CategoryName == 'Comedy') {
$FullName = $Title." [$Year]";
$DisplayLink = $Title." [$Year]";
2012-01-28 08:00:29 +00:00
} else {
$FullName = $Title;
$DisplayLink = $Title;
}
//Votes time
$RequestVotes = get_votes_array($RequestID);
$VoteCount = count($RequestVotes['Voters']);
2013-04-19 08:00:55 +00:00
$ProjectCanEdit = (check_perms('project_team') && !$IsFilled && (($CategoryID == 0) || ($CategoryName == 'Music' && $Year == 0)));
2012-01-28 08:00:29 +00:00
$UserCanEdit = (!$IsFilled && $LoggedUser['ID'] == $RequestorID && $VoteCount < 2);
$CanEdit = ($UserCanEdit || $ProjectCanEdit || check_perms('site_moderate_requests'));
if ($CategoryName == "Music") {
$JsonMusicInfo = array(
/*'composers' => $ArtistForm[4] != null ? $ArtistForm[4] : array(),
'dj' => $ArtistForm[6] != null ? $ArtistForm[6] : array(),
'artists' => $ArtistForm[1] != null ? $ArtistForm[1] : array(),
'with' => $ArtistForm[2] != null ? $ArtistForm[2] : array(),
'conductor' => $ArtistForm[5] != null ? $ArtistForm[5] : array(),
'remixedBy' => $ArtistForm[3] != null ? $ArtistForm[3] : array()*/
'composers' => $ArtistForm[4] == null ? array() : pullmediainfo($ArtistForm[4]),
'dj' => $ArtistForm[6] == null ? array() : pullmediainfo($ArtistForm[6]),
'artists' => $ArtistForm[1] == null ? array() : pullmediainfo($ArtistForm[1]),
'with' => $ArtistForm[2] == null ? array() : pullmediainfo($ArtistForm[2]),
'conductor' => $ArtistForm[5] == null ? array() : pullmediainfo($ArtistForm[5]),
2012-02-19 08:00:19 +00:00
'remixedBy' => $ArtistForm[3] == null ? array() : pullmediainfo($ArtistForm[3]),
'producer' => $ArtistForm[7] == null ? array() : pullmediainfo($ArtistForm[7])
2012-01-28 08:00:29 +00:00
);
2013-04-24 08:00:23 +00:00
} else {
$JsonMusicInfo = new stdClass; //json_encodes into an empty object: {}
2012-01-28 08:00:29 +00:00
}
$JsonTopContributors = array();
$VoteMax = ($VoteCount < 5 ? $VoteCount : 5);
2013-04-19 08:00:55 +00:00
for ($i = 0; $i < $VoteMax; $i++) {
2012-01-28 08:00:29 +00:00
$User = array_shift($RequestVotes['Voters']);
$JsonTopContributors[] = array(
'userId' => (int) $User['UserID'],
'userName' => $User['Username'],
'bounty' => (int) $User['Bounty']
);
}
reset($RequestVotes['Voters']);
$Results = $Cache->get_value('request_comments_'.$RequestID);
2013-04-15 08:00:54 +00:00
if ($Results === false) {
2012-01-28 08:00:29 +00:00
$DB->query("SELECT
COUNT(c.ID)
FROM requests_comments as c
WHERE c.RequestID = '$RequestID'");
list($Results) = $DB->next_record();
$Cache->cache_value('request_comments_'.$RequestID, $Results, 0);
}
2012-10-11 08:00:15 +00:00
list($Page,$Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE,$Results);
2012-01-28 08:00:29 +00:00
//Get the cache catalogue
2013-04-15 08:00:54 +00:00
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
2012-01-28 08:00:29 +00:00
$CatalogueLimit=$CatalogueID*THREAD_CATALOGUE . ', ' . THREAD_CATALOGUE;
//---------- Get some data to start processing
// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
$Catalogue = $Cache->get_value('request_comments_'.$RequestID.'_catalogue_'.$CatalogueID);
2013-04-15 08:00:54 +00:00
if ($Catalogue === false) {
$DB->query("
SELECT
c.ID,
c.AuthorID,
c.AddedTime,
c.Body,
c.EditedUserID,
c.EditedTime,
u.Username
2012-01-28 08:00:29 +00:00
FROM requests_comments as c
2013-04-15 08:00:54 +00:00
LEFT JOIN users_main AS u ON u.ID=c.EditedUserID
2012-01-28 08:00:29 +00:00
WHERE c.RequestID = '$RequestID'
ORDER BY c.ID
LIMIT $CatalogueLimit");
$Catalogue = $DB->to_array(false,MYSQLI_ASSOC);
$Cache->cache_value('request_comments_'.$RequestID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
}
//This is a hybrid to reduce the catalogue down to the page elements: We use the page limit % catalogue
2013-04-15 08:00:54 +00:00
$Thread = array_slice($Catalogue,((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) % THREAD_CATALOGUE),TORRENT_COMMENTS_PER_PAGE,true);
2012-01-28 08:00:29 +00:00
$JsonRequestComments = array();
2013-05-04 08:00:48 +00:00
foreach ($Thread as $Key => $Post) {
2012-01-28 08:00:29 +00:00
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
2012-10-11 08:00:15 +00:00
list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
2012-01-28 08:00:29 +00:00
$JsonRequestComments[] = array(
'postId' => (int) $PostID,
'authorId' => (int) $AuthorID,
'name' => $Username,
'donor' => $Donor == 1,
'warned' => ($Warned!='0000-00-00 00:00:00'),
'enabled' => ($Enabled == 2 ? false : true),
2012-10-11 08:00:15 +00:00
'class' => Users::make_class_string($PermissionID),
2012-01-28 08:00:29 +00:00
'addedTime' => $AddedTime,
'avatar' => $Avatar,
'comment' => $Text->full_format($Body),
'editedUserId' => (int) $EditedUserID,
'editedUsername' => $EditedUsername,
'editedTime' => $EditedTime
);
}
$JsonTags = array();
2013-04-15 08:00:54 +00:00
foreach ($Request['Tags'] as $Tag) {
2012-01-28 08:00:29 +00:00
$JsonTags[] = $Tag;
}
2013-04-24 08:00:23 +00:00
json_die("success", array(
'requestId' => (int) $RequestID,
'requestorId' => (int) $RequestorID,
'requestorName' => $RequestorName,
'requestTax' => $RequestTax,
'timeAdded' => $TimeAdded,
'canEdit' => $CanEdit,
'canVote' => $CanVote,
'minimumVote' => $MinimumVote,
'voteCount' => $VoteCount,
'lastVote' => $LastVote,
'topContributors' => $JsonTopContributors,
'totalBounty' => (int) $RequestVotes['TotalBounty'],
'categoryId' => (int) $CategoryID,
'categoryName' => $CategoryName,
'title' => $Title,
'year' => (int) $Year,
'image' => $Image,
'description' => $Text->full_format($Description),
'musicInfo' => $JsonMusicInfo,
'catalogueNumber' => $CatalogueNumber,
'releaseType' => (int) $ReleaseType,
'releaseName' => $ReleaseName,
'bitrateList' => $BitrateList,
'formatList' => $FormatList,
'mediaList' => $MediaList,
'logCue' => $LogCue,
'isFilled' => $IsFilled,
'fillerId' => (int) $FillerID,
'fillerName' => $FillerName,
'torrentId' => (int) $TorrentID,
'timeFilled' => $TimeFilled,
'tags' => $JsonTags,
'comments' => $JsonRequestComments,
'commentPage' => (int) $Page,
'commentPages' => (int) ceil($Results / TORRENT_COMMENTS_PER_PAGE)
));
2012-01-28 08:00:29 +00:00
?>