Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Brickner/Podsumer/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,23 @@ public function getFeedItems(int $feed_id): array
return (false === $result) ? [] : $result;
}

public function getAllItems(): array
{
$sql = 'SELECT items.name, items.feed_id, items.id, items.guid, items.audio_url, items.audio_file, COALESCE(items.image, feeds.image) AS image, items.size, items.published, items.description, items.playback_position, feeds.name AS feed_name FROM items JOIN feeds ON feeds.id = items.feed_id ORDER BY items.published DESC';

$result = $this->query($sql);

return (false === $result) ? [] : $result;
}

public function getFeedItemsPage(int $feed_id, int $limit, int $page = 1): array
{
$offset = ($page - 1) * $limit;
$sql = 'SELECT items.name, items.feed_id, items.id, items.guid, items.audio_url, items.audio_file, COALESCE(items.image, feeds.image) AS image, items.size, items.published, items.description, items.playback_position FROM items JOIN feeds ON feeds.id = items.feed_id WHERE items.feed_id = :id ORDER BY items.published DESC LIMIT :limit OFFSET :offset';
$params = ['id' => $feed_id, 'limit' => $limit, 'offset' => $offset];
$result = $this->query($sql, $params);


return (false === $result) ? [] : $result;
}

Expand Down
2 changes: 2 additions & 0 deletions templates/base.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<h1 class="text-m font-black text-right">
<a href="/">Feeds</a>
&nbsp;|&nbsp;
<a href="/episodes">Episodes</a>
&nbsp;|&nbsp;
<a href="/opml">OPML</a>
&nbsp;|&nbsp;
<?= round($db_size/1024/1024/1024, 2) ?> GB
Expand Down
32 changes: 32 additions & 0 deletions templates/episodes.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container py-10">
<? if (empty($items)): ?>
<div class="container py-10 clear">
<h1 class="text-2xl">No Episodes</h1>
</div>
<? else: ?>
<? foreach ($items as $item): ?>
<div class="w-full clear-left py-8">
<a href="/item?item_id=<?= $item['id'] ?>">
<img src="/image?<?= !empty($item['item_image']) ? 'item_id=' . $item['id'] : 'feed_id=' . $item['feed_id'] ?>" class="w-32 border-solid border-neutral-800 border inline float-left mr-4">
</a>
<a href="/item?item_id=<?= $item['id'] ?>" class="text-xl">
<?= $item['name'] ?>
</a>
<br>
<span class="text-neutral-500">
<?= $item['feed_name'] ?>
&nbsp;|&nbsp;
<?= round($item['size'] / 1024 / 1024, 1) ?>MB
&nbsp;|&nbsp;
<?= date('m/d/Y', strtotime($item['published'])); ?>
<? if (!empty($item['audio_file'])) { ?>
&nbsp;|&nbsp;
<a href="/delete_audio?item_id=<?= $item['id'] ?>">Delete Audio</a>
<? } ?>
</span>
<br>
<?= substr(strip_tags($item['description']), 0, 360); ?>
</div>
<? endforeach ?>
<? endif ?>
</div>
8 changes: 8 additions & 0 deletions tests/Brickner/Podsumer/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public function testGetFeedItems()
$this->assertEquals(4, count($items));
}

public function testGetAllItems()
{
$this->feed = new Feed(self::TEST_FEED_URL);
$this->state->addFeed($this->feed);
$items = $this->state->getAllItems();
$this->assertEquals(4, count($items));
}

public function testGetFeedItemsPage()
{
$this->feed = new Feed(self::TEST_FEED_URL);
Expand Down
12 changes: 12 additions & 0 deletions www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ function home(array $args): void
Template::render($main, 'home', $vars);
}

#[Route('/episodes', 'GET', true)]
function episodes(array $args): void
{
global $main;

$vars = [
'items' => $main->getState()->getAllItems()
];

Template::render($main, 'episodes', $vars);
}

/**
* Add new feed(s)
* Path: /add
Expand Down