From 6cc1efff1523ccbdcdb3cc8e128feec918702bf1 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 24 Sep 2024 09:39:30 +0300 Subject: [PATCH] Adds platforms switcher in menu --- app/helpers/profile.php | 28 ++++++++++++++++++++++++++++ app/templates/page-menu.php | 6 ++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/helpers/profile.php b/app/helpers/profile.php index ad4f53c..cc1e780 100644 --- a/app/helpers/profile.php +++ b/app/helpers/profile.php @@ -17,4 +17,32 @@ function getUTCOffset($timezone) { } +// switch platforms +function switchPlatform($platform_id) { + // get the current URL and parse it + $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; + $current_url = "$scheme://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + $url_components = parse_url($current_url); + + // parse query parameters if they exist + parse_str($url_components['query'] ?? '', $query_params); + + // check if the 'platform' parameter is set + if (isset($query_params['platform'])) { + // change the platform to the new platform_id + $query_params['platform'] = $platform_id; + + // rebuild the query and the URL + $new_query_string = http_build_query($query_params); + $new_url = $scheme . '://' . $url_components['host'] . $url_components['path'] . '?' . $new_query_string; + + // return the new URL with the new platform_id + return $new_url; + + // there is no 'platform', we redirect to front page of the new platform_id + } else { + return $current_url; + } +} + ?> diff --git a/app/templates/page-menu.php b/app/templates/page-menu.php index 1918aa3..9470040 100644 --- a/app/templates/page-menu.php +++ b/app/templates/page-menu.php @@ -12,9 +12,11 @@ - +
  • - +