From 8907dbf9912c2ddb3177779962ce54064deecd8f Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Tue, 17 Jun 2025 18:07:31 +0400 Subject: [PATCH 01/46] Update composer.lock and improve SQL queries in online_userlist.php and tr_cleanup_and_dlstat.php (#1949) - Updated plugin API version in composer.lock from 2.3.0 to 2.6.0. - Modified SQL queries in online_userlist.php to use MAX() for session data and adjusted GROUP BY clause for better accuracy. - Enhanced SQL logic in tr_cleanup_and_dlstat.php to utilize MAX() for determining the releaser status. --- composer.lock | 4 ++-- library/includes/cron/jobs/tr_cleanup_and_dlstat.php | 2 +- library/includes/online_userlist.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index a3fa490ba..3721bdaa1 100644 --- a/composer.lock +++ b/composer.lock @@ -3746,6 +3746,6 @@ "platform": { "php": ">=8.1" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php index a0d7efd25..9d633bbed 100644 --- a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php +++ b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php @@ -39,7 +39,7 @@ if ($bb_cfg['tracker']['update_dlstat']) { INSERT INTO " . NEW_BB_BT_LAST_TORSTAT . " (topic_id, user_id, dl_status, up_add, down_add, release_add, speed_up, speed_down) SELECT - topic_id, user_id, IF(releaser, $releaser, seeder), SUM(up_add), SUM(down_add), IF(releaser, SUM(up_add), 0), SUM(speed_up), SUM(speed_down) + topic_id, user_id, IF(MAX(releaser), $releaser, seeder), SUM(up_add), SUM(down_add), IF(MAX(releaser), SUM(up_add), 0), SUM(speed_up), SUM(speed_down) FROM " . BB_BT_TRACKER . " WHERE (up_add != 0 OR down_add != 0) GROUP BY topic_id, user_id diff --git a/library/includes/online_userlist.php b/library/includes/online_userlist.php index ffa0cd2e4..7434f79ea 100644 --- a/library/includes/online_userlist.php +++ b/library/includes/online_userlist.php @@ -36,11 +36,11 @@ $online = $online_short = ['userlist' => '']; $sql = " SELECT u.username, u.user_id, u.user_opt, u.user_rank, u.user_level, - s.session_logged_in, s.session_ip, (s.session_time - s.session_start) AS ses_len, COUNT(s.session_id) AS sessions, COUNT(DISTINCT s.session_ip) AS ips + MAX(s.session_logged_in) AS session_logged_in, MAX(s.session_ip) AS session_ip, MAX(s.session_time - s.session_start) AS ses_len, COUNT(s.session_id) AS sessions, COUNT(DISTINCT s.session_ip) AS ips FROM " . BB_SESSIONS . " s, " . BB_USERS . " u WHERE s.session_time > $time_online AND u.user_id = s.session_user_id - GROUP BY s.session_user_id + GROUP BY s.session_user_id, u.username, u.user_id, u.user_opt, u.user_rank, u.user_level ORDER BY u.username "; From 5842994782dfa62788f8427c55045abdbfb5b8e9 Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Tue, 17 Jun 2025 18:41:45 +0400 Subject: [PATCH 02/46] refactor(config): encapsulate global $bb_cfg array in Config class (#1950) - Create new TorrentPier\Config singleton class with dot notation support - Add config() helper function for global access - Replace direct $bb_cfg access in core files (common.php, Emailer.php, Ajax.php) - Implement methods: get(), set(), has(), all(), getSection(), merge() - Add magic methods for property-like access - Maintain backward compatibility with existing $bb_cfg usage BREAKING CHANGE: None - maintains full backward compatibility --- common.php | 37 ++++++---- src/Ajax.php | 6 +- src/Config.php | 182 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Emailer.php | 45 ++++++------ 4 files changed, 231 insertions(+), 39 deletions(-) create mode 100644 src/Config.php diff --git a/common.php b/common.php index a455a7de2..e62800df7 100644 --- a/common.php +++ b/common.php @@ -86,6 +86,19 @@ if (is_file(BB_PATH . '/library/config.local.php')) { require_once BB_PATH . '/library/config.local.php'; } +// Initialize Config singleton +$config = \TorrentPier\Config::init($bb_cfg); + +/** + * Get the Config instance + * + * @return \TorrentPier\Config + */ +function config(): \TorrentPier\Config +{ + return \TorrentPier\Config::getInstance(); +} + /** * Initialize debug */ @@ -100,16 +113,16 @@ if (APP_ENV === 'local') { /** * Server variables initialize */ -$server_protocol = $bb_cfg['cookie_secure'] ? 'https://' : 'http://'; -$server_port = in_array((int)$bb_cfg['server_port'], [80, 443], true) ? '' : ':' . $bb_cfg['server_port']; -define('FORUM_PATH', $bb_cfg['script_path']); -define('FULL_URL', $server_protocol . $bb_cfg['server_name'] . $server_port . $bb_cfg['script_path']); +$server_protocol = config()->get('cookie_secure') ? 'https://' : 'http://'; +$server_port = in_array((int)config()->get('server_port'), [80, 443], true) ? '' : ':' . config()->get('server_port'); +define('FORUM_PATH', config()->get('script_path')); +define('FULL_URL', $server_protocol . config()->get('server_name') . $server_port . config()->get('script_path')); unset($server_protocol, $server_port); /** * Database */ -$DBS = new TorrentPier\Legacy\Dbs($bb_cfg); +$DBS = new TorrentPier\Legacy\Dbs(config()->all()); function DB(string $db_alias = 'db') { @@ -120,7 +133,7 @@ function DB(string $db_alias = 'db') /** * Cache */ -$CACHES = new TorrentPier\Legacy\Caches($bb_cfg); +$CACHES = new TorrentPier\Legacy\Caches(config()->all()); function CACHE(string $cache_name) { @@ -131,22 +144,22 @@ function CACHE(string $cache_name) /** * Datastore */ -switch ($bb_cfg['datastore_type']) { +switch (config()->get('datastore_type')) { case 'apcu': - $datastore = new TorrentPier\Legacy\Datastore\APCu($bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\APCu(config()->get('cache.prefix')); break; case 'memcached': - $datastore = new TorrentPier\Legacy\Datastore\Memcached($bb_cfg['cache']['memcached'], $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Memcached(config()->get('cache.memcached'), config()->get('cache.prefix')); break; case 'sqlite': - $datastore = new TorrentPier\Legacy\Datastore\Sqlite($bb_cfg['cache']['db_dir'] . 'datastore', $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Sqlite(config()->get('cache.db_dir') . 'datastore', config()->get('cache.prefix')); break; case 'redis': - $datastore = new TorrentPier\Legacy\Datastore\Redis($bb_cfg['cache']['redis'], $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Redis(config()->get('cache.redis'), config()->get('cache.prefix')); break; case 'filecache': default: - $datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\File(config()->get('cache.db_dir') . 'datastore/', config()->get('cache.prefix')); } // Functions diff --git a/src/Ajax.php b/src/Ajax.php index a2f3e6090..a4005ee90 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -68,7 +68,7 @@ class Ajax */ public function exec() { - global $lang, $bb_cfg; + global $lang; // Exit if we already have errors if (!empty($this->response['error_code'])) { @@ -89,8 +89,8 @@ class Ajax } // Exit if board is disabled via ON/OFF trigger or by admin - if ($bb_cfg['board_disable'] || is_file(BB_DISABLED)) { - if ($bb_cfg['board_disable']) { + if (config()->get('board_disable') || is_file(BB_DISABLED)) { + if (config()->get('board_disable')) { $this->ajax_die($lang['BOARD_DISABLE']); } elseif (is_file(BB_DISABLED) && $this->action !== 'manage_admin') { $this->ajax_die($lang['BOARD_DISABLE_CRON']); diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 000000000..2490e94c3 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,182 @@ +config = $config; + } + + /** + * Get the singleton instance of Config + */ + public static function getInstance(array $config = []): Config + { + if (self::$instance === null) { + self::$instance = new self($config); + } + return self::$instance; + } + + /** + * Initialize the config with the global $bb_cfg array + */ + public static function init(array $bb_cfg): Config + { + self::$instance = new self($bb_cfg); + return self::$instance; + } + + /** + * Get a configuration value by key + * Supports dot notation for nested arrays (e.g., 'db.host') + */ + public function get(string $key, mixed $default = null): mixed + { + if (str_contains($key, '.')) { + return $this->getNestedValue($key, $default); + } + + return $this->config[$key] ?? $default; + } + + /** + * Set a configuration value by key + * Supports dot notation for nested arrays + */ + public function set(string $key, mixed $value): void + { + if (str_contains($key, '.')) { + $this->setNestedValue($key, $value); + } else { + $this->config[$key] = $value; + } + } + + /** + * Check if a configuration key exists + * Supports dot notation for nested arrays + */ + public function has(string $key): bool + { + if (str_contains($key, '.')) { + return $this->getNestedValue($key) !== null; + } + + return array_key_exists($key, $this->config); + } + + /** + * Get all configuration values + */ + public function all(): array + { + return $this->config; + } + + /** + * Get a nested value using dot notation + */ + private function getNestedValue(string $key, mixed $default = null): mixed + { + $keys = explode('.', $key); + $value = $this->config; + + foreach ($keys as $k) { + if (!is_array($value) || !array_key_exists($k, $value)) { + return $default; + } + $value = $value[$k]; + } + + return $value; + } + + /** + * Set a nested value using dot notation + */ + private function setNestedValue(string $key, mixed $value): void + { + $keys = explode('.', $key); + $target = &$this->config; + + foreach ($keys as $k) { + if (!isset($target[$k]) || !is_array($target[$k])) { + $target[$k] = []; + } + $target = &$target[$k]; + } + + $target = $value; + } + + /** + * Merge additional configuration values + */ + public function merge(array $config): void + { + $this->config = array_merge_recursive($this->config, $config); + } + + /** + * Get a section of the configuration + */ + public function getSection(string $section): array + { + return $this->config[$section] ?? []; + } + + /** + * Magic method to allow property access + */ + public function __get(string $key): mixed + { + return $this->get($key); + } + + /** + * Magic method to allow property setting + */ + public function __set(string $key, mixed $value): void + { + $this->set($key, $value); + } + + /** + * Magic method to check if property exists + */ + public function __isset(string $key): bool + { + return $this->has($key); + } + + /** + * Prevent cloning of the singleton instance + */ + private function __clone() {} + + /** + * Prevent unserialization of the singleton instance + */ + public function __wakeup() + { + throw new \Exception("Cannot unserialize a singleton."); + } +} \ No newline at end of file diff --git a/src/Emailer.php b/src/Emailer.php index 7330f9405..d31e3716e 100644 --- a/src/Emailer.php +++ b/src/Emailer.php @@ -87,17 +87,15 @@ class Emailer */ public function set_template(string $template_file, string $template_lang = ''): void { - global $bb_cfg; - if (!$template_lang) { - $template_lang = $bb_cfg['default_lang']; + $template_lang = config()->get('default_lang'); } if (empty($this->tpl_msg[$template_lang . $template_file])) { $tpl_file = LANG_ROOT_DIR . '/' . $template_lang . '/email/' . $template_file . '.html'; if (!is_file($tpl_file)) { - $tpl_file = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/email/' . $template_file . '.html'; + $tpl_file = LANG_ROOT_DIR . '/' . config()->get('default_lang') . '/email/' . $template_file . '.html'; if (!is_file($tpl_file)) { throw new Exception('Could not find email template file: ' . $template_file); @@ -125,9 +123,9 @@ class Emailer */ public function send(string $email_format = 'text/plain'): bool { - global $bb_cfg, $lang; + global $lang; - if (!$bb_cfg['emailer']['enabled']) { + if (!config()->get('emailer.enabled')) { return false; } @@ -142,24 +140,25 @@ class Emailer $this->subject = !empty($this->subject) ? $this->subject : $lang['EMAILER_SUBJECT']['EMPTY']; /** Prepare message */ - if ($bb_cfg['emailer']['smtp']['enabled']) { - if (!empty($bb_cfg['emailer']['smtp']['host'])) { - if (empty($bb_cfg['emailer']['smtp']['ssl_type'])) { - $bb_cfg['emailer']['smtp']['ssl_type'] = null; + if (config()->get('emailer.smtp.enabled')) { + if (!empty(config()->get('emailer.smtp.host'))) { + $sslType = config()->get('emailer.smtp.ssl_type'); + if (empty($sslType)) { + $sslType = null; } /** @var EsmtpTransport $transport external SMTP with SSL */ $transport = (new EsmtpTransport( - $bb_cfg['emailer']['smtp']['host'], - $bb_cfg['emailer']['smtp']['port'], - $bb_cfg['emailer']['smtp']['ssl_type'] + config()->get('emailer.smtp.host'), + config()->get('emailer.smtp.port'), + $sslType )) - ->setUsername($bb_cfg['emailer']['smtp']['username']) - ->setPassword($bb_cfg['emailer']['smtp']['password']); + ->setUsername(config()->get('emailer.smtp.username')) + ->setPassword(config()->get('emailer.smtp.password')); } else { $transport = new EsmtpTransport('localhost', 25); } } else { - $transport = new SendmailTransport($bb_cfg['emailer']['sendmail_command']); + $transport = new SendmailTransport(config()->get('emailer.sendmail_command')); } $mailer = new Mailer($transport); @@ -168,9 +167,9 @@ class Emailer $message = (new Email()) ->subject($this->subject) ->to($this->to) - ->from(new Address($bb_cfg['board_email'], $bb_cfg['board_email_sitename'])) - ->returnPath(new Address($bb_cfg['bounce_email'])) - ->replyTo($this->reply ?? new Address($bb_cfg['board_email'])); + ->from(new Address(config()->get('board_email'), config()->get('board_email_sitename'))) + ->returnPath(new Address(config()->get('bounce_email'))) + ->replyTo($this->reply ?? new Address(config()->get('board_email'))); /** * This non-standard header tells compliant autoresponders ("email holiday mode") to not @@ -209,12 +208,10 @@ class Emailer */ public function assign_vars($vars): void { - global $bb_cfg; - $this->vars = array_merge([ - 'BOARD_EMAIL' => $bb_cfg['board_email'], - 'SITENAME' => $bb_cfg['board_email_sitename'], - 'EMAIL_SIG' => !empty($bb_cfg['board_email_sig']) ? "-- \n{$bb_cfg['board_email_sig']}" : '', + 'BOARD_EMAIL' => config()->get('board_email'), + 'SITENAME' => config()->get('board_email_sitename'), + 'EMAIL_SIG' => !empty(config()->get('board_email_sig')) ? "-- \n" . config()->get('board_email_sig') : '', ], $vars); } } From 81bf67c2be85d49e988b7802ca7e9738ff580031 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Tue, 17 Jun 2025 18:14:47 +0300 Subject: [PATCH 03/46] fix(installer): Strip protocol from TP_HOST to keep only hostname (#1952) --- install.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/install.php b/install.php index 009098420..327c0fb5d 100644 --- a/install.php +++ b/install.php @@ -206,6 +206,12 @@ if (is_file(BB_ROOT . '.env')) { $newValue = trim(readline()); if (!empty($newValue) || $key === 'DB_PASSWORD') { + if ($key === 'TP_HOST') { + if (!preg_match('/^https?:\/\//', $newValue)) { + $newValue = 'https://' . $newValue; + } + $newValue = parse_url($newValue, PHP_URL_HOST); + } $line = "$key=$newValue"; $$key = $newValue; } else { From 37a0675adfb02014e7068f4aa82301e29f39eab6 Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Tue, 17 Jun 2025 20:28:14 +0400 Subject: [PATCH 04/46] fix(sql): resolve only_full_group_by compatibility issues in tracker cleanup (#1951) - Replace non-aggregated 'seeder' column with MAX(seeder) in GROUP BY query - Remove ORDER BY clause incompatible with GROUP BY in seeder update query Fixes MySQL 5.7+ strict SQL mode errors in tr_cleanup_and_dlstat cron job. --- library/includes/cron/jobs/tr_cleanup_and_dlstat.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php index 9d633bbed..a0a64251f 100644 --- a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php +++ b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php @@ -39,7 +39,7 @@ if ($bb_cfg['tracker']['update_dlstat']) { INSERT INTO " . NEW_BB_BT_LAST_TORSTAT . " (topic_id, user_id, dl_status, up_add, down_add, release_add, speed_up, speed_down) SELECT - topic_id, user_id, IF(MAX(releaser), $releaser, seeder), SUM(up_add), SUM(down_add), IF(MAX(releaser), SUM(up_add), 0), SUM(speed_up), SUM(speed_down) + topic_id, user_id, IF(MAX(releaser), $releaser, MAX(seeder)), SUM(up_add), SUM(down_add), IF(MAX(releaser), SUM(up_add), 0), SUM(speed_up), SUM(speed_down) FROM " . BB_BT_TRACKER . " WHERE (up_add != 0 OR down_add != 0) GROUP BY topic_id, user_id @@ -61,7 +61,6 @@ DB()->query(" FROM " . BB_BT_TRACKER . " WHERE seeder = 1 GROUP BY topic_id, user_id - ORDER BY update_time DESC "); // Clean peers table From bf9100fbfa74768edb01c62636198a44739d9923 Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Wed, 18 Jun 2025 01:19:49 +0400 Subject: [PATCH 05/46] feat: implement centralized Config class to replace global $bb_cfg array (#1953) * feat: implement centralized Config class to replace global $bb_cfg array - Add singleton Config class with dot notation support for nested configuration - Implement thread-safe configuration access with magic methods (__get, __set, __isset) - Add global config() helper function for convenient access - Support for getSection(), merge(), has(), all() methods with type safety BREAKING CHANGE: While $bb_cfg global array still works for backward compatibility, new code should use config()->get() method with dot notation Updated files: - src/Config.php: New Config singleton class implementation - common.php: Initialize Config singleton and add global helper - src/Emailer.php: Replace $bb_cfg with config()->get() - src/Ajax.php: Replace $bb_cfg with config()->get() - src/Censor.php: Replace $bb_cfg with config()->get() - src/Validate.php: Replace $bb_cfg with config()->get() - src/Dev.php: Replace $bb_cfg with config()->get() - src/Sitemap.php: Replace $bb_cfg with config()->get() - src/TorrServerAPI.php: Replace $bb_cfg with config()->get() - src/Sessions.php: Replace $bb_cfg with config()->get() - src/Legacy/TorrentFileList.php: Replace $bb_cfg with config()->get() - src/Legacy/Poll.php: Replace $bb_cfg with config()->get() - src/Legacy/Torrent.php: Replace $bb_cfg with config()->get() - src/Legacy/Common/User.php: Replace $bb_cfg with config()->get() - src/Legacy/Template.php: Replace $bb_cfg with config()->get() - src/Legacy/Atom.php: Replace $bb_cfg with config()->get() - src/Legacy/Admin/Common.php: Replace $bb_cfg with config()->get() - viewforum.php: Replace $bb_cfg with config()->get() - posting.php: Replace $bb_cfg with config()->get() - dl.php: Replace $bb_cfg with config()->get() - feed.php: Replace $bb_cfg with config()->get() - filelist.php: Replace $bb_cfg with config()->get() - group_edit.php: Replace $bb_cfg with config()->get() - group.php: Replace $bb_cfg with config()->get() - index.php: Replace $bb_cfg with config()->get() - login.php: Replace $bb_cfg with config()->get() - memberlist.php: Replace $bb_cfg with config()->get() - modcp.php: Replace $bb_cfg with config()->get() - playback_m3u.php: Replace $bb_cfg with config()->get() - poll.php: Replace $bb_cfg with config()->get() * refactor: replace $bb_cfg with config() in various admin files - Updated multiple admin files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - common.php - index.php - admin_attach_cp.php - admin_log.php - admin_mass_email.php - admin_sitemap.php - admin_smilies.php - admin_terms.php - admin_user_search.php - admin_words.php - admin/index.php - admin/stats/tracker.php * refactor: update init_bb.php to use config() for configuration management - Replaced the merging of $bb_cfg with a call to config()->merge() for improved clarity and maintainability. - Updated the retrieval of all configuration settings to use config()->all(). This change continues the transition towards a centralized configuration system. * refactor: replace $bb_cfg with config() in various files - Updated multiple files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - privmsg.php - search.php - terms.php - tracker.php - viewtopic.php - bt/announce.php - bt/scrape.php - bt/includes/init_tr.php - library/ajax/*.php - src/Config.php * refactor: replace $bb_cfg with config() in attachment and display files - Updated multiple files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - attachment_mod.php - displaying_torrent.php - functions_delete.php - bbcode.php - functions.php - init_bb.php - online_userlist.php - page_footer.php - page_header.php - torrent_show_dl_list.php - cron jobs (various files) - datastore build files (various files) * refactor: replace $bb_cfg with config() in user control panel files - Updated multiple user control panel files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - bonus.php - email.php - register.php - sendpasswd.php - topic_watch.php - viewprofile.php * refactor: replace $bb_cfg with config() in various legacy files - Updated multiple legacy files to utilize the new Config class for configuration access. - Replaced instances of $bb_cfg with config()->get() for improved maintainability and consistency. - Ensured backward compatibility while transitioning to the new configuration system. Files modified: - sidebar2.html - BBCode.php - LogAction.php - Post.php - Template.php - Torrent.php - Common/User.php - Common/Select.php - Common/Upload.php - Admin/Common.php - tpl_config.php * refactor: remove legacy DOCUMENTATION.md and add UPGRADE_GUIDE.md - Deleted the outdated DOCUMENTATION.md file, which contained legacy configuration information. - Introduced a new UPGRADE_GUIDE.md to assist users in migrating to the new configuration system. - The upgrade guide includes migration strategies, breaking changes, and best practices for using the new Config class. Files modified: - DOCUMENTATION.md (deleted) - UPGRADE_GUIDE.md (new) * refactor: update legacy files to maintain compatibility with bb_cfg deprecation - Added comments in init_bb.php, Template.php, and Cron.php to indicate that bb_cfg is deprecated but retained for compatibility with non-adapted code. - Ensured clarity in documentation for future reference while transitioning to the new configuration system. Files modified: - init_bb.php - Template.php - Cron.php --- UPGRADE_GUIDE.md | 165 ++++++++++++++++++ admin/admin_attach_cp.php | 26 +-- admin/admin_log.php | 2 +- admin/admin_mass_email.php | 4 +- admin/admin_sitemap.php | 2 +- admin/admin_smilies.php | 2 +- admin/admin_terms.php | 6 +- admin/admin_user_search.php | 6 +- admin/admin_words.php | 4 +- admin/index.php | 14 +- admin/stats/tracker.php | 2 +- bt/announce.php | 72 ++++---- bt/includes/init_tr.php | 6 +- bt/scrape.php | 8 +- common.php | 6 +- dl.php | 6 +- feed.php | 12 +- filelist.php | 8 +- group.php | 12 +- group_edit.php | 6 +- index.php | 40 ++--- library/ajax/avatar.php | 2 +- library/ajax/callseed.php | 6 +- library/ajax/change_tor_status.php | 14 +- library/ajax/change_torrent.php | 2 +- library/ajax/edit_group_profile.php | 2 +- library/ajax/edit_user_profile.php | 14 +- library/ajax/ffprobe_info.php | 6 +- library/ajax/index_data.php | 20 +-- library/ajax/manage_admin.php | 18 +- library/ajax/manage_user.php | 2 +- library/ajax/mod_action.php | 18 +- library/ajax/posts.php | 24 +-- library/ajax/sitemap.php | 4 +- library/ajax/thanks.php | 8 +- library/ajax/user_register.php | 2 +- library/ajax/view_post.php | 4 +- library/attach_mod/attachment_mod.php | 10 +- library/attach_mod/displaying_torrent.php | 44 ++--- .../attach_mod/includes/functions_delete.php | 4 +- library/includes/bbcode.php | 25 +-- .../includes/cron/jobs/attach_maintenance.php | 2 +- .../includes/cron/jobs/board_maintenance.php | 6 +- library/includes/cron/jobs/clean_dlstat.php | 10 +- library/includes/cron/jobs/clean_log.php | 2 +- library/includes/cron/jobs/clean_pm.php | 2 +- library/includes/cron/jobs/demo_mode.php | 2 +- library/includes/cron/jobs/prune_forums.php | 2 +- .../cron/jobs/prune_inactive_users.php | 4 +- .../includes/cron/jobs/prune_topic_moved.php | 4 +- .../includes/cron/jobs/sessions_cleanup.php | 6 +- .../cron/jobs/tr_cleanup_and_dlstat.php | 10 +- library/includes/cron/jobs/tr_maintenance.php | 6 +- .../includes/cron/jobs/tr_make_snapshot.php | 8 +- library/includes/cron/jobs/tr_seed_bonus.php | 10 +- .../includes/cron/jobs/update_forums_atom.php | 10 +- .../includes/datastore/build_cat_forums.php | 12 +- .../datastore/build_check_updates.php | 8 +- library/includes/datastore/build_smilies.php | 4 +- library/includes/datastore/build_stats.php | 10 +- library/includes/functions.php | 141 +++++++-------- library/includes/init_bb.php | 35 ++-- library/includes/online_userlist.php | 2 +- library/includes/page_footer.php | 10 +- library/includes/page_header.php | 34 ++-- library/includes/torrent_show_dl_list.php | 20 +-- library/includes/ucp/bonus.php | 6 +- library/includes/ucp/email.php | 2 +- library/includes/ucp/register.php | 90 +++++----- library/includes/ucp/sendpasswd.php | 4 +- library/includes/ucp/topic_watch.php | 6 +- library/includes/ucp/viewprofile.php | 12 +- library/language/source/html/sidebar2.html | 2 +- login.php | 10 +- memberlist.php | 14 +- modcp.php | 18 +- playback_m3u.php | 4 +- poll.php | 4 +- posting.php | 22 +-- privmsg.php | 32 ++-- search.php | 22 ++- src/Censor.php | 4 +- src/Config.php | 4 +- src/Dev.php | 22 +-- src/Legacy/Admin/Common.php | 8 +- src/Legacy/Admin/Cron.php | 1 + src/Legacy/Atom.php | 20 +-- src/Legacy/BBCode.php | 8 +- src/Legacy/Common/Select.php | 14 +- src/Legacy/Common/Upload.php | 4 +- src/Legacy/Common/User.php | 63 +++---- src/Legacy/LogAction.php | 2 +- src/Legacy/Poll.php | 6 +- src/Legacy/Post.php | 40 ++--- src/Legacy/Template.php | 12 +- src/Legacy/Torrent.php | 54 +++--- src/Legacy/TorrentFileList.php | 8 +- src/Sessions.php | 4 +- src/Sitemap.php | 6 +- src/TorrServerAPI.php | 20 +-- src/Validate.php | 16 +- styles/templates/default/tpl_config.php | 40 ++--- terms.php | 4 +- tracker.php | 16 +- viewforum.php | 26 +-- viewtopic.php | 40 ++--- 106 files changed, 885 insertions(+), 803 deletions(-) create mode 100644 UPGRADE_GUIDE.md diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md new file mode 100644 index 000000000..98bf8ca1c --- /dev/null +++ b/UPGRADE_GUIDE.md @@ -0,0 +1,165 @@ +# 🚀 TorrentPier Upgrade Guide + +This guide helps you upgrade your TorrentPier installation to the latest version, covering breaking changes, new features, and migration strategies. + +## 📖 Table of Contents + +- [Configuration System Migration](#configuration-system-migration) +- [Breaking Changes](#breaking-changes) +- [Best Practices](#best-practices) + +## ⚙️ Configuration System Migration + +The new TorrentPier features a modern, centralized configuration system with full backward compatibility. + +### Quick Migration Overview + +```php +// ❌ Old way (still works, but not recommended) +global $bb_cfg; +$announceUrl = $bb_cfg['bt_announce_url']; +$dbHost = $bb_cfg['database']['host']; + +// ✅ New way (recommended) +$announceUrl = config()->get('bt_announce_url'); +$dbHost = config()->get('database.host'); +``` + +### Key Configuration Changes + +#### Basic Usage +```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 Values +```php +// Set configuration values +config()->set('sitename', 'My Awesome Tracker'); +config()->set('database.port', 3306); +config()->set('cache.enabled', true); +``` + +#### Working with Sections +```php +// Get entire configuration section +$dbConfig = config()->getSection('database'); +$trackerConfig = config()->getSection('tracker'); + +// Check if configuration exists +if (config()->has('bt_announce_url')) { + $announceUrl = config()->get('bt_announce_url'); +} +``` + +### Common Configuration Mappings + +| Old Syntax | New Syntax | +|------------|------------| +| `$bb_cfg['sitename']` | `config()->get('sitename')` | +| `$bb_cfg['database']['host']` | `config()->get('database.host')` | +| `$bb_cfg['tracker']['enabled']` | `config()->get('tracker.enabled')` | +| `$bb_cfg['cache']['timeout']` | `config()->get('cache.timeout')` | +| `$bb_cfg['torr_server']['url']` | `config()->get('torr_server.url')` | + +### Magic Methods Support +```php +// Magic getter +$siteName = config()->sitename; +$dbHost = config()->{'database.host'}; + +// Magic setter +config()->sitename = 'New Site Name'; +config()->{'database.port'} = 3306; + +// Magic isset +if (isset(config()->bt_announce_url)) { + // Configuration exists +} +``` + +## ⚠️ Breaking Changes + +### Deprecated Functions +- `get_config()` → Use `config()->get()` +- `set_config()` → Use `config()->set()` +- Direct `$bb_cfg` access → Use `config()` methods + +### File Structure Changes +- New `/src/` directory for modern PHP classes +- Reorganized template structure + +### Template Changes +- Updated template syntax in some areas +- New template variables available +- Deprecated template functions + +## 📋 Best Practices + +### Configuration Management +```php +// ✅ Always provide defaults +$timeout = config()->get('api.timeout', 30); + +// ✅ Use type hints +function getMaxUploadSize(): int { + return (int) config()->get('upload.max_size', 10485760); +} + +// ✅ Cache frequently used values +class TrackerService { + private string $announceUrl; + + public function __construct() { + $this->announceUrl = config()->get('bt_announce_url'); + } +} +``` + +### Error Handling +```php +// ✅ Graceful error handling +try { + $dbConfig = config()->getSection('database'); + // Database operations +} catch (Exception $e) { + error_log("Database configuration error: " . $e->getMessage()); + // Fallback behavior +} +``` + +### Performance Optimization +```php +// ✅ Minimize configuration calls in loops +$cacheEnabled = config()->get('cache.enabled', false); +for ($i = 0; $i < 1000; $i++) { + if ($cacheEnabled) { + // Use cached value + } +} +``` + +### Security Considerations +```php +// ✅ Validate configuration values +$maxFileSize = min( + config()->get('upload.max_size', 1048576), + 1048576 * 100 // Hard limit: 100MB +); + +// ✅ Sanitize user-configurable values +$siteName = htmlspecialchars(config()->get('sitename', 'TorrentPier')); +``` + +--- + +**Important**: Always test the upgrade process in a staging environment before applying it to production. Keep backups of your database and files until you're confident the upgrade was successful. + +For additional support, visit our [Official Forum](https://torrentpier.com) or check our [GitHub Repository](https://github.com/torrentpier/torrentpier) for the latest updates and community discussions. diff --git a/admin/admin_attach_cp.php b/admin/admin_attach_cp.php index 6928a253b..a7f1ab498 100644 --- a/admin/admin_attach_cp.php +++ b/admin/admin_attach_cp.php @@ -69,44 +69,44 @@ $order_by = ''; if ($view === 'username') { switch ($mode) { case 'username': - $order_by = 'ORDER BY u.username ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY u.username ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'attachments': - $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'filesize': - $order_by = 'ORDER BY total_size ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY total_size ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; default: $mode = 'attachments'; $sort_order = 'DESC'; - $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY total_attachments ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; } } elseif ($view === 'attachments') { switch ($mode) { case 'real_filename': - $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'comment': - $order_by = 'ORDER BY a.comment ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.comment ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'extension': - $order_by = 'ORDER BY a.extension ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.extension ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'filesize': - $order_by = 'ORDER BY a.filesize ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.filesize ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'downloads': - $order_by = 'ORDER BY a.download_count ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.download_count ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; case 'post_time': - $order_by = 'ORDER BY a.filetime ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.filetime ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; default: $mode = 'a.real_filename'; $sort_order = 'ASC'; - $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . $bb_cfg['topics_per_page']; + $order_by = 'ORDER BY a.real_filename ' . $sort_order . ' LIMIT ' . $start . ', ' . config()->get('topics_per_page'); break; } } @@ -470,8 +470,8 @@ if ($view === 'attachments') { } // Generate Pagination -if ($do_pagination && $total_rows > $bb_cfg['topics_per_page']) { - generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, $bb_cfg['topics_per_page'], $start); +if ($do_pagination && $total_rows > config()->get('topics_per_page')) { + generate_pagination('admin_attach_cp.php?view=' . $view . '&mode=' . $mode . '&order=' . $sort_order . '&uid=' . $uid, $total_rows, config()->get('topics_per_page'), $start); } print_page('admin_attach_cp.tpl', 'admin'); diff --git a/admin/admin_log.php b/admin/admin_log.php index 517a4b9bb..89f0e8b0b 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -151,7 +151,7 @@ if ($var =& $_REQUEST[$daysback_key] && $var != $def_days) { $url = url_arg($url, $daysback_key, $daysback_val); } if ($var =& $_REQUEST[$datetime_key] && $var != $def_datetime) { - $tz = TIMENOW + (3600 * $bb_cfg['board_timezone']); + $tz = TIMENOW + (3600 * config()->get('board_timezone')); if (($tmp_timestamp = strtotime($var, $tz)) > 0) { $datetime_val = $tmp_timestamp; $url = url_arg($url, $datetime_key, date($dt_format, $datetime_val)); diff --git a/admin/admin_mass_email.php b/admin/admin_mass_email.php index d2765f9d6..51902d960 100644 --- a/admin/admin_mass_email.php +++ b/admin/admin_mass_email.php @@ -14,7 +14,7 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; -if (!$bb_cfg['emailer']['enabled']) { +if (!config()->get('emailer.enabled')) { bb_die($lang['EMAILER_DISABLED']); } @@ -23,7 +23,7 @@ set_time_limit(1200); $subject = trim(request_var('subject', '')); $message = (string)request_var('message', ''); $group_id = (int)request_var(POST_GROUPS_URL, 0); -$reply_to = (string)request_var('reply_to', $bb_cfg['board_email']); +$reply_to = (string)request_var('reply_to', config()->get('board_email')); $message_type = (string)request_var('message_type', ''); $errors = $user_id_sql = []; diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php index 3e3fd1fb6..66e2f800b 100644 --- a/admin/admin_sitemap.php +++ b/admin/admin_sitemap.php @@ -39,7 +39,7 @@ if (!$result = DB()->sql_query($sql)) { } } -$s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ''; +$s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], config()->get('post_date_format')) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ''; $message = is_file(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED']; $template->assign_vars([ diff --git a/admin/admin_smilies.php b/admin/admin_smilies.php index e53c24223..9e84c3ea0 100644 --- a/admin/admin_smilies.php +++ b/admin/admin_smilies.php @@ -26,7 +26,7 @@ if ($mode == 'delete' && isset($_POST['cancel'])) { $mode = ''; } -$pathToSmilesDir = BB_ROOT . $bb_cfg['smilies_path']; +$pathToSmilesDir = BB_ROOT . config()->get('smilies_path'); $delimeter = '=+:'; $s_hidden_fields = ''; $smiley_paks = $smiley_images = []; diff --git a/admin/admin_terms.php b/admin/admin_terms.php index 4e294c3a5..45acd875c 100644 --- a/admin/admin_terms.php +++ b/admin/admin_terms.php @@ -17,15 +17,15 @@ require INC_DIR . '/bbcode.php'; $preview = isset($_POST['preview']); -if (isset($_POST['post']) && ($bb_cfg['terms'] !== $_POST['message'])) { +if (isset($_POST['post']) && (config()->get('terms') !== $_POST['message'])) { bb_update_config(['terms' => $_POST['message']]); bb_die($lang['TERMS_UPDATED_SUCCESSFULLY'] . '

' . sprintf($lang['CLICK_RETURN_TERMS_CONFIG'], '', '') . '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); } $template->assign_vars([ 'S_ACTION' => 'admin_terms.php', - 'EXT_LINK_NW' => $bb_cfg['ext_link_new_win'], - 'MESSAGE' => $preview ? $_POST['message'] : $bb_cfg['terms'], + 'EXT_LINK_NW' => config()->get('ext_link_new_win'), + 'MESSAGE' => $preview ? $_POST['message'] : config()->get('terms'), 'PREVIEW_HTML' => $preview ? bbcode2html($_POST['message']) : '', ]); diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index f89f3f669..d383e5a29 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -841,10 +841,10 @@ if (!isset($_REQUEST['dosearch'])) { if ($page == 1) { $offset = 0; } else { - $offset = (($page - 1) * $bb_cfg['topics_per_page']); + $offset = (($page - 1) * config()->get('topics_per_page')); } - $limit = "LIMIT $offset, " . $bb_cfg['topics_per_page']; + $limit = "LIMIT $offset, " . config()->get('topics_per_page'); $select_sql .= " $limit"; @@ -859,7 +859,7 @@ if (!isset($_REQUEST['dosearch'])) { bb_die($lang['SEARCH_NO_RESULTS']); } } - $num_pages = ceil($total_pages['total'] / $bb_cfg['topics_per_page']); + $num_pages = ceil($total_pages['total'] / config()->get('topics_per_page')); $pagination = ''; diff --git a/admin/admin_words.php b/admin/admin_words.php index 919afb64b..ba0746ca1 100644 --- a/admin/admin_words.php +++ b/admin/admin_words.php @@ -14,8 +14,8 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; -if (!$bb_cfg['use_word_censor']) { - bb_die('Word censor disabled

($bb_cfg[\'use_word_censor\'] in config.php)'); +if (!config()->get('use_word_censor')) { + bb_die('Word censor disabled

(use_word_censor in config.php)'); } $mode = request_var('mode', ''); diff --git a/admin/index.php b/admin/index.php index ea3d0a2aa..3d3ddba58 100644 --- a/admin/index.php +++ b/admin/index.php @@ -78,7 +78,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { } elseif (isset($_GET['pane']) && $_GET['pane'] == 'right') { $template->assign_vars([ 'TPL_ADMIN_MAIN' => true, - 'ADMIN_LOCK' => (bool)$bb_cfg['board_disable'], + 'ADMIN_LOCK' => (bool)config()->get('board_disable'), 'ADMIN_LOCK_CRON' => is_file(BB_DISABLED), ]); @@ -98,8 +98,8 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $total_posts = $stats['postcount']; $total_topics = $stats['topiccount']; $total_users = $stats['usercount']; - $start_date = bb_date($bb_cfg['board_startdate']); - $boarddays = (TIMENOW - $bb_cfg['board_startdate']) / 86400; + $start_date = bb_date(config()->get('board_startdate')); + $boarddays = (TIMENOW - config()->get('board_startdate')) / 86400; $posts_per_day = sprintf('%.2f', $total_posts / $boarddays); $topics_per_day = sprintf('%.2f', $total_topics / $boarddays); @@ -107,10 +107,10 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $avatar_dir_size = 0; - if ($avatar_dir = opendir($bb_cfg['avatars']['upload_path'])) { + if ($avatar_dir = opendir(config()->get('avatars.upload_path'))) { while ($file = readdir($avatar_dir)) { if ($file != '.' && $file != '..') { - $avatar_dir_size += @filesize($bb_cfg['avatars']['upload_path'] . $file); + $avatar_dir_size += @filesize(config()->get('avatars.upload_path') . $file); } } closedir($avatar_dir); @@ -187,7 +187,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { 'STARTED' => bb_date($onlinerow_reg[$i]['session_start'], 'd-M-Y H:i', false), 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'd-M-Y H:i', false), 'IP_ADDRESS' => $reg_ip, - 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $reg_ip, + 'U_WHOIS_IP' => config()->get('whois_info') . $reg_ip, ]); } } @@ -206,7 +206,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { 'STARTED' => bb_date($onlinerow_guest[$i]['session_start'], 'd-M-Y H:i', false), 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'd-M-Y H:i', false), 'IP_ADDRESS' => $guest_ip, - 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $guest_ip, + 'U_WHOIS_IP' => config()->get('whois_info') . $guest_ip, ]); } } diff --git a/admin/stats/tracker.php b/admin/stats/tracker.php index 977856b4c..677373d78 100644 --- a/admin/stats/tracker.php +++ b/admin/stats/tracker.php @@ -21,7 +21,7 @@ if (!IS_ADMIN) { $peers_in_last_minutes = [30, 15, 5, 1]; $peers_in_last_sec_limit = 300; -$announce_interval = (int)$bb_cfg['announce_interval']; +$announce_interval = (int)config()->get('announce_interval'); $stat = []; define('TMP_TRACKER_TABLE', 'tmp_tracker'); diff --git a/bt/announce.php b/bt/announce.php index 91d9d1e23..ea1cca19a 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -11,8 +11,6 @@ define('IN_TRACKER', true); define('BB_ROOT', './../'); require dirname(__DIR__) . '/common.php'; -global $bb_cfg; - // Check User-Agent for existence $userAgent = (string)$_SERVER['HTTP_USER_AGENT']; if (empty($userAgent)) { @@ -20,8 +18,8 @@ if (empty($userAgent)) { die; } -$announce_interval = $bb_cfg['announce_interval']; -$passkey_key = $bb_cfg['passkey_key']; +$announce_interval = config()->get('announce_interval'); +$passkey_key = config()->get('passkey_key'); // Recover info_hash if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) { @@ -67,10 +65,10 @@ if (strlen($peer_id) !== 20) { } // Check for client ban -if ($bb_cfg['client_ban']['enabled']) { +if (config()->get('client_ban.enabled')) { $targetClient = []; - foreach ($bb_cfg['client_ban']['clients'] as $clientId => $banReason) { + foreach (config()->get('client_ban.clients') as $clientId => $banReason) { if (str_starts_with($peer_id, $clientId)) { $targetClient = [ 'peer_id' => $clientId, @@ -80,7 +78,7 @@ if ($bb_cfg['client_ban']['enabled']) { } } - if ($bb_cfg['client_ban']['only_allow_mode']) { + if (config()->get('client_ban.only_allow_mode')) { if (empty($targetClient['peer_id'])) { msg_die('Your BitTorrent client has been banned!'); } @@ -131,7 +129,7 @@ if ( || !is_numeric($port) || ($port < 1024 && !$stopped) || $port > 0xFFFF - || (!empty($bb_cfg['disallowed_ports']) && in_array($port, $bb_cfg['disallowed_ports'])) + || (!empty(config()->get('disallowed_ports')) && in_array($port, config()->get('disallowed_ports'))) ) { msg_die('Invalid port: ' . $port); } @@ -170,13 +168,13 @@ if (preg_match('/(Mozilla|Browser|Chrome|Safari|AppleWebKit|Opera|Links|Lynx|Bot $ip = $_SERVER['REMOTE_ADDR']; // 'ip' query handling -if (!$bb_cfg['ignore_reported_ip'] && isset($_GET['ip']) && $ip !== $_GET['ip']) { - if (!$bb_cfg['verify_reported_ip'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { +if (!config()->get('ignore_reported_ip') && isset($_GET['ip']) && $ip !== $_GET['ip']) { + if (!config()->get('verify_reported_ip') && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $x_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if ($x_ip === $_GET['ip']) { $filteredIp = filter_var($x_ip, FILTER_VALIDATE_IP); - if ($filteredIp !== false && ($bb_cfg['allow_internal_ip'] || !filter_var($filteredIp, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))) { + if ($filteredIp !== false && (config()->get('allow_internal_ip') || !filter_var($filteredIp, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))) { $ip = $filteredIp; } } @@ -272,7 +270,7 @@ if ($lp_info) { define('IS_MOD', !IS_GUEST && (int)$row['user_level'] === MOD); define('IS_GROUP_MEMBER', !IS_GUEST && (int)$row['user_level'] === GROUP_MEMBER); define('IS_USER', !IS_GUEST && (int)$row['user_level'] === USER); - define('IS_SUPER_ADMIN', IS_ADMIN && isset($bb_cfg['super_admins'][$user_id])); + define('IS_SUPER_ADMIN', IS_ADMIN && isset(config()->get('super_admins')[$user_id])); define('IS_AM', IS_ADMIN || IS_MOD); $topic_id = $row['topic_id']; $releaser = (int)($user_id == $row['poster_id']); @@ -280,13 +278,13 @@ if ($lp_info) { $tor_status = $row['tor_status']; // Check tor status - if (!IS_AM && isset($bb_cfg['tor_frozen'][$tor_status]) && !(isset($bb_cfg['tor_frozen_author_download'][$tor_status]) && $releaser)) { + if (!IS_AM && isset(config()->get('tor_frozen')[$tor_status]) && !(isset(config()->get('tor_frozen_author_download')[$tor_status]) && $releaser)) { msg_die('Torrent frozen and cannot be downloaded'); } // Check hybrid status if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) { - $stat_protocol = match ((int)$bb_cfg['tracker']['hybrid_stat_protocol']) { + $stat_protocol = match ((int)config()->get('tracker.hybrid_stat_protocol')) { 2 => substr($row['info_hash_v2'], 0, 20), default => $row['info_hash'] // 1 }; @@ -296,7 +294,7 @@ if ($lp_info) { } // Ratio limits - if ((RATIO_ENABLED || $bb_cfg['tracker']['limit_concurrent_ips']) && !$stopped) { + if ((RATIO_ENABLED || config()->get('tracker.limit_concurrent_ips')) && !$stopped) { $user_ratio = get_bt_ratio($row); if ($user_ratio === null) { $user_ratio = 1; @@ -304,10 +302,10 @@ if ($lp_info) { $rating_msg = ''; if (!$seeder) { - foreach ($bb_cfg['rating'] as $ratio => $limit) { + foreach (config()->get('rating') as $ratio => $limit) { if ($user_ratio < $ratio) { - $bb_cfg['tracker']['limit_active_tor'] = 1; - $bb_cfg['tracker']['limit_leech_count'] = $limit; + config()->set('tracker.limit_active_tor', 1); + config()->set('tracker.limit_leech_count', $limit); $rating_msg = " (ratio < $ratio)"; break; } @@ -315,29 +313,29 @@ if ($lp_info) { } // Limit active torrents - if (!isset($bb_cfg['unlimited_users'][$user_id]) && $bb_cfg['tracker']['limit_active_tor'] && (($bb_cfg['tracker']['limit_seed_count'] && $seeder) || ($bb_cfg['tracker']['limit_leech_count'] && !$seeder))) { + if (!isset(config()->get('unlimited_users')[$user_id]) && config()->get('tracker.limit_active_tor') && ((config()->get('tracker.limit_seed_count') && $seeder) || (config()->get('tracker.limit_leech_count') && !$seeder))) { $sql = "SELECT COUNT(DISTINCT topic_id) AS active_torrents FROM " . BB_BT_TRACKER . " WHERE user_id = $user_id AND seeder = $seeder AND topic_id != $topic_id"; - if (!$seeder && $bb_cfg['tracker']['leech_expire_factor'] && $user_ratio < 0.5) { - $sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']); + if (!$seeder && config()->get('tracker.leech_expire_factor') && $user_ratio < 0.5) { + $sql .= " AND update_time > " . (TIMENOW - 60 * config()->get('tracker.leech_expire_factor')); } $sql .= " GROUP BY user_id"; if ($row = DB()->fetch_row($sql)) { - if ($seeder && $bb_cfg['tracker']['limit_seed_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_seed_count']) { - msg_die('Only ' . $bb_cfg['tracker']['limit_seed_count'] . ' torrent(s) allowed for seeding'); - } elseif (!$seeder && $bb_cfg['tracker']['limit_leech_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_leech_count']) { - msg_die('Only ' . $bb_cfg['tracker']['limit_leech_count'] . ' torrent(s) allowed for leeching' . $rating_msg); + if ($seeder && config()->get('tracker.limit_seed_count') && $row['active_torrents'] >= config()->get('tracker.limit_seed_count')) { + msg_die('Only ' . config()->get('tracker.limit_seed_count') . ' torrent(s) allowed for seeding'); + } elseif (!$seeder && config()->get('tracker.limit_leech_count') && $row['active_torrents'] >= config()->get('tracker.limit_leech_count')) { + msg_die('Only ' . config()->get('tracker.limit_leech_count') . ' torrent(s) allowed for leeching' . $rating_msg); } } } // Limit concurrent IPs - if ($bb_cfg['tracker']['limit_concurrent_ips'] && (($bb_cfg['tracker']['limit_seed_ips'] && $seeder) || ($bb_cfg['tracker']['limit_leech_ips'] && !$seeder))) { + if (config()->get('tracker.limit_concurrent_ips') && ((config()->get('tracker.limit_seed_ips') && $seeder) || (config()->get('tracker.limit_leech_ips') && !$seeder))) { $sql = "SELECT COUNT(DISTINCT ip) AS ips FROM " . BB_BT_TRACKER . " WHERE topic_id = $topic_id @@ -345,16 +343,16 @@ if ($lp_info) { AND seeder = $seeder AND $ip_version != '$ip_sql'"; - if (!$seeder && $bb_cfg['tracker']['leech_expire_factor']) { - $sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']); + if (!$seeder && config()->get('tracker.leech_expire_factor')) { + $sql .= " AND update_time > " . (TIMENOW - 60 * config()->get('tracker.leech_expire_factor')); } $sql .= " GROUP BY topic_id"; if ($row = DB()->fetch_row($sql)) { - if ($seeder && $bb_cfg['tracker']['limit_seed_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_seed_ips']) { - msg_die('You can seed only from ' . $bb_cfg['tracker']['limit_seed_ips'] . " IP's"); - } elseif (!$seeder && $bb_cfg['tracker']['limit_leech_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_leech_ips']) { - msg_die('You can leech only from ' . $bb_cfg['tracker']['limit_leech_ips'] . " IP's"); + if ($seeder && config()->get('tracker.limit_seed_ips') && $row['ips'] >= config()->get('tracker.limit_seed_ips')) { + msg_die('You can seed only from ' . config()->get('tracker.limit_seed_ips') . " IP's"); + } elseif (!$seeder && config()->get('tracker.limit_leech_ips') && $row['ips'] >= config()->get('tracker.limit_leech_ips')) { + msg_die('You can leech only from ' . config()->get('tracker.limit_leech_ips') . " IP's"); } } } @@ -378,7 +376,7 @@ $up_add = ($lp_info && $uploaded > $lp_info['uploaded']) ? $uploaded - $lp_info[ $down_add = ($lp_info && $downloaded > $lp_info['downloaded']) ? $downloaded - $lp_info['downloaded'] : 0; // Gold/Silver releases -if ($bb_cfg['tracker']['gold_silver_enabled'] && $down_add) { +if (config()->get('tracker.gold_silver_enabled') && $down_add) { if ($tor_type == TOR_TYPE_GOLD) { $down_add = 0; } // Silver releases @@ -388,7 +386,7 @@ if ($bb_cfg['tracker']['gold_silver_enabled'] && $down_add) { } // Freeleech -if ($bb_cfg['tracker']['freeleech'] && $down_add) { +if (config()->get('tracker.freeleech') && $down_add) { $down_add = 0; } @@ -466,8 +464,8 @@ $output = CACHE('tr_cache')->get(PEERS_LIST_PREFIX . $topic_id); if (!$output) { // Retrieve peers - $numwant = (int)$bb_cfg['tracker']['numwant']; - $compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact)); + $numwant = (int)config()->get('tracker.numwant'); + $compact_mode = (config()->get('tracker.compact_mode') || !empty($compact)); $rowset = DB()->fetch_rowset(" SELECT ip, ipv6, port @@ -512,7 +510,7 @@ if (!$output) { $seeders = $leechers = $client_completed = 0; - if ($bb_cfg['tracker']['scrape']) { + if (config()->get('tracker.scrape')) { $row = DB()->fetch_row(" SELECT seeders, leechers, completed FROM " . BB_BT_TRACKER_SNAP . " diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index 43e6bf43b..283c71ede 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -11,11 +11,9 @@ if (!defined('IN_TRACKER')) { die(basename(__FILE__)); } -global $bb_cfg; - // Exit if tracker is disabled -if ($bb_cfg['tracker']['bt_off']) { - msg_die($bb_cfg['tracker']['bt_off_reason']); +if (config()->get('tracker.bt_off')) { + msg_die(config()->get('tracker.bt_off_reason')); } // diff --git a/bt/scrape.php b/bt/scrape.php index 534cd57fd..dd94ab8ff 100644 --- a/bt/scrape.php +++ b/bt/scrape.php @@ -11,9 +11,7 @@ define('IN_TRACKER', true); define('BB_ROOT', './../'); require dirname(__DIR__) . '/common.php'; -global $bb_cfg; - -if (!$bb_cfg['tracker']['scrape']) { +if (!config()->get('tracker.scrape')) { msg_die('Please disable SCRAPE!'); } @@ -60,8 +58,8 @@ foreach ($info_hash_array[1] as $hash) { $info_hash_count = count($info_hashes); if (!empty($info_hash_count)) { - if ($info_hash_count > $bb_cfg['max_scrapes']) { - $info_hashes = array_slice($info_hashes, 0, $bb_cfg['max_scrapes']); + if ($info_hash_count > config()->get('max_scrapes')) { + $info_hashes = array_slice($info_hashes, 0, config()->get('max_scrapes')); } $info_hashes_sql = implode('\', \'', $info_hashes); diff --git a/common.php b/common.php index e62800df7..b896f4194 100644 --- a/common.php +++ b/common.php @@ -377,9 +377,9 @@ if (!defined('IN_TRACKER')) { } else { define('DUMMY_PEER', pack('Nn', \TorrentPier\Helpers\IPHelper::ip2long($_SERVER['REMOTE_ADDR']), !empty($_GET['port']) ? (int)$_GET['port'] : random_int(1000, 65000))); - define('PEER_HASH_EXPIRE', round($bb_cfg['announce_interval'] * (0.85 * $bb_cfg['tracker']['expire_factor']))); - define('PEERS_LIST_EXPIRE', round($bb_cfg['announce_interval'] * 0.7)); - define('SCRAPE_LIST_EXPIRE', round($bb_cfg['scrape_interval'] * 0.7)); + define('PEER_HASH_EXPIRE', round(config()->get('announce_interval') * (0.85 * config()->get('tracker.expire_factor')))); + define('PEERS_LIST_EXPIRE', round(config()->get('announce_interval') * 0.7)); + define('SCRAPE_LIST_EXPIRE', round(config()->get('scrape_interval') * 0.7)); define('PEER_HASH_PREFIX', 'peer_'); define('PEERS_LIST_PREFIX', 'peers_list_'); 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..c946c758f 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']]), ]); } @@ -275,7 +275,7 @@ $template->assign_vars([ 'TOTAL_TOPICS' => sprintf($lang['POSTED_TOPICS_TOTAL'], $stats['topiccount']), 'TOTAL_POSTS' => sprintf($lang['POSTED_ARTICLES_TOTAL'], $stats['postcount']), 'TOTAL_USERS' => sprintf($lang['REGISTERED_USERS_TOTAL'], $stats['usercount']), - 'TOTAL_GENDER' => $bb_cfg['gender'] ? sprintf( + 'TOTAL_GENDER' => config()->get('gender') ? sprintf( $lang['USERS_TOTAL_GENDER'], $stats['male'], $stats['female'], @@ -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/library/ajax/avatar.php b/library/ajax/avatar.php index 1b35c8bd1..08ae4a057 100644 --- a/library/ajax/avatar.php +++ b/library/ajax/avatar.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang, $user; +global $lang, $user; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); diff --git a/library/ajax/callseed.php b/library/ajax/callseed.php index a2e523612..9ef54a72d 100644 --- a/library/ajax/callseed.php +++ b/library/ajax/callseed.php @@ -11,9 +11,9 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $userdata, $lang; +global $userdata, $lang; -if (!$bb_cfg['callseed']) { +if (!config()->get('callseed')) { $this->ajax_die($lang['MODULE_OFF']); } @@ -32,7 +32,7 @@ if ($t_data['seeders'] >= 3) { } elseif ($t_data['call_seed_time'] >= (TIMENOW - 86400)) { $time_left = delta_time($t_data['call_seed_time'] + 86400, TIMENOW, 'days'); $this->ajax_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left)); -} elseif (isset($bb_cfg['tor_no_tor_act'][$t_data['tor_status']])) { +} elseif (isset(config()->get('tor_no_tor_act')[$t_data['tor_status']])) { $this->ajax_die($lang['NOT_AVAILABLE']); } diff --git a/library/ajax/change_tor_status.php b/library/ajax/change_tor_status.php index 0ece009cb..ae534774c 100644 --- a/library/ajax/change_tor_status.php +++ b/library/ajax/change_tor_status.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $userdata, $bb_cfg, $lang, $log_action; +global $userdata, $lang, $log_action; if (!$attach_id = (int)$this->request['attach_id']) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); @@ -22,7 +22,7 @@ if (!$mode = (string)$this->request['mode']) { } $comment = false; -if ($bb_cfg['tor_comment']) { +if (config()->get('tor_comment')) { $comment = (string)$this->request['comment']; } @@ -88,7 +88,7 @@ switch ($mode) { \TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $new_status); // Log action - $log_msg = sprintf($lang['TOR_STATUS_LOG_ACTION'], $bb_cfg['tor_icons'][$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status] . '', $bb_cfg['tor_icons'][$tor['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor['tor_status']] . ''); + $log_msg = sprintf($lang['TOR_STATUS_LOG_ACTION'], config()->get('tor_icons')[$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status] . '', config()->get('tor_icons')[$tor['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor['tor_status']] . ''); if ($comment && $comment != $lang['COMMENT']) { $log_msg .= "
{$lang['COMMENT']}: $comment."; } @@ -99,12 +99,12 @@ switch ($mode) { 'log_msg' => $log_msg . '
-------------', ]); - $this->response['status'] = $bb_cfg['tor_icons'][$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status] . ' · ' . profile_url($userdata) . ' · ' . delta_time(TIMENOW) . $lang['TOR_BACK'] . ''; + $this->response['status'] = config()->get('tor_icons')[$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status] . ' · ' . profile_url($userdata) . ' · ' . delta_time(TIMENOW) . $lang['TOR_BACK'] . ''; - if ($bb_cfg['tor_comment'] && (($comment && $comment != $lang['COMMENT']) || in_array($new_status, $bb_cfg['tor_reply']))) { + if (config()->get('tor_comment') && (($comment && $comment != $lang['COMMENT']) || in_array($new_status, config()->get('tor_reply')))) { if ($tor['poster_id'] > 0) { $subject = sprintf($lang['TOR_MOD_TITLE'], $tor['topic_title']); - $message = sprintf($lang['TOR_MOD_MSG'], get_username($tor['poster_id']), make_url(TOPIC_URL . $tor['topic_id']), $bb_cfg['tor_icons'][$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status]); + $message = sprintf($lang['TOR_MOD_MSG'], get_username($tor['poster_id']), make_url(TOPIC_URL . $tor['topic_id']), config()->get('tor_icons')[$new_status] . ' ' . $lang['TOR_STATUS_NAME'][$new_status]); if ($comment && $comment != $lang['COMMENT']) { $message .= "\n\n[b]" . $lang['COMMENT'] . '[/b]: ' . $comment; @@ -117,7 +117,7 @@ switch ($mode) { break; case 'status_reply': - if (!$bb_cfg['tor_comment']) { + if (!config()->get('tor_comment')) { $this->ajax_die($lang['MODULE_OFF']); } diff --git a/library/ajax/change_torrent.php b/library/ajax/change_torrent.php index ca26b7c24..dbcef89c8 100644 --- a/library/ajax/change_torrent.php +++ b/library/ajax/change_torrent.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $userdata, $bb_cfg, $lang, $log_action; +global $userdata, $lang, $log_action; if (!isset($this->request['attach_id'])) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); diff --git a/library/ajax/edit_group_profile.php b/library/ajax/edit_group_profile.php index 1a40f941f..f66911ed1 100644 --- a/library/ajax/edit_group_profile.php +++ b/library/ajax/edit_group_profile.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $userdata, $lang; +global $userdata, $lang; if (!$group_id = (int)$this->request['group_id'] or !$group_info = \TorrentPier\Legacy\Group::get_group_data($group_id)) { $this->ajax_die($lang['NO_GROUP_ID_SPECIFIED']); diff --git a/library/ajax/edit_user_profile.php b/library/ajax/edit_user_profile.php index 9b7f24b5a..8cfc342f7 100644 --- a/library/ajax/edit_user_profile.php +++ b/library/ajax/edit_user_profile.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang; +global $lang; if (!$user_id = (int)$this->request['user_id'] or !$profiledata = get_userdata($user_id)) { $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); @@ -55,7 +55,7 @@ switch ($field) { break; case 'user_gender': - if (!$bb_cfg['gender']) { + if (!config()->get('gender')) { $this->ajax_die($lang['MODULE_OFF']); } if (!isset($lang['GENDER_SELECT'][$value])) { @@ -65,7 +65,7 @@ switch ($field) { break; case 'user_birthday': - if (!$bb_cfg['birthday_enabled']) { + if (!config()->get('birthday_enabled')) { $this->ajax_die($lang['MODULE_OFF']); } $birthday_date = date_parse($value); @@ -73,10 +73,10 @@ switch ($field) { if (!empty($birthday_date['year'])) { if (strtotime($value) >= TIMENOW) { $this->ajax_die($lang['WRONG_BIRTHDAY_FORMAT']); - } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > $bb_cfg['birthday_max_age']) { - $this->ajax_die(sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday_max_age'])); - } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < $bb_cfg['birthday_min_age']) { - $this->ajax_die(sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday_min_age'])); + } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > config()->get('birthday_max_age')) { + $this->ajax_die(sprintf($lang['BIRTHDAY_TO_HIGH'], config()->get('birthday_max_age'))); + } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < config()->get('birthday_min_age')) { + $this->ajax_die(sprintf($lang['BIRTHDAY_TO_LOW'], config()->get('birthday_min_age'))); } } diff --git a/library/ajax/ffprobe_info.php b/library/ajax/ffprobe_info.php index d6bf8067d..c2b8e7e5c 100644 --- a/library/ajax/ffprobe_info.php +++ b/library/ajax/ffprobe_info.php @@ -11,13 +11,13 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang; +global $lang; -if (!$bb_cfg['torr_server']['enabled']) { +if (!config()->get('torr_server.enabled')) { $this->ajax_die($lang['MODULE_OFF']); } -if ($bb_cfg['torr_server']['disable_for_guest'] && IS_GUEST) { +if (config()->get('torr_server.disable_for_guest') && IS_GUEST) { $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); } diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php index 42ec056c5..95fdaacda 100644 --- a/library/ajax/index_data.php +++ b/library/ajax/index_data.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang, $userdata, $datastore; +global $lang, $userdata, $datastore; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); @@ -31,9 +31,9 @@ switch ($mode) { foreach ($stats['birthday_week_list'] as $week) { $users[] = profile_url($week) . ' (' . birthday_age(date('Y-m-d', strtotime('-1 year', strtotime($week['user_birthday'])))) . ')'; } - $html = sprintf($lang['BIRTHDAY_WEEK'], $bb_cfg['birthday_check_day'], implode(', ', $users)); + $html = sprintf($lang['BIRTHDAY_WEEK'], config()->get('birthday_check_day'), implode(', ', $users)); } else { - $html = sprintf($lang['NOBIRTHDAY_WEEK'], $bb_cfg['birthday_check_day']); + $html = sprintf($lang['NOBIRTHDAY_WEEK'], config()->get('birthday_check_day')); } break; @@ -84,7 +84,7 @@ switch ($mode) { break; case 'null_ratio': - if (!$bb_cfg['ratio_null_enabled'] || !RATIO_ENABLED) { + if (!config()->get('ratio_null_enabled') || !RATIO_ENABLED) { $this->ajax_die($lang['MODULE_OFF']); } if (empty($this->request['confirmed'])) { @@ -106,8 +106,8 @@ switch ($mode) { if ($ratio_nulled && !IS_ADMIN) { $this->ajax_die($lang['BT_NULL_RATIO_AGAIN']); } - if (($user_ratio >= $bb_cfg['ratio_to_null']) && !IS_ADMIN) { - $this->ajax_die(sprintf($lang['BT_NULL_RATIO_NOT_NEEDED'], $bb_cfg['ratio_to_null'])); + if (($user_ratio >= config()->get('ratio_to_null')) && !IS_ADMIN) { + $this->ajax_die(sprintf($lang['BT_NULL_RATIO_NOT_NEEDED'], config()->get('ratio_to_null'))); } $ratio_nulled_sql = !IS_ADMIN ? ', ratio_nulled = 1' : ''; @@ -172,7 +172,7 @@ switch ($mode) { ' . $lang['UPLOADED'] . ' ' . $lang['RELEASED'] . ' ' . $lang['BONUS'] . ''; - $html .= $bb_cfg['seed_bonus_enabled'] ? '' . $lang['SEED_BONUS'] . '' : ''; + $html .= config()->get('seed_bonus_enabled') ? '' . $lang['SEED_BONUS'] . '' : ''; $html .= ' ' . $lang['TOTAL_TRAF'] . ' @@ -180,17 +180,17 @@ switch ($mode) { ' . humn_size($btu['u_up_total']) . ' ' . humn_size($btu['u_up_release']) . ' ' . humn_size($btu['u_up_bonus']) . ''; - $html .= $bb_cfg['seed_bonus_enabled'] ? '' . $profiledata['user_points'] . '' : ''; + $html .= config()->get('seed_bonus_enabled') ? '' . $profiledata['user_points'] . '' : ''; $html .= ' ' . $lang['MAX_SPEED'] . ' ' . $lang['DL_DL_SPEED'] . ': ' . $speed_down . ' ' . $lang['DL_UL_SPEED'] . ': ' . $speed_up . ''; - $html .= $bb_cfg['seed_bonus_enabled'] ? '' : ''; + $html .= config()->get('seed_bonus_enabled') ? '' : ''; $html .= ''; $this->response['user_ratio'] = ' - ' . $lang['USER_RATIO'] . ': + ' . $lang['USER_RATIO'] . ': ' . $user_ratio . ' '; break; diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index cb0249239..29ecbb3bc 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $userdata, $lang, $bb_cfg; +global $userdata, $lang; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); @@ -19,7 +19,7 @@ if (!$mode = (string)$this->request['mode']) { switch ($mode) { case 'clear_cache': - foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { + foreach (config()->get('cache.engines') as $cache_name => $cache_val) { CACHE($cache_name)->rm(); } @@ -48,20 +48,20 @@ switch ($mode) { $this->response['template_cache_html'] = '' . $lang['ALL_TEMPLATE_CLEARED'] . ''; break; case 'indexer': - exec("indexer --config {$bb_cfg['sphinx_config_path']} --all --rotate", $result); + exec("indexer --config " . config()->get('sphinx_config_path') . " --all --rotate", $result); - if (!is_file($bb_cfg['sphinx_config_path'] . ".log")) { - file_put_contents($bb_cfg['sphinx_config_path'] . ".log", "##############################" . date("H:i:s", TIMENOW) . "##############################\r\n\r\n\r\n\r\n", FILE_APPEND); + if (!is_file(config()->get('sphinx_config_path') . ".log")) { + file_put_contents(config()->get('sphinx_config_path') . ".log", "##############################" . date("H:i:s", TIMENOW) . "##############################\r\n\r\n\r\n\r\n", FILE_APPEND); } - file_put_contents($bb_cfg['sphinx_config_path'] . ".log", "##############################" . date("H:i:s", TIMENOW) . "##############################\r\n", FILE_APPEND); + file_put_contents(config()->get('sphinx_config_path') . ".log", "##############################" . date("H:i:s", TIMENOW) . "##############################\r\n", FILE_APPEND); foreach ($result as $row) { - file_put_contents($bb_cfg['sphinx_config_path'] . ".log", $row . "\r\n", FILE_APPEND); + file_put_contents(config()->get('sphinx_config_path') . ".log", $row . "\r\n", FILE_APPEND); } - file_put_contents($bb_cfg['sphinx_config_path'] . ".log", "\r\n", FILE_APPEND); - file_put_contents($bb_cfg['sphinx_config_path'] . ".log", "\r\n", FILE_APPEND); + file_put_contents(config()->get('sphinx_config_path') . ".log", "\r\n", FILE_APPEND); + file_put_contents(config()->get('sphinx_config_path') . ".log", "\r\n", FILE_APPEND); $this->response['indexer_html'] = '' . $lang['INDEXER'] . ''; break; diff --git a/library/ajax/manage_user.php b/library/ajax/manage_user.php index 8a1e4b25e..3925b739f 100644 --- a/library/ajax/manage_user.php +++ b/library/ajax/manage_user.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $userdata, $lang, $bb_cfg; +global $userdata, $lang; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); diff --git a/library/ajax/mod_action.php b/library/ajax/mod_action.php index 0817f7e4e..a82c122a0 100644 --- a/library/ajax/mod_action.php +++ b/library/ajax/mod_action.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $userdata, $bb_cfg, $lang, $datastore, $log_action; +global $userdata, $lang, $datastore, $log_action; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); @@ -44,7 +44,7 @@ switch ($mode) { \TorrentPier\Legacy\Torrent::change_tor_status($attach_id, $status); // Log action - $log_msg = sprintf($lang['TOR_STATUS_LOG_ACTION'], $bb_cfg['tor_icons'][$status] . ' ' . $lang['TOR_STATUS_NAME'][$status] . '', $bb_cfg['tor_icons'][$tor['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor['tor_status']] . ''); + $log_msg = sprintf($lang['TOR_STATUS_LOG_ACTION'], config()->get('tor_icons')[$status] . ' ' . $lang['TOR_STATUS_NAME'][$status] . '', config()->get('tor_icons')[$tor['tor_status']] . ' ' . $lang['TOR_STATUS_NAME'][$tor['tor_status']] . ''); $log_action->mod('mod_topic_change_tor_status', [ 'forum_id' => $tor['forum_id'], 'topic_id' => $tor['topic_id'], @@ -52,7 +52,7 @@ switch ($mode) { 'log_msg' => $log_msg . '
-------------', ]); } - $this->response['status'] = $bb_cfg['tor_icons'][$status]; + $this->response['status'] = config()->get('tor_icons')[$status]; $this->response['topics'] = explode(',', $topics); break; @@ -78,16 +78,16 @@ switch ($mode) { DB()->query("UPDATE " . BB_TOPICS . " SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id LIMIT 1"); // Update the news cache on the index page - $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); - if (isset($news_forums[$t_data['forum_id']]) && $bb_cfg['show_latest_news']) { + $news_forums = array_flip(explode(',', config()->get('latest_news_forum_id'))); + if (isset($news_forums[$t_data['forum_id']]) && config()->get('show_latest_news')) { $datastore->enqueue([ 'latest_news' ]); $datastore->update('latest_news'); } - $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); - if (isset($net_forums[$t_data['forum_id']]) && $bb_cfg['show_network_news']) { + $net_forums = array_flip(explode(',', config()->get('network_news_forum_id'))); + if (isset($net_forums[$t_data['forum_id']]) && config()->get('show_network_news')) { $datastore->enqueue([ 'network_news' ]); @@ -151,8 +151,8 @@ switch ($mode) { } else { $user_reg_ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($profiledata['user_reg_ip']); $user_last_ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($profiledata['user_last_ip']); - $reg_ip = '' . $user_reg_ip . ''; - $last_ip = '' . $user_last_ip . ''; + $reg_ip = '' . $user_reg_ip . ''; + $last_ip = '' . $user_last_ip . ''; } $this->response['ip_list_html'] = ' diff --git a/library/ajax/posts.php b/library/ajax/posts.php index e34b8b2c1..2c5405df3 100644 --- a/library/ajax/posts.php +++ b/library/ajax/posts.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $lang, $bb_cfg, $userdata, $wordCensor; +global $lang, $userdata, $wordCensor; if (!isset($this->request['type'])) { $this->ajax_die('empty type'); @@ -76,7 +76,7 @@ switch ($this->request['type']) { $message = "[quote=\"" . $quote_username . "\"][qpost=" . $post['post_id'] . "]" . $post['post_text'] . "[/quote]\r"; // 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); @@ -120,10 +120,10 @@ switch ($this->request['type']) { if (mb_strlen($text) > 2) { if ($text != $post['post_text']) { - if ($bb_cfg['max_smilies']) { - $count_smilies = substr_count(bbcode2html($text), 'request['type']) { $sql = "SELECT MAX(p.post_time) AS last_post_time FROM " . BB_POSTS . " p WHERE $where_sql"; if ($row = DB()->fetch_row($sql) and $row['last_post_time']) { if ($userdata['user_level'] == USER) { - if ((TIMENOW - $row['last_post_time']) < $bb_cfg['flood_interval']) { + if ((TIMENOW - $row['last_post_time']) < config()->get('flood_interval')) { $this->ajax_die($lang['FLOOD_ERROR']); } } @@ -251,10 +251,10 @@ switch ($this->request['type']) { } } - if ($bb_cfg['max_smilies']) { - $count_smilies = substr_count(bbcode2html($message), '' . make_url('sitemap/sitemap.xml') . ''; + $html .= $lang['SITEMAP_CREATED'] . ': ' . bb_date(TIMENOW, config()->get('post_date_format')) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ''; } else { $html .= $lang['SITEMAP_NOT_CREATED']; } diff --git a/library/ajax/thanks.php b/library/ajax/thanks.php index cbe29ac01..c4eb38689 100644 --- a/library/ajax/thanks.php +++ b/library/ajax/thanks.php @@ -11,9 +11,9 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang, $userdata; +global $lang, $userdata; -if (!$bb_cfg['tor_thank']) { +if (!config()->get('tor_thank')) { $this->ajax_die($lang['MODULE_OFF']); } @@ -49,12 +49,12 @@ switch ($mode) { // Limit voters per topic $thanks_count = DB()->fetch_row('SELECT COUNT(*) as thx FROM ' . BB_THX . " WHERE topic_id = $topic_id")['thx']; - if ($thanks_count > (int)$bb_cfg['tor_thank_limit_per_topic']) { + if ($thanks_count > (int)config()->get('tor_thank_limit_per_topic')) { DB()->query('DELETE FROM ' . BB_THX . " WHERE topic_id = $topic_id ORDER BY time ASC LIMIT 1"); } break; case 'get': - if (IS_GUEST && !$bb_cfg['tor_thanks_list_guests']) { + if (IS_GUEST && !config()->get('tor_thanks_list_guests')) { $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); } diff --git a/library/ajax/user_register.php b/library/ajax/user_register.php index 9491e3b57..ef03c683d 100644 --- a/library/ajax/user_register.php +++ b/library/ajax/user_register.php @@ -11,7 +11,7 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $bb_cfg, $lang, $userdata; +global $lang, $userdata; if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); diff --git a/library/ajax/view_post.php b/library/ajax/view_post.php index 916ce6cb6..e5d3e8462 100644 --- a/library/ajax/view_post.php +++ b/library/ajax/view_post.php @@ -11,11 +11,11 @@ if (!defined('IN_AJAX')) { die(basename(__FILE__)); } -global $user, $lang, $bb_cfg; +global $user, $lang; $post_id = isset($this->request['post_id']) ? (int)$this->request['post_id'] : null; $topic_id = isset($this->request['topic_id']) ? (int)$this->request['topic_id'] : null; -$return_text = $bb_cfg['show_post_bbcode_button']['enabled'] && isset($this->request['return_text']) && (bool)$this->request['return_text']; +$return_text = config()->get('show_post_bbcode_button.enabled') && isset($this->request['return_text']) && (bool)$this->request['return_text']; if (is_null($post_id)) { $post_id = DB()->fetch_row("SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_id = $topic_id", 'topic_first_post_id'); diff --git a/library/attach_mod/attachment_mod.php b/library/attach_mod/attachment_mod.php index b59d273ca..16fa06a8b 100644 --- a/library/attach_mod/attachment_mod.php +++ b/library/attach_mod/attachment_mod.php @@ -25,11 +25,11 @@ if (defined('ATTACH_INSTALL')) { */ function attach_mod_get_lang($language_file) { - global $attach_config, $bb_cfg; + global $attach_config; - $file = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/' . $language_file . '.php'; + $file = LANG_ROOT_DIR . '/' . config()->get('default_lang') . '/' . $language_file . '.php'; if (file_exists($file)) { - return $bb_cfg['default_lang']; + return config()->get('default_lang'); } $file = LANG_ROOT_DIR . '/' . $attach_config['board_lang'] . '/' . $language_file . '.php'; @@ -45,8 +45,6 @@ function attach_mod_get_lang($language_file) */ function get_config() { - global $bb_cfg; - $attach_config = []; $sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG; @@ -60,7 +58,7 @@ function get_config() } // We assign the original default board language here, because it gets overwritten later with the users default language - $attach_config['board_lang'] = trim($bb_cfg['default_lang']); + $attach_config['board_lang'] = trim(config()->get('default_lang')); return $attach_config; } diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 06a670266..edded7f47 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg, $t_data, $poster_id, $is_auth, $dl_link_css, $dl_status_css, $lang, $images; +global $t_data, $poster_id, $is_auth, $dl_link_css, $dl_status_css, $lang, $images; $tor_status_by_for_all = true; $change_peers_bgr_over = true; @@ -40,7 +40,7 @@ $template->assign_vars([ ]); // Define show peers mode (count only || user names with complete % || full details) -$cfg_sp_mode = $bb_cfg['bt_show_peers_mode']; +$cfg_sp_mode = config()->get('bt_show_peers_mode'); $get_sp_mode = $_GET['spmode'] ?? ''; $s_mode = 'count'; @@ -51,7 +51,7 @@ if ($cfg_sp_mode == SHOW_PEERS_NAMES) { $s_mode = 'full'; } -if ($bb_cfg['bt_allow_spmode_change']) { +if (config()->get('bt_allow_spmode_change')) { if ($get_sp_mode == 'names') { $s_mode = 'names'; } elseif ($get_sp_mode == 'full') { @@ -68,7 +68,7 @@ $tor_file_size = humn_size($attachments['_' . $post_id][$i]['filesize']); $tor_file_time = bb_date($attachments['_' . $post_id][$i]['filetime']); $tor_reged = (bool)$tracker_status; -$show_peers = (bool)$bb_cfg['bt_show_peers']; +$show_peers = (bool)config()->get('bt_show_peers'); $locked = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED); $tor_auth = ($bt_user_id != GUEST_UID && (($bt_user_id == $poster_id && !$locked) || $is_auth['auth_mod'])); @@ -88,10 +88,10 @@ if ($tor_auth_reg || $tor_auth_del) { $tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url; } -if ($bb_cfg['tracker']['use_old_torrent_name_format']) { - $display_name = '[' . $bb_cfg['server_name'] . '].t' . $bt_topic_id . '.' . TORRENT_EXT; +if (config()->get('tracker.use_old_torrent_name_format')) { + $display_name = '[' . config()->get('server_name') . '].t' . $bt_topic_id . '.' . TORRENT_EXT; } else { - $display_name = $t_data['topic_title'] . ' [' . $bb_cfg['server_name'] . '-' . $bt_topic_id . ']' . '.' . TORRENT_EXT; + $display_name = $t_data['topic_title'] . ' [' . config()->get('server_name') . '-' . $bt_topic_id . ']' . '.' . TORRENT_EXT; } if (!$tor_reged) { @@ -152,8 +152,8 @@ if ($tor_reged && $tor_info) { $tor_magnet = create_magnet($tor_info['info_hash'], $tor_info['info_hash_v2'], $user_passkey, html_ent_decode($t_data['topic_title']), $tor_size); // ratio limits - $min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor']; - $min_ratio_warn = $bb_cfg['bt_min_ratio_warning']; + $min_ratio_dl = config()->get('bt_min_ratio_allow_dl_tor'); + $min_ratio_warn = config()->get('bt_min_ratio_warning'); $dl_allowed = true; $user_ratio = 0; @@ -182,7 +182,7 @@ if ($tor_reged && $tor_info) { if ((isset($user_ratio, $min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS) || ($bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO)) { $template->assign_vars([ 'SHOW_RATIO_WARN' => true, - 'RATIO_WARN_MSG' => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, $bb_cfg['ratio_url_help']), + 'RATIO_WARN_MSG' => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, config()->get('ratio_url_help')), ]); } } @@ -202,12 +202,12 @@ if ($tor_reged && $tor_info) { 'TOR_TYPE' => is_gold($tor_type), // torrent status mod - 'TOR_FROZEN' => !IS_AM ? (isset($bb_cfg['tor_frozen'][$tor_info['tor_status']]) && !(isset($bb_cfg['tor_frozen_author_download'][$tor_info['tor_status']]) && $userdata['user_id'] == $tor_info['poster_id'])) ? true : '' : '', + 'TOR_FROZEN' => !IS_AM ? (isset(config()->get('tor_frozen')[$tor_info['tor_status']]) && !(isset(config()->get('tor_frozen_author_download')[$tor_info['tor_status']]) && $userdata['user_id'] == $tor_info['poster_id'])) ? true : '' : '', 'TOR_STATUS_TEXT' => $lang['TOR_STATUS_NAME'][$tor_info['tor_status']], - 'TOR_STATUS_ICON' => $bb_cfg['tor_icons'][$tor_info['tor_status']], + 'TOR_STATUS_ICON' => config()->get('tor_icons')[$tor_info['tor_status']], 'TOR_STATUS_BY' => ($tor_info['checked_user_id'] && ($is_auth['auth_mod'] || $tor_status_by_for_all)) ? (' · ' . profile_url($tor_info) . ' · ' . delta_time($tor_info['checked_time']) . $lang['TOR_BACK'] . '') : '', 'TOR_STATUS_SELECT' => build_select('sel_status', array_flip($lang['TOR_STATUS_NAME']), TOR_APPROVED), - 'TOR_STATUS_REPLY' => $bb_cfg['tor_comment'] && !IS_GUEST && in_array($tor_info['tor_status'], $bb_cfg['tor_reply']) && $userdata['user_id'] == $tor_info['poster_id'] && $t_data['topic_status'] != TOPIC_LOCKED, + 'TOR_STATUS_REPLY' => config()->get('tor_comment') && !IS_GUEST && in_array($tor_info['tor_status'], config()->get('tor_reply')) && $userdata['user_id'] == $tor_info['poster_id'] && $t_data['topic_status'] != TOPIC_LOCKED, //end torrent status mod 'S_UPLOAD_IMAGE' => $upload_image, @@ -227,7 +227,7 @@ if ($tor_reged && $tor_info) { ]); // TorrServer integration - if ($bb_cfg['torr_server']['enabled'] && (!IS_GUEST || !$bb_cfg['torr_server']['disable_for_guest']) && (new \TorrentPier\TorrServerAPI())->getM3UPath($attach_id)) { + if (config()->get('torr_server.enabled') && (!IS_GUEST || !config()->get('torr_server.disable_for_guest')) && (new \TorrentPier\TorrServerAPI())->getM3UPath($attach_id)) { $template->assign_block_vars('postrow.attach.tor_reged.tor_server', [ 'TORR_SERVER_M3U_LINK' => PLAYBACK_M3U_URL . $bt_topic_id, 'TORR_SERVER_M3U_ICON' => $images['icon_tor_m3u_icon'], @@ -239,7 +239,7 @@ if ($tor_reged && $tor_info) { } } - if ($bb_cfg['show_tor_info_in_dl_list']) { + if (config()->get('show_tor_info_in_dl_list')) { $template->assign_vars([ 'SHOW_DL_LIST' => true, 'SHOW_DL_LIST_TOR_INFO' => true, @@ -470,7 +470,7 @@ if ($tor_reged && $tor_info) { } $peerCountry = $lang['HIDDEN_USER']; - if ($bb_cfg['ip2country_settings']['enabled']) { + if (config()->get('ip2country_settings.enabled')) { if (IS_AM || $peer['user_id'] == $userdata['user_id'] || !bf($peer['user_opt'], 'user_opt', 'user_hide_peer_country')) { if ($infoByIP = infoByIP((!empty($peer['ipv6']) ? $peer['ipv6'] : $peer['ip']), $peer['port'])) { if (!empty($infoByIP['countryCode'])) { @@ -500,7 +500,7 @@ if ($tor_reged && $tor_info) { if ($ip) { $template->assign_block_vars("$x_full.$x_row.ip", [ - 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $ip, + 'U_WHOIS_IP' => config()->get('whois_info') . $ip, 'IP' => $ip ]); } @@ -563,7 +563,7 @@ if ($tor_reged && $tor_info) { } } -if ($bb_cfg['bt_allow_spmode_change'] && $s_mode != 'full') { +if (config()->get('bt_allow_spmode_change') && $s_mode != 'full') { $template->assign_vars([ 'PEERS_FULL_LINK' => true, 'SPMODE_FULL_HREF' => TOPIC_URL . "$bt_topic_id&spmode=full#seeders" @@ -571,14 +571,14 @@ if ($bb_cfg['bt_allow_spmode_change'] && $s_mode != 'full') { } $template->assign_vars([ - 'SHOW_DL_LIST_LINK' => (($bb_cfg['bt_show_dl_list'] || $bb_cfg['allow_dl_list_names_mode']) && $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL), - 'SHOW_TOR_ACT' => ($tor_reged && $show_peers && (!isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) || IS_AM)), + 'SHOW_DL_LIST_LINK' => ((config()->get('bt_show_dl_list') || config()->get('allow_dl_list_names_mode')) && $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL), + 'SHOW_TOR_ACT' => ($tor_reged && $show_peers && (!isset(config()->get('tor_no_tor_act')[$tor_info['tor_status']]) || IS_AM)), 'S_MODE_COUNT' => ($s_mode == 'count'), 'S_MODE_NAMES' => ($s_mode == 'names'), 'S_MODE_FULL' => ($s_mode == 'full'), 'PEER_EXIST' => ($seeders || $leechers || defined('SEEDER_EXIST') || defined('LEECHER_EXIST')), 'SEED_EXIST' => ($seeders || defined('SEEDER_EXIST')), 'LEECH_EXIST' => ($leechers || defined('LEECHER_EXIST')), - 'TOR_HELP_LINKS' => $bb_cfg['tor_help_links'], - 'CALL_SEED' => (!IS_GUEST && $bb_cfg['callseed'] && $tor_reged && !isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) && $seed_count < 3 && $tor_info['call_seed_time'] < (TIMENOW - 86400)), + 'TOR_HELP_LINKS' => config()->get('tor_help_links'), + 'CALL_SEED' => (!IS_GUEST && config()->get('callseed') && $tor_reged && !isset(config()->get('tor_no_tor_act')[$tor_info['tor_status']]) && $seed_count < 3 && $tor_info['call_seed_time'] < (TIMENOW - 86400)), ]); diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index 4a2b7ae0c..79679db2a 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -16,7 +16,7 @@ */ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0) { - global $lang, $bb_cfg; + global $lang; // Generate Array, if it's not an array if ($post_id_array === 0 && $attach_id_array === 0 && $page === 0) { @@ -215,7 +215,7 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } // TorrServer integration - if ($bb_cfg['torr_server']['enabled']) { + if (config()->get('torr_server.enabled')) { $torrServer = new \TorrentPier\TorrServerAPI(); $torrServer->removeM3U($attachments[$j]['attach_id']); } diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index d2465c275..7e5a40916 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -123,7 +123,7 @@ function prepare_message($message) // Either in a window or inline function generate_smilies($mode) { - global $bb_cfg, $template, $lang, $user, $datastore; + global $template, $lang, $user, $datastore; $inline_columns = 4; $inline_rows = 7; @@ -160,7 +160,7 @@ function generate_smilies($mode) $template->assign_block_vars('smilies_row.smilies_col', [ 'SMILEY_CODE' => $data['code'], - 'SMILEY_IMG' => $bb_cfg['smilies_path'] . '/' . $smile_url, + 'SMILEY_IMG' => config()->get('smilies_path') . '/' . $smile_url, 'SMILEY_DESC' => $data['emoticon'], ]); @@ -341,11 +341,9 @@ function strip_bbcode($message, $stripquotes = true, $fast_and_dirty = false, $s function extract_search_words($text) { - global $bb_cfg; - - $max_words_count = $bb_cfg['max_search_words_per_post']; - $min_word_len = max(2, $bb_cfg['search_min_word_len'] - 1); - $max_word_len = $bb_cfg['search_max_word_len']; + $max_words_count = config()->get('max_search_words_per_post'); + $min_word_len = max(2, config()->get('search_min_word_len') - 1); + $max_word_len = config()->get('search_max_word_len'); $text = ' ' . str_compact(strip_tags(mb_strtolower($text))) . ' '; $text = str_replace(['[', ']'], ['[', ']'], $text); @@ -382,12 +380,10 @@ function extract_search_words($text) function add_search_words($post_id, $post_message, $topic_title = '', $only_return_words = false) { - global $bb_cfg; - $text = $topic_title . ' ' . $post_message; $words = ($text) ? extract_search_words($text) : []; - if ($only_return_words || $bb_cfg['search_engine_type'] == 'sphinx') { + if ($only_return_words || config()->get('search_engine_type') == 'sphinx') { return implode("\n", $words); } @@ -425,22 +421,19 @@ function get_words_rate($text) function hide_passkey($str) { - global $bb_cfg; - return preg_replace("#\?{$bb_cfg['passkey_key']}=[a-zA-Z0-9]{" . BT_AUTH_KEY_LENGTH . "}#", "?{$bb_cfg['passkey_key']}=passkey", $str); + return preg_replace("#\?{config()->get('passkey_key')}=[a-zA-Z0-9]{" . BT_AUTH_KEY_LENGTH . "}#", "?{config()->get('passkey_key')}=passkey", $str); } function get_parsed_post($postrow, $mode = 'full', $return_chars = 600) { - global $bb_cfg; - - if ($bb_cfg['use_posts_cache'] && !empty($postrow['post_html'])) { + if (config()->get('use_posts_cache') && !empty($postrow['post_html'])) { return $postrow['post_html']; } $message = bbcode2html($postrow['post_text']); // Posts cache - if ($bb_cfg['use_posts_cache']) { + if (config()->get('use_posts_cache')) { DB()->shutdown['post_html'][] = [ 'post_id' => (int)$postrow['post_id'], 'post_html' => (string)$message diff --git a/library/includes/cron/jobs/attach_maintenance.php b/library/includes/cron/jobs/attach_maintenance.php index 99e9a7168..84987405e 100644 --- a/library/includes/cron/jobs/attach_maintenance.php +++ b/library/includes/cron/jobs/attach_maintenance.php @@ -144,7 +144,7 @@ if ($check_attachments) { $orphan_db_attach[] = $row['attach_id']; } // Delete all orphan attachments - if ($bb_cfg['torr_server']['enabled'] && $fix_errors) { + if (config()->get('torr_server.enabled') && $fix_errors) { foreach ($orphan_db_attach as $attach_id) { // TorrServer integration $torrServer = new \TorrentPier\TorrServerAPI(); diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index de789f9f8..e25cf5f75 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -17,7 +17,7 @@ if (!defined('BB_ROOT')) { \TorrentPier\Legacy\Admin\Common::sync_all_forums(); // Cleaning bb_poll_users -if ($poll_max_days = (int)$bb_cfg['poll_max_days']) { +if ($poll_max_days = (int)config()->get('poll_max_days')) { $per_cycle = 20000; $row = DB()->fetch_row("SELECT MIN(topic_id) AS start_id, MAX(topic_id) AS finish_id FROM " . BB_POLL_USERS); $start_id = (int)$row['start_id']; @@ -45,12 +45,12 @@ if ($poll_max_days = (int)$bb_cfg['poll_max_days']) { DB()->query("UPDATE " . BB_USERS . " SET user_newpasswd = '' WHERE user_lastvisit < " . (TIMENOW - 7 * 86400)); // Cleaning post cache -if ($posts_days = (int)$bb_cfg['posts_cache_days_keep']) { +if ($posts_days = (int)config()->get('posts_cache_days_keep')) { DB()->query("DELETE FROM " . BB_POSTS_HTML . " WHERE post_html_time < DATE_SUB(NOW(), INTERVAL $posts_days DAY)"); } // Autofill announcer url -if (empty($bb_cfg['bt_announce_url']) || ($bb_cfg['bt_announce_url'] === 'https://localhost/bt/announce.php')) { +if (empty(config()->get('bt_announce_url')) || (config()->get('bt_announce_url') === 'https://localhost/bt/announce.php')) { bb_update_config(['bt_announce_url' => FULL_URL . 'bt/announce.php']); } diff --git a/library/includes/cron/jobs/clean_dlstat.php b/library/includes/cron/jobs/clean_dlstat.php index 2c2c433b2..490254561 100644 --- a/library/includes/cron/jobs/clean_dlstat.php +++ b/library/includes/cron/jobs/clean_dlstat.php @@ -13,10 +13,10 @@ if (!defined('BB_ROOT')) { // Delete staled dl-status records $keeping_dlstat = [ - DL_STATUS_WILL => (int)$bb_cfg['dl_will_days_keep'], - DL_STATUS_DOWN => (int)$bb_cfg['dl_down_days_keep'], - DL_STATUS_COMPLETE => (int)$bb_cfg['dl_complete_days_keep'], - DL_STATUS_CANCEL => (int)$bb_cfg['dl_cancel_days_keep'] + DL_STATUS_WILL => (int)config()->get('dl_will_days_keep'), + DL_STATUS_DOWN => (int)config()->get('dl_down_days_keep'), + DL_STATUS_COMPLETE => (int)config()->get('dl_complete_days_keep'), + DL_STATUS_CANCEL => (int)config()->get('dl_cancel_days_keep') ]; $delete_dlstat_sql = []; @@ -51,7 +51,7 @@ DB()->query(" "); // Tor-Stats cleanup -if ($torstat_days_keep = (int)$bb_cfg['torstat_days_keep']) { +if ($torstat_days_keep = (int)config()->get('torstat_days_keep')) { DB()->query("DELETE QUICK FROM " . BB_BT_TORSTAT . " WHERE last_modified_torstat < DATE_SUB(NOW(), INTERVAL $torstat_days_keep DAY)"); } diff --git a/library/includes/cron/jobs/clean_log.php b/library/includes/cron/jobs/clean_log.php index c21ee2b5f..b136c298b 100644 --- a/library/includes/cron/jobs/clean_log.php +++ b/library/includes/cron/jobs/clean_log.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -$log_days_keep = (int)$bb_cfg['log_days_keep']; +$log_days_keep = (int)config()->get('log_days_keep'); if ($log_days_keep !== 0) { DB()->query("DELETE FROM " . BB_LOG . " WHERE log_time < " . (TIMENOW - 86400 * $log_days_keep)); diff --git a/library/includes/cron/jobs/clean_pm.php b/library/includes/cron/jobs/clean_pm.php index 1d4203995..abbe6d343 100644 --- a/library/includes/cron/jobs/clean_pm.php +++ b/library/includes/cron/jobs/clean_pm.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -$pm_days_keep = (int)$bb_cfg['pm_days_keep']; +$pm_days_keep = (int)config()->get('pm_days_keep'); if ($pm_days_keep !== 0) { $per_cycle = 20000; diff --git a/library/includes/cron/jobs/demo_mode.php b/library/includes/cron/jobs/demo_mode.php index cbdb252ea..ec02cc498 100644 --- a/library/includes/cron/jobs/demo_mode.php +++ b/library/includes/cron/jobs/demo_mode.php @@ -23,7 +23,7 @@ if (!IN_DEMO_MODE || !is_file($dump_path) || !is_readable($dump_path)) { // Clean cache & datastore $datastore->clean(); -foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { +foreach (config()->get('cache.engines') as $cache_name => $cache_val) { CACHE($cache_name)->rm(); } diff --git a/library/includes/cron/jobs/prune_forums.php b/library/includes/cron/jobs/prune_forums.php index 722aef2c5..473bb4156 100644 --- a/library/includes/cron/jobs/prune_forums.php +++ b/library/includes/cron/jobs/prune_forums.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -if ($bb_cfg['prune_enable']) { +if (config()->get('prune_enable')) { $sql = "SELECT forum_id, prune_days FROM " . BB_FORUMS . " WHERE prune_days != 0"; foreach (DB()->fetch_rowset($sql) as $row) { diff --git a/library/includes/cron/jobs/prune_inactive_users.php b/library/includes/cron/jobs/prune_inactive_users.php index 92b271a91..527ba0609 100644 --- a/library/includes/cron/jobs/prune_inactive_users.php +++ b/library/includes/cron/jobs/prune_inactive_users.php @@ -17,7 +17,7 @@ while (true) { set_time_limit(600); $prune_users = $not_activated_users = $not_active_users = []; - if ($not_activated_days = (int)$bb_cfg['user_not_activated_days_keep']) { + if ($not_activated_days = (int)config()->get('user_not_activated_days_keep')) { $sql = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_level = 0 AND user_lastvisit = 0 @@ -31,7 +31,7 @@ while (true) { } } - if ($not_active_days = (int)$bb_cfg['user_not_active_days_keep']) { + if ($not_active_days = (int)config()->get('user_not_active_days_keep')) { $sql = DB()->fetch_rowset("SELECT user_id FROM " . BB_USERS . " WHERE user_level = 0 AND user_posts = 0 diff --git a/library/includes/cron/jobs/prune_topic_moved.php b/library/includes/cron/jobs/prune_topic_moved.php index 9c1f6cb76..d43fa07ce 100644 --- a/library/includes/cron/jobs/prune_topic_moved.php +++ b/library/includes/cron/jobs/prune_topic_moved.php @@ -11,8 +11,8 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -if ($bb_cfg['topic_moved_days_keep']) { - $prune_time = TIMENOW - 86400 * $bb_cfg['topic_moved_days_keep']; +if (config()->get('topic_moved_days_keep')) { + $prune_time = TIMENOW - 86400 * config()->get('topic_moved_days_keep'); DB()->query(" DELETE FROM " . BB_TOPICS . " diff --git a/library/includes/cron/jobs/sessions_cleanup.php b/library/includes/cron/jobs/sessions_cleanup.php index 07fc2a76d..1f6adbc5e 100644 --- a/library/includes/cron/jobs/sessions_cleanup.php +++ b/library/includes/cron/jobs/sessions_cleanup.php @@ -11,10 +11,10 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -$user_session_expire_time = TIMENOW - (int)$bb_cfg['user_session_duration']; -$admin_session_expire_time = TIMENOW - (int)$bb_cfg['admin_session_duration']; +$user_session_expire_time = TIMENOW - (int)config()->get('user_session_duration'); +$admin_session_expire_time = TIMENOW - (int)config()->get('admin_session_duration'); -$user_session_gc_time = $user_session_expire_time - (int)$bb_cfg['user_session_gc_ttl']; +$user_session_gc_time = $user_session_expire_time - (int)config()->get('user_session_gc_ttl'); $admin_session_gc_time = $admin_session_expire_time; // ############################ Tables LOCKED ################################ diff --git a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php index a0a64251f..ecd557c71 100644 --- a/library/includes/cron/jobs/tr_cleanup_and_dlstat.php +++ b/library/includes/cron/jobs/tr_cleanup_and_dlstat.php @@ -27,7 +27,7 @@ DB()->query("CREATE TABLE " . NEW_BB_BT_LAST_USERSTAT . " LIKE " . BB_BT_LAST_US DB()->expect_slow_query(600); // Update dlstat (part 1) -if ($bb_cfg['tracker']['update_dlstat']) { +if (config()->get('tracker.update_dlstat')) { // ############################ Tables LOCKED ################################ DB()->lock([ BB_BT_TRACKER, @@ -64,16 +64,16 @@ DB()->query(" "); // Clean peers table -if ($bb_cfg['tracker']['autoclean']) { - $announce_interval = max((int)$bb_cfg['announce_interval'], 60); - $expire_factor = max((float)$bb_cfg['tracker']['expire_factor'], 1); +if (config()->get('tracker.autoclean')) { + $announce_interval = max((int)config()->get('announce_interval'), 60); + $expire_factor = max((float)config()->get('tracker.expire_factor'), 1); $peer_expire_time = TIMENOW - floor($announce_interval * $expire_factor); DB()->query("DELETE FROM " . BB_BT_TRACKER . " WHERE update_time < $peer_expire_time"); } // Update dlstat (part 2) -if ($bb_cfg['tracker']['update_dlstat']) { +if (config()->get('tracker.update_dlstat')) { // Set "only 1 seeder" bonus DB()->query(" UPDATE diff --git a/library/includes/cron/jobs/tr_maintenance.php b/library/includes/cron/jobs/tr_maintenance.php index 04dd77857..0e7e20dab 100644 --- a/library/includes/cron/jobs/tr_maintenance.php +++ b/library/includes/cron/jobs/tr_maintenance.php @@ -11,12 +11,12 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -if (empty($bb_cfg['seeder_last_seen_days_keep']) || empty($bb_cfg['seeder_never_seen_days_keep'])) { +if (empty(config()->get('seeder_last_seen_days_keep')) || empty(config()->get('seeder_never_seen_days_keep'))) { return; } -$last_seen_time = TIMENOW - 86400 * $bb_cfg['seeder_last_seen_days_keep']; -$never_seen_time = TIMENOW - 86400 * $bb_cfg['seeder_never_seen_days_keep']; +$last_seen_time = TIMENOW - 86400 * config()->get('seeder_last_seen_days_keep'); +$never_seen_time = TIMENOW - 86400 * config()->get('seeder_never_seen_days_keep'); $limit_sql = 3000; $topics_sql = $attach_sql = []; diff --git a/library/includes/cron/jobs/tr_make_snapshot.php b/library/includes/cron/jobs/tr_make_snapshot.php index 3ec24cd92..9dda76187 100644 --- a/library/includes/cron/jobs/tr_make_snapshot.php +++ b/library/includes/cron/jobs/tr_make_snapshot.php @@ -11,8 +11,6 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - DB()->expect_slow_query(600); // @@ -81,7 +79,7 @@ DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_DLSTATUS_SNAP . ", " . OLD_BB_BT DB()->query("CREATE TABLE " . NEW_BB_BT_DLSTATUS_SNAP . " LIKE " . BB_BT_DLSTATUS_SNAP); -if ($bb_cfg['bt_show_dl_list'] && $bb_cfg['bt_dl_list_only_count']) { +if (config()->get('bt_show_dl_list') && config()->get('bt_dl_list_only_count')) { DB()->query(" INSERT INTO " . NEW_BB_BT_DLSTATUS_SNAP . " (topic_id, dl_status, users_count) @@ -104,7 +102,7 @@ DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_DLSTATUS_SNAP . ", " . OLD_BB_BT // // TORHELP // -if ($bb_cfg['torhelp_enabled']) { +if (config()->get('torhelp_enabled')) { $tor_min_seeders = 0; // "<=" $tor_min_leechers = 2; // ">=" $tor_min_completed = 10; // ">=" @@ -147,7 +145,7 @@ if ($bb_cfg['torhelp_enabled']) { WHERE trsn.seeders <= $tor_min_seeders AND trsn.leechers >= $tor_min_leechers - AND tor.forum_id != " . (int)$bb_cfg['trash_forum_id'] . " + AND tor.forum_id != " . (int)config()->get('trash_forum_id') . " AND tor.complete_count >= $tor_min_completed AND tor.seeder_last_seen <= (UNIX_TIMESTAMP() - $tor_seed_last_seen_days*86400) AND dl.user_id IN($online_users_csv) diff --git a/library/includes/cron/jobs/tr_seed_bonus.php b/library/includes/cron/jobs/tr_seed_bonus.php index 83e817ea9..b3bdaf936 100644 --- a/library/includes/cron/jobs/tr_seed_bonus.php +++ b/library/includes/cron/jobs/tr_seed_bonus.php @@ -13,7 +13,7 @@ if (!defined('BB_ROOT')) { DB()->expect_slow_query(600); -if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['seed_bonus_release']) { +if (config()->get('seed_bonus_enabled') && config()->get('seed_bonus_points') && config()->get('seed_bonus_release')) { DB()->query(" CREATE TEMPORARY TABLE tmp_bonus ( user_id INT UNSIGNED NOT NULL DEFAULT '0', @@ -21,7 +21,7 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se ) ENGINE = MEMORY "); - $tor_size = ($bb_cfg['seed_bonus_tor_size'] * 1073741824); + $tor_size = (config()->get('seed_bonus_tor_size') * 1073741824); DB()->query("INSERT INTO tmp_bonus SELECT bt.user_id, count(bt.seeder) AS release_count @@ -32,8 +32,8 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se GROUP BY bt.user_id "); - $seed_bonus = unserialize($bb_cfg['seed_bonus_points']); - $seed_release = unserialize($bb_cfg['seed_bonus_release']); + $seed_bonus = unserialize(config()->get('seed_bonus_points')); + $seed_release = unserialize(config()->get('seed_bonus_release')); foreach ($seed_bonus as $i => $points) { if (!$points || !$seed_release[$i]) { @@ -42,7 +42,7 @@ if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['se $user_points = ((float)$points / 4); $release = (int)$seed_release[$i]; - $user_regdate = (TIMENOW - $bb_cfg['seed_bonus_user_regdate'] * 86400); + $user_regdate = (TIMENOW - config()->get('seed_bonus_user_regdate') * 86400); DB()->query(" UPDATE " . BB_USERS . " u, " . BB_BT_USERS . " bu, tmp_bonus b diff --git a/library/includes/cron/jobs/update_forums_atom.php b/library/includes/cron/jobs/update_forums_atom.php index e6151add0..6cbfd1973 100644 --- a/library/includes/cron/jobs/update_forums_atom.php +++ b/library/includes/cron/jobs/update_forums_atom.php @@ -11,13 +11,11 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - $timecheck = TIMENOW - 600; $forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS); -if (is_file($bb_cfg['atom']['path'] . '/f/0.atom')) { - if (filemtime($bb_cfg['atom']['path'] . '/f/0.atom') <= $timecheck) { +if (is_file(config()->get('atom.path') . '/f/0.atom')) { + if (filemtime(config()->get('atom.path') . '/f/0.atom') <= $timecheck) { \TorrentPier\Legacy\Atom::update_forum_feed(0, $forums_data); } } else { @@ -25,8 +23,8 @@ if (is_file($bb_cfg['atom']['path'] . '/f/0.atom')) { } foreach ($forums_data as $forum_data) { - if (is_file($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom')) { - if (filemtime($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom') <= $timecheck) { + if (is_file(config()->get('atom.path') . '/f/' . $forum_data['forum_id'] . '.atom')) { + if (filemtime(config()->get('atom.path') . '/f/' . $forum_data['forum_id'] . '.atom') <= $timecheck) { \TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data); } } else { diff --git a/library/includes/datastore/build_cat_forums.php b/library/includes/datastore/build_cat_forums.php index 8df40d67f..fcf71e9e3 100644 --- a/library/includes/datastore/build_cat_forums.php +++ b/library/includes/datastore/build_cat_forums.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bf, $bb_cfg; +global $bf; // // cat_forums @@ -106,7 +106,7 @@ $this->store('cat_forums', $data); // // jumpbox // -if ($bb_cfg['show_jumpbox']) { +if (config()->get('show_jumpbox')) { $data = [ 'guest' => get_forum_select('guest', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'' . FORUM_URL . '\'+this.value;"'), 'user' => get_forum_select('user', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'' . FORUM_URL . '\'+this.value;"'), @@ -125,8 +125,8 @@ $this->store('viewtopic_forum_select', $data); // // latest_news // -if ($bb_cfg['show_latest_news'] and $news_forum_ids = $bb_cfg['latest_news_forum_id']) { - $news_count = max($bb_cfg['latest_news_count'], 1); +if (config()->get('show_latest_news') and $news_forum_ids = config()->get('latest_news_forum_id')) { + $news_count = max(config()->get('latest_news_count'), 1); $data = DB()->fetch_rowset(" SELECT topic_id, topic_time, topic_title, forum_id @@ -143,8 +143,8 @@ if ($bb_cfg['show_latest_news'] and $news_forum_ids = $bb_cfg['latest_news_forum // // Network_news // -if ($bb_cfg['show_network_news'] and $net_forum_ids = $bb_cfg['network_news_forum_id']) { - $net_count = max($bb_cfg['network_news_count'], 1); +if (config()->get('show_network_news') and $net_forum_ids = config()->get('network_news_forum_id')) { + $net_count = max(config()->get('network_news_count'), 1); $data = DB()->fetch_rowset(" SELECT topic_id, topic_time, topic_title, forum_id diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php index a990d4364..416a9d4f7 100644 --- a/library/includes/datastore/build_check_updates.php +++ b/library/includes/datastore/build_check_updates.php @@ -11,19 +11,17 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - -if (!$bb_cfg['tp_updater_settings']['enabled']) { +if (!config()->get('tp_updater_settings.enabled')) { return; } $data = []; $updaterDownloader = new \TorrentPier\Updater(); -$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']); +$updaterDownloader = $updaterDownloader->getLastVersion(config()->get('tp_updater_settings.allow_pre_releases')); $getVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($updaterDownloader['tag_name']); -$currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_version']); +$currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix(config()->get('tp_version')); // Has update! if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) { diff --git a/library/includes/datastore/build_smilies.php b/library/includes/datastore/build_smilies.php index 40b9c85f7..204a92e62 100644 --- a/library/includes/datastore/build_smilies.php +++ b/library/includes/datastore/build_smilies.php @@ -11,8 +11,6 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - $smilies = []; $rowset = DB()->fetch_rowset("SELECT * FROM " . BB_SMILIES); @@ -20,7 +18,7 @@ sort($rowset); foreach ($rowset as $smile) { $smilies['orig'][] = '#(?<=^|\W)' . preg_quote($smile['code'], '#') . '(?=$|\W)#'; - $smilies['repl'][] = ' ' . $smile['code'] . ''; + $smilies['repl'][] = ' ' . $smile['code'] . ''; $smilies['smile'][] = $smile; } diff --git a/library/includes/datastore/build_stats.php b/library/includes/datastore/build_stats.php index e25d8e085..86fd14a35 100644 --- a/library/includes/datastore/build_stats.php +++ b/library/includes/datastore/build_stats.php @@ -11,8 +11,6 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - $data = []; // usercount @@ -29,7 +27,7 @@ $data['postcount'] = commify($row['postcount']); $data['topiccount'] = commify($row['topiccount']); // Tracker stats -if ($bb_cfg['tor_stats']) { +if (config()->get('tor_stats')) { // torrents stat $row = DB()->fetch_row("SELECT COUNT(topic_id) AS torrentcount, SUM(size) AS size FROM " . BB_BT_TORRENTS); $data['torrentcount'] = commify($row['torrentcount']); @@ -44,7 +42,7 @@ if ($bb_cfg['tor_stats']) { } // gender stat -if ($bb_cfg['gender']) { +if (config()->get('gender')) { $male = DB()->fetch_row("SELECT COUNT(user_id) AS male FROM " . BB_USERS . " WHERE user_gender = " . MALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")"); $female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM " . BB_USERS . " WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")"); $unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM " . BB_USERS . " WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS . ")"); @@ -55,7 +53,7 @@ if ($bb_cfg['gender']) { } // birthday stat -if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { +if (config()->get('birthday_check_day') && config()->get('birthday_enabled')) { $sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ") @@ -66,7 +64,7 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { "); $date_today = bb_date(TIMENOW, 'md', false); - $date_forward = bb_date(TIMENOW + ($bb_cfg['birthday_check_day'] * 86400), 'md', false); + $date_forward = bb_date(TIMENOW + (config()->get('birthday_check_day') * 86400), 'md', false); $birthday_today_list = $birthday_week_list = []; diff --git a/library/includes/functions.php b/library/includes/functions.php index 67256eb1f..c569b55b3 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -13,22 +13,19 @@ if (!defined('BB_ROOT')) { function get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div) { - global $bb_cfg; - $ext = $bb_cfg['file_id_ext'][$ext_id] ?? ''; + $ext = config()->get('file_id_ext')[$ext_id] ?? ''; return ($base_path ? "$base_path/" : '') . floor($id / $first_div) . '/' . ($id % $sec_div) . '/' . $id . ($ext ? ".$ext" : ''); } function get_avatar_path($id, $ext_id, $base_path = null, $first_div = 10000, $sec_div = 100) { - global $bb_cfg; - $base_path ??= $bb_cfg['avatars']['upload_path']; + $base_path ??= config()->get('avatars.upload_path'); return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div); } function get_attach_path($id, $ext_id = '', $base_path = null, $first_div = 10000, $sec_div = 100) { - global $bb_cfg; - $base_path ??= $bb_cfg['attach']['upload_path']; + $base_path ??= config()->get('attach.upload_path'); return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div); } @@ -600,8 +597,6 @@ function humn_size($size, $rounder = null, $min = null, $space = ' ') function bt_show_ip($ip, $port = '') { - global $bb_cfg; - if (IS_AM) { $ip = \TorrentPier\Helpers\IPHelper::long2ip_extended($ip); @@ -617,18 +612,16 @@ function bt_show_ip($ip, $port = '') return $ip; } - return $bb_cfg['bt_show_ip_only_moder'] ? false : \TorrentPier\Helpers\IPHelper::anonymizeIP($ip); + return config()->get('bt_show_ip_only_moder') ? false : \TorrentPier\Helpers\IPHelper::anonymizeIP($ip); } function bt_show_port($port) { - global $bb_cfg; - if (IS_AM) { return $port; } - return $bb_cfg['bt_show_port_only_moder'] ? false : $port; + return config()->get('bt_show_port_only_moder') ? false : $port; } function checkbox_get_val(&$key, &$val, $default = 1, $on = 1, $off = 0) @@ -802,24 +795,24 @@ function str_short($text, $max_length, $space = ' ') function generate_user_info($row, bool $have_auth = IS_ADMIN): array { - global $userdata, $lang, $images, $bb_cfg; + global $userdata, $lang, $images; $from = !empty($row['user_from']) ? render_flag($row['user_from'], false) : $lang['NOSELECT']; $joined = bb_date($row['user_regdate'], 'Y-m-d H:i', false); $user_time = !empty($row['user_time']) ? sprintf('%s (%s)', bb_date($row['user_time']), delta_time($row['user_time'])) : $lang['NOSELECT']; $posts = '' . $row['user_posts'] ?: 0 . ''; - $pm = $bb_cfg['text_buttons'] ? '' . $lang['SEND_PM_TXTB'] . '' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; + $pm = config()->get('text_buttons') ? '' . $lang['SEND_PM_TXTB'] . '' : '' . $lang['SEND_PRIVATE_MESSAGE'] . ''; $avatar = get_avatar($row['user_id'], $row['avatar_ext_id'], !bf($row['user_opt'], 'user_opt', 'dis_avatar'), 50, 50); if (bf($row['user_opt'], 'user_opt', 'user_viewemail') || $have_auth || ($row['user_id'] == $userdata['user_id'])) { - $email_uri = ($bb_cfg['board_email_form']) ? ("profile.php?mode=email&" . POST_USERS_URL . "=" . $row['user_id']) : 'mailto:' . $row['user_email']; + $email_uri = (config()->get('board_email_form')) ? ("profile.php?mode=email&" . POST_USERS_URL . "=" . $row['user_id']) : 'mailto:' . $row['user_email']; $email = '' . $row['user_email'] . ''; } else { $email = $lang['HIDDEN_USER']; } if ($row['user_website']) { - $www = $bb_cfg['text_buttons'] ? '' . $lang['VISIT_WEBSITE_TXTB'] . '' : '' . $lang['VISIT_WEBSITE'] . ''; + $www = config()->get('text_buttons') ? '' . $lang['VISIT_WEBSITE_TXTB'] . '' : '' . $lang['VISIT_WEBSITE'] . ''; } else { $www = $lang['NOSELECT']; } @@ -996,9 +989,9 @@ function get_userdata(int|string $u, bool $is_name = false, bool $allow_guest = function make_jumpbox(): void { - global $datastore, $template, $bb_cfg; + global $datastore, $template; - if (!$bb_cfg['show_jumpbox']) { + if (!config()->get('show_jumpbox')) { return; } @@ -1076,14 +1069,14 @@ function get_forum_select($mode = 'guest', $name = POST_FORUM_URL, $selected = n function setup_style() { - global $bb_cfg, $template, $userdata; + global $template, $userdata; // AdminCP works only with default template - $tpl_dir_name = defined('IN_ADMIN') ? 'default' : basename($bb_cfg['tpl_name']); - $stylesheet = defined('IN_ADMIN') ? 'main.css' : basename($bb_cfg['stylesheet']); + $tpl_dir_name = defined('IN_ADMIN') ? 'default' : basename(config()->get('tpl_name')); + $stylesheet = defined('IN_ADMIN') ? 'main.css' : basename(config()->get('stylesheet')); if (!IS_GUEST && !empty($userdata['tpl_name'])) { - foreach ($bb_cfg['templates'] as $folder => $name) { + foreach (config()->get('templates') as $folder => $name) { if ($userdata['tpl_name'] == $folder) { $tpl_dir_name = basename($userdata['tpl_name']); } @@ -1096,7 +1089,7 @@ function setup_style() $template->assign_vars([ 'SPACER' => make_url('styles/images/spacer.gif'), 'STYLESHEET' => make_url($css_dir . $stylesheet), - 'EXT_LINK_NEW_WIN' => $bb_cfg['ext_link_new_win'], + 'EXT_LINK_NEW_WIN' => config()->get('ext_link_new_win'), 'TPL_DIR' => make_url($css_dir), 'SITE_URL' => make_url('/') ]); @@ -1109,19 +1102,19 @@ function setup_style() // Create date / time with format and friendly date function bb_date($gmepoch, $format = false, $friendly_date = true) { - global $bb_cfg, $lang, $userdata; + global $lang, $userdata; $gmepoch = (int)$gmepoch; if (!$format) { - $format = $bb_cfg['default_dateformat']; + $format = config()->get('default_dateformat'); } if (empty($lang)) { - require_once($bb_cfg['default_lang_dir'] . 'main.php'); + require_once(config()->get('default_lang_dir') . 'main.php'); } if (!defined('IS_GUEST') || IS_GUEST) { - $tz = $bb_cfg['board_timezone']; + $tz = config()->get('board_timezone'); } else { $tz = $userdata['user_timezone']; } @@ -1156,7 +1149,7 @@ function bb_date($gmepoch, $format = false, $friendly_date = true) } } - return ($bb_cfg['translate_dates']) ? strtr(strtoupper($date), $lang['DATETIME']) : $date; + return (config()->get('translate_dates')) ? strtr(strtoupper($date), $lang['DATETIME']) : $date; } /** @@ -1167,12 +1160,11 @@ function bb_date($gmepoch, $format = false, $friendly_date = true) */ function get_user_torrent_client(string $peer_id): string { - global $bb_cfg; static $iconExtension = '.png'; $bestMatch = null; $bestMatchLength = 0; - foreach ($bb_cfg['tor_clients'] as $key => $clientName) { + foreach (config()->get('tor_clients') as $key => $clientName) { if (str_starts_with($peer_id, $key) !== false && strlen($key) > $bestMatchLength) { $bestMatch = $clientName; $bestMatchLength = strlen($key); @@ -1223,12 +1215,11 @@ function render_flag(string $code, bool $showName = true): string function birthday_age($date) { - global $bb_cfg; if (!$date) { return ''; } - $tz = TIMENOW + (3600 * $bb_cfg['board_timezone']); + $tz = TIMENOW + (3600 * config()->get('board_timezone')); return delta_time(strtotime($date, $tz)); } @@ -1339,7 +1330,7 @@ function bb_preg_quote($str, $delimiter) function bb_die($msg_text, $status_code = null) { - global $ajax, $bb_cfg, $lang, $template, $theme, $userdata, $user; + global $ajax, $lang, $template, $theme, $userdata, $user; if (isset($status_code)) { http_response_code($status_code); @@ -1358,7 +1349,7 @@ function bb_die($msg_text, $status_code = null) // If empty lang if (empty($lang)) { - require($bb_cfg['default_lang_dir'] . 'main.php'); + require(config()->get('default_lang_dir') . 'main.php'); } // If empty session @@ -1369,7 +1360,7 @@ function bb_die($msg_text, $status_code = null) // If the header hasn't been output then do it if (!defined('PAGE_HEADER_SENT')) { if (empty($template)) { - $template = new TorrentPier\Legacy\Template(BB_ROOT . "templates/{$bb_cfg['tpl_name']}"); + $template = new TorrentPier\Legacy\Template(BB_ROOT . "templates/" . config()->get('tpl_name')); } if (empty($theme)) { $theme = setup_style(); @@ -1397,8 +1388,6 @@ function bb_die($msg_text, $status_code = null) function bb_simple_die($txt, $status_code = null) { - global $bb_cfg; - header('Content-Type: text/plain; charset=' . DEFAULT_CHARSET); if (isset($status_code)) { @@ -1426,8 +1415,6 @@ function meta_refresh($url, $time = 5) function redirect($url) { - global $bb_cfg; - if (headers_sent($filename, $linenum)) { trigger_error("Headers already sent in $filename($linenum)", E_USER_ERROR); } @@ -1437,11 +1424,11 @@ function redirect($url) } $url = trim($url); - $server_protocol = ($bb_cfg['cookie_secure']) ? 'https://' : 'http://'; + $server_protocol = (config()->get('cookie_secure')) ? 'https://' : 'http://'; - $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($bb_cfg['server_name'])); - $server_port = ($bb_cfg['server_port'] <> 80) ? ':' . trim($bb_cfg['server_port']) : ''; - $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($bb_cfg['script_path'])); + $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim(config()->get('server_name'))); + $server_port = (config()->get('server_port') <> 80) ? ':' . trim(config()->get('server_port')) : ''; + $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim(config()->get('script_path'))); if ($script_name) { $script_name = "/$script_name"; @@ -1549,9 +1536,9 @@ function cat_exists($cat_id): bool function get_topic_icon($topic, $is_unread = null) { - global $bb_cfg, $images; + global $images; - $t_hot = ($topic['topic_replies'] >= $bb_cfg['hot_threshold']); + $t_hot = ($topic['topic_replies'] >= config()->get('hot_threshold')); $is_unread ??= is_unread($topic['topic_last_post_time'], $topic['topic_id'], $topic['forum_id']); if ($topic['topic_status'] == TOPIC_MOVED) { @@ -1684,7 +1671,7 @@ function clean_title($str, $replace_underscore = false) function clean_text_match($text, $ltrim_star = true, $die_if_empty = false) { - global $bb_cfg, $lang; + global $lang; $text = str_compact($text); $ltrim_chars = ($ltrim_star) ? ' *-!' : ' '; @@ -1692,7 +1679,7 @@ function clean_text_match($text, $ltrim_star = true, $die_if_empty = false) $text = ' ' . str_compact(ltrim($text, $ltrim_chars)) . ' '; - if ($bb_cfg['search_engine_type'] == 'sphinx') { + if (config()->get('search_engine_type') == 'sphinx') { $text = preg_replace('#(?<=\S)\-#u', ' ', $text); // "1-2-3" -> "1 2 3" $text = preg_replace('#[^0-9a-zA-Zа-яА-ЯёЁ\-_*|]#u', ' ', $text); // valid characters (except '"' which are separate) $text = str_replace(['-', '*'], [' -', '* '], $text); // only at the beginning/end of a word @@ -1742,7 +1729,7 @@ function log_sphinx_error($err_type, $err_msg, $query = '') function get_title_match_topics($title_match_sql, array $forum_ids = []) { - global $bb_cfg, $sphinx, $userdata, $title_match, $lang; + global $sphinx, $userdata, $title_match, $lang; $where_ids = []; if ($forum_ids) { @@ -1750,12 +1737,12 @@ function get_title_match_topics($title_match_sql, array $forum_ids = []) } $title_match_sql = encode_text_match($title_match_sql); - if ($bb_cfg['search_engine_type'] == 'sphinx') { + if (config()->get('search_engine_type') == 'sphinx') { $sphinx = init_sphinx(); $where = $title_match ? 'topics' : 'posts'; - $sphinx->setServer($bb_cfg['sphinx_topic_titles_host'], $bb_cfg['sphinx_topic_titles_port']); + $sphinx->setServer(config()->get('sphinx_topic_titles_host'), config()->get('sphinx_topic_titles_port')); if ($forum_ids) { $sphinx->setFilter('forum_id', $forum_ids, false); } @@ -1775,9 +1762,9 @@ function get_title_match_topics($title_match_sql, array $forum_ids = []) if ($warning = $sphinx->getLastWarning()) { log_sphinx_error('wrn', $warning, $title_match_sql); } - } elseif ($bb_cfg['search_engine_type'] == 'mysql') { + } elseif (config()->get('search_engine_type') == 'mysql') { $where_forum = ($forum_ids) ? "AND forum_id IN(" . implode(',', $forum_ids) . ")" : ''; - $search_bool_mode = ($bb_cfg['allow_search_in_bool_mode']) ? ' IN BOOLEAN MODE' : ''; + $search_bool_mode = (config()->get('allow_search_in_bool_mode')) ? ' IN BOOLEAN MODE' : ''; if ($title_match) { $where_id = 'topic_id'; @@ -1832,14 +1819,14 @@ function decode_text_match($txt) */ function create_magnet(string $infohash, string $infohash_v2, string $auth_key, string $name, int|string $length = 0): string { - global $bb_cfg, $images, $lang; + global $images, $lang; - if (!$bb_cfg['magnet_links_enabled']) { + if (!config()->get('magnet_links_enabled')) { return false; } // Only for registered users - if (!$bb_cfg['magnet_links_for_guests'] && IS_GUEST) { + if (!config()->get('magnet_links_for_guests') && IS_GUEST) { return false; } @@ -1864,7 +1851,7 @@ function create_magnet(string $infohash, string $infohash_v2, string $auth_key, $magnet .= '&xl=' . $length; } - return ''; + return 'get('passkey_key') . "=$auth_key") . '&dn=' . urlencode($name) . '">'; } function set_die_append_msg($forum_id = null, $topic_id = null, $group_id = null) @@ -1925,7 +1912,7 @@ function send_pm($user_id, $subject, $message, $poster_id = BOT_UID) */ function profile_url(array $data, bool $target_blank = false, bool $no_link = false): string { - global $bb_cfg, $lang, $datastore; + global $lang, $datastore; if (!$ranks = $datastore->get('ranks')) { $datastore->update('ranks'); @@ -1940,7 +1927,7 @@ function profile_url(array $data, bool $target_blank = false, bool $no_link = fa $style = 'colorUser'; if (isset($ranks[$user_rank])) { $title = $ranks[$user_rank]['rank_title']; - if ($bb_cfg['color_nick']) { + if (config()->get('color_nick')) { $style = $ranks[$user_rank]['rank_style']; } } @@ -1968,18 +1955,16 @@ function profile_url(array $data, bool $target_blank = false, bool $no_link = fa function get_avatar($user_id, $ext_id, $allow_avatar = true, $height = '', $width = '') { - global $bb_cfg; - $height = $height ? 'height="' . $height . '"' : ''; $width = $width ? 'width="' . $width . '"' : ''; - $user_avatar = '' . $user_id . ''; + $user_avatar = '' . $user_id . ''; - if ($user_id == BOT_UID && $bb_cfg['avatars']['bot_avatar']) { - $user_avatar = '' . $user_id . ''; + if ($user_id == BOT_UID && config()->get('avatars.bot_avatar')) { + $user_avatar = '' . $user_id . ''; } elseif ($allow_avatar && $ext_id) { if (is_file(get_avatar_path($user_id, $ext_id))) { - $user_avatar = '' . $user_id . ''; + $user_avatar = '' . $user_id . ''; } } @@ -1994,9 +1979,9 @@ function get_avatar($user_id, $ext_id, $allow_avatar = true, $height = '', $widt */ function genderImage(int $gender): ?string { - global $bb_cfg, $lang, $images; + global $lang, $images; - if (!$bb_cfg['gender']) { + if (!config()->get('gender')) { return false; } @@ -2009,12 +1994,12 @@ function genderImage(int $gender): ?string function is_gold($type): string { - global $lang, $bb_cfg, $images; + global $lang, $images; $type = (int)$type; $is_gold = ''; - if (!$bb_cfg['tracker']['gold_silver_enabled']) { + if (!config()->get('tracker.gold_silver_enabled')) { return $is_gold; } @@ -2083,10 +2068,10 @@ function hash_search($hash) */ function bb_captcha(string $mode): bool|string { - global $bb_cfg, $lang; + global $lang; - $settings = $bb_cfg['captcha']; - $settings['language'] = $bb_cfg['default_lang']; + $settings = config()->get('captcha'); + $settings['language'] = config()->get('default_lang'); // Checking captcha settings if (!$settings['disabled'] && $settings['service'] !== 'text') { @@ -2138,13 +2123,13 @@ function clean_tor_dirname($dirname) */ function user_birthday_icon($user_birthday, $user_id): string { - global $bb_cfg, $images, $lang; + global $images, $lang; $current_date = bb_date(TIMENOW, 'md', false); $user_birthday = ($user_id != GUEST_UID && !empty($user_birthday) && $user_birthday != '1900-01-01') ? bb_date(strtotime($user_birthday), 'md', false) : false; - return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '' . $lang['HAPPY_BIRTHDAY'] . '' : ''; + return (config()->get('birthday_enabled') && $current_date == $user_birthday) ? '' . $lang['HAPPY_BIRTHDAY'] . '' : ''; } /** @@ -2190,9 +2175,7 @@ function readUpdaterFile(): array|bool */ function infoByIP(string $ipAddress, int $port = 0): array { - global $bb_cfg; - - if (!$bb_cfg['ip2country_settings']['enabled']) { + if (!config()->get('ip2country_settings.enabled')) { return []; } @@ -2203,14 +2186,14 @@ function infoByIP(string $ipAddress, int $port = 0): array $data = []; $contextOptions = []; - if (!empty($bb_cfg['ip2country_settings']['api_token'])) { + if (!empty(config()->get('ip2country_settings.api_token'))) { $contextOptions['http'] = [ - 'header' => "Authorization: Bearer " . $bb_cfg['ip2country_settings']['api_token'] . "\r\n" + 'header' => "Authorization: Bearer " . config()->get('ip2country_settings.api_token') . "\r\n" ]; } $context = stream_context_create($contextOptions); - $response = file_get_contents($bb_cfg['ip2country_settings']['endpoint'] . $ipAddress, context: $context); + $response = file_get_contents(config()->get('ip2country_settings.endpoint') . $ipAddress, context: $context); if ($response !== false) { $json = json_decode($response, true); diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 932dba5a1..622e696cf 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -39,9 +39,7 @@ function send_page($contents) */ function compress_output($contents) { - global $bb_cfg; - - if ($bb_cfg['gzip_compress'] && GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) { + if (config()->get('gzip_compress') && GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) { if (UA_GZIP_SUPPORTED && strlen($contents) > 2000) { header('Content-Encoding: gzip'); $contents = gzencode($contents, 1); @@ -59,7 +57,7 @@ if (!defined('IN_AJAX')) { } // Cookie params -$c = $bb_cfg['cookie_prefix']; +$c = config()->get('cookie_prefix'); define('COOKIE_DATA', $c . 'data'); define('COOKIE_FORUM', $c . 'f'); define('COOKIE_MARK', $c . 'mark_read'); @@ -85,16 +83,14 @@ define('COOKIE_MAX_TRACKS', 90); */ function bb_setcookie(string $name, mixed $val, int $lifetime = COOKIE_PERSIST, bool $httponly = false, bool $isRaw = false): void { - global $bb_cfg; - $cookie = new \Josantonius\Cookie\Cookie( - domain: $bb_cfg['cookie_domain'], + domain: config()->get('cookie_domain'), expires: $lifetime, httpOnly: $httponly, - path: $bb_cfg['script_path'], + path: config()->get('script_path'), raw: $isRaw, - sameSite: $bb_cfg['cookie_same_site'], - secure: $bb_cfg['cookie_secure'] + sameSite: config()->get('cookie_same_site'), + secure: config()->get('cookie_secure') ); if (!empty($val)) { @@ -275,14 +271,14 @@ define('PAGE_HEADER', INC_DIR . '/page_header.php'); define('PAGE_FOOTER', INC_DIR . '/page_footer.php'); define('CAT_URL', 'index.php?' . POST_CAT_URL . '='); -define('DL_URL', $bb_cfg['dl_url']); +define('DL_URL', config()->get('dl_url')); define('FORUM_URL', 'viewforum.php?' . POST_FORUM_URL . '='); define('GROUP_URL', 'group.php?' . POST_GROUPS_URL . '='); -define('LOGIN_URL', $bb_cfg['login_url']); +define('LOGIN_URL', config()->get('login_url')); define('MODCP_URL', 'modcp.php?' . POST_FORUM_URL . '='); -define('PM_URL', $bb_cfg['pm_url']); +define('PM_URL', config()->get('pm_url')); define('POST_URL', 'viewtopic.php?' . POST_POST_URL . '='); -define('POSTING_URL', $bb_cfg['posting_url']); +define('POSTING_URL', config()->get('posting_url')); define('PROFILE_URL', 'profile.php?mode=viewprofile&' . POST_USERS_URL . '='); define('BONUS_URL', 'profile.php?mode=bonus'); define('TOPIC_URL', 'viewtopic.php?' . POST_TOPIC_URL . '='); @@ -378,7 +374,10 @@ function make_url(string $path = ''): string */ require_once INC_DIR . '/functions.php'; -$bb_cfg = array_merge(bb_get_config(BB_CONFIG), $bb_cfg); +// Merge database configuration with base configuration using singleton +// bb_cfg deprecated, but kept for compatibility with non-adapted code +config()->merge(bb_get_config(BB_CONFIG)); +$bb_cfg = config()->all(); $log_action = new TorrentPier\Legacy\LogAction(); $wordCensor = new TorrentPier\Censor(); @@ -396,7 +395,7 @@ if ( !is_file(CRON_RUNNING) && (TorrentPier\Helpers\CronHelper::isEnabled() || defined('START_CRON')) ) { - if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) { + if (TIMENOW - config()->get('cron_last_check') > config()->get('cron_check_interval')) { /** Update cron_last_check */ bb_update_config(['cron_last_check' => TIMENOW + 10]); @@ -436,8 +435,8 @@ if ( /** * Exit if board is disabled via trigger */ -if (($bb_cfg['board_disable'] || is_file(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) { - if ($bb_cfg['board_disable']) { +if ((config()->get('board_disable') || is_file(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) { + if (config()->get('board_disable')) { // admin lock send_no_cache_headers(); bb_die('BOARD_DISABLE', 503); diff --git a/library/includes/online_userlist.php b/library/includes/online_userlist.php index 7434f79ea..ca3651e72 100644 --- a/library/includes/online_userlist.php +++ b/library/includes/online_userlist.php @@ -116,7 +116,7 @@ if (!$online['userlist']) { $total_online = $logged_online + $guests_online; -if ($total_online > $bb_cfg['record_online_users']) { +if ($total_online > config()->get('record_online_users')) { bb_update_config([ 'record_online_users' => $total_online, 'record_online_date' => TIMENOW diff --git a/library/includes/page_footer.php b/library/includes/page_footer.php index 2eadbe6f2..80b15b559 100644 --- a/library/includes/page_footer.php +++ b/library/includes/page_footer.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg, $userdata, $template, $DBS, $lang; +global $userdata, $template, $DBS, $lang; if (!empty($template)) { $birthday_tp = ((string)bb_date(TIMENOW, 'd.m', false) === '04.04') ? ' | 🎉🍰💚' : ''; @@ -29,7 +29,7 @@ if (!empty($template)) { $show_dbg_info = (DBG_USER && !(isset($_GET['pane']) && $_GET['pane'] == 'left')); -if (!$bb_cfg['gzip_compress']) { +if (!config()->get('gzip_compress')) { flush(); } @@ -37,7 +37,7 @@ if ($show_dbg_info) { $gen_time = utime() - TIMESTART; $gen_time_txt = sprintf('%.3f', $gen_time); $gzip_text = UA_GZIP_SUPPORTED ? "{$lang['GZIP_COMPRESSION']}: " : "{$lang['GZIP_COMPRESSION']}: "; - $gzip_text .= $bb_cfg['gzip_compress'] ? $lang['ON'] : $lang['OFF']; + $gzip_text .= config()->get('gzip_compress') ? $lang['ON'] : $lang['OFF']; $stat = '[  ' . $lang['EXECUTION_TIME'] . " $gen_time_txt " . $lang['SEC']; @@ -51,7 +51,7 @@ if ($show_dbg_info) { $stat .= "  |  $gzip_text"; $stat .= '  |  ' . $lang['MEMORY']; - $stat .= humn_size($bb_cfg['mem_on_start'], 2) . ' / '; + $stat .= humn_size(config()->get('mem_on_start'), 2) . ' / '; $stat .= humn_size(sys('mem_peak'), 2) . ' / '; $stat .= humn_size(sys('mem'), 2); @@ -83,7 +83,7 @@ echo ' if (defined('REQUESTED_PAGE') && !defined('DISABLE_CACHING_OUTPUT')) { if (IS_GUEST === true) { - caching_output(true, 'store', REQUESTED_PAGE . '_guest_' . $bb_cfg['default_lang']); + caching_output(true, 'store', REQUESTED_PAGE . '_guest_' . config()->get('default_lang')); } } diff --git a/library/includes/page_header.php b/library/includes/page_header.php index 195bcec10..e3bdc3e12 100644 --- a/library/includes/page_header.php +++ b/library/includes/page_header.php @@ -16,7 +16,7 @@ if (defined('PAGE_HEADER_SENT')) { } // Parse and show the overall page header -global $page_cfg, $userdata, $user, $ads, $bb_cfg, $template, $lang, $images; +global $page_cfg, $userdata, $user, $ads, $template, $lang, $images; $logged_in = (int)!empty($userdata['session_logged_in']); @@ -52,7 +52,7 @@ if (defined('SHOW_ONLINE') && SHOW_ONLINE) { 'TOTAL_USERS_ONLINE' => ${$online_list}['stat'], 'LOGGED_IN_USER_LIST' => ${$online_list}['userlist'], 'USERS_ONLINE_COUNTS' => ${$online_list}['cnt'], - 'RECORD_USERS' => sprintf($lang['RECORD_ONLINE_USERS'], $bb_cfg['record_online_users'], bb_date($bb_cfg['record_online_date'])), + 'RECORD_USERS' => sprintf($lang['RECORD_ONLINE_USERS'], config()->get('record_online_users'), bb_date(config()->get('record_online_date'))), ]); } @@ -122,12 +122,12 @@ $template->assign_vars([ 'USER_OPTIONS_JS' => IS_GUEST ? '{}' : json_encode($user->opt_js, JSON_THROW_ON_ERROR), 'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']), - 'ALLOW_ROBOTS' => !$bb_cfg['board_disable'] && (!isset($page_cfg['allow_robots']) || $page_cfg['allow_robots'] === true), + 'ALLOW_ROBOTS' => !config()->get('board_disable') && (!isset($page_cfg['allow_robots']) || $page_cfg['allow_robots'] === true), 'META_DESCRIPTION' => !empty($page_cfg['meta_description']) ? trim(htmlCHR($page_cfg['meta_description'])) : '', - 'SITENAME' => $bb_cfg['sitename'], + 'SITENAME' => config()->get('sitename'), 'U_INDEX' => BB_ROOT . 'index.php', - 'T_INDEX' => sprintf($lang['FORUM_INDEX'], $bb_cfg['sitename']), + 'T_INDEX' => sprintf($lang['FORUM_INDEX'], config()->get('sitename')), 'IS_GUEST' => IS_GUEST, 'IS_USER' => IS_USER, @@ -138,9 +138,9 @@ $template->assign_vars([ 'FORUM_PATH' => FORUM_PATH, 'FULL_URL' => FULL_URL, - 'CURRENT_TIME' => sprintf($lang['CURRENT_TIME'], bb_date(TIMENOW, $bb_cfg['last_visit_date_format'], false)), - 'S_TIMEZONE' => preg_replace('/\(.*?\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', (float)$bb_cfg['board_timezone'])])), - 'BOARD_TIMEZONE' => $bb_cfg['board_timezone'], + 'CURRENT_TIME' => sprintf($lang['CURRENT_TIME'], bb_date(TIMENOW, config()->get('last_visit_date_format'), false)), + 'S_TIMEZONE' => preg_replace('/\(.*?\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', (float)config()->get('board_timezone'))])), + 'BOARD_TIMEZONE' => config()->get('board_timezone'), 'PM_INFO' => $pm_info, 'PRIVMSG_IMG' => $icon_pm, @@ -151,7 +151,7 @@ $template->assign_vars([ 'THIS_USER' => profile_url($userdata), 'THIS_AVATAR' => get_avatar($userdata['user_id'], $userdata['avatar_ext_id'], !bf($userdata['user_opt'], 'user_opt', 'dis_avatar')), 'SHOW_LOGIN_LINK' => !defined('IN_LOGIN'), - 'AUTOLOGIN_DISABLED' => !$bb_cfg['allow_autologin'], + 'AUTOLOGIN_DISABLED' => !config()->get('allow_autologin'), 'S_LOGIN_ACTION' => LOGIN_URL, 'U_CUR_DOWNLOADS' => PROFILE_URL . $userdata['user_id'], @@ -167,11 +167,11 @@ $template->assign_vars([ 'U_REGISTER' => 'profile.php?mode=register', 'U_SEARCH' => 'search.php', 'U_SEND_PASSWORD' => "profile.php?mode=sendpassword", - 'U_TERMS' => $bb_cfg['terms_and_conditions_url'], + 'U_TERMS' => config()->get('terms_and_conditions_url'), 'U_TRACKER' => 'tracker.php', - 'SHOW_SIDEBAR1' => !empty($bb_cfg['page']['show_sidebar1'][BB_SCRIPT]) || $bb_cfg['show_sidebar1_on_every_page'], - 'SHOW_SIDEBAR2' => !empty($bb_cfg['page']['show_sidebar2'][BB_SCRIPT]) || $bb_cfg['show_sidebar2_on_every_page'], + 'SHOW_SIDEBAR1' => !empty(config()->get('page.show_sidebar1')[BB_SCRIPT]) || config()->get('show_sidebar1_on_every_page'), + 'SHOW_SIDEBAR2' => !empty(config()->get('page.show_sidebar2')[BB_SCRIPT]) || config()->get('show_sidebar2_on_every_page'), 'HTML_AGREEMENT' => LANG_DIR . 'html/user_agreement.html', 'HTML_COPYRIGHT' => LANG_DIR . 'html/copyright_holders.html', @@ -185,11 +185,11 @@ $template->assign_vars([ 'DOWNLOAD_URL' => BB_ROOT . DL_URL, 'FORUM_URL' => BB_ROOT . FORUM_URL, 'GROUP_URL' => BB_ROOT . GROUP_URL, - 'LOGIN_URL' => $bb_cfg['login_url'], + 'LOGIN_URL' => config()->get('login_url'), 'NEWEST_URL' => '&view=newest#newest', - 'PM_URL' => $bb_cfg['pm_url'], + 'PM_URL' => config()->get('pm_url'), 'POST_URL' => BB_ROOT . POST_URL, - 'POSTING_URL' => $bb_cfg['posting_url'], + 'POSTING_URL' => config()->get('posting_url'), 'PROFILE_URL' => BB_ROOT . PROFILE_URL, 'BONUS_URL' => BB_ROOT . BONUS_URL, 'TOPIC_URL' => BB_ROOT . TOPIC_URL, @@ -208,7 +208,7 @@ $template->assign_vars([ 'U_WATCHED_TOPICS' => 'profile.php?mode=watch' ]); -if (!empty($bb_cfg['page']['show_torhelp'][BB_SCRIPT]) && !empty($userdata['torhelp'])) { +if (!empty(config()->get('page.show_torhelp')[BB_SCRIPT]) && !empty($userdata['torhelp'])) { $ignore_time = !empty($_COOKIE['torhelp']) ? (int)$_COOKIE['torhelp'] : 0; if (TIMENOW > $ignore_time) { @@ -249,6 +249,6 @@ $template->pparse('page_header'); define('PAGE_HEADER_SENT', true); -if (!$bb_cfg['gzip_compress']) { +if (!config()->get('gzip_compress')) { flush(); } diff --git a/library/includes/torrent_show_dl_list.php b/library/includes/torrent_show_dl_list.php index b5384f4ad..02e1f6f7b 100644 --- a/library/includes/torrent_show_dl_list.php +++ b/library/includes/torrent_show_dl_list.php @@ -21,12 +21,12 @@ $dl_users_div_style_overflow = "padding: 6px; height: $dl_users_overflow_div_hei $template->assign_vars(['DL_BUTTONS' => false]); -$count_mode = ($bb_cfg['bt_dl_list_only_count'] && !(@$_GET['dl'] === 'names')); +$count_mode = (config()->get('bt_dl_list_only_count') && !(@$_GET['dl'] === 'names')); -$have_dl_buttons_enabled = ($bb_cfg['bt_show_dl_but_will'] || $bb_cfg['bt_show_dl_but_down'] || $bb_cfg['bt_show_dl_but_compl'] || $bb_cfg['bt_show_dl_but_cancel']); -$dl_topic = ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL && !($bb_cfg['bt_dl_list_only_1st_page'] && $start)); -$show_dl_list = ($dl_topic && ($bb_cfg['bt_show_dl_list'] || ($bb_cfg['allow_dl_list_names_mode'] && @$_GET['dl'] === 'names'))); -$show_dl_buttons = (!IS_GUEST && $dl_topic && $bb_cfg['bt_show_dl_list_buttons']); +$have_dl_buttons_enabled = (config()->get('bt_show_dl_but_will') || config()->get('bt_show_dl_but_down') || config()->get('bt_show_dl_but_compl') || config()->get('bt_show_dl_but_cancel')); +$dl_topic = ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL && !(config()->get('bt_dl_list_only_1st_page') && $start)); +$show_dl_list = ($dl_topic && (config()->get('bt_show_dl_list') || (config()->get('allow_dl_list_names_mode') && @$_GET['dl'] === 'names'))); +$show_dl_buttons = (!IS_GUEST && $dl_topic && config()->get('bt_show_dl_list_buttons')); // link to clear DL-List $template->assign_vars(['S_DL_DELETE' => false]); @@ -99,7 +99,7 @@ if ($show_dl_list) { ]); } } - } elseif ($bb_cfg['bt_show_dl_list_buttons'] && $have_dl_buttons_enabled) { + } elseif (config()->get('bt_show_dl_list_buttons') && $have_dl_buttons_enabled) { $template->assign_block_vars('dl_list_none', []); } } @@ -107,10 +107,10 @@ if ($show_dl_list) { if ($show_dl_buttons) { $template->assign_vars([ 'DL_BUTTONS' => true, - 'DL_BUT_WILL' => $bb_cfg['bt_show_dl_but_will'], - 'DL_BUT_DOWN' => $bb_cfg['bt_show_dl_but_down'], - 'DL_BUT_COMPL' => $bb_cfg['bt_show_dl_but_compl'], - 'DL_BUT_CANCEL' => $bb_cfg['bt_show_dl_but_cancel'] + 'DL_BUT_WILL' => config()->get('bt_show_dl_but_will'), + 'DL_BUT_DOWN' => config()->get('bt_show_dl_but_down'), + 'DL_BUT_COMPL' => config()->get('bt_show_dl_but_compl'), + 'DL_BUT_CANCEL' => config()->get('bt_show_dl_but_cancel') ]); $dl_hidden_fields = ' diff --git a/library/includes/ucp/bonus.php b/library/includes/ucp/bonus.php index 6dfa707ac..4959b9b71 100644 --- a/library/includes/ucp/bonus.php +++ b/library/includes/ucp/bonus.php @@ -14,9 +14,9 @@ if (!defined('BB_ROOT')) { $user_id = $userdata['user_id']; $user_points = $userdata['user_points']; -if ($bb_cfg['seed_bonus_enabled'] && $bb_cfg['bonus_upload'] && $bb_cfg['bonus_upload_price']) { - $upload_row = unserialize($bb_cfg['bonus_upload']); - $price_row = unserialize($bb_cfg['bonus_upload_price']); +if (config()->get('seed_bonus_enabled') && config()->get('bonus_upload') && config()->get('bonus_upload_price')) { + $upload_row = unserialize(config()->get('bonus_upload')); + $price_row = unserialize(config()->get('bonus_upload_price')); } else { bb_die($lang['EXCHANGE_NOT']); } diff --git a/library/includes/ucp/email.php b/library/includes/ucp/email.php index 6cb8b94df..e64d57d1f 100644 --- a/library/includes/ucp/email.php +++ b/library/includes/ucp/email.php @@ -12,7 +12,7 @@ if (!defined('BB_ROOT')) { } // Is send through board enabled? No, return to index -if (!$bb_cfg['board_email_form']) { +if (!config()->get('board_email_form')) { redirect('index.php'); } diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index 5e101a310..53d5bae2b 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -16,7 +16,7 @@ array_deep($_POST, 'trim'); set_die_append_msg(); if (IS_ADMIN) { - $bb_cfg['reg_email_activation'] = false; + config()->set('reg_email_activation', false); $new_user = (int)request_var('admin', ''); if ($new_user) { @@ -50,17 +50,17 @@ switch ($mode) { if (!IS_ADMIN) { // IP limit - if ($bb_cfg['unique_ip']) { + if (config()->get('unique_ip')) { if ($users = DB()->fetch_row("SELECT user_id, username FROM " . BB_USERS . " WHERE user_reg_ip = '" . USER_IP . "' LIMIT 1")) { - bb_die(sprintf($lang['ALREADY_REG_IP'], '' . $users['username'] . '', $bb_cfg['tech_admin_email'])); + bb_die(sprintf($lang['ALREADY_REG_IP'], '' . $users['username'] . '', config()->get('tech_admin_email'))); } } // Disabling registration - if ($bb_cfg['new_user_reg_disabled'] || ($bb_cfg['reg_email_activation'] && !$bb_cfg['emailer']['enabled'])) { + if (config()->get('new_user_reg_disabled') || (config()->get('reg_email_activation') && !config()->get('emailer.enabled'))) { bb_die($lang['NEW_USER_REG_DISABLED']); } // Time limit - elseif ($bb_cfg['new_user_reg_restricted']) { - if (in_array(date('G'), $bb_cfg['new_user_reg_interval'], true)) { + elseif (config()->get('new_user_reg_restricted')) { + if (in_array(date('G'), config()->get('new_user_reg_interval'), true)) { bb_die($lang['REGISTERED_IN_TIME']); } } @@ -83,8 +83,8 @@ switch ($mode) { 'user_password' => '', 'user_email' => '', 'invite_code' => '', - 'user_timezone' => $bb_cfg['board_timezone'], - 'user_lang' => $bb_cfg['default_lang'], + 'user_timezone' => config()->get('board_timezone'), + 'user_lang' => config()->get('default_lang'), 'user_opt' => 0, 'avatar_ext_id' => 0 ]; @@ -101,13 +101,13 @@ switch ($mode) { // field => can_edit $profile_fields = [ 'user_active' => IS_ADMIN, - 'username' => (IS_ADMIN || $bb_cfg['allow_namechange']) && !IN_DEMO_MODE, + 'username' => (IS_ADMIN || config()->get('allow_namechange')) && !IN_DEMO_MODE, 'user_password' => !IN_DEMO_MODE, 'user_email' => !IN_DEMO_MODE, // should be after user_password - 'user_lang' => $bb_cfg['allow_change']['language'], - 'user_gender' => $bb_cfg['gender'], - 'user_birthday' => $bb_cfg['birthday_enabled'], - 'user_timezone' => $bb_cfg['allow_change']['timezone'], + 'user_lang' => config()->get('allow_change.language'), + 'user_gender' => config()->get('gender'), + 'user_birthday' => config()->get('birthday_enabled'), + 'user_timezone' => config()->get('allow_change.timezone'), 'user_opt' => true, 'avatar_ext_id' => true, 'user_icq' => true, @@ -152,7 +152,7 @@ switch ($mode) { } // Captcha -$need_captcha = ($mode == 'register' && !IS_ADMIN && !$bb_cfg['captcha']['disabled']); +$need_captcha = ($mode == 'register' && !IS_ADMIN && !config()->get('captcha.disabled')); if ($submit) { if ($need_captcha && !bb_captcha('check')) { @@ -203,12 +203,13 @@ foreach ($profile_fields as $field => $can_edit) { * Invite code (reg) */ case 'invite_code': - if ($bb_cfg['invites_system']['enabled']) { + if (config()->get('invites_system.enabled')) { $invite_code = $_POST['invite_code'] ?? ''; if ($submit) { - if (isset($bb_cfg['invites_system']['codes'][$invite_code])) { - if ($bb_cfg['invites_system']['codes'][$invite_code] !== 'permanent') { - if (TIMENOW > strtotime($bb_cfg['invites_system']['codes'][$invite_code])) { + $inviteCodes = config()->get('invites_system.codes'); + if (isset($inviteCodes[$invite_code])) { + if ($inviteCodes[$invite_code] !== 'permanent') { + if (TIMENOW > strtotime($inviteCodes[$invite_code])) { $errors[] = $lang['INVITE_EXPIRED']; } } @@ -264,7 +265,7 @@ foreach ($profile_fields as $field => $can_edit) { } $db_data['user_email'] = $email; } elseif ($email != $pr_data['user_email']) { - if ($bb_cfg['email_change_disabled'] && !$adm_edit && !IS_ADMIN) { + if (config()->get('email_change_disabled') && !$adm_edit && !IS_ADMIN) { $errors[] = $lang['EMAIL_CHANGING_DISABLED']; } if (!$cur_pass_valid) { @@ -273,7 +274,7 @@ foreach ($profile_fields as $field => $can_edit) { if (!$errors and $err = \TorrentPier\Validate::email($email)) { $errors[] = $err; } - if ($bb_cfg['reg_email_activation']) { + if (config()->get('reg_email_activation')) { $pr_data['user_active'] = 0; $db_data['user_active'] = 0; } @@ -336,10 +337,10 @@ foreach ($profile_fields as $field => $can_edit) { if (!empty($birthday_date['year'])) { if (strtotime($user_birthday) >= TIMENOW) { $errors[] = $lang['WRONG_BIRTHDAY_FORMAT']; - } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > $bb_cfg['birthday_max_age']) { - $errors[] = sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday_max_age']); - } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < $bb_cfg['birthday_min_age']) { - $errors[] = sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday_min_age']); + } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] > config()->get('birthday_max_age')) { + $errors[] = sprintf($lang['BIRTHDAY_TO_HIGH'], config()->get('birthday_max_age')); + } elseif (bb_date(TIMENOW, 'Y', false) - $birthday_date['year'] < config()->get('birthday_min_age')) { + $errors[] = sprintf($lang['BIRTHDAY_TO_LOW'], config()->get('birthday_min_age')); } } @@ -357,16 +358,16 @@ foreach ($profile_fields as $field => $can_edit) { $update_user_opt = [ # 'user_opt_name' => ($reg_mode) ? #reg_value : #in_login_change - 'user_viewemail' => $reg_mode ? false : (IS_ADMIN || $bb_cfg['show_email_visibility_settings']), + 'user_viewemail' => $reg_mode ? false : (IS_ADMIN || config()->get('show_email_visibility_settings')), 'user_viewonline' => $reg_mode ? false : true, 'user_notify' => $reg_mode ? true : true, - 'user_notify_pm' => $reg_mode ? true : $bb_cfg['pm_notify_enabled'], + 'user_notify_pm' => $reg_mode ? true : config()->get('pm_notify_enabled'), 'user_porn_forums' => $reg_mode ? false : true, 'user_dls' => $reg_mode ? false : true, 'user_callseed' => $reg_mode ? true : true, 'user_retracker' => $reg_mode ? true : true, 'user_hide_torrent_client' => $reg_mode ? true : true, - 'user_hide_peer_country' => $reg_mode ? true : $bb_cfg['ip2country_settings']['enabled'], + 'user_hide_peer_country' => $reg_mode ? true : config()->get('ip2country_settings.enabled'), 'user_hide_peer_username' => $reg_mode ? false : true, ]; @@ -390,7 +391,7 @@ foreach ($profile_fields as $field => $can_edit) { if ($submit && !bf($pr_data['user_opt'], 'user_opt', 'dis_avatar')) { // Integration with MonsterID if (empty($_FILES['avatar']['name']) && !isset($_POST['delete_avatar']) && isset($_POST['use_monster_avatar'])) { - $monsterAvatar = new Arokettu\MonsterID\Monster($pr_data['user_email'], $bb_cfg['avatars']['max_height']); + $monsterAvatar = new Arokettu\MonsterID\Monster($pr_data['user_email'], config()->get('avatars.max_height')); $tempAvatar = tmpfile(); $tempAvatarPath = stream_get_meta_data($tempAvatar)['uri']; $monsterAvatar->writeToStream($tempAvatar); @@ -412,10 +413,10 @@ foreach ($profile_fields as $field => $can_edit) { delete_avatar($pr_data['user_id'], $pr_data['avatar_ext_id']); $pr_data['avatar_ext_id'] = 0; $db_data['avatar_ext_id'] = 0; - } elseif (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed']) { + } elseif (!empty($_FILES['avatar']['name']) && config()->get('avatars.up_allowed')) { $upload = new TorrentPier\Legacy\Common\Upload(); - if ($upload->init($bb_cfg['avatars'], $_FILES['avatar'], !isset($_POST['use_monster_avatar'])) and $upload->store('avatar', $pr_data)) { + if ($upload->init(config()->getSection('avatars'), $_FILES['avatar'], !isset($_POST['use_monster_avatar'])) and $upload->store('avatar', $pr_data)) { $pr_data['avatar_ext_id'] = $upload->file_ext_id; $db_data['avatar_ext_id'] = (int)$upload->file_ext_id; } else { @@ -423,7 +424,7 @@ foreach ($profile_fields as $field => $can_edit) { } } } - $tp_data['AVATARS_MAX_SIZE'] = humn_size($bb_cfg['avatars']['max_size']); + $tp_data['AVATARS_MAX_SIZE'] = humn_size(config()->get('avatars.max_size')); break; /** @@ -484,7 +485,7 @@ foreach ($profile_fields as $field => $can_edit) { if ($submit && $sig != $pr_data['user_sig']) { $sig = prepare_message($sig); - if (mb_strlen($sig, DEFAULT_CHARSET) > $bb_cfg['max_sig_chars']) { + if (mb_strlen($sig, DEFAULT_CHARSET) > config()->get('max_sig_chars')) { $errors[] = $lang['SIGNATURE_TOO_LONG']; } elseif (preg_match('#<(a|b|i|u|table|tr|td|img) #i', $sig) || preg_match('#(href|src|target|title)=#i', $sig)) { $errors[] = $lang['SIGNATURE_ERROR_HTML']; @@ -559,9 +560,10 @@ foreach ($profile_fields as $field => $can_edit) { $templates = isset($_POST['tpl_name']) ? (string)$_POST['tpl_name'] : $pr_data['tpl_name']; $templates = htmlCHR($templates); if ($submit && $templates != $pr_data['tpl_name']) { - $pr_data['tpl_name'] = $bb_cfg['tpl_name']; - $db_data['tpl_name'] = (string)$bb_cfg['tpl_name']; - foreach ($bb_cfg['templates'] as $folder => $name) { + $pr_data['tpl_name'] = config()->get('tpl_name'); + $db_data['tpl_name'] = (string)config()->get('tpl_name'); + $availableTemplates = config()->get('templates'); + foreach ($availableTemplates as $folder => $name) { if ($templates == $folder) { $pr_data['tpl_name'] = $templates; $db_data['tpl_name'] = (string)$templates; @@ -585,7 +587,7 @@ if ($submit && !$errors) { * Создание нового профиля */ if ($mode == 'register') { - if ($bb_cfg['reg_email_activation']) { + if (config()->get('reg_email_activation')) { $user_actkey = make_rand_str(ACTKEY_LENGTH); $db_data['user_active'] = 0; $db_data['user_actkey'] = $user_actkey; @@ -600,7 +602,7 @@ if ($submit && !$errors) { } if (!isset($db_data['tpl_name'])) { - $db_data['tpl_name'] = (string)$bb_cfg['tpl_name']; + $db_data['tpl_name'] = (string)config()->get('tpl_name'); } $sql_args = DB()->build_array('INSERT', $db_data); @@ -622,13 +624,13 @@ if ($submit && !$errors) { set_pr_die_append_msg($new_user_id); $message = $lang['ACCOUNT_ADDED']; } else { - if ($bb_cfg['reg_email_activation']) { + if (config()->get('reg_email_activation')) { $message = $lang['ACCOUNT_INACTIVE']; - $email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME_INACTIVE'], $bb_cfg['sitename']); + $email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME_INACTIVE'], config()->get('sitename')); $email_template = 'user_welcome_inactive'; } else { $message = $lang['ACCOUNT_ADDED']; - $email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME'], $bb_cfg['sitename']); + $email_subject = sprintf($lang['EMAILER_SUBJECT']['USER_WELCOME'], config()->get('sitename')); $email_template = 'user_welcome'; } @@ -640,7 +642,7 @@ if ($submit && !$errors) { $emailer->set_template($email_template, $user_lang); $emailer->assign_vars([ - 'WELCOME_MSG' => sprintf($lang['WELCOME_SUBJECT'], $bb_cfg['sitename']), + 'WELCOME_MSG' => sprintf($lang['WELCOME_SUBJECT'], config()->get('sitename')), 'USERNAME' => html_entity_decode($username), 'PASSWORD' => $new_pass, 'U_ACTIVATE' => make_url('profile.php?mode=activate&' . POST_USERS_URL . '=' . $new_user_id . '&act_key=' . $db_data['user_actkey']) @@ -728,12 +730,12 @@ $template->assign_vars([ 'LANGUAGE_SELECT' => \TorrentPier\Legacy\Common\Select::language($pr_data['user_lang'], 'user_lang'), 'TIMEZONE_SELECT' => \TorrentPier\Legacy\Common\Select::timezone($pr_data['user_timezone'], 'user_timezone'), - 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], $bb_cfg['avatars']['max_width'], $bb_cfg['avatars']['max_height'], humn_size($bb_cfg['avatars']['max_size'])), + 'AVATAR_EXPLAIN' => sprintf($lang['AVATAR_EXPLAIN'], config()->get('avatars.max_width'), config()->get('avatars.max_height'), humn_size(config()->get('avatars.max_size'))), 'AVATAR_DISALLOWED' => bf($pr_data['user_opt'], 'user_opt', 'dis_avatar'), - 'AVATAR_DIS_EXPLAIN' => sprintf($lang['AVATAR_DISABLE'], $bb_cfg['terms_and_conditions_url']), + 'AVATAR_DIS_EXPLAIN' => sprintf($lang['AVATAR_DISABLE'], config()->get('terms_and_conditions_url')), 'AVATAR_IMG' => get_avatar($pr_data['user_id'], $pr_data['avatar_ext_id'], !bf($pr_data['user_opt'], 'user_opt', 'dis_avatar')), - 'SIGNATURE_EXPLAIN' => sprintf($lang['SIGNATURE_EXPLAIN'], $bb_cfg['max_sig_chars']), + 'SIGNATURE_EXPLAIN' => sprintf($lang['SIGNATURE_EXPLAIN'], config()->get('max_sig_chars')), 'SIG_DISALLOWED' => bf($pr_data['user_opt'], 'user_opt', 'dis_sig'), 'PR_USER_ID' => $pr_data['user_id'], diff --git a/library/includes/ucp/sendpasswd.php b/library/includes/ucp/sendpasswd.php index ab6c619dd..7660cb427 100644 --- a/library/includes/ucp/sendpasswd.php +++ b/library/includes/ucp/sendpasswd.php @@ -13,11 +13,11 @@ if (!defined('BB_ROOT')) { set_die_append_msg(); -if (!$bb_cfg['emailer']['enabled']) { +if (!config()->get('emailer.enabled')) { bb_die($lang['EMAILER_DISABLED']); } -$need_captcha = ($_GET['mode'] == 'sendpassword' && !IS_ADMIN && !$bb_cfg['captcha']['disabled']); +$need_captcha = ($_GET['mode'] == 'sendpassword' && !IS_ADMIN && !config()->get('captcha.disabled')); if (isset($_POST['submit'])) { if ($need_captcha && !bb_captcha('check')) { diff --git a/library/includes/ucp/topic_watch.php b/library/includes/ucp/topic_watch.php index d3355d406..c684cbabc 100644 --- a/library/includes/ucp/topic_watch.php +++ b/library/includes/ucp/topic_watch.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -if (!$bb_cfg['topic_notify_enabled']) { +if (!config()->get('topic_notify_enabled')) { bb_die($lang['DISABLED']); } @@ -35,7 +35,7 @@ if (isset($_GET[POST_USERS_URL])) { } } $start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0; -$per_page = $bb_cfg['topics_per_page']; +$per_page = config()->get('topics_per_page'); if (isset($_POST['topic_id_list'])) { $topic_ids = implode(",", $_POST['topic_id_list']); @@ -96,7 +96,7 @@ if ($watch_count > 0) { 'IS_UNREAD' => $is_unread, 'POLL' => (bool)$watch[$i]['topic_vote'], 'TOPIC_ICON' => get_topic_icon($watch[$i], $is_unread), - 'PAGINATION' => ($watch[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $watch[$i]['topic_id'], $watch[$i]['topic_replies'], $bb_cfg['posts_per_page']) + 'PAGINATION' => ($watch[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $watch[$i]['topic_id'], $watch[$i]['topic_replies'], config()->get('posts_per_page')) ]); } diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index 7dbc44541..3d4605e68 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -50,7 +50,7 @@ if (IS_ADMIN) { } if (bf($profiledata['user_opt'], 'user_opt', 'user_viewemail') || $profiledata['user_id'] == $userdata['user_id'] || IS_ADMIN) { - $email_uri = ($bb_cfg['board_email_form']) ? 'profile.php?mode=email&' . POST_USERS_URL . '=' . $profiledata['user_id'] : 'mailto:' . $profiledata['user_email']; + $email_uri = (config()->get('board_email_form')) ? 'profile.php?mode=email&' . POST_USERS_URL . '=' . $profiledata['user_id'] : 'mailto:' . $profiledata['user_email']; $email = '' . $profiledata['user_email'] . ''; } else { $email = ''; @@ -62,7 +62,7 @@ if (bf($profiledata['user_opt'], 'user_opt', 'user_viewemail') || $profiledata[' $profile_user_id = ($profiledata['user_id'] == $userdata['user_id']); -$signature = ($bb_cfg['allow_sig'] && $profiledata['user_sig']) ? $profiledata['user_sig'] : ''; +$signature = (config()->get('allow_sig') && $profiledata['user_sig']) ? $profiledata['user_sig'] : ''; if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) { if ($profile_user_id) { @@ -75,7 +75,7 @@ if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) { } // Null ratio -if ($bb_cfg['ratio_null_enabled'] && $btu = get_bt_userdata($profiledata['user_id'])) { +if (config()->get('ratio_null_enabled') && $btu = get_bt_userdata($profiledata['user_id'])) { $template->assign_vars(['NULLED_RATIO' => $btu['ratio_nulled']]); } @@ -110,10 +110,10 @@ $template->assign_vars([ 'SKYPE' => $profiledata['user_skype'], 'TWITTER' => $profiledata['user_twitter'], 'USER_POINTS' => $profiledata['user_points'], - 'GENDER' => $bb_cfg['gender'] ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '', - 'BIRTHDAY' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '', + 'GENDER' => config()->get('gender') ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '', + 'BIRTHDAY' => (config()->get('birthday_enabled') && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? $profiledata['user_birthday'] : '', 'BIRTHDAY_ICON' => user_birthday_icon($profiledata['user_birthday'], $profiledata['user_id']), - 'AGE' => ($bb_cfg['birthday_enabled'] && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '', + 'AGE' => (config()->get('birthday_enabled') && !empty($profiledata['user_birthday']) && $profiledata['user_birthday'] != '1900-01-01') ? birthday_age($profiledata['user_birthday']) : '', 'L_VIEWING_PROFILE' => sprintf($lang['VIEWING_USER_PROFILE'], $profiledata['username']), 'L_MY_PROFILE' => sprintf($lang['VIEWING_MY_PROFILE'], 'profile.php?mode=editprofile'), diff --git a/library/language/source/html/sidebar2.html b/library/language/source/html/sidebar2.html index 08a4bdf20..168ec84a7 100644 --- a/library/language/source/html/sidebar2.html +++ b/library/language/source/html/sidebar2.html @@ -7,5 +7,5 @@
  • style/templates/default/page_footer.tpl

  • - To disable this sidebar, set the variable $bb_cfg['page']['show_sidebar2'] in file config.php to false. + To disable this sidebar, set the variable page.show_sidebar2 in file config.php to false. 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/privmsg.php b/privmsg.php index 5bd56d1b6..42b47d1c1 100644 --- a/privmsg.php +++ b/privmsg.php @@ -24,7 +24,7 @@ $page_cfg['load_tpl_vars'] = [ // // Is PM disabled? // -if ($bb_cfg['privmsg_disable']) { +if (config()->get('privmsg_disable')) { bb_die('PM_DISABLED'); } @@ -59,13 +59,13 @@ $user->session_start(['req_login' => true]); $template->assign_vars([ 'IN_PM' => true, - 'QUICK_REPLY' => $bb_cfg['show_quick_reply'] && $folder == 'inbox' && $mode == 'read', + 'QUICK_REPLY' => config()->get('show_quick_reply') && $folder == 'inbox' && $mode == 'read', ]); // // Set mode for quick reply // -if (empty($mode) && $bb_cfg['show_quick_reply'] && $folder == 'inbox' && $preview) { +if (empty($mode) && config()->get('show_quick_reply') && $folder == 'inbox' && $preview) { $mode = 'reply'; } @@ -206,7 +206,7 @@ if ($mode == 'read') { } if ($sent_info = DB()->sql_fetchrow($result)) { - if ($bb_cfg['max_sentbox_privmsgs'] && $sent_info['sent_items'] >= $bb_cfg['max_sentbox_privmsgs']) { + if (config()->get('max_sentbox_privmsgs') && $sent_info['sent_items'] >= config()->get('max_sentbox_privmsgs')) { $sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . " WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . " AND privmsgs_date = " . $sent_info['oldest_post_time'] . " @@ -604,7 +604,7 @@ if ($mode == 'read') { } if ($saved_info = DB()->sql_fetchrow($result)) { - if ($bb_cfg['max_savebox_privmsgs'] && $saved_info['savebox_items'] >= $bb_cfg['max_savebox_privmsgs']) { + if (config()->get('max_savebox_privmsgs') && $saved_info['savebox_items'] >= config()->get('max_savebox_privmsgs')) { $sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . " WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) @@ -749,7 +749,7 @@ if ($mode == 'read') { $last_post_time = $db_row['last_post_time']; $current_time = TIMENOW; - if (($current_time - $last_post_time) < $bb_cfg['flood_interval']) { + if (($current_time - $last_post_time) < config()->get('flood_interval')) { bb_die($lang['FLOOD_ERROR']); } } @@ -802,11 +802,11 @@ if ($mode == 'read') { } // Check smilies limit - if ($bb_cfg['max_smilies_pm']) { - $count_smilies = substr_count(bbcode2html($privmsg_message), 'get('pm_notify_enabled')) { // Sending email $emailer = new TorrentPier\Emailer(); @@ -1252,7 +1252,7 @@ if ($mode == 'read') { $msg_days = 0; } - $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $bb_cfg['topics_per_page']; + $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . config()->get('topics_per_page'); $sql_all_tot = $sql_tot; $sql_tot .= $limit_msg_time_total; @@ -1308,11 +1308,11 @@ if ($mode == 'read') { // Output data for inbox status // $box_limit_img_length = $box_limit_percent = $l_box_size_status = ''; - $max_pm = ($folder != 'outbox') ? $bb_cfg["max_{$folder}_privmsgs"] : null; + $max_pm = ($folder != 'outbox') ? config()->get("max_{$folder}_privmsgs") : null; if ($max_pm) { $box_limit_percent = min(round(($pm_all_total / $max_pm) * 100), 100); - $box_limit_img_length = min(round(($pm_all_total / $max_pm) * $bb_cfg['privmsg_graphic_length']), $bb_cfg['privmsg_graphic_length']); + $box_limit_img_length = min(round(($pm_all_total / $max_pm) * config()->get('privmsg_graphic_length')), config()->get('privmsg_graphic_length')); $box_limit_remain = max(($max_pm - $pm_all_total), 0); $template->assign_var('PM_BOX_SIZE_INFO'); @@ -1410,7 +1410,7 @@ if ($mode == 'read') { ]); } while ($row = DB()->sql_fetchrow($result)); - generate_pagination(PM_URL . "?folder=$folder", $pm_total, $bb_cfg['topics_per_page'], $start); + generate_pagination(PM_URL . "?folder=$folder", $pm_total, config()->get('topics_per_page'), $start); } else { $template->assign_block_vars('switch_no_messages', []); } diff --git a/search.php b/search.php index 5e85b5940..b0d9bb977 100644 --- a/search.php +++ b/search.php @@ -20,7 +20,7 @@ $page_cfg['load_tpl_vars'] = [ ]; // Start session management -$user->session_start(array('req_login' => $bb_cfg['disable_search_for_guest'])); +$user->session_start(array('req_login' => config()->get('disable_search_for_guest'))); set_die_append_msg(); @@ -289,7 +289,7 @@ if (empty($_GET) && empty($_POST)) { 'MY_TOPICS_ID' => 'my_topics', 'MY_TOPICS_CHBOX' => build_checkbox($my_topics_key, $lang['SEARCH_MY_TOPICS'], $my_topics_val, true, null, 'my_topics'), - 'TITLE_ONLY_CHBOX' => build_checkbox($title_only_key, $lang['SEARCH_TITLES_ONLY'], true, $bb_cfg['disable_ft_search_in_posts']), + 'TITLE_ONLY_CHBOX' => build_checkbox($title_only_key, $lang['SEARCH_TITLES_ONLY'], true, config()->get('disable_ft_search_in_posts')), 'ALL_WORDS_CHBOX' => build_checkbox($all_words_key, $lang['SEARCH_ALL_WORDS'], true), 'DL_CANCEL_CHBOX' => build_checkbox($dl_cancel_key, $lang['SEARCH_DL_CANCEL'], $dl_cancel_val, IS_GUEST, 'dlCancel'), 'DL_COMPL_CHBOX' => build_checkbox($dl_compl_key, $lang['SEARCH_DL_COMPLETE'], $dl_compl_val, IS_GUEST, 'dlComplete'), @@ -421,7 +421,7 @@ $prev_days = ($time_val != $search_all); $new_topics = (!IS_GUEST && ($new_topics_val || isset($_GET['newposts']))); $my_topics = ($poster_id_val && $my_topics_val); $my_posts = ($poster_id_val && !$my_topics_val); -$title_match = ($text_match_sql && ($title_only_val || $bb_cfg['disable_ft_search_in_posts'])); +$title_match = ($text_match_sql && ($title_only_val || config()->get('disable_ft_search_in_posts'))); // "Display as" mode (posts or topics) $post_mode = (!$dl_search && ($display_as_val == $as_posts || isset($_GET['search_author']))); @@ -433,7 +433,7 @@ $SQL = DB()->get_empty_sql_array(); if ($post_mode) { $order = $order_opt[$order_val]['sql']; $sort = $sort_opt[$sort_val]['sql']; - $per_page = $bb_cfg['posts_per_page']; + $per_page = config()->get('posts_per_page'); $display_as_val = $as_posts; // Run initial search for post_ids @@ -593,7 +593,7 @@ if ($post_mode) { 'POSTER_ID' => $post['poster_id'], 'POSTER' => profile_url($post), 'POST_ID' => $post['post_id'], - 'POST_DATE' => bb_date($post['post_time'], $bb_cfg['post_date_format']), + 'POST_DATE' => bb_date($post['post_time'], config()->get('post_date_format')), 'IS_UNREAD' => is_unread($post['post_time'], $topic_id, $forum_id), 'MESSAGE' => $message, 'POSTED_AFTER' => '', @@ -612,7 +612,7 @@ if ($post_mode) { else { $order = $order_opt[$order_val]['sql']; $sort = $sort_opt[$sort_val]['sql']; - $per_page = $bb_cfg['topics_per_page']; + $per_page = config()->get('topics_per_page'); $display_as_val = $as_topics; // Run initial search for topic_ids @@ -733,7 +733,7 @@ else { // Build SQL for displaying topics $SQL = DB()->get_empty_sql_array(); - $join_dl = ($bb_cfg['show_dl_status_in_search'] && !IS_GUEST); + $join_dl = (config()->get('show_dl_status_in_search') && !IS_GUEST); $SQL['SELECT'][] = " t.*, t.topic_poster AS first_user_id, u1.user_rank AS first_user_rank, @@ -790,7 +790,7 @@ else { 'TOPIC_TITLE' => $wordCensor->censorString($topic['topic_title']), 'IS_UNREAD' => $is_unread, 'TOPIC_ICON' => get_topic_icon($topic, $is_unread), - 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $topic['topic_replies'], $bb_cfg['posts_per_page']), + 'PAGINATION' => $moved ? '' : build_topic_pagination(TOPIC_URL . $topic_id, $topic['topic_replies'], config()->get('posts_per_page')), 'REPLIES' => $moved ? '' : $topic['topic_replies'], 'ATTACH' => $topic['topic_attachment'], 'STATUS' => $topic['topic_status'], @@ -888,15 +888,13 @@ function fetch_search_ids($sql, $search_type = SEARCH_TYPE_POST) function prevent_huge_searches($SQL) { - global $bb_cfg; - - if ($bb_cfg['limit_max_search_results']) { + if (config()->get('limit_max_search_results')) { $SQL['select_options'][] = 'SQL_CALC_FOUND_ROWS'; $SQL['ORDER BY'] = []; $SQL['LIMIT'] = array('0'); if (DB()->query($SQL) and $row = DB()->fetch_row("SELECT FOUND_ROWS() AS rows_count")) { - if ($row['rows_count'] > $bb_cfg['limit_max_search_results']) { + if ($row['rows_count'] > config()->get('limit_max_search_results')) { # bb_log(str_compact(DB()->build_sql($SQL)) ." [{$row['rows_count']} rows]". LOG_LF, 'sql_huge_search'); bb_die('Too_many_search_results'); } 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/Config.php b/src/Config.php index 2490e94c3..9d39668b8 100644 --- a/src/Config.php +++ b/src/Config.php @@ -11,7 +11,7 @@ namespace TorrentPier; /** * Configuration management class - * + * * Encapsulates the global $bb_cfg array and provides methods to access configuration values */ class Config @@ -179,4 +179,4 @@ class Config { throw new \Exception("Cannot unserialize a singleton."); } -} \ No newline at end of file +} 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/Admin/Common.php b/src/Legacy/Admin/Common.php index eeb5bbeda..db0d93215 100644 --- a/src/Legacy/Admin/Common.php +++ b/src/Legacy/Admin/Common.php @@ -217,7 +217,7 @@ class Common */ public static function topic_delete($mode_or_topic_id, $forum_id = null, $prune_time = 0, $prune_all = false) { - global $bb_cfg, $lang, $log_action; + global $lang, $log_action; $topic_csv = []; $prune = ($mode_or_topic_id === 'prune'); @@ -348,7 +348,7 @@ class Common @unlink("$attach_dir/" . THUMB_DIR . '/t_' . $filename); } // TorrServer integration - if ($bb_cfg['torr_server']['enabled']) { + if (config()->get('torr_server.enabled')) { $torrServer = new \TorrentPier\TorrServerAPI(); $torrServer->removeM3U($row['attach_id']); } @@ -699,7 +699,7 @@ class Common */ public static function user_delete($user_id, $delete_posts = false) { - global $bb_cfg, $log_action; + global $log_action; if (!$user_csv = get_id_csv($user_id)) { return false; @@ -779,7 +779,7 @@ class Common // Delete user feed foreach (explode(',', $user_csv) as $user_id) { - $file_path = $bb_cfg['atom']['path'] . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom'; + $file_path = config()->get('atom.path') . '/u/' . floor($user_id / 5000) . '/' . ($user_id % 100) . '/' . $user_id . '.atom'; @unlink($file_path); } } diff --git a/src/Legacy/Admin/Cron.php b/src/Legacy/Admin/Cron.php index 451152160..7da89ac8a 100644 --- a/src/Legacy/Admin/Cron.php +++ b/src/Legacy/Admin/Cron.php @@ -23,6 +23,7 @@ class Cron public static function run_jobs(string $jobs): void { /** @noinspection PhpUnusedLocalVariableInspection */ + // bb_cfg deprecated, but kept for compatibility with non-adapted cron jobs global $bb_cfg, $datastore; \define('IN_CRON', true); 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/BBCode.php b/src/Legacy/BBCode.php index 330fc6a02..2825e57d1 100644 --- a/src/Legacy/BBCode.php +++ b/src/Legacy/BBCode.php @@ -157,15 +157,13 @@ class BBCode */ public function bbcode2html(string $text): string { - global $bb_cfg; - $text = self::clean_up($text); $text = $this->parse($text); $text = $this->make_clickable($text); $text = $this->smilies_pass($text); $text = $this->new_line2html($text); - if ($bb_cfg['tidy_post']) { + if (config()->get('tidy_post')) { $text = $this->tidy($text); } @@ -395,9 +393,7 @@ class BBCode */ private function nofollow_url(string $href, string $name): string { - global $bb_cfg; - - if (\in_array(parse_url($href, PHP_URL_HOST), $bb_cfg['nofollow']['allowed_url']) || $bb_cfg['nofollow']['disabled']) { + if (\in_array(parse_url($href, PHP_URL_HOST), config()->get('nofollow.allowed_url')) || config()->get('nofollow.disabled')) { $link = "$name"; } else { $link = "$name"; diff --git a/src/Legacy/Common/Select.php b/src/Legacy/Common/Select.php index 424c99869..69b7c5959 100644 --- a/src/Legacy/Common/Select.php +++ b/src/Legacy/Common/Select.php @@ -25,11 +25,9 @@ class Select */ public static function language(string $default_lang, string $select_name = 'language'): mixed { - global $bb_cfg; - $lang_select = ''; - return ($x > 1) ? $lang_select : reset($bb_cfg['lang']); + $languages = config()->get('lang'); + return ($x > 1) ? $lang_select : reset($languages); } /** @@ -77,11 +76,9 @@ class Select */ public static function template(string $default_style, string $select_name = 'tpl_name'): mixed { - global $bb_cfg; - $templates_select = ''; - return ($x > 1) ? $templates_select : reset($bb_cfg['templates']); + $templates = config()->get('templates'); + return ($x > 1) ? $templates_select : reset($templates); } } diff --git a/src/Legacy/Common/Upload.php b/src/Legacy/Common/Upload.php index 685614803..d16542c07 100644 --- a/src/Legacy/Common/Upload.php +++ b/src/Legacy/Common/Upload.php @@ -103,7 +103,7 @@ class Upload */ public function init(array $cfg = [], array $post_params = [], bool $uploaded_only = true): bool { - global $bb_cfg, $lang; + global $lang; $this->cfg = array_merge($this->cfg, $cfg); $this->file = $post_params; @@ -150,7 +150,7 @@ class Upload $file_name_ary = explode('.', $this->file['name']); $this->file_ext = strtolower(end($file_name_ary)); - $this->ext_ids = array_flip($bb_cfg['file_id_ext']); + $this->ext_ids = array_flip(config()->get('file_id_ext')); // Actions for images [E.g. Change avatar] if ($this->cfg['max_width'] || $this->cfg['max_height']) { diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index b1a6a6713..f5738083e 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(); @@ -243,8 +243,6 @@ class User */ public function session_create(array $userdata, bool $auto_created = false): array { - global $bb_cfg; - $this->data = $userdata; $session_id = $this->sessiondata['sid']; @@ -281,8 +279,8 @@ class User if (!$session_time = $this->data['user_session_time']) { $last_visit = TIMENOW; define('FIRST_LOGON', true); - } elseif ($session_time < (TIMENOW - $bb_cfg['last_visit_update_intrv'])) { - $last_visit = max($session_time, (TIMENOW - 86400 * $bb_cfg['max_last_visit_days'])); + } elseif ($session_time < (TIMENOW - config()->get('last_visit_update_intrv'))) { + $last_visit = max($session_time, (TIMENOW - 86400 * config()->get('max_last_visit_days'))); } if ($last_visit != $this->data['user_lastvisit']) { @@ -301,7 +299,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); } @@ -463,7 +461,6 @@ class User */ public function set_session_cookies($user_id) { - global $bb_cfg; $debug_cookies = [ COOKIE_DBG, @@ -486,10 +483,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 +519,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 +526,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 +579,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 +626,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 +799,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 +826,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/LogAction.php b/src/Legacy/LogAction.php index b1d7b2dfb..25689c853 100644 --- a/src/Legacy/LogAction.php +++ b/src/Legacy/LogAction.php @@ -44,7 +44,7 @@ class LogAction */ public function init() { - global $lang, $bb_cfg; + global $lang; foreach ($lang['LOG_ACTION']['LOG_TYPE'] as $log_type => $log_desc) { $this->log_type_select[strip_tags($log_desc)] = $this->log_type[$log_type]; 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/Post.php b/src/Legacy/Post.php index 0a08cb3d2..feb0a71f1 100644 --- a/src/Legacy/Post.php +++ b/src/Legacy/Post.php @@ -31,7 +31,7 @@ class Post */ public static function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message) { - global $bb_cfg, $user, $userdata, $lang; + global $user, $userdata, $lang; // Check username if (!empty($username)) { @@ -60,15 +60,15 @@ class Post } // Check smilies limit - if ($bb_cfg['max_smilies']) { - $count_smilies = substr_count(bbcode2html($message), 'fetch_row($sql) and $row['last_post_time']) { if ($userdata['user_level'] == USER) { - if ((TIMENOW - $row['last_post_time']) < $bb_cfg['flood_interval']) { + if ((TIMENOW - $row['last_post_time']) < config()->get('flood_interval')) { bb_die($lang['FLOOD_ERROR']); } } @@ -200,9 +200,9 @@ class Post update_post_html(['post_id' => $post_id, 'post_text' => $post_message]); // Updating news cache on index page - if ($bb_cfg['show_latest_news']) { - $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); - if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $mode == 'newtopic') { + if (config()->get('show_latest_news')) { + $news_forums = array_flip(explode(',', config()->get('latest_news_forum_id'))); + if (isset($news_forums[$forum_id]) && config()->get('show_latest_news') && $mode == 'newtopic') { $datastore->enqueue([ 'latest_news' ]); @@ -210,9 +210,9 @@ class Post } } - if ($bb_cfg['show_network_news']) { - $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); - if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $mode == 'newtopic') { + if (config()->get('show_network_news')) { + $net_forums = array_flip(explode(',', config()->get('network_news_forum_id'))); + if (isset($net_forums[$forum_id]) && config()->get('show_network_news') && $mode == 'newtopic') { $datastore->enqueue([ 'network_news' ]); @@ -341,9 +341,9 @@ class Post */ public static function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$notify_user) { - global $bb_cfg, $lang, $userdata, $wordCensor; + global $lang, $userdata, $wordCensor; - if (!$bb_cfg['topic_notify_enabled']) { + if (!config()->get('topic_notify_enabled')) { return; } @@ -378,7 +378,7 @@ class Post $emailer->set_template('topic_notify', $row['user_lang']); $emailer->assign_vars([ 'TOPIC_TITLE' => html_entity_decode($topic_title), - 'SITENAME' => $bb_cfg['sitename'], + 'SITENAME' => config()->get('sitename'), 'USERNAME' => $row['username'], 'U_TOPIC' => $u_topic, 'U_STOP_WATCHING_TOPIC' => $unwatch_topic, @@ -500,7 +500,7 @@ class Post */ public static function topic_review($topic_id) { - global $bb_cfg, $template; + global $template; // Fetch posts data $review_posts = DB()->fetch_rowset(" @@ -513,7 +513,7 @@ class Post LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id) WHERE p.topic_id = " . (int)$topic_id . " ORDER BY p.post_time DESC - LIMIT " . $bb_cfg['posts_per_page'] . " + LIMIT " . config()->get('posts_per_page') . " "); // Topic posts block @@ -523,7 +523,7 @@ class Post 'POSTER' => profile_url($post), 'POSTER_NAME_JS' => addslashes($post['username']), 'POST_ID' => $post['post_id'], - 'POST_DATE' => bb_date($post['post_time'], $bb_cfg['post_date_format']), + 'POST_DATE' => bb_date($post['post_time'], config()->get('post_date_format')), 'IS_UNREAD' => is_unread($post['post_time'], $topic_id, $post['forum_id']), 'MESSAGE' => get_parsed_post($post), ]); diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index 1c509d3bd..fa1139415 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -17,7 +17,7 @@ class Template { /** * Variable that holds all the data we'll be substituting into the compiled templates. - * This will end up being a multi-dimensional array like this: + * This will end up being a multidimensional array like this: * $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value * if it's a root-level variable, it'll be like this: * $this->vars[varname] == value or $this->_tpldata['.'][0][varname] == value @@ -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)) { @@ -228,6 +228,8 @@ class Template { $this->cur_tpl = $filename; + /** @noinspection PhpUnusedLocalVariableInspection */ + // bb_cfg deprecated, but kept for compatibility with non-adapted themes global $lang, $source_lang, $bb_cfg, $user; $L =& $lang; @@ -987,11 +989,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..7bdf42943 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); } @@ -277,7 +277,7 @@ class Torrent */ public static function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW) { - global $bb_cfg, $lang, $reg_mode; + global $lang, $reg_mode; $attach_id = (int)$attach_id; $reg_mode = $mode; @@ -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,8 +504,8 @@ class Torrent $user_id = $userdata['user_id']; $attach_id = $attachment['attach_id']; - if (!$passkey_key = $bb_cfg['passkey_key']) { - bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])'); + if (!$passkey_key = config()->get('passkey_key')) { + bb_die('Could not add passkey (wrong config passkey_key)'); } // Get $post_id & $poster_id @@ -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/styles/templates/default/tpl_config.php b/styles/templates/default/tpl_config.php index 29b3c2b93..aa69b6d53 100644 --- a/styles/templates/default/tpl_config.php +++ b/styles/templates/default/tpl_config.php @@ -7,14 +7,14 @@ * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License */ -global $bb_cfg, $page_cfg, $template, $images, $lang; +global $page_cfg, $template, $images, $lang; $width = $height = []; $template_name = basename(__DIR__); $_img = BB_ROOT . 'styles/images/'; $_main = BB_ROOT . 'styles/' . basename(TEMPLATES_DIR) . '/' . $template_name . '/images/'; -$_lang = $_main . 'lang/' . basename($bb_cfg['default_lang']) . '/'; +$_lang = $_main . 'lang/' . basename(config()->get('default_lang')) . '/'; // post_buttons $images['icon_code'] = $_lang . 'icon_code.gif'; @@ -117,13 +117,13 @@ $images['progress_bar_full'] = $_main . 'progress_bar_full.gif'; $template->assign_vars([ 'IMG' => $_main, - 'TEXT_BUTTONS' => $bb_cfg['text_buttons'], - 'POST_BTN_SPACER' => $bb_cfg['text_buttons'] ? ' ' : '', + 'TEXT_BUTTONS' => config()->get('text_buttons'), + 'POST_BTN_SPACER' => config()->get('text_buttons') ? ' ' : '', 'TOPIC_ATTACH_ICON' => '', 'OPEN_MENU_IMG_ALT' => '', - 'TOPIC_LEFT_COL_SPACER_WITDH' => $bb_cfg['topic_left_column_witdh'] - 8, // 8px padding - 'POST_IMG_WIDTH_DECR_JS' => $bb_cfg['topic_left_column_witdh'] + $bb_cfg['post_img_width_decr'], - 'ATTACH_IMG_WIDTH_DECR_JS' => $bb_cfg['topic_left_column_witdh'] + $bb_cfg['attach_img_width_decr'], + 'TOPIC_LEFT_COL_SPACER_WITDH' => config()->get('topic_left_column_witdh') - 8, // 8px padding + 'POST_IMG_WIDTH_DECR_JS' => config()->get('topic_left_column_witdh') + config()->get('post_img_width_decr'), + 'ATTACH_IMG_WIDTH_DECR_JS' => config()->get('topic_left_column_witdh') + config()->get('attach_img_width_decr'), 'FEED_IMG' => '' . $lang['ATOM_FEED'] . '', ]); @@ -131,25 +131,25 @@ $template->assign_vars([ if (!empty($page_cfg['load_tpl_vars']) and $vars = array_flip($page_cfg['load_tpl_vars'])) { if (isset($vars['post_buttons'])) { $template->assign_vars([ - 'CODE_IMG' => $bb_cfg['text_buttons'] ? $lang['CODE_TOPIC_TXTB'] : '' . $lang['CODE_TOPIC_TXTB'] . '', - 'QUOTE_IMG' => $bb_cfg['text_buttons'] ? $lang['REPLY_WITH_QUOTE_TXTB'] : '' . $lang['REPLY_WITH_QUOTE_TXTB'] . '', - 'EDIT_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['EDIT_DELETE_POST_TXTB'] : '' . $lang['EDIT_DELETE_POST_TXTB'] . '', - 'DELETE_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['DELETE_POST_TXTB'] : '' . $lang['DELETE_POST_TXTB'] . '', - 'IP_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['VIEW_IP_TXTB'] : '' . $lang['VIEW_IP_TXTB'] . '', - 'MOD_POST_IMG' => $bb_cfg['text_buttons'] ? $lang['MODERATE_POST_TXTB'] : '' . $lang['MODERATE_POST_TXTB'] . '', - 'MC_IMG' => $bb_cfg['text_buttons'] ? '[' . $lang['COMMENT'] . ']' : '[' . $lang['COMMENT'] . ']', - 'POLL_IMG' => $bb_cfg['text_buttons'] ? $lang['TOPIC_POLL'] : '' . $lang['TOPIC_POLL'] . '', + 'CODE_IMG' => config()->get('text_buttons') ? $lang['CODE_TOPIC_TXTB'] : '' . $lang['CODE_TOPIC_TXTB'] . '', + 'QUOTE_IMG' => config()->get('text_buttons') ? $lang['REPLY_WITH_QUOTE_TXTB'] : '' . $lang['REPLY_WITH_QUOTE_TXTB'] . '', + 'EDIT_POST_IMG' => config()->get('text_buttons') ? $lang['EDIT_DELETE_POST_TXTB'] : '' . $lang['EDIT_DELETE_POST_TXTB'] . '', + 'DELETE_POST_IMG' => config()->get('text_buttons') ? $lang['DELETE_POST_TXTB'] : '' . $lang['DELETE_POST_TXTB'] . '', + 'IP_POST_IMG' => config()->get('text_buttons') ? $lang['VIEW_IP_TXTB'] : '' . $lang['VIEW_IP_TXTB'] . '', + 'MOD_POST_IMG' => config()->get('text_buttons') ? $lang['MODERATE_POST_TXTB'] : '' . $lang['MODERATE_POST_TXTB'] . '', + 'MC_IMG' => config()->get('text_buttons') ? '[' . $lang['COMMENT'] . ']' : '[' . $lang['COMMENT'] . ']', + 'POLL_IMG' => config()->get('text_buttons') ? $lang['TOPIC_POLL'] : '' . $lang['TOPIC_POLL'] . '', 'QUOTE_URL' => BB_ROOT . POSTING_URL . '?mode=quote&' . POST_POST_URL . '=', 'EDIT_POST_URL' => BB_ROOT . POSTING_URL . '?mode=editpost&' . POST_POST_URL . '=', 'DELETE_POST_URL' => BB_ROOT . POSTING_URL . '?mode=delete&' . POST_POST_URL . '=', 'IP_POST_URL' => BB_ROOT . 'modcp.php?mode=ip&' . POST_POST_URL . '=', - 'PROFILE_IMG' => $bb_cfg['text_buttons'] ? $lang['READ_PROFILE_TXTB'] : '' . $lang['READ_PROFILE_TXTB'] . '', - 'PM_IMG' => $bb_cfg['text_buttons'] ? $lang['SEND_PM_TXTB'] : '' . $lang['SEND_PM_TXTB'] . '', - 'EMAIL_IMG' => $bb_cfg['text_buttons'] ? $lang['SEND_EMAIL_TXTB'] : '' . $lang['SEND_EMAIL_TXTB'] . '', - 'WWW_IMG' => $bb_cfg['text_buttons'] ? $lang['VISIT_WEBSITE_TXTB'] : '' . $lang['VISIT_WEBSITE_TXTB'] . '', - 'ICQ_IMG' => $bb_cfg['text_buttons'] ? $lang['ICQ_TXTB'] : '' . $lang['ICQ_TXTB'] . '', + 'PROFILE_IMG' => config()->get('text_buttons') ? $lang['READ_PROFILE_TXTB'] : '' . $lang['READ_PROFILE_TXTB'] . '', + 'PM_IMG' => config()->get('text_buttons') ? $lang['SEND_PM_TXTB'] : '' . $lang['SEND_PM_TXTB'] . '', + 'EMAIL_IMG' => config()->get('text_buttons') ? $lang['SEND_EMAIL_TXTB'] : '' . $lang['SEND_EMAIL_TXTB'] . '', + 'WWW_IMG' => config()->get('text_buttons') ? $lang['VISIT_WEBSITE_TXTB'] : '' . $lang['VISIT_WEBSITE_TXTB'] . '', + 'ICQ_IMG' => config()->get('text_buttons') ? $lang['ICQ_TXTB'] : '' . $lang['ICQ_TXTB'] . '', 'EMAIL_URL' => BB_ROOT . 'profile.php?mode=email&' . POST_USERS_URL . '=', 'FORUM_URL' => BB_ROOT . FORUM_URL, diff --git a/terms.php b/terms.php index d173f82f8..e3598073f 100644 --- a/terms.php +++ b/terms.php @@ -15,13 +15,13 @@ require INC_DIR . '/bbcode.php'; // Start session management $user->session_start(); -if (!$bb_cfg['terms'] && !IS_ADMIN) { +if (!config()->get('terms') && !IS_ADMIN) { redirect('index.php'); } $template->assign_vars([ 'TERMS_EDIT' => bbcode2html(sprintf($lang['TERMS_EMPTY_TEXT'], make_url('admin/admin_terms.php'))), - 'TERMS_HTML' => bbcode2html($bb_cfg['terms']), + 'TERMS_HTML' => bbcode2html(config()->get('terms')), ]); print_page('terms.tpl'); diff --git a/tracker.php b/tracker.php index 2e94615b9..ddb56a51f 100644 --- a/tracker.php +++ b/tracker.php @@ -19,7 +19,7 @@ $page_cfg['load_tpl_vars'] = [ ]; // Session start -$user->session_start(array('req_login' => $bb_cfg['bt_tor_browse_only_reg'])); +$user->session_start(array('req_login' => config()->get('bt_tor_browse_only_reg'))); set_die_append_msg(); @@ -30,7 +30,7 @@ $max_forums_selected = 50; $title_match_max_len = 60; $poster_name_max_len = 25; $tor_colspan = 12; // torrents table colspan with all columns -$per_page = $bb_cfg['topics_per_page']; +$per_page = config()->get('topics_per_page'); $tracker_url = basename(__FILE__); $time_format = 'H:i'; @@ -299,8 +299,8 @@ if (isset($_GET[$user_releases_key])) { } // Random release -if ($bb_cfg['tracker']['random_release_button'] && isset($_GET['random_release'])) { - if ($random_release = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE tor_status NOT IN(" . implode(', ', array_keys($bb_cfg['tor_frozen'])) . ") ORDER BY RAND() LIMIT 1")) { +if (config()->get('tracker.random_release_button') && isset($_GET['random_release'])) { + if ($random_release = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE tor_status NOT IN(" . implode(', ', array_keys(config()->get('tor_frozen'))) . ") ORDER BY RAND() LIMIT 1")) { redirect(TOPIC_URL . $random_release['topic_id']); } else { bb_die($lang['NO_MATCH']); @@ -749,8 +749,8 @@ if ($allowed_forums) { 'MAGNET' => $tor_magnet, 'TOR_TYPE' => is_gold($tor['tor_type']), - 'TOR_FROZEN' => !IS_AM ? isset($bb_cfg['tor_frozen'][$tor['tor_status']]) : '', - 'TOR_STATUS_ICON' => $bb_cfg['tor_icons'][$tor['tor_status']], + 'TOR_FROZEN' => !IS_AM ? isset(config()->get('tor_frozen')[$tor['tor_status']]) : '', + 'TOR_STATUS_ICON' => config()->get('tor_icons')[$tor['tor_status']], 'TOR_STATUS_TEXT' => $lang['TOR_STATUS_NAME'][$tor['tor_status']], 'TOR_SIZE_RAW' => $size, @@ -819,9 +819,9 @@ $search_all_opt = '