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:
2024-06-12 02:07:35 +00:00
parent 819979f2b2
commit 0c87392910
43 changed files with 1652 additions and 1142 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Bookmark Partial Handler
@@ -6,43 +6,35 @@
* This will display a button which will either add or remove a bookmark for a given item.
*/
use BitBadger\PDODocument\{DocumentException, Patch};
use FeedReaderCentral\{ItemWithFeed, Table};
include '../start.php';
$db = Data::getConnection();
Security::verifyUser($db);
FeedReaderCentral\Security::verifyUser();
$id = $_GET['id'];
$id = key_exists('id', $_GET) ? (int)$_GET['id'] : -1;
$existsQuery = $db->prepare(
'SELECT item.id FROM item INNER JOIN feed ON feed.id = item.feed_id WHERE item.id = :id AND feed.user_id = :user');
$existsQuery->bindValue(':id', $id);
$existsQuery->bindValue(':user', $_SESSION[Key::USER_ID]);
$existsResult = $existsQuery->execute();
$exists = $existsResult ? $existsResult->fetchArray(SQLITE3_ASSOC) : false;
if (!$exists) not_found();
if (!$item = ItemWithFeed::retrieveById($id)) not_found();
if (key_exists('action', $_GET)) {
if ($_GET['action'] == 'add') {
$flag = 1;
} elseif ($_GET['action'] == 'remove') {
$flag = 0;
}
$flag = match ($_GET['action']) {
'add' => 1,
'remove' => 0,
default => null
};
if (isset($flag)) {
$update = $db->prepare('UPDATE item SET is_bookmarked = :flag WHERE id = :id');
$update->bindValue(':id', $id);
$update->bindValue(':flag', $flag);
if (!$update->execute()) die(Data::error($db)['error']);
try {
Patch::byId(Table::ITEM, $id, ['is_bookmarked' => $flag]);
$item->is_bookmarked = $flag;
} catch (DocumentException $ex) {
add_error("$ex");
}
}
}
$bookQuery = $db->prepare('SELECT id, is_bookmarked FROM item WHERE id = :id');
$bookQuery->bindValue(':id', $id);
$bookResult = $bookQuery->execute();
$bookmark = $bookResult ? $bookResult->fetchArray(SQLITE3_ASSOC) : ['id' => $id, 'is_bookmarked' => 0];
$action = $bookmark['is_bookmarked'] ? 'remove' : 'add';
$icon = $bookmark['is_bookmarked'] ? 'added' : 'add'; ?>
$action = $item->isBookmarked() ? 'remove' : 'add';
$icon = $item->isBookmarked() ? 'added' : 'add'; ?>
<button class="bookmark <?=$action?>" type=button role=button hx-patch="/bookmark?id=<?=$id?>&action=<?=$action?>"
hx-target=this hx-swap=outerHTML hx-push-url=false title="<?=init_cap($action)?> Bookmark">
<img src=/assets/bookmark-<?=$icon?>.png alt="<?=$action?> bookmark">