diff --git a/src/app-config.php b/src/app-config.php index bc29c5a..76994d9 100644 --- a/src/app-config.php +++ b/src/app-config.php @@ -1,7 +1,7 @@ "", + 1 => strtoupper($value), + default => strtoupper(substr($value, 0, 1)) . substr($value, 1), + }; +} diff --git a/src/cli-start.php b/src/cli-start.php index 5a61045..b6dda7e 100644 --- a/src/cli-start.php +++ b/src/cli-start.php @@ -28,17 +28,3 @@ function cli_title(string $title): void { printfn(' | %s | %s |', $title, $appTitle); printfn($dashes . PHP_EOL); } - -/** - * Capitalize the first letter of the given string - * - * @param string $value The string to be capitalized - * @return string The given string with the first letter capitalized - */ -function init_cap(string $value): string { - return match (strlen($value)) { - 0 => "", - 1 => strtoupper($value), - default => strtoupper(substr($value, 0, 1)) . substr($value, 1), - }; -} diff --git a/src/public/assets/bookmark-add.png b/src/public/assets/bookmark-add.png new file mode 100644 index 0000000..c50719a Binary files /dev/null and b/src/public/assets/bookmark-add.png differ diff --git a/src/public/assets/bookmark-added.png b/src/public/assets/bookmark-added.png new file mode 100644 index 0000000..b7d1e05 Binary files /dev/null and b/src/public/assets/bookmark-added.png differ diff --git a/src/public/assets/style.css b/src/public/assets/style.css index d63410c..da1fefa 100644 --- a/src/public/assets/style.css +++ b/src/public/assets/style.css @@ -79,10 +79,6 @@ main { margin-top: .25rem; } - .item_heading { - margin-bottom: 0; - } - .item_published { margin-bottom: 1rem; line-height: 1.2; @@ -153,3 +149,31 @@ code { p.back-link { margin-top: -1rem; } +.item_heading { + margin-bottom: 0; + + .bookmark { + padding: 0; + border: solid 1px black; + border-radius: .5rem; + + &.add { + background-color: lightgray; + :hover { + background: linear-gradient(lightgreen, gray); + } + } + &.remove { + background: linear-gradient(lightgreen, green); + :hover { + background: linear-gradient(gray, lightgreen); + } + } + + img { + max-width: 1.5rem; + max-height: 1.5rem; + padding: .5rem; + } + } +} diff --git a/src/public/bookmark.php b/src/public/bookmark.php new file mode 100644 index 0000000..4c16617 --- /dev/null +++ b/src/public/bookmark.php @@ -0,0 +1,49 @@ +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 (key_exists('action', $_GET)) { + if ($_GET['action'] == 'add') { + $flag = 1; + } elseif ($_GET['action'] == 'remove') { + $flag = 0; + } + 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']); + } +} + +$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'; ?> + while ($item) { ?>


New   ' : ''?> + Bookmarked   ' : ''?> fetchArray(SQLITE3_ASSOC); } diff --git a/src/public/item.php b/src/public/item.php index 21659c9..3633f87 100644 --- a/src/public/item.php +++ b/src/public/item.php @@ -75,6 +75,8 @@ $updated = isset($item['updated_on']) ? date_time($item['updated_on']) : null; page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?>

+