mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 01:09:21 +02:00
[WIP] App rewrite
This commit is contained in:
parent
c336569684
commit
c357f392a0
@ -575,7 +575,7 @@ function template_footer(): string
|
||||
// please respect my work and help spreading the word, thanks!
|
||||
$footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4=');
|
||||
|
||||
global $hooks;
|
||||
$hooks = app()->get('hooks');
|
||||
$footer = $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer);
|
||||
|
||||
return implode('<br/>', $footer);
|
||||
@ -1688,12 +1688,12 @@ function getAccountIdentityColumn(): string
|
||||
}
|
||||
|
||||
function app() {
|
||||
static $_app;
|
||||
if (!isset($_app)) {
|
||||
$_app = new App();
|
||||
static $__app;
|
||||
if (!isset($__app)) {
|
||||
$__app = new App();
|
||||
}
|
||||
|
||||
return $_app;
|
||||
return $__app;
|
||||
}
|
||||
|
||||
// validator functions
|
||||
|
@ -78,6 +78,7 @@ foreach($_REQUEST as $var => $value) {
|
||||
|
||||
// load otserv config file
|
||||
$config_lua_reload = true;
|
||||
global $cache;
|
||||
$cache = app()->get('cache');
|
||||
if($cache->enabled()) {
|
||||
$tmp = null;
|
||||
@ -129,7 +130,7 @@ if(!isset($foundValue)) {
|
||||
$foundValue = config('server_path') . 'data/';
|
||||
}
|
||||
|
||||
$config['data_path'] = $foundValue;
|
||||
config(['data_path', $foundValue]);
|
||||
unset($foundValue);
|
||||
|
||||
// POT
|
||||
|
@ -662,8 +662,9 @@ class OTS_Player extends OTS_Row_DAO
|
||||
//$groups = new DOMDocument();
|
||||
//$groups->load($path);
|
||||
|
||||
global $groups;
|
||||
$groups = app()->get('groups');
|
||||
$tmp = $groups->getGroup($this->data['group_id']);
|
||||
|
||||
if($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use MyAAC\Models\PlayerDeath;
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Characters';
|
||||
|
||||
$groups = new OTS_Groups_List();
|
||||
$groups = app()->get('groups');
|
||||
function generate_search_form($autofocus = false): string
|
||||
{
|
||||
$twig = app()->get('twig');
|
||||
|
@ -16,6 +16,7 @@ use Twig\Loader\FilesystemLoader;
|
||||
class App
|
||||
{
|
||||
private bool $isLoggedIn = false;
|
||||
private ?\OTS_Account $accountLogged = null;
|
||||
private array $instances = [];
|
||||
|
||||
public function run(): void
|
||||
@ -29,11 +30,12 @@ class App
|
||||
$template_place_holders = [];
|
||||
|
||||
require_once SYSTEM . 'init.php';
|
||||
|
||||
require_once SYSTEM . 'template.php';
|
||||
|
||||
$loginService = new LoginService();
|
||||
$this->isLoggedIn = $loginService->checkLogin();
|
||||
$checkLogin = $loginService->checkLogin();
|
||||
$logged = $checkLogin['logged'];
|
||||
$account_logged = $checkLogin['account'];
|
||||
|
||||
$statusService = new StatusService();
|
||||
$status = $statusService->checkStatus();
|
||||
@ -53,8 +55,8 @@ class App
|
||||
$title = $handleRouting['title'];
|
||||
$content = $handleRouting['content'];
|
||||
|
||||
$anonymouseStatisticsService = new AnonymousStatisticsService();
|
||||
$anonymouseStatisticsService->checkReport();
|
||||
$anonymousStatisticsService = new AnonymousStatisticsService();
|
||||
$anonymousStatisticsService->checkReport();
|
||||
|
||||
if(setting('core.views_counter')) {
|
||||
require_once SYSTEM . 'counter.php';
|
||||
@ -71,12 +73,16 @@ class App
|
||||
*/
|
||||
if ($this->isLoggedIn && admin()) {
|
||||
$content .= $twig->render('admin-bar.html.twig', [
|
||||
'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId()
|
||||
'username' => USE_ACCOUNT_NAME ? $this->accountLogged->getName() : $this->accountLogged->getId()
|
||||
]);
|
||||
}
|
||||
|
||||
global $template_path, $template_index;
|
||||
$title_full = (isset($title) ? $title . ' - ' : '') . $config['lua']['serverName'];
|
||||
|
||||
$logged = $this->isLoggedIn;
|
||||
$accountLogged = $this->accountLogged;
|
||||
|
||||
require $template_path . '/' . $template_index;
|
||||
|
||||
echo base64_decode('PCEtLSBQb3dlcmVkIGJ5IE15QUFDIDo6IGh0dHBzOi8vd3d3Lm15LWFhYy5vcmcvIC0tPg==') . PHP_EOL;
|
||||
@ -91,6 +97,14 @@ class App
|
||||
$hooks->trigger(HOOK_FINISH);
|
||||
}
|
||||
|
||||
public function setAccountLogged(\OTS_Account $accountLogged): void {
|
||||
$this->accountLogged = $accountLogged;
|
||||
}
|
||||
|
||||
public function getAccountLogged(): ?\OTS_Account {
|
||||
return $this->accountLogged;
|
||||
}
|
||||
|
||||
public function setLoggedIn($loggedIn): void {
|
||||
$this->isLoggedIn = $loggedIn;
|
||||
}
|
||||
@ -116,6 +130,10 @@ class App
|
||||
$this->instances[$what] = $databaseService->getConnectionHandle();
|
||||
break;
|
||||
|
||||
case 'groups':
|
||||
$this->instances[$what] = new \OTS_Groups_List();
|
||||
break;
|
||||
|
||||
case 'hooks':
|
||||
$this->instances[$what] = new Hooks();
|
||||
break;
|
||||
|
@ -14,10 +14,14 @@ class Hook
|
||||
|
||||
public function execute($params)
|
||||
{
|
||||
global $db, $config, $template_path, $ots, $content, $twig;
|
||||
global $config, $template_path, $ots, $content;
|
||||
|
||||
if(is_callable($this->_file))
|
||||
{
|
||||
$db = app()->get('db');
|
||||
$cache = app()->get('cache');
|
||||
$hooks = app()->get('hooks');
|
||||
$twig = app()->get('twig');
|
||||
|
||||
if(is_callable($this->_file)) {
|
||||
$params['db'] = $db;
|
||||
$params['config'] = $config;
|
||||
$params['template_path'] = $template_path;
|
||||
|
@ -4,9 +4,9 @@ namespace MyAAC\Services;
|
||||
|
||||
class LoginService
|
||||
{
|
||||
public function checkLogin(): bool
|
||||
public function checkLogin(): array
|
||||
{
|
||||
global $logged, $logged_flags, $account_logged;
|
||||
global $logged_flags;
|
||||
|
||||
$logged = false;
|
||||
$logged_flags = 0;
|
||||
@ -41,7 +41,9 @@ class LoginService
|
||||
}
|
||||
setSession('last_uri', $_SERVER['REQUEST_URI']);
|
||||
|
||||
app()->setLoggedIn($logged);
|
||||
return $logged;
|
||||
return [
|
||||
'logged' => $logged,
|
||||
'account' => $account_logged,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ class RouterService
|
||||
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
if(str_contains($uri, 'index.php')) {
|
||||
/** @var TYPE_NAME $uri */
|
||||
$uri = str_replace_first('/index.php', '', $uri);
|
||||
}
|
||||
|
||||
@ -92,6 +91,7 @@ class RouterService
|
||||
/** @var \OTS_Account $account_logged */
|
||||
global $logged_access;
|
||||
$logged_access = 0;
|
||||
$account_logged = app()->getAccountLogged();
|
||||
if($logged && $account_logged && $account_logged->isLoaded()) {
|
||||
$logged_access = $account_logged->getAccess();
|
||||
}
|
||||
@ -309,6 +309,8 @@ class RouterService
|
||||
ob_start();
|
||||
|
||||
global $config;
|
||||
|
||||
$cache = app()->get('cache');
|
||||
$hooks = app()->get('hooks');
|
||||
|
||||
if($hooks->trigger(HOOK_BEFORE_PAGE)) {
|
||||
|
@ -8,9 +8,9 @@ class EnvironmentBridge extends Environment
|
||||
{
|
||||
public function display($name, array $context = []): void
|
||||
{
|
||||
global $hooks;
|
||||
|
||||
$context['viewName'] = $name;
|
||||
|
||||
$hooks = app()->get('hooks');
|
||||
$context = $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context);
|
||||
|
||||
parent::display($name, $context);
|
||||
@ -18,9 +18,9 @@ class EnvironmentBridge extends Environment
|
||||
|
||||
public function render($name, array $context = []): string
|
||||
{
|
||||
global $hooks;
|
||||
|
||||
$context['viewName'] = $name;
|
||||
|
||||
$hooks = app()->get('hooks');
|
||||
$context = $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context);
|
||||
|
||||
return parent::render($name, $context);
|
||||
|
@ -15,6 +15,7 @@ use MyAAC\Plugins;
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
// template
|
||||
global $template_name;
|
||||
$template_name = setting('core.template');
|
||||
if(setting('core.template_allow_change'))
|
||||
{
|
||||
@ -69,6 +70,7 @@ else {
|
||||
}
|
||||
}
|
||||
|
||||
global $config;
|
||||
if(file_exists(BASE . $template_path . '/config.php')) {
|
||||
require BASE . $template_path . '/config.php';
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
|
||||
<td><img src="{{ template_path }}/images/general/blank.gif" width="10" height="1" border="0"></td>
|
||||
<td>
|
||||
{{ hook(constant('HOOK_CHARACTERS_BEFORE_INFORMATIONS')) }}
|
||||
{{ hook(constant('HOOK_CHARACTERS_BEFORE_INFORMATIONS')) }}
|
||||
{% if canEdit %}
|
||||
<a href="{{ constant('ADMIN_URL') }}?p=players&id={{ player.getId() }}" title="Edit in Admin Panel" target="_blank">
|
||||
<img src="images/edit.png"/>Edit
|
||||
|
@ -24,7 +24,7 @@ if(isset($config['boxes']))
|
||||
|
||||
<script type="text/javascript">
|
||||
var menus = '';
|
||||
var loginStatus="<?php echo ($logged ? 'true' : 'false'); ?>";
|
||||
var loginStatus="<?php echo (app()->isLoggedIn() ? 'true' : 'false'); ?>";
|
||||
<?php
|
||||
if(PAGE !== 'news') {
|
||||
if(isset($_REQUEST['subtopic'])) {
|
||||
@ -120,7 +120,7 @@ if(isset($config['boxes']))
|
||||
|
||||
<?php
|
||||
$menuInitStr = '';
|
||||
foreach ($config['menu_categories'] as $item) {
|
||||
foreach (config('menu_categories') as $item) {
|
||||
if ($item['id'] !== 'shops' || setting('core.gifts_system')) {
|
||||
$menuInitStr .= $item['id'] . '=' . ($item['id'] === 'news' ? '1' : '0') . '&';
|
||||
}
|
||||
@ -332,7 +332,6 @@ if(isset($config['boxes']))
|
||||
<div id="LoginBottom" class="Loginstatus" style="background-image:url(<?php echo $template_path; ?>/images/general/box-bottom.gif)" ></div>
|
||||
</div>
|
||||
|
||||
<div-- id='Menu'>
|
||||
<div id='MenuTop' style='background-image:url(<?php echo $template_path; ?>/images/general/box-top.gif);'></div>
|
||||
|
||||
<?php
|
||||
@ -348,7 +347,7 @@ foreach($config['menu_categories'] as $id => $cat) {
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach($config['menu_categories'] as $id => $cat) {
|
||||
foreach(config('menu_categories') as $id => $cat) {
|
||||
if(!isset($menus[$id]) || ($id == MENU_CATEGORY_SHOP && !setting('core.gifts_system'))) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user