mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-18 03:33:26 +02:00
Move admin code to App\Admin class
Removed old myaac_admin_menu code Add logged() + accountLogged() functions
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user