Compare commits
No commits in common. "da34f3653066bc3ab8ea5dcf8629daa61802fa49" and "4fa4dcb8314de952ac4133b7feefb099e2e83942" have entirely different histories.
da34f36530
...
4fa4dcb831
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/** The current Feed Reader Central version */
|
/** The current Feed Reader Central version */
|
||||||
const FRC_VERSION = '1.0.0-alpha7';
|
const FRC_VERSION = '1.0.0-alpha6';
|
||||||
|
|
||||||
spl_autoload_register(function ($class) {
|
spl_autoload_register(function ($class) {
|
||||||
$file = implode(DIRECTORY_SEPARATOR, [__DIR__, 'lib', "$class.php"]);
|
$file = implode(DIRECTORY_SEPARATOR, [__DIR__, 'lib', "$class.php"]);
|
||||||
@ -18,17 +18,3 @@ Data::ensureDb();
|
|||||||
|
|
||||||
/** @var string The date the world wide web was created */
|
/** @var string The date the world wide web was created */
|
||||||
const WWW_EPOCH = '1993-04-30T00:00:00+00:00';
|
const WWW_EPOCH = '1993-04-30T00:00:00+00:00';
|
||||||
|
|
||||||
/**
|
|
||||||
* 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),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -28,3 +28,17 @@ function cli_title(string $title): void {
|
|||||||
printfn(' | %s | %s |', $title, $appTitle);
|
printfn(' | %s | %s |', $title, $appTitle);
|
||||||
printfn($dashes . PHP_EOL);
|
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),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -14,31 +14,6 @@ class Data {
|
|||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the search index and synchronization triggers for the item table
|
|
||||||
*
|
|
||||||
* @param SQLite3 $db The database connection on which these will be created
|
|
||||||
*/
|
|
||||||
public static function createSearchIndex(SQLite3 $db): void {
|
|
||||||
$db->exec("CREATE VIRTUAL TABLE item_search USING fts5(content, content='item', content_rowid='id')");
|
|
||||||
$db->exec(<<<'SQL'
|
|
||||||
CREATE TRIGGER item_ai AFTER INSERT ON item BEGIN
|
|
||||||
INSERT INTO item_search (rowid, content) VALUES (new.id, new.content);
|
|
||||||
END;
|
|
||||||
SQL);
|
|
||||||
$db->exec(<<<'SQL'
|
|
||||||
CREATE TRIGGER item_au AFTER UPDATE ON item BEGIN
|
|
||||||
INSERT INTO item_search (item_search, rowid, content) VALUES ('delete', old.id, old.content);
|
|
||||||
INSERT INTO item_search (rowid, content) VALUES (new.id, new.content);
|
|
||||||
END;
|
|
||||||
SQL);
|
|
||||||
$db->exec(<<<'SQL'
|
|
||||||
CREATE TRIGGER item_ad AFTER DELETE ON item BEGIN
|
|
||||||
INSERT INTO item_search (item_search, rowid, content) VALUES ('delete', old.id, old.content);
|
|
||||||
END;
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the expected tables exist
|
* Make sure the expected tables exist
|
||||||
*/
|
*/
|
||||||
@ -48,16 +23,17 @@ class Data {
|
|||||||
$tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
|
$tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
|
||||||
while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0];
|
while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0];
|
||||||
if (!in_array('frc_user', $tables)) {
|
if (!in_array('frc_user', $tables)) {
|
||||||
$db->exec(<<<'SQL'
|
$query = <<<'SQL'
|
||||||
CREATE TABLE frc_user (
|
CREATE TABLE frc_user (
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
email TEXT NOT NULL,
|
email TEXT NOT NULL,
|
||||||
password TEXT NOT NULL)
|
password TEXT NOT NULL)
|
||||||
SQL);
|
SQL;
|
||||||
|
$db->exec($query);
|
||||||
$db->exec('CREATE INDEX idx_user_email ON frc_user (email)');
|
$db->exec('CREATE INDEX idx_user_email ON frc_user (email)');
|
||||||
}
|
}
|
||||||
if (!in_array('feed', $tables)) {
|
if (!in_array('feed', $tables)) {
|
||||||
$db->exec(<<<'SQL'
|
$query = <<<'SQL'
|
||||||
CREATE TABLE feed (
|
CREATE TABLE feed (
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
@ -66,10 +42,11 @@ class Data {
|
|||||||
updated_on TEXT,
|
updated_on TEXT,
|
||||||
checked_on TEXT,
|
checked_on TEXT,
|
||||||
FOREIGN KEY (user_id) REFERENCES frc_user (id))
|
FOREIGN KEY (user_id) REFERENCES frc_user (id))
|
||||||
SQL);
|
SQL;
|
||||||
|
$db->exec($query);
|
||||||
}
|
}
|
||||||
if (!in_array('item', $tables)) {
|
if (!in_array('item', $tables)) {
|
||||||
$db->exec(<<<'SQL'
|
$query = <<<'SQL'
|
||||||
CREATE TABLE item (
|
CREATE TABLE item (
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
feed_id INTEGER NOT NULL,
|
feed_id INTEGER NOT NULL,
|
||||||
@ -82,8 +59,8 @@ class Data {
|
|||||||
is_read BOOLEAN NOT NULL DEFAULT 0,
|
is_read BOOLEAN NOT NULL DEFAULT 0,
|
||||||
is_bookmarked BOOLEAN NOT NULL DEFAULT 0,
|
is_bookmarked BOOLEAN NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY (feed_id) REFERENCES feed (id))
|
FOREIGN KEY (feed_id) REFERENCES feed (id))
|
||||||
SQL);
|
SQL;
|
||||||
self::createSearchIndex($db);
|
$db->exec($query);
|
||||||
}
|
}
|
||||||
$db->close();
|
$db->close();
|
||||||
}
|
}
|
||||||
|
@ -239,19 +239,19 @@ class Feed {
|
|||||||
$start = strtolower(strlen($doc['content']) >= 9 ? substr($doc['content'], 0, 9) : $doc['content']);
|
$start = strtolower(strlen($doc['content']) >= 9 ? substr($doc['content'], 0, 9) : $doc['content']);
|
||||||
if ($start == '<!doctype' || str_starts_with($start, '<html')) {
|
if ($start == '<!doctype' || str_starts_with($start, '<html')) {
|
||||||
$derivedURL = self::deriveFeedFromHTML($doc['content']);
|
$derivedURL = self::deriveFeedFromHTML($doc['content']);
|
||||||
if (key_exists('error', $derivedURL)) return ['error' => $derivedURL['error']];
|
if (array_key_exists('error', $derivedURL)) return ['error' => $derivedURL['error']];
|
||||||
$feedURL = $derivedURL['ok'];
|
$feedURL = $derivedURL['ok'];
|
||||||
if (!str_starts_with($feedURL, 'http')) {
|
if (!str_starts_with($feedURL, 'http')) {
|
||||||
// Relative URL; feed should be retrieved in the context of the original URL
|
// Relative URL; feed should be retrieved in the context of the original URL
|
||||||
$original = parse_url($url);
|
$original = parse_url($url);
|
||||||
$port = key_exists('port', $original) ? ":{$original['port']}" : '';
|
$port = array_key_exists('port', $original) ? ":{$original['port']}" : '';
|
||||||
$feedURL = $original['scheme'] . '://' . $original['host'] . $port . $feedURL;
|
$feedURL = $original['scheme'] . '://' . $original['host'] . $port . $feedURL;
|
||||||
}
|
}
|
||||||
$doc = self::retrieveDocument($feedURL);
|
$doc = self::retrieveDocument($feedURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed = self::parseFeed($doc['content']);
|
$parsed = self::parseFeed($doc['content']);
|
||||||
if (key_exists('error', $parsed)) return ['error' => $parsed['error']];
|
if (array_key_exists('error', $parsed)) return ['error' => $parsed['error']];
|
||||||
|
|
||||||
$extract = $parsed['ok']->getElementsByTagNameNS(self::ATOM_NS, 'feed')->length > 0
|
$extract = $parsed['ok']->getElementsByTagNameNS(self::ATOM_NS, 'feed')->length > 0
|
||||||
? self::fromAtom(...) : self::fromRSS(...);
|
? self::fromAtom(...) : self::fromRSS(...);
|
||||||
@ -388,7 +388,7 @@ class Feed {
|
|||||||
*/
|
*/
|
||||||
public static function refreshFeed(int $feedId, string $url, SQLite3 $db): array {
|
public static function refreshFeed(int $feedId, string $url, SQLite3 $db): array {
|
||||||
$feedRetrieval = self::retrieveFeed($url);
|
$feedRetrieval = self::retrieveFeed($url);
|
||||||
if (key_exists('error', $feedRetrieval)) return $feedRetrieval;
|
if (array_key_exists('error', $feedRetrieval)) return $feedRetrieval;
|
||||||
$feed = $feedRetrieval['ok'];
|
$feed = $feedRetrieval['ok'];
|
||||||
|
|
||||||
$lastCheckedQuery = $db->prepare('SELECT checked_on FROM feed where id = :id');
|
$lastCheckedQuery = $db->prepare('SELECT checked_on FROM feed where id = :id');
|
||||||
@ -399,7 +399,7 @@ class Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$itemUpdate = self::updateItems($feedId, $feed, $lastChecked, $db);
|
$itemUpdate = self::updateItems($feedId, $feed, $lastChecked, $db);
|
||||||
if (key_exists('error', $itemUpdate)) return $itemUpdate;
|
if (array_key_exists('error', $itemUpdate)) return $itemUpdate;
|
||||||
|
|
||||||
$urlUpdate = $url == $feed->url ? '' : ', url = :url';
|
$urlUpdate = $url == $feed->url ? '' : ', url = :url';
|
||||||
$feedUpdate = $db->prepare(<<<SQL
|
$feedUpdate = $db->prepare(<<<SQL
|
||||||
@ -428,7 +428,7 @@ class Feed {
|
|||||||
*/
|
*/
|
||||||
public static function add(string $url, SQLite3 $db): array {
|
public static function add(string $url, SQLite3 $db): array {
|
||||||
$feedExtract = self::retrieveFeed($url);
|
$feedExtract = self::retrieveFeed($url);
|
||||||
if (key_exists('error', $feedExtract)) return $feedExtract;
|
if (array_key_exists('error', $feedExtract)) return $feedExtract;
|
||||||
|
|
||||||
$feed = $feedExtract['ok'];
|
$feed = $feedExtract['ok'];
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ class Feed {
|
|||||||
|
|
||||||
$feedId = $db->lastInsertRowID();
|
$feedId = $db->lastInsertRowID();
|
||||||
$result = self::updateItems($feedId, $feed, date_create_immutable(WWW_EPOCH), $db);
|
$result = self::updateItems($feedId, $feed, date_create_immutable(WWW_EPOCH), $db);
|
||||||
if (key_exists('error', $result)) return $result;
|
if (array_key_exists('error', $result)) return $result;
|
||||||
|
|
||||||
return ['ok' => $feedId];
|
return ['ok' => $feedId];
|
||||||
}
|
}
|
||||||
@ -504,12 +504,12 @@ class Feed {
|
|||||||
*/
|
*/
|
||||||
public static function refreshAll(SQLite3 $db): array {
|
public static function refreshAll(SQLite3 $db): array {
|
||||||
$feeds = self::retrieveAll($db, $_SESSION[Key::USER_ID]);
|
$feeds = self::retrieveAll($db, $_SESSION[Key::USER_ID]);
|
||||||
if (key_exists('error', $feeds)) return $feeds;
|
if (array_key_exists('error', $feeds)) return $feeds;
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
array_walk($feeds, function ($feed) use ($db, &$errors) {
|
array_walk($feeds, function ($feed) use ($db, &$errors) {
|
||||||
$result = self::refreshFeed($feed['id'], $feed['url'], $db);
|
$result = self::refreshFeed($feed['id'], $feed['url'], $db);
|
||||||
if (key_exists('error', $result)) $errors[] = $result['error'];
|
if (array_key_exists('error', $result)) $errors[] = $result['error'];
|
||||||
});
|
});
|
||||||
|
|
||||||
return sizeof($errors) == 0 ? ['ok' => true] : ['error' => implode("\n", $errors)];
|
return sizeof($errors) == 0 ? ['ok' => true] : ['error' => implode("\n", $errors)];
|
||||||
|
@ -1,191 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of items to be displayed
|
|
||||||
*
|
|
||||||
* This is a wrapper for retrieval and display of arbitrary lists of items based on a SQLite result.
|
|
||||||
*/
|
|
||||||
class ItemList {
|
|
||||||
|
|
||||||
/** @var SQLite3Result The list of items to be displayed */
|
|
||||||
private SQLite3Result $items;
|
|
||||||
|
|
||||||
/** @var string The error message generated by executing a query */
|
|
||||||
public string $error = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is there an error condition associated with this list?
|
|
||||||
*
|
|
||||||
* @return bool True if there is an error condition associated with this list, false if not
|
|
||||||
*/
|
|
||||||
public function isError(): bool {
|
|
||||||
return $this->error != '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var bool Whether to render a link to the feed to which the item belongs */
|
|
||||||
public bool $linkFeed = false;
|
|
||||||
|
|
||||||
/** @var bool Whether to display the feed to which the item belongs */
|
|
||||||
public bool $displayFeed = false;
|
|
||||||
|
|
||||||
/** @var bool Whether to show read / bookmarked indicators on posts */
|
|
||||||
public bool $showIndicators = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param SQLite3 $db The database connection (used to retrieve error information if the query fails)
|
|
||||||
* @param SQLite3Stmt $query The query to retrieve the items for this list
|
|
||||||
* @param string $itemType The type of item being displayed (unread, bookmark, etc.)
|
|
||||||
* @param string $returnURL The URL to which the item page should return once the item has been viewed
|
|
||||||
*/
|
|
||||||
private function __construct(SQLite3 $db, SQLite3Stmt $query, public string $itemType, public string $returnURL = '') {
|
|
||||||
$result = $query->execute();
|
|
||||||
if (!$result) {
|
|
||||||
$this->error = Data::error($db)['error'];
|
|
||||||
} else {
|
|
||||||
$this->items = $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list query
|
|
||||||
*
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @param array $criteria One or more SQL WHERE conditions (will be combined with AND)
|
|
||||||
* @param array $parameters Parameters to be added to the query (key index 0, value index 1; optional)
|
|
||||||
* @return SQLite3Stmt The query, ready to be executed
|
|
||||||
*/
|
|
||||||
private static function makeQuery(SQLite3 $db, array $criteria, array $parameters = []): SQLite3Stmt {
|
|
||||||
$where = empty($criteria) ? '' : 'AND ' . implode(' AND ', $criteria);
|
|
||||||
$sql = <<<SQL
|
|
||||||
SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
|
|
||||||
item.is_read, item.is_bookmarked, feed.title AS feed_title
|
|
||||||
FROM item INNER JOIN feed ON feed.id = item.feed_id
|
|
||||||
WHERE feed.user_id = :userId $where
|
|
||||||
ORDER BY coalesce(item.updated_on, item.published_on) DESC
|
|
||||||
SQL;
|
|
||||||
$query = $db->prepare($sql);
|
|
||||||
$query->bindValue(':userId', $_SESSION[Key::USER_ID]);
|
|
||||||
foreach ($parameters as $param) $query->bindValue($param[0], $param[1]);
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with all the current user's bookmarked items
|
|
||||||
*
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list with all bookmarked items
|
|
||||||
*/
|
|
||||||
public static function allBookmarked(SQLite3 $db): static {
|
|
||||||
$list = new static($db, self::makeQuery($db, ['item.is_bookmarked = 1']), 'Bookmarked', '/?bookmarked');
|
|
||||||
$list->linkFeed = true;
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with all the current user's unread items
|
|
||||||
*
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list with all unread items
|
|
||||||
*/
|
|
||||||
public static function allUnread(SQLite3 $db): static {
|
|
||||||
$list = new static($db, self::makeQuery($db, ['item.is_read = 0']), 'Unread');
|
|
||||||
$list->linkFeed = true;
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with all items for the given feed
|
|
||||||
*
|
|
||||||
* @param int $feedId The ID of the feed for which items should be retrieved
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list with all items for the given feed
|
|
||||||
*/
|
|
||||||
public static function allForFeed(int $feedId, SQLite3 $db): static {
|
|
||||||
$list = new static($db, self::makeQuery($db, ['feed.id = :feed'], [[':feed', $feedId]]), '',
|
|
||||||
"/feed/items?id=$feedId");
|
|
||||||
$list->showIndicators = true;
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with unread items for the given feed
|
|
||||||
*
|
|
||||||
* @param int $feedId The ID of the feed for which items should be retrieved
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list with unread items for the given feed
|
|
||||||
*/
|
|
||||||
public static function unreadForFeed(int $feedId, SQLite3 $db): static {
|
|
||||||
return new static($db, self::makeQuery($db, ['feed.id = :feed', 'item.is_read = 0'], [[':feed', $feedId]]),
|
|
||||||
'Unread', "/feed/items?id=$feedId&unread");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with bookmarked items for the given feed
|
|
||||||
*
|
|
||||||
* @param int $feedId The ID of the feed for which items should be retrieved
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list with bookmarked items for the given feed
|
|
||||||
*/
|
|
||||||
public static function bookmarkedForFeed(int $feedId, SQLite3 $db): static {
|
|
||||||
return new static($db,
|
|
||||||
self::makeQuery($db, ['feed.id = :feed', 'item.is_bookmarked = 1'], [[':feed', $feedId]]), 'Bookmarked',
|
|
||||||
"/feed/items?id=$feedId&bookmarked");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an item list with items matching given search terms
|
|
||||||
*
|
|
||||||
* @param string $search The item search terms / query
|
|
||||||
* @param bool $isBookmarked Whether to restrict the search to bookmarked items
|
|
||||||
* @param SQLite3 $db The database connection to use to obtain items
|
|
||||||
* @return static An item list match the given search terms
|
|
||||||
*/
|
|
||||||
public static function matchingSearch(string $search, bool $isBookmarked, SQLite3 $db): static {
|
|
||||||
$where = $isBookmarked ? ['item.is_bookmarked = 1'] : [];
|
|
||||||
$where[] = 'item.id IN (SELECT ROWID FROM item_search WHERE content MATCH :search)';
|
|
||||||
$list = new static($db, self::makeQuery($db, $where, [[':search', $search]]),
|
|
||||||
'Matching' . ($isBookmarked ? ' Bookmarked' : ''),
|
|
||||||
"/search?search=$search&items=" . ($isBookmarked ? 'bookmarked' : 'all'));
|
|
||||||
$list->showIndicators = true;
|
|
||||||
$list->displayFeed = true;
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render this item list
|
|
||||||
*/
|
|
||||||
public function render(): void {
|
|
||||||
if ($this->isError()) { ?>
|
|
||||||
<p>Error retrieving list:<br><?=$this->error?><?php
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$item = $this->items->fetchArray(SQLITE3_ASSOC);
|
|
||||||
$return = $this->returnURL == '' ? '' : '&from=' . urlencode($this->returnURL);
|
|
||||||
echo '<article>';
|
|
||||||
if ($item) {
|
|
||||||
while ($item) { ?>
|
|
||||||
<p><?=hx_get("/item?id={$item['id']}$return", strip_tags($item['item_title']))?><br>
|
|
||||||
<small><?php
|
|
||||||
if ($this->showIndicators) {
|
|
||||||
if (!$item['is_read']) echo '<strong>Unread</strong> ';
|
|
||||||
if ($item['is_bookmarked']) echo '<strong>Bookmarked</strong> ';
|
|
||||||
}
|
|
||||||
echo '<em>' . date_time($item['as_of']) . '</em>';
|
|
||||||
if ($this->linkFeed) {
|
|
||||||
echo ' • ' .
|
|
||||||
hx_get("/feed/items?id={$item['feed_id']}&" . strtolower($this->itemType),
|
|
||||||
htmlentities($item['feed_title']));
|
|
||||||
} elseif ($this->displayFeed) {
|
|
||||||
echo ' • ' . htmlentities($item['feed_title']);
|
|
||||||
} ?>
|
|
||||||
</small><?php
|
|
||||||
$item = $this->items->fetchArray(SQLITE3_ASSOC);
|
|
||||||
}
|
|
||||||
} else { ?>
|
|
||||||
<p><em>There are no <?=strtolower($this->itemType)?> items</em><?php
|
|
||||||
}
|
|
||||||
echo '</article>';
|
|
||||||
}
|
|
||||||
}
|
|
@ -131,7 +131,7 @@ class Security {
|
|||||||
* @param bool $redirectIfAnonymous Whether to redirect the request if there is no user logged on
|
* @param bool $redirectIfAnonymous Whether to redirect the request if there is no user logged on
|
||||||
*/
|
*/
|
||||||
public static function verifyUser(SQLite3 $db, bool $redirectIfAnonymous = true): void {
|
public static function verifyUser(SQLite3 $db, bool $redirectIfAnonymous = true): void {
|
||||||
if (key_exists(Key::USER_ID, $_SESSION)) return;
|
if (array_key_exists(Key::USER_ID, $_SESSION)) return;
|
||||||
|
|
||||||
if (SECURITY_MODEL == self::SINGLE_USER) self::logOnSingleUser($db);
|
if (SECURITY_MODEL == self::SINGLE_USER) self::logOnSingleUser($db);
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB |
@ -25,28 +25,28 @@ header {
|
|||||||
flex-flow: row wrap;
|
flex-flow: row wrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
div, nav {
|
|
||||||
|
div {
|
||||||
margin-bottom: .25rem;
|
margin-bottom: .25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.version {
|
.version {
|
||||||
font-size: .85rem;
|
font-size: .85rem;
|
||||||
padding-left: .5rem;
|
padding-left: .5rem;
|
||||||
color: rgba(255, 255, 255, .75);
|
color: rgba(255, 255, 255, .75);
|
||||||
}
|
}
|
||||||
|
|
||||||
a:link, a:visited {
|
a:link, a:visited {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
nav {
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row wrap;
|
|
||||||
gap: 0 .4rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
main {
|
main {
|
||||||
padding: 0 .5rem;
|
padding: 0 .5rem;
|
||||||
|
|
||||||
.refresh, .loading {
|
.refresh, .loading {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
font-size: .9rem;
|
font-size: .9rem;
|
||||||
@ -54,12 +54,14 @@ main {
|
|||||||
.htmx-request .refresh {
|
.htmx-request .refresh {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading {
|
.loading {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.htmx-request .loading {
|
.htmx-request .loading {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user_messages {
|
.user_messages {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
@ -72,9 +74,15 @@ main {
|
|||||||
background-color: rgba(255, 255, 255, .75);
|
background-color: rgba(255, 255, 255, .75);
|
||||||
padding: .25rem;
|
padding: .25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user_messages + h1 {
|
.user_messages + h1 {
|
||||||
margin-top: .25rem;
|
margin-top: .25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item_heading {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.item_published {
|
.item_published {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
@ -83,73 +91,37 @@ main {
|
|||||||
article {
|
article {
|
||||||
max-width: 60rem;
|
max-width: 60rem;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
|
||||||
.item_content {
|
.item_content {
|
||||||
border: solid 1px navy;
|
border: solid 1px navy;
|
||||||
border-radius: .5rem;
|
border-radius: .5rem;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: .5rem;
|
padding: .5rem;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
|
height: unset;
|
||||||
|
width: unset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta {
|
.meta {
|
||||||
font-size: .9rem;
|
font-size: .9rem;
|
||||||
}
|
}
|
||||||
&.docs {
|
}
|
||||||
|
article.docs {
|
||||||
line-height: 1.4rem;
|
line-height: 1.4rem;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
form {
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row wrap;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 0 2rem;
|
|
||||||
label {
|
|
||||||
font-size: .9rem;
|
|
||||||
font-weight: bold;
|
|
||||||
input, select {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.break {
|
|
||||||
flex-basis: 100%;
|
|
||||||
height: 1rem;
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
input[type=url],
|
|
||||||
input[type=text],
|
|
||||||
input[type=email],
|
|
||||||
input[type=password],
|
|
||||||
select {
|
|
||||||
min-width: 12rem;
|
|
||||||
max-width: 100%;
|
|
||||||
font-size: 1rem;
|
|
||||||
padding: .25rem;
|
|
||||||
border-radius: .25rem;
|
|
||||||
background-color: white;
|
|
||||||
border: solid 2px navy;
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
min-width: unset;
|
|
||||||
max-width: unset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media all and (min-width: 60rem) {
|
|
||||||
form {
|
|
||||||
input[type=url],
|
input[type=url],
|
||||||
input[type=text],
|
input[type=text],
|
||||||
input[type=email],
|
input[type=email],
|
||||||
input[type=password] {
|
input[type=password] {
|
||||||
min-width: 25rem;
|
width: 40%;
|
||||||
}
|
font-size: 1rem;
|
||||||
}
|
padding: .25rem;
|
||||||
}
|
border-radius: .25rem;
|
||||||
.action_buttons {
|
|
||||||
margin: 1rem 0;
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row nowrap;
|
|
||||||
justify-content: space-evenly;
|
|
||||||
}
|
}
|
||||||
button,
|
button,
|
||||||
.action_buttons a:link,
|
.action_buttons a:link,
|
||||||
@ -162,11 +134,18 @@ button,
|
|||||||
border-radius: .25rem;
|
border-radius: .25rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: none;
|
border: none;
|
||||||
&:hover {
|
}
|
||||||
|
button:hover,
|
||||||
|
.action_buttons a:hover {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: linear-gradient(navy, #000032);
|
background: linear-gradient(navy, #000032);
|
||||||
}
|
}
|
||||||
|
.action_buttons {
|
||||||
|
margin: 1rem 0;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
justify-content: space-evenly;
|
||||||
}
|
}
|
||||||
code {
|
code {
|
||||||
font-size: .9rem;
|
font-size: .9rem;
|
||||||
@ -174,28 +153,3 @@ code {
|
|||||||
p.back-link {
|
p.back-link {
|
||||||
margin-top: -1rem;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bookmark Partial Handler
|
|
||||||
*
|
|
||||||
* This will display a button which will either add or remove a bookmark for a given item.
|
|
||||||
*/
|
|
||||||
|
|
||||||
include '../start.php';
|
|
||||||
|
|
||||||
$db = Data::getConnection();
|
|
||||||
Security::verifyUser($db);
|
|
||||||
|
|
||||||
$id = $_GET['id'];
|
|
||||||
|
|
||||||
$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 (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'; ?>
|
|
||||||
<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">
|
|
||||||
</button><?php
|
|
@ -35,7 +35,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|||||||
$toEdit = Feed::retrieveById($_POST['id'], $db);
|
$toEdit = Feed::retrieveById($_POST['id'], $db);
|
||||||
$result = $toEdit ? Feed::update($toEdit, $_POST['url'], $db) : ['error' => "Feed {$_POST['id']} not found"];
|
$result = $toEdit ? Feed::update($toEdit, $_POST['url'], $db) : ['error' => "Feed {$_POST['id']} not found"];
|
||||||
}
|
}
|
||||||
if (key_exists('ok', $result)) {
|
if (array_key_exists('ok', $result)) {
|
||||||
add_info('Feed saved successfully');
|
add_info('Feed saved successfully');
|
||||||
frc_redirect('/feeds');
|
frc_redirect('/feeds');
|
||||||
}
|
}
|
||||||
@ -61,8 +61,7 @@ page_head($title); ?>
|
|||||||
<label>
|
<label>
|
||||||
Feed URL
|
Feed URL
|
||||||
<input type=url name=url required autofocus value="<?=$feed['url']?>">
|
<input type=url name=url required autofocus value="<?=$feed['url']?>">
|
||||||
</label>
|
</label><br>
|
||||||
<span class=break></span>
|
|
||||||
<button type=submit>Save</button>
|
<button type=submit>Save</button>
|
||||||
</form>
|
</form>
|
||||||
</article><?php
|
</article><?php
|
||||||
|
@ -12,19 +12,68 @@ Security::verifyUser($db);
|
|||||||
|
|
||||||
if (!($feed = Feed::retrieveById($_GET['id'], $db))) not_found();
|
if (!($feed = Feed::retrieveById($_GET['id'], $db))) not_found();
|
||||||
|
|
||||||
$list = match (true) {
|
/** Display a list of unread items for this feed */
|
||||||
key_exists('unread', $_GET) => ItemList::unreadForFeed($feed['id'], $db),
|
const TYPE_UNREAD = 0;
|
||||||
key_exists('bookmarked', $_GET) => ItemList::bookmarkedForFeed($feed['id'], $db),
|
|
||||||
default => ItemList::allForFeed($feed['id'], $db)
|
/** Display a list of bookmarked items for this feed */
|
||||||
|
const TYPE_BOOKMARKED = 1;
|
||||||
|
|
||||||
|
/** Display all items for this feed */
|
||||||
|
const TYPE_ALL = 2;
|
||||||
|
|
||||||
|
$type = match (true) {
|
||||||
|
array_key_exists('unread', $_GET) => TYPE_UNREAD,
|
||||||
|
array_key_exists('bookmarked', $_GET) => TYPE_BOOKMARKED,
|
||||||
|
default => TYPE_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
page_head(($list->itemType != '' ? "$list->itemType Items | " : '') . strip_tags($feed['title']));
|
$extraSQL = match ($type) {
|
||||||
if ($list->itemType == '') {
|
TYPE_UNREAD => ' AND is_read = 0',
|
||||||
echo '<h1>' . htmlentities($feed['title']) . '</h1>';
|
TYPE_BOOKMARKED => ' AND is_bookmarked = 1',
|
||||||
} else {
|
default => ''
|
||||||
echo '<h1 class=item_heading>' . htmlentities($feed['title']) . '</h1>';
|
};
|
||||||
echo "<div class=item_published>$list->itemType Items</div>";
|
$itemQuery = $db->prepare(<<<SQL
|
||||||
|
SELECT id, title, coalesce(updated_on, published_on) AS as_of, is_read, is_bookmarked
|
||||||
|
FROM item
|
||||||
|
WHERE feed_id = :feed$extraSQL
|
||||||
|
ORDER BY date(coalesce(updated_on, published_on)) DESC
|
||||||
|
SQL);
|
||||||
|
$itemQuery->bindValue(':feed', $feed['id']);
|
||||||
|
if (!($itemResult = $itemQuery->execute())) add_error(Data::error($db)['error']);
|
||||||
|
$item = $itemResult ? $itemResult->fetchArray(SQLITE3_ASSOC) : false;
|
||||||
|
|
||||||
|
$queryParam = match ($type) {
|
||||||
|
TYPE_UNREAD => '&unread',
|
||||||
|
TYPE_BOOKMARKED => '&bookmarked',
|
||||||
|
default => ''
|
||||||
|
};
|
||||||
|
$thisURL = urlencode("/feed/items?id={$feed['id']}$queryParam");
|
||||||
|
|
||||||
|
$listType = match ($type) {
|
||||||
|
TYPE_UNREAD => 'Unread',
|
||||||
|
TYPE_BOOKMARKED => 'Bookmarked',
|
||||||
|
default => ''
|
||||||
|
};
|
||||||
|
|
||||||
|
page_head(($type != TYPE_ALL ? "$listType Items | " : '') . strip_tags($feed['title']));
|
||||||
|
if ($type == TYPE_ALL) { ?>
|
||||||
|
<h1><?=htmlentities($feed['title'])?></h1><?php
|
||||||
|
} else { ?>
|
||||||
|
<h1 class=item_heading><?=htmlentities($feed['title'])?></h1>
|
||||||
|
<div class=item_published><?=$listType?> Items</div><?php
|
||||||
|
} ?>
|
||||||
|
<article><?php
|
||||||
|
if ($item) {
|
||||||
|
while ($item) { ?>
|
||||||
|
<p><?=hx_get("/item?id={$item['id']}&from=$thisURL", strip_tags($item['title']))?><br>
|
||||||
|
<small><?=$item['is_read'] == 0 ? '<strong>New</strong> ' : ''?>
|
||||||
|
<em><?=date_time($item['as_of'])?></em></small><?php
|
||||||
|
$item = $itemResult->fetchArray(SQLITE3_ASSOC);
|
||||||
}
|
}
|
||||||
$list->render();
|
} else { ?>
|
||||||
|
<p><em>There are no <?=strtolower($listType)?> items</em><?php
|
||||||
|
} ?>
|
||||||
|
</article>
|
||||||
|
<?php
|
||||||
page_foot();
|
page_foot();
|
||||||
$db->close();
|
$db->close();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Home Page
|
* Home Page
|
||||||
*
|
*
|
||||||
* Displays a list of unread or bookmarked items for the current user
|
* Displays a list of unread feed items for the current user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include '../start.php';
|
include '../start.php';
|
||||||
@ -10,28 +10,46 @@ include '../start.php';
|
|||||||
$db = Data::getConnection();
|
$db = Data::getConnection();
|
||||||
Security::verifyUser($db);
|
Security::verifyUser($db);
|
||||||
|
|
||||||
if (key_exists('refresh', $_GET)) {
|
if (array_key_exists('refresh', $_GET)) {
|
||||||
$refreshResult = Feed::refreshAll($db);
|
$refreshResult = Feed::refreshAll($db);
|
||||||
if (key_exists('ok', $refreshResult)) {
|
if (array_key_exists('ok', $refreshResult)) {
|
||||||
add_info('All feeds refreshed successfully');
|
add_info('All feeds refreshed successfully');
|
||||||
} else {
|
} else {
|
||||||
add_error(nl2br($refreshResult['error']));
|
add_error(nl2br($refreshResult['error']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = match (true) {
|
$query = $db->prepare(<<<'SQL'
|
||||||
key_exists('bookmarked', $_GET) => ItemList::allBookmarked($db),
|
SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
|
||||||
default => ItemList::allUnread($db)
|
feed.title AS feed_title
|
||||||
};
|
FROM item
|
||||||
$title = "Your $list->itemType Items";
|
INNER JOIN feed ON feed.id = item.feed_id
|
||||||
|
WHERE feed.user_id = :userId
|
||||||
|
AND item.is_read = 0
|
||||||
|
ORDER BY coalesce(item.updated_on, item.published_on) DESC
|
||||||
|
SQL);
|
||||||
|
$query->bindValue(':userId', $_SESSION[Key::USER_ID]);
|
||||||
|
$result = $query->execute();
|
||||||
|
$item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false;
|
||||||
|
|
||||||
page_head($title);
|
page_head('Your Unread Items'); ?>
|
||||||
echo "<h1>$title";
|
<h1>
|
||||||
if ($list->itemType == 'Unread') {
|
Your Unread Items
|
||||||
echo ' ' . hx_get('/?refresh', '(Refresh All Feeds)', 'class=refresh hx-indicator="closest h1"')
|
<a class=refresh href=/?refresh hx-get=/?refresh hx-indicator="closest h1">(Refresh All Feeds)</a>
|
||||||
. '<span class=loading>Refreshing…</span>';
|
<span class=loading>Refreshing…</span>
|
||||||
|
</h1>
|
||||||
|
<article><?php
|
||||||
|
if ($item) {
|
||||||
|
while ($item) { ?>
|
||||||
|
<p><?=hx_get("/item?id={$item['id']}", strip_tags($item['item_title']))?><br>
|
||||||
|
<small><?=date_time($item['as_of'])?> •
|
||||||
|
<?=hx_get("/feed/items?id={$item['feed_id']}&unread", htmlentities($item['feed_title']))?></small><?php
|
||||||
|
$item = $result->fetchArray(SQLITE3_ASSOC);
|
||||||
}
|
}
|
||||||
echo '</h1>';
|
} else { ?>
|
||||||
$list->render();
|
<p>There are no unread items</p><?php
|
||||||
|
} ?>
|
||||||
|
</article><?php
|
||||||
|
|
||||||
page_foot();
|
page_foot();
|
||||||
$db->close();
|
$db->close();
|
||||||
|
@ -75,8 +75,6 @@ $updated = isset($item['updated_on']) ? date_time($item['updated_on']) : null;
|
|||||||
|
|
||||||
page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?>
|
page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?>
|
||||||
<h1 class=item_heading>
|
<h1 class=item_heading>
|
||||||
<span class=bookmark hx-get="/bookmark?id=<?=$_GET['id']?>" hx-trigger=load hx-target=this hx-swap=outerHTML
|
|
||||||
hx-push-url=false></span>
|
|
||||||
<a href="<?=$item['item_link']?>" target=_blank rel=noopener><?=strip_tags($item['item_title'])?></a><br>
|
<a href="<?=$item['item_link']?>" target=_blank rel=noopener><?=strip_tags($item['item_title'])?></a><br>
|
||||||
</h1>
|
</h1>
|
||||||
<div class=item_published>
|
<div class=item_published>
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Item Search Page
|
|
||||||
*
|
|
||||||
* Search for items across all feeds
|
|
||||||
*/
|
|
||||||
|
|
||||||
include '../start.php';
|
|
||||||
|
|
||||||
$db = Data::getConnection();
|
|
||||||
Security::verifyUser($db);
|
|
||||||
|
|
||||||
$search = $_GET['search'] ?? '';
|
|
||||||
$items = $_GET['items'] ?? 'all';
|
|
||||||
|
|
||||||
if ($search != '') {
|
|
||||||
$list = ItemList::matchingSearch($search, $items == 'bookmarked', $db);
|
|
||||||
}
|
|
||||||
|
|
||||||
page_head('Item Search'); ?>
|
|
||||||
<h1>Item Search</h1>
|
|
||||||
<article>
|
|
||||||
<form method=GET action=/search>
|
|
||||||
<label>
|
|
||||||
Search Criteria
|
|
||||||
<input type=text name=search required autofocus value="<?=htmlspecialchars($search)?>">
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
Items to Search
|
|
||||||
<select name=items>
|
|
||||||
<option value=all <?=$items == 'all' ? ' selected' : ''?>>All</option>
|
|
||||||
<option value=bookmarked <?=$items == 'bookmarked' ? ' selected' : ''?>>Bookmarked</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<span class=break></span>
|
|
||||||
<button type=submit>Search</button>
|
|
||||||
</form><?php
|
|
||||||
if (isset($list)) { ?>
|
|
||||||
<hr><?php
|
|
||||||
$list->render();
|
|
||||||
} ?>
|
|
||||||
</article><?php
|
|
||||||
page_foot();
|
|
||||||
$db->close();
|
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
include '../../start.php';
|
include '../../start.php';
|
||||||
|
|
||||||
if (key_exists(Key::USER_ID, $_SESSION)) session_destroy();
|
if (array_key_exists(Key::USER_ID, $_SESSION)) session_destroy();
|
||||||
|
|
||||||
frc_redirect('/');
|
frc_redirect('/');
|
||||||
|
@ -5,7 +5,7 @@ $db = Data::getConnection();
|
|||||||
Security::verifyUser($db, redirectIfAnonymous: false);
|
Security::verifyUser($db, redirectIfAnonymous: false);
|
||||||
|
|
||||||
// Users already logged on have no need of this page
|
// Users already logged on have no need of this page
|
||||||
if (key_exists(Key::USER_ID, $_SESSION)) frc_redirect('/');
|
if (array_key_exists(Key::USER_ID, $_SESSION)) frc_redirect('/');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
Security::logOnUser($_POST['email'] ?? '', $_POST['password'], $_POST['returnTo'] ?? null, $db);
|
Security::logOnUser($_POST['email'] ?? '', $_POST['password'], $_POST['returnTo'] ?? null, $db);
|
||||||
@ -26,13 +26,12 @@ page_head('Log On'); ?>
|
|||||||
<label>
|
<label>
|
||||||
E-mail Address
|
E-mail Address
|
||||||
<input type=email name=email required autofocus>
|
<input type=email name=email required autofocus>
|
||||||
</label><?php
|
</label><br><?php
|
||||||
} ?>
|
} ?>
|
||||||
<label>
|
<label>
|
||||||
Password
|
Password
|
||||||
<input type=password name=password required<?=$isSingle ? ' autofocus' : ''?>>
|
<input type=password name=password required<?=$isSingle ? ' autofocus' : ''?>>
|
||||||
</label>
|
</label><br>
|
||||||
<span class=break></span>
|
|
||||||
<button type=submit>Log On</button>
|
<button type=submit>Log On</button>
|
||||||
</form>
|
</form>
|
||||||
</article><?php
|
</article><?php
|
||||||
|
@ -16,7 +16,7 @@ session_start([
|
|||||||
* @param string $message The message itself
|
* @param string $message The message itself
|
||||||
*/
|
*/
|
||||||
function add_message(string $level, string $message): void {
|
function add_message(string $level, string $message): void {
|
||||||
if (!key_exists(Key::USER_MSG, $_SESSION)) $_SESSION[Key::USER_MSG] = array();
|
if (!array_key_exists(Key::USER_MSG, $_SESSION)) $_SESSION[Key::USER_MSG] = array();
|
||||||
$_SESSION[Key::USER_MSG][] = ['level' => $level, 'message' => $message];
|
$_SESSION[Key::USER_MSG][] = ['level' => $level, 'message' => $message];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,12 +39,8 @@ function add_info(string $message): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var bool $is_htmx True if this request was initiated by htmx, false if not */
|
/** @var bool $is_htmx True if this request was initiated by htmx, false if not */
|
||||||
$is_htmx = key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
|
$is_htmx = array_key_exists('HTTP_HX_REQUEST', $_SERVER)
|
||||||
|
&& !array_key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
|
||||||
function nav_link(string $link, bool $isFirst = false) {
|
|
||||||
$sep = $isFirst ? '' : ' | ';
|
|
||||||
echo "<span>$sep$link</span>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the title bar for the page
|
* Render the title bar for the page
|
||||||
@ -56,36 +52,18 @@ function title_bar(): void {
|
|||||||
default => FRC_VERSION
|
default => FRC_VERSION
|
||||||
}; ?>
|
}; ?>
|
||||||
<header hx-target=#main hx-push-url=true>
|
<header hx-target=#main hx-push-url=true>
|
||||||
<div><a href=/ class=title>Feed Reader Central</a><span class=version>v<?=$version?></span></div>
|
<div><?=hx_get('/', 'Feed Reader Central', 'class=title')?><span class=version>v<?=$version?></span></div>
|
||||||
<nav><?php
|
<div><?php
|
||||||
if (key_exists(Key::USER_ID, $_SESSION)) {
|
if (array_key_exists(Key::USER_ID, $_SESSION)) { ?>
|
||||||
$db = Data::getConnection();
|
<?=hx_get('/feeds', 'Feeds')?> | <?=hx_get('/docs/', 'Docs')?> |
|
||||||
try {
|
<a href=/user/log-off>Log Off</a><?php
|
||||||
$bookQuery = $db->prepare(<<<'SQL'
|
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) { ?>
|
||||||
SELECT EXISTS(
|
| <?=$_SESSION[Key::USER_EMAIL]?><?php
|
||||||
SELECT 1
|
|
||||||
FROM item INNER JOIN feed ON item.feed_id = feed.id
|
|
||||||
WHERE feed.user_id = :id AND item.is_bookmarked = 1)
|
|
||||||
SQL);
|
|
||||||
$bookQuery->bindValue(':id', $_SESSION[Key::USER_ID]);
|
|
||||||
$bookResult = $bookQuery->execute();
|
|
||||||
$hasBookmarks = $bookResult && $bookResult->fetchArray(SQLITE3_NUM)[0];
|
|
||||||
nav_link(hx_get('/feeds', 'Feeds'), true);
|
|
||||||
if ($hasBookmarks) nav_link(hx_get('/?bookmarked', 'Bookmarked'));
|
|
||||||
nav_link(hx_get('/search', 'Search'));
|
|
||||||
nav_link(hx_get('/docs/', 'Docs'));
|
|
||||||
nav_link('<a href=/user/log-off>Log Off</a>');
|
|
||||||
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) {
|
|
||||||
nav_link($_SESSION[Key::USER_EMAIL]);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} else { ?>
|
||||||
$db->close();
|
<?=hx_get('/user/log-on', 'Log On')?> | <?=hx_get('/docs/', 'Docs')?><?php
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nav_link(hx_get('/user/log-on', 'Log On'), true);
|
|
||||||
nav_link(hx_get('/docs/', 'Docs'));
|
|
||||||
} ?>
|
} ?>
|
||||||
</nav>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<main id=main hx-target=this hx-push-url=true hx-swap="innerHTML show:window:top"><?php
|
<main id=main hx-target=this hx-push-url=true hx-swap="innerHTML show:window:top"><?php
|
||||||
}
|
}
|
||||||
@ -128,7 +106,9 @@ function page_head(string $title): void {
|
|||||||
function page_foot(): void {
|
function page_foot(): void {
|
||||||
global $is_htmx; ?>
|
global $is_htmx; ?>
|
||||||
</main><?php
|
</main><?php
|
||||||
if (!$is_htmx) echo '<script src=/assets/htmx.min.js></script>'; ?>
|
if (!$is_htmx) { ?>
|
||||||
|
<script src=/assets/htmx.min.js></script><?php
|
||||||
|
} ?>
|
||||||
</body>
|
</body>
|
||||||
</html><?php
|
</html><?php
|
||||||
session_commit();
|
session_commit();
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
|
||||||
|
|
||||||
require __DIR__ . '/../cli-start.php';
|
|
||||||
|
|
||||||
cli_title('SEARCH MAINTENANCE');
|
|
||||||
|
|
||||||
if ($argc < 2) display_help();
|
|
||||||
|
|
||||||
switch ($argv[1]) {
|
|
||||||
case 'rebuild':
|
|
||||||
rebuild_index();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printfn('Unrecognized option "%s"', $argv[1]);
|
|
||||||
display_help();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the options for this utility and exit
|
|
||||||
*/
|
|
||||||
#[NoReturn]
|
|
||||||
function display_help(): void {
|
|
||||||
printfn('Options:');
|
|
||||||
printfn(' - rebuild');
|
|
||||||
printfn(' Rebuilds search index');
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rebuild the search index, creating it if it does not already exist
|
|
||||||
*/
|
|
||||||
function rebuild_index(): void {
|
|
||||||
$db = Data::getConnection();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$hasIndex = $db->query("SELECT COUNT(*) FROM sqlite_master WHERE name = 'item_ai'");
|
|
||||||
if ($hasIndex->fetchArray(SQLITE3_NUM)[0] == 0) {
|
|
||||||
printfn('Creating search index....');
|
|
||||||
Data::createSearchIndex($db);
|
|
||||||
}
|
|
||||||
printfn('Rebuilding search index...');
|
|
||||||
$db->exec("INSERT INTO item_search (item_search) VALUES ('rebuild')");
|
|
||||||
printfn(PHP_EOL . 'Search index rebuilt');
|
|
||||||
} finally {
|
|
||||||
$db->close();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user