diff --git a/dl.php b/dl.php index aa0cf45cb..b7d244495 100644 --- a/dl.php +++ b/dl.php @@ -2,92 +2,76 @@ define('BB_SCRIPT', 'dl'); define('NO_GZIP', true); -define('BB_ROOT', './'); -require(BB_ROOT .'common.php'); +define('BB_ROOT', './'); +require(BB_ROOT . 'common.php'); -if (!$topic_id = (int) request_var('t', 0)) -{ - bb_simple_die('Ошибочный запрос: не указан topic_id'); // TODO: перевести +$di = \TorrentPier\Di::getInstance(); + +if (!$topic_id = $di->request->get('t', 0)) { + bb_simple_die($di->translator->trans('Invalid request: not specified %data%', ['%data%' => 'topic_id'])); } $user->session_start(); -global $bb_cfg, $lang, $userdata; +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('Файл не найден [DB]'); // TODO: перевести +$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('Файл не найден [EXT_ID]'); // TODO: перевести +if (!$t_data['attach_ext_id']) { + bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => '[EXT_ID]'])); } // Auth check $is_auth = auth(AUTH_ALL, $t_data['forum_id'], $userdata, $t_data); -if (!IS_GUEST) -{ - if (!$is_auth['auth_download']) login_redirect($bb_cfg['dl_url'] . $topic_id); -} -elseif (!$bb_cfg['tracker']['guest_tracker']) -{ - login_redirect($bb_cfg['dl_url'] . $topic_id); +if (!IS_GUEST) { + if (!$is_auth['auth_download']) login_redirect($di->config->get('dl_url') . $topic_id); +} elseif (!$di->config->get('tracker.guest_tracker')) { + login_redirect($di->config->get('dl_url') . $topic_id); } // Downloads counter DB()->sql_query('UPDATE ' . BB_TOPICS . ' SET attach_dl_cnt = attach_dl_cnt + 1 WHERE topic_id = ' . $topic_id); // Captcha for guest -if (IS_GUEST && !bb_captcha('check')) -{ - global $template; +if (IS_GUEST && !bb_captcha('check')) { + $redirectUrl = $di->request->get('redirect_url'); + $redirectTemplate = $redirectUrl ? $redirectUrl : $di->request->server->get('HTTP_REFERER', '/'); - $redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); - $message = '
'; //! - $message .= $lang['CAPTCHA'].':'; - $message .= '
'. bb_captcha('get') .'
'; - $message .= ''; - $message .= '  '; - $message .= ''; - $message .= '
'; + $content = $di->view->make('dl', [ + 'captcha' => bb_captcha('get'), + 'download_url' => DOWNLOAD_URL . $topic_id, + 'redirect_template' => $redirectTemplate, + ]); - $template->assign_vars(array( - 'ERROR_MESSAGE' => $message, - )); + $response = \Symfony\Component\HttpFoundation\Response::create(); - require(PAGE_HEADER); - require(PAGE_FOOTER); + $response->setContent($content); + $response->send(); } $t_data['user_id'] = $userdata['user_id']; -$t_data['is_am'] = IS_AM; +$t_data['is_am'] = IS_AM; // Torrent -if ($t_data['attach_ext_id'] == 8) -{ - require(INC_DIR .'functions_torrent.php'); - send_torrent_with_passkey($t_data); +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']); -if (($file_contents = @file_get_contents($file_path)) === false) -{ - bb_simple_die("Файл не найден [HDD]"); // TODO: перевести +if (($file_contents = @file_get_contents($file_path)) === false) { + bb_simple_die($di->translator->trans('File not found: %location%', ['%location%' => '[HDD]'])); } -$send_filename = "t-$topic_id.". $bb_cfg['file_id_ext'][$t_data['attach_ext_id']]; +$send_filename = "t-$topic_id." . $di->config->get('file_id_ext')[$t_data['attach_ext_id']]; -header("Content-Type: application/x-download; name=\"$send_filename\""); -header("Content-Disposition: attachment; filename=\"$send_filename\""); +$response = \Symfony\Component\HttpFoundation\BinaryFileResponse::create(); +$response->setFile($file_path, 'attachment; filename=' . $send_filename); -bb_exit($file_contents); \ No newline at end of file +$response->prepare($di->request); +$response->send(); \ No newline at end of file diff --git a/library/config.php b/library/config.php index 45fe18f29..ce6e93a3c 100644 --- a/library/config.php +++ b/library/config.php @@ -477,7 +477,7 @@ $config = [ 'retracker' => true, 'retracker_host' => 'http://retracker.local/announce', 'freeleech' => false, - 'guest_tracker' => false, + 'guest_tracker' => true, ], // Ratio settings diff --git a/messages/en.php b/messages/en.php index 8acb94edd..91ccc1ff0 100644 --- a/messages/en.php +++ b/messages/en.php @@ -1,12 +1,17 @@ 'Style guide', - 'Send' => 'Send', - 'Hello, %name%' => 'Hello, %name%', + // Common + 'Captcha' => 'Captcha', + 'Go back' => 'Go back', + 'Send' => 'Send', + 'Submit' => 'Submit', + + // Errors + 'File not found: %location%' => 'File not found: %location%', + 'Invalid request: not specified %data%' => 'Invalid request: not specified %data%', + + // Style guide (styleguide.php) + 'Hello, %name%' => 'Hello, %name%', + 'Style guide' => 'Style guide', ]; \ No newline at end of file diff --git a/styles/templates/default/dl.twig b/styles/templates/default/dl.twig new file mode 100644 index 000000000..f08af065f --- /dev/null +++ b/styles/templates/default/dl.twig @@ -0,0 +1,9 @@ +
+ {% trans %}Captcha{% endtrans %}: +
+ {{ captcha|raw }} +
+ + + +
\ No newline at end of file