Avoid globals where possible

$logged => logged()
$account_logged => accountLogged()
This commit is contained in:
slawkens 2025-03-16 12:36:22 +01:00
parent a71f41193c
commit 13b8fcf454
85 changed files with 226 additions and 192 deletions

View File

@ -6,11 +6,9 @@ use MyAAC\Services\StatusService;
// few things we'll need // few things we'll need
require '../common.php'; require '../common.php';
const ADMIN_PANEL = true;
const MYAAC_ADMIN = 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/'); header('Location: ' . BASE_URL . 'install/');
exit; exit;
} }
@ -32,8 +30,11 @@ require __DIR__ . '/includes/debugbar.php';
$loginService = new LoginService(); $loginService = new LoginService();
$checkLogin = $loginService->checkLogin(); $checkLogin = $loginService->checkLogin();
$logged = $checkLogin['logged']; $logged = $checkLogin['logged'];
$account_logged = $checkLogin['account']; $account_logged = $checkLogin['account'];
app()->setLoggedIn($logged);
app()->setAccountLogged($account_logged); app()->setAccountLogged($account_logged);
$statusService = new StatusService(); $statusService = new StatusService();
@ -49,7 +50,7 @@ if (ACTION == 'logout') {
} }
// if we're not logged in - show login box // if we're not logged in - show login box
if(!$logged || !admin()) { if(!logged() || !admin()) {
$page = 'login'; $page = 'login';
} }

View File

@ -13,7 +13,7 @@ $title = 'Login';
csrfProtect(); csrfProtect();
require PAGES . 'account/login.php'; require PAGES . 'account/login.php';
if ($logged) { if (logged()) {
header('Location: ' . (admin() ? ADMIN_URL : BASE_URL)); header('Location: ' . (admin() ? ADMIN_URL : BASE_URL));
return; return;
} }

View File

