2024-06-21 03:06:31 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2024-06-21 23:01:12 +00:00
|
|
|
use Dotenv\Dotenv;
|
|
|
|
use MyPrayerJournal\{Auth, Layout};
|
|
|
|
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
/** The version of this application */
|
|
|
|
const MPJ_VERSION = '4.0.0-alpha1';
|
|
|
|
|
|
|
|
(Dotenv::createImmutable(__DIR__))->load();
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
$auth0_session = Auth::client()->getCredentials();
|
|
|
|
if (!is_null($auth0_session)) {
|
|
|
|
$_SESSION['user_id'] = $auth0_session->user['sub'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
|
|
|
function page_link(string $href, string $text, array $attrs = []): void
|
2024-06-21 23:01:12 +00:00
|
|
|
{
|
|
|
|
echo '<a href="' . $href . '" hx-get="' . $href . '" hx-target="#top" hx-swap=innerHTML hx-push-url=true';
|
|
|
|
foreach ($attrs as $key => $value) echo " $key=\"" . htmlspecialchars($value) . "\"";
|
|
|
|
echo ">$text</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
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>';
|
|
|
|
}
|