mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 01:09:21 +02:00
Avoid globals where possible
$logged => logged() $account_logged => accountLogged()
This commit is contained in:
parent
a71f41193c
commit
13b8fcf454
@ -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';
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ $title = 'Login';
|
||||
csrfProtect();
|
||||
|
||||
require PAGES . 'account/login.php';
|
||||
if ($logged) {
|
||||
if (logged()) {
|
||||
header('Location: ' . (admin() ? ADMIN_URL : BASE_URL));
|
||||
return;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
</head>
|
||||
<body class="sidebar-mini ">
|
||||
<?php $hooks->trigger(HOOK_ADMIN_BODY_START); ?>
|
||||
<?php if ($logged && admin()) { ?>
|
||||
<?php if (logged() && admin()) { ?>
|
||||
<div class="wrapper">
|
||||
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
|
||||
<ul class="navbar-nav">
|
||||
@ -177,7 +177,7 @@
|
||||
<div id="sidebar-overlay"></div>
|
||||
</div>
|
||||
|
||||
<?php } else if (!$logged && !admin()) {
|
||||
<?php } else if (!logged() && !admin()) {
|
||||
echo $content;
|
||||
}
|
||||
?>
|
||||
@ -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()
|
||||
]);
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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 .= '<option ' . ($template_name == $value ? 'SELECTED' : '') . '>' . $value . '</option>';
|
||||
|
||||
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('')
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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'];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use MyAAC\Settings;
|
||||
|
||||
function updateHighscoresIdsHidden(): void
|
||||
{
|
||||
global $db;
|
||||
$db = app()->get('database');
|
||||
|
||||
if (!$db->hasTable('players')) {
|
||||
return;
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
if(!$logged)
|
||||
if(!logged())
|
||||
{
|
||||
$title = 'Login';
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Change Info';
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Change Password';
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ $title = 'Logout';
|
||||
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ $title = 'Account Management';
|
||||
require __DIR__ . '/login.php';
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Register Account';
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Register Account';
|
||||
require __DIR__ . '/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ if ($ret === false) {
|
||||
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 />';
|
||||
return;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ if ($ret === false) {
|
||||
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 />';
|
||||
return;
|
||||
}
|
||||
|
@ -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'];
|
||||
|
@ -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'];
|
||||
|
@ -18,7 +18,7 @@ if ($ret === false) {
|
||||
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 />';
|
||||
return;
|
||||
}
|
||||
|
@ -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>';
|
||||
|
||||
if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
|
||||
if(logged() && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
|
||||
echo '<br /><br />
|
||||
<a href="' . getLink('forum') . '?action=new_thread§ion_id='.$section_id.'"><img src="images/forum/topic.gif" border="0" /></a>';
|
||||
}
|
||||
@ -94,7 +94,7 @@ if(isset($last_threads[0])) {
|
||||
}
|
||||
|
||||
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§ion_id=' . $section_id . '"><img src="images/forum/topic.gif" border="0" /></a>';
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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.';
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
@ -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 {
|
||||
|
@ -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');
|
||||
|
@ -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');
|
||||
|
@ -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.';
|
||||
}
|
||||
|
||||
|
@ -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') {
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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.";
|
||||
}
|
||||
|
||||
|
@ -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.';
|
||||
}
|
||||
|
||||
|
@ -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.";
|
||||
}
|
||||
|
||||
|
@ -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(),
|
||||
));
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)) {
|
||||
|
@ -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())
|
||||
|
@ -48,7 +48,7 @@ function getColorByPercent($percent)
|
||||
<tr BGCOLOR="'.$bgcolor.'">
|
||||
<td>
|
||||
<a href="';
|
||||
if($logged)
|
||||
if(logged())
|
||||
echo $link.'?id='.$poll['id'];
|
||||
else
|
||||
echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']);
|
||||
@ -77,7 +77,7 @@ function getColorByPercent($percent)
|
||||
<tr BGCOLOR="'.$bgcolor.'">
|
||||
<td>
|
||||
<a href="';
|
||||
if($logged)
|
||||
if(logged())
|
||||
echo $link.'?id='.$poll['id'];
|
||||
else
|
||||
echo getLink('account/manage') . '?redirect=' . urlencode($link.'?id='.$poll['id']);
|
||||
@ -98,9 +98,8 @@ function getColorByPercent($percent)
|
||||
$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 />';
|
||||
if(!logged()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1544,7 +1544,8 @@ Sent by MyAAC,<br/>
|
||||
'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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class MigrateRunCommand extends Command
|
||||
|
||||
private function executeMigration($id, $io): void
|
||||
{
|
||||
global $db;
|
||||
$db = app()->get('database');
|
||||
|
||||
$db->revalidateCache();
|
||||
|
||||
|
@ -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 <b>' . $name . '</b> has been created.<br/>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ class UsageStatistics {
|
||||
}
|
||||
|
||||
public static function getStats() {
|
||||
global $config, $db;
|
||||
global $config;
|
||||
|
||||
$db = app()->get('database');
|
||||
|
||||
$ret = array();
|
||||
|
||||
|
@ -237,7 +237,9 @@ class Validator
|
||||
*/
|
||||
public static function newCharacterName($name)
|
||||
{
|
||||
global $db, $config;
|
||||
global $config;
|
||||
|
||||
$db = app()->get('database');
|
||||
|
||||
$name_lower = strtolower($name);
|
||||
|
||||
|
@ -24,7 +24,7 @@ if(isset($config['boxes']))
|
||||
|
||||
<script type="text/javascript">
|
||||
var menus = '';
|
||||
var loginStatus="<?php echo (app()->isLoggedIn() ? 'true' : 'false'); ?>";
|
||||
var loginStatus="<?php echo (logged() ? 'true' : 'false'); ?>";
|
||||
<?php
|
||||
if(PAGE !== 'news') {
|
||||
if(isset($_REQUEST['subtopic'])) {
|
||||
@ -472,8 +472,6 @@ foreach(config('menu_categories') as $id => $cat) {
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function logo_monster()
|
||||
{
|
||||
global $config;
|
||||
return str_replace(" ", "", trim(strtolower($config['logo_monster'])));
|
||||
function logo_monster() {
|
||||
return str_replace(" ", "", trim(strtolower(config('logo_monster'))));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user