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'] . '