'FRCSESSION',
'use_strict_mode' => true,
'cookie_httponly' => true,
'cookie_samesite' => 'Strict']);
/**
* Add a message to be displayed at the top of the page
*
* @param string $level The level (type) of the message
* @param string $message The message itself
*/
function add_message(string $level, string $message): void {
if (!array_key_exists(Key::USER_MSG, $_SESSION)) $_SESSION[Key::USER_MSG] = array();
$_SESSION[Key::USER_MSG][] = ['level' => $level, 'message' => $message];
}
/**
* Add an error message to be displayed at the top of the page
*
* @param string $message The message to be displayed
*/
function add_error(string $message): void {
add_message('ERROR', $message);
}
/**
* Add an error message to be displayed at the top of the page
*
* @param string $message The message to be displayed
*/
function add_info(string $message): void {
add_message('INFO', $message);
}
/** @var bool $is_htmx True if this request was initiated by htmx, false if not */
$is_htmx = array_key_exists('HTTP_HX_REQUEST', $_SERVER)
&& !array_key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
/**
* Render the title bar for the page
*/
function title_bar(): void {
$version = match (true) {
str_ends_with(FRC_VERSION, '.0.0') => substr(FRC_VERSION, 0, strlen(FRC_VERSION) - 4),
str_ends_with(FRC_VERSION, '.0') => substr(FRC_VERSION, 0, strlen(FRC_VERSION) - 2),
default => FRC_VERSION
}; ?>
format(DATE_TIME_FORMAT);
} catch (Exception) {
return '(invalid date)';
}
}
/**
* Create an anchor tag with both `href` and `hx-get` attributes
*
* @param string $url The URL to which navigation should occur
* @param string $text The text for the link
* @param string $extraAttrs Extra attributes for the anchor tag (must be attribute-encoded)
* @return string The anchor tag with both `href` and `hx-get` attributes
*/
function hx_get(string $url, string $text, string $extraAttrs = ''): string {
$attrs = $extraAttrs != '' ? " $extraAttrs" : '';
return "$text";
}
/**
* Return a 404 Not Found
*/
#[NoReturn]
function not_found(): void {
http_response_code(404);
die('Not Found');
}