From ab9537d0daf110ca313b2c04a01727c7ceea8c17 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 30 Apr 2024 22:26:28 -0400 Subject: [PATCH 1/3] First cut of feed mgt page (#13) - Moved feed page to feed directory - Implement feed deletion - Add hx_get func for htmx-enabled but not dependent links --- src/app-config.php | 2 +- src/lib/Data.php | 20 ------ src/lib/Feed.php | 14 +++++ src/public/assets/style.css | 4 ++ src/public/docs/index.php | 9 +-- src/public/docs/refresh-feeds.php | 2 +- src/public/docs/security-modes.php | 2 +- src/public/docs/the-cli.php | 2 +- src/public/{feed.php => feed/index.php} | 38 ++++++++--- src/public/feeds.php | 51 +++++++++++++++ src/public/index.php | 4 +- src/public/item.php | 2 +- src/start.php | 84 +++++++++++++++---------- 13 files changed, 159 insertions(+), 75 deletions(-) rename src/public/{feed.php => feed/index.php} (53%) create mode 100644 src/public/feeds.php diff --git a/src/app-config.php b/src/app-config.php index 0862dab..bc29c5a 100644 --- a/src/app-config.php +++ b/src/app-config.php @@ -1,7 +1,7 @@ prepare('SELECT * FROM feed WHERE id = :id AND user_id = :user'); - $query->bindValue(':id', $feedId); - $query->bindValue(':user', $_SESSION[Key::USER_ID]); - $result = $query->execute(); - return $result ? $result->fetchArray(SQLITE3_ASSOC) : false; - } finally { - if (is_null($dbConn)) $db->close(); - } - } - /** * Return the last SQLite error message as a result array * diff --git a/src/lib/Feed.php b/src/lib/Feed.php index c6e9191..7dd5fca 100644 --- a/src/lib/Feed.php +++ b/src/lib/Feed.php @@ -514,4 +514,18 @@ class Feed { return sizeof($errors) == 0 ? ['ok' => true] : ['error' => implode("\n", $errors)]; } + + /** + * Retrieve a feed by its ID for the current user + * + * @param int $feedId The ID of the feed to retrieve + * @param SQLite3 $db A database connection to use to retrieve the feed + * @return array|bool The data for the feed if found, false if not found + */ + public static function retrieveById(int $feedId, SQLite3 $db): array|bool { + $query = $db->prepare('SELECT * FROM feed WHERE id = :id AND user_id = :user'); + $query->bindValue(':id', $feedId); + $query->bindValue(':user', $_SESSION[Key::USER_ID]); + return ($result = $query->execute()) ? $result->fetchArray(SQLITE3_ASSOC) : false; + } } diff --git a/src/public/assets/style.css b/src/public/assets/style.css index 14747cc..cd7a30b 100644 --- a/src/public/assets/style.css +++ b/src/public/assets/style.css @@ -101,6 +101,10 @@ article { width: unset; } } + + .meta { + font-size: .9rem; + } } article.docs { line-height: 1.4rem; diff --git a/src/public/docs/index.php b/src/public/docs/index.php index 37278bf..1811c50 100644 --- a/src/public/docs/index.php +++ b/src/public/docs/index.php @@ -7,10 +7,11 @@ Security::verifyUser($db, redirectIfAnonymous: false); page_head('Documentation'); ?>

Documentation Home

-

About the CLI provides orientation on Feed Reader Central’s command line interface -

Configuring Security Modes describes the three security modes and how to manage each - of them -

Refresh Feeds has instructions on how feeds can be refreshed on a schedule +

provides orientation on Feed Reader Central’s command line + interface +

describes the three security modes and how to + manage each of them +

has instructions on how feeds can be refreshed on a schedule

close(); diff --git a/src/public/docs/refresh-feeds.php b/src/public/docs/refresh-feeds.php index 1407e83..f5812af 100644 --- a/src/public/docs/refresh-feeds.php +++ b/src/public/docs/refresh-feeds.php @@ -6,7 +6,7 @@ Security::verifyUser($db, redirectIfAnonymous: false); page_head('Refresh Feeds | Documentation'); ?>

Refresh Feeds

-

Manual Feed Refresh

Next to the “Your Unread Items” heading on the main page, there is a link labeled “Refresh All diff --git a/src/public/docs/security-modes.php b/src/public/docs/security-modes.php index 32ddf49..222294c 100644 --- a/src/public/docs/security-modes.php +++ b/src/public/docs/security-modes.php @@ -6,7 +6,7 @@ Security::verifyUser($db, redirectIfAnonymous: false); page_head('Security Modes | Documentation'); ?>

Configuring Security Modes

-

Security Modes

Single-User mode assumes that every connection to the application is the same person. It is diff --git a/src/public/docs/the-cli.php b/src/public/docs/the-cli.php index 80aec65..d833e51 100644 --- a/src/public/docs/the-cli.php +++ b/src/public/docs/the-cli.php @@ -6,7 +6,7 @@ Security::verifyUser($db, redirectIfAnonymous: false); page_head('About the CLI | Documentation'); ?>

About the CLI

-

Feed Reader Central’s low-friction design includes having many administrative tasks run in a terminal or shell. “CLI” is short for “Command Line Interface”, and refers to commands that are run diff --git a/src/public/feed.php b/src/public/feed/index.php similarity index 53% rename from src/public/feed.php rename to src/public/feed/index.php index 80f985a..f7808da 100644 --- a/src/public/feed.php +++ b/src/public/feed/index.php @@ -1,32 +1,50 @@ prepare('DELETE FROM item WHERE feed_id = :feed'); + $itemDelete->bindValue(':feed', $feed['id']); + if (!$itemDelete->execute()) add_error(Data::error($db)['error']); + $feedDelete = $db->prepare('DELETE FROM feed WHERE id = :feed'); + $feedDelete->bindValue(':feed', $feed['id']); + if ($feedDelete->execute()) { + add_info('Feed “' . htmlentities($feed['title']) . '” deleted successfully'); + } else { + add_error(Data::error($db)['error']); + } + frc_redirect('/feeds'); +} + if ($_SERVER['REQUEST_METHOD'] == 'POST') { $isNew = $_POST['id'] == 'new'; if ($isNew) { $result = Feed::add($_POST['url'], $db); } else { - $toEdit = Data::retrieveFeedById($_POST['id'], $db); + $toEdit = Feed::retrieveById($_POST['id'], $db); $result = $toEdit ? Feed::update($toEdit, $_POST['url'], $db) : ['error' => "Feed {$_POST['id']} not found"]; } if (array_key_exists('ok', $result)) { add_info('Feed saved successfully'); - $feedId = $isNew ? $result['ok'] : $_POST['id']; - } else { - add_error($result['error']); - $feedId = 'error'; + frc_redirect('/feeds'); } + add_error($result['error']); + $feedId = 'error'; } if ($feedId == 'new') { @@ -37,7 +55,7 @@ if ($feedId == 'new') { if ($feedId == 'error') { $feed = ['id' => $_POST['id'] ?? '', 'url' => $_POST['url'] ?? '']; } else { - $feed = Data::retrieveFeedById((int) $feedId, $db); + $feed = Feed::retrieveById((int) $feedId, $db); if (!$feed) { http_response_code(404); die(); @@ -48,7 +66,7 @@ if ($feedId == 'new') { page_head($title); ?>

-
+ >