Gazelle/sections/torrents/index.php

458 lines
12 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
//Function used for pagination of peer/snatch/download lists on details.php
function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
2013-04-20 08:01:01 +00:00
$NumPages = ceil($NumResults / 100);
2011-03-28 14:21:28 +00:00
$PageLinks = array();
2013-04-20 08:01:01 +00:00
for ($i = 1; $i <= $NumPages; $i++) {
if ($i == $CurrentPage) {
$PageLinks[] = $i;
2011-03-28 14:21:28 +00:00
} else {
2013-07-04 08:00:56 +00:00
$PageLinks[] = "<a href=\"#\" onclick=\"$Action($TorrentID, $i)\">$i</a>";
2011-03-28 14:21:28 +00:00
}
}
2013-07-04 08:00:56 +00:00
return implode(' | ', $PageLinks);
2011-03-28 14:21:28 +00:00
}
2012-02-23 08:00:18 +00:00
// This gets used in a few places
$ArtistTypes = array(1 => 'Main', 2 => 'Guest', 3 => 'Remixer', 4 => 'Composer', 5 => 'Conductor', 6 => 'DJ/Compiler', 7 => 'Producer');
2013-04-20 08:01:01 +00:00
if (!empty($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
2011-03-28 14:21:28 +00:00
case 'edit':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/edit.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'editgroup':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/editgroup.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'editgroupid':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/editgroupid.php');
break;
2013-02-22 08:00:24 +00:00
2013-03-02 08:00:34 +00:00
case 'changecategory':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takechangecategory.php');
break;
2011-03-28 14:21:28 +00:00
case 'takeedit':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takeedit.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'newgroup':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takenewgroup.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'peerlist':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/peerlist.php');
break;
2013-04-20 08:01:01 +00:00
2011-03-28 14:21:28 +00:00
case 'snatchlist':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/snatchlist.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'downloadlist':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/downloadlist.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'redownload':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/redownload.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'revert':
case 'takegroupedit':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takegroupedit.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'nonwikiedit':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/nonwikiedit.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'rename':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/rename.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'merge':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/merge.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'add_alias':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/add_alias.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'delete_alias':
enforce_login();
authorize();
include(SERVER_ROOT.'/sections/torrents/delete_alias.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'history':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/history.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'delete':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/delete.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'takedelete':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takedelete.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'masspm':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/masspm.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'reseed':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/reseed.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'takemasspm':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/takemasspm.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'vote_tag':
enforce_login();
authorize();
include(SERVER_ROOT.'/sections/torrents/vote_tag.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'add_tag':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/add_tag.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'delete_tag':
enforce_login();
authorize();
include(SERVER_ROOT.'/sections/torrents/delete_tag.php');
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'notify':
enforce_login();
include(SERVER_ROOT.'/sections/torrents/notify.php');
break;
case 'manage_artists':
enforce_login();
2013-02-22 08:00:24 +00:00
require(SERVER_ROOT.'/sections/torrents/manage_artists.php');
2011-03-28 14:21:28 +00:00
break;
2012-10-27 08:00:09 +00:00
case 'notify_clear':
case 'notify_clear_item':
2013-02-15 08:00:35 +00:00
case 'notify_clear_items':
2012-10-27 08:00:09 +00:00
case 'notify_clearitem':
case 'notify_clear_filter':
2011-03-28 14:21:28 +00:00
case 'notify_cleargroup':
2012-10-27 08:00:09 +00:00
case 'notify_catchup':
case 'notify_catchup_filter':
2011-03-28 14:21:28 +00:00
authorize();
enforce_login();
2012-10-27 08:00:09 +00:00
require(SERVER_ROOT.'/sections/torrents/notify_actions.php');
2011-03-28 14:21:28 +00:00
break;
2012-10-27 08:00:09 +00:00
2011-03-28 14:21:28 +00:00
case 'download':
require(SERVER_ROOT.'/sections/torrents/download.php');
2011-03-28 14:21:28 +00:00
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'reply':
enforce_login();
authorize();
2013-04-20 08:01:01 +00:00
if (!isset($_POST['groupid']) || !is_number($_POST['groupid']) || trim($_POST['body']) === '' || !isset($_POST['body'])) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-04-20 08:01:01 +00:00
if ($LoggedUser['DisablePosting']) {
2013-05-05 08:00:31 +00:00
error('Your posting privileges have been removed.');
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$GroupID = $_POST['groupid'];
2013-04-20 08:01:01 +00:00
if (!$GroupID) {
error(404);
}
2013-02-22 08:00:24 +00:00
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT
CEIL((
2013-07-04 08:00:56 +00:00
SELECT COUNT(ID) + 1
2013-05-05 08:00:31 +00:00
FROM torrents_comments AS tc
2013-07-04 08:00:56 +00:00
WHERE tc.GroupID = '".db_string($GroupID)."'
) / ".TORRENT_COMMENTS_PER_PAGE.'
) AS Pages');
2011-03-28 14:21:28 +00:00
list($Pages) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2013-05-05 08:00:31 +00:00
$DB->query("
2013-07-04 08:00:56 +00:00
INSERT INTO torrents_comments
(GroupID, AuthorID, AddedTime, Body)
VALUES
('".db_string($GroupID)."', '".db_string($LoggedUser['ID'])."', '".sqltime()."', '".db_string($_POST['body'])."')");
2013-05-05 08:00:31 +00:00
$PostID = $DB->inserted_id();
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
2013-07-04 08:00:56 +00:00
$Cache->begin_transaction("torrent_comments_{$GroupID}_catalogue_$CatalogueID");
2011-03-28 14:21:28 +00:00
$Post = array(
2013-07-04 08:00:56 +00:00
'ID' => $PostID,
'AuthorID' => $LoggedUser['ID'],
'AddedTime' => sqltime(),
'Body' => $_POST['body'],
'EditedUserID' => 0,
'EditedTime' => '0000-00-00 00:00:00',
'Username' => ''
2011-03-28 14:21:28 +00:00
);
$Cache->insert('', $Post);
$Cache->commit_transaction(0);
2013-07-04 08:00:56 +00:00
$Cache->increment("torrent_comments_$GroupID");
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
header("Location: torrents.php?id=$GroupID&page=$Pages");
2011-03-28 14:21:28 +00:00
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'get_post':
enforce_login();
2013-04-20 08:01:01 +00:00
if (!$_GET['post'] || !is_number($_GET['post'])) {
error(0);
}
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT Body
FROM torrents_comments
WHERE ID = '".db_string($_GET['post'])."'");
2011-03-28 14:21:28 +00:00
list($Body) = $DB->next_record(MYSQLI_NUM);
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
echo trim($Body);
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'takeedit_post':
enforce_login();
authorize();
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/text.class.php'); // Text formatting class
2011-03-28 14:21:28 +00:00
$Text = new TEXT;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Quick SQL injection check
2013-04-20 08:01:01 +00:00
if (!$_POST['post'] || !is_number($_POST['post'])) {
error(0);
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Mainly
2013-05-16 16:15:57 +00:00
$DB->query("
SELECT
tc.Body,
tc.AuthorID,
tc.GroupID,
tc.AddedTime
2011-03-28 14:21:28 +00:00
FROM torrents_comments AS tc
2013-07-04 08:00:56 +00:00
WHERE tc.ID = '".db_string($_POST['post'])."'");
list($OldBody, $AuthorID, $GroupID, $AddedTime) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2013-05-16 16:15:57 +00:00
$DB->query("
SELECT ceil(COUNT(ID) / ".TORRENT_COMMENTS_PER_PAGE.") AS Page
FROM torrents_comments
WHERE GroupID = $GroupID
AND ID <= $_POST[post]");
2011-03-28 14:21:28 +00:00
list($Page) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if ($LoggedUser['ID'] != $AuthorID && !check_perms('site_moderate_forums')) {
error(404);
}
if ($DB->record_count() == 0) {
error(404);
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Perform the update
2013-05-16 16:15:57 +00:00
$DB->query("
UPDATE torrents_comments
SET
Body = '".db_string($_POST['body'])."',
EditedUserID = '".db_string($LoggedUser['ID'])."',
EditedTime = '".sqltime()."'
2013-07-04 08:00:56 +00:00
WHERE ID = '".db_string($_POST['post'])."'");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Update the cache
2013-04-20 08:01:01 +00:00
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
2013-07-04 08:00:56 +00:00
$Cache->begin_transaction("torrent_comments_{$GroupID}_catalogue_$CatalogueID");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$Cache->update_row($_POST['key'], array(
2013-07-04 08:00:56 +00:00
'ID' => $_POST['post'],
'AuthorID' => $AuthorID,
'AddedTime' => $AddedTime,
'Body' => $_POST['body'],
'EditedUserID' => db_string($LoggedUser['ID']),
'EditedTime' => sqltime(),
'Username' => $LoggedUser['Username']
2011-03-28 14:21:28 +00:00
));
$Cache->commit_transaction(0);
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT INTO comments_edits
(Page, PostID, EditUser, EditTime, Body)
VALUES
('torrents', ".db_string($_POST['post']).", ".db_string($LoggedUser['ID']).", '".sqltime()."', '".db_string($OldBody)."')");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// This gets sent to the browser, which echoes it in place of the old body
echo $Text->full_format($_POST['body']);
break;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
case 'delete_post':
enforce_login();
authorize();
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Quick SQL injection check
2013-04-20 08:01:01 +00:00
if (!$_GET['postid'] || !is_number($_GET['postid'])) {
error(0);
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Make sure they are moderators
2013-04-20 08:01:01 +00:00
if (!check_perms('site_moderate_forums')) {
error(403);
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Get topicid, forumid, number of pages
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT
GroupID,
CEIL(COUNT(tc.ID) / ".TORRENT_COMMENTS_PER_PAGE.") AS Pages,
CEIL(SUM(IF(tc.ID <= ".$_GET['postid'].", 1, 0)) / ".TORRENT_COMMENTS_PER_PAGE.") AS Page
2011-03-28 14:21:28 +00:00
FROM torrents_comments AS tc
2013-07-04 08:00:56 +00:00
WHERE tc.GroupID =
(SELECT GroupID
FROM torrents_comments
WHERE ID = ".$_GET['postid'].')
GROUP BY tc.GroupID');
2013-04-20 08:01:01 +00:00
list($GroupID, $Pages, $Page) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// $Pages = number of pages in the thread
// $Page = which page the post is on
// These are set for cache clearing.
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
$DB->query("
DELETE FROM torrents_comments
WHERE ID = '".db_string($_GET['postid'])."'");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//We need to clear all subsequential catalogues as they've all been bumped with the absence of this post
2013-04-20 08:01:01 +00:00
$ThisCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
for ($i = $ThisCatalogue; $i <= $LastCatalogue; $i++) {
2013-07-04 08:00:56 +00:00
$Cache->delete_value("torrent_comments_{$GroupID}_catalogue_$i");
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-04 08:00:56 +00:00
// Delete thread info cache (e.g. number of pages)
$Cache->delete_value("torrent_comments_$GroupID");
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
break;
2013-07-04 08:00:56 +00:00
case 'regen_filelist':
2013-04-20 08:01:01 +00:00
if (check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
2013-02-11 08:00:34 +00:00
Torrents::regenerate_filelist($_GET['torrentid']);
header('Location: torrents.php?torrentid='.$_GET['torrentid']);
2011-03-28 14:21:28 +00:00
die();
} else {
error(403);
}
break;
2013-07-04 08:00:56 +00:00
case 'fix_group':
2013-04-20 08:01:01 +00:00
if ((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
2013-07-04 08:00:56 +00:00
$DB->query('
SELECT COUNT(ID)
FROM torrents
WHERE GroupID = '.$_GET['groupid']);
2011-03-28 14:21:28 +00:00
list($Count) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if ($Count == 0) {
2012-10-11 08:00:15 +00:00
Torrents::delete_group($_GET['groupid']);
2011-03-28 14:21:28 +00:00
} else {
}
2013-04-20 08:01:01 +00:00
if (!empty($_GET['artistid']) && is_number($_GET['artistid'])) {
2011-03-28 14:21:28 +00:00
header('Location: artist.php?id='.$_GET['artistid']);
} else {
header('Location: torrents.php?id='.$_GET['groupid']);
}
} else {
error(403);
}
break;
2013-07-04 08:00:56 +00:00
case 'warn':
2013-02-07 08:00:47 +00:00
include(SERVER_ROOT.'/sections/torrents/warn.php');
break;
2013-07-04 08:00:56 +00:00
case 'take_warn':
2013-02-07 08:00:47 +00:00
include(SERVER_ROOT.'/sections/torrents/take_warn.php');
break;
2013-05-27 08:00:58 +00:00
case 'add_cover_art':
include(SERVER_ROOT.'/sections/torrents/add_cover_art.php');
break;
case 'remove_cover_art':
include(SERVER_ROOT.'/sections/torrents/remove_cover_art.php');
break;
2013-07-01 08:01:00 +00:00
case 'autocomplete_tags':
include(SERVER_ROOT.'/sections/torrents/autocomplete_tags.php');
break;
2011-03-28 14:21:28 +00:00
default:
enforce_login();
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if (!empty($_GET['id'])) {
2011-03-28 14:21:28 +00:00
include(SERVER_ROOT.'/sections/torrents/details.php');
2013-04-20 08:01:01 +00:00
} elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
2013-07-04 08:00:56 +00:00
$DB->query('
SELECT GroupID
FROM torrents
WHERE ID = '.$_GET['torrentid']);
2011-03-28 14:21:28 +00:00
list($GroupID) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if ($GroupID) {
2013-07-04 08:00:56 +00:00
header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid']);
2011-03-28 14:21:28 +00:00
}
} else {
include(SERVER_ROOT.'/sections/torrents/browse2.php');
}
break;
}
} else {
enforce_login();
2013-04-20 08:01:01 +00:00
if (!empty($_GET['id'])) {
2011-03-28 14:21:28 +00:00
include(SERVER_ROOT.'/sections/torrents/details.php');
2013-04-20 08:01:01 +00:00
} elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT GroupID
FROM torrents
WHERE ID = ".$_GET['torrentid']);
2011-03-28 14:21:28 +00:00
list($GroupID) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if ($GroupID) {
2013-07-04 08:00:56 +00:00
header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid'].'#torrent'.$_GET['torrentid']);
2011-03-28 14:21:28 +00:00
} else {
2012-09-27 08:00:20 +00:00
header("Location: log.php?search=Torrent+$_GET[torrentid]");
2011-03-28 14:21:28 +00:00
}
2013-04-20 08:01:01 +00:00
} elseif (!empty($_GET['type'])) {
2011-03-28 14:21:28 +00:00
include(SERVER_ROOT.'/sections/torrents/user.php');
2013-04-20 08:01:01 +00:00
} elseif (!empty($_GET['groupname']) && !empty($_GET['forward'])) {
2013-07-04 08:00:56 +00:00
$DB->query("
SELECT ID
FROM torrents_group
WHERE Name LIKE '".db_string($_GET['groupname'])."'");
2011-03-28 14:21:28 +00:00
list($GroupID) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if ($GroupID) {
2013-07-04 08:00:56 +00:00
header("Location: torrents.php?id=$GroupID");
2011-03-28 14:21:28 +00:00
} else {
include(SERVER_ROOT.'/sections/torrents/browse2.php');
}
} else {
include(SERVER_ROOT.'/sections/torrents/browse2.php');
}
}
?>