Documents and Documentation (beta 1) (#23)
- Change to SQLite document store - Complete documentation on usage of Feed Reader Central - Update INSTALLING.md for new installation procedures Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
@@ -1,51 +1,44 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Feed Maintenance Page
|
||||
*
|
||||
* List feeds and provide links for maintenance actions
|
||||
*/
|
||||
|
||||
use BitBadger\PDODocument\{Custom, Field, Query};
|
||||
use BitBadger\PDODocument\Mapper\{ArrayMapper, DocumentMapper};
|
||||
use FeedReaderCentral\{Feed, Key, Table};
|
||||
|
||||
include '../start.php';
|
||||
|
||||
$db = Data::getConnection();
|
||||
Security::verifyUser($db);
|
||||
FeedReaderCentral\Security::verifyUser();
|
||||
|
||||
$feedQuery = $db->prepare('SELECT * FROM feed WHERE user_id = :user ORDER BY lower(title)');
|
||||
$feedQuery->bindValue(':user', $_SESSION[Key::USER_ID]);
|
||||
if (!($feedResult = $feedQuery->execute())) {
|
||||
add_error(Data::error($db)['error']);
|
||||
$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->appendParameter([]), new DocumentMapper(Feed::class));
|
||||
|
||||
page_head('Your Feeds');
|
||||
echo '<h1>Your Feeds</h1><article><p class=action_buttons>' . hx_get('/feed/?id=-1', 'Add Feed') . '</p>';
|
||||
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,
|
||||
(SELECT COUNT(*) FROM $item WHERE data->>'feed_id' = :feed AND data->>'is_read' = 0) AS unread,
|
||||
(SELECT COUNT(*) FROM $item WHERE data->>'feed_id' = :feed AND data->>'is_bookmarked' = 1) AS marked
|
||||
SQL, [':feed' => $feed->id], new ArrayMapper()) ?? ['total' => 0, 'unread' => 0, 'marked' => 0];
|
||||
echo '<p><strong>' . htmlentities($feed->title) . '</strong><br>'
|
||||
. '<span class=meta><em>Last Updated ' . date_time($feed->updated_on) . ' • '
|
||||
. 'As of ' . date_time($feed->checked_on) . '</em><br>' . hx_get("/feed/?id=$feed->id", 'Edit') . ' • '
|
||||
. 'Read ' . ($counts['unread'] > 0 ? hx_get("/feed/items?id=$feed->id&unread", 'Unread') : 'Unread')
|
||||
. " ({$counts['unread']}) | "
|
||||
. ($counts['total'] > 0 ? hx_get("/feed/items?id=$feed->id", 'All') : 'All') . " ({$counts['total']}) | "
|
||||
. ($counts['marked'] > 0 ? hx_get("/feed/items?id=$feed->id&bookmarked", 'Bookmarked') : 'Bookmarked')
|
||||
. " ({$counts['marked']}) • "
|
||||
. "<a href=/feed/?id=$feed->id hx-delete=/feed/?id=$feed->id "
|
||||
. ' hx-confirm="Are you sure you want to delete “' . htmlspecialchars($feed->title)
|
||||
. '”? This will remove the feed and all its items, including unread and bookmarked.">Delete</a>'
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
page_head('Your Feeds'); ?>
|
||||
<h1>Your Feeds</h1>
|
||||
<article>
|
||||
<p class=action_buttons><?=hx_get('/feed/?id=new', 'Add Feed')?></p><?php
|
||||
if ($feedResult) {
|
||||
while ($feed = $feedResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$feedId = $feed['id'];
|
||||
$countQuery = $db->prepare(<<<'SQL'
|
||||
SELECT (SELECT COUNT(*) FROM item WHERE feed_id = :feed) AS total,
|
||||
(SELECT COUNT(*) FROM item WHERE feed_id = :feed AND is_read = 0) AS unread,
|
||||
(SELECT COUNT(*) FROM item WHERE feed_id = :feed AND is_bookmarked = 1) AS marked
|
||||
SQL);
|
||||
$countQuery->bindValue(':feed', $feed['id']);
|
||||
$countResult = $countQuery->execute();
|
||||
$counts = $countResult
|
||||
? $countResult->fetchArray(SQLITE3_ASSOC) : ['total' => 0, 'unread' => 0, 'marked' => 0]; ?>
|
||||
<p><strong><?=htmlentities($feed['title'])?></strong><br>
|
||||
<span class=meta><em>Last Updated <?=date_time($feed['updated_on'])?> •
|
||||
As of <?=date_time($feed['checked_on'])?></em><br>
|
||||
<?=hx_get("/feed/?id=$feedId", 'Edit')?> • Read
|
||||
<?=$counts['unread'] > 0 ? hx_get("/feed/items?id=$feedId&unread", 'Unread') : 'Unread'?>
|
||||
(<?=$counts['unread']?>) |
|
||||
<?=$counts['total'] > 0 ? hx_get("/feed/items?id=$feedId", 'All') : 'All'?> (<?=$counts['total']?>) |
|
||||
<?=$counts['marked'] > 0 ? hx_get("/feed/items?id=$feedId&bookmarked", 'Bookmarked') : 'Bookmarked'?>
|
||||
(<?=$counts['marked']?>) •
|
||||
<a href=/feed/?id=<?=$feedId?> hx-delete=/feed/?id=<?=$feedId?>
|
||||
hx-confirm="Are you sure you want to delete “<?=htmlentities($feed['title'], ENT_QUOTES)?>”? This will remove the feed and all its items, including unread and bookmarked.">Delete</a>
|
||||
</span><?php
|
||||
}
|
||||
} ?>
|
||||
</article><?php
|
||||
echo '</article>';
|
||||
page_foot();
|
||||
$db->close();
|
||||
|
||||
Reference in New Issue
Block a user