2011-03-28 14:21:28 +00:00
|
|
|
<?
|
2012-07-11 08:00:16 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
authorize();
|
|
|
|
|
2013-05-27 08:00:58 +00:00
|
|
|
include(SERVER_ROOT.'/classes/validate.class.php');
|
2011-03-28 14:21:28 +00:00
|
|
|
$Val = new VALIDATE;
|
|
|
|
|
2013-05-25 08:01:03 +00:00
|
|
|
function add_torrent($CollageID, $GroupID) {
|
2012-02-07 08:00:20 +00:00
|
|
|
global $Cache, $LoggedUser, $DB;
|
|
|
|
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT MAX(Sort)
|
|
|
|
FROM collages_torrents
|
|
|
|
WHERE CollageID = '$CollageID'");
|
2012-02-07 08:00:20 +00:00
|
|
|
list($Sort) = $DB->next_record();
|
2013-06-28 08:01:04 +00:00
|
|
|
$Sort += 10;
|
2012-02-07 08:00:20 +00:00
|
|
|
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT GroupID
|
|
|
|
FROM collages_torrents
|
|
|
|
WHERE CollageID = '$CollageID'
|
|
|
|
AND GroupID = '$GroupID'");
|
2013-07-10 00:08:53 +00:00
|
|
|
if (!$DB->has_results()) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
INSERT IGNORE INTO collages_torrents
|
|
|
|
(CollageID, GroupID, UserID, Sort, AddedOn)
|
2012-02-07 08:00:20 +00:00
|
|
|
VALUES
|
2013-06-28 08:01:04 +00:00
|
|
|
('$CollageID', '$GroupID', '$LoggedUser[ID]', '$Sort', '" . sqltime() . "')");
|
|
|
|
|
|
|
|
$DB->query("
|
|
|
|
UPDATE collages
|
|
|
|
SET NumTorrents = NumTorrents + 1, Updated = '" . sqltime() . "'
|
|
|
|
WHERE ID = '$CollageID'");
|
|
|
|
|
|
|
|
$Cache->delete_value("collage_$CollageID");
|
|
|
|
$Cache->delete_value("torrents_details_$GroupID");
|
|
|
|
$Cache->delete_value("torrent_collages_$GroupID");
|
|
|
|
$Cache->delete_value("torrent_collages_personal_$GroupID");
|
|
|
|
|
|
|
|
$DB->query("
|
|
|
|
SELECT UserID
|
|
|
|
FROM users_collage_subs
|
|
|
|
WHERE CollageID = $CollageID");
|
2012-02-07 08:00:20 +00:00
|
|
|
while (list($CacheUserID) = $DB->next_record()) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Cache->delete_value("collage_subs_user_new_$CacheUserID");
|
2012-02-07 08:00:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$CollageID = $_POST['collageid'];
|
2012-11-03 08:00:19 +00:00
|
|
|
if (!is_number($CollageID)) {
|
|
|
|
error(404);
|
|
|
|
}
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT UserID, CategoryID, Locked, NumTorrents, MaxGroups, MaxGroupsPerUser
|
|
|
|
FROM collages
|
|
|
|
WHERE ID = '$CollageID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($UserID, $CategoryID, $Locked, $NumTorrents, $MaxGroups, $MaxGroupsPerUser) = $DB->next_record();
|
2012-11-03 08:00:19 +00:00
|
|
|
|
|
|
|
if (!check_perms('site_collages_delete')) {
|
|
|
|
if ($Locked) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Err = 'This collage is locked';
|
2012-11-03 08:00:19 +00:00
|
|
|
}
|
|
|
|
if ($CategoryID == 0 && $UserID != $LoggedUser['ID']) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Err = 'You cannot edit someone else\'s personal collage.';
|
2012-11-03 08:00:19 +00:00
|
|
|
}
|
|
|
|
if ($MaxGroups > 0 && $NumTorrents >= $MaxGroups) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Err = 'This collage already holds its maximum allowed number of torrents.';
|
2012-11-03 08:00:19 +00:00
|
|
|
}
|
2013-02-16 08:00:57 +00:00
|
|
|
|
|
|
|
if (isset($Err)) {
|
|
|
|
error($Err);
|
|
|
|
}
|
2012-11-03 08:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($MaxGroupsPerUser > 0) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT COUNT(*)
|
|
|
|
FROM collages_torrents
|
|
|
|
WHERE CollageID = '$CollageID'
|
|
|
|
AND UserID = '$LoggedUser[ID]'");
|
2012-11-03 08:00:19 +00:00
|
|
|
list($GroupsForUser) = $DB->next_record();
|
|
|
|
if (!check_perms('site_collages_delete') && $GroupsForUser >= $MaxGroupsPerUser) {
|
2011-03-28 14:21:28 +00:00
|
|
|
error(403);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 08:00:20 +00:00
|
|
|
if ($_REQUEST['action'] == 'add_torrent') {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Val->SetFields('url', '1', 'regex', 'The URL must be a link to a torrent on the site.', array('regex' => '/^'.TORRENT_GROUP_REGEX.'/i'));
|
2012-02-07 08:00:20 +00:00
|
|
|
$Err = $Val->ValidateForm($_POST);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2012-11-03 08:00:19 +00:00
|
|
|
if ($Err) {
|
2012-02-07 08:00:20 +00:00
|
|
|
error($Err);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2012-02-07 08:00:20 +00:00
|
|
|
$URL = $_POST['url'];
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2012-02-07 08:00:20 +00:00
|
|
|
// Get torrent ID
|
2013-06-11 08:01:24 +00:00
|
|
|
preg_match('/^'.TORRENT_GROUP_REGEX.'/i', $URL, $Matches);
|
|
|
|
$TorrentID = $Matches[4];
|
2012-11-03 08:00:19 +00:00
|
|
|
if (!$TorrentID || (int)$TorrentID == 0) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT ID
|
|
|
|
FROM torrents_group
|
|
|
|
WHERE ID = '$TorrentID'");
|
2012-02-07 08:00:20 +00:00
|
|
|
list($GroupID) = $DB->next_record();
|
2012-11-03 08:00:19 +00:00
|
|
|
if (!$GroupID) {
|
2012-02-07 08:00:20 +00:00
|
|
|
error('The torrent was not found in the database.');
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-05-25 08:01:03 +00:00
|
|
|
add_torrent($CollageID, $GroupID);
|
2012-02-07 08:00:20 +00:00
|
|
|
} else {
|
2013-06-28 08:01:04 +00:00
|
|
|
$URLs = explode("\n", $_REQUEST['urls']);
|
2012-02-07 08:00:20 +00:00
|
|
|
$GroupIDs = array();
|
|
|
|
$Err = '';
|
2012-11-03 08:00:19 +00:00
|
|
|
foreach ($URLs as $Key => &$URL) {
|
2012-02-07 08:00:20 +00:00
|
|
|
$URL = trim($URL);
|
2012-11-03 08:00:19 +00:00
|
|
|
if ($URL == '') {
|
|
|
|
unset($URLs[$Key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($URL);
|
|
|
|
|
|
|
|
if (!check_perms('site_collages_delete')) {
|
|
|
|
if ($MaxGroups > 0 && ($NumTorrents + count($URLs) > $MaxGroups)) {
|
|
|
|
$Err = "This collage can only hold $MaxGroups torrents.";
|
|
|
|
}
|
|
|
|
if ($MaxGroupsPerUser > 0 && ($GroupsForUser + count($URLs) > $MaxGroupsPerUser)) {
|
|
|
|
$Err = "You may only have $MaxGroupsPerUser torrents in this collage.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($URLs as $URL) {
|
2012-02-07 08:00:20 +00:00
|
|
|
$Matches = array();
|
2013-06-11 08:01:24 +00:00
|
|
|
if (preg_match('/^'.TORRENT_GROUP_REGEX.'/i', $URL, $Matches)) {
|
|
|
|
$GroupIDs[] = $Matches[4];
|
|
|
|
$GroupID = $Matches[4];
|
2012-02-07 08:00:20 +00:00
|
|
|
} else {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Err = "One of the entered URLs ($URL) does not correspond to a torrent group on the site.";
|
2012-02-07 08:00:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-06-28 08:01:04 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT ID
|
|
|
|
FROM torrents_group
|
|
|
|
WHERE ID = '$GroupID'");
|
2013-07-10 00:08:53 +00:00
|
|
|
if (!$DB->has_results()) {
|
2013-06-28 08:01:04 +00:00
|
|
|
$Err = "One of the entered URLs ($URL) does not correspond to a torrent group on the site.";
|
2012-02-07 08:00:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-27 08:00:15 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-11-03 08:00:19 +00:00
|
|
|
if ($Err) {
|
2012-02-07 08:00:20 +00:00
|
|
|
error($Err);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($GroupIDs as $GroupID) {
|
2013-05-25 08:01:03 +00:00
|
|
|
add_torrent($CollageID, $GroupID);
|
2013-02-22 08:00:24 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-16 08:00:57 +00:00
|
|
|
header('Location: collages.php?id='.$CollageID);
|