From ee86eeef13d15e58e4d9da3e5c5e4b5c8bdf1297 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 13 Apr 2024 13:39:49 -0400 Subject: [PATCH] Add item read page (#7) - Open items links in an external window - Include "Keep as New" button --- src/public/assets/style.css | 38 ++++++++++++++++-- src/public/index.php | 11 ++---- src/public/item.php | 79 +++++++++++++++++++++++++++++++++++++ src/start.php | 30 ++++++++++++++ 4 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 src/public/item.php diff --git a/src/public/assets/style.css b/src/public/assets/style.css index bc42762..86bd961 100644 --- a/src/public/assets/style.css +++ b/src/public/assets/style.css @@ -36,10 +36,26 @@ header { } main { padding: 0 .5rem; + + .item_heading { + margin-bottom: 0; + } + + .item_published { + margin-bottom: 1rem; + line-height: 1.2; + } } article { max-width: 60rem; margin: auto; + + .item_content { + border: solid 1px navy; + border-radius: .5rem; + background-color: white; + padding: .5rem; + } } input[type=url], input[type=text] { width: 50%; @@ -47,11 +63,27 @@ input[type=url], input[type=text] { padding: .25rem; border-radius: .25rem; } -button { +button, +.action_buttons a:link, +.action_buttons a:visited { font-size: 1rem; + font-weight: normal; background-color: navy; color: white; - padding: .25rem 1rem; + padding: .5rem 1rem; border-radius: .25rem; cursor: pointer; -} \ No newline at end of file + border: none; +} +button:hover, +.action_buttons a:hover { + text-decoration: none; + cursor: pointer; + background: linear-gradient(navy, #000032); +} +.action_buttons { + margin: 1rem 0; + display: flex; + flex-flow: row nowrap; + justify-content: space-evenly; +} diff --git a/src/public/index.php b/src/public/index.php index 852558e..799d67d 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -24,14 +24,9 @@ page_head('Welcome'); ?>

Your Unread Items

format(DATE_TIME_FORMAT); - } catch (Exception) { - $asOf = '(invalid date)'; - } ?> -

>
-
+

>
+
fetchArray(SQLITE3_ASSOC); } } else { ?> diff --git a/src/public/item.php b/src/public/item.php new file mode 100644 index 0000000..59a1630 --- /dev/null +++ b/src/public/item.php @@ -0,0 +1,79 @@ +prepare(<<<'SQL' + SELECT COUNT(*) + FROM item INNER JOIN feed ON feed.id = item.feed_id + WHERE item.id = :id AND feed.user_id = :user + SQL); + $isValidQuery->bindValue(':id', $_POST['id']); + $isValidQuery->bindValue(':user', $_REQUEST[Key::USER_ID]); + $isValidResult = $isValidQuery->execute(); + if ($isValidResult && $isValidResult->fetchArray(SQLITE3_NUM)[0] == 1) { + $keepUnread = $db->prepare('UPDATE item SET is_read = 0 WHERE id = :id'); + $keepUnread->bindValue(':id', $_POST['id']); + $keepUnread->execute(); + } + $db->close(); + frc_redirect('/'); +} + +$query = $db->prepare(<<<'SQL' + SELECT item.title AS item_title, item.item_link, item.published_on, item.updated_on, item.content, item.is_encoded, + feed.title AS feed_title + FROM item INNER JOIN feed ON feed.id = item.feed_id + WHERE item.id = :id + AND feed.user_id = :user + SQL); +$query->bindValue(':id', $_GET['id']); +$query->bindValue(':user', $_REQUEST[Key::USER_ID]); +$result = $query->execute(); +$item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false; + +if ($item) { + $markRead = $db->prepare('UPDATE item SET is_read = 1 WHERE id = :id'); + $markRead->bindValue(':id', $_GET['id']); + $markRead->execute(); +} + +$published = date_time($item['published_on']); +$updated = isset($item['updated_on']) ? date_time($item['updated_on']) : null; +$isEncoded = (bool) $item['is_encoded']; + +page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?> +

+
+

+
+ From
+ Published +
+
+
+
+
+ > + Done + +
+
close(); diff --git a/src/start.php b/src/start.php index 2d5ce21..78624af 100644 --- a/src/start.php +++ b/src/start.php @@ -49,6 +49,7 @@ function page_head(string $title): void { ?> + <?=$title?> | Feed Reader Central @@ -79,3 +80,32 @@ function page_head(string $title): void { function page_foot(): void { ?>format(DATE_TIME_FORMAT); + } catch (Exception) { + return '(invalid date)'; + } +}