Gazelle/sections/torrents/redownload.php

131 lines
3.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
if (!empty($_GET['userid']) && is_number($_GET['userid'])) {
$UserID = $_GET['userid'];
} else {
error(0);
}
2012-10-21 08:00:14 +00:00
if (!check_perms('zip_downloader')) {
2011-03-28 14:21:28 +00:00
error(403);
}
2012-10-11 08:00:15 +00:00
$User = Users::user_info($UserID);
$Perms = Permissions::get_permissions($User['PermissionID']);
$UserClass = $Perms['Class'];
2011-03-28 14:21:28 +00:00
require(SERVER_ROOT.'/classes/class_torrent.php');
require(SERVER_ROOT.'/classes/class_zip.php');
if (empty($_GET['type'])) {
error(0);
} else {
switch ($_GET['type']) {
case 'uploads':
2012-10-21 08:00:14 +00:00
if (!check_paranoia('uploads', $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-03-28 14:21:28 +00:00
$SQL = "WHERE t.UserID='$UserID'";
$Month = "t.Time";
break;
case 'snatches':
2012-10-21 08:00:14 +00:00
if (!check_paranoia('snatched', $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-03-28 14:21:28 +00:00
$SQL = "JOIN xbt_snatched AS x ON t.ID=x.fid WHERE x.uid='$UserID'";
$Month = "FROM_UNIXTIME(x.tstamp)";
break;
case 'seeding':
2012-10-21 08:00:14 +00:00
if (!check_paranoia('seeding', $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-03-28 14:21:28 +00:00
$SQL = "JOIN xbt_files_users AS xfu ON t.ID = xfu.fid WHERE xfu.uid='$UserID' AND xfu.remaining = 0";
$Month = "FROM_UNIXTIME(xfu.mtime)";
break;
default:
error(0);
}
}
ZIP::unlimit();
$DB->query("SELECT
2012-10-21 08:00:14 +00:00
t.ID,
DATE_FORMAT(".$Month.",'%Y - %m') AS Month,
2011-03-28 14:21:28 +00:00
t.GroupID,
t.Media,
t.Format,
t.Encoding,
IF(t.RemasterYear=0,tg.Year,t.RemasterYear),
tg.Name,
2012-10-21 08:00:14 +00:00
t.Size
2011-03-28 14:21:28 +00:00
FROM torrents as t
JOIN torrents_group AS tg ON t.GroupID=tg.ID
".$SQL."
GROUP BY t.ID");
2012-10-21 08:00:14 +00:00
$Downloads = $DB->to_array(0, MYSQLI_NUM, false);
2012-10-11 08:00:15 +00:00
$Artists = Artists::get_artists($DB->collect('GroupID'));
2011-03-28 14:21:28 +00:00
2012-10-21 08:00:14 +00:00
if (!empty($Downloads)) {
$DB->query("SELECT TorrentID, File FROM torrents_files WHERE TorrentID IN (".implode(',', array_keys($Downloads)).")");
$TorrentFiles = $DB->to_array(0, MYSQLI_NUM, false);
}
2012-10-11 08:00:15 +00:00
list($UserID, $Username) = array_values(Users::user_info($UserID));
2011-03-28 14:21:28 +00:00
$Zip = new ZIP($Username.'\'s '.ucfirst($_GET['type']));
2012-10-21 08:00:14 +00:00
foreach ($Downloads as $Download) {
list($TorrentID, $Month, $GroupID, $Media, $Format, $Encoding, $Year, $Album, $Size) = $Download;
if (!isset($TorrentFiles[$TorrentID])) {
continue;
}
2012-10-11 08:00:15 +00:00
$Artist = Artists::display_artists($Artists[$GroupID],false,true,false);
2012-10-21 08:00:14 +00:00
$Contents = unserialize(base64_decode($TorrentFiles[$TorrentID][1]));
2011-03-28 14:21:28 +00:00
$Tor = new TORRENT($Contents, true);
$Tor->set_announce_url(ANNOUNCE_URL.'/'.$LoggedUser['torrent_pass'].'/announce');
unset($Tor->Val['announce-list']);
2012-10-21 08:00:14 +00:00
$TorrentName = '';
$TorrentInfo = '';
2011-03-28 14:21:28 +00:00
$TorrentName = $Artist;
$TorrentName .= $Album;
2012-10-21 08:00:14 +00:00
if ($Year > 0) {
$TorrentName .= ' - '.$Year;
}
2011-03-28 14:21:28 +00:00
2012-10-21 08:00:14 +00:00
if ($Media != '') {
$TorrentInfo .= $Media;
}
2011-03-28 14:21:28 +00:00
2012-10-21 08:00:14 +00:00
if ($Format != '') {
if ($TorrentInfo != '') {
$TorrentInfo .= ' - ';
}
$TorrentInfo .= $Format;
2011-03-28 14:21:28 +00:00
}
if ($Encoding!='') {
2012-10-21 08:00:14 +00:00
if ($TorrentInfo != '') {
$TorrentInfo .= ' - ';
}
$TorrentInfo .= $Encoding;
2011-03-28 14:21:28 +00:00
}
2012-10-21 08:00:14 +00:00
if ($TorrentInfo != '') {
$TorrentName .= ' ('.$TorrentInfo.')';
}
2011-03-28 14:21:28 +00:00
2012-10-21 08:00:14 +00:00
if (!$TorrentName) {
$TorrentName = "No Name";
}
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
$FileName = Misc::file_string($TorrentName);
2011-03-28 14:21:28 +00:00
if ($Browser == 'Internet Explorer') {
$FileName = urlencode($FileName);
}
$FileName .= '.torrent';
2012-10-11 08:00:15 +00:00
$Zip->add_file($Tor->enc(), Misc::file_string($Month).'/'.$FileName);
2011-03-28 14:21:28 +00:00
}
$Zip->close_stream();
2012-08-25 08:00:15 +00:00
define('IE_WORKAROUND_NO_CACHE_HEADERS', 1);