94aea8501f
Changed: [app/View.php](/Users/tyemeclifford/Documents/GH/blog/app/View.php): generated URLs now honor a base path like /blog. [app/Config.php](/Users/tyemeclifford/Documents/GH/blog/app/Config.php): added base_path support and derives it from base_url or SCRIPT_NAME. [app/App.php](/Users/tyemeclifford/Documents/GH/blog/app/App.php): route parsing strips the base path, and PHP can safely serve theme/upload assets for virtual subdirectory previews. [.htaccess](/Users/tyemeclifford/Documents/GH/blog/.htaccess): removed hardcoded RewriteBase /. [themes/neon/layout.php](/Users/tyemeclifford/Documents/GH/blog/themes/neon/layout.php): root-relative social links like /feed.xml now become /blog/feed.xml. [README.md](/Users/tyemeclifford/Documents/GH/blog/README.md): documented subdirectory setup.
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use NeonBlog\App;
|
|
use NeonBlog\CommentService;
|
|
use NeonBlog\Config;
|
|
use NeonBlog\ContentRepository;
|
|
use NeonBlog\Database;
|
|
use NeonBlog\Stats;
|
|
|
|
define('BLOG_ROOT', dirname(__DIR__));
|
|
|
|
spl_autoload_register(static function (string $class): void {
|
|
$prefix = 'NeonBlog\\';
|
|
if (strncmp($class, $prefix, strlen($prefix)) !== 0) {
|
|
return;
|
|
}
|
|
|
|
$relative = substr($class, strlen($prefix));
|
|
$path = BLOG_ROOT . '/app/' . str_replace('\\', '/', $relative) . '.php';
|
|
if (is_file($path)) {
|
|
require $path;
|
|
}
|
|
});
|
|
|
|
$isPublicAssetRequest = static function (): bool {
|
|
$path = (string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? ''), PHP_URL_PATH);
|
|
$route = (string) ($_GET['route'] ?? '');
|
|
|
|
return (bool) preg_match('#/(themes/[a-z0-9_-]+/assets/.+|bl-content/uploads/.+)$#', $path)
|
|
|| (bool) preg_match('#^(themes/[a-z0-9_-]+/assets/.+|bl-content/uploads/.+)$#', $route);
|
|
};
|
|
|
|
if (PHP_SAPI !== 'cli' && session_status() !== PHP_SESSION_ACTIVE && !$isPublicAssetRequest()) {
|
|
session_start([
|
|
'cookie_httponly' => true,
|
|
'cookie_samesite' => 'Lax',
|
|
]);
|
|
}
|
|
|
|
$config = Config::load(BLOG_ROOT . '/config/site.json');
|
|
date_default_timezone_set((string) $config->get('timezone', 'UTC'));
|
|
|
|
$repository = new ContentRepository(
|
|
BLOG_ROOT . '/bl-content/pages',
|
|
BLOG_ROOT . '/bl-content/databases/pages.json'
|
|
);
|
|
|
|
$pdo = Database::connect(BLOG_ROOT . '/storage/database/blog.sqlite');
|
|
$comments = new CommentService($pdo, $config);
|
|
$stats = new Stats(BLOG_ROOT . '/storage/stats/visits.csv', $config);
|
|
|
|
return new App($config, $repository, $comments, $stats);
|