Gazelle/sections/torrents/takegroupedit.php

214 lines
5.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/text.class.php');
2011-03-28 14:21:28 +00:00
$Text = new TEXT;
// Quick SQL injection check
2013-05-01 08:00:16 +00:00
if (!$_REQUEST['groupid'] || !is_number($_REQUEST['groupid'])) {
2011-03-28 14:21:28 +00:00
error(404);
}
// End injection check
2013-05-01 08:00:16 +00:00
if (!check_perms('site_edit_wiki')) {
error(403);
}
2011-03-28 14:21:28 +00:00
// Variables for database input
$UserID = $LoggedUser['ID'];
$GroupID = $_REQUEST['groupid'];
2012-02-22 08:00:31 +00:00
// Get information for the group log
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT VanityHouse
FROM torrents_group
WHERE ID = '$GroupID'");
2012-02-22 08:00:31 +00:00
if (!(list($OldVH) = $DB->next_record())) {
error(404);
}
2013-05-01 08:00:16 +00:00
if (!empty($_GET['action']) && $_GET['action'] == 'revert') { // if we're reverting to a previous revision
2013-06-19 08:01:09 +00:00
$RevisionID = $_GET['revisionid'];
2013-05-01 08:00:16 +00:00
if (!is_number($RevisionID)) {
error(0);
}
2013-02-16 08:00:57 +00:00
// to cite from merge: "Everything is legit, let's just confim they're not retarded"
2013-05-01 08:00:16 +00:00
if (empty($_GET['confirm'])) {
2013-02-16 08:00:57 +00:00
View::show_header();
?>
<div class="center thin">
<div class="header">
<h2>Revert Confirm!</h2>
</div>
<div class="box pad">
<form class="confirm_form" name="torrent_group" action="torrents.php" method="get">
<input type="hidden" name="action" value="revert" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="confirm" value="true" />
<input type="hidden" name="groupid" value="<?=$GroupID?>" />
<input type="hidden" name="revisionid" value="<?=$RevisionID?>" />
2013-06-19 08:01:09 +00:00
<h3>You are attempting to revert to the revision <a href="torrents.php?id=<?=$GroupID?>&amp;revisionid=<?=$RevisionID?>"><?=$RevisionID?></a>.</h3>
2013-02-16 08:00:57 +00:00
<input type="submit" value="Confirm" />
</form>
</div>
</div>
<?
View::show_footer();
die();
}
2011-03-28 14:21:28 +00:00
} else { // with edit, the variables are passed with POST
$Body = $_POST['body'];
$Image = $_POST['image'];
$ReleaseType = (int)$_POST['releasetype'];
2013-06-19 08:01:09 +00:00
if (check_perms('torrents_edit_vanityhouse')) {
$VanityHouse = (isset($_POST['vanity_house']) ? 1 : 0);
} else {
2013-03-07 08:00:21 +00:00
$VanityHouse = $OldVH;
}
2011-03-28 14:21:28 +00:00
2013-05-01 08:00:16 +00:00
if (($GroupInfo = $Cache->get_value('torrents_details_'.$GroupID)) && !isset($GroupInfo[0][0])) {
2012-10-16 08:00:18 +00:00
$GroupCategoryID = $GroupInfo[0]['CategoryID'];
2011-03-28 14:21:28 +00:00
} else {
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT CategoryID
FROM torrents_group
WHERE ID = '$GroupID'");
2011-03-28 14:21:28 +00:00
list($GroupCategoryID) = $DB->next_record();
}
2013-05-01 08:00:16 +00:00
if ($GroupCategoryID == 1 && !isset($ReleaseTypes[$ReleaseType]) || $GroupCategoryID != 1 && $ReleaseType) {
2011-03-28 14:21:28 +00:00
error(403);
}
// Trickery
2013-05-01 08:00:16 +00:00
if (!preg_match("/^".IMAGE_REGEX."$/i", $Image)) {
2011-03-28 14:21:28 +00:00
$Image = '';
}
2013-02-25 21:16:55 +00:00
ImageTools::blacklisted($Image);
2011-03-28 14:21:28 +00:00
$Summary = db_string($_POST['summary']);
}
// Insert revision
2013-05-01 08:00:16 +00:00
if (empty($RevisionID)) { // edit
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO wiki_torrents
(PageID, Body, Image, UserID, Summary, Time)
VALUES
('$GroupID', '".db_string($Body)."', '".db_string($Image)."', '$UserID', '$Summary', '".sqltime()."')");
2013-02-22 08:00:24 +00:00
2013-06-19 08:01:09 +00:00
$DB->query("
UPDATE torrents_group
SET ReleaseType = '$ReleaseType'
WHERE ID = '$GroupID'");
2012-10-11 08:00:15 +00:00
Torrents::update_hash($GroupID);
2011-03-28 14:21:28 +00:00
}
else { // revert
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT PageID, Body, Image
FROM wiki_torrents
WHERE RevisionID = '$RevisionID'");
2011-03-28 14:21:28 +00:00
list($PossibleGroupID, $Body, $Image) = $DB->next_record();
2013-05-01 08:00:16 +00:00
if ($PossibleGroupID != $GroupID) {
error(404);
}
2013-02-22 08:00:24 +00:00
2013-06-19 08:01:09 +00:00
$DB->query("
INSERT INTO wiki_torrents
(PageID, Body, Image, UserID, Summary, Time)
2013-02-22 08:00:24 +00:00
SELECT '$GroupID', Body, Image, '$UserID', 'Reverted to revision $RevisionID', '".sqltime()."'
2013-06-19 08:01:09 +00:00
FROM wiki_artists
WHERE RevisionID = '$RevisionID'");
2011-03-28 14:21:28 +00:00
}
2013-06-19 08:01:09 +00:00
$RevisionID = $DB->inserted_id();
2011-03-28 14:21:28 +00:00
$Body = db_string($Body);
$Image = db_string($Image);
// Update torrents table (technically, we don't need the RevisionID column, but we can use it for a join which is nice and fast)
2013-05-06 08:00:32 +00:00
$DB->query("
UPDATE torrents_group
SET
2013-06-19 08:01:09 +00:00
RevisionID = '$RevisionID',
".((isset($VanityHouse)) ? "VanityHouse = '$VanityHouse'," : '')."
WikiBody = '$Body',
WikiImage = '$Image'
2011-03-28 14:21:28 +00:00
WHERE ID='$GroupID'");
2012-02-22 08:00:31 +00:00
// Log VH changes
if ($OldVH != $VanityHouse && check_perms('torrents_edit_vanityhouse')) {
2013-05-06 08:00:32 +00:00
$DB->query("
2013-06-19 08:01:09 +00:00
INSERT INTO group_log
(GroupID, UserID, Time, Info)
VALUES
('$GroupID',".$LoggedUser['ID'].",'".sqltime()."','".db_string('Vanity House status changed to '.($VanityHouse ? 'true' : 'false'))."')");
2012-02-22 08:00:31 +00:00
}
2011-03-28 14:21:28 +00:00
// There we go, all done!
$Cache->delete_value('torrents_details_'.$GroupID);
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT CollageID
FROM collages_torrents
WHERE GroupID = '$GroupID'");
2013-05-01 08:00:16 +00:00
if ($DB->record_count() > 0) {
2013-05-06 08:00:32 +00:00
while (list($CollageID) = $DB->next_record()) {
2011-03-28 14:21:28 +00:00
$Cache->delete_value('collage_'.$CollageID);
}
}
//Fix Recent Uploads/Downloads for image change
2013-05-06 08:00:32 +00:00
$DB->query("
SELECT DISTINCT UserID
FROM torrents AS t
LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID
WHERE tg.ID = $GroupID");
2011-03-28 14:21:28 +00:00
$UserIDs = $DB->collect('UserID');
2013-05-01 08:00:16 +00:00
foreach ($UserIDs as $UserID) {
2011-03-28 14:21:28 +00:00
$RecentUploads = $Cache->get_value('recent_uploads_'.$UserID);
2013-05-01 08:00:16 +00:00
if (is_array($RecentUploads)) {
foreach ($RecentUploads as $Key => $Recent) {
if ($Recent['ID'] == $GroupID) {
if ($Recent['WikiImage'] != $Image) {
2011-03-28 14:21:28 +00:00
$Recent['WikiImage'] = $Image;
$Cache->begin_transaction('recent_uploads_'.$UserID);
$Cache->update_row($Key, $Recent);
$Cache->commit_transaction(0);
}
}
}
}
}
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT ID
FROM torrents
WHERE GroupID = $GroupID");
2013-05-01 08:00:16 +00:00
if ($DB->record_count()) {
$TorrentIDs = implode(',', $DB->collect('ID'));
2013-06-19 08:01:09 +00:00
$DB->query("
SELECT DISTINCT uid
FROM xbt_snatched
WHERE fid IN ($TorrentIDs)");
2012-03-19 08:00:24 +00:00
$Snatchers = $DB->collect('uid');
2013-05-01 08:00:16 +00:00
foreach ($Snatchers as $UserID) {
2012-03-19 08:00:24 +00:00
$RecentSnatches = $Cache->get_value('recent_snatches_'.$UserID);
2013-05-01 08:00:16 +00:00
if (is_array($RecentSnatches)) {
foreach ($RecentSnatches as $Key => $Recent) {
if ($Recent['ID'] == $GroupID) {
if ($Recent['WikiImage'] != $Image) {
2012-03-19 08:00:24 +00:00
$Recent['WikiImage'] = $Image;
$Cache->begin_transaction('recent_snatches_'.$UserID);
$Cache->update_row($Key, $Recent);
$Cache->commit_transaction(0);
}
2011-03-28 14:21:28 +00:00
}
}
}
}
}
2013-06-19 08:01:09 +00:00
header("Location: torrents.php?id=$GroupID");
2011-03-28 14:21:28 +00:00
?>