Tweaks to document access

This commit is contained in:
2024-06-03 18:18:51 -04:00
parent 93dd8e880f
commit 1ca7dbdedd
12 changed files with 107 additions and 30 deletions

View File

@@ -15,7 +15,7 @@ include '../start.php';
FeedReaderCentral\Security::verifyUser();
$id = $_GET['id'];
$id = key_exists('id', $_GET) ? (int)$_GET['id'] : -1;
if (!$item = ItemWithFeed::retrieveById($id)) not_found();

View File

@@ -13,7 +13,8 @@ include '../../start.php';
FeedReaderCentral\Security::verifyUser();
if (!($feed = Feed::retrieveById($_GET['id']))) not_found();
$id = key_exists('id', $_GET) ? (int)$_GET['id'] : -1;
if (!($feed = Feed::retrieveById($id))) not_found();
$list = match (true) {
key_exists('unread', $_GET) => ItemList::unreadForFeed($feed->id),

View File

@@ -22,13 +22,13 @@ FeedReaderCentral\Security::verifyUser();
// TODO: adapt query when document list is done
$field = Field::EQ('user_id', $_SESSION[Key::USER_ID], '@user');
$feeds = Custom::list(Query\Find::byFields(Table::FEED, [$field]) . " ORDER BY lower(data->>'title')",
$field->toParameter(), new JsonMapper(Feed::class));
$field->appendParameter([]), new JsonMapper(Feed::class));
page_head('Your Feeds'); ?>
<h1>Your Feeds</h1>
<article>
<p class=action_buttons><?=hx_get('/feed/?id=new', 'Add Feed')?></p><?php
iterator_apply($feeds->items(), function (Feed $feed) {
foreach ($feeds->items() as /** @var Feed $feed */ $feed) {
$item = Table::ITEM;
$counts = Custom::single(<<<SQL
SELECT (SELECT COUNT(*) FROM $item WHERE data->>'feed_id' = @feed) AS total,
@@ -47,6 +47,6 @@ page_head('Your Feeds'); ?>
<a href=/feed/?id=<?=$feed->id?> hx-delete=/feed/?id=<?=$feed->id?>
hx-confirm="Are you sure you want to delete &ldquo;<?=htmlspecialchars($feed->title)?>&rdquo;? This will remove the feed and all its items, including unread and bookmarked.">Delete</a>
</span><?php
}); ?>
} ?>
</article><?php
page_foot();

View File

@@ -16,11 +16,17 @@ include '../start.php';
FeedReaderCentral\Security::verifyUser();
$id = match (true) {
key_exists('id', $_POST) => (int)$_POST['id'],
key_exists('id', $_GET) => (int)$_GET['id'],
default => -1
};
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
// "Keep as New" button sends a POST request to reset the is_read flag before going back to the item list
if (ItemWithFeed::existsById($_POST['id'])) {
Patch::byId(Table::ITEM, $_POST['id'], ['is_read' => 0]);
if (ItemWithFeed::existsById($id)) {
Patch::byId(Table::ITEM, $id, ['is_read' => 0]);
}
frc_redirect($_POST['from']);
} catch (DocumentException $ex) {
@@ -32,8 +38,8 @@ $from = $_GET['from'] ?? '/';
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
try {
if (ItemWithFeed::existsById($_GET['id'])) {
Delete::byId(Table::ITEM, $_GET['id']);
if (ItemWithFeed::existsById($id)) {
Delete::byId(Table::ITEM, $id);
}
} catch (DocumentException $ex) {
add_error("$ex");
@@ -41,10 +47,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
frc_redirect($from);
}
if (!$item = ItemWithFeed::retrieveById($_GET['id'])) not_found();
if (!$item = ItemWithFeed::retrieveById($id)) not_found();
try {
Patch::byId(Table::ITEM, $_GET['id'], ['is_read' => 1]);
Patch::byId(Table::ITEM, $id, ['is_read' => 1]);
} catch (DocumentException $ex) {
add_error("$ex");
}