Files

83 lines
2.3 KiB
PHP

<?php
require_once __DIR__.'/lab.php';
$web_config = lab_config();
$debug_env = getenv('APP_DEBUG');
$debug_enabled = $debug_env === false
? false
: filter_var($debug_env, FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE);
if($debug_enabled === null)
$debug_enabled = false;
$error_reporting_level = $debug_enabled
? E_ALL
: (E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING);
error_reporting($error_reporting_level);
ini_set('display_errors', $debug_enabled ? 'on' : 'off');
// Handle JSON POST requests
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (strpos($contentType, 'application/json') !== false) {
$rawInput = file_get_contents('php://input');
if ($rawInput) {
$jsonData = json_decode($rawInput, true);
if (json_last_error() === JSON_ERROR_NONE && is_array($jsonData)) {
$_POST = array_merge($_POST, $jsonData);
$_REQUEST = array_merge($_REQUEST, $jsonData);
}
}
}
}
define('DATE_FORMAT', 'd.m.Y');
define('DATETIME_FORMAT', 'd.m.Y H:i');
define('DATE_FORMAT_ZULU', 'Ymd\THis\Z');
define('ONE_MINUTE', 60);
define('ONE_HOUR', 60*60);
define('ONE_DAY', 60*60*24);
define('ONE_MONTH', 60*60*24*30);
define('ONE_YEAR', 60*60*24*365);
$GLOBALS['config'] = array(
'debug' => array(
'enabled' => $debug_enabled,
'display_errors' => $debug_enabled,
'reporting' => $error_reporting_level,
),
'url' => array(
'root' => '',
'content-type' => 'html',
),
'theme' => array(
'key' => 'exoplasim',
'path' => 'themes/exoplasim/',
'mode' => 'dark',
'meta_description' => 'ExoPlaSim model workbench',
'theme_color' => '#0f172a',
),
'site' => array(
'name' => 'ExoPlaSim',
'default_page_title' => 'Home',
'include_paths' => ['views/', 'components/'],
'timezone' => 'UTC',
),
'track' => array(
'changes' => array(),
),
'menu' => array('' => array('title' => 'Home', 'hidden' => true)),
);
if(!$GLOBALS['config']['url']['root'])
{
$sroot = $_SERVER['SCRIPT_NAME'] ?? ($_SERVER['PHP_SELF'] ?? ($_SERVER['DOCUMENT_URI'] ?? ''));
if(substr($sroot, -9) == 'index.php')
$GLOBALS['config']['url']['root'] = substr($sroot, 0, -strlen('index.php'));
}
date_default_timezone_set($GLOBALS['config']['site']['timezone'] ?: 'UTC');