This commit is contained in:
Roman Kelesidis 2024-09-16 22:04:07 +07:00
commit 9c004f0651
2 changed files with 110 additions and 97 deletions

115
dl.php
View file

@ -18,9 +18,14 @@ $datastore->enqueue([
'cat_forums' 'cat_forums'
]); ]);
$download_id = request_var('id', 0); $download_id = request_var('id', '');
$thumbnail = request_var('thumb', 0); $thumbnail = request_var('thumb', 0);
$m3u = request_var('m3u', 0);
// Check M3U download mode
$is_m3u = false;
if (str_starts_with($download_id, \TorrentPier\TorrServerAPI::M3U['prefix'])) {
$is_m3u = true;
}
// Send file to browser // Send file to browser
function send_file_to_browser($attachment, $upload_dir) function send_file_to_browser($attachment, $upload_dir)
@ -89,44 +94,39 @@ if ($attach_config['disable_mod'] && !IS_ADMIN) {
bb_die($lang['ATTACHMENT_FEATURE_DISABLED']); bb_die($lang['ATTACHMENT_FEATURE_DISABLED']);
} }
$sql = 'SELECT * FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int)$download_id; if (!$is_m3u) {
$sql = 'SELECT * FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int)$download_id;
if (!($result = DB()->sql_query($sql))) { if (!($result = DB()->sql_query($sql))) {
bb_die('Could not query attachment information #1'); bb_die('Could not query attachment information #1');
} }
if (!($attachment = DB()->sql_fetchrow($result))) { if (!($attachment = DB()->sql_fetchrow($result))) {
bb_die($lang['ERROR_NO_ATTACHMENT']);
}
$attachment['physical_filename'] = basename($attachment['physical_filename']);
if ($thumbnail) {
// Re-define $attachment['physical_filename'] for thumbnails
$attachment['physical_filename'] = THUMB_DIR . '/t_' . $attachment['physical_filename'];
} elseif ($m3u) {
// Check m3u file exist
if (!$m3uFile = (new \TorrentPier\TorrServerAPI())->getM3UPath($m3u)) {
bb_die($lang['ERROR_NO_ATTACHMENT']); bb_die($lang['ERROR_NO_ATTACHMENT']);
} }
$attachment['physical_filename'] = basename($m3uFile);
}
DB()->sql_freeresult($result); $attachment['physical_filename'] = basename($attachment['physical_filename']);
// get forum_id for attachment authorization or private message authorization // Re-define $attachment['physical_filename'] for thumbnails
$authorised = false; if ($thumbnail) {
$attachment['physical_filename'] = THUMB_DIR . '/t_' . $attachment['physical_filename'];
}
$sql = 'SELECT * FROM ' . BB_ATTACHMENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id']; DB()->sql_freeresult($result);
if (!($result = DB()->sql_query($sql))) { // get forum_id for attachment authorization or private message authorization
$authorised = false;
$sql = 'SELECT * FROM ' . BB_ATTACHMENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id'];
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not query attachment information #2'); bb_die('Could not query attachment information #2');
} }
$auth_pages = DB()->sql_fetchrowset($result); $auth_pages = DB()->sql_fetchrowset($result);
$num_auth_pages = DB()->num_rows($result); $num_auth_pages = DB()->num_rows($result);
for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++) { for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++) {
$auth_pages[$i]['post_id'] = (int)$auth_pages[$i]['post_id']; $auth_pages[$i]['post_id'] = (int)$auth_pages[$i]['post_id'];
if ($auth_pages[$i]['post_id'] != 0) { if ($auth_pages[$i]['post_id'] != 0) {
@ -148,17 +148,17 @@ for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++) {
$authorised = true; $authorised = true;
} }
} }
} }
// Check the auth rights // Check the auth rights
if (!$authorised) { if (!$authorised) {
bb_die($lang['SORRY_AUTH_VIEW_ATTACH'], 403); bb_die($lang['SORRY_AUTH_VIEW_ATTACH'], 403);
} }
$datastore->rm('cat_forums'); $datastore->rm('cat_forums');
// Check tor status // Check tor status
if (!IS_AM && str_contains($attachment['mimetype'], 'bittorrent')) { if (!IS_AM && str_contains($attachment['mimetype'], 'bittorrent')) {
$sql = 'SELECT tor_status, poster_id FROM ' . BB_BT_TORRENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id']; $sql = 'SELECT tor_status, poster_id FROM ' . BB_BT_TORRENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id'];
if (!($result = DB()->sql_query($sql))) { if (!($result = DB()->sql_query($sql))) {
@ -172,41 +172,54 @@ if (!IS_AM && str_contains($attachment['mimetype'], 'bittorrent')) {
} }
DB()->sql_freeresult($result); DB()->sql_freeresult($result);
} }
// Get Information on currently allowed Extensions // Get Information on currently allowed Extensions
$rows = get_extension_informations(); $rows = get_extension_informations();
$num_rows = count($rows); $num_rows = count($rows);
$allowed_extensions = $download_mode = []; $allowed_extensions = $download_mode = [];
for ($i = 0; $i < $num_rows; $i++) { for ($i = 0; $i < $num_rows; $i++) {
$extension = strtolower(trim($rows[$i]['extension'])); $extension = strtolower(trim($rows[$i]['extension']));
// Get allowed extensions // Get allowed extensions
if ((int)$rows[$i]['allow_group'] === 1) { if ((int)$rows[$i]['allow_group'] === 1) {
$allowed_extensions[] = $extension; $allowed_extensions[] = $extension;
} }
$download_mode[$extension] = $rows[$i]['download_mode']; $download_mode[$extension] = $rows[$i]['download_mode'];
} }
// Disallowed // Disallowed
if (!in_array($attachment['extension'], $allowed_extensions) && !IS_ADMIN) { if (!in_array($attachment['extension'], $allowed_extensions) && !IS_ADMIN) {
bb_die(sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) . '<br /><br />' . $lang['FILENAME'] . ":&nbsp;" . $attachment['physical_filename']); bb_die(sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) . '<br /><br />' . $lang['FILENAME'] . ":&nbsp;" . $attachment['physical_filename']);
} }
// Getting download mode by extension // Getting download mode by extension
if (isset($download_mode[$attachment['extension']])) { if (isset($download_mode[$attachment['extension']])) {
$download_mode = (int)$download_mode[$attachment['extension']]; $download_mode = (int)$download_mode[$attachment['extension']];
} else { } else {
bb_die(sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) . '<br /><br />' . $lang['FILENAME'] . ":&nbsp;" . $attachment['physical_filename']); bb_die(sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) . '<br /><br />' . $lang['FILENAME'] . ":&nbsp;" . $attachment['physical_filename']);
} }
// Update download count // Update download count
if ((!$m3u && !$thumbnail) && is_file(realpath($upload_dir . '/' . $attachment['physical_filename']))) { if (!$thumbnail && is_file(realpath($upload_dir . '/' . $attachment['physical_filename']))) {
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int)$attachment['attach_id']; $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int)$attachment['attach_id'];
if (!DB()->sql_query($sql)) { if (!DB()->sql_query($sql)) {
bb_die('Could not update attachment download count'); bb_die('Could not update attachment download count');
} }
}
} else {
$download_mode = INLINE_LINK;
$attachment = [];
// Check m3u file exist
if (!$m3uFile = (new \TorrentPier\TorrServerAPI())->getM3UPath((int)str_replace(\TorrentPier\TorrServerAPI::M3U['prefix'], '', $download_id))) {
bb_die($lang['ERROR_NO_ATTACHMENT']);
}
$attachment['physical_filename'] = $attachment['real_filename'] = basename($m3uFile);
$attachment['mimetype'] = mime_content_type($m3uFile);
$attachment['extension'] = str_replace('.', '', \TorrentPier\TorrServerAPI::M3U['extension']);
} }
// Determine the 'presenting'-method // Determine the 'presenting'-method

View file

@ -99,7 +99,7 @@ foreach ($m3uData as $entry) {
'IS_VALID' => in_array($getExtension, array_merge($validFormats['audio'], $validFormats['video'])), 'IS_VALID' => in_array($getExtension, array_merge($validFormats['audio'], $validFormats['video'])),
'IS_AUDIO' => in_array($getExtension, $validFormats['audio']), 'IS_AUDIO' => in_array($getExtension, $validFormats['audio']),
'STREAM_LINK' => $streamLink, 'STREAM_LINK' => $streamLink,
'M3U_DL_LINK' => PLAYBACK_M3U_URL . $topic_id . '&dl_m3u=1', 'M3U_DL_LINK' => DL_URL . \TorrentPier\TorrServerAPI::M3U['prefix'] . $topic_id,
'TITLE' => $title, 'TITLE' => $title,
]); ]);
} }