49 lines
2.4 KiB
PHP
49 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Feed Maintenance Page
|
|
*
|
|
* List feeds and provide links for maintenance actions
|
|
*
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
* @license MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use BitBadger\PDODocument\{Custom, Field, Query};
|
|
use BitBadger\PDODocument\Mapper\{ArrayMapper, DocumentMapper};
|
|
use FeedReaderCentral\{Feed, Key, Table};
|
|
|
|
include '../start.php';
|
|
|
|
FeedReaderCentral\Security::verifyUser();
|
|
|
|
$field = Field::EQ('user_id', $_SESSION[Key::UserId], ':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>';
|
|
$feeds->iter(function (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())->getOrDefault(['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>';
|
|
});
|
|
echo '</article>';
|
|
page_foot();
|