From 13b8fcf4542a354039d591d32ac7f09dbe324072 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 16 Mar 2025 12:36:22 +0100 Subject: [PATCH] Avoid globals where possible $logged => logged() $account_logged => accountLogged() --- admin/index.php | 9 +-- admin/pages/login.php | 2 +- admin/pages/mass_account.php | 7 +- admin/pages/mass_teleport.php | 6 +- admin/pages/menus.php | 2 +- admin/template/template.php | 6 +- install/includes/functions.php | 4 +- install/steps/7-finish.php | 2 +- install/tools/7-finish.php | 4 +- system/counter.php | 2 +- system/functions.php | 68 ++++++++++++------- system/libs/pot/OTS_Account.php | 16 ++--- system/libs/pot/OTS_DB_MySQL.php | 10 +-- system/libs/pot/OTS_Group.php | 4 +- system/libs/pot/OTS_Guild.php | 2 - system/libs/pot/OTS_Player.php | 3 +- system/logout.php | 11 ++- system/migrations/20.php | 2 +- system/pages/account/base.php | 2 +- system/pages/account/change-email.php | 2 +- system/pages/account/change-info.php | 2 +- system/pages/account/change-password.php | 2 +- .../account/characters/change-comment.php | 2 +- .../pages/account/characters/change-name.php | 2 +- .../pages/account/characters/change-sex.php | 2 +- system/pages/account/characters/create.php | 2 +- system/pages/account/characters/delete.php | 2 +- system/pages/account/create.php | 3 +- system/pages/account/login.php | 4 ++ system/pages/account/logout.php | 2 +- system/pages/account/manage.php | 2 +- system/pages/account/register-new.php | 2 +- system/pages/account/register.php | 2 +- system/pages/faq.php | 7 +- system/pages/forum/edit_post.php | 2 +- system/pages/forum/move_thread.php | 2 +- system/pages/forum/new_post.php | 2 +- system/pages/forum/new_thread.php | 2 +- system/pages/forum/remove_post.php | 2 +- system/pages/forum/show_board.php | 4 +- system/pages/gallery.php | 4 +- system/pages/guilds/accept_invite.php | 2 +- system/pages/guilds/add_rank.php | 2 +- system/pages/guilds/change_description.php | 2 +- system/pages/guilds/change_logo.php | 2 +- system/pages/guilds/change_motd.php | 2 +- system/pages/guilds/change_nick.php | 2 +- system/pages/guilds/change_rank.php | 2 +- system/pages/guilds/cleanup_guilds.php | 2 +- system/pages/guilds/cleanup_players.php | 2 +- system/pages/guilds/create.php | 2 +- system/pages/guilds/delete_by_admin.php | 2 +- system/pages/guilds/delete_guild.php | 2 +- system/pages/guilds/delete_invite.php | 2 +- system/pages/guilds/delete_rank.php | 2 +- system/pages/guilds/invite.php | 2 +- system/pages/guilds/kick_player.php | 2 +- system/pages/guilds/leave.php | 2 +- system/pages/guilds/list.php | 2 +- system/pages/guilds/manager.php | 2 +- system/pages/guilds/pass_leadership.php | 2 +- system/pages/guilds/save_ranks.php | 2 +- system/pages/guilds/show.php | 5 +- system/pages/highscores.php | 2 +- system/pages/news.php | 2 +- system/pages/polls.php | 7 +- system/settings.php | 3 +- system/src/App/App.php | 5 +- system/src/Changelog.php | 4 +- system/src/Commands/MigrateRunCommand.php | 2 +- system/src/CreateCharacter.php | 4 +- system/src/Data.php | 8 +-- system/src/DataLoader.php | 4 +- system/src/Forum.php | 38 ++++++----- system/src/Models/Guild.php | 2 +- system/src/Models/Player.php | 11 +-- system/src/News.php | 4 +- system/src/Plugins.php | 18 ++--- system/src/RateLimit.php | 6 +- system/src/Services/LoginService.php | 5 +- system/src/Services/RouterService.php | 6 +- system/src/Settings.php | 6 +- system/src/UsageStatistics.php | 4 +- system/src/Validator.php | 4 +- templates/tibiacom/index.php | 8 +-- 85 files changed, 226 insertions(+), 192 deletions(-) diff --git a/admin/index.php b/admin/index.php index b371103b..f97056ac 100644 --- a/admin/index.php +++ b/admin/index.php @@ -6,11 +6,9 @@ use MyAAC\Services\StatusService; // few things we'll need require '../common.php'; -const ADMIN_PANEL = true; const MYAAC_ADMIN = true; -if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) -{ +if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) { header('Location: ' . BASE_URL . 'install/'); exit; } @@ -32,8 +30,11 @@ require __DIR__ . '/includes/debugbar.php'; $loginService = new LoginService(); $checkLogin = $loginService->checkLogin(); + $logged = $checkLogin['logged']; $account_logged = $checkLogin['account']; + +app()->setLoggedIn($logged); app()->setAccountLogged($account_logged); $statusService = new StatusService(); @@ -49,7 +50,7 @@ if (ACTION == 'logout') { } // if we're not logged in - show login box -if(!$logged || !admin()) { +if(!logged() || !admin()) { $page = 'login'; } diff --git a/admin/pages/login.php b/admin/pages/login.php index eb6466d3..3bb9505c 100644 --- a/admin/pages/login.php +++ b/admin/pages/login.php @@ -13,7 +13,7 @@ $title = 'Login'; csrfProtect(); require PAGES . 'account/login.php'; -if ($logged) { +if (logged()) { header('Location: ' . (admin() ? ADMIN_URL : BASE_URL)); return; } diff --git a/admin/pages/mass_account.php b/admin/pages/mass_account.php index 46c9bc9d..9b6a7727 100644 --- a/admin/pages/mass_account.php +++ b/admin/pages/mass_account.php @@ -57,13 +57,14 @@ function admin_give_coins($coins) function admin_give_premdays($days) { - global $db, $freePremium; + global $freePremium; if ($freePremium) { displayMessage('Premium days not supported. Free Premium enabled.'); return; } + $db = app()->get('database'); $value = $days * 86400; $now = time(); // othire @@ -174,10 +175,12 @@ else { } function displayMessage($message, $success = false) { - global $twig, $hasCoinsColumn, $hasPointsColumn, $freePremium; + global $hasCoinsColumn, $hasPointsColumn, $freePremium; $success ? success($message): error($message); + $twig = app()->get('twig'); + $twig->display('admin.tools.account.html.twig', array( 'hasCoinsColumn' => $hasCoinsColumn, 'hasPointsColumn' => $hasPointsColumn, diff --git a/admin/pages/mass_teleport.php b/admin/pages/mass_teleport.php index 5264914d..6dc0800b 100644 --- a/admin/pages/mass_teleport.php +++ b/admin/pages/mass_teleport.php @@ -99,9 +99,9 @@ else { } -function displayMessage($message, $success = false) { - global $twig; - +function displayMessage($message, $success = false) +{ + $twig = app()->get('twig'); $success ? success($message): error($message); $twig->display('admin.tools.teleport.html.twig', array()); } diff --git a/admin/pages/menus.php b/admin/pages/menus.php index 19d7b486..893ed9ff 100644 --- a/admin/pages/menus.php +++ b/admin/pages/menus.php @@ -203,7 +203,7 @@ if (isset($_POST['template'])) { function onTemplateMenusChange(): void { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $cache->delete('template_menus'); } diff --git a/admin/template/template.php b/admin/template/template.php index c6b8747b..7547e5ec 100644 --- a/admin/template/template.php +++ b/admin/template/template.php @@ -21,7 +21,7 @@ trigger(HOOK_ADMIN_BODY_START); ?> - +
- @@ -185,7 +185,7 @@ /** * @var OTS_Account $account_logged */ -if ($logged && admin()) { +if (logged() && admin()) { $twig->display('admin-bar.html.twig', [ 'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId() ]); diff --git a/install/includes/functions.php b/install/includes/functions.php index d8dd2cb9..f4692a6a 100644 --- a/install/includes/functions.php +++ b/install/includes/functions.php @@ -2,7 +2,9 @@ defined('MYAAC') or die('Direct access not allowed!'); function query($query) { - global $db, $error; + global $error; + + $db = app()->get('database'); try { $db->query($query); diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php index cb4e5821..77f22553 100644 --- a/install/steps/7-finish.php +++ b/install/steps/7-finish.php @@ -12,7 +12,7 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save return; } -$cache = Cache::getInstance(); +$cache = app()->get('cache'); if ($cache->enabled()) { // clear plugin_hooks to have fresh hooks $cache->delete('plugins_hooks'); diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php index 6620f7d9..0f4dfca7 100644 --- a/install/tools/7-finish.php +++ b/install/tools/7-finish.php @@ -33,7 +33,9 @@ if ($db->hasTable('players')) { $time = time(); function insert_sample_if_not_exist($p) { - global $db, $success, $deleted, $time; + global $success, $deleted, $time; + + $db = app()->get('database'); $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($p['name'])); if ($query->rowCount() == 0) { diff --git a/system/counter.php b/system/counter.php index 2c2512d3..07d5edc6 100644 --- a/system/counter.php +++ b/system/counter.php @@ -15,7 +15,7 @@ define('COUNTER_SYNC', 10); // how often counter is synchronized with database ( $views_counter = 1; // default value, must be here! -$cache = Cache::getInstance(); +$cache = app()->get('cache'); if($cache->enabled()) { $value = 0; diff --git a/system/functions.php b/system/functions.php index 85514788..8f0b2384 100644 --- a/system/functions.php +++ b/system/functions.php @@ -275,7 +275,10 @@ function generateRandomString($length, $lowCase = true, $upCase = false, $numeri */ function getForumBoards() { - global $db, $canEdit; + global $canEdit; + + $db = app()->get('database'); + $sections = $db->query('SELECT `id`, `name`, `description`, `closed`, `guild`, `access`' . ($canEdit ? ', `hide`, `ordering`' : '') . ' FROM `' . TABLE_PREFIX . 'forum_boards` ' . (!$canEdit ? ' WHERE `hide` != 1' : '') . ' ORDER BY `ordering`;'); if($sections) @@ -351,13 +354,12 @@ function updateDatabaseConfig($name, $value) */ function encrypt($str) { - global $config; - if(isset($config['database_salt'])) // otserv - $str .= $config['database_salt']; + $configDatabaseSalt = config('database_salt'); + if(isset($configDatabaseSalt)) // otserv + $str .= $configDatabaseSalt; - $encryptionType = $config['database_encryption']; - if(isset($encryptionType) && strtolower($encryptionType) !== 'plain') - { + $encryptionType = config('database_encryption'); + if(isset($encryptionType) && strtolower($encryptionType) !== 'plain') { if($encryptionType === 'vahash') return base64_encode(hash('sha256', $str)); @@ -433,7 +435,7 @@ function delete_guild($id) if(count($rank_list) > 0) { $rank_list->orderBy('level'); - global $db; + $db = app()->get('database'); /** * @var OTS_GuildRank $rank_in_guild */ @@ -495,9 +497,11 @@ function tickers() */ function template_place_holder($type): string { - global $twig, $template_place_holders, $debugBar; + global $template_place_holders, $debugBar; $ret = ''; + $twig = app()->get('twig'); + if (isset($debugBar)) { $debugBarRenderer = $debugBar->getJavascriptRenderer(); } @@ -529,9 +533,11 @@ function template_place_holder($type): string */ function template_header($is_admin = false): string { - global $title_full, $twig; + global $title_full; $charset = setting('core.charset') ?? 'utf-8'; + $twig = app()->get('twig'); + return $twig->render('templates.header.html.twig', [ 'charset' => $charset, @@ -583,7 +589,7 @@ function template_footer(): string function template_ga_code() { - global $twig; + $twig = app()->get('twig'); if(!isset(setting('core.google_analytics_id')[0])) return ''; @@ -602,7 +608,7 @@ function template_form() foreach($templates as $value) $options .= ''; - global $twig; + $twig = app()->get('twig'); return $twig->render('forms.change_template.html.twig', ['options' => $options]); } @@ -717,13 +723,20 @@ function getSkillName($skillId, $suffix = true) return 'unknown'; } +function logged(): bool { + return app()->isLoggedIn(); +} + +function accountLogged(): OTS_Account { + $loggedAccount = app()->getAccountLogged(); + return $loggedAccount ?? new OTS_Account(); +} /** * Performs flag check on the current logged in user. * Table in database: accounts, field: website_flags */ function hasFlag(int $flag): bool { - global $logged, $logged_flags; - return ($logged && ($logged_flags & $flag) == $flag); + return (logged() && (accountLogged()->getWebFlags() & $flag) == $flag); } /** * Check if current logged user have got admin flag set. @@ -866,7 +879,7 @@ function getWorldName($id) */ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true) { - global $mailer, $config; + global $mailer; if (!setting('core.mail_enabled')) { log_append('mailer-error.log', '_mail() function has been used, but Mail Support is disabled.'); @@ -918,7 +931,7 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true) $mailer->From = setting('core.mail_address'); $mailer->Sender = setting('core.mail_address'); $mailer->CharSet = 'utf-8'; - $mailer->FromName = $config['lua']['serverName']; + $mailer->FromName = configLua('serverName'); $mailer->Subject = $subject; $mailer->addAddress($to); $mailer->Body = $tmp_body; @@ -1110,7 +1123,7 @@ function csrfProtect(): void } function getTopPlayers($limit = 5, $skill = 'level') { - global $db; + $db = app()->get('database'); if ($skill === 'level') { $skill = 'experience'; @@ -1253,7 +1266,7 @@ function clearCache() } } - global $db; + $db = app()->get('database'); $db->setClearCacheAfter(true); } @@ -1281,7 +1294,8 @@ function clearRouteCache(): void function getCustomPageInfo($name) { - global $logged_access; + $logged_access = logged() ? accountLogged()->getAccess() : 0; + $page = Pages::isPublic() ->where('name', 'LIKE', $name) ->where('access', '<=', $logged_access) @@ -1295,7 +1309,9 @@ function getCustomPageInfo($name) } function getCustomPage($name, &$success): string { - global $twig, $title, $ignore; + global $title, $ignore; + + $twig = app()->get('twig'); $success = false; $content = ''; @@ -1509,8 +1525,7 @@ function verify_number($number, $name, $max_length) function Outfits_loadfromXML() { - global $config; - $file_path = $config['data_path'] . 'XML/outfits.xml'; + $file_path = config('data_path') . 'XML/outfits.xml'; if (!file_exists($file_path)) { return null; } $xml = new DOMDocument; @@ -1535,8 +1550,7 @@ function Outfits_loadfromXML() function Mounts_loadfromXML() { - global $config; - $file_path = $config['data_path'] . 'XML/mounts.xml'; + $file_path = config('data_path') . 'XML/mounts.xml'; if (!file_exists($file_path)) { return null; } $xml = new DOMDocument; @@ -1659,8 +1673,10 @@ function getGuildLogoById($id) return BASE_URL . GUILD_IMAGES_DIR . $logo; } -function displayErrorBoxWithBackButton($errors, $action = null) { - global $twig; +function displayErrorBoxWithBackButton($errors, $action = null) +{ + $twig = app()->get('twig'); + $twig->display('error_box.html.twig', ['errors' => $errors]); $twig->display('account.back_button.html.twig', [ 'action' => $action ?: getLink('') diff --git a/system/libs/pot/OTS_Account.php b/system/libs/pot/OTS_Account.php index 231230af..bb9e3a02 100644 --- a/system/libs/pot/OTS_Account.php +++ b/system/libs/pot/OTS_Account.php @@ -478,12 +478,12 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable public function isPremium() { - global $config; - if(isset($config['lua']['freePremium']) && getBoolean($config['lua']['freePremium'])) return true; + $configFreePremium = configLua('freePremium'); + if(isset($configFreePremium) && getBoolean($configFreePremium)) return true; - if(isset($this->data['premium_ends_at'])) { - return $this->data['premium_ends_at'] > time(); - } + if(isset($this->data['premium_ends_at'])) { + return $this->data['premium_ends_at'] > time(); + } if(isset($this->data['premend'])) { return $this->data['premend'] > time(); @@ -772,7 +772,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable $filter->compareField('account_id', (int) $this->data['id']); if(!$withDeleted) { - global $db; + $db = app()->get('database'); if($db->hasColumn('players', 'deletion')) { $filter->compareField('deletion', 0); } else { @@ -936,7 +936,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable return $this->data['group_id']; } - global $db; + $db = app()->get('database'); if($db->hasColumn('accounts', 'group_id')) { $query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch(); // if anything was found @@ -963,7 +963,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable return $this->data['group_id']; } - global $db; + $db = app()->get('database'); if($db->hasColumn('accounts', 'group_id')) { $query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch(); // if anything was found diff --git a/system/libs/pot/OTS_DB_MySQL.php b/system/libs/pot/OTS_DB_MySQL.php index cc2ed25a..d9865d01 100644 --- a/system/libs/pot/OTS_DB_MySQL.php +++ b/system/libs/pot/OTS_DB_MySQL.php @@ -97,14 +97,13 @@ class OTS_DB_MySQL extends OTS_Base_DB $params['persistent'] = false; } - global $config; $cache = app()->get('cache'); if($cache->enabled()) { $tmp = null; $need_revalidation = true; if($cache->fetch('database_checksum', $tmp) && $tmp) { $tmp = unserialize($tmp); - if(sha1($config['database_host'] . '.' . $config['database_name']) === $tmp) { + if(sha1(config('database_host') . '.' . config('database_name')) === $tmp) { $need_revalidation = false; } } @@ -148,8 +147,6 @@ class OTS_DB_MySQL extends OTS_Base_DB public function __destruct() { - global $config; - $cache = app()->get('cache'); if($cache->enabled()) { if ($this->clearCacheAfter) { @@ -160,7 +157,7 @@ class OTS_DB_MySQL extends OTS_Base_DB else { $cache->set('database_tables', serialize($this->has_table_cache), 3600); $cache->set('database_columns', serialize($this->has_column_cache), 3600); - $cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])), 3600); + $cache->set('database_checksum', serialize(sha1(config('database_host') . '.' . config('database_name'))), 3600); } } @@ -218,8 +215,7 @@ class OTS_DB_MySQL extends OTS_Base_DB } private function hasTableInternal($name) { - global $config; - return ($this->has_table_cache[$name] = $this->query('SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = ' . $this->quote($config['database_name']) . ' AND `TABLE_NAME` = ' . $this->quote($name) . ' LIMIT 1;')->rowCount() > 0); + return ($this->has_table_cache[$name] = $this->query('SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = ' . $this->quote(config('database_name')) . ' AND `TABLE_NAME` = ' . $this->quote($name) . ' LIMIT 1;')->rowCount() > 0); } public function hasColumn($table, $column) { diff --git a/system/libs/pot/OTS_Group.php b/system/libs/pot/OTS_Group.php index d094d365..176f0e08 100644 --- a/system/libs/pot/OTS_Group.php +++ b/system/libs/pot/OTS_Group.php @@ -490,7 +490,9 @@ class OTS_Group extends OTS_Row_DAO implements IteratorAggregate, Countable // creates filter $filter = new OTS_SQLFilter(); $filter->compareField('group_id', (int) $this->data['id']); - global $db; + + $db = app()->get('database'); + if($db->hasColumn('players', 'deletion')) $filter->compareField('deletion', 0); else diff --git a/system/libs/pot/OTS_Guild.php b/system/libs/pot/OTS_Guild.php index bab363a8..e6b2eb51 100644 --- a/system/libs/pot/OTS_Guild.php +++ b/system/libs/pot/OTS_Guild.php @@ -284,8 +284,6 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable } public function hasMember(OTS_Player $player) { - global $db; - if(!$player || !$player->isLoaded()) { return false; } diff --git a/system/libs/pot/OTS_Player.php b/system/libs/pot/OTS_Player.php index 17e52798..b4834201 100644 --- a/system/libs/pot/OTS_Player.php +++ b/system/libs/pot/OTS_Player.php @@ -854,9 +854,8 @@ class OTS_Player extends OTS_Row_DAO } if(isset($this->data['promotion'])) { - global $config; if((int)$this->data['promotion'] > 0) - return ($this->data['vocation'] + ($this->data['promotion'] * $config['vocations_amount'])); + return ($this->data['vocation'] + ($this->data['promotion'] * config('vocations_amount'))); } return $this->data['vocation']; diff --git a/system/logout.php b/system/logout.php index dd72a455..9c5da866 100644 --- a/system/logout.php +++ b/system/logout.php @@ -12,7 +12,10 @@ use MyAAC\CsrfToken; defined('MYAAC') or die('Direct access not allowed!'); -if(isset($account_logged) && $account_logged->isLoaded()) { +$account_logged = accountLogged(); +$hooks = app()->get('hooks'); + +if($account_logged !== null && $account_logged->isLoaded()) { if($hooks->trigger(HOOK_LOGOUT, ['account_id' => $account_logged->getId()])) { unsetSession('account'); unsetSession('password'); @@ -20,7 +23,11 @@ if(isset($account_logged) && $account_logged->isLoaded()) { CsrfToken::generate(); + global $logged, $account_logged; $logged = false; - unset($account_logged); + $account_logged = new OTS_Account(); + + app()->setLoggedIn($logged); + app()->setAccountLogged($account_logged); } } diff --git a/system/migrations/20.php b/system/migrations/20.php index ccc20a51..a21e001c 100644 --- a/system/migrations/20.php +++ b/system/migrations/20.php @@ -4,7 +4,7 @@ use MyAAC\Settings; function updateHighscoresIdsHidden(): void { - global $db; + $db = app()->get('database'); if (!$db->hasTable('players')) { return; diff --git a/system/pages/account/base.php b/system/pages/account/base.php index e644b610..ad4e1876 100644 --- a/system/pages/account/base.php +++ b/system/pages/account/base.php @@ -10,7 +10,7 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -if(!$logged) +if(!logged()) { $title = 'Login'; diff --git a/system/pages/account/change-email.php b/system/pages/account/change-email.php index c97b5541..b5a8e2bf 100644 --- a/system/pages/account/change-email.php +++ b/system/pages/account/change-email.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change E-Mail'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/change-info.php b/system/pages/account/change-info.php index 709dce27..0929e579 100644 --- a/system/pages/account/change-info.php +++ b/system/pages/account/change-info.php @@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change Info'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/change-password.php b/system/pages/account/change-password.php index bf172455..a5fb09a7 100644 --- a/system/pages/account/change-password.php +++ b/system/pages/account/change-password.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change Password'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/characters/change-comment.php b/system/pages/account/characters/change-comment.php index 7fa10c69..81495745 100644 --- a/system/pages/account/characters/change-comment.php +++ b/system/pages/account/characters/change-comment.php @@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change Comment'; require PAGES . 'account/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/characters/change-name.php b/system/pages/account/characters/change-name.php index 975369d1..1e98f953 100644 --- a/system/pages/account/characters/change-name.php +++ b/system/pages/account/characters/change-name.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change Name'; require PAGES . 'account/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/characters/change-sex.php b/system/pages/account/characters/change-sex.php index efefe7c9..48dc5348 100644 --- a/system/pages/account/characters/change-sex.php +++ b/system/pages/account/characters/change-sex.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Change Sex'; require PAGES . 'account/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/characters/create.php b/system/pages/account/characters/create.php index 5ad21dab..2c139f90 100644 --- a/system/pages/account/characters/create.php +++ b/system/pages/account/characters/create.php @@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Create Character'; require PAGES . 'account/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/characters/delete.php b/system/pages/account/characters/delete.php index af32070b..5ecd98e2 100644 --- a/system/pages/account/characters/delete.php +++ b/system/pages/account/characters/delete.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Delete Character'; require PAGES . 'account/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/create.php b/system/pages/account/create.php index 1c8f1e9f..db4b26d7 100644 --- a/system/pages/account/create.php +++ b/system/pages/account/create.php @@ -17,8 +17,7 @@ $title = 'Create Account'; if (setting('core.account_country')) require SYSTEM . 'countries.conf.php'; -if($logged) -{ +if(logged()) { echo 'Please logout before attempting to create a new account.'; return; } diff --git a/system/pages/account/login.php b/system/pages/account/login.php index 3e8ebba3..9c0d2709 100644 --- a/system/pages/account/login.php +++ b/system/pages/account/login.php @@ -29,6 +29,7 @@ if(!empty($login_account) && !empty($login_password)) $limiter->enabled = setting('core.account_login_ipban_protection'); $limiter->load(); + global $logged, $account_logged, $logged_flags; $account_logged = new OTS_Account(); if (config('account_login_by_email')) { $account_logged->findByEMail($login_account); @@ -69,6 +70,9 @@ if(!empty($login_account) && !empty($login_password)) $account_logged->setCustomField('web_lastlogin', time()); } + app()->setLoggedIn($logged); + app()->setAccountLogged($account_logged); + $hooks->trigger(HOOK_LOGIN, array('account' => $account_logged, 'password' => $login_password, 'remember_me' => $remember_me)); } diff --git a/system/pages/account/logout.php b/system/pages/account/logout.php index 55e15585..780ccc1d 100644 --- a/system/pages/account/logout.php +++ b/system/pages/account/logout.php @@ -13,7 +13,7 @@ $title = 'Logout'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/manage.php b/system/pages/account/manage.php index f5a34a25..63fec93b 100644 --- a/system/pages/account/manage.php +++ b/system/pages/account/manage.php @@ -14,7 +14,7 @@ $title = 'Account Management'; require __DIR__ . '/login.php'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/register-new.php b/system/pages/account/register-new.php index 04e8bf33..87e313a5 100644 --- a/system/pages/account/register-new.php +++ b/system/pages/account/register-new.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Register Account'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/account/register.php b/system/pages/account/register.php index f33f0b17..76b2f88c 100644 --- a/system/pages/account/register.php +++ b/system/pages/account/register.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Register Account'; require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { return; } diff --git a/system/pages/faq.php b/system/pages/faq.php index 155983b9..b1a77a52 100644 --- a/system/pages/faq.php +++ b/system/pages/faq.php @@ -168,10 +168,8 @@ class FAQ static public function move($id, $i, &$errors) { - global $db; $row = ModelsFAQ::find($id); - if($row) - { + if($row) { $ordering = $row->ordering + $i; $old_record = ModelsFAQ::where('ordering', $ordering)->first(); if($old_record) { @@ -182,8 +180,9 @@ class FAQ $row->ordering = $ordering; $row->save(); } - else + else { $errors[] = 'FAQ with id ' . $id . ' does not exists.'; + } return !count($errors); } diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php index 53fcdb71..5ef9c004 100644 --- a/system/pages/forum/edit_post.php +++ b/system/pages/forum/edit_post.php @@ -18,7 +18,7 @@ if ($ret === false) { return; } -if(!$logged) { +if(!logged()) { echo 'You are not logged in. Log in to post on the forum.

'; return; } diff --git a/system/pages/forum/move_thread.php b/system/pages/forum/move_thread.php index d9731e5b..40c09bf5 100644 --- a/system/pages/forum/move_thread.php +++ b/system/pages/forum/move_thread.php @@ -18,7 +18,7 @@ if ($ret === false) { return; } -if(!$logged) { +if(!logged()) { echo 'You are not logged in. Log in to post on the forum.

'; return; } diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php index b0db84fd..393dbb6c 100644 --- a/system/pages/forum/new_post.php +++ b/system/pages/forum/new_post.php @@ -18,7 +18,7 @@ if ($ret === false) { return; } -if(!$logged) { +if(!logged()) { $extra_url = ''; if(isset($_GET['thread_id'])) { $extra_url = '?action=new_post&thread_id=' . $_GET['thread_id']; diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php index e6c8fe80..88908c42 100644 --- a/system/pages/forum/new_thread.php +++ b/system/pages/forum/new_thread.php @@ -18,7 +18,7 @@ if ($ret === false) { return; } -if(!$logged) { +if(!logged()) { $extra_url = ''; if(isset($_GET['section_id'])) { $extra_url = '?action=new_thread§ion_id=' . $_GET['section_id']; diff --git a/system/pages/forum/remove_post.php b/system/pages/forum/remove_post.php index 690b3f75..bc6bf121 100644 --- a/system/pages/forum/remove_post.php +++ b/system/pages/forum/remove_post.php @@ -18,7 +18,7 @@ if ($ret === false) { return; } -if(!$logged) { +if(!logged()) { echo 'You are not logged in. Log in to post on the forum.

'; return; } diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php index 5997bdba..0147bc54 100644 --- a/system/pages/forum/show_board.php +++ b/system/pages/forum/show_board.php @@ -44,7 +44,7 @@ for($i = 0; $i < $threads_count['threads_count'] / setting('core.forum_threads_p echo 'Boards >> '.$sections[$section_id]['name'].''; -if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { +if(logged() && (!$sections[$section_id]['closed'] || Forum::isModerator())) { echo '

'; } @@ -94,7 +94,7 @@ if(isset($last_threads[0])) { } echo ''; - if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { + if(logged() && (!$sections[$section_id]['closed'] || Forum::isModerator())) { echo '
'; } } diff --git a/system/pages/gallery.php b/system/pages/gallery.php index cb854fca..a889f171 100644 --- a/system/pages/gallery.php +++ b/system/pages/gallery.php @@ -132,7 +132,7 @@ class Gallery { static public function add($comment, $image, $author, &$errors) { - global $db; + $db = app()->get('database'); if(isset($comment[0]) && isset($image[0]) && isset($author[0])) { $query = @@ -225,7 +225,7 @@ class Gallery static public function move($id, $i, &$errors) { - global $db; + $db = app()->get('database'); $query = self::get($id); if($query !== false) { diff --git a/system/pages/guilds/accept_invite.php b/system/pages/guilds/accept_invite.php index bc782480..294de2a7 100644 --- a/system/pages/guilds/accept_invite.php +++ b/system/pages/guilds/accept_invite.php @@ -15,7 +15,7 @@ require __DIR__ . '/base.php'; //set rights in guild $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null; -if(!$logged) { +if(!logged()) { $errors[] = 'You are not logged in. You can\'t accept invitations.'; } diff --git a/system/pages/guilds/add_rank.php b/system/pages/guilds/add_rank.php index e66ba49e..03ec6b12 100644 --- a/system/pages/guilds/add_rank.php +++ b/system/pages/guilds/add_rank.php @@ -22,7 +22,7 @@ if(empty($errors)) { if(!Validator::rankName($rank_name)) { $errors[] = 'Invalid rank name format.'; } - if(!$logged) { + if(!logged()) { $errors[] = 'You are not logged.'; } $guild = new OTS_Guild(); diff --git a/system/pages/guilds/change_description.php b/system/pages/guilds/change_description.php index 765665bf..600d96a8 100644 --- a/system/pages/guilds/change_description.php +++ b/system/pages/guilds/change_description.php @@ -26,7 +26,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/change_logo.php b/system/pages/guilds/change_logo.php index d8257e66..094ca43e 100644 --- a/system/pages/guilds/change_logo.php +++ b/system/pages/guilds/change_logo.php @@ -27,7 +27,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $guild_leader = false; $account_players = $account_logged->getPlayers(); diff --git a/system/pages/guilds/change_motd.php b/system/pages/guilds/change_motd.php index babb806c..e5280199 100644 --- a/system/pages/guilds/change_motd.php +++ b/system/pages/guilds/change_motd.php @@ -29,7 +29,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/change_nick.php b/system/pages/guilds/change_nick.php index bf773124..8f823d41 100644 --- a/system/pages/guilds/change_nick.php +++ b/system/pages/guilds/change_nick.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { $errors[] = "You are not logged in. You can't change nick."; $twig->display('error_box.html.twig', array('errors' => $errors)); $twig->display('guilds.back_button.html.twig'); diff --git a/system/pages/guilds/change_rank.php b/system/pages/guilds/change_rank.php index 4341db16..9cea6f47 100644 --- a/system/pages/guilds/change_rank.php +++ b/system/pages/guilds/change_rank.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); require __DIR__ . '/base.php'; -if(!$logged) { +if(!logged()) { $errors[] = "You are not logged in. You can't change rank."; } else { diff --git a/system/pages/guilds/cleanup_guilds.php b/system/pages/guilds/cleanup_guilds.php index 302d81f9..058a969e 100644 --- a/system/pages/guilds/cleanup_guilds.php +++ b/system/pages/guilds/cleanup_guilds.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); require __DIR__ . '/base.php'; -if(!$logged) +if(!logged()) { echo "You are not logged in."; $twig->display('guilds.back_button.html.twig'); diff --git a/system/pages/guilds/cleanup_players.php b/system/pages/guilds/cleanup_players.php index 7e02fbeb..422c96d3 100644 --- a/system/pages/guilds/cleanup_players.php +++ b/system/pages/guilds/cleanup_players.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); require __DIR__ . '/base.php'; -if(!$logged) +if(!logged()) { echo "You are not logged in."; $twig->display('guilds.back_button.html.twig'); diff --git a/system/pages/guilds/create.php b/system/pages/guilds/create.php index b404c494..aaba6541 100644 --- a/system/pages/guilds/create.php +++ b/system/pages/guilds/create.php @@ -17,7 +17,7 @@ require __DIR__ . '/base.php'; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; $todo = isset($_REQUEST['todo']) ? $_REQUEST['todo'] : NULL; -if(!$logged) { +if(!logged()) { $guild_errors[] = 'You are not logged in. You can\'t create guild.'; } diff --git a/system/pages/guilds/delete_by_admin.php b/system/pages/guilds/delete_by_admin.php index e403cbda..2f1abee5 100644 --- a/system/pages/guilds/delete_by_admin.php +++ b/system/pages/guilds/delete_by_admin.php @@ -26,7 +26,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { if(admin()) { $saved = false; if(isset($_POST['todo']) && $_POST['todo'] == 'save') { diff --git a/system/pages/guilds/delete_guild.php b/system/pages/guilds/delete_guild.php index 978ac513..bdbc27fa 100644 --- a/system/pages/guilds/delete_guild.php +++ b/system/pages/guilds/delete_guild.php @@ -26,7 +26,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/delete_invite.php b/system/pages/guilds/delete_invite.php index 7bf4067a..a4555fa1 100644 --- a/system/pages/guilds/delete_invite.php +++ b/system/pages/guilds/delete_invite.php @@ -15,7 +15,7 @@ require __DIR__ . '/base.php'; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $name = stripslashes($_REQUEST['name']); -if(!$logged) +if(!logged()) $errors[] = 'You are not logged in. You can\'t delete invitations.'; if(!Validator::guildName($guild_name)) diff --git a/system/pages/guilds/delete_rank.php b/system/pages/guilds/delete_rank.php index 56322cd9..3a468917 100644 --- a/system/pages/guilds/delete_rank.php +++ b/system/pages/guilds/delete_rank.php @@ -26,7 +26,7 @@ if(empty($guild_errors)) { } } if(empty($guild_errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/invite.php b/system/pages/guilds/invite.php index 8fae8e27..528a5a5e 100644 --- a/system/pages/guilds/invite.php +++ b/system/pages/guilds/invite.php @@ -15,7 +15,7 @@ require __DIR__ . '/base.php'; //set rights in guild $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; -if(!$logged) { +if(!logged()) { $errors[] = "You are not logged in. You can't invite players."; } diff --git a/system/pages/guilds/kick_player.php b/system/pages/guilds/kick_player.php index 5ce79187..8aa64c9c 100644 --- a/system/pages/guilds/kick_player.php +++ b/system/pages/guilds/kick_player.php @@ -16,7 +16,7 @@ require __DIR__ . '/base.php'; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null; -if(!$logged) { +if(!logged()) { $errors[] = 'You are not logged in. You can\'t kick characters.'; } diff --git a/system/pages/guilds/leave.php b/system/pages/guilds/leave.php index 9a11595d..3cdf5853 100644 --- a/system/pages/guilds/leave.php +++ b/system/pages/guilds/leave.php @@ -15,7 +15,7 @@ require __DIR__ . '/base.php'; //set rights in guild $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; -if(!$logged) { +if(!logged()) { $errors[] = "You are not logged in. You can't leave guild."; } diff --git a/system/pages/guilds/list.php b/system/pages/guilds/list.php index 96d7bf08..d51f8fc7 100644 --- a/system/pages/guilds/list.php +++ b/system/pages/guilds/list.php @@ -39,6 +39,6 @@ if(count($guilds_list) > 0) $twig->display('guilds.list.html.twig', array( 'guilds' => $guilds, - 'logged' => isset($logged) ? $logged : false, + 'logged' => logged(), 'isAdmin' => admin(), )); diff --git a/system/pages/guilds/manager.php b/system/pages/guilds/manager.php index 4d59c22e..f2456653 100644 --- a/system/pages/guilds/manager.php +++ b/system/pages/guilds/manager.php @@ -26,7 +26,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/pass_leadership.php b/system/pages/guilds/pass_leadership.php index c09b4285..e490d06f 100644 --- a/system/pages/guilds/pass_leadership.php +++ b/system/pages/guilds/pass_leadership.php @@ -56,7 +56,7 @@ if(empty($guild_errors)) { } } if(empty($guild_errors) && empty($guild_errors2)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $guild_leader = false; $account_players = $account_logged->getPlayers(); diff --git a/system/pages/guilds/save_ranks.php b/system/pages/guilds/save_ranks.php index e1483659..6b8f1143 100644 --- a/system/pages/guilds/save_ranks.php +++ b/system/pages/guilds/save_ranks.php @@ -26,7 +26,7 @@ if(empty($errors)) { } if(empty($errors)) { - if($logged) { + if(logged()) { $guild_leader_char = $guild->getOwner(); $rank_list = $guild->getGuildRanksList(); $rank_list->orderBy('level', POT::ORDER_DESC); diff --git a/system/pages/guilds/show.php b/system/pages/guilds/show.php index 33039ad3..69e38fc6 100644 --- a/system/pages/guilds/show.php +++ b/system/pages/guilds/show.php @@ -47,8 +47,7 @@ $level_in_guild = 0; $players_from_account_in_guild = array(); $players_from_account_ids = array(); -if($logged) -{ +if(logged()) { $account_players = $account_logged->getPlayers(); foreach($account_players as $player) { @@ -127,7 +126,7 @@ include(SYSTEM . 'libs/pot/InvitesDriver.php'); new InvitesDriver($guild); $invited_list = $guild->listInvites(); $show_accept_invite = 0; -if($logged && count($invited_list) > 0) +if(logged() && count($invited_list) > 0) { foreach($invited_list as $invited_player) { diff --git a/system/pages/highscores.php b/system/pages/highscores.php index 91ba2e2b..a506d852 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -139,7 +139,7 @@ $highscores = []; $needReCache = true; $cacheKey = 'highscores_' . $skill . '_' . $vocation . '_' . $page . '_' . $configHighscoresPerPage; -$cache = Cache::getInstance(); +$cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch($cacheKey, $tmp)) { diff --git a/system/pages/news.php b/system/pages/news.php index dc8c700e..9baebc88 100644 --- a/system/pages/news.php +++ b/system/pages/news.php @@ -105,7 +105,7 @@ if(isset($_GET['archive'])) header('X-XSS-Protection: 0'); $title = 'Latest News'; -$cache = Cache::getInstance(); +$cache = app()->get('cache'); $news_cached = false; if($cache->enabled()) diff --git a/system/pages/polls.php b/system/pages/polls.php index 37372f25..c285aa0e 100644 --- a/system/pages/polls.php +++ b/system/pages/polls.php @@ -48,7 +48,7 @@ function getColorByPercent($percent) Log in to vote in polls.

'; + if(!logged()) { return; } diff --git a/system/settings.php b/system/settings.php index 56722b0a..b8a5c176 100644 --- a/system/settings.php +++ b/system/settings.php @@ -1544,7 +1544,8 @@ Sent by MyAAC,
'default' => 'premium_points', 'callbacks' => [ 'beforeSave' => function($key, $value, &$errorMessage) { - global $db; + $db = app()->get('database'); + if ($value == 'coins' && !$db->hasColumn('accounts', 'coins')) { $errorMessage = "Shop: Donate Column: Cannot set column to coins, because it doesn't exist in database."; return false; diff --git a/system/src/App/App.php b/system/src/App/App.php index 848950b8..113fcbca 100644 --- a/system/src/App/App.php +++ b/system/src/App/App.php @@ -16,7 +16,7 @@ use Twig\Loader\FilesystemLoader; class App { private bool $isLoggedIn = false; - private ?\OTS_Account $accountLogged = null; + private ?\OTS_Account $accountLogged; private array $instances = []; public function run(): void @@ -37,9 +37,10 @@ class App $this->accountLogged = $checkLogin['account']; $this->isLoggedIn = $checkLogin['logged']; - global $logged, $account_logged; + global $logged, $account_logged, $logged_flags; $logged = $this->isLoggedIn; $account_logged = $this->accountLogged; + $logged_flags = $checkLogin['flags']; $statusService = new StatusService(); $status = $statusService->checkStatus(); diff --git a/system/src/Changelog.php b/system/src/Changelog.php index bd07c400..363e2316 100644 --- a/system/src/Changelog.php +++ b/system/src/Changelog.php @@ -119,7 +119,7 @@ class Changelog { global $template_name; - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; @@ -134,7 +134,7 @@ class Changelog static public function clearCache() { global $template_name; - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if (!$cache->enabled()) { return; } diff --git a/system/src/Commands/MigrateRunCommand.php b/system/src/Commands/MigrateRunCommand.php index edfa108d..8f760f59 100644 --- a/system/src/Commands/MigrateRunCommand.php +++ b/system/src/Commands/MigrateRunCommand.php @@ -54,7 +54,7 @@ class MigrateRunCommand extends Command private function executeMigration($id, $io): void { - global $db; + $db = app()->get('database'); $db->revalidateCache(); diff --git a/system/src/CreateCharacter.php b/system/src/CreateCharacter.php index 89443e71..a11265e3 100644 --- a/system/src/CreateCharacter.php +++ b/system/src/CreateCharacter.php @@ -132,7 +132,7 @@ class CreateCharacter return false; } - global $db; + $db = app()->get('database'); if($sex == "0") $playerSample->setLookType(136); @@ -250,7 +250,7 @@ class CreateCharacter return false; } - global $twig; + $twig = app()->get('twig'); $twig->display('success.html.twig', array( 'title' => 'Character Created', 'description' => 'The character ' . $name . ' has been created.
diff --git a/system/src/Data.php b/system/src/Data.php index 6d264c46..53bca214 100644 --- a/system/src/Data.php +++ b/system/src/Data.php @@ -20,25 +20,25 @@ class Data public function get($where) { - global $db; + $db = app()->get('database'); return $db->select($this->table, $where); } public function add($data) { - global $db; + $db = app()->get('database'); return $db->insert($this->table, $data); } public function delete($data, $where) { - global $db; + $db = app()->get('database'); return $db->delete($this->table, $data, $where); } public function update($data, $where) { - global $db; + $db = app()->get('database'); return $db->update($this->table, $data, $where); } } diff --git a/system/src/DataLoader.php b/system/src/DataLoader.php index cfa756cd..d3bec8e4 100644 --- a/system/src/DataLoader.php +++ b/system/src/DataLoader.php @@ -81,12 +81,12 @@ class DataLoader self::$startTime = microtime(true); - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $cache->delete('towns'); // will be reloaded after next page load } - global $db; + $db = app()->get('database'); if ($db->hasTable('towns') && Town::count() > 0) { success(self::$locale['step_database_loaded_towns'] . self::getLoadedTime()); } diff --git a/system/src/Forum.php b/system/src/Forum.php index 199e279b..1274075a 100644 --- a/system/src/Forum.php +++ b/system/src/Forum.php @@ -37,13 +37,15 @@ class Forum */ public static function canPost($account) { - global $db, $config; - - if(!$account->isLoaded() || $account->isBanned()) + if(!$account->isLoaded() || $account->isBanned()) { return false; + } - if(self::isModerator()) + if(self::isModerator()) { return true; + } + + $db = app()->get('database'); return $db->query( @@ -58,7 +60,7 @@ class Forum public static function add_thread($title, $body, $section_id, $player_id, $account_id, &$errors) { - global $db; + $db = app()->get('database'); $thread_id = 0; if($db->insert(FORUM_TABLE_PREFIX . 'forum', array( 'first_post' => 0, @@ -83,7 +85,7 @@ class Forum public static function add_post($thread_id, $section, $author_aid, $author_guid, $post_text, $post_topic, $smile, $html) { - global $db; + $db = app()->get('database'); $db->insert(FORUM_TABLE_PREFIX . 'forum', array( 'first_post' => $thread_id, 'section' => $section, @@ -99,7 +101,7 @@ class Forum } public static function add_board($name, $description, $access, $guild, &$errors) { - global $db; + $db = app()->get('database'); if(isset($name[0]) && isset($description[0])) { $query = $db->select(TABLE_PREFIX . 'forum_boards', array('name' => $name)); @@ -129,19 +131,21 @@ class Forum return !count($errors); } - public static function get_board($id) { - global $db; + public static function get_board($id) + { + $db = app()->get('database'); return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id)); } - public static function update_board($id, $name, $access, $guild, $description) { - global $db; + public static function update_board($id, $name, $access, $guild, $description) + { + $db = app()->get('database'); $db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild), array('id' => $id)); } public static function delete_board($id, &$errors) { - global $db; + $db = app()->get('database'); if(isset($id)) { if(self::get_board($id) !== false) @@ -157,7 +161,7 @@ class Forum public static function toggleHide_board($id, &$errors) { - global $db; + $db = app()->get('database'); if(isset($id)) { $query = self::get_board($id); @@ -174,7 +178,7 @@ class Forum public static function move_board($id, $i, &$errors) { - global $db; + $db = app()->get('database'); $query = self::get_board($id); if($query !== false) { @@ -295,12 +299,12 @@ class Forum $hasAccess = true; $section = $sections[$board_id]; if($section['guild'] > 0) { - if(app()->isLoggedIn()) { + if(logged()) { $guild = new \OTS_Guild(); $guild->load($section['guild']); $status = false; if($guild->isLoaded()) { - $account_players = app()->getAccountLogged()->getPlayersList(); + $account_players = accountLogged()->getPlayersList(); foreach ($account_players as $player) { if($guild->hasMember($player)) { $status = true; @@ -316,7 +320,7 @@ class Forum } if($section['access'] > 0) { - $logged_access = app()->isLoggedIn() ? app()->getAccountLogged()->getAccess() : 0; + $logged_access = logged() ? accountLogged()->getAccess() : 0; if($logged_access < $section['access']) { $hasAccess = false; } diff --git a/system/src/Models/Guild.php b/system/src/Models/Guild.php index bd7ded8d..63d9a720 100644 --- a/system/src/Models/Guild.php +++ b/system/src/Models/Guild.php @@ -11,7 +11,7 @@ class Guild extends Model { public function owner() { - global $db; + $db = app()->get('database'); $column = 'ownerid'; if($db->hasColumn('guilds', 'owner_id')) { $column = 'owner_id'; diff --git a/system/src/Models/Player.php b/system/src/Models/Player.php index 77fe4504..91478fa4 100644 --- a/system/src/Models/Player.php +++ b/system/src/Models/Player.php @@ -40,7 +40,7 @@ class Player extends Model { public function scopeOrderBySkill($query, $value) { - global $db; + $db = app()->get('database'); $query->when($db->hasColumn('players', 'skill_fist'), function ($query) { }); @@ -69,8 +69,9 @@ class Player extends Model { return false; } - public function scopeNotDeleted($query) { - global $db; + public function scopeNotDeleted($query) + { + $db = app()->get('database'); $column = 'deleted'; if($db->hasColumn('players', 'deletion')) { @@ -82,7 +83,7 @@ class Player extends Model { public function scopeWithOnlineStatus($query) { - global $db; + $db = app()->get('database'); if ($db->hasColumn('players', 'online')) { $query->addSelect('online'); } @@ -99,7 +100,7 @@ class Player extends Model { public function getOnlineStatusAttribute() { - global $db; + $db = app()->get('database'); if ($db->hasColumn('players', 'online')) { return $this->online; } diff --git a/system/src/News.php b/system/src/News.php index 15849d85..988abd58 100644 --- a/system/src/News.php +++ b/system/src/News.php @@ -182,7 +182,7 @@ class News { global $template_name; - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; @@ -196,7 +196,7 @@ class News static public function clearCache() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if (!$cache->enabled()) { return; } diff --git a/system/src/Plugins.php b/system/src/Plugins.php index aba192c2..7af31113 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -13,7 +13,7 @@ class Plugins { public static function getRoutes() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins_routes', $tmp)) { @@ -146,7 +146,7 @@ class Plugins { public static function getThemes() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins_themes', $tmp)) { @@ -178,7 +178,7 @@ class Plugins { public static function getCommands() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins_commands', $tmp)) { @@ -207,7 +207,7 @@ class Plugins { public static function getHooks() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins_hooks', $tmp)) { @@ -257,7 +257,7 @@ class Plugins { public static function getAllPluginsSettings() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins_settings', $tmp)) { @@ -287,7 +287,7 @@ class Plugins { public static function getAllPluginsJson($disabled = false) { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('plugins', $tmp)) { @@ -357,7 +357,7 @@ class Plugins { public static function install($file): bool { - global $db; + $db = app()->get('database'); if(!\class_exists('\ZipArchive')) { throw new \RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.'); @@ -660,7 +660,7 @@ class Plugins { return false; } - global $db; + $db = app()->get('database'); if (file_exists(BASE . $plugin_json['install'])) { $db->revalidateCache(); require BASE . $plugin_json['install']; @@ -770,7 +770,7 @@ class Plugins { */ public static function installMenus($templateName, $menus, $clearOld = false) { - global $db; + $db = app()->get('database'); if ($clearOld) { Menu::where('template', $templateName)->delete(); diff --git a/system/src/RateLimit.php b/system/src/RateLimit.php index df4349e5..32def71e 100644 --- a/system/src/RateLimit.php +++ b/system/src/RateLimit.php @@ -42,7 +42,7 @@ class RateLimit public function increment(string $ip): bool { - global $cache; + $cache = app()->get('cache'); if ($this->enabled && $cache->enabled()) { if (isset($this->data[$ip]['attempts']) && isset($this->data[$ip]['last'])) { $this->data[$ip]['attempts']++; @@ -75,7 +75,7 @@ class RateLimit public function save(): void { - global $cache; + $cache = app()->get('cache'); if (!$this->enabled || !$cache->enabled()) { return; } @@ -86,7 +86,7 @@ class RateLimit public function load(): void { - global $cache; + $cache = app()->get('cache'); if (!$this->enabled) { return; } diff --git a/system/src/Services/LoginService.php b/system/src/Services/LoginService.php index f73783d9..8c225711 100644 --- a/system/src/Services/LoginService.php +++ b/system/src/Services/LoginService.php @@ -6,8 +6,6 @@ class LoginService { public function checkLogin(): array { - global $logged_flags; - $logged = false; $logged_flags = 0; $account_logged = new \OTS_Account(); @@ -23,7 +21,7 @@ class LoginService } else { unsetSession('account'); - unset($account_logged); + $account_logged = new \OTS_Account(); } } @@ -44,6 +42,7 @@ class LoginService return [ 'logged' => $logged, 'account' => $account_logged, + 'flags' => $logged_flags, ]; } } diff --git a/system/src/Services/RouterService.php b/system/src/Services/RouterService.php index a7d81ab1..e7ab8a33 100644 --- a/system/src/Services/RouterService.php +++ b/system/src/Services/RouterService.php @@ -13,8 +13,8 @@ class RouterService $db = app()->get('database'); $twig = app()->get('twig'); - $logged = app()->isLoggedIn(); - $account_logged = app()->getAccountLogged(); + $logged = logged(); + $account_logged = accountLogged(); if(!isset($content[0])) { $content = ''; @@ -32,7 +32,7 @@ class RouterService $load_it = false; } - if(!$logged) { + if(!logged()) { ob_start(); require SYSTEM . 'pages/account/manage.php'; $content .= ob_get_contents(); diff --git a/system/src/Settings.php b/system/src/Settings.php index 34b7b68c..56316729 100644 --- a/system/src/Settings.php +++ b/system/src/Settings.php @@ -28,7 +28,7 @@ class Settings implements \ArrayAccess public function load() { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('settings', $tmp)) { @@ -72,7 +72,7 @@ class Settings implements \ArrayAccess } } - global $db; + $db = app()->get('database'); try { $db->beginTransaction(); @@ -630,7 +630,7 @@ class Settings implements \ArrayAccess public function clearCache(): void { - $cache = Cache::getInstance(); + $cache = app()->get('cache'); if ($cache->enabled()) { $cache->delete('settings'); } diff --git a/system/src/UsageStatistics.php b/system/src/UsageStatistics.php index 1fd45b33..f6433eb5 100644 --- a/system/src/UsageStatistics.php +++ b/system/src/UsageStatistics.php @@ -33,7 +33,9 @@ class UsageStatistics { } public static function getStats() { - global $config, $db; + global $config; + + $db = app()->get('database'); $ret = array(); diff --git a/system/src/Validator.php b/system/src/Validator.php index ad9e3e50..204b0988 100644 --- a/system/src/Validator.php +++ b/system/src/Validator.php @@ -237,7 +237,9 @@ class Validator */ public static function newCharacterName($name) { - global $db, $config; + global $config; + + $db = app()->get('database'); $name_lower = strtolower($name); diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index 784889f4..2675e259 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -24,7 +24,7 @@ if(isset($config['boxes']))