WIP on document conversion
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
use FeedReaderCentral\Data;
|
||||
use FeedReaderCentral\Key;
|
||||
use FeedReaderCentral\Security;
|
||||
|
||||
require 'app-config.php';
|
||||
|
||||
@@ -15,7 +18,8 @@ session_start([
|
||||
* @param string $level The level (type) of the message
|
||||
* @param string $message The message itself
|
||||
*/
|
||||
function add_message(string $level, string $message): void {
|
||||
function add_message(string $level, string $message): void
|
||||
{
|
||||
if (!key_exists(Key::USER_MSG, $_SESSION)) $_SESSION[Key::USER_MSG] = array();
|
||||
$_SESSION[Key::USER_MSG][] = ['level' => $level, 'message' => $message];
|
||||
}
|
||||
@@ -25,7 +29,8 @@ function add_message(string $level, string $message): void {
|
||||
*
|
||||
* @param string $message The message to be displayed
|
||||
*/
|
||||
function add_error(string $message): void {
|
||||
function add_error(string $message): void
|
||||
{
|
||||
add_message('ERROR', $message);
|
||||
}
|
||||
|
||||
@@ -34,14 +39,22 @@ function add_error(string $message): void {
|
||||
*
|
||||
* @param string $message The message to be displayed
|
||||
*/
|
||||
function add_info(string $message): void {
|
||||
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 = key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
|
||||
|
||||
function nav_link(string $link, bool $isFirst = false) {
|
||||
/**
|
||||
* Create a navigation link in the top right nav bar
|
||||
*
|
||||
* @param string $link The link to be placed
|
||||
* @param bool $isFirst True if this is the first link being placed, false if not
|
||||
*/
|
||||
function nav_link(string $link, bool $isFirst = false): void
|
||||
{
|
||||
$sep = $isFirst ? '' : ' | ';
|
||||
echo "<span>$sep$link</span>";
|
||||
}
|
||||
@@ -49,8 +62,9 @@ function nav_link(string $link, bool $isFirst = false) {
|
||||
/**
|
||||
* Render the title bar for the page
|
||||
*/
|
||||
function title_bar(): void {
|
||||
$version = display_version();; ?>
|
||||
function title_bar(): void
|
||||
{
|
||||
$version = display_version(); ?>
|
||||
<header hx-target=#main hx-push-url=true>
|
||||
<div><a href=/ class=title>Feed Reader Central</a><span class=version><?=$version?></span></div>
|
||||
<nav><?php
|
||||
@@ -90,9 +104,9 @@ function title_bar(): void {
|
||||
* Render the page title
|
||||
* @param string $title The title of the page being displayed
|
||||
*/
|
||||
function page_head(string $title): void {
|
||||
global $is_htmx;
|
||||
?>
|
||||
function page_head(string $title): void
|
||||
{
|
||||
global $is_htmx; ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang=en>
|
||||
<head>
|
||||
@@ -121,7 +135,8 @@ function page_head(string $title): void {
|
||||
/**
|
||||
* Render the end of the page
|
||||
*/
|
||||
function page_foot(): void {
|
||||
function page_foot(): void
|
||||
{
|
||||
global $is_htmx; ?>
|
||||
</main><?php
|
||||
if (!$is_htmx) echo '<script src=/assets/htmx.min.js></script>'; ?>
|
||||
@@ -135,8 +150,8 @@ function page_foot(): void {
|
||||
*
|
||||
* @param string $value A local URL to which the user should be redirected
|
||||
*/
|
||||
#[NoReturn]
|
||||
function frc_redirect(string $value): void {
|
||||
function frc_redirect(string $value): never
|
||||
{
|
||||
if (str_starts_with($value, 'http')) {
|
||||
http_response_code(400);
|
||||
die();
|
||||
@@ -152,7 +167,8 @@ function frc_redirect(string $value): void {
|
||||
* @param string $value The date/time string
|
||||
* @return string The standard format of a date/time, or '(invalid date)' if the date could not be parsed
|
||||
*/
|
||||
function date_time(string $value): string {
|
||||
function date_time(string $value): string
|
||||
{
|
||||
try {
|
||||
return (new DateTimeImmutable($value))->format(DATE_TIME_FORMAT);
|
||||
} catch (Exception) {
|
||||
@@ -168,7 +184,8 @@ function date_time(string $value): string {
|
||||
* @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 {
|
||||
function hx_get(string $url, string $text, string $extraAttrs = ''): string
|
||||
{
|
||||
$attrs = $extraAttrs != '' ? " $extraAttrs" : '';
|
||||
return "<a href=\"$url\" hx-get=\"$url\"$attrs>$text</a>";
|
||||
}
|
||||
@@ -176,8 +193,8 @@ function hx_get(string $url, string $text, string $extraAttrs = ''): string {
|
||||
/**
|
||||
* Return a 404 Not Found
|
||||
*/
|
||||
#[NoReturn]
|
||||
function not_found(): void {
|
||||
function not_found(): never
|
||||
{
|
||||
http_response_code(404);
|
||||
die('Not Found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user