diff --git a/helpers/functions.php b/helpers/functions.php index c10cba2..b820f1f 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,30 @@ function textCleanUp(string $text) { return str_replace(['"', '\'', '-'], '', $text); } + +/** + * Encodes current query string to URL-safe base64. + * @param string $query + * @return string + */ +function nav_ref_encode(?string $query): string +{ + return $query ? rtrim(strtr(base64_encode($query), '+/', '-_'), '=') : ''; +} + +/** + * Decodes a URL-safe base64 reference back to query string. + * + * @param string $ref + * @return string + */ +function nav_ref_decode(?string $ref): string +{ + if ($ref === 'my-posts') { + return '/my-posts'; + } + + $decoded = $ref ? base64_decode(strtr($ref, '-_', '+/'), true) : false; + + return '/posts' . ($decoded ? '?' . $decoded : ''); +} \ No newline at end of file