From 6e312ad8372d4a6765d15d453a083445417da015 Mon Sep 17 00:00:00 2001 From: live-soft Date: Tue, 13 Jan 2026 16:40:55 +0400 Subject: [PATCH 1/4] Add helpers to encode and decode query string as URL-safe base64 --- helpers/functions.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/helpers/functions.php b/helpers/functions.php index c10cba2..a9e7549 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -18,6 +18,7 @@ use Quantum\Libraries\HttpClient\HttpClient; use Quantum\App\Exceptions\BaseException; use Quantum\Di\Exceptions\DiException; +use Quantum\Http\Request; /** * Gets the url with selected language @@ -117,3 +118,26 @@ function textCleanUp(string $text) { return str_replace(['"', '\'', '-'], '', $text); } + +/** + * Encodes current query string to URL-safe base64. + * + * @return string + */ +function nav_ref_encode(): string +{ + $q = Request::getQuery(); + return $q ? rtrim(strtr(base64_encode($q), '+/', '-_'), '=') : ''; +} + +/** + * Decodes a URL-safe base64 reference back to query string. + * + * @param string|null $ref + * @return string|null + */ +function nav_ref_decode(?string $ref): ?string +{ + if (!$ref) return null; + return base64_decode(strtr($ref, '-_', '+/')) ?: null; +} \ No newline at end of file From 3ef7bfea6ff0e9c9d611611e7f2cb27d9bf84a5b Mon Sep 17 00:00:00 2001 From: live-soft Date: Wed, 14 Jan 2026 19:05:21 +0400 Subject: [PATCH 2/4] code refactoring --- helpers/functions.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/helpers/functions.php b/helpers/functions.php index a9e7549..0a7f2a0 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -121,13 +121,12 @@ function textCleanUp(string $text) /** * Encodes current query string to URL-safe base64. - * + * @param string $query * @return string */ -function nav_ref_encode(): string +function nav_ref_encode(?string $query): string { - $q = Request::getQuery(); - return $q ? rtrim(strtr(base64_encode($q), '+/', '-_'), '=') : ''; + return $query ? rtrim(strtr(base64_encode($query), '+/', '-_'), '=') : ''; } /** From f3a6f722dd4d2b49d5b382c209c33683d24d788f Mon Sep 17 00:00:00 2001 From: live-soft Date: Thu, 15 Jan 2026 11:14:31 +0400 Subject: [PATCH 3/4] code refactoring --- helpers/functions.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/helpers/functions.php b/helpers/functions.php index 0a7f2a0..9611cb5 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -132,11 +132,16 @@ function nav_ref_encode(?string $query): string /** * Decodes a URL-safe base64 reference back to query string. * - * @param string|null $ref - * @return string|null + * @param string $ref + * @return string */ -function nav_ref_decode(?string $ref): ?string +function nav_ref_decode(?string $ref): string { - if (!$ref) return null; - return base64_decode(strtr($ref, '-_', '+/')) ?: null; + if (!$ref) { + return ''; + } + + $decoded = base64_decode(strtr($ref, '-_', '+/'), true); + + return ($decoded === false || $decoded === '') ? '' : $decoded; } \ No newline at end of file From 17c698d3ffe9edec537021c2ee0af87d18968cfc Mon Sep 17 00:00:00 2001 From: live-soft Date: Thu, 15 Jan 2026 11:55:37 +0400 Subject: [PATCH 4/4] code refactoring --- helpers/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helpers/functions.php b/helpers/functions.php index 9611cb5..b820f1f 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -137,11 +137,11 @@ function nav_ref_encode(?string $query): string */ function nav_ref_decode(?string $ref): string { - if (!$ref) { - return ''; + if ($ref === 'my-posts') { + return '/my-posts'; } - $decoded = base64_decode(strtr($ref, '-_', '+/'), true); + $decoded = $ref ? base64_decode(strtr($ref, '-_', '+/'), true) : false; - return ($decoded === false || $decoded === '') ? '' : $decoded; + return '/posts' . ($decoded ? '?' . $decoded : ''); } \ No newline at end of file