parent
ab9537d0da
commit
49c209f7cd
|
@ -22,10 +22,14 @@ header {
|
|||
border-bottom-right-radius: .5rem;
|
||||
color: white;
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
flex-flow: row wrap;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
|
||||
div {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,7 @@ Security::verifyUser($db);
|
|||
$feedId = $_GET['id'] ?? '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
||||
$feed = Feed::retrieveById($feedId, $db);
|
||||
if (!$feed) {
|
||||
http_response_code(404);
|
||||
die();
|
||||
}
|
||||
if (!($feed = Feed::retrieveById($feedId, $db))) not_found();
|
||||
$itemDelete = $db->prepare('DELETE FROM item WHERE feed_id = :feed');
|
||||
$itemDelete->bindValue(':feed', $feed['id']);
|
||||
if (!$itemDelete->execute()) add_error(Data::error($db)['error']);
|
||||
|
@ -54,13 +50,7 @@ if ($feedId == 'new') {
|
|||
$title = 'Edit RSS Feed';
|
||||
if ($feedId == 'error') {
|
||||
$feed = ['id' => $_POST['id'] ?? '', 'url' => $_POST['url'] ?? ''];
|
||||
} else {
|
||||
$feed = Feed::retrieveById((int) $feedId, $db);
|
||||
if (!$feed) {
|
||||
http_response_code(404);
|
||||
die();
|
||||
}
|
||||
}
|
||||
} elseif (!($feed = Feed::retrieveById((int) $feedId, $db))) not_found();
|
||||
}
|
||||
|
||||
page_head($title); ?>
|
||||
|
|
79
src/public/feed/items.php
Normal file
79
src/public/feed/items.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Feed Item List Page
|
||||
*
|
||||
* Lists items in a given feed (all, unread, or bookmarked)
|
||||
*/
|
||||
|
||||
include '../../start.php';
|
||||
|
||||
$db = Data::getConnection();
|
||||
Security::verifyUser($db);
|
||||
|
||||
if (!($feed = Feed::retrieveById($_GET['id'], $db))) not_found();
|
||||
|
||||
/** Display a list of unread items for this feed */
|
||||
const TYPE_UNREAD = 0;
|
||||
|
||||
/** Display a list of bookmarked items for this feed */
|
||||
const TYPE_BOOKMARKED = 1;
|
||||
|
||||
/** Display all items for this feed */
|
||||
const TYPE_ALL = 2;
|
||||
|
||||
$type = match (true) {
|
||||
array_key_exists('unread', $_GET) => TYPE_UNREAD,
|
||||
array_key_exists('bookmarked', $_GET) => TYPE_BOOKMARKED,
|
||||
default => TYPE_ALL
|
||||
};
|
||||
|
||||
$extraSQL = match ($type) {
|
||||
TYPE_UNREAD => ' AND is_read = 0',
|
||||
TYPE_BOOKMARKED => ' AND is_bookmarked = 1',
|
||||
default => ''
|
||||
};
|
||||
$itemQuery = $db->prepare(<<<SQL
|
||||
SELECT id, title, coalesce(updated_on, published_on) AS as_of, is_read, is_bookmarked
|
||||
FROM item
|
||||
WHERE feed_id = :feed$extraSQL
|
||||
ORDER BY date(coalesce(updated_on, published_on)) DESC
|
||||
SQL);
|
||||
$itemQuery->bindValue(':feed', $feed['id']);
|
||||
if (!($itemResult = $itemQuery->execute())) add_error(Data::error($db)['error']);
|
||||
$item = $itemResult ? $itemResult->fetchArray(SQLITE3_ASSOC) : false;
|
||||
|
||||
$queryParam = match ($type) {
|
||||
TYPE_UNREAD => '&unread',
|
||||
TYPE_BOOKMARKED => '&bookmarked',
|
||||
default => ''
|
||||
};
|
||||
$thisURL = urlencode("/feed/items?id={$feed['id']}$queryParam");
|
||||
|
||||
$listType = match ($type) {
|
||||
TYPE_UNREAD => 'Unread',
|
||||
TYPE_BOOKMARKED => 'Bookmarked',
|
||||
default => ''
|
||||
};
|
||||
|
||||
page_head(($type != TYPE_ALL ? "$listType Items | " : '') . strip_tags($feed['title']));
|
||||
if ($type == TYPE_ALL) { ?>
|
||||
<h1><?=htmlentities($feed['title'])?></h1><?php
|
||||
} else { ?>
|
||||
<h1 class=item_heading><?=htmlentities($feed['title'])?></h1>
|
||||
<div class=item_published><?=$listType?> Items</div><?php
|
||||
} ?>
|
||||
<article><?php
|
||||
if ($item) {
|
||||
while ($item) { ?>
|
||||
<p><?=hx_get("/item?id={$item['id']}&from=$thisURL", strip_tags($item['title']))?><br>
|
||||
<small><?=$item['is_read'] == 0 ? '<strong>New</strong> ' : ''?>
|
||||
<em><?=date_time($item['as_of'])?></em></small><?php
|
||||
$item = $itemResult->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
} else { ?>
|
||||
<p><em>There are no <?=strtolower($listType)?> items</em><?php
|
||||
} ?>
|
||||
</article>
|
||||
<?php
|
||||
page_foot();
|
||||
$db->close();
|
|
@ -27,9 +27,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|||
$keepUnread->execute();
|
||||
}
|
||||
$db->close();
|
||||
frc_redirect('/');
|
||||
frc_redirect($_POST['from']);
|
||||
}
|
||||
|
||||
$from = $_GET['from'] ?? '/';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
||||
$deleteQuery = $db->prepare(<<<'SQL'
|
||||
DELETE FROM item
|
||||
|
@ -47,7 +49,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
|||
add_error(Data::error($db)['error']);
|
||||
}
|
||||
$db->close();
|
||||
frc_redirect('/');
|
||||
frc_redirect($from);
|
||||
}
|
||||
|
||||
$query = $db->prepare(<<<'SQL'
|
||||
|
@ -83,7 +85,8 @@ page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?>
|
|||
<div class=item_content><?=str_replace('<a ', '<a target=_blank rel=noopener ', $item['content'])?></div>
|
||||
<form class=action_buttons action=/item method=POST hx-post=/item>
|
||||
<input type=hidden name=id value=<?=$_GET['id']?>>
|
||||
<?=hx_get('/', 'Done')?>
|
||||
<input type=hidden name=from value="<?=$from?>">
|
||||
<?=hx_get($from, 'Done')?>
|
||||
<button type=submit>Keep as New</button>
|
||||
<button type=button hx-delete=/item>Delete</button>
|
||||
</form>
|
||||
|
|
|
@ -81,6 +81,7 @@ function page_head(string $title): void {
|
|||
<title><?=$title?> | Feed Reader Central</title><?php
|
||||
if (!$is_htmx) { ?>
|
||||
<meta name=viewport content="width=device-width, initial-scale=1">
|
||||
<meta name=htmx-config content='{"historyCacheSize":0}'>
|
||||
<link href=/assets/style.css rel=stylesheet><?php
|
||||
} ?>
|
||||
</head>
|
||||
|
@ -155,3 +156,12 @@ function hx_get(string $url, string $text, string $extraAttrs = ''): string {
|
|||
$attrs = $extraAttrs != '' ? " $extraAttrs" : '';
|
||||
return "<a href=\"$url\" hx-get=\"$url\"$attrs>$text</a>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 404 Not Found
|
||||
*/
|
||||
#[NoReturn]
|
||||
function not_found(): void {
|
||||
http_response_code(404);
|
||||
die('Not Found');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user