Files
AudioCore/public/index.php
2026-03-04 20:46:11 +00:00

87 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../core/bootstrap.php';
$uriPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
$uriPath = is_string($uriPath) && $uriPath !== '' ? $uriPath : '/';
$isAdminRoute = str_starts_with($uriPath, '/admin');
$maintenanceWhitelist = [
'/support/imap-sync',
];
if (
Core\Services\Settings::get('site_maintenance_enabled', '0') === '1'
&& !Core\Services\Auth::check()
&& !$isAdminRoute
&& !in_array($uriPath, $maintenanceWhitelist, true)
) {
$title = Core\Services\Settings::get('site_maintenance_title', 'Coming Soon');
$message = Core\Services\Settings::get('site_maintenance_message', 'We are currently updating the site. Please check back soon.');
$buttonLabel = Core\Services\Settings::get('site_maintenance_button_label', '');
$buttonUrl = Core\Services\Settings::get('site_maintenance_button_url', '');
$customHtml = Core\Services\Settings::get('site_maintenance_html', '');
$siteTitle = Core\Services\Settings::get('site_title', 'AudioCore V1.5');
$contentHtml = '';
if ($customHtml !== '') {
$contentHtml = $customHtml;
} else {
$contentHtml = '<div class="ac-maintenance-wrap">'
. '<div class="ac-maintenance-badge">Maintenance Mode</div>'
. '<h1>' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</h1>'
. '<p>' . nl2br(htmlspecialchars($message, ENT_QUOTES, 'UTF-8')) . '</p>';
if ($buttonLabel !== '' && $buttonUrl !== '') {
$contentHtml .= '<a class="ac-maintenance-btn" href="' . htmlspecialchars($buttonUrl, ENT_QUOTES, 'UTF-8') . '">'
. htmlspecialchars($buttonLabel, ENT_QUOTES, 'UTF-8')
. '</a>';
}
$contentHtml .= '</div>';
}
$maintenanceHtml = '<!doctype html><html lang="en"><head><meta charset="utf-8">'
. '<meta name="viewport" content="width=device-width, initial-scale=1">'
. '<title>' . htmlspecialchars($siteTitle, ENT_QUOTES, 'UTF-8') . '</title>'
. '<style>'
. 'body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px;background:linear-gradient(180deg,#131419,#0f1014);color:#eef2ff;font-family:Syne,system-ui,sans-serif;}'
. '.ac-maintenance-wrap{max-width:780px;width:100%;padding:36px;border-radius:22px;border:1px solid rgba(255,255,255,.12);background:rgba(21,23,30,.86);box-shadow:0 20px 60px rgba(0,0,0,.35);}'
. '.ac-maintenance-badge{font-family:IBM Plex Mono,monospace;text-transform:uppercase;font-size:11px;letter-spacing:.24em;color:rgba(255,255,255,.6);}'
. 'h1{font-size:42px;line-height:1.08;margin:14px 0 0;}'
. 'p{font-size:18px;line-height:1.7;margin:16px 0 0;color:rgba(235,241,255,.8);}'
. '.ac-maintenance-btn{margin-top:20px;display:inline-block;padding:10px 18px;border-radius:999px;border:1px solid rgba(255,255,255,.2);color:#f7f8ff;text-decoration:none;font-size:12px;text-transform:uppercase;letter-spacing:.18em;}'
. '.ac-maintenance-btn:hover{background:rgba(255,255,255,.08);}'
. '</style></head><body>' . $contentHtml . '</body></html>';
(new Core\Http\Response($maintenanceHtml, 503, ['Content-Type' => 'text/html; charset=utf-8']))->send();
exit;
}
$router = new Core\Http\Router();
$router->get('/', function (): Core\Http\Response {
$db = Core\Services\Database::get();
if ($db instanceof PDO) {
$stmt = $db->prepare("SELECT title, content_html FROM ac_pages WHERE is_home = 1 AND is_published = 1 LIMIT 1");
$stmt->execute();
$page = $stmt->fetch(PDO::FETCH_ASSOC);
if ($page) {
$view = new Core\Views\View(__DIR__ . '/../modules/pages/views');
return new Core\Http\Response($view->render('site/show.php', [
'title' => (string)$page['title'],
'content_html' => Core\Services\Shortcodes::render((string)$page['content_html'], [
'page_slug' => 'home',
'page_title' => (string)$page['title'],
]),
]));
}
}
$view = new Core\Views\View(__DIR__ . '/../views');
return new Core\Http\Response($view->render('site/home.php', [
'title' => 'AudioCore V1.5',
]));
});
$router->registerModules(__DIR__ . '/../modules');
Core\Services\Plugins::register($router);
$response = $router->dispatch($_SERVER['REQUEST_URI'] ?? '/', $_SERVER['REQUEST_METHOD'] ?? 'GET');
$response->send();