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
This commit is contained in:
2024-04-11 22:01:36 -04:00
parent 7d294b9be8
commit da9a569e4a
7 changed files with 275 additions and 144 deletions

View File

@@ -19,8 +19,26 @@ Data::ensureDb();
* @param string $message The message itself
*/
function add_message(string $level, string $message): void {
if (!array_key_exists('USER_MSG', $_REQUEST)) $_REQUEST['USER_MSG'] = array();
$_REQUEST['USER_MSG'][] = ['level' => $level, 'message' => $message];
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);
}
/**
@@ -38,15 +56,15 @@ function page_head(string $title): void {
<header>
<a class=title href="/">Feed Reader Central</a>
<div><?php
if (array_key_exists('FRC_USER_ID', $_REQUEST)) {
if (array_key_exists(Key::USER_ID, $_REQUEST)) {
echo '<a href=/feed?id=new>Add Feed</a>';
if ($_REQUEST['FRC_USER_EMAIL'] != 'solouser@example.com') echo " | {$_REQUEST['FRC_USER_EMAIL']}";
if ($_REQUEST[Key::USER_EMAIL] != 'solouser@example.com') echo " | {$_REQUEST[Key::USER_EMAIL]}";
} ?>
</div>
</header>
<main hx-target=this><?php
if (array_key_exists('USER_MSG', $_REQUEST)) {
foreach ($_REQUEST['USER_MSG'] as $msg) { ?>
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']?>