mirror of
https://github.com/slawkens/myaac.git
synced 2026-03-20 09:33:32 +01:00
[WIP] App rewrite
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user