<?php
if (session_status() === PHP_SESSION_NONE) session_start();
define('ROOT_PATH', realpath(__DIR__ . '/../') . '/');
define('BASE_URL', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']);

define('DB_HOST', 'localhost');
define('DB_NAME', 'enovelcms');
define('DB_USER', 'enovelcms');
define('DB_PASS', 'wensha0624');
define('DB_CHARSET', 'utf8mb4');
$dirs = [ROOT_PATH . 'data', ROOT_PATH . 'data/chapters', ROOT_PATH . 'data/covers', ROOT_PATH . 'assets/uploads/ads', ROOT_PATH . 'assets/uploads/logo'];
foreach ($dirs as $dir) { if (!is_dir($dir)) mkdir($dir, 0755, true); }

spl_autoload_register(function ($class) {
    $base_dir = ROOT_PATH . 'includes/';
    $file = $base_dir . str_replace('\\', '/', $class) . '.php';
    if (file_exists($file)) { require $file; return true; }
    return false;
});

require_once ROOT_PATH . 'includes/functions.php';
$db = new Database();
$lang = new Language();
$GLOBALS['db'] = $db;
$GLOBALS['lang'] = $lang;
?>