feed-reader-central/src/start.php
Daniel J. Summers da9a569e4a Add editing of feed URL (#4)
- Move feed-specific database calls to Feed class
- Detect when feed items have been updated
- Add const keys for $_REQUEST values
2024-04-11 22:01:36 -04:00

82 lines
2.1 KiB
PHP

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