Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 : '');
}