@ -57,13 +57,14 @@ function admin_give_coins($coins)
function admin_give_premdays($days) function admin_give_premdays($days)
{ {
global $db, $freePremium; global $freePremium;
if ($freePremium) { if ($freePremium) {
displayMessage('Premium days not supported. Free Premium enabled.'); displayMessage('Premium days not supported. Free Premium enabled.');
return; return;
} }
$db = app()->get('database');
$value = $days * 86400; $value = $days * 86400;
$now = time(); $now = time();
// othire // othire
@ -174,10 +175,12 @@ else {
} }
function displayMessage($message, $success = false) { function displayMessage($message, $success = false) {
global $twig, $hasCoinsColumn, $hasPointsColumn, $freePremium; global $hasCoinsColumn, $hasPointsColumn, $freePremium;
$success ? success($message): error($message); $success ? success($message): error($message);
$twig = app()->get('twig');
$twig->display('admin.tools.account.html.twig', array( $twig->display('admin.tools.account.html.twig', array(
'hasCoinsColumn' => $hasCoinsColumn, 'hasCoinsColumn' => $hasCoinsColumn,
'hasPointsColumn' => $hasPointsColumn, 'hasPointsColumn' => $hasPointsColumn,

View File

@ -99,9 +99,9 @@ else {
} }
function displayMessage($message, $success = false) { function displayMessage($message, $success = false)
global $twig; {
$twig = app()->get('twig');
$success ? success($message): error($message); $success ? success($message): error($message);
$twig->display('admin.tools.teleport.html.twig', array()); $twig->display('admin.tools.teleport.html.twig', array());
} }

View File

@ -203,7 +203,7 @@ if (isset($_POST['template'])) {
function onTemplateMenusChange(): void function onTemplateMenusChange(): void
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$cache->delete('template_menus'); $cache->delete('template_menus');
} }

View File

@ -21,7 +21,7 @@
</head> </head>
<body class="sidebar-mini "> <body class="sidebar-mini ">
<?php $hooks->trigger(HOOK_ADMIN_BODY_START); ?> <?php $hooks->trigger(HOOK_ADMIN_BODY_START); ?>
<?php if ($logged && admin()) { ?> <?php if (logged() && admin()) { ?>
<div class="wrapper"> <div class="wrapper">
<nav class="main-header navbar navbar-expand navbar-white navbar-light"> <nav class="main-header navbar navbar-expand navbar-white navbar-light">
<ul class="navbar-nav"> <ul class="navbar-nav">
@ -177,7 +177,7 @@
<div id="sidebar-overlay"></div> <div id="sidebar-overlay"></div>
</div> </div>
<?php } else if (!$logged && !admin()) { <?php } else if (!logged() && !admin()) {
echo $content; echo $content;
} }
?> ?>
@ -185,7 +185,7 @@
/** /**
* @var OTS_Account $account_logged * @var OTS_Account $account_logged
*/ */
if ($logged && admin()) { if (logged() && admin()) {
$twig->display('admin-bar.html.twig', [ $twig->display('admin-bar.html.twig', [
'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId() 'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId()
]); ]);

View File

@ -2,7 +2,9 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
function query($query) function query($query)
{ {
global $db, $error; global $error;
$db = app()->get('database');
try { try {
$db->query($query); $db->query($query);

View File

@ -12,7 +12,7 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save
return; return;
} }
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
// clear plugin_hooks to have fresh hooks // clear plugin_hooks to have fresh hooks
$cache->delete('plugins_hooks'); $cache->delete('plugins_hooks');

View File

@ -33,7 +33,9 @@ if ($db->hasTable('players')) {
$time = time(); $time = time();
function insert_sample_if_not_exist($p) 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'])); $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($p['name']));
if ($query->rowCount() == 0) { if ($query->rowCount() == 0) {

View File

@ -15,7 +15,7 @@ define('COUNTER_SYNC', 10); // how often counter is synchronized with database (
$views_counter = 1; // default value, must be here! $views_counter = 1; // default value, must be here!
$cache = Cache::getInstance(); $cache = app()->get('cache');
if($cache->enabled()) if($cache->enabled())
{ {
$value = 0; $value = 0;

View File

@ -275,7 +275,10 @@ function generateRandomString($length, $lowCase = true, $upCase = false, $numeri
*/ */
function getForumBoards() 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' : '') . $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`;'); ' ORDER BY `ordering`;');
if($sections) if($sections)
@ -351,13 +354,12 @@ function updateDatabaseConfig($name, $value)
*/ */
function encrypt($str) function encrypt($str)
{ {
global $config; $configDatabaseSalt = config('database_salt');
if(isset($config['database_salt'])) // otserv if(isset($configDatabaseSalt)) // otserv
$str .= $config['database_salt']; $str .= $configDatabaseSalt;
$encryptionType = $config['database_encryption']; $encryptionType = config('database_encryption');
if(isset($encryptionType) && strtolower($encryptionType) !== 'plain') if(isset($encryptionType) && strtolower($encryptionType) !== 'plain') {
{
if($encryptionType === 'vahash') if($encryptionType === 'vahash')
return base64_encode(hash('sha256', $str)); return base64_encode(hash('sha256', $str));
@ -433,7 +435,7 @@ function delete_guild($id)
if(count($rank_list) > 0) { if(count($rank_list) > 0) {
$rank_list->orderBy('level'); $rank_list->orderBy('level');
global $db; $db = app()->get('database');
/** /**
* @var OTS_GuildRank $rank_in_guild * @var OTS_GuildRank $rank_in_guild
*/ */
@ -495,9 +497,11 @@ function tickers()
*/ */
function template_place_holder($type): string function template_place_holder($type): string
{ {
global $twig, $template_place_holders, $debugBar; global $template_place_holders, $debugBar;
$ret = ''; $ret = '';
$twig = app()->get('twig');
if (isset($debugBar)) { if (isset($debugBar)) {
$debugBarRenderer = $debugBar->getJavascriptRenderer(); $debugBarRenderer = $debugBar->getJavascriptRenderer();
} }
@ -529,9 +533,11 @@ function template_place_holder($type): string
*/ */
function template_header($is_admin = false): string function template_header($is_admin = false): string
{ {
global $title_full, $twig; global $title_full;
$charset = setting('core.charset') ?? 'utf-8'; $charset = setting('core.charset') ?? 'utf-8';
$twig = app()->get('twig');
return $twig->render('templates.header.html.twig', return $twig->render('templates.header.html.twig',
[ [
'charset' => $charset, 'charset' => $charset,
@ -583,7 +589,7 @@ function template_footer(): string
function template_ga_code() function template_ga_code()
{ {
global $twig; $twig = app()->get('twig');
if(!isset(setting('core.google_analytics_id')[0])) if(!isset(setting('core.google_analytics_id')[0]))
return ''; return '';
@ -602,7 +608,7 @@ function template_form()
foreach($templates as $value) foreach($templates as $value)
$options .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>'; $options .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>';
global $twig; $twig = app()->get('twig');
return $twig->render('forms.change_template.html.twig', ['options' => $options]); return $twig->render('forms.change_template.html.twig', ['options' => $options]);
} }
@ -717,13 +723,20 @@ function getSkillName($skillId, $suffix = true)
return 'unknown'; 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. * Performs flag check on the current logged in user.
* Table in database: accounts, field: website_flags * Table in database: accounts, field: website_flags
*/ */
function hasFlag(int $flag): bool { function hasFlag(int $flag): bool {
global $logged, $logged_flags; return (logged() && (accountLogged()->getWebFlags() & $flag) == $flag);
return ($logged && ($logged_flags & $flag) == $flag);
} }
/** /**
* Check if current logged user have got admin flag set. * 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) function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true)
{ {
global $mailer, $config; global $mailer;
if (!setting('core.mail_enabled')) { if (!setting('core.mail_enabled')) {
log_append('mailer-error.log', '_mail() function has been used, but Mail Support is disabled.'); 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->From = setting('core.mail_address');
$mailer->Sender = setting('core.mail_address'); $mailer->Sender = setting('core.mail_address');
$mailer->CharSet = 'utf-8'; $mailer->CharSet = 'utf-8';
$mailer->FromName = $config['lua']['serverName']; $mailer->FromName = configLua('serverName');
$mailer->Subject = $subject; $mailer->Subject = $subject;
$mailer->addAddress($to); $mailer->addAddress($to);
$mailer->Body = $tmp_body; $mailer->Body = $tmp_body;
@ -1110,7 +1123,7 @@ function csrfProtect(): void
} }
function getTopPlayers($limit = 5, $skill = 'level') { function getTopPlayers($limit = 5, $skill = 'level') {
global $db; $db = app()->get('database');
if ($skill === 'level') { if ($skill === 'level') {
$skill = 'experience'; $skill = 'experience';
@ -1253,7 +1266,7 @@ function clearCache()
} }
} }
global $db; $db = app()->get('database');
$db->setClearCacheAfter(true); $db->setClearCacheAfter(true);
} }
@ -1281,7 +1294,8 @@ function clearRouteCache(): void
function getCustomPageInfo($name) function getCustomPageInfo($name)
{ {
global $logged_access; $logged_access = logged() ? accountLogged()->getAccess() : 0;
$page = Pages::isPublic() $page = Pages::isPublic()
->where('name', 'LIKE', $name) ->where('name', 'LIKE', $name)
->where('access', '<=', $logged_access) ->where('access', '<=', $logged_access)
@ -1295,7 +1309,9 @@ function getCustomPageInfo($name)
} }
function getCustomPage($name, &$success): string function getCustomPage($name, &$success): string
{ {
global $twig, $title, $ignore; global $title, $ignore;
$twig = app()->get('twig');
$success = false; $success = false;
$content = ''; $content = '';
@ -1509,8 +1525,7 @@ function verify_number($number, $name, $max_length)
function Outfits_loadfromXML() 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; } if (!file_exists($file_path)) { return null; }
$xml = new DOMDocument; $xml = new DOMDocument;
@ -1535,8 +1550,7 @@ function Outfits_loadfromXML()
function Mounts_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; } if (!file_exists($file_path)) { return null; }
$xml = new DOMDocument; $xml = new DOMDocument;
@ -1659,8 +1673,10 @@ function getGuildLogoById($id)
return BASE_URL . GUILD_IMAGES_DIR . $logo; return BASE_URL . GUILD_IMAGES_DIR . $logo;
} }
function displayErrorBoxWithBackButton($errors, $action = null) { function displayErrorBoxWithBackButton($errors, $action = null)
global $twig; {
$twig = app()->get('twig');
$twig->display('error_box.html.twig', ['errors' => $errors]); $twig->display('error_box.html.twig', ['errors' => $errors]);
$twig->display('account.back_button.html.twig', [ $twig->display('account.back_button.html.twig', [
'action' => $action ?: getLink('') 'action' => $action ?: getLink('')

View File

@ -478,12 +478,12 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
public function isPremium() public function isPremium()
{ {
global $config; $configFreePremium = configLua('freePremium');
if(isset($config['lua']['freePremium']) && getBoolean($config['lua']['freePremium'])) return true; if(isset($configFreePremium) && getBoolean($configFreePremium)) return true;
if(isset($this->data['premium_ends_at'])) { if(isset($this->data['premium_ends_at'])) {
return $this->data['premium_ends_at'] > time(); return $this->data['premium_ends_at'] > time();
} }
if(isset($this->data['premend'])) { if(isset($this->data['premend'])) {
return $this->data['premend'] > time(); 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']); $filter->compareField('account_id', (int) $this->data['id']);
if(!$withDeleted) { if(!$withDeleted) {
global $db; $db = app()->get('database');
if($db->hasColumn('players', 'deletion')) { if($db->hasColumn('players', 'deletion')) {
$filter->compareField('deletion', 0); $filter->compareField('deletion', 0);
} else { } else {
@ -936,7 +936,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
return $this->data['group_id']; return $this->data['group_id'];
} }
global $db; $db = app()->get('database');
if($db->hasColumn('accounts', 'group_id')) { if($db->hasColumn('accounts', 'group_id')) {
$query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch(); $query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch();
// if anything was found // if anything was found
@ -963,7 +963,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
return $this->data['group_id']; return $this->data['group_id'];
} }
global $db; $db = app()->get('database');
if($db->hasColumn('accounts', 'group_id')) { if($db->hasColumn('accounts', 'group_id')) {
$query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch(); $query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch();
// if anything was found // if anything was found

View File

@ -97,14 +97,13 @@ class OTS_DB_MySQL extends OTS_Base_DB
$params['persistent'] = false; $params['persistent'] = false;
} }
global $config;
$cache = app()->get('cache'); $cache = app()->get('cache');
if($cache->enabled()) { if($cache->enabled()) {
$tmp = null; $tmp = null;
$need_revalidation = true; $need_revalidation = true;
if($cache->fetch('database_checksum', $tmp) && $tmp) { if($cache->fetch('database_checksum', $tmp) && $tmp) {
$tmp = unserialize($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; $need_revalidation = false;
} }
} }
@ -148,8 +147,6 @@ class OTS_DB_MySQL extends OTS_Base_DB
public function __destruct() public function __destruct()
{ {
global $config;
$cache = app()->get('cache'); $cache = app()->get('cache');
if($cache->enabled()) { if($cache->enabled()) {
if ($this->clearCacheAfter) { if ($this->clearCacheAfter) {
@ -160,7 +157,7 @@ class OTS_DB_MySQL extends OTS_Base_DB
else { else {
$cache->set('database_tables', serialize($this->has_table_cache), 3600); $cache->set('database_tables', serialize($this->has_table_cache), 3600);
$cache->set('database_columns', serialize($this->has_column_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) { 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) { public function hasColumn($table, $column) {

View File

@ -490,7 +490,9 @@ class OTS_Group extends OTS_Row_DAO implements IteratorAggregate, Countable
// creates filter // creates filter
$filter = new OTS_SQLFilter(); $filter = new OTS_SQLFilter();
$filter->compareField('group_id', (int) $this->data['id']); $filter->compareField('group_id', (int) $this->data['id']);
global $db;
$db = app()->get('database');
if($db->hasColumn('players', 'deletion')) if($db->hasColumn('players', 'deletion'))
$filter->compareField('deletion', 0); $filter->compareField('deletion', 0);
else else

View File

@ -284,8 +284,6 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
} }
public function hasMember(OTS_Player $player) { public function hasMember(OTS_Player $player) {
global $db;
if(!$player || !$player->isLoaded()) { if(!$player || !$player->isLoaded()) {
return false; return false;
} }

View File

@ -854,9 +854,8 @@ class OTS_Player extends OTS_Row_DAO
} }
if(isset($this->data['promotion'])) { if(isset($this->data['promotion'])) {
global $config;
if((int)$this->data['promotion'] > 0) 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']; return $this->data['vocation'];

View File

@ -12,7 +12,10 @@ use MyAAC\CsrfToken;
defined('MYAAC') or die('Direct access not allowed!'); 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()])) { if($hooks->trigger(HOOK_LOGOUT, ['account_id' => $account_logged->getId()])) {
unsetSession('account'); unsetSession('account');
unsetSession('password'); unsetSession('password');
@ -20,7 +23,11 @@ if(isset($account_logged) && $account_logged->isLoaded()) {
CsrfToken::generate(); CsrfToken::generate();
global $logged, $account_logged;
$logged = false; $logged = false;
unset($account_logged); $account_logged = new OTS_Account();
app()->setLoggedIn($logged);
app()->setAccountLogged($account_logged);
} }
} }

View File

@ -4,7 +4,7 @@ use MyAAC\Settings;
function updateHighscoresIdsHidden(): void function updateHighscoresIdsHidden(): void
{ {
global $db; $db = app()->get('database');
if (!$db->hasTable('players')) { if (!$db->hasTable('players')) {
return; return;

View File

@ -10,7 +10,7 @@
*/ */
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
if(!$logged) if(!logged())
{ {
$title = 'Login'; $title = 'Login';

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change E-Mail'; $title = 'Change E-Mail';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Info'; $title = 'Change Info';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Password'; $title = 'Change Password';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Comment'; $title = 'Change Comment';
require PAGES . 'account/base.php'; require PAGES . 'account/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Name'; $title = 'Change Name';
require PAGES . 'account/base.php'; require PAGES . 'account/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Sex'; $title = 'Change Sex';
require PAGES . 'account/base.php'; require PAGES . 'account/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Create Character'; $title = 'Create Character';
require PAGES . 'account/base.php'; require PAGES . 'account/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Delete Character'; $title = 'Delete Character';
require PAGES . 'account/base.php'; require PAGES . 'account/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -17,8 +17,7 @@ $title = 'Create Account';
if (setting('core.account_country')) if (setting('core.account_country'))
require SYSTEM . 'countries.conf.php'; require SYSTEM . 'countries.conf.php';
if($logged) if(logged()) {
{
echo 'Please logout before attempting to create a new account.'; echo 'Please logout before attempting to create a new account.';
return; return;
} }

View File

@ -29,6 +29,7 @@ if(!empty($login_account) && !empty($login_password))
$limiter->enabled = setting('core.account_login_ipban_protection'); $limiter->enabled = setting('core.account_login_ipban_protection');
$limiter->load(); $limiter->load();
global $logged, $account_logged, $logged_flags;
$account_logged = new OTS_Account(); $account_logged = new OTS_Account();
if (config('account_login_by_email')) { if (config('account_login_by_email')) {
$account_logged->findByEMail($login_account); $account_logged->findByEMail($login_account);
@ -69,6 +70,9 @@ if(!empty($login_account) && !empty($login_password))
$account_logged->setCustomField('web_lastlogin', time()); $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)); $hooks->trigger(HOOK_LOGIN, array('account' => $account_logged, 'password' => $login_password, 'remember_me' => $remember_me));
} }

View File

@ -13,7 +13,7 @@ $title = 'Logout';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -14,7 +14,7 @@ $title = 'Account Management';
require __DIR__ . '/login.php'; require __DIR__ . '/login.php';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Register Account'; $title = 'Register Account';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Register Account'; $title = 'Register Account';
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
return; return;
} }

View File

@ -168,10 +168,8 @@ class FAQ
static public function move($id, $i, &$errors) static public function move($id, $i, &$errors)
{ {
global $db;
$row = ModelsFAQ::find($id); $row = ModelsFAQ::find($id);
if($row) if($row) {
{
$ordering = $row->ordering + $i; $ordering = $row->ordering + $i;
$old_record = ModelsFAQ::where('ordering', $ordering)->first(); $old_record = ModelsFAQ::where('ordering', $ordering)->first();
if($old_record) { if($old_record) {
@ -182,8 +180,9 @@ class FAQ
$row->ordering = $ordering; $row->ordering = $ordering;
$row->save(); $row->save();
} }
else else {
$errors[] = 'FAQ with id ' . $id . ' does not exists.'; $errors[] = 'FAQ with id ' . $id . ' does not exists.';
}
return !count($errors); return !count($errors);
} }

View File

@ -18,7 +18,7 @@ if ($ret === false) {
return; return;
} }
if(!$logged) { if(!logged()) {
echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />'; echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />';
return; return;
} }

View File

@ -18,7 +18,7 @@ if ($ret === false) {
return; return;
} }
if(!$logged) { if(!logged()) {
echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />'; echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />';
return; return;
} }

View File

@ -18,7 +18,7 @@ if ($ret === false) {
return; return;
} }
if(!$logged) { if(!logged()) {
$extra_url = ''; $extra_url = '';
if(isset($_GET['thread_id'])) { if(isset($_GET['thread_id'])) {
$extra_url = '?action=new_post&thread_id=' . $_GET['thread_id']; $extra_url = '?action=new_post&thread_id=' . $_GET['thread_id'];

View File

@ -18,7 +18,7 @@ if ($ret === false) {
return; return;
} }
if(!$logged) { if(!logged()) {
$extra_url = ''; $extra_url = '';
if(isset($_GET['section_id'])) { if(isset($_GET['section_id'])) {
$extra_url = '?action=new_thread&section_id=' . $_GET['section_id']; $extra_url = '?action=new_thread&section_id=' . $_GET['section_id'];

View File

@ -18,7 +18,7 @@ if ($ret === false) {
return; return;
} }
if(!$logged) { if(!logged()) {
echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />'; echo 'You are not logged in. <a href="' . getLink('account/manage') . '?redirect=' . urlencode(getLink('forum')) . '">Log in</a> to post on the forum.<br /><br />';
return; return;
} }

View File

@ -44,7 +44,7 @@ for($i = 0; $i < $threads_count['threads_count'] / setting('core.forum_threads_p
echo '<a href="' . getLink('forum') . '">Boards</a> >> <b>'.$sections[$section_id]['name'].'</b>'; echo '<a href="' . getLink('forum') . '">Boards</a> >> <b>'.$sections[$section_id]['name'].'</b>';
if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { if(logged() && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
echo '<br /><br /> echo '<br /><br />
<a href="' . getLink('forum') . '?action=new_thread&section_id='.$section_id.'"><img src="images/forum/topic.gif" border="0" /></a>'; <a href="' . getLink('forum') . '?action=new_thread&section_id='.$section_id.'"><img src="images/forum/topic.gif" border="0" /></a>';
} }
@ -94,7 +94,7 @@ if(isset($last_threads[0])) {
} }
echo '</table>'; echo '</table>';
if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { if(logged() && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
echo '<br /><a href="' . getLink('forum') . '?action=new_thread&section_id=' . $section_id . '"><img src="images/forum/topic.gif" border="0" /></a>'; echo '<br /><a href="' . getLink('forum') . '?action=new_thread&section_id=' . $section_id . '"><img src="images/forum/topic.gif" border="0" /></a>';
} }
} }

View File

@ -132,7 +132,7 @@ class Gallery
{ {
static public function add($comment, $image, $author, &$errors) static public function add($comment, $image, $author, &$errors)
{ {
global $db; $db = app()->get('database');
if(isset($comment[0]) && isset($image[0]) && isset($author[0])) if(isset($comment[0]) && isset($image[0]) && isset($author[0]))
{ {
$query = $query =
@ -225,7 +225,7 @@ class Gallery
static public function move($id, $i, &$errors) static public function move($id, $i, &$errors)
{ {
global $db; $db = app()->get('database');
$query = self::get($id); $query = self::get($id);
if($query !== false) if($query !== false)
{ {

View File

@ -15,7 +15,7 @@ require __DIR__ . '/base.php';
//set rights in guild //set rights in guild
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null;
$name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null;
if(!$logged) { if(!logged()) {
$errors[] = 'You are not logged in. You can\'t accept invitations.'; $errors[] = 'You are not logged in. You can\'t accept invitations.';
} }

View File

@ -22,7 +22,7 @@ if(empty($errors)) {
if(!Validator::rankName($rank_name)) { if(!Validator::rankName($rank_name)) {
$errors[] = 'Invalid rank name format.'; $errors[] = 'Invalid rank name format.';
} }
if(!$logged) { if(!logged()) {
$errors[] = 'You are not logged.'; $errors[] = 'You are not logged.';
} }
$guild = new OTS_Guild(); $guild = new OTS_Guild();

View File

@ -26,7 +26,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -27,7 +27,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$guild_leader = false; $guild_leader = false;
$account_players = $account_logged->getPlayers(); $account_players = $account_logged->getPlayers();

View File

@ -29,7 +29,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
$errors[] = "You are not logged in. You can't change nick."; $errors[] = "You are not logged in. You can't change nick.";
$twig->display('error_box.html.twig', array('errors' => $errors)); $twig->display('error_box.html.twig', array('errors' => $errors));
$twig->display('guilds.back_button.html.twig'); $twig->display('guilds.back_button.html.twig');

View File

@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) { if(!logged()) {
$errors[] = "You are not logged in. You can't change rank."; $errors[] = "You are not logged in. You can't change rank.";
} }
else { else {

View File

@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) if(!logged())
{ {
echo "You are not logged in."; echo "You are not logged in.";
$twig->display('guilds.back_button.html.twig'); $twig->display('guilds.back_button.html.twig');

View File

@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
require __DIR__ . '/base.php'; require __DIR__ . '/base.php';
if(!$logged) if(!logged())
{ {
echo "You are not logged in."; echo "You are not logged in.";
$twig->display('guilds.back_button.html.twig'); $twig->display('guilds.back_button.html.twig');

View File

@ -17,7 +17,7 @@ require __DIR__ . '/base.php';
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL;
$name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL;
$todo = isset($_REQUEST['todo']) ? $_REQUEST['todo'] : NULL; $todo = isset($_REQUEST['todo']) ? $_REQUEST['todo'] : NULL;
if(!$logged) { if(!logged()) {
$guild_errors[] = 'You are not logged in. You can\'t create guild.'; $guild_errors[] = 'You are not logged in. You can\'t create guild.';
} }

View File

@ -26,7 +26,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
if(admin()) { if(admin()) {
$saved = false; $saved = false;
if(isset($_POST['todo']) && $_POST['todo'] == 'save') { if(isset($_POST['todo']) && $_POST['todo'] == 'save') {

View File

@ -26,7 +26,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -15,7 +15,7 @@ require __DIR__ . '/base.php';
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null;
$name = stripslashes($_REQUEST['name']); $name = stripslashes($_REQUEST['name']);
if(!$logged) if(!logged())
$errors[] = 'You are not logged in. You can\'t delete invitations.'; $errors[] = 'You are not logged in. You can\'t delete invitations.';
if(!Validator::guildName($guild_name)) if(!Validator::guildName($guild_name))

View File

@ -26,7 +26,7 @@ if(empty($guild_errors)) {
} }
} }
if(empty($guild_errors)) { if(empty($guild_errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -15,7 +15,7 @@ require __DIR__ . '/base.php';
//set rights in guild //set rights in guild
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL;
$name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL;
if(!$logged) { if(!logged()) {
$errors[] = "You are not logged in. You can't invite players."; $errors[] = "You are not logged in. You can't invite players.";
} }

View File

@ -16,7 +16,7 @@ require __DIR__ . '/base.php';
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : null;
$name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : null;
if(!$logged) { if(!logged()) {
$errors[] = 'You are not logged in. You can\'t kick characters.'; $errors[] = 'You are not logged in. You can\'t kick characters.';
} }

View File

@ -15,7 +15,7 @@ require __DIR__ . '/base.php';
//set rights in guild //set rights in guild
$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL; $guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL;
$name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL; $name = isset($_REQUEST['name']) ? stripslashes($_REQUEST['name']) : NULL;
if(!$logged) { if(!logged()) {
$errors[] = "You are not logged in. You can't leave guild."; $errors[] = "You are not logged in. You can't leave guild.";
} }

View File

@ -39,6 +39,6 @@ if(count($guilds_list) > 0)
$twig->display('guilds.list.html.twig', array( $twig->display('guilds.list.html.twig', array(
'guilds' => $guilds, 'guilds' => $guilds,
'logged' => isset($logged) ? $logged : false, 'logged' => logged(),
'isAdmin' => admin(), 'isAdmin' => admin(),
)); ));

View File

@ -26,7 +26,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -56,7 +56,7 @@ if(empty($guild_errors)) {
} }
} }
if(empty($guild_errors) && empty($guild_errors2)) { if(empty($guild_errors) && empty($guild_errors2)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$guild_leader = false; $guild_leader = false;
$account_players = $account_logged->getPlayers(); $account_players = $account_logged->getPlayers();

View File

@ -26,7 +26,7 @@ if(empty($errors)) {
} }
if(empty($errors)) { if(empty($errors)) {
if($logged) { if(logged()) {
$guild_leader_char = $guild->getOwner(); $guild_leader_char = $guild->getOwner();
$rank_list = $guild->getGuildRanksList(); $rank_list = $guild->getGuildRanksList();
$rank_list->orderBy('level', POT::ORDER_DESC); $rank_list->orderBy('level', POT::ORDER_DESC);

View File

@ -47,8 +47,7 @@ $level_in_guild = 0;
$players_from_account_in_guild = array(); $players_from_account_in_guild = array();
$players_from_account_ids = array(); $players_from_account_ids = array();
if($logged) if(logged()) {
{
$account_players = $account_logged->getPlayers(); $account_players = $account_logged->getPlayers();
foreach($account_players as $player) foreach($account_players as $player)
{ {
@ -127,7 +126,7 @@ include(SYSTEM . 'libs/pot/InvitesDriver.php');
new InvitesDriver($guild); new InvitesDriver($guild);
$invited_list = $guild->listInvites(); $invited_list = $guild->listInvites();
$show_accept_invite = 0; $show_accept_invite = 0;
if($logged && count($invited_list) > 0) if(logged() && count($invited_list) > 0)
{ {
foreach($invited_list as $invited_player) foreach($invited_list as $invited_player)
{ {

View File

@ -139,7 +139,7 @@ $highscores = [];
$needReCache = true; $needReCache = true;
$cacheKey = 'highscores_' . $skill . '_' . $vocation . '_' . $page . '_' . $configHighscoresPerPage; $cacheKey = 'highscores_' . $skill . '_' . $vocation . '_' . $page . '_' . $configHighscoresPerPage;
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch($cacheKey, $tmp)) { if ($cache->fetch($cacheKey, $tmp)) {

View File

@ -105,7 +105,7 @@ if(isset($_GET['archive']))
header('X-XSS-Protection: 0'); header('X-XSS-Protection: 0');
$title = 'Latest News'; $title = 'Latest News';
$cache = Cache::getInstance(); $cache = app()->get('cache');
$news_cached = false; $news_cached = false;
if($cache->enabled()) if($cache->enabled())

View File

@ -48,7 +48,7 @@ function getColorByPercent($percent)
<tr BGCOLOR="'.$bgcolor.'"> <tr BGCOLOR="'.$bgcolor.'">
<td> <td>
<a href="'; <a href="';
if($logged) if(logged())
echo $link.'?id='.$poll['id']; echo $link.'?id='.$poll['id'];
else else
echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']); echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']);
@ -77,7 +77,7 @@ function getColorByPercent($percent)
<tr BGCOLOR="'.$bgcolor.'"> <tr BGCOLOR="'.$bgcolor.'">
<td> <td>
<a href="'; <a href="';
if($logged) if(logged())
echo $link.'?id='.$poll['id']; echo $link.'?id='.$poll['id'];
else else
echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']); echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']);
@ -98,9 +98,8 @@ function getColorByPercent($percent)
$showed=true; $showed=true;
} }
if(!$logged)
{
echo 'You are not logged in. <a href="?subtopic=accountmanagement&redirect=' . BASE_URL . urlencode('?subtopic=polls') . '">Log in</a> to vote in polls.<br /><br />'; echo 'You are not logged in. <a href="?subtopic=accountmanagement&redirect=' . BASE_URL . urlencode('?subtopic=polls') . '">Log in</a> to vote in polls.<br /><br />';
if(!logged()) {
return; return;
} }

View File

@ -1544,7 +1544,8 @@ Sent by MyAAC,<br/>
'default' => 'premium_points', 'default' => 'premium_points',
'callbacks' => [ 'callbacks' => [
'beforeSave' => function($key, $value, &$errorMessage) { 'beforeSave' => function($key, $value, &$errorMessage) {
global $db; $db = app()->get('database');
if ($value == 'coins' && !$db->hasColumn('accounts', 'coins')) { if ($value == 'coins' && !$db->hasColumn('accounts', 'coins')) {
$errorMessage = "Shop: Donate Column: Cannot set column to coins, because it doesn't exist in database."; $errorMessage = "Shop: Donate Column: Cannot set column to coins, because it doesn't exist in database.";
return false; return false;

View File

@ -16,7 +16,7 @@ use Twig\Loader\FilesystemLoader;
class App class App
{ {
private bool $isLoggedIn = false; private bool $isLoggedIn = false;
private ?\OTS_Account $accountLogged = null; private ?\OTS_Account $accountLogged;
private array $instances = []; private array $instances = [];
public function run(): void public function run(): void
@ -37,9 +37,10 @@ class App
$this->accountLogged = $checkLogin['account']; $this->accountLogged = $checkLogin['account'];
$this->isLoggedIn = $checkLogin['logged']; $this->isLoggedIn = $checkLogin['logged'];
global $logged, $account_logged; global $logged, $account_logged, $logged_flags;
$logged = $this->isLoggedIn; $logged = $this->isLoggedIn;
$account_logged = $this->accountLogged; $account_logged = $this->accountLogged;
$logged_flags = $checkLogin['flags'];
$statusService = new StatusService(); $statusService = new StatusService();
$status = $statusService->checkStatus(); $status = $statusService->checkStatus();

View File

@ -119,7 +119,7 @@ class Changelog
{ {
global $template_name; global $template_name;
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) if ($cache->enabled())
{ {
$tmp = ''; $tmp = '';
@ -134,7 +134,7 @@ class Changelog
static public function clearCache() static public function clearCache()
{ {
global $template_name; global $template_name;
$cache = Cache::getInstance(); $cache = app()->get('cache');
if (!$cache->enabled()) { if (!$cache->enabled()) {
return; return;
} }

View File

@ -54,7 +54,7 @@ class MigrateRunCommand extends Command
private function executeMigration($id, $io): void private function executeMigration($id, $io): void
{ {
global $db; $db = app()->get('database');
$db->revalidateCache(); $db->revalidateCache();

View File

@ -132,7 +132,7 @@ class CreateCharacter
return false; return false;
} }
global $db; $db = app()->get('database');
if($sex == "0") if($sex == "0")
$playerSample->setLookType(136); $playerSample->setLookType(136);
@ -250,7 +250,7 @@ class CreateCharacter
return false; return false;
} }
global $twig; $twig = app()->get('twig');
$twig->display('success.html.twig', array( $twig->display('success.html.twig', array(
'title' => 'Character Created', 'title' => 'Character Created',
'description' => 'The character <b>' . $name . '</b> has been created.<br/> 'description' => 'The character <b>' . $name . '</b> has been created.<br/>

View File

@ -20,25 +20,25 @@ class Data
public function get($where) public function get($where)
{ {
global $db; $db = app()->get('database');
return $db->select($this->table, $where); return $db->select($this->table, $where);
} }
public function add($data) public function add($data)
{ {
global $db; $db = app()->get('database');
return $db->insert($this->table, $data); return $db->insert($this->table, $data);
} }
public function delete($data, $where) public function delete($data, $where)
{ {
global $db; $db = app()->get('database');
return $db->delete($this->table, $data, $where); return $db->delete($this->table, $data, $where);
} }
public function update($data, $where) public function update($data, $where)
{ {
global $db; $db = app()->get('database');
return $db->update($this->table, $data, $where); return $db->update($this->table, $data, $where);
} }
} }

View File

@ -81,12 +81,12 @@ class DataLoader
self::$startTime = microtime(true); self::$startTime = microtime(true);
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$cache->delete('towns'); // will be reloaded after next page load $cache->delete('towns'); // will be reloaded after next page load
} }
global $db; $db = app()->get('database');
if ($db->hasTable('towns') && Town::count() > 0) { if ($db->hasTable('towns') && Town::count() > 0) {
success(self::$locale['step_database_loaded_towns'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_towns'] . self::getLoadedTime());
} }

View File

@ -37,13 +37,15 @@ class Forum
*/ */
public static function canPost($account) public static function canPost($account)
{ {
global $db, $config; if(!$account->isLoaded() || $account->isBanned()) {
if(!$account->isLoaded() || $account->isBanned())
return false; return false;
}
if(self::isModerator()) if(self::isModerator()) {
return true; return true;
}
$db = app()->get('database');
return return
$db->query( $db->query(
@ -58,7 +60,7 @@ class Forum
public static function add_thread($title, $body, $section_id, $player_id, $account_id, &$errors) public static function add_thread($title, $body, $section_id, $player_id, $account_id, &$errors)
{ {
global $db; $db = app()->get('database');
$thread_id = 0; $thread_id = 0;
if($db->insert(FORUM_TABLE_PREFIX . 'forum', array( if($db->insert(FORUM_TABLE_PREFIX . 'forum', array(
'first_post' => 0, '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) 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( $db->insert(FORUM_TABLE_PREFIX . 'forum', array(
'first_post' => $thread_id, 'first_post' => $thread_id,
'section' => $section, 'section' => $section,
@ -99,7 +101,7 @@ class Forum
} }
public static function add_board($name, $description, $access, $guild, &$errors) public static function add_board($name, $description, $access, $guild, &$errors)
{ {
global $db; $db = app()->get('database');
if(isset($name[0]) && isset($description[0])) if(isset($name[0]) && isset($description[0]))
{ {
$query = $db->select(TABLE_PREFIX . 'forum_boards', array('name' => $name)); $query = $db->select(TABLE_PREFIX . 'forum_boards', array('name' => $name));
@ -129,19 +131,21 @@ class Forum
return !count($errors); return !count($errors);
} }
public static function get_board($id) { public static function get_board($id)
global $db; {
$db = app()->get('database');
return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id)); return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id));
} }
public static function update_board($id, $name, $access, $guild, $description) { public static function update_board($id, $name, $access, $guild, $description)
global $db; {
$db = app()->get('database');
$db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild), array('id' => $id)); $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) public static function delete_board($id, &$errors)
{ {
global $db; $db = app()->get('database');
if(isset($id)) if(isset($id))
{ {
if(self::get_board($id) !== false) if(self::get_board($id) !== false)
@ -157,7 +161,7 @@ class Forum
public static function toggleHide_board($id, &$errors) public static function toggleHide_board($id, &$errors)
{ {
global $db; $db = app()->get('database');
if(isset($id)) if(isset($id))
{ {
$query = self::get_board($id); $query = self::get_board($id);
@ -174,7 +178,7 @@ class Forum
public static function move_board($id, $i, &$errors) public static function move_board($id, $i, &$errors)
{ {
global $db; $db = app()->get('database');
$query = self::get_board($id); $query = self::get_board($id);
if($query !== false) if($query !== false)
{ {
@ -295,12 +299,12 @@ class Forum
$hasAccess = true; $hasAccess = true;
$section = $sections[$board_id]; $section = $sections[$board_id];
if($section['guild'] > 0) { if($section['guild'] > 0) {
if(app()->isLoggedIn()) { if(logged()) {
$guild = new \OTS_Guild(); $guild = new \OTS_Guild();
$guild->load($section['guild']); $guild->load($section['guild']);
$status = false; $status = false;
if($guild->isLoaded()) { if($guild->isLoaded()) {
$account_players = app()->getAccountLogged()->getPlayersList(); $account_players = accountLogged()->getPlayersList();
foreach ($account_players as $player) { foreach ($account_players as $player) {
if($guild->hasMember($player)) { if($guild->hasMember($player)) {
$status = true; $status = true;
@ -316,7 +320,7 @@ class Forum
} }
if($section['access'] > 0) { if($section['access'] > 0) {
$logged_access = app()->isLoggedIn() ? app()->getAccountLogged()->getAccess() : 0; $logged_access = logged() ? accountLogged()->getAccess() : 0;
if($logged_access < $section['access']) { if($logged_access < $section['access']) {
$hasAccess = false; $hasAccess = false;
} }

View File

@ -11,7 +11,7 @@ class Guild extends Model {
public function owner() public function owner()
{ {
global $db; $db = app()->get('database');
$column = 'ownerid'; $column = 'ownerid';
if($db->hasColumn('guilds', 'owner_id')) { if($db->hasColumn('guilds', 'owner_id')) {
$column = 'owner_id'; $column = 'owner_id';

View File

@ -40,7 +40,7 @@ class Player extends Model {
public function scopeOrderBySkill($query, $value) public function scopeOrderBySkill($query, $value)
{ {
global $db; $db = app()->get('database');
$query->when($db->hasColumn('players', 'skill_fist'), function ($query) { $query->when($db->hasColumn('players', 'skill_fist'), function ($query) {
}); });
@ -69,8 +69,9 @@ class Player extends Model {
return false; return false;
} }
public function scopeNotDeleted($query) { public function scopeNotDeleted($query)
global $db; {
$db = app()->get('database');
$column = 'deleted'; $column = 'deleted';
if($db->hasColumn('players', 'deletion')) { if($db->hasColumn('players', 'deletion')) {
@ -82,7 +83,7 @@ class Player extends Model {
public function scopeWithOnlineStatus($query) public function scopeWithOnlineStatus($query)
{ {
global $db; $db = app()->get('database');
if ($db->hasColumn('players', 'online')) { if ($db->hasColumn('players', 'online')) {
$query->addSelect('online'); $query->addSelect('online');
} }
@ -99,7 +100,7 @@ class Player extends Model {
public function getOnlineStatusAttribute() public function getOnlineStatusAttribute()
{ {
global $db; $db = app()->get('database');
if ($db->hasColumn('players', 'online')) { if ($db->hasColumn('players', 'online')) {
return $this->online; return $this->online;
} }

View File

@ -182,7 +182,7 @@ class News
{ {
global $template_name; global $template_name;
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) if ($cache->enabled())
{ {
$tmp = ''; $tmp = '';
@ -196,7 +196,7 @@ class News
static public function clearCache() static public function clearCache()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if (!$cache->enabled()) { if (!$cache->enabled()) {
return; return;
} }

View File

@ -13,7 +13,7 @@ class Plugins {
public static function getRoutes() public static function getRoutes()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins_routes', $tmp)) { if ($cache->fetch('plugins_routes', $tmp)) {
@ -146,7 +146,7 @@ class Plugins {
public static function getThemes() public static function getThemes()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins_themes', $tmp)) { if ($cache->fetch('plugins_themes', $tmp)) {
@ -178,7 +178,7 @@ class Plugins {
public static function getCommands() public static function getCommands()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins_commands', $tmp)) { if ($cache->fetch('plugins_commands', $tmp)) {
@ -207,7 +207,7 @@ class Plugins {
public static function getHooks() public static function getHooks()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins_hooks', $tmp)) { if ($cache->fetch('plugins_hooks', $tmp)) {
@ -257,7 +257,7 @@ class Plugins {
public static function getAllPluginsSettings() public static function getAllPluginsSettings()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins_settings', $tmp)) { if ($cache->fetch('plugins_settings', $tmp)) {
@ -287,7 +287,7 @@ class Plugins {
public static function getAllPluginsJson($disabled = false) public static function getAllPluginsJson($disabled = false)
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('plugins', $tmp)) { if ($cache->fetch('plugins', $tmp)) {
@ -357,7 +357,7 @@ class Plugins {
public static function install($file): bool public static function install($file): bool
{ {
global $db; $db = app()->get('database');
if(!\class_exists('\ZipArchive')) { if(!\class_exists('\ZipArchive')) {
throw new \RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.'); throw new \RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.');
@ -660,7 +660,7 @@ class Plugins {
return false; return false;
} }
global $db; $db = app()->get('database');
if (file_exists(BASE . $plugin_json['install'])) { if (file_exists(BASE . $plugin_json['install'])) {
$db->revalidateCache(); $db->revalidateCache();
require BASE . $plugin_json['install']; require BASE . $plugin_json['install'];
@ -770,7 +770,7 @@ class Plugins {
*/ */
public static function installMenus($templateName, $menus, $clearOld = false) public static function installMenus($templateName, $menus, $clearOld = false)
{ {
global $db; $db = app()->get('database');
if ($clearOld) { if ($clearOld) {
Menu::where('template', $templateName)->delete(); Menu::where('template', $templateName)->delete();

View File

@ -42,7 +42,7 @@ class RateLimit
public function increment(string $ip): bool public function increment(string $ip): bool
{ {
global $cache; $cache = app()->get('cache');
if ($this->enabled && $cache->enabled()) { if ($this->enabled && $cache->enabled()) {
if (isset($this->data[$ip]['attempts']) && isset($this->data[$ip]['last'])) { if (isset($this->data[$ip]['attempts']) && isset($this->data[$ip]['last'])) {
$this->data[$ip]['attempts']++; $this->data[$ip]['attempts']++;
@ -75,7 +75,7 @@ class RateLimit
public function save(): void public function save(): void
{ {
global $cache; $cache = app()->get('cache');
if (!$this->enabled || !$cache->enabled()) { if (!$this->enabled || !$cache->enabled()) {
return; return;
} }
@ -86,7 +86,7 @@ class RateLimit
public function load(): void public function load(): void
{ {
global $cache; $cache = app()->get('cache');
if (!$this->enabled) { if (!$this->enabled) {
return; return;
} }

View File

@ -6,8 +6,6 @@ class LoginService
{ {
public function checkLogin(): array public function checkLogin(): array
{ {
global $logged_flags;
$logged = false; $logged = false;
$logged_flags = 0; $logged_flags = 0;
$account_logged = new \OTS_Account(); $account_logged = new \OTS_Account();
@ -23,7 +21,7 @@ class LoginService
} }
else { else {
unsetSession('account'); unsetSession('account');
unset($account_logged); $account_logged = new \OTS_Account();
} }
} }
@ -44,6 +42,7 @@ class LoginService
return [ return [
'logged' => $logged, 'logged' => $logged,
'account' => $account_logged, 'account' => $account_logged,
'flags' => $logged_flags,
]; ];
} }
} }

View File

@ -13,8 +13,8 @@ class RouterService
$db = app()->get('database'); $db = app()->get('database');
$twig = app()->get('twig'); $twig = app()->get('twig');
$logged = app()->isLoggedIn(); $logged = logged();
$account_logged = app()->getAccountLogged(); $account_logged = accountLogged();
if(!isset($content[0])) { if(!isset($content[0])) {
$content = ''; $content = '';
@ -32,7 +32,7 @@ class RouterService
$load_it = false; $load_it = false;
} }
if(!$logged) { if(!logged()) {
ob_start(); ob_start();
require SYSTEM . 'pages/account/manage.php'; require SYSTEM . 'pages/account/manage.php';
$content .= ob_get_contents(); $content .= ob_get_contents();

View File

@ -28,7 +28,7 @@ class Settings implements \ArrayAccess
public function load() public function load()
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$tmp = ''; $tmp = '';
if ($cache->fetch('settings', $tmp)) { if ($cache->fetch('settings', $tmp)) {
@ -72,7 +72,7 @@ class Settings implements \ArrayAccess
} }
} }
global $db; $db = app()->get('database');
try { try {
$db->beginTransaction(); $db->beginTransaction();
@ -630,7 +630,7 @@ class Settings implements \ArrayAccess
public function clearCache(): void public function clearCache(): void
{ {
$cache = Cache::getInstance(); $cache = app()->get('cache');
if ($cache->enabled()) { if ($cache->enabled()) {
$cache->delete('settings'); $cache->delete('settings');
} }

View File

@ -33,7 +33,9 @@ class UsageStatistics {
} }
public static function getStats() { public static function getStats() {
global $config, $db; global $config;
$db = app()->get('database');
$ret = array(); $ret = array();

View File

@ -237,7 +237,9 @@ class Validator
*/ */
public static function newCharacterName($name) public static function newCharacterName($name)
{ {
global $db, $config; global $config;
$db = app()->get('database');
$name_lower = strtolower($name); $name_lower = strtolower($name);

View File

@ -24,7 +24,7 @@ if(isset($config['boxes']))
<script type="text/javascript"> <script type="text/javascript">
var menus = ''; var menus = '';
var loginStatus="<?php echo (app()->isLoggedIn() ? 'true' : 'false'); ?>"; var loginStatus="<?php echo (logged() ? 'true' : 'false'); ?>";
<?php <?php
if(PAGE !== 'news') { if(PAGE !== 'news') {
if(isset($_REQUEST['subtopic'])) { if(isset($_REQUEST['subtopic'])) {
@ -472,8 +472,6 @@ foreach(config('menu_categories') as $id => $cat) {
</body> </body>
</html> </html>
<?php <?php
function logo_monster() function logo_monster() {
{ return str_replace(" ", "", trim(strtolower(config('logo_monster'))));
global $config;
return str_replace(" ", "", trim(strtolower($config['logo_monster'])));
} }