mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Merge pull request #79 from torrentpier/di_usage_example
DI usage example (dl.php)
This commit is contained in:
commit
9caec2b29a
4 changed files with 61 additions and 63 deletions
86
dl.php
86
dl.php
|
@ -3,91 +3,75 @@
|
|||
define('BB_SCRIPT', 'dl');
|
||||
define('NO_GZIP', true);
|
||||
define('BB_ROOT', './');
|
||||
require(BB_ROOT .'common.php');
|
||||
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 = '<form action="'. DOWNLOAD_URL . $topic_id .'" method="post">'; //!
|
||||
$message .= $lang['CAPTCHA'].':';
|
||||
$message .= '<div class="mrg_10" align="center">'. bb_captcha('get') .'</div>';
|
||||
$message .= '<input type="hidden" name="redirect_url" value="'. $redirect_url .'" />';
|
||||
$message .= '<input type="submit" class="bold" value="'. $lang['SUBMIT'] .'" /> ';
|
||||
$message .= '<input type="button" class="bold" value="'. $lang['GO_BACK'] .'" onclick="document.location.href = \''. $redirect_url .'\';" />';
|
||||
$message .= '</form>';
|
||||
$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;
|
||||
|
||||
// Torrent
|
||||
if ($t_data['attach_ext_id'] == 8)
|
||||
{
|
||||
require(INC_DIR .'functions_torrent.php');
|
||||
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);
|
||||
$response->prepare($di->request);
|
||||
$response->send();
|
|
@ -477,7 +477,7 @@ $config = [
|
|||
'retracker' => true,
|
||||
'retracker_host' => 'http://retracker.local/announce',
|
||||
'freeleech' => false,
|
||||
'guest_tracker' => false,
|
||||
'guest_tracker' => true,
|
||||
],
|
||||
|
||||
// Ratio settings
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* TorrentPier english localization
|
||||
* In progress
|
||||
*/
|
||||
|
||||
return [
|
||||
'Style guide' => 'Style guide',
|
||||
// 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',
|
||||
];
|
9
styles/templates/default/dl.twig
Normal file
9
styles/templates/default/dl.twig
Normal file
|
@ -0,0 +1,9 @@
|
|||
<form action="{{ download_url }}" method="post">
|
||||
{% trans %}Captcha{% endtrans %}:
|
||||
<div>
|
||||
{{ captcha|raw }}
|
||||
</div>
|
||||
<input type="hidden" name="redirect_url" value="{{ redirect_template }}"/>
|
||||
<input type="submit" value="{% trans %}Submit{% endtrans %}"/>
|
||||
<input type="button" value="{% trans %}Go back{% endtrans %}" onclick="location.href = '{{ redirect_template }}'"/>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue