mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-01-18 12:11:36 +00:00
Adding action=user_torrents
This commit is contained in:
parent
a302576db8
commit
8580bb98fc
@ -160,6 +160,9 @@
|
||||
case 'pushbullet_devices':
|
||||
require(SERVER_ROOT . '/sections/ajax/pushbullet_devices.php');
|
||||
break;
|
||||
case 'user_torrents':
|
||||
require(SERVER_ROOT . '/sections/ajax/user_torrents.php');
|
||||
break;
|
||||
default:
|
||||
// If they're screwing around with the query string
|
||||
json_die("failure");
|
||||
|
110
sections/ajax/user_torrents.php
Normal file
110
sections/ajax/user_torrents.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?
|
||||
$UserID = (int)$_GET['userid'];
|
||||
$Type = (string)$_GET['type'];
|
||||
$Limit = (int)$_GET['limit'];
|
||||
$Offset = (int)$_GET['offset'];
|
||||
|
||||
if (empty($UserID) || empty($Type)) {
|
||||
json_die("failure", "bad parameters");
|
||||
}
|
||||
|
||||
if ($UserID != $LoggedUser['ID']) {
|
||||
// We can always view our own torrents
|
||||
$DB->query("
|
||||
SELECT m.Paranoia
|
||||
FROM users_main AS m
|
||||
WHERE m.ID = $UserID");
|
||||
|
||||
if (!$DB->has_results()) { // If user doesn't exist
|
||||
json_die("failure", "no such user");
|
||||
}
|
||||
|
||||
list($Paranoia) = $DB->next_record(MYSQLI_NUM, false);
|
||||
|
||||
$Paranoia = unserialize($Paranoia);
|
||||
if (!is_array($Paranoia)) {
|
||||
$Paranoia = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($Limit)) {
|
||||
// retrive all values. Somehow this is the accepted way to do this: http://stackoverflow.com/questions/2294842/mysql-retrieve-all-rows-with-limit
|
||||
$Limit = 2147483647;
|
||||
}
|
||||
if (empty($Offset)) {
|
||||
$Offset = 0;
|
||||
}
|
||||
|
||||
switch ($Type) {
|
||||
case 'snatched':
|
||||
$From = "FROM xbt_snatched AS s
|
||||
INNER JOIN torrents AS t ON t.ID = s.fid
|
||||
INNER JOIN torrents_group AS g ON t.GroupID = g.ID";
|
||||
$Where = "WHERE s.uid = '$UserID'
|
||||
AND g.CategoryID = '1'";
|
||||
$Order = "ORDER BY s.tstamp DESC";
|
||||
break;
|
||||
case 'seeding':
|
||||
$From = "FROM xbt_files_users AS xfu
|
||||
JOIN torrents AS t ON t.ID = xfu.fid
|
||||
INNER JOIN torrents_group AS g ON t.GroupID = g.ID";
|
||||
$Where = "WHERE xfu.uid = '$UserID'
|
||||
AND xfu.active = 1
|
||||
AND xfu.Remaining = 0";
|
||||
$Order = "ORDER BY xfu.mtime DESC";
|
||||
break;
|
||||
case 'leeching':
|
||||
$From = "FROM xbt_files_users AS xfu
|
||||
JOIN torrents AS t ON t.ID = xfu.fid
|
||||
INNER JOIN torrents_group AS g ON t.GroupID = g.ID";
|
||||
$Where = "WHERE xfu.uid = '$UserID'
|
||||
AND xfu.active = 1
|
||||
AND xfu.Remaining > 0";
|
||||
$Order = "ORDER BY xfu.mtime DESC";
|
||||
break;
|
||||
case 'uploaded':
|
||||
$Type = 'uploads'; // paranoia settings use 'uploads' but the main site typically uses 'uploaded'
|
||||
// fall through
|
||||
case 'uploads':
|
||||
$From = "FROM torrents_group AS g
|
||||
INNER JOIN torrents AS t ON t.GroupID = g.ID";
|
||||
$Where = "WHERE t.UserID = '$UserID'
|
||||
AND g.CategoryID = '1'";
|
||||
$Order = "ORDER BY t.Time DESC";
|
||||
break;
|
||||
default:
|
||||
json_die("failure", $Type." is not a valid type");
|
||||
}
|
||||
|
||||
$Results = array();
|
||||
if (check_paranoia_here($Type)) {
|
||||
$DB->query("SELECT
|
||||
g.ID AS groupId,
|
||||
g.Name AS name,
|
||||
t.ID AS torrentId ".
|
||||
$From." ".$Where." ".$Order." ".
|
||||
"LIMIT $Offset, $Limit");
|
||||
$TorrentGroups = $DB->to_array(false, MYSQLI_ASSOC);
|
||||
|
||||
$Artists = Artists::get_artists($DB->collect('groupId'));
|
||||
|
||||
foreach ($TorrentGroups as $Key => $SnatchInfo) {
|
||||
$TorrentGroups[$Key]['artistName'] = Artists::display_artists($Artists[$SnatchInfo['groupId']], false, false, true);
|
||||
if (Count($Artists[$SnatchInfo['groupId']][1]) === 1)
|
||||
$TorrentGroups[$Key]['artistId'] = $Artists[$SnatchInfo['groupId']][1][0]['id'];
|
||||
}
|
||||
$Results[$Type] = $TorrentGroups;
|
||||
} else {
|
||||
$Results[$Type] = "hidden";
|
||||
}
|
||||
|
||||
json_print("success", $Results);
|
||||
|
||||
function check_paranoia_here($Setting) {
|
||||
global $Paranoia, $Class, $UserID, $Preview;
|
||||
if ($Preview == 1) {
|
||||
return check_paranoia($Setting, $Paranoia, $Class);
|
||||
} else {
|
||||
return check_paranoia($Setting, $Paranoia, $Class, $UserID);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user