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