2024-04-04 23:15:58 +00:00
|
|
|
<?php
|
2024-04-06 02:14:24 +00:00
|
|
|
spl_autoload_register(function ($class) {
|
|
|
|
$file = implode(DIRECTORY_SEPARATOR, [ __DIR__, 'lib', "$class.php" ]);
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require $file;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2024-04-04 23:15:58 +00:00
|
|
|
|
2024-04-06 02:14:24 +00:00
|
|
|
require 'user-config.php';
|
2024-04-04 23:15:58 +00:00
|
|
|
|
2024-04-06 02:14:24 +00:00
|
|
|
Data::ensureDb();
|
2024-04-05 00:49:25 +00:00
|
|
|
|
2024-04-11 23:07:39 +00:00
|
|
|
/**
|
|
|
|
* 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 {
|
2024-04-12 02:01:36 +00:00
|
|
|
if (!array_key_exists(Key::USER_MSG, $_REQUEST)) $_REQUEST[Key::USER_MSG] = array();
|
|
|
|
$_REQUEST[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);
|
2024-04-11 23:07:39 +00:00
|
|
|
}
|
|
|
|
|
2024-04-05 00:49:25 +00:00
|
|
|
/**
|
|
|
|
* Render the page title
|
|
|
|
* @param string $title The title of the page being displayed
|
|
|
|
*/
|
|
|
|
function page_head(string $title): void {
|
|
|
|
?><!DOCTYPE html>
|
2024-04-08 11:31:32 +00:00
|
|
|
<html lang=en>
|
2024-04-05 00:49:25 +00:00
|
|
|
<head>
|
|
|
|
<title><?=$title?> | Feed Reader Central</title>
|
2024-04-06 15:02:48 +00:00
|
|
|
<link href=/assets/style.css rel=stylesheet>
|
2024-04-05 00:49:25 +00:00
|
|
|
</head>
|
2024-04-06 15:02:48 +00:00
|
|
|
<body>
|
|
|
|
<header>
|
2024-04-08 11:31:32 +00:00
|
|
|
<a class=title href="/">Feed Reader Central</a>
|
2024-04-06 15:02:48 +00:00
|
|
|
<div><?php
|
2024-04-12 02:01:36 +00:00
|
|
|
if (array_key_exists(Key::USER_ID, $_REQUEST)) {
|
2024-04-06 15:02:48 +00:00
|
|
|
echo '<a href=/feed?id=new>Add Feed</a>';
|
2024-04-12 02:01:36 +00:00
|
|
|
if ($_REQUEST[Key::USER_EMAIL] != 'solouser@example.com') echo " | {$_REQUEST[Key::USER_EMAIL]}";
|
2024-04-06 15:02:48 +00:00
|
|
|
} ?>
|
|
|
|
</div>
|
|
|
|
</header>
|
2024-04-11 23:07:39 +00:00
|
|
|
<main hx-target=this><?php
|
2024-04-12 02:01:36 +00:00
|
|
|
if (array_key_exists(Key::USER_MSG, $_REQUEST)) {
|
|
|
|
foreach ($_REQUEST[Key::USER_MSG] as $msg) { ?>
|
2024-04-11 23:07:39 +00:00
|
|
|
<div>
|
|
|
|
<?=$msg['level'] == 'INFO' ? '' : "<strong>{$msg['level']}</strong><br>"?>
|
|
|
|
<?=$msg['message']?>
|
|
|
|
</div><?php
|
|
|
|
}
|
|
|
|
}
|
2024-04-05 00:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the end of the page
|
|
|
|
*/
|
|
|
|
function page_foot(): void {
|
2024-04-06 15:02:48 +00:00
|
|
|
?></main></body></html><?php
|
2024-04-05 00:49:25 +00:00
|
|
|
}
|