From 0e386d2c7fd46832fa67ce574637d30a15e88641 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 26 Nov 2019 20:12:43 +0100 Subject: Removed global $page --- includes/pages/admin_questions.php | 4 +--- includes/pages/user_news.php | 4 +--- includes/sys_menu.php | 16 ++++++++++++---- src/Middleware/LegacyMiddleware.php | 2 -- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index 0e41390f..04868e32 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -18,9 +18,7 @@ function admin_questions_title() */ function admin_new_questions() { - global $page; - - if ($page != 'admin_questions') { + if (current_page() != 'admin_questions') { if (auth()->can('admin_questions')) { $new_messages = count(DB::select('SELECT `QID` FROM `Questions` WHERE `AID` IS NULL')); diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index 8ce3dffb..4eb8f0ce 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -87,8 +87,6 @@ function news_text(News $news): string */ function display_news(News $news): string { - global $page; - $html = ''; $html .= '
'; $html .= '
'; @@ -109,7 +107,7 @@ function display_news(News $news): string $html .= ' ' . $news->created_at->format('Y-m-d H:i') . ' '; $html .= User_Nick_render($news->user); - if ($page != 'news_comments') { + if (current_page() != 'news_comments') { $html .= ' ' . ' ' . __('Comments') . ' » ' diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 4dabc857..3bb061ce 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -40,13 +40,22 @@ function header_render_hints() return $hints_renderer->render(); } +/** + * Returns the path of the current path with underscores instead of hyphens + * + * @return string + */ +function current_page() +{ + return request()->query->get('p') ?: str_replace('-', '_', request()->path()); +} + /** * @return array */ function make_user_submenu() { - global $page; - + $page = current_page(); $user_submenu = make_language_select(); if (auth()->can('user_settings') || auth()->can('logout')) { @@ -79,8 +88,7 @@ function make_user_submenu() */ function make_navigation() { - global $page; - + $page = current_page(); $menu = []; $pages = [ 'news' => __('News'), diff --git a/src/Middleware/LegacyMiddleware.php b/src/Middleware/LegacyMiddleware.php index f652e766..8a0ff002 100644 --- a/src/Middleware/LegacyMiddleware.php +++ b/src/Middleware/LegacyMiddleware.php @@ -58,8 +58,6 @@ class LegacyMiddleware implements MiddlewareInterface ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { - global $page; - /** @var Request $appRequest */ $appRequest = $this->container->get('request'); $page = $appRequest->query->get('p'); -- cgit v1.2.3-54-g00ecf