2024-06-21 03:06:31 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2024-06-22 03:22:56 +00:00
|
|
|
use BitBadger\PDODocument\{Configuration, Definition, Mode};
|
2024-06-21 23:01:12 +00:00
|
|
|
use Dotenv\Dotenv;
|
2024-06-22 03:22:56 +00:00
|
|
|
use MyPrayerJournal\{Auth, Layout, Table};
|
2024-06-21 23:01:12 +00:00
|
|
|
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
/** The version of this application */
|
|
|
|
const MPJ_VERSION = '4.0.0-alpha1';
|
|
|
|
|
|
|
|
(Dotenv::createImmutable(__DIR__))->load();
|
|
|
|
|
2024-06-22 16:30:26 +00:00
|
|
|
if (php_sapi_name() != 'cli') {
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
$auth0_session = Auth::client()->getCredentials();
|
|
|
|
if (!is_null($auth0_session)) {
|
|
|
|
$_SESSION['user_id'] = $auth0_session->user['sub'];
|
|
|
|
}
|
2024-06-21 23:01:12 +00:00
|
|
|
}
|
|
|
|
|
2024-06-22 03:22:56 +00:00
|
|
|
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']);
|
|
|
|
Configuration::$mode = Mode::SQLite;
|
|
|
|
Definition::ensureTable(Table::REQUEST);
|
|
|
|
|
2024-06-21 23:01:12 +00:00
|
|
|
/**
|
|
|
|
* Is this an htmx request?
|
|
|
|
*
|
|
|
|
* @return bool True if this is an htmx request, false if not
|
|
|
|
*/
|
|
|
|
function is_htmx(): bool
|
|
|
|
{
|
|
|
|
return key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
|
2024-06-21 03:06:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-21 23:01:12 +00:00
|
|
|
function page_head(string $title): void
|
|
|
|
{
|
|
|
|
Layout::htmlHead($title);
|
|
|
|
echo '<body>';
|
|
|
|
if (!is_htmx()) echo '<section id=top aria-label="Top navigation">';
|
|
|
|
Layout::navBar();
|
|
|
|
echo '<main role=main>';
|
2024-06-21 03:06:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-21 23:01:12 +00:00
|
|
|
function page_foot(): void
|
2024-06-21 03:06:31 +00:00
|
|
|
{
|
2024-06-21 23:01:12 +00:00
|
|
|
echo '</main>';
|
|
|
|
if (!is_htmx()) {
|
|
|
|
echo '</section>';
|
|
|
|
Layout::htmlFoot();
|
|
|
|
}
|
|
|
|
echo '</body></html>';
|
|
|
|
}
|