diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 000000000..419685df6 --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,473 @@ +# ⚙️ TorrentPier Configuration System + +TorrentPier features a modern, centralized configuration system using the `Config` class with full backward compatibility. The new system provides better IDE support, type safety, and dot notation for nested configurations. + +## 📖 Table of Contents + +- [Basic Usage](#basic-usage) +- [Advanced Usage](#advanced-usage) +- [Migration Guide](#migration-guide) +- [Configuration Reference](#configuration-reference) +- [Magic Methods](#magic-methods) +- [Type Safety & IDE Support](#type-safety--ide-support) +- [Thread Safety](#thread-safety) +- [Best Practices](#best-practices) + +## 🚀 Basic Usage + +### Getting Configuration Values + +```php +// Get configuration values using dot notation +$siteName = config()->get('sitename'); +$dbHost = config()->get('database.host'); +$cacheTimeout = config()->get('cache.timeout'); + +// Get with default value if key doesn't exist +$maxUsers = config()->get('max_users_online', 100); +$debugMode = config()->get('debug.enabled', false); +``` + +### Setting Configuration Values + +```php +// Set configuration values +config()->set('sitename', 'My Awesome Tracker'); +config()->set('database.port', 3306); +config()->set('cache.enabled', true); + +// Set nested configuration +config()->set('torr_server.enabled', true); +config()->set('torr_server.url', 'http://localhost:8090'); +``` + +### Checking Configuration Existence + +```php +// Check if configuration exists +if (config()->has('bt_announce_url')) { + $announceUrl = config()->get('bt_announce_url'); +} + +// Check nested configuration +if (config()->has('tracker.retracker_host')) { + $retrackerHost = config()->get('tracker.retracker_host'); +} +``` + +## 🔧 Advanced Usage + +### Working with Configuration Sections + +```php +// Get entire configuration section +$dbConfig = config()->getSection('database'); +// Returns: ['host' => 'localhost', 'port' => 3306, 'name' => 'torrentpier'] + +$trackerConfig = config()->getSection('tracker'); +// Returns all tracker-related settings + +// Get all configuration +$allConfig = config()->all(); +``` + +### Merging Configuration Arrays + +```php +// Merge configuration arrays (useful for extending existing config) +config()->merge('tor_icons', [ + 10 => '🔥', // Hot torrent + 11 => '⭐', // Featured torrent + 12 => '💎' // Premium torrent +]); + +// Merge tracker settings +config()->merge('tracker', [ + 'new_feature_enabled' => true, + 'custom_announce_interval' => 1800 +]); +``` + +### Using Global Helper Function + +```php +// Alternative syntax using global helper +$serverName = config('server_name'); +$dbTimeout = config('database.timeout', 30); + +// These are equivalent: +config()->get('sitename'); +config('sitename'); +``` + +## 🔄 Migration Guide + +The system maintains **full backward compatibility** while providing modern access patterns: + +### Old vs New Syntax Examples + +```php +// ❌ Old way (still works, but not recommended) +global $bb_cfg; +$announceUrl = $bb_cfg['bt_announce_url']; +$dbHost = $bb_cfg['database']['host']; +$trackerEnabled = $bb_cfg['tracker']['enabled']; +$atomPath = $bb_cfg['atom']['path']; + +// ✅ New way (recommended) +$announceUrl = config()->get('bt_announce_url'); +$dbHost = config()->get('database.host'); +$trackerEnabled = config()->get('tracker.enabled'); +$atomPath = config()->get('atom.path'); +``` + +### Migration Steps + +1. **Replace global $bb_cfg declarations** with config() calls +2. **Convert array access** to dot notation +3. **Add null checks** where appropriate +4. **Use type hints** for better IDE support + +```php +// Before migration +function getDbConnection() { + global $bb_cfg; + $host = $bb_cfg['database']['host']; + $port = $bb_cfg['database']['port'] ?? 3306; + // ... +} + +// After migration +function getDbConnection() { + $host = config()->get('database.host'); + $port = config()->get('database.port', 3306); + // ... +} +``` + +## 📚 Configuration Reference + +### Site Settings +```php +config()->get('sitename') // $bb_cfg['sitename'] +config()->get('site_desc') // $bb_cfg['site_desc'] +config()->get('server_name') // $bb_cfg['server_name'] +config()->get('server_port') // $bb_cfg['server_port'] +config()->get('default_lang') // $bb_cfg['default_lang'] +config()->get('board_timezone') // $bb_cfg['board_timezone'] +``` + +### Database Settings +```php +config()->get('database.host') // $bb_cfg['database']['host'] +config()->get('database.port') // $bb_cfg['database']['port'] +config()->get('database.name') // $bb_cfg['database']['name'] +config()->get('database.user') // $bb_cfg['database']['user'] +config()->get('database.password') // $bb_cfg['database']['password'] +``` + +### BitTorrent Settings +```php +config()->get('bt_announce_url') // $bb_cfg['bt_announce_url'] +config()->get('bt_disable_dht') // $bb_cfg['bt_disable_dht'] +config()->get('bt_check_announce_url') // $bb_cfg['bt_check_announce_url'] +config()->get('bt_add_auth_key') // $bb_cfg['bt_add_auth_key'] +config()->get('bt_replace_ann_url') // $bb_cfg['bt_replace_ann_url'] +config()->get('bt_del_addit_ann_urls') // $bb_cfg['bt_del_addit_ann_urls'] +config()->get('bt_set_dltype_on_tor_reg') // $bb_cfg['bt_set_dltype_on_tor_reg'] +config()->get('bt_unset_dltype_on_tor_unreg') // $bb_cfg['bt_unset_dltype_on_tor_unreg'] +config()->get('bt_min_ratio_allow_dl_tor') // $bb_cfg['bt_min_ratio_allow_dl_tor'] +config()->get('bt_newtopic_auto_reg') // $bb_cfg['bt_newtopic_auto_reg'] +``` + +### Tracker Settings +```php +config()->get('tracker.disabled_v1_torrents') // $bb_cfg['tracker']['disabled_v1_torrents'] +config()->get('tracker.disabled_v2_torrents') // $bb_cfg['tracker']['disabled_v2_torrents'] +config()->get('tracker.retracker_host') // $bb_cfg['tracker']['retracker_host'] +config()->get('tracker.retracker') // $bb_cfg['tracker']['retracker'] +config()->get('tracker.tor_topic_up') // $bb_cfg['tracker']['tor_topic_up'] +config()->get('tracker.use_old_torrent_name_format') // $bb_cfg['tracker']['use_old_torrent_name_format'] +``` + +### TorrServer Integration +```php +config()->get('torr_server.enabled') // $bb_cfg['torr_server']['enabled'] +config()->get('torr_server.url') // $bb_cfg['torr_server']['url'] +config()->get('torr_server.timeout') // $bb_cfg['torr_server']['timeout'] +config()->get('torr_server.disable_for_guest') // $bb_cfg['torr_server']['disable_for_guest'] +``` + +### Security & Authentication +```php +config()->get('captcha.disabled') // $bb_cfg['captcha']['disabled'] +config()->get('passkey_key') // $bb_cfg['passkey_key'] +config()->get('password_symbols.nums') // $bb_cfg['password_symbols']['nums'] +config()->get('password_symbols.chars') // $bb_cfg['password_symbols']['chars'] +config()->get('password_hash_options.algo') // $bb_cfg['password_hash_options']['algo'] +config()->get('password_hash_options.options') // $bb_cfg['password_hash_options']['options'] +config()->get('allow_autologin') // $bb_cfg['allow_autologin'] +config()->get('max_autologin_time') // $bb_cfg['max_autologin_time'] +config()->get('session_update_intrv') // $bb_cfg['session_update_intrv'] +config()->get('invalid_logins') // $bb_cfg['invalid_logins'] +config()->get('first_logon_redirect_url') // $bb_cfg['first_logon_redirect_url'] +``` + +### Cache Settings +```php +config()->get('cache.prefix') // $bb_cfg['cache']['prefix'] +config()->get('cache.timeout') // $bb_cfg['cache']['timeout'] +config()->get('cache.enabled') // $bb_cfg['cache']['enabled'] +``` + +### Forum Settings +```php +config()->get('topics_per_page') // $bb_cfg['topics_per_page'] +config()->get('posts_per_page') // $bb_cfg['posts_per_page'] +config()->get('allowed_topics_per_page') // $bb_cfg['allowed_topics_per_page'] +config()->get('hot_threshold') // $bb_cfg['hot_threshold'] +config()->get('show_dl_status_in_forum') // $bb_cfg['show_dl_status_in_forum'] +config()->get('sf_on_first_page_only') // $bb_cfg['sf_on_first_page_only'] +config()->get('last_post_date_format') // $bb_cfg['last_post_date_format'] +config()->get('post_date_format') // $bb_cfg['post_date_format'] +config()->get('group_members_per_page') // $bb_cfg['group_members_per_page'] +config()->get('flist_timeout') // $bb_cfg['flist_timeout'] +config()->get('flist_max_files') // $bb_cfg['flist_max_files'] +``` + +### News & Feeds +```php +config()->get('show_latest_news') // $bb_cfg['show_latest_news'] +config()->get('latest_news_forum_id') // $bb_cfg['latest_news_forum_id'] +config()->get('show_network_news') // $bb_cfg['show_network_news'] +config()->get('network_news_forum_id') // $bb_cfg['network_news_forum_id'] +config()->get('atom.path') // $bb_cfg['atom']['path'] +config()->get('atom.url') // $bb_cfg['atom']['url'] +config()->get('atom.direct_down') // $bb_cfg['atom']['direct_down'] +config()->get('atom.direct_view') // $bb_cfg['atom']['direct_view'] +``` + +### Torrent Status & Icons +```php +config()->get('tor_icons') // $bb_cfg['tor_icons'] +config()->get('tor_frozen') // $bb_cfg['tor_frozen'] +config()->get('tor_cannot_new') // $bb_cfg['tor_cannot_new'] +config()->get('tor_cannot_edit') // $bb_cfg['tor_cannot_edit'] +``` + +### Poll Settings +```php +config()->get('max_poll_options') // $bb_cfg['max_poll_options'] +config()->get('poll_max_days') // $bb_cfg['poll_max_days'] +``` + +### Debug & Development +```php +config()->get('xs_use_cache') // $bb_cfg['xs_use_cache'] +config()->get('auto_language_detection') // $bb_cfg['auto_language_detection'] +config()->get('dbg_users') // $bb_cfg['dbg_users'] +config()->get('super_admins') // $bb_cfg['super_admins'] +config()->get('torhelp_enabled') // $bb_cfg['torhelp_enabled'] +config()->get('premod') // $bb_cfg['premod'] +``` + +### Email Settings +```php +config()->get('emailer.enabled') // $bb_cfg['emailer']['enabled'] +config()->get('emailer.smtp.host') // $bb_cfg['emailer']['smtp']['host'] +config()->get('emailer.smtp.port') // $bb_cfg['emailer']['smtp']['port'] +config()->get('group_send_email') // $bb_cfg['group_send_email'] +``` + +### Avatar & Upload Settings +```php +config()->get('group_avatars.up_allowed') // $bb_cfg['group_avatars']['up_allowed'] +config()->get('group_avatars.max_size') // $bb_cfg['group_avatars']['max_size'] +``` + +## 🪄 Magic Methods + +The Config class supports magic methods for convenient access: + +### Magic Getter +```php +// Using magic getter (equivalent to get()) +$siteName = config()->sitename; +$serverName = config()->server_name; + +// For nested keys, use curly braces +$dbHost = config()->{'database.host'}; +$atomPath = config()->{'atom.path'}; +``` + +### Magic Setter +```php +// Using magic setter (equivalent to set()) +config()->sitename = 'New Site Name'; +config()->server_port = 8080; + +// For nested keys +config()->{'database.port'} = 3306; +config()->{'torr_server.enabled'} = true; +``` + +### Magic Isset +```php +// Using magic isset (equivalent to has()) +if (isset(config()->bt_announce_url)) { + // Configuration exists +} + +if (isset(config()->{'tracker.retracker_host'})) { + // Nested configuration exists +} +``` + +## 🔍 Type Safety & IDE Support + +The Config class provides better type safety and IDE autocomplete support: + +```php +// IDE will provide autocomplete and type hints +$config = config(); +$siteName = $config->get('sitename'); // Returns string|null +$isEnabled = $config->has('feature_enabled'); // Returns bool +$allSettings = $config->all(); // Returns array +$section = $config->getSection('database'); // Returns array|null +``` + +### Type Declarations +```php +// You can add type hints for better code documentation +function getDatabaseConfig(): ?array { + return config()->getSection('database'); +} + +function getSiteName(): string { + return config()->get('sitename', 'TorrentPier'); +} + +function isFeatureEnabled(string $feature): bool { + return config()->get($feature, false); +} +``` + +## 🧵 Thread Safety + +The Config class is implemented as a thread-safe singleton, ensuring consistent configuration access across your application: + +```php +// These will return the same instance +$config1 = config(); +$config2 = \TorrentPier\Config::getInstance(); +var_dump($config1 === $config2); // true + +// Configuration is shared across all instances +config()->set('test_value', 'hello'); +echo \TorrentPier\Config::getInstance()->get('test_value'); // "hello" +``` + +## 📋 Best Practices + +### 1. Use Dot Notation for Nested Config +```php +// ✅ Recommended +$host = config()->get('database.host'); +$enabled = config()->get('torr_server.enabled'); + +// ❌ Avoid (though it works) +$dbConfig = config()->get('database'); +$host = $dbConfig['host']; +``` + +### 2. Always Provide Defaults for Optional Settings +```php +// ✅ Good - provides sensible defaults +$timeout = config()->get('api.timeout', 30); +$maxRetries = config()->get('api.max_retries', 3); +$debugMode = config()->get('debug.enabled', false); + +// ❌ Avoid - might return null unexpectedly +$timeout = config()->get('api.timeout'); +``` + +### 3. Use Type Hints and Validation +```php +// ✅ Good - validates and converts types +function getMaxUploadSize(): int { + $size = config()->get('upload.max_size', 10485760); // 10MB default + return (int) $size; +} + +function isMaintenanceMode(): bool { + return (bool) config()->get('maintenance.enabled', false); +} +``` + +### 4. Cache Frequently Used Config Values +```php +// ✅ Good for performance-critical code +class TrackerService { + private string $announceUrl; + private int $announceInterval; + + public function __construct() { + $this->announceUrl = config()->get('bt_announce_url'); + $this->announceInterval = config()->get('bt_announce_interval', 1800); + } +} +``` + +### 5. Use Sections for Related Configuration +```php +// ✅ Good - organize related settings +function setupEmailer(): void { + $emailConfig = config()->getSection('emailer'); + + if ($emailConfig['enabled'] ?? false) { + // Configure SMTP with $emailConfig['smtp'] + } +} +``` + +### 6. Validate Critical Configuration at Startup +```php +// ✅ Good - validate required configuration early +function validateConfig(): void { + $required = [ + 'database.host', + 'database.name', + 'bt_announce_url', + 'server_name' + ]; + + foreach ($required as $key) { + if (!config()->has($key)) { + throw new ConfigurationException("Required configuration missing: {$key}"); + } + } +} +``` + +## 🚨 Migration Checklist + +When migrating from `$bb_cfg` to the Config class: + +- [ ] Replace `global $bb_cfg;` with `config()` calls +- [ ] Convert array syntax `$bb_cfg['key']['nested']` to dot notation `config()->get('key.nested')` +- [ ] Add default values where appropriate +- [ ] Add type hints to function returns +- [ ] Test all configuration-dependent functionality +- [ ] Update documentation and comments +- [ ] Consider caching frequently accessed values + +## 📞 Support + +If you encounter issues with the configuration system: + +1. Join our [Official Support Forum](https://torrentpier.com) +2. Search existing [GitHub Issues](https://github.com/torrentpier/torrentpier/issues) + +--- + +**Note**: The old `$bb_cfg` global array system continues to work for backward compatibility, but using the new Config class is recommended for all new code and when refactoring existing code. \ No newline at end of file diff --git a/dl.php b/dl.php index 2812f1fa0..bfc0ef678 100644 --- a/dl.php +++ b/dl.php @@ -25,7 +25,7 @@ $m3u = isset($_GET['m3u']) && $_GET['m3u']; // Send file to browser function send_file_to_browser($attachment, $upload_dir) { - global $bb_cfg, $lang; + global $lang; $filename = $upload_dir . '/' . $attachment['physical_filename']; $gotit = false; @@ -170,7 +170,7 @@ if (!IS_AM && ($attachment['mimetype'] === TORRENT_MIMETYPE)) { $row = DB()->sql_fetchrow($result); - if (isset($bb_cfg['tor_frozen'][$row['tor_status']]) && !(isset($bb_cfg['tor_frozen_author_download'][$row['tor_status']]) && $userdata['user_id'] === $row['poster_id'])) { + if (isset(config()->get('tor_frozen')[$row['tor_status']]) && !(isset(config()->get('tor_frozen_author_download')[$row['tor_status']]) && $userdata['user_id'] === $row['poster_id'])) { bb_die($lang['TOR_STATUS_FORBIDDEN'] . $lang['TOR_STATUS_NAME'][$row['tor_status']]); } @@ -219,7 +219,7 @@ switch ($download_mode) { header('Location: ' . $url); exit; case INLINE_LINK: - if (IS_GUEST && !$bb_cfg['captcha']['disabled'] && !bb_captcha('check')) { + if (IS_GUEST && !config()->get('captcha.disabled') && !bb_captcha('check')) { global $template; $redirect_url = $_POST['redirect_url'] ?? $_SERVER['HTTP_REFERER'] ?? '/'; diff --git a/feed.php b/feed.php index 366518ef0..bbd9eb3e0 100644 --- a/feed.php +++ b/feed.php @@ -34,11 +34,11 @@ if ($mode === 'get_feed_url' && ($type === 'f' || $type === 'u') && $id >= 0) { bb_simple_die($lang['ATOM_ERROR'] . ' #1'); } } - if (is_file($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') > $timecheck) { - redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom'); + if (is_file(config()->get('atom.path') . '/f/' . $id . '.atom') && filemtime(config()->get('atom.path') . '/f/' . $id . '.atom') > $timecheck) { + redirect(config()->get('atom.url') . '/f/' . $id . '.atom'); } else { if (\TorrentPier\Legacy\Atom::update_forum_feed($id, $forum_data)) { - redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom'); + redirect(config()->get('atom.url') . '/f/' . $id . '.atom'); } else { bb_simple_die($lang['ATOM_NO_FORUM']); } @@ -52,11 +52,11 @@ if ($mode === 'get_feed_url' && ($type === 'f' || $type === 'u') && $id >= 0) { if (!$username = get_username($id)) { bb_simple_die($lang['ATOM_ERROR'] . ' #3'); } - if (is_file($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > $timecheck) { - redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); + if (is_file(config()->get('atom.path') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime(config()->get('atom.path') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > $timecheck) { + redirect(config()->get('atom.url') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); } else { if (\TorrentPier\Legacy\Atom::update_user_feed($id, $username)) { - redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); + redirect(config()->get('atom.url') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); } else { bb_simple_die($lang['ATOM_NO_USER']); } diff --git a/filelist.php b/filelist.php index 8e256dc67..81a241d20 100644 --- a/filelist.php +++ b/filelist.php @@ -14,7 +14,7 @@ require __DIR__ . '/common.php'; // Start session management $user->session_start(); -if ($bb_cfg['bt_disable_dht'] && IS_GUEST) { +if (config()->get('bt_disable_dht') && IS_GUEST) { bb_die($lang['BT_PRIVATE_TRACKER'], 403); } @@ -55,7 +55,7 @@ if (!is_file($file_path)) { } $file_contents = file_get_contents($file_path); -if ($bb_cfg['flist_max_files']) { +if (config()->get('flist_max_files')) { $filetree_pos = $meta_v2 ? strpos($file_contents, '9:file tree') : false; $files_pos = $meta_v1 ? strpos($file_contents, '5:files', $filetree_pos) : false; @@ -65,8 +65,8 @@ if ($bb_cfg['flist_max_files']) { $file_count = substr_count($file_contents, '6:length', $files_pos); } - if ($file_count > $bb_cfg['flist_max_files']) { - bb_die(sprintf($lang['BT_FLIST_LIMIT'], $bb_cfg['flist_max_files'], $file_count), 410); + if ($file_count > config()->get('flist_max_files')) { + bb_die(sprintf($lang['BT_FLIST_LIMIT'], config()->get('flist_max_files'), $file_count), 410); } } diff --git a/group.php b/group.php index b674c823d..e88bb6de7 100644 --- a/group.php +++ b/group.php @@ -24,7 +24,7 @@ set_die_append_msg(); $group_id = isset($_REQUEST[POST_GROUPS_URL]) ? (int)$_REQUEST[POST_GROUPS_URL] : null; $start = isset($_REQUEST['start']) ? abs((int)$_REQUEST['start']) : 0; -$per_page = $bb_cfg['group_members_per_page']; +$per_page = config()->get('group_members_per_page'); $view_mode = isset($_REQUEST['view']) ? (string)$_REQUEST['view'] : null; $rel_limit = 50; @@ -168,7 +168,7 @@ if (!$group_id) { \TorrentPier\Legacy\Group::add_user_into_group($group_id, $userdata['user_id'], 1, TIMENOW); - if ($bb_cfg['group_send_email']) { + if (config()->get('group_send_email')) { // Sending email $emailer = new TorrentPier\Emailer(); @@ -224,7 +224,7 @@ if (!$group_id) { \TorrentPier\Legacy\Group::add_user_into_group($group_id, $row['user_id']); - if ($bb_cfg['group_send_email']) { + if (config()->get('group_send_email')) { // Sending email $emailer = new TorrentPier\Emailer(); @@ -273,10 +273,10 @@ if (!$group_id) { } } // Email users when they are approved - if (!empty($_POST['approve']) && $bb_cfg['group_send_email']) { + if (!empty($_POST['approve']) && config()->get('group_send_email')) { $sql_select = "SELECT username, user_email, user_lang - FROM " . BB_USERS . " - WHERE user_id IN($sql_in)"; + FROM " . BB_USERS . " + WHERE user_id IN($sql_in)"; if (!$result = DB()->sql_query($sql_select)) { bb_die('Could not get user email information'); diff --git a/group_edit.php b/group_edit.php index f98e69aed..041365bf4 100644 --- a/group_edit.php +++ b/group_edit.php @@ -35,10 +35,10 @@ if ($group_id) { if ($is_moderator) { // Avatar if ($submit) { - if (!empty($_FILES['avatar']['name']) && $bb_cfg['group_avatars']['up_allowed']) { + if (!empty($_FILES['avatar']['name']) && config()->get('group_avatars.up_allowed')) { $upload = new TorrentPier\Legacy\Common\Upload(); - if ($upload->init($bb_cfg['group_avatars'], $_FILES['avatar']) and $upload->store('avatar', ['user_id' => GROUP_AVATAR_MASK . $group_id, 'avatar_ext_id' => $group_info['avatar_ext_id']])) { + if ($upload->init(config()->get('group_avatars'), $_FILES['avatar']) and $upload->store('avatar', ['user_id' => GROUP_AVATAR_MASK . $group_id, 'avatar_ext_id' => $group_info['avatar_ext_id']])) { $avatar_ext_id = (int)$upload->file_ext_id; DB()->query("UPDATE " . BB_GROUPS . " SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1"); } else { @@ -76,7 +76,7 @@ if ($is_moderator) { 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_GROUP_CONFIG_ACTION' => "group_edit.php?" . POST_GROUPS_URL . "=$group_id", - 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['group_avatars']['max_width'], $bb_cfg['group_avatars']['max_height'], humn_size($bb_cfg['group_avatars']['max_size'])), + 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], config()->get('group_avatars.max_width'), config()->get('group_avatars.max_height'), humn_size(config()->get('group_avatars.max_size'))), 'AVATAR_IMG' => get_avatar(GROUP_AVATAR_MASK . $group_id, $group_info['avatar_ext_id']), ]); diff --git a/index.php b/index.php index 2c752341c..6ff9468fb 100644 --- a/index.php +++ b/index.php @@ -31,12 +31,12 @@ $datastore->enqueue([ 'cat_forums' ]); -if ($bb_cfg['show_latest_news']) { +if (config()->get('show_latest_news')) { $datastore->enqueue([ 'latest_news' ]); } -if ($bb_cfg['show_network_news']) { +if (config()->get('show_network_news')) { $datastore->enqueue([ 'network_news' ]); @@ -46,7 +46,7 @@ if ($bb_cfg['show_network_news']) { $user->session_start(); // Set meta description -$page_cfg['meta_description'] = $bb_cfg['site_desc']; +$page_cfg['meta_description'] = config()->get('site_desc'); // Init main vars $viewcat = isset($_GET[POST_CAT_URL]) ? (int)$_GET[POST_CAT_URL] : 0; @@ -57,7 +57,7 @@ $req_page = 'index_page'; $req_page .= $viewcat ? "_c{$viewcat}" : ''; define('REQUESTED_PAGE', $req_page); -caching_output(IS_GUEST, 'send', REQUESTED_PAGE . '_guest_' . $bb_cfg['default_lang']); +caching_output(IS_GUEST, 'send', REQUESTED_PAGE . '_guest_' . config()->get('default_lang')); $hide_cat_opt = isset($user->opt_js['h_cat']) ? (string)$user->opt_js['h_cat'] : 0; $hide_cat_user = array_flip(explode('-', $hide_cat_opt)); @@ -259,7 +259,7 @@ foreach ($cat_forums as $cid => $c) { 'LAST_TOPIC_ID' => $f['last_topic_id'], 'LAST_TOPIC_TIP' => $f['last_topic_title'], 'LAST_TOPIC_TITLE' => str_short($f['last_topic_title'], $last_topic_max_len), - 'LAST_POST_TIME' => bb_date($f['last_post_time'], $bb_cfg['last_post_date_format']), + 'LAST_POST_TIME' => bb_date($f['last_post_time'], config()->get('last_post_date_format')), 'LAST_POST_USER' => profile_url(['username' => str_short($f['last_post_username'], 15), 'user_id' => $f['last_post_user_id'], 'user_rank' => $f['last_post_user_rank']]), ]); } @@ -284,22 +284,22 @@ $template->assign_vars([ 'NEWEST_USER' => sprintf($lang['NEWEST_USER'], profile_url($stats['newestuser'])), // Tracker stats - 'TORRENTS_STAT' => $bb_cfg['tor_stats'] ? sprintf( + 'TORRENTS_STAT' => config()->get('tor_stats') ? sprintf( $lang['TORRENTS_STAT'], $stats['torrentcount'], humn_size($stats['size']) ) : '', - 'PEERS_STAT' => $bb_cfg['tor_stats'] ? sprintf( + 'PEERS_STAT' => config()->get('tor_stats') ? sprintf( $lang['PEERS_STAT'], $stats['peers'], $stats['seeders'], $stats['leechers'] ) : '', - 'SPEED_STAT' => $bb_cfg['tor_stats'] ? sprintf( + 'SPEED_STAT' => config()->get('tor_stats') ? sprintf( $lang['SPEED_STAT'], humn_size($stats['speed']) . '/s' ) : '', - 'SHOW_MOD_INDEX' => $bb_cfg['show_mod_index'], + 'SHOW_MOD_INDEX' => config()->get('show_mod_index'), 'FORUM_IMG' => $images['forum'], 'FORUM_NEW_IMG' => $images['forum_new'], 'FORUM_LOCKED_IMG' => $images['forum_locked'], @@ -312,19 +312,19 @@ $template->assign_vars([ 'U_SEARCH_SELF_BY_MY' => "search.php?uid={$userdata['user_id']}&o=1", 'U_SEARCH_LATEST' => 'search.php?search_id=latest', 'U_SEARCH_UNANSWERED' => 'search.php?search_id=unanswered', - 'U_ATOM_FEED' => is_file($bb_cfg['atom']['path'] . '/f/0.atom') ? make_url($bb_cfg['atom']['url'] . '/f/0.atom') : false, + 'U_ATOM_FEED' => is_file(config()->get('atom.path') . '/f/0.atom') ? make_url(config()->get('atom.url') . '/f/0.atom') : false, 'SHOW_LAST_TOPIC' => $show_last_topic, - 'BOARD_START' => $bb_cfg['show_board_start_index'] ? ($lang['BOARD_STARTED'] . ': ' . '' . bb_date($bb_cfg['board_startdate']) . '') : false, + 'BOARD_START' => config()->get('show_board_start_index') ? ($lang['BOARD_STARTED'] . ': ' . '' . bb_date(config()->get('board_startdate')) . '') : false, ]); // Set tpl vars for bt_userdata -if ($bb_cfg['bt_show_dl_stat_on_index'] && !IS_GUEST) { +if (config()->get('bt_show_dl_stat_on_index') && !IS_GUEST) { show_bt_userdata($userdata['user_id']); } // Latest news -if ($bb_cfg['show_latest_news']) { +if (config()->get('show_latest_news')) { if (!$latest_news = $datastore->get('latest_news')) { $datastore->update('latest_news'); $latest_news = $datastore->get('latest_news'); @@ -339,7 +339,7 @@ if ($bb_cfg['show_latest_news']) { $template->assign_block_vars('news', [ 'NEWS_TOPIC_ID' => $news['topic_id'], - 'NEWS_TITLE' => str_short($wordCensor->censorString($news['topic_title']), $bb_cfg['max_news_title']), + 'NEWS_TITLE' => str_short($wordCensor->censorString($news['topic_title']), config()->get('max_news_title')), 'NEWS_TIME' => bb_date($news['topic_time'], 'd-M', false), 'NEWS_IS_NEW' => is_unread($news['topic_time'], $news['topic_id'], $news['forum_id']), ]); @@ -347,7 +347,7 @@ if ($bb_cfg['show_latest_news']) { } // Network news -if ($bb_cfg['show_network_news']) { +if (config()->get('show_network_news')) { if (!$network_news = $datastore->get('network_news')) { $datastore->update('network_news'); $network_news = $datastore->get('network_news'); @@ -362,14 +362,14 @@ if ($bb_cfg['show_network_news']) { $template->assign_block_vars('net', [ 'NEWS_TOPIC_ID' => $net['topic_id'], - 'NEWS_TITLE' => str_short($wordCensor->censorString($net['topic_title']), $bb_cfg['max_net_title']), + 'NEWS_TITLE' => str_short($wordCensor->censorString($net['topic_title']), config()->get('max_net_title')), 'NEWS_TIME' => bb_date($net['topic_time'], 'd-M', false), 'NEWS_IS_NEW' => is_unread($net['topic_time'], $net['topic_id'], $net['forum_id']), ]); } } -if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { +if (config()->get('birthday_check_day') && config()->get('birthday_enabled')) { $week_list = $today_list = []; $week_all = $today_all = false; @@ -383,9 +383,9 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { $week_list[] = profile_url($week) . ' (' . birthday_age(date('Y-m-d', strtotime('-1 year', strtotime($week['user_birthday'])))) . ')'; } $week_all = $week_all ? ' ...' : ''; - $week_list = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], implode(', ', $week_list)) . $week_all; + $week_list = sprintf($lang['BIRTHDAY_WEEK'], config()->get('birthday_check_day'), implode(', ', $week_list)) . $week_all; } else { - $week_list = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); + $week_list = sprintf($lang['NOBIRTHDAY_WEEK'], config()->get('birthday_check_day')); } if (!empty($stats['birthday_today_list'])) { diff --git a/login.php b/login.php index 66bf544df..eb45e7109 100644 --- a/login.php +++ b/login.php @@ -63,7 +63,7 @@ $login_password = $_POST['login_password'] ?? ''; $need_captcha = false; if (!$mod_admin_login) { $need_captcha = CACHE('bb_login_err')->get('l_err_' . USER_IP); - if ($need_captcha < $bb_cfg['invalid_logins']) { + if ($need_captcha < config()->get('invalid_logins')) { $need_captcha = false; } } @@ -80,13 +80,13 @@ if (isset($_POST['login'])) { } // Captcha - if ($need_captcha && !$bb_cfg['captcha']['disabled'] && !bb_captcha('check')) { + if ($need_captcha && !config()->get('captcha.disabled') && !bb_captcha('check')) { $login_errors[] = $lang['CAPTCHA_WRONG']; } if (!$login_errors) { if ($user->login($_POST, $mod_admin_login)) { - $redirect_url = (defined('FIRST_LOGON')) ? $bb_cfg['first_logon_redirect_url'] : $redirect_url; + $redirect_url = (defined('FIRST_LOGON')) ? config()->get('first_logon_redirect_url') : $redirect_url; // Reset when entering the correct login/password combination CACHE('bb_login_err')->rm('l_err_' . USER_IP); @@ -101,7 +101,7 @@ if (isset($_POST['login'])) { if (!$mod_admin_login) { $login_err = CACHE('bb_login_err')->get('l_err_' . USER_IP); - if ($login_err > $bb_cfg['invalid_logins']) { + if ($login_err > config()->get('invalid_logins')) { $need_captcha = true; } CACHE('bb_login_err')->set('l_err_' . USER_IP, ($login_err + 1), 3600); @@ -118,7 +118,7 @@ if (IS_GUEST || $mod_admin_login) { 'ERROR_MESSAGE' => implode('
', $login_errors), 'ADMIN_LOGIN' => $mod_admin_login, 'REDIRECT_URL' => htmlCHR($redirect_url), - 'CAPTCHA_HTML' => ($need_captcha && !$bb_cfg['captcha']['disabled']) ? bb_captcha('get') : '', + 'CAPTCHA_HTML' => ($need_captcha && !config()->get('captcha.disabled')) ? bb_captcha('get') : '', 'PAGE_TITLE' => $lang['LOGIN'], 'S_LOGIN_ACTION' => LOGIN_URL ]); diff --git a/memberlist.php b/memberlist.php index 2182a2a2d..e70cfc0e3 100644 --- a/memberlist.php +++ b/memberlist.php @@ -54,26 +54,26 @@ $select_sort_role .= ''; switch ($mode) { case 'username': - $order_by = "username $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "username $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; case 'location': - $order_by = "user_from $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "user_from $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; case 'posts': - $order_by = "user_posts $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "user_posts $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; case 'email': - $order_by = "user_email $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "user_email $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; case 'website': - $order_by = "user_website $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "user_website $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; case 'topten': $order_by = "user_posts $sort_order LIMIT 10"; break; case 'joined': default: - $order_by = "user_regdate $sort_order LIMIT $start, " . $bb_cfg['topics_per_page']; + $order_by = "user_regdate $sort_order LIMIT $start, " . config()->get('topics_per_page'); break; } @@ -134,7 +134,7 @@ if ($mode != 'topten') { } if ($total = DB()->sql_fetchrow($result)) { $total_members = $total['total']; - generate_pagination($paginationurl, $total_members, $bb_cfg['topics_per_page'], $start); + generate_pagination($paginationurl, $total_members, config()->get('topics_per_page'), $start); } DB()->sql_freeresult($result); } diff --git a/modcp.php b/modcp.php index 33a578ac7..63b059130 100644 --- a/modcp.php +++ b/modcp.php @@ -223,16 +223,16 @@ switch ($mode) { $result = \TorrentPier\Legacy\Admin\Common::topic_delete($req_topics, $forum_id); //Обновление кеша новостей на главной - $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); - if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $result) { + $news_forums = array_flip(explode(',', config()->get('latest_news_forum_id'))); + if (isset($news_forums[$forum_id]) && config()->get('show_latest_news') && $result) { $datastore->enqueue([ 'latest_news' ]); $datastore->update('latest_news'); } - $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); - if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $result) { + $net_forums = array_flip(explode(',', config()->get('network_news_forum_id'))); + if (isset($net_forums[$forum_id]) && config()->get('show_network_news') && $result) { $datastore->enqueue([ 'network_news' ]); @@ -258,16 +258,16 @@ switch ($mode) { $result = \TorrentPier\Legacy\Admin\Common::topic_move($req_topics, $new_forum_id, $forum_id, isset($_POST['move_leave_shadow']), isset($_POST['insert_bot_msg']), $_POST['reason_move_bot']); //Обновление кеша новостей на главной - $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); - if ((isset($news_forums[$forum_id]) || isset($news_forums[$new_forum_id])) && $bb_cfg['show_latest_news'] && $result) { + $news_forums = array_flip(explode(',', config()->get('latest_news_forum_id'))); + if ((isset($news_forums[$forum_id]) || isset($news_forums[$new_forum_id])) && config()->get('show_latest_news') && $result) { $datastore->enqueue([ 'latest_news' ]); $datastore->update('latest_news'); } - $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); - if ((isset($net_forums[$forum_id]) || isset($net_forums[$new_forum_id])) && $bb_cfg['show_network_news'] && $result) { + $net_forums = array_flip(explode(',', config()->get('network_news_forum_id'))); + if ((isset($net_forums[$forum_id]) || isset($net_forums[$new_forum_id])) && config()->get('show_network_news') && $result) { $datastore->enqueue([ 'network_news' ]); @@ -557,7 +557,7 @@ switch ($mode) { $poster = $postrow[$i]['username']; $poster_rank = $postrow[$i]['user_rank']; - $post_date = bb_date($postrow[$i]['post_time'], $bb_cfg['post_date_format']); + $post_date = bb_date($postrow[$i]['post_time'], config()->get('post_date_format')); $message = $postrow[$i]['post_text']; diff --git a/playback_m3u.php b/playback_m3u.php index 3bf98fbd6..0cdcc3115 100644 --- a/playback_m3u.php +++ b/playback_m3u.php @@ -11,7 +11,7 @@ define('BB_SCRIPT', 'playback_m3u'); require __DIR__ . '/common.php'; -if (!$bb_cfg['torr_server']['enabled']) { +if (!config()->get('torr_server.enabled')) { redirect('index.php'); } @@ -22,7 +22,7 @@ $validFormats = [ ]; // Start session management -$user->session_start(['req_login' => $bb_cfg['torr_server']['disable_for_guest']]); +$user->session_start(['req_login' => config()->get('torr_server.disable_for_guest')]); // Disable robots indexing $page_cfg['allow_robots'] = false; diff --git a/poll.php b/poll.php index f64d04b70..7181b3f4e 100644 --- a/poll.php +++ b/poll.php @@ -47,8 +47,8 @@ if ($mode != 'poll_vote') { // Checking the ability to make changes if ($mode == 'poll_delete') { - if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400) { - bb_die(sprintf($lang['NEW_POLL_DAYS'], $bb_cfg['poll_max_days'])); + if ($t_data['topic_time'] < TIMENOW - config()->get('poll_max_days') * 86400) { + bb_die(sprintf($lang['NEW_POLL_DAYS'], config()->get('poll_max_days'))); } if (!IS_ADMIN && ($t_data['topic_vote'] != POLL_FINISHED)) { bb_die($lang['CANNOT_DELETE_POLL']); diff --git a/posting.php b/posting.php index 39d44c373..b41db5f6e 100644 --- a/posting.php +++ b/posting.php @@ -221,7 +221,7 @@ if (!$is_auth[$is_auth_type]) { } if ($mode == 'new_rel') { - if ($tor_status = implode(',', $bb_cfg['tor_cannot_new'])) { + if ($tor_status = implode(',', config()->get('tor_cannot_new'))) { $sql = DB()->fetch_rowset("SELECT t.topic_title, t.topic_id, tor.tor_status FROM " . BB_BT_TORRENTS . " tor, " . BB_TOPICS . " t WHERE poster_id = {$userdata['user_id']} @@ -232,7 +232,7 @@ if ($mode == 'new_rel') { $topics = ''; foreach ($sql as $row) { - $topics .= $bb_cfg['tor_icons'][$row['tor_status']] . '' . $row['topic_title'] . '
'; + $topics .= config()->get('tor_icons')[$row['tor_status']] . '' . $row['topic_title'] . '
'; } if ($topics && !(IS_SUPER_ADMIN && !empty($_REQUEST['edit_tpl']))) { bb_die($topics . $lang['UNEXECUTED_RELEASE']); @@ -243,9 +243,9 @@ if ($mode == 'new_rel') { } // Disallowed release editing with a certain status -if (!empty($bb_cfg['tor_cannot_edit']) && $post_info['allow_reg_tracker'] && $post_data['first_post'] && !IS_AM) { - if ($tor_status = DB()->fetch_row("SELECT tor_status FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id AND forum_id = $forum_id AND tor_status IN(" . implode(',', $bb_cfg['tor_cannot_edit']) . ") LIMIT 1")) { - bb_die($lang['NOT_EDIT_TOR_STATUS'] . ': ' . $bb_cfg['tor_icons'][$tor_status['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor_status['tor_status']] . '.'); +if (!empty(config()->get('tor_cannot_edit')) && $post_info['allow_reg_tracker'] && $post_data['first_post'] && !IS_AM) { + if ($tor_status = DB()->fetch_row("SELECT tor_status FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id AND forum_id = $forum_id AND tor_status IN(" . implode(',', config()->get('tor_cannot_edit')) . ") LIMIT 1")) { + bb_die($lang['NOT_EDIT_TOR_STATUS'] . ': ' . config()->get('tor_icons')[$tor_status['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor_status['tor_status']] . '.'); } } @@ -281,7 +281,7 @@ if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' AND pt.post_id = p.post_id AND p.post_time > $topic_last_read ORDER BY p.post_time - LIMIT " . $bb_cfg['posts_per_page']; + LIMIT " . config()->get('posts_per_page'); if ($rowset = DB()->fetch_rowset($sql)) { $topic_has_new_posts = true; @@ -291,7 +291,7 @@ if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', 'POSTER' => profile_url($row), 'POSTER_NAME_JS' => addslashes($row['username']), - 'POST_DATE' => '' . bb_date($row['post_time'], $bb_cfg['post_date_format']) . '', + 'POST_DATE' => '' . bb_date($row['post_time'], config()->get('post_date_format')) . '', 'MESSAGE' => get_parsed_post($row) ]); } @@ -374,9 +374,9 @@ if (($delete || $mode == 'delete') && !$confirm) { set_tracks(COOKIE_TOPIC, $tracking_topics, $topic_id); } - if (defined('TORRENT_ATTACH_ID') && $bb_cfg['bt_newtopic_auto_reg'] && !$error_msg) { + if (defined('TORRENT_ATTACH_ID') && config()->get('bt_newtopic_auto_reg') && !$error_msg) { if (!DB()->fetch_row("SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = " . TORRENT_ATTACH_ID)) { - if ($bb_cfg['premod']) { + if (config()->get('premod')) { // Getting a list of forum ids starting with "parent" $forum_parent = $forum_id; if ($post_info['forum_parent']) { @@ -468,7 +468,7 @@ if ($refresh || $error_msg || ($submit && $topic_has_new_posts)) { $message = '[quote="' . $quote_username . '"][qpost=' . $post_info['post_id'] . ']' . $message . '[/quote]'; // hide user passkey - $message = preg_replace('#(?<=[\?&;]' . $bb_cfg['passkey_key'] . '=)[a-zA-Z0-9]#', 'passkey', $message); + $message = preg_replace('#(?<=[\?&;]' . config()->get('passkey_key') . '=)[a-zA-Z0-9]#', 'passkey', $message); // hide sid $message = preg_replace('#(?<=[\?&;]sid=)[a-zA-Z0-9]#', 'sid', $message); @@ -618,7 +618,7 @@ $template->assign_vars([ 'U_VIEW_FORUM' => FORUM_URL . $forum_id, 'USERNAME' => @$username, - 'CAPTCHA_HTML' => (IS_GUEST && !$bb_cfg['captcha']['disabled']) ? bb_captcha('get') : '', + 'CAPTCHA_HTML' => (IS_GUEST && !config()->get('captcha.disabled')) ? bb_captcha('get') : '', 'SUBJECT' => $subject, 'MESSAGE' => $message, diff --git a/src/Censor.php b/src/Censor.php index 5b4d00a73..5d564240e 100644 --- a/src/Censor.php +++ b/src/Censor.php @@ -34,9 +34,9 @@ class Censor */ public function __construct() { - global $bb_cfg, $datastore; + global $datastore; - if (!$bb_cfg['use_word_censor']) { + if (!config()->get('use_word_censor')) { return; } diff --git a/src/Dev.php b/src/Dev.php index e1539eb03..0ad193880 100644 --- a/src/Dev.php +++ b/src/Dev.php @@ -67,13 +67,11 @@ class Dev */ private function getBugsnag(): void { - global $bb_cfg; - - if (!$bb_cfg['bugsnag']['enabled']) { + if (!config()->get('bugsnag.enabled')) { return; } - $bugsnag = Client::make($bb_cfg['bugsnag']['api_key']); + $bugsnag = Client::make(config()->get('bugsnag.api_key')); $this->whoops->pushHandler(function ($e) use ($bugsnag) { $bugsnag->notifyException($e); }); @@ -86,9 +84,7 @@ class Dev */ private function getTelegramSender(): void { - global $bb_cfg; - - if (!$bb_cfg['telegram_sender']['enabled']) { + if (!config()->get('telegram_sender.enabled')) { return; } @@ -96,7 +92,7 @@ class Dev $telegramSender->loggerOnly(true); $telegramSender->setLogger((new Logger( APP_NAME, - [(new TelegramHandler($bb_cfg['telegram_sender']['token'], (int)$bb_cfg['telegram_sender']['chat_id'], timeout: (int)$bb_cfg['telegram_sender']['timeout'])) + [(new TelegramHandler(config()->get('telegram_sender.token'), (int)config()->get('telegram_sender.chat_id'), timeout: (int)config()->get('telegram_sender.timeout'))) ->setFormatter(new TelegramFormatter())] ))); $this->whoops->pushHandler($telegramSender); @@ -109,13 +105,11 @@ class Dev */ private function getWhoopsOnPage(): void { - global $bb_cfg; - /** * Show errors on page */ $prettyPageHandler = new PrettyPageHandler(); - foreach ($bb_cfg['whoops']['blacklist'] as $key => $secrets) { + foreach (config()->get('whoops.blacklist', []) as $key => $secrets) { foreach ($secrets as $secret) { $prettyPageHandler->blacklist($key, $secret); } @@ -163,10 +157,8 @@ class Dev */ private function getWhoopsPlaceholder(): void { - global $bb_cfg; - - $this->whoops->pushHandler(function ($e) use ($bb_cfg) { - echo $bb_cfg['whoops']['error_message']; + $this->whoops->pushHandler(function ($e) { + echo config()->get('whoops.error_message'); echo "
Error: {$e->getMessage()}."; }); } diff --git a/src/Legacy/Atom.php b/src/Legacy/Atom.php index 10b78422e..090f23aee 100644 --- a/src/Legacy/Atom.php +++ b/src/Legacy/Atom.php @@ -25,9 +25,9 @@ class Atom */ public static function update_forum_feed($forum_id, $forum_data) { - global $bb_cfg, $lang, $datastore; + global $lang, $datastore; $sql = null; - $file_path = $bb_cfg['atom']['path'] . '/f/' . $forum_id . '.atom'; + $file_path = config()->get('atom.path') . '/f/' . $forum_id . '.atom'; $select_tor_sql = $join_tor_sql = ''; if (!$forums = $datastore->get('cat_forums')) { @@ -37,7 +37,7 @@ class Atom $not_forums_id = $forums['not_auth_forums']['guest_view']; if ($forum_id == 0) { - $forum_data['forum_name'] = $lang['ATOM_GLOBAL_FEED'] ?? $bb_cfg['server_name']; + $forum_data['forum_name'] = $lang['ATOM_GLOBAL_FEED'] ?? config()->get('server_name'); } if ($forum_id > 0 && $forum_data['allow_reg_tracker']) { $select_tor_sql = ', tor.size AS tor_size, tor.tor_status, tor.attach_id'; @@ -93,7 +93,7 @@ class Atom } } if (isset($topic['tor_status'])) { - if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) { + if (isset(config()->get('tor_frozen')[$topic['tor_status']])) { continue; } } @@ -120,8 +120,8 @@ class Atom */ public static function update_user_feed($user_id, $username) { - global $bb_cfg; - $file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom'; + global $lang, $datastore; + $file_path = config()->get('atom.path') . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom'; $sql = " SELECT t.topic_id, t.topic_title, t.topic_status, @@ -149,7 +149,7 @@ class Atom } } if (isset($topic['tor_status'])) { - if (isset($bb_cfg['tor_frozen'][$topic['tor_status']])) { + if (isset(config()->get('tor_frozen')[$topic['tor_status']])) { continue; } } @@ -179,7 +179,7 @@ class Atom */ private static function create_atom($file_path, $mode, $id, $title, $topics) { - global $bb_cfg, $lang, $wordCensor; + global $lang, $wordCensor; $date = null; $time = null; $dir = \dirname($file_path); @@ -233,13 +233,13 @@ class Atom $atom .= " \n"; $atom .= " " . $date . "T$time+00:00\n"; $atom .= " tag:rto.feed," . $date . ":/t/$topic_id\n"; - if ($bb_cfg['atom']['direct_down'] && isset($topic['attach_id'])) { + if (config()->get('atom.direct_down') && isset($topic['attach_id'])) { $atom .= " \n"; } else { $atom .= " \n"; } - if ($bb_cfg['atom']['direct_view']) { + if (config()->get('atom.direct_view')) { $atom .= " " . $topic['post_html'] . "\n\nNews URL: " . FULL_URL . TOPIC_URL . $topic_id . "\n"; } diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index b1a6a6713..f6a424b55 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -111,7 +111,7 @@ class User */ public function session_start(array $cfg = []) { - global $bb_cfg, $lang; + global $lang; $update_sessions_table = false; $this->cfg = array_merge($this->cfg, $cfg); @@ -130,7 +130,7 @@ class User if ($session_id) { $SQL['WHERE'][] = "s.session_id = '$session_id'"; - if ($bb_cfg['torhelp_enabled']) { + if (config()->get('torhelp_enabled')) { $SQL['SELECT'][] = "th.topic_id_csv AS torhelp"; $SQL['LEFT JOIN'][] = BB_BT_TORHELP . " th ON(u.user_id = th.user_id)"; } @@ -146,7 +146,7 @@ class User if (!$this->data = Sessions::cache_get_userdata($userdata_cache_id)) { $this->data = DB()->fetch_row($SQL); - if ($this->data && (TIMENOW - $this->data['session_time']) > $bb_cfg['session_update_intrv']) { + if ($this->data && (TIMENOW - $this->data['session_time']) > config()->get('session_update_intrv')) { $this->data['session_time'] = TIMENOW; $update_sessions_table = true; } @@ -187,7 +187,7 @@ class User // using the cookie user_id if available to pull basic user prefs. if (!$this->data) { $login = false; - $user_id = ($bb_cfg['allow_autologin'] && $this->sessiondata['uk'] && $this->sessiondata['uid']) ? $this->sessiondata['uid'] : GUEST_UID; + $user_id = (config()->get('allow_autologin') && $this->sessiondata['uk'] && $this->sessiondata['uid']) ? $this->sessiondata['uid'] : GUEST_UID; if ($userdata = get_userdata((int)$user_id, false, true)) { if ($userdata['user_id'] != GUEST_UID && $userdata['user_active']) { @@ -208,7 +208,7 @@ class User define('IS_MOD', !IS_GUEST && (int)$this->data['user_level'] === MOD); define('IS_GROUP_MEMBER', !IS_GUEST && (int)$this->data['user_level'] === GROUP_MEMBER); define('IS_USER', !IS_GUEST && (int)$this->data['user_level'] === USER); - define('IS_SUPER_ADMIN', IS_ADMIN && isset($bb_cfg['super_admins'][$this->data['user_id']])); + define('IS_SUPER_ADMIN', IS_ADMIN && isset(config()->get('super_admins')[$this->data['user_id']])); define('IS_AM', IS_ADMIN || IS_MOD); $this->set_shortcuts(); @@ -301,7 +301,7 @@ class User $this->data['user_lastvisit'] = $last_visit; } - if (!empty($_POST['autologin']) && $bb_cfg['allow_autologin']) { + if (!empty($_POST['autologin']) && config()->get('allow_autologin')) { if (!$auto_created) { $this->verify_autologin_id($this->data, true, true); } @@ -486,10 +486,10 @@ class User } } } else { - if (!isset($bb_cfg['dbg_users'][$this->data['user_id']]) && DBG_USER) { + if (!isset(config()->get('dbg_users')[$this->data['user_id']]) && DBG_USER) { bb_setcookie(COOKIE_DBG, null); - } elseif (isset($bb_cfg['dbg_users'][$this->data['user_id']]) && !DBG_USER) { - bb_setcookie(COOKIE_DBG, hash('xxh128', $bb_cfg['dbg_users'][$this->data['user_id']]), COOKIE_SESSION); + } elseif (isset(config()->get('dbg_users')[$this->data['user_id']]) && !DBG_USER) { + bb_setcookie(COOKIE_DBG, hash('xxh128', config()->get('dbg_users')[$this->data['user_id']]), COOKIE_SESSION); } // Unset sql debug cookies if SQL_DEBUG is disabled or DBG_USER cookie not present @@ -522,8 +522,6 @@ class User */ public function verify_autologin_id($userdata, bool $expire_check = false, bool $create_new = true): bool|string { - global $bb_cfg; - $autologin_id = $userdata['autologin_id']; if ($expire_check) { @@ -531,8 +529,8 @@ class User return $this->create_autologin_id($userdata); } - if ($autologin_id && $userdata['user_session_time'] && $bb_cfg['max_autologin_time']) { - if (TIMENOW - $userdata['user_session_time'] > $bb_cfg['max_autologin_time'] * 86400) { + if ($autologin_id && $userdata['user_session_time'] && config()->get('max_autologin_time')) { + if (TIMENOW - $userdata['user_session_time'] > config()->get('max_autologin_time') * 86400) { return $this->create_autologin_id($userdata, $create_new); } } @@ -584,39 +582,39 @@ class User */ public function init_userprefs() { - global $bb_cfg, $theme, $source_lang, $DeltaTime; + global $theme, $source_lang, $DeltaTime; if (defined('LANG_DIR')) { return; } // prevent multiple calling // Apply browser language - if ($bb_cfg['auto_language_detection'] && IS_GUEST && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + if (config()->get('auto_language_detection') && IS_GUEST && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $http_accept_language = locale_get_primary_language(locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE'])); - if (isset($bb_cfg['lang'][$http_accept_language])) { - $bb_cfg['default_lang'] = $http_accept_language; + if (isset(config()->get('lang')[$http_accept_language])) { + config()->set('default_lang', $http_accept_language); } } - define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); + define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . config()->get('default_lang') . '/'); define('SOURCE_LANG_DIR', LANG_ROOT_DIR . '/source/'); if ($this->data['user_id'] != GUEST_UID) { if (IN_DEMO_MODE && isset($_COOKIE['user_lang'])) { $this->data['user_lang'] = $_COOKIE['user_lang']; } - if ($this->data['user_lang'] && $this->data['user_lang'] != $bb_cfg['default_lang']) { - $bb_cfg['default_lang'] = basename($this->data['user_lang']); - define('LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); + if ($this->data['user_lang'] && $this->data['user_lang'] != config()->get('default_lang')) { + config()->set('default_lang', basename($this->data['user_lang'])); + define('LANG_DIR', LANG_ROOT_DIR . '/' . config()->get('default_lang') . '/'); } if (isset($this->data['user_timezone'])) { - $bb_cfg['board_timezone'] = $this->data['user_timezone']; + config()->set('board_timezone', $this->data['user_timezone']); } } - $this->data['user_lang'] = $bb_cfg['default_lang']; - $this->data['user_timezone'] = $bb_cfg['board_timezone']; + $this->data['user_lang'] = config()->get('default_lang'); + $this->data['user_timezone'] = config()->get('board_timezone'); if (!defined('LANG_DIR')) { define('LANG_DIR', DEFAULT_LANG_DIR); @@ -631,7 +629,7 @@ class User /** Place user language to the global */ global $lang; require(LANG_DIR . 'main.php'); - setlocale(LC_ALL, $bb_cfg['lang'][$this->data['user_lang']]['locale'] ?? 'en_US.UTF-8'); + setlocale(LC_ALL, config()->get('lang')[$this->data['user_lang']]['locale'] ?? 'en_US.UTF-8'); $lang += $source_lang; $theme = setup_style(); @@ -804,10 +802,8 @@ class User */ public function checkPassword(string $enteredPassword, array $userdata): bool { - global $bb_cfg; - if (password_verify($enteredPassword, $userdata['user_password'])) { - if (password_needs_rehash($userdata['user_password'], $bb_cfg['password_hash_options']['algo'], $bb_cfg['password_hash_options']['options'])) { + if (password_needs_rehash($userdata['user_password'], config()->get('password_hash_options.algo'), config()->get('password_hash_options.options'))) { // Update password_hash DB()->query("UPDATE " . BB_USERS . " SET user_password = '" . $this->password_hash($enteredPassword) . "' WHERE user_id = '" . $userdata['user_id'] . "' AND user_password = '" . $userdata['user_password'] . "' LIMIT 1"); } @@ -833,8 +829,6 @@ class User */ public function password_hash(string $enteredPassword): string { - global $bb_cfg; - - return password_hash($enteredPassword, $bb_cfg['password_hash_options']['algo'], $bb_cfg['password_hash_options']['options']); + return password_hash($enteredPassword, config()->get('password_hash_options.algo'), config()->get('password_hash_options.options')); } } diff --git a/src/Legacy/Poll.php b/src/Legacy/Poll.php index c0d70b7bc..a4ece7cfe 100644 --- a/src/Legacy/Poll.php +++ b/src/Legacy/Poll.php @@ -21,8 +21,7 @@ class Poll public function __construct() { - global $bb_cfg; - $this->max_votes = $bb_cfg['max_poll_options']; + $this->max_votes = config()->get('max_poll_options'); } /** @@ -162,7 +161,6 @@ class Poll */ public static function pollIsActive(array $t_data): bool { - global $bb_cfg; - return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400); + return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - config()->get('poll_max_days') * 86400); } } diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index 1c509d3bd..a9f8ab406 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -99,7 +99,7 @@ class Template */ public function __construct($root = '.') { - global $bb_cfg, $lang; + global $lang; // setting pointer "vars" $this->vars = &$this->_tpldata['.'][0]; @@ -108,7 +108,7 @@ class Template $this->root = $root; $this->tpl = basename($root); $this->lang =& $lang; - $this->use_cache = $bb_cfg['xs_use_cache']; + $this->use_cache = config()->get('xs_use_cache'); // Check template exists if (!is_dir($this->root)) { @@ -987,11 +987,9 @@ class Template public function xs_startup() { - global $bb_cfg; - // adding language variable (eg: "english" or "german") // can be used to make truly multi-lingual templates - $this->vars['LANG'] ??= $bb_cfg['default_lang']; + $this->vars['LANG'] ??= config()->get('default_lang'); // adding current template $tpl = $this->root . '/'; if (str_starts_with($tpl, './')) { diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 791ff30bd..e0a905433 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -97,7 +97,7 @@ class Torrent */ public static function tracker_unregister($attach_id, $mode = '') { - global $lang, $bb_cfg, $log_action; + global $lang, $log_action; $attach_id = (int)$attach_id; $post_id = $topic_id = $topic_title = $forum_id = null; @@ -132,7 +132,7 @@ class Torrent } // Unset DL-Type for topic - if ($bb_cfg['bt_unset_dltype_on_tor_unreg'] && $topic_id) { + if (config()->get('bt_unset_dltype_on_tor_unreg') && $topic_id) { $sql = "UPDATE " . BB_TOPICS . " SET topic_dl_type = " . TOPIC_DL_TYPE_NORMAL . " WHERE topic_id = $topic_id"; if (!$result = DB()->sql_query($sql)) { @@ -148,7 +148,7 @@ class Torrent } // TorrServer integration - if ($bb_cfg['torr_server']['enabled']) { + if (config()->get('torr_server.enabled')) { $torrServer = new TorrServerAPI(); $torrServer->removeM3U($attach_id); } @@ -327,19 +327,19 @@ class Torrent self::torrent_error_exit(htmlCHR("{$lang['TORFILE_INVALID']}: {$e->getMessage()}")); } - if ($bb_cfg['bt_disable_dht']) { + if (config()->get('bt_disable_dht')) { $tor['info']['private'] = (int)1; $fp = fopen($filename, 'wb+'); fwrite($fp, Bencode::encode($tor)); fclose($fp); } - if ($bb_cfg['bt_check_announce_url']) { + if (config()->get('bt_check_announce_url')) { $announce_urls = []; include INC_DIR . '/torrent_announce_urls.php'; $ann = $tor['announce'] ?? ''; - $announce_urls['main_url'] = $bb_cfg['bt_announce_url']; + $announce_urls['main_url'] = config()->get('bt_announce_url'); if (!$ann || !in_array($ann, $announce_urls)) { $msg = sprintf($lang['INVALID_ANN_URL'], htmlspecialchars($ann), $announce_urls['main_url']); @@ -365,11 +365,11 @@ class Torrent $bt_v1 = true; } - if ($bb_cfg['tracker']['disabled_v1_torrents'] && isset($bt_v1) && !isset($bt_v2)) { + if (config()->get('tracker.disabled_v1_torrents') && isset($bt_v1) && !isset($bt_v2)) { self::torrent_error_exit($lang['BT_V1_ONLY_DISALLOWED']); } - if ($bb_cfg['tracker']['disabled_v2_torrents'] && !isset($bt_v1) && isset($bt_v2)) { + if (config()->get('tracker.disabled_v2_torrents') && !isset($bt_v1) && isset($bt_v2)) { self::torrent_error_exit($lang['BT_V2_ONLY_DISALLOWED']); } @@ -388,7 +388,7 @@ class Torrent } // TorrServer integration - if ($bb_cfg['torr_server']['enabled']) { + if (config()->get('torr_server.enabled')) { $torrServer = new TorrServerAPI(); if ($torrServer->uploadTorrent($filename, $torrent['mimetype'])) { $torrServer->saveM3U($attach_id, bin2hex($info_hash ?? $info_hash_v2)); @@ -467,7 +467,7 @@ class Torrent } // set DL-Type for topic - if ($bb_cfg['bt_set_dltype_on_tor_reg']) { + if (config()->get('bt_set_dltype_on_tor_reg')) { $sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = $topic_id"; if (!$result = DB()->sql_query($sql)) { @@ -475,7 +475,7 @@ class Torrent } } - if ($bb_cfg['tracker']['tor_topic_up']) { + if (config()->get('tracker.tor_topic_up')) { DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id"); } @@ -494,9 +494,9 @@ class Torrent */ public static function send_torrent_with_passkey($filename) { - global $attachment, $auth_pages, $userdata, $bb_cfg, $lang; + global $attachment, $auth_pages, $userdata, $lang; - if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename)) { + if (!config()->get('bt_add_auth_key') || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename)) { return; } @@ -504,7 +504,7 @@ class Torrent $user_id = $userdata['user_id']; $attach_id = $attachment['attach_id']; - if (!$passkey_key = $bb_cfg['passkey_key']) { + if (!$passkey_key = config()->get('passkey_key')) { bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])'); } @@ -543,7 +543,7 @@ class Torrent } // Ratio limits - $min_ratio = $bb_cfg['bt_min_ratio_allow_dl_tor']; + $min_ratio = config()->get('bt_min_ratio_allow_dl_tor'); if ($min_ratio && $user_id != $poster_id && ($user_ratio = get_bt_ratio($bt_userdata)) !== null) { if ($user_ratio < $min_ratio && $post_id) { @@ -570,15 +570,15 @@ class Torrent } // Get tracker announcer - $announce_url = $bb_cfg['bt_announce_url'] . "?$passkey_key=$passkey_val"; + $announce_url = config()->get('bt_announce_url') . "?$passkey_key=$passkey_val"; // Replace original announce url with tracker default - if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) { + if (config()->get('bt_replace_ann_url') || !isset($tor['announce'])) { $tor['announce'] = $announce_url; } // Creating / cleaning announce-list - if (!isset($tor['announce-list']) || !is_array($tor['announce-list']) || $bb_cfg['bt_del_addit_ann_urls'] || $bb_cfg['bt_disable_dht']) { + if (!isset($tor['announce-list']) || !is_array($tor['announce-list']) || config()->get('bt_del_addit_ann_urls') || config()->get('bt_disable_dht')) { $tor['announce-list'] = []; } @@ -597,15 +597,15 @@ class Torrent } // Add retracker - if (!empty($bb_cfg['tracker']['retracker_host']) && $bb_cfg['tracker']['retracker']) { + if (!empty(config()->get('tracker.retracker_host')) && config()->get('tracker.retracker')) { if (bf($userdata['user_opt'], 'user_opt', 'user_retracker') || IS_GUEST) { - $tor['announce-list'] = array_merge($tor['announce-list'], [[$bb_cfg['tracker']['retracker_host']]]); + $tor['announce-list'] = array_merge($tor['announce-list'], [[config()->get('tracker.retracker_host')]]); } } // Adding tracker announcer to announce-list if (!empty($tor['announce-list'])) { - if ($bb_cfg['bt_replace_ann_url']) { + if (config()->get('bt_replace_ann_url')) { // Adding tracker announcer as main announcer (At start) array_unshift($tor['announce-list'], [$announce_url]); } else { @@ -629,7 +629,7 @@ class Torrent } // Add publisher & topic url - $publisher_name = $bb_cfg['server_name']; + $publisher_name = config()->get('server_name'); $publisher_url = make_url(TOPIC_URL . $topic_id); $tor['publisher'] = (string)$publisher_name; @@ -644,10 +644,10 @@ class Torrent // Send torrent $output = Bencode::encode($tor); - if ($bb_cfg['tracker']['use_old_torrent_name_format']) { - $dl_fname = '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.' . TORRENT_EXT; + if (config()->get('tracker.use_old_torrent_name_format')) { + $dl_fname = '[' . config()->get('server_name') . '].t' . $topic_id . '.' . TORRENT_EXT; } else { - $dl_fname = html_ent_decode($topic_title) . ' [' . $bb_cfg['server_name'] . '-' . $topic_id . ']' . '.' . TORRENT_EXT; + $dl_fname = html_ent_decode($topic_title) . ' [' . config()->get('server_name') . '-' . $topic_id . ']' . '.' . TORRENT_EXT; } if (!empty($_COOKIE['explain'])) { diff --git a/src/Legacy/TorrentFileList.php b/src/Legacy/TorrentFileList.php index fd600d015..b3fcaeccc 100644 --- a/src/Legacy/TorrentFileList.php +++ b/src/Legacy/TorrentFileList.php @@ -41,12 +41,12 @@ class TorrentFileList */ public function get_filelist() { - global $bb_cfg, $html; + global $html; $info = &$this->tor_decoded['info']; if (isset($info['meta version'], $info['file tree'])) { //v2 if (($info['meta version']) === 2 && is_array($info['file tree'])) { - return $this->fileTreeList($info['file tree'], $info['name'] ?? '', $bb_cfg['flist_timeout']); + return $this->fileTreeList($info['file tree'], $info['name'] ?? '', config()->get('flist_timeout')); } } @@ -71,8 +71,6 @@ class TorrentFileList */ private function build_filelist_array() { - global $bb_cfg; - $info = &$this->tor_decoded['info']; if (isset($info['name.utf-8'])) { @@ -95,7 +93,7 @@ class TorrentFileList continue; } - $structure = array_deep($f['path'], 'clean_tor_dirname', timeout: $bb_cfg['flist_timeout']); + $structure = array_deep($f['path'], 'clean_tor_dirname', timeout: config()->get('flist_timeout')); if (isset($structure['timeout'])) { bb_die("Timeout, too many nested files/directories for file listing, aborting after \n{$structure['recs']} recursive calls.\nNesting level: " . count($info['files'], COUNT_RECURSIVE)); } diff --git a/src/Sessions.php b/src/Sessions.php index dca5a1009..97e0e773a 100644 --- a/src/Sessions.php +++ b/src/Sessions.php @@ -51,14 +51,12 @@ class Sessions */ public static function cache_set_userdata(?array $userdata, bool $force = false): bool { - global $bb_cfg; - if (!$userdata || (self::ignore_cached_userdata() && !$force)) { return false; } $id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id']; - return CACHE('session_cache')->set($id, $userdata, $bb_cfg['session_update_intrv']); + return CACHE('session_cache')->set($id, $userdata, config()->get('session_update_intrv')); } /** diff --git a/src/Sitemap.php b/src/Sitemap.php index f3fc70538..75e059ce5 100644 --- a/src/Sitemap.php +++ b/src/Sitemap.php @@ -99,13 +99,11 @@ class Sitemap */ private function getStaticUrls(): array { - global $bb_cfg; - $staticUrls = []; - if (isset($bb_cfg['static_sitemap'])) { + if (config()->has('static_sitemap')) { /** @var array $urls разбиваем строку по переносам */ - $urls = explode("\n", $bb_cfg['static_sitemap']); + $urls = explode("\n", config()->get('static_sitemap')); foreach ($urls as $url) { /** @var string $url проверяем что адрес валиден и с указанными протоколом */ if (filter_var(trim($url), FILTER_VALIDATE_URL)) { diff --git a/src/TorrServerAPI.php b/src/TorrServerAPI.php index 3764c56e6..59a7cef32 100644 --- a/src/TorrServerAPI.php +++ b/src/TorrServerAPI.php @@ -52,9 +52,7 @@ class TorrServerAPI */ public function __construct() { - global $bb_cfg; - - $this->url = $bb_cfg['torr_server']['url'] . '/'; + $this->url = config()->get('torr_server.url') . '/'; } /** @@ -66,15 +64,13 @@ class TorrServerAPI */ public function uploadTorrent(string $path, string $mimetype): bool { - global $bb_cfg; - // Check mimetype if ($mimetype !== TORRENT_MIMETYPE) { return false; } $curl = new Curl(); - $curl->setTimeout($bb_cfg['torr_server']['timeout']); + $curl->setTimeout(config()->get('torr_server.timeout')); $curl->setHeaders([ 'Accept' => 'application/json', @@ -101,8 +97,6 @@ class TorrServerAPI */ public function saveM3U(string|int $attach_id, string $hash): string { - global $bb_cfg; - $m3uFile = get_attachments_dir() . '/' . self::M3U['prefix'] . $attach_id . self::M3U['extension']; // Make stream call to store torrent in memory @@ -115,7 +109,7 @@ class TorrServerAPI } $curl = new Curl(); - $curl->setTimeout($bb_cfg['torr_server']['timeout']); + $curl->setTimeout(config()->get('torr_server.timeout')); $curl->setHeader('Accept', 'audio/x-mpegurl'); $curl->get($this->url . $this->endpoints['playlist'], ['hash' => $hash]); @@ -197,8 +191,6 @@ class TorrServerAPI */ public function getFfpInfo(string $hash, int $index, int|string $attach_id): mixed { - global $bb_cfg; - if (!$response = CACHE('tr_cache')->get("ffprobe_m3u_$attach_id")) { $response = new stdClass(); } @@ -214,7 +206,7 @@ class TorrServerAPI } $curl = new Curl(); - $curl->setTimeout($bb_cfg['torr_server']['timeout']); + $curl->setTimeout(config()->get('torr_server.timeout')); $curl->setHeader('Accept', 'application/json'); $curl->get($this->url . $this->endpoints['ffprobe'] . '/' . $hash . '/' . $index); @@ -238,10 +230,8 @@ class TorrServerAPI */ private function getStream(string $hash): bool { - global $bb_cfg; - $curl = new Curl(); - $curl->setTimeout($bb_cfg['torr_server']['timeout']); + $curl->setTimeout(config()->get('torr_server.timeout')); $curl->setHeader('Accept', 'application/octet-stream'); $curl->get($this->url . $this->endpoints['stream'], ['link' => $hash]); diff --git a/src/Validate.php b/src/Validate.php index 9aee03998..b3d63a4f2 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -99,7 +99,7 @@ class Validate */ public static function email(string $email, bool $check_taken = true) { - global $lang, $userdata, $bb_cfg; + global $lang, $userdata; // Check for empty if (empty($email)) { @@ -117,7 +117,7 @@ class Validate } // Extended email validation - if ($bb_cfg['extended_email_validation']) { + if (config()->get('extended_email_validation')) { $validator = new EmailValidator(); $multipleValidations = new MultipleValidationWithAnd([ @@ -157,7 +157,7 @@ class Validate */ public static function password(string $password, string $password_confirm) { - global $lang, $bb_cfg; + global $lang; // Check for empty if (empty($password) || empty($password_confirm)) { @@ -178,26 +178,26 @@ class Validate } // Symbols check - if ($bb_cfg['password_symbols']) { + if (config()->get('password_symbols')) { // Numbers - if ($bb_cfg['password_symbols']['nums']) { + if (config()->get('password_symbols.nums')) { if (!StringHelper::isContainsNums($password)) { return $lang['CHOOSE_PASS_ERR_NUM']; } } // Letters - if ($bb_cfg['password_symbols']['letters']['lowercase']) { + if (config()->get('password_symbols.letters.lowercase')) { if (!StringHelper::isContainsLetters($password)) { return $lang['CHOOSE_PASS_ERR_LETTER']; } } - if ($bb_cfg['password_symbols']['letters']['uppercase']) { + if (config()->get('password_symbols.letters.uppercase')) { if (!StringHelper::isContainsLetters($password, true)) { return $lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE']; } } // Spec symbols - if ($bb_cfg['password_symbols']['spec_symbols']) { + if (config()->get('password_symbols.spec_symbols')) { if (!StringHelper::isContainsSpecSymbols($password)) { return $lang['CHOOSE_PASS_ERR_SPEC_SYMBOL']; } diff --git a/viewforum.php b/viewforum.php index d77d1ed99..d1cfb460f 100644 --- a/viewforum.php +++ b/viewforum.php @@ -121,7 +121,7 @@ if ($mark_read && !IS_GUEST) { } // Subforums -$show_subforums = $bb_cfg['sf_on_first_page_only'] ? !$start : true; +$show_subforums = config()->get('sf_on_first_page_only') ? !$start : true; if (!$forums = $datastore->get('cat_forums')) { $datastore->update('cat_forums'); @@ -179,7 +179,7 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) $last_post_user = profile_url(['username' => $sf_data['sf_last_username'], 'user_id' => $sf_data['sf_last_user_id'], 'user_rank' => $sf_data['user_rank']]); if ($sf_data['forum_last_post_id']) { - $last_post = bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']); + $last_post = bb_date($sf_data['topic_last_post_time'], config()->get('last_post_date_format')); $last_post .= "
$last_post_user"; $last_post .= 'latest'; } @@ -203,7 +203,7 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums']) 'LAST_TOPIC_ID' => $sf_data['last_topic_id'], 'LAST_TOPIC_TIP' => $sf_data['last_topic_title'], 'LAST_TOPIC_TITLE' => str_short($sf_data['last_topic_title'], $last_topic_max_len), - 'LAST_POST_TIME' => bb_date($sf_data['topic_last_post_time'], $bb_cfg['last_post_date_format']), + 'LAST_POST_TIME' => bb_date($sf_data['topic_last_post_time'], config()->get('last_post_date_format')), 'LAST_POST_ID' => $sf_data['forum_last_post_id'], 'LAST_POST_USER' => $last_post_user, 'ICON_LATEST_REPLY' => $images['icon_latest_reply'] @@ -217,16 +217,16 @@ unset($rowset); $datastore->rm('cat_forums'); // Topics per page -$topics_per_page = $bb_cfg['topics_per_page']; +$topics_per_page = config()->get('topics_per_page'); $select_tpp = ''; if ($is_auth['auth_mod']) { - if ($req_tpp = abs((int)(@$_REQUEST['tpp'])) and in_array($req_tpp, $bb_cfg['allowed_topics_per_page'])) { + if ($req_tpp = abs((int)(@$_REQUEST['tpp'])) and in_array($req_tpp, config()->get('allowed_topics_per_page'))) { $topics_per_page = $req_tpp; } $select_tpp = []; - foreach ($bb_cfg['allowed_topics_per_page'] as $tpp) { + foreach (config()->get('allowed_topics_per_page') as $tpp) { $select_tpp[$tpp] = $tpp; } } @@ -282,7 +282,7 @@ $order_sql = "ORDER BY t.topic_type DESC, $sort_method $order_method"; $limit_topics_time_sql = ($topic_days) ? "AND t.topic_last_post_time > " . (TIMENOW - 86400 * $topic_days) : ''; $select_tor_sql = $join_tor_sql = ''; -$join_dl = ($bb_cfg['show_dl_status_in_forum'] && !IS_GUEST); +$join_dl = (config()->get('show_dl_status_in_forum') && !IS_GUEST); $where_tor_sql = ''; if ($forum_data['allow_reg_tracker']) { @@ -423,7 +423,7 @@ foreach ($topic_rowset as $topic) { $topic_id = $topic['topic_id']; $moved = ($topic['topic_status'] == TOPIC_MOVED); $replies = $topic['topic_replies']; - $t_hot = ($replies >= $bb_cfg['hot_threshold']); + $t_hot = ($replies >= config()->get('hot_threshold')); $t_type = $topic['topic_type']; $separator = ''; $is_unread = is_unread($topic['topic_last_post_time'], $topic_id, $forum_id); @@ -449,14 +449,14 @@ foreach ($topic_rowset as $topic) { 'TOPICS_SEPARATOR' => $separator, 'IS_UNREAD' => $is_unread, 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), - 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, $bb_cfg['posts_per_page']), + 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $replies, config()->get('posts_per_page')), 'REPLIES' => $moved ? '' : $replies, 'VIEWS' => $moved ? '' : $topic['topic_views'], 'TOR_STALED' => ($forum_data['allow_reg_tracker'] && !($t_type == POST_ANNOUNCE || $t_type == POST_STICKY || $topic['tor_size'])), - 'TOR_FROZEN' => isset($topic['tor_status']) ? ((!IS_AM) ? isset($bb_cfg['tor_frozen'][$topic['tor_status']]) : '') : '', + 'TOR_FROZEN' => isset($topic['tor_status']) ? ((!IS_AM) ? isset(config()->get('tor_frozen')[$topic['tor_status']]) : '') : '', 'TOR_TYPE' => isset($topic['tor_type']) ? is_gold($topic['tor_type']) : '', - 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? $bb_cfg['tor_icons'][$topic['tor_status']] : '', + 'TOR_STATUS_ICON' => isset($topic['tor_status']) ? config()->get('tor_icons')[$topic['tor_status']] : '', 'TOR_STATUS_TEXT' => isset($topic['tor_status']) ? $lang['TOR_STATUS_NAME'][$topic['tor_status']] : '', 'ATTACH' => $topic['topic_attachment'] ?? false, @@ -468,7 +468,7 @@ foreach ($topic_rowset as $topic) { 'TOPIC_AUTHOR' => profile_url(['username' => str_short($topic['first_username'], 15), 'user_id' => $topic['first_user_id'], 'user_rank' => $topic['first_user_rank']]), 'LAST_POSTER' => profile_url(['username' => str_short($topic['last_username'], 15), 'user_id' => $topic['last_user_id'], 'user_rank' => $topic['last_user_rank']]), - 'LAST_POST_TIME' => bb_date($topic['topic_last_post_time']), + 'LAST_POST_TIME' => bb_date($topic['topic_last_post_time'], config()->get('last_post_date_format')), 'LAST_POST_ID' => $topic['topic_last_post_id'], ]); @@ -498,7 +498,7 @@ $pg_url .= $topic_days ? "&topicdays=$topic_days" : ''; $pg_url .= $sort_value ? "&sort=$sort_value" : ''; $pg_url .= $order_value ? "&order=$order_value" : ''; $pg_url .= $moderation ? "&mod=1" : ''; -$pg_url .= ($topics_per_page != $bb_cfg['topics_per_page']) ? "&tpp=$topics_per_page" : ''; +$pg_url .= ($topics_per_page != config()->get('topics_per_page')) ? "&tpp=$topics_per_page" : ''; if ($found_topics) { generate_pagination($pg_url, $forum_topics, $topics_per_page, $start);