This commit is contained in:
Exile 2016-02-28 01:51:15 +00:00
commit c0e1c0573a
3 changed files with 31 additions and 21 deletions

46
dl.php
View file

@ -6,7 +6,12 @@ require_once __DIR__ . '/common.php';
$di = \TorrentPier\Di::getInstance();
if (!$topic_id = $di->request->get('t', 0)) {
/** @var \TorrentPier\Db\Adapter $db */
$db = $di->db;
$topic_id = $di->request->query->getInt('t');
if (!$topic_id) {
bb_simple_die($di->translator->trans('Invalid request: not specified %data%', ['%data%' => 'topic_id']));
}
@ -14,17 +19,21 @@ $user->session_start();
global $userdata;
// $t_data
$sql = "SELECT t.*, f.* FROM " . BB_TOPICS . " t, " . BB_FORUMS . " f WHERE t.topic_id = $topic_id AND f.forum_id = t.forum_id LIMIT 1";
if (!$t_data = DB()->fetch_row($sql)) {
bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => '[DB]']));
}
if (!$t_data['attach_ext_id']) {
bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => '[EXT_ID]']));
// TODO: явное указание полей, для send_torrent_with_passkey и auth нужен рефакторинг
$t_data = $db->select(['t' => BB_TOPICS], function (\Zend\Db\Sql\Select $select) use ($topic_id) {
$select->where(function (\Zend\Db\Sql\Where $where) use ($topic_id) {
$where->equalTo('topic_id', $topic_id);
$where->greaterThan('attach_ext_id', 0);
});
$select->join(['f' => BB_FORUMS], 'f.forum_id = t.forum_id');
})->one();
if (!$t_data) {
bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => 'database']));
}
// Auth check
$is_auth = auth(AUTH_ALL, $t_data['forum_id'], $userdata, $t_data);
$is_auth = auth(AUTH_ALL, $t_data->forum_id, $userdata, $t_data);
if (!IS_GUEST) {
if (!$is_auth['auth_download']) login_redirect($di->config->get('dl_url') . $topic_id);
} elseif (!$di->config->get('tracker.guest_tracker')) {
@ -32,7 +41,7 @@ if (!IS_GUEST) {
}
// Downloads counter
DB()->sql_query('UPDATE ' . BB_TOPICS . ' SET attach_dl_cnt = attach_dl_cnt + 1 WHERE topic_id = ' . $topic_id);
$db->increment(BB_TOPICS, 'attach_dl_cnt', ['topic_id' => $topic_id]);
// Captcha for guest
if (IS_GUEST && !bb_captcha('check')) {
@ -45,6 +54,7 @@ if (IS_GUEST && !bb_captcha('check')) {
'redirect_template' => $redirectTemplate,
]);
/** @var \Symfony\Component\HttpFoundation\Response $response */
$response = \Symfony\Component\HttpFoundation\Response::create();
$response->setContent($content);
@ -52,26 +62,24 @@ if (IS_GUEST && !bb_captcha('check')) {
$response->send();
}
$t_data['user_id'] = $userdata['user_id'];
$t_data['is_am'] = IS_AM;
// Torrent
if ($t_data['attach_ext_id'] == 8) {
if ($t_data->attach_ext_id == 8) {
require(INC_DIR . 'functions_torrent.php');
send_torrent_with_passkey($t_data);
}
// All other
$file_path = get_attach_path($topic_id, $t_data['attach_ext_id']);
$file_path = get_attach_path($topic_id, $t_data->attach_ext_id);
if (($file_contents = @file_get_contents($file_path)) === false) {
bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => '[HDD]']));
if (!file_exists($file_path)) {
bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => 'HDD']));
}
$send_filename = "t-$topic_id." . $di->config->get('file_id_ext')[$t_data['attach_ext_id']];
$send_filename = "t-$topic_id." . $di->config->get('file_id_ext')[$t_data->attach_ext_id];
/** @var \Symfony\Component\HttpFoundation\BinaryFileResponse $response */
$response = \Symfony\Component\HttpFoundation\BinaryFileResponse::create();
$response->setFile($file_path, 'attachment; filename=' . $send_filename);
$response->prepare($di->request);
$response->send();
$response->send();

View file

@ -21,6 +21,7 @@ $config = [
// Database
'db' => [
'debug' => '{self.debug}',
'driver' => 'Pdo_Mysql',
'hostname' => '127.0.0.1',
'database' => 'tp_220',
@ -31,6 +32,7 @@ $config = [
// Sphinx
'sphinx' => [
'debug' => '{self.debug}',
'driver' => '{self.db.driver}',
'hostname' => '{self.db.hostname}',
'username' => 'user',

View file

@ -305,7 +305,7 @@ function send_torrent_with_passkey ($t_data)
$topic_id = $t_data['topic_id'];
$poster_id = $t_data['topic_poster'];
$user_id = $t_data['user_id'];
$user_id = $userdata['user_id'];
// Запрет на скачивание закрытого или незарегистрированного торрента
$row = DB()->fetch_row("SELECT tor_status FROM ". BB_BT_TORRENTS ." WHERE topic_id = $topic_id LIMIT 1");
@ -316,7 +316,7 @@ function send_torrent_with_passkey ($t_data)
}
else if (isset($bb_cfg['tor_frozen'][$row['tor_status']]))
{
if (!$t_data['is_am']) bb_die("Раздача имеет статус: <b>{$lang['TOR_STATUS_NAME'][$row['tor_status']]}</b><br /><br />Скачивание запрещено"); //TODO: перевести
if (!IS_AM) bb_die("Раздача имеет статус: <b>{$lang['TOR_STATUS_NAME'][$row['tor_status']]}</b><br /><br />Скачивание запрещено"); //TODO: перевести
}
$passkey_val = '';