Completed result/option migration

- Change casing on exposed constants
- Add file-level phpdoc
This commit is contained in:
2024-07-25 21:14:57 -04:00
parent 1d5a3c1c7a
commit 6dc264d34c
34 changed files with 658 additions and 383 deletions

View File

@@ -1,4 +1,14 @@
<?php declare(strict_types=1);
<?php
/**
* Web Request Start Script
*
* This loads the environment needed for a web request
*
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
use BitBadger\PDODocument\Configuration;
use FeedReaderCentral\{Key, Security, User};
@@ -19,8 +29,8 @@ session_start([
*/
function add_message(string $level, string $message): void
{
if (!key_exists(Key::USER_MSG, $_SESSION)) $_SESSION[Key::USER_MSG] = array();
$_SESSION[Key::USER_MSG][] = ['level' => $level, 'message' => $message];
if (!key_exists(Key::UserMsg, $_SESSION)) $_SESSION[Key::UserMsg] = [];
$_SESSION[Key::UserMsg][] = ['level' => $level, 'message' => $message];
}
/**
@@ -43,7 +53,7 @@ function add_info(string $message): void
add_message('INFO', $message);
}
/** @var bool $is_htmx True if this request was initiated by htmx, false if not */
/** 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);
/**
@@ -67,14 +77,14 @@ function title_bar(): void
echo "<header hx-target=#main hx-push-url=true>"
. "<div><a href=/ class=title>Feed Reader Central</a><span class=version>$version</span></div>"
. "<nav>";
if (key_exists(Key::USER_ID, $_SESSION)) {
if (key_exists(Key::UserId, $_SESSION)) {
nav_link(hx_get('/feeds', 'Feeds'), true);
if (User::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]);
if ($_SESSION[Key::UserEmail] !== Security::SingleUserEmail) {
nav_link($_SESSION[Key::UserEmail]);
}
} else {
nav_link(hx_get('/user/log-on', 'Log On'), true);
@@ -100,15 +110,15 @@ function page_head(string $title): void
}
echo '</head><body>';
if (!$is_htmx) title_bar();
if (sizeof($messages = $_SESSION[Key::USER_MSG] ?? []) > 0) {
if (sizeof($messages = $_SESSION[Key::UserMsg] ?? []) > 0) {
echo '<div class=user_messages>';
array_walk($messages, function ($msg) {
echo '<div class=user_message>'
. ($msg['level'] == 'INFO' ? '' : "<strong>{$msg['level']}</strong><br>")
. ($msg['level'] === 'INFO' ? '' : "<strong>{$msg['level']}</strong><br>")
. $msg['message'] . '</div>';
});
echo '</div>';
$_SESSION[Key::USER_MSG] = [];
$_SESSION[Key::UserMsg] = [];
}
}
@@ -164,7 +174,7 @@ function date_time(string $value): string
*/
function hx_get(string $url, string $text, string $extraAttrs = ''): string
{
$attrs = $extraAttrs != '' ? " $extraAttrs" : '';
$attrs = $extraAttrs !== '' ? " $extraAttrs" : '';
return "<a href=\"$url\" hx-get=\"$url\"$attrs>$text</a>";
}