- Change to SQLite document store - Complete documentation on usage of Feed Reader Central - Update INSTALLING.md for new installation procedures Reviewed-on: #23
77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
* Add/Edit/Delete Feed Page
|
|
*
|
|
* Allows users to add, edit, and delete feeds
|
|
*/
|
|
|
|
use BitBadger\PDODocument\{Delete, DocumentException, Field};
|
|
use FeedReaderCentral\{Feed, Security, Table};
|
|
|
|
include '../../start.php';
|
|
|
|
Security::verifyUser();
|
|
|
|
$feedId = key_exists('id', $_GET) ? (int)$_GET['id'] : -1;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
|
try {
|
|
if (!($feed = Feed::retrieveById($feedId))) not_found();
|
|
Delete::byFields(Table::ITEM, [Field::EQ('feed_id', $feed->id)]);
|
|
Delete::byId(Table::FEED, $feed->id);
|
|
add_info('Feed “' . htmlentities($feed->title) . '” deleted successfully');
|
|
frc_redirect('/feeds');
|
|
} catch (DocumentException $ex) {
|
|
add_error("$ex");
|
|
}
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
try {
|
|
$isNew = $_POST['id'] == '-1';
|
|
if ($isNew) {
|
|
$result = Feed::add($_POST['url']);
|
|
} else {
|
|
$feedId = (int)$_POST['id'];
|
|
$toEdit = Feed::retrieveById($feedId);
|
|
$result = $toEdit
|
|
? Feed::update($toEdit, $_POST['url'])
|
|
: ['error' => "Feed $feedId not found"];
|
|
}
|
|
if (key_exists('ok', $result)) {
|
|
add_info('Feed saved successfully');
|
|
frc_redirect('/feeds');
|
|
}
|
|
add_error($result['error']);
|
|
$feedId = 'error';
|
|
} catch (DocumentException $ex) {
|
|
add_error("$ex");
|
|
}
|
|
}
|
|
|
|
if ($feedId == -1) {
|
|
$title = 'Add RSS Feed';
|
|
$feed = new Feed(id: -1);
|
|
} else {
|
|
$title = 'Edit RSS Feed';
|
|
if ($feedId == 'error') {
|
|
$feed = new Feed(id: (int)$_POST['id'], url: $_POST['url'] ?? '');
|
|
} elseif (!($feed = Feed::retrieveById((int)$feedId))) not_found();
|
|
}
|
|
|
|
page_head($title); ?>
|
|
<h1><?=$title?></h1>
|
|
<article>
|
|
<form method=POST action=/feed/ hx-post=/feed/>
|
|
<input type=hidden name=id value=<?=$feed->id?>>
|
|
<label>
|
|
Feed URL
|
|
<input type=url name=url required autofocus value="<?=$feed->url?>">
|
|
</label>
|
|
<span class=break></span>
|
|
<button type=submit>Save</button>
|
|
</form>
|
|
</article><?php
|
|
page_foot();
|