- Implement form styling throughout - Modify header links for narrower views - Clean up CSS
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Add/Edit/Delete Feed Page
|
|
*
|
|
* Allows users to add, edit, and delete feeds
|
|
*/
|
|
|
|
include '../../start.php';
|
|
|
|
$db = Data::getConnection();
|
|
Security::verifyUser($db);
|
|
|
|
$feedId = $_GET['id'] ?? '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
|
|
if (!($feed = Feed::retrieveById($feedId, $db))) not_found();
|
|
$itemDelete = $db->prepare('DELETE FROM item WHERE feed_id = :feed');
|
|
$itemDelete->bindValue(':feed', $feed['id']);
|
|
if (!$itemDelete->execute()) add_error(Data::error($db)['error']);
|
|
$feedDelete = $db->prepare('DELETE FROM feed WHERE id = :feed');
|
|
$feedDelete->bindValue(':feed', $feed['id']);
|
|
if ($feedDelete->execute()) {
|
|
add_info('Feed “' . htmlentities($feed['title']) . '” deleted successfully');
|
|
} else {
|
|
add_error(Data::error($db)['error']);
|
|
}
|
|
frc_redirect('/feeds');
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$isNew = $_POST['id'] == 'new';
|
|
if ($isNew) {
|
|
$result = Feed::add($_POST['url'], $db);
|
|
} else {
|
|
$toEdit = Feed::retrieveById($_POST['id'], $db);
|
|
$result = $toEdit ? Feed::update($toEdit, $_POST['url'], $db) : ['error' => "Feed {$_POST['id']} not found"];
|
|
}
|
|
if (key_exists('ok', $result)) {
|
|
add_info('Feed saved successfully');
|
|
frc_redirect('/feeds');
|
|
}
|
|
add_error($result['error']);
|
|
$feedId = 'error';
|
|
}
|
|
|
|
if ($feedId == 'new') {
|
|
$title = 'Add RSS Feed';
|
|
$feed = [ 'id' => $_GET['id'], 'url' => ''];
|
|
} else {
|
|
$title = 'Edit RSS Feed';
|
|
if ($feedId == 'error') {
|
|
$feed = ['id' => $_POST['id'] ?? '', 'url' => $_POST['url'] ?? ''];
|
|
} elseif (!($feed = Feed::retrieveById((int) $feedId, $db))) 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();
|
|
$db->close();
|