From 7008c9f4d8ac521f999f70ea94de6fa33a77949c Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 5 Dec 2021 10:33:31 +0100 Subject: [PATCH] Optimisations & fixes. --- admin/index.php | 10 ++++++---- system/pages/admin/changelog.php | 15 +++++++-------- system/pages/admin/login.php | 8 ++++---- system/pages/changelog.php | 5 ++--- system/router.php | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/admin/index.php b/admin/index.php index c47ac1d6..573f634e 100644 --- a/admin/index.php +++ b/admin/index.php @@ -2,8 +2,8 @@ // few things we'll need require '../common.php'; -define('ADMIN_PANEL', true); -define('MYAAC_ADMIN', true); +const ADMIN_PANEL = true; +const MYAAC_ADMIN = true; if(file_exists(BASE . 'config.local.php')) { require_once BASE . 'config.local.php'; @@ -18,7 +18,7 @@ if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['i $content = ''; // validate page -$page = isset($_GET['p']) ? $_GET['p'] : ''; +$page = $_GET['p'] ?? ''; if(empty($page) || preg_match("/[^a-zA-Z0-9_\-]/", $page)) $page = 'dashboard'; @@ -52,6 +52,9 @@ if(!$logged || !admin()) { $page = 'login'; } +// more pages have action, lets define it here +$action = $_REQUEST['action'] ?? ''; + // include our page $file = SYSTEM . 'pages/admin/' . $page . '.php'; if(!@file_exists($file)) { @@ -68,4 +71,3 @@ ob_end_clean(); // template $template_path = 'template/'; require ADMIN . $template_path . 'template.php'; -?> diff --git a/system/pages/admin/changelog.php b/system/pages/admin/changelog.php index a6e7d01c..414a38e1 100644 --- a/system/pages/admin/changelog.php +++ b/system/pages/admin/changelog.php @@ -17,13 +17,13 @@ if (!hasFlag(FLAG_CONTENT_PAGES) && !superAdmin()) { $title = 'Changelog'; $use_datatable = true; -define('CL_LIMIT', 600); // maximum changelog body length +const CL_LIMIT = 600; // maximum changelog body length ?> display('admin.changelog.form.html.twig', array( 'action' => $action, 'cl_link_form' => constant('ADMIN_URL').'?p=changelog&action=' . ($action == 'edit' ? 'edit' : 'add'), - 'cl_id' => isset($id) ? $id : null, + 'cl_id' => $id ?? null, 'body' => isset($body) ? htmlentities($body, ENT_COMPAT, 'UTF-8') : '', - 'create_date' => isset($create_date) ? $create_date : '', - 'player' => isset($player) && $player->isLoaded() ? $player : null, - 'player_id' => isset($player_id) ? $player_id : null, + 'create_date' => $create_date ?? '', + 'player_id' => $player_id ?? null, 'account_players' => $account_players, - 'type' => isset($type) ? $type : 0, - 'where' => isset($where) ? $where : 0, + 'type' => $type ?? 0, + 'where' => $where ?? 0, 'log_type' => $log_type, 'log_where' => $log_where, )); diff --git a/system/pages/admin/login.php b/system/pages/admin/login.php index 2c6d4e9f..03ccfe2b 100644 --- a/system/pages/admin/login.php +++ b/system/pages/admin/login.php @@ -10,8 +10,8 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Login'; -$twig->display('admin.login.html.twig', array( - 'logout' => ($action == 'logout' ? 'You have been logged out!' : ''), +$twig->display('admin.login.html.twig', [ + 'logout' => (ACTION == 'logout' ? 'You have been logged out!' : ''), 'account' => USE_ACCOUNT_NAME ? 'Name' : 'Number', - 'errors' => isset($errors)? $errors : '' -)); + 'errors' => $errors ?? '' +]); diff --git a/system/pages/changelog.php b/system/pages/changelog.php index 541f9088..dddabf8d 100644 --- a/system/pages/changelog.php +++ b/system/pages/changelog.php @@ -10,8 +10,8 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Changelog'; -$_page = isset($_GET['page']) ? $_GET['page'] : 0; -$id = isset($_GET['id']) ? $_GET['id'] : 0; +$_page = $_GET['page'] ?? 0; +$id = $_GET['id'] ?? 0; $limit = 30; $offset = $_page * $limit; $next_page = false; @@ -43,4 +43,3 @@ $twig->display('changelog.html.twig', array( 'next_page' => $next_page, 'canEdit' => $canEdit, )); -?> diff --git a/system/router.php b/system/router.php index 8117cdaf..c2c8e268 100644 --- a/system/router.php +++ b/system/router.php @@ -41,7 +41,7 @@ if($success) { $page = $uri; } else { // old support for pages like /?subtopic=accountmanagement - $page = isset($_REQUEST['p']) ? $_REQUEST['p'] : (isset($_REQUEST['subtopic']) ? $_REQUEST['subtopic'] : ''); + $page = $_REQUEST['p'] ?? ($_REQUEST['subtopic'] ?? ''); if(!empty($page) && preg_match('/^[A-z0-9\-]+$/', $page)) { if(config('backward_support')) { require SYSTEM . 'compat_pages.php';