80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?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();
|