Move admin code to App\Admin class

Removed old myaac_admin_menu code
Add logged() + accountLogged() functions
This commit is contained in:
slawkens
2025-03-16 19:18:25 +01:00
parent 18ac8537c7
commit 8e86b8c015
15 changed files with 138 additions and 125 deletions

View File

@@ -2,7 +2,75 @@
namespace MyAAC\App;
use MyAAC\Services\LoginService;
use MyAAC\Services\StatusService;
class Admin
{
public function run(): void
{
App::preInstallCheck();
$content = '';
// validate page
$page = $_GET['p'] ?? '';
if(empty($page) || preg_match("/[^a-zA-Z0-9_\-\/.]/", $page)) {
$page = 'dashboard';
}
$page = strtolower($page);
define('PAGE', $page);
require_once SYSTEM . 'init.php';
require_once ADMIN . 'includes/debugbar.php';
$loginService = new LoginService();
$loginService->checkLogin();
$statusService = new StatusService();
$status = $statusService->checkStatus();
require ADMIN . '/includes/functions.php';
global $config;
$twig = app()->get('twig');
$twig->addGlobal('config', $config);
$twig->addGlobal('status', $status);
if (ACTION == 'logout') {
require SYSTEM . 'logout.php';
}
// if we're not logged in - show login box
if(!logged() || !admin()) {
$page = 'login';
}
// include our page
$file = ADMIN . '/pages/' . $page . '.php';
if(!@file_exists($file)) {
if (str_contains($page, 'plugins/')) {
$file = BASE . $page;
}
else {
$page = '404';
$file = SYSTEM . 'pages/404.php';
}
}
$hooks = app()->get('hooks');
ob_start();
if($hooks->trigger(HOOK_ADMIN_BEFORE_PAGE)) {
require $file;
}
$content .= ob_get_contents();
ob_end_clean();
// template
$template_path = 'template/';
require ADMIN . '/' . $template_path . 'template.php';
}
}

View File

@@ -21,11 +21,7 @@ class App
public function run(): void
{
$configInstalled = config('installed');
if((!isset($configInstalled) || !$configInstalled) && file_exists(BASE . 'install')) {
header('Location: ' . BASE_URL . 'install/');
exit();
}
self::preInstallCheck();
$template_place_holders = [];
@@ -34,9 +30,8 @@ class App
$loginService = new LoginService();
$checkLogin = $loginService->checkLogin();
$this->accountLogged = $checkLogin['account'];
$this->isLoggedIn = $checkLogin['logged'];
// TODO: Remove those globals, once plugins migrated
global $logged, $account_logged, $logged_flags;
$logged = $this->isLoggedIn;
$account_logged = $this->accountLogged;
@@ -168,4 +163,13 @@ class App
return $this->instances[$what];
}
public static function preInstallCheck(): void
{
$configInstalled = config('installed');
if((!isset($configInstalled) || !$configInstalled) && file_exists(BASE . 'install')) {
header('Location: ' . BASE_URL . 'install/');
exit();
}
}
}

View File

@@ -39,6 +39,9 @@ class LoginService
}
setSession('last_uri', $_SERVER['REQUEST_URI']);
app()->setLoggedIn($logged);
app()->setAccountLogged($account_logged);
return [
'logged' => $logged,
'account' => $account_logged,