mirror of
https://github.com/torrentpier/torrentpier
synced 2025-07-05 20:41:41 -07:00
* feat: implement centralized Config class to replace global $bb_cfg array - Add singleton Config class with dot notation support for nested configuration - Implement thread-safe configuration access with magic methods (__get, __set, __isset) - Add global config() helper function for convenient access - Support for getSection(), merge(), has(), all() methods with type safety BREAKING CHANGE: While $bb_cfg global array still works for backward compatibility, new code should use config()->get() method with dot notation Updated files: - src/Config.php: New Config singleton class implementation - common.php: Initialize Config singleton and add global helper - src/Emailer.php: Replace $bb_cfg with config()->get() - src/Ajax.php: Replace $bb_cfg with config()->get() - src/Censor.php: Replace $bb_cfg with config()->get() - src/Validate.php: Replace $bb_cfg with config()->get() - src/Dev.php: Replace $bb_cfg with config()->get() - src/Sitemap.php: Replace $bb_cfg with config()->get() - src/TorrServerAPI.php: Replace $bb_cfg with config()->get() - src/Sessions.php: Replace $bb_cfg with config()->get() - src/Legacy/TorrentFileList.php: Replace $bb_cfg with config()->get() - src/Legacy/Poll.php: Replace $bb_cfg with config()->get() - src/Legacy/Torrent.php: Replace $bb_cfg with config()->get() - src/Legacy/Common/User.php: Replace $bb_cfg with config()->get() - src/Legacy/Template.php: Replace $bb_cfg with config()->get() - src/Legacy/Atom.php: Replace $bb_cfg with config()->get() - src/Legacy/Admin/Common.php: Replace $bb_cfg with config()->get() - viewforum.php: Replace $bb_cfg with config()->get() - posting.php: Replace $bb_cfg with config()->get() - dl.php: Replace $bb_cfg with config()->get() - feed.php: Replace $bb_cfg with config()->get() - filelist.php: Replace $bb_cfg with config()->get() - group_edit.php: Replace $bb_cfg with config()->get() - group.php: Replace $bb_cfg with config()->get() - index.php: Replace $bb_cfg with config()->get() - login.php: Replace $bb_cfg with config()->get() - memberlist.php: Replace $bb_cfg with config()->get() - modcp.php: Replace $bb_cfg with config()->get() - playback_m3u.php: Replace $bb_cfg with config()->get() - poll.php: Replace $bb_cfg with config()->get() * refactor: replace $bb_cfg with config() in various admin files - Updated multiple admin files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - common.php - index.php - admin_attach_cp.php - admin_log.php - admin_mass_email.php - admin_sitemap.php - admin_smilies.php - admin_terms.php - admin_user_search.php - admin_words.php - admin/index.php - admin/stats/tracker.php * refactor: update init_bb.php to use config() for configuration management - Replaced the merging of $bb_cfg with a call to config()->merge() for improved clarity and maintainability. - Updated the retrieval of all configuration settings to use config()->all(). This change continues the transition towards a centralized configuration system. * refactor: replace $bb_cfg with config() in various files - Updated multiple files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - privmsg.php - search.php - terms.php - tracker.php - viewtopic.php - bt/announce.php - bt/scrape.php - bt/includes/init_tr.php - library/ajax/*.php - src/Config.php * refactor: replace $bb_cfg with config() in attachment and display files - Updated multiple files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - attachment_mod.php - displaying_torrent.php - functions_delete.php - bbcode.php - functions.php - init_bb.php - online_userlist.php - page_footer.php - page_header.php - torrent_show_dl_list.php - cron jobs (various files) - datastore build files (various files) * refactor: replace $bb_cfg with config() in user control panel files - Updated multiple user control panel files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - bonus.php - email.php - register.php - sendpasswd.php - topic_watch.php - viewprofile.php * refactor: replace $bb_cfg with config() in various legacy files - Updated multiple legacy files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - sidebar2.html - BBCode.php - LogAction.php - Post.php - Template.php - Torrent.php - Common/User.php - Common/Select.php - Common/Upload.php - Admin/Common.php - tpl_config.php * refactor: remove legacy DOCUMENTATION.md and add UPGRADE_GUIDE.md - Deleted the outdated DOCUMENTATION.md file, which contained legacy configuration information. - Introduced a new UPGRADE_GUIDE.md to assist users in migrating to the new configuration system. - The upgrade guide includes migration strategies, breaking changes, and best practices for using the new Config class. Files modified: - DOCUMENTATION.md (deleted) - UPGRADE_GUIDE.md (new) * refactor: update legacy files to maintain compatibility with bb_cfg deprecation - Added comments in init_bb.php, Template.php, and Cron.php to indicate that bb_cfg is deprecated but retained for compatibility with non-adapted code. - Ensured clarity in documentation for future reference while transitioning to the new configuration system. Files modified: - init_bb.php - Template.php - Cron.php
119 lines
3.4 KiB
PHP
119 lines
3.4 KiB
PHP
<?php
|
||
/**
|
||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||
*
|
||
* @copyright Copyright (c) 2005-2025 TorrentPier (https://torrentpier.com)
|
||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||
*/
|
||
|
||
define('BB_SCRIPT', 'playback_m3u');
|
||
|
||
require __DIR__ . '/common.php';
|
||
|
||
if (!config()->get('torr_server.enabled')) {
|
||
redirect('index.php');
|
||
}
|
||
|
||
// Valid file formats
|
||
$validFormats = [
|
||
'audio' => ['mp3', 'flac', 'wav', 'm4a'],
|
||
'video' => ['mp4', 'mkv', 'avi', 'm4v']
|
||
];
|
||
|
||
// Start session management
|
||
$user->session_start(['req_login' => config()->get('torr_server.disable_for_guest')]);
|
||
|
||
// Disable robots indexing
|
||
$page_cfg['allow_robots'] = false;
|
||
|
||
// Check topic_id
|
||
$topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0;
|
||
if (!$topic_id) {
|
||
bb_die($lang['INVALID_TOPIC_ID'], 404);
|
||
}
|
||
|
||
// Getting torrent info from database
|
||
$sql = 'SELECT attach_id, forum_id, info_hash, info_hash_v2
|
||
FROM ' . BB_BT_TORRENTS . '
|
||
WHERE topic_id = ' . $topic_id . '
|
||
LIMIT 1';
|
||
|
||
if (!$row = DB()->fetch_row($sql)) {
|
||
bb_die($lang['INVALID_TOPIC_ID_DB'], 404);
|
||
}
|
||
|
||
// Check m3u file exist
|
||
$torrServer = new \TorrentPier\TorrServerAPI();
|
||
if (!$m3uFile = $torrServer->getM3UPath($row['attach_id'])) {
|
||
bb_die($lang['ERROR_NO_ATTACHMENT']);
|
||
}
|
||
|
||
$forum_id = $row['forum_id'];
|
||
set_die_append_msg($forum_id, $topic_id);
|
||
|
||
// Check rights
|
||
$is_auth = auth(AUTH_ALL, $forum_id, $userdata);
|
||
if (!$is_auth['auth_download']) {
|
||
bb_die($lang['SORRY_AUTH_VIEW_ATTACH']);
|
||
}
|
||
|
||
// Parse M3U file
|
||
$m3uParser = new M3uParser\M3uParser();
|
||
$m3uParser->addDefaultTags();
|
||
$m3uData = $m3uParser->parseFile($m3uFile);
|
||
|
||
$filesCount = 0;
|
||
foreach ($m3uData as $entry) {
|
||
// Validate URL
|
||
$streamLink = $entry->getPath();
|
||
if (!filter_var($streamLink, FILTER_VALIDATE_URL)) {
|
||
continue;
|
||
}
|
||
parse_str(parse_url($streamLink, PHP_URL_QUERY), $urlParams);
|
||
|
||
// Parse tags
|
||
foreach ($entry->getExtTags() as $extTag) {
|
||
// #EXTINF tag
|
||
if ($extTag == $extTag instanceof \M3uParser\Tag\ExtInf) {
|
||
$title = $extTag->getTitle();
|
||
}
|
||
}
|
||
|
||
// Validate title
|
||
if (!isset($title)) {
|
||
continue;
|
||
}
|
||
|
||
// Validate file extension
|
||
$getExtension = pathinfo($title, PATHINFO_EXTENSION);
|
||
if ($getExtension === str_replace('.', '', $torrServer::M3U['extension'])) {
|
||
// Skip m3u files
|
||
continue;
|
||
}
|
||
|
||
$filesCount++;
|
||
$rowClass = ($filesCount % 2) ? 'row1' : 'row2';
|
||
$template->assign_block_vars('m3ulist', [
|
||
'ROW_NUMBER' => $filesCount,
|
||
'FILE_INDEX' => $urlParams['index'],
|
||
'ROW_CLASS' => $rowClass,
|
||
'IS_VALID' => in_array($getExtension, array_merge($validFormats['audio'], $validFormats['video'])),
|
||
'IS_AUDIO' => (int)in_array($getExtension, $validFormats['audio']),
|
||
'STREAM_LINK' => $streamLink,
|
||
'M3U_DL_LINK' => DL_URL . $row['attach_id'] . '&m3u=1',
|
||
'TITLE' => $title,
|
||
]);
|
||
}
|
||
|
||
// Generate output
|
||
$template->assign_vars([
|
||
'HAS_ITEMS' => $filesCount > 0,
|
||
'PAGE_TITLE' => $lang['PLAYBACK_M3U'],
|
||
'ATTACH_ID' => $row['attach_id'],
|
||
'INFO_HASH' => bin2hex($row['info_hash'] ?? $row['info_hash_v2']),
|
||
'FILES_COUNT_TITLE' => sprintf($lang['BT_FLIST_FILE_PATH'], declension($filesCount, 'files')),
|
||
'U_TOPIC' => TOPIC_URL . $topic_id,
|
||
]);
|
||
|
||
print_page('playback_m3u.tpl');
|