41 lines
1.7 KiB
PHP
41 lines
1.7 KiB
PHP
<?php
|
|
// partials/structure/app_config.php
|
|
// Gemeinsame Basisparameter für die Landingpages im Emailtemplate-Projekt.
|
|
|
|
if (!isset($layoutContext) || !is_array($layoutContext)) {
|
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
|
|
|
$layoutContext = [
|
|
'app_base_url' => rtrim($GLOBALS['app_base_url'] ?? ($scheme . '://' . $host), '/'),
|
|
'app_api_base' => rtrim($GLOBALS['app_api_base'] ?? ($scheme . '://' . $host . '/api'), '/'),
|
|
'asset_version' => defined('ASSET_VERSION') ? ASSET_VERSION : time(),
|
|
'app_env' => $GLOBALS['app_env'] ?? (defined('APP_ENV') ? APP_ENV : 'prod'),
|
|
];
|
|
|
|
$layoutContext['asset_base'] = $layoutContext['app_base_url'] ?: '';
|
|
$layoutContext['debug_redirect'] = isset($_GET['debug_redirect']);
|
|
$GLOBALS['layoutContext'] = $layoutContext;
|
|
}
|
|
|
|
$GLOBALS['layoutContext'] = $layoutContext;
|
|
|
|
$appBaseUrl = $layoutContext['app_base_url'];
|
|
$appApiBase = $layoutContext['app_api_base'];
|
|
$assetBase = $layoutContext['asset_base'];
|
|
$assetVersion = $layoutContext['asset_version'];
|
|
$debugRedirect = $layoutContext['debug_redirect'];
|
|
|
|
if (!function_exists('app_asset_url')) {
|
|
function app_asset_url(string $path, ?int $version = null): string
|
|
{
|
|
$base = $GLOBALS['layoutContext']['asset_base'] ?? '';
|
|
$version = $version ?? ($GLOBALS['layoutContext']['asset_version'] ?? null);
|
|
$url = rtrim($base, '/') . $path;
|
|
if ($version !== null) {
|
|
$url .= (strpos($url, '?') === false ? '?' : '&') . 'v=' . rawurlencode((string)$version);
|
|
}
|
|
return $url;
|
|
}
|
|
}
|