Alpha 6: Feed-level Pages (#21)
Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
@@ -42,18 +42,38 @@ function add_info(string $message): void {
|
||||
$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
|
||||
}; ?>
|
||||
<header hx-target=#main hx-push-url=true>
|
||||
<div><?=hx_get('/', 'Feed Reader Central', 'class=title')?><span class=version>v<?=$version?></span></div>
|
||||
<div><?php
|
||||
if (array_key_exists(Key::USER_ID, $_SESSION)) { ?>
|
||||
<?=hx_get('/feeds', 'Feeds')?> | <?=hx_get('/docs/', 'Docs')?> |
|
||||
<a href=/user/log-off>Log Off</a><?php
|
||||
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) { ?>
|
||||
| <?=$_SESSION[Key::USER_EMAIL]?><?php
|
||||
}
|
||||
} else { ?>
|
||||
<?=hx_get('/user/log-on', 'Log On')?> | <?=hx_get('/docs/', 'Docs')?><?php
|
||||
} ?>
|
||||
</div>
|
||||
</header>
|
||||
<main id=main hx-target=this hx-push-url=true hx-swap="innerHTML show:window:top"><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the page title
|
||||
* @param string $title The title of the page being displayed
|
||||
*/
|
||||
function page_head(string $title): void {
|
||||
global $is_htmx;
|
||||
$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
|
||||
};
|
||||
//if ($is_htmx) header('HX-Push-Url: true');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang=en>
|
||||
@@ -61,39 +81,23 @@ function page_head(string $title): void {
|
||||
<title><?=$title?> | Feed Reader Central</title><?php
|
||||
if (!$is_htmx) { ?>
|
||||
<meta name=viewport content="width=device-width, initial-scale=1">
|
||||
<meta name=htmx-config content='{"historyCacheSize":0}'>
|
||||
<link href=/assets/style.css rel=stylesheet><?php
|
||||
} ?>
|
||||
</head>
|
||||
<body><?php
|
||||
if (!$is_htmx) { ?>
|
||||
<header hx-target=#main hx-push-url=true>
|
||||
<div><a class=title href=/ hx-get="/">Feed Reader Central</a><span class=version>v<?=$version?></span></div>
|
||||
<div><?php
|
||||
if (array_key_exists(Key::USER_ID, $_SESSION)) { ?>
|
||||
<a href=/feed?id=new hx-get=/feed?id=new>Add Feed</a> |
|
||||
<a href=/docs/ hx-get=/docs/>Docs</a> |
|
||||
<a href=/user/log-off hx-get=/user/log-off>Log Off</a><?php
|
||||
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) { ?>
|
||||
| <?=$_SESSION[Key::USER_EMAIL]?><?php
|
||||
}
|
||||
} else { ?>
|
||||
<a href=/user/log-on hx-get=/user/log-on>Log On</a> | <a href=/docs/ hx-get=/docs/>Docs</a><?php
|
||||
} ?>
|
||||
</div>
|
||||
</header>
|
||||
<main id=main hx-target=this hx-push-url=true hx-swap="innerHTML show:window:top"><?php
|
||||
if (!$is_htmx) title_bar();
|
||||
if (sizeof($messages = $_SESSION[Key::USER_MSG] ?? []) > 0) { ?>
|
||||
<div class=user_messages><?php
|
||||
array_walk($messages, function ($msg) { ?>
|
||||
<div class=user_message>
|
||||
<?=$msg['level'] == 'INFO' ? '' : "<strong>{$msg['level']}</strong><br>"?>
|
||||
<?=$msg['message']?>
|
||||
</div><?php
|
||||
}); ?>
|
||||
</div><?php
|
||||
$_SESSION[Key::USER_MSG] = [];
|
||||
}
|
||||
if (sizeof($messages = $_SESSION[Key::USER_MSG] ?? []) > 0) { ?>
|
||||
<div class=user_messages><?php
|
||||
array_walk($messages, function ($msg) { ?>
|
||||
<div class=user_message>
|
||||
<?=$msg['level'] == 'INFO' ? '' : "<strong>{$msg['level']}</strong><br>"?>
|
||||
<?=$msg['message']?>
|
||||
</div><?php
|
||||
}); ?>
|
||||
</div><?php
|
||||
$_SESSION[Key::USER_MSG] = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,3 +143,25 @@ function date_time(string $value): string {
|
||||
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 "<a href=\"$url\" hx-get=\"$url\"$attrs>$text</a>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 404 Not Found
|
||||
*/
|
||||
#[NoReturn]
|
||||
function not_found(): void {
|
||||
http_response_code(404);
|
||||
die('Not Found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user