<?php

declare(strict_types=1);

define('APP_NAME', 'TubePress');
define('APP_VERSION', '1.1.35');
define('APP_ROOT', dirname(__DIR__));

 
 
 
 
 
 
 
 
 
(static function (): void {
    $path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/';
    if (!preg_match('#^/(?:themes/[^/]+/assets/.+|templates/(?:admin|install)/.+)$#', $path)) {
        return;
    }
    if (preg_match('#\.(?:php|phtml|phar|json)$#i', $path)) {
        return;  
    }
    $full = realpath(APP_ROOT . '/' . ltrim($path, '/'));
    if ($full === false || !is_file($full)) {
        return;
    }
     
     
     
     
     
     
     
    $allowed = false;
    foreach ([APP_ROOT . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR,
              APP_ROOT . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR] as $allowedBase) {
        if (str_starts_with($full, $allowedBase)) { $allowed = true; break; }
    }
    if (!$allowed) {
        return;
    }
    static $types = [
        'css' => 'text/css', 'js' => 'application/javascript', 'mjs' => 'application/javascript',
        'map' => 'application/json', 'svg' => 'image/svg+xml', 'png' => 'image/png',
        'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'webp' => 'image/webp',
        'avif' => 'image/avif', 'ico' => 'image/x-icon', 'woff2' => 'font/woff2', 'woff' => 'font/woff',
        'ttf' => 'font/ttf', 'eot' => 'application/vnd.ms-fontobject', 'mp4' => 'video/mp4', 'webm' => 'video/webm',
    ];
    $ext = strtolower(pathinfo($full, PATHINFO_EXTENSION));
    header('Content-Type: ' . ($types[$ext] ?? 'application/octet-stream'));
    header('Content-Length: ' . filesize($full));
    header('Cache-Control: public, max-age=2592000');
    header('X-Content-Type-Options: nosniff');
    readfile($full);
    exit;
})();

 
 
if (!function_exists('mb_ucfirst')) {
    function mb_ucfirst(string $s, ?string $encoding = null): string
    {
        $encoding = $encoding ?? mb_internal_encoding();
        if ($s === '') return '';
        return mb_strtoupper(mb_substr($s, 0, 1, $encoding), $encoding) . mb_substr($s, 1, null, $encoding);
    }
}

require_once APP_ROOT . '/src/Core/App.php';

App::boot();

 
 
 
 
UpdateManager::ensureSchema();

function __(string $key, array $replacements = []): string
{
    return Translator::get($key, $replacements);
}

function url(string $path): string
{
    return Router::url($path);
}
