62 lines
3.2 KiB
PHP
62 lines
3.2 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/i18n.php';
|
|
require_once __DIR__ . '/components/asset-url.php';
|
|
require_once __DIR__ . '/components/site-domain.php';
|
|
require_once __DIR__ . '/components/theme-preference.php';
|
|
require_once __DIR__ . '/components/utm-codec.php';
|
|
|
|
$configFile = __DIR__ . '/config.json';
|
|
$config = file_exists($configFile) ? json_decode(file_get_contents($configFile), true) : [];
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
throw new RuntimeException('JSON syntax error: ' . json_last_error_msg());
|
|
}
|
|
|
|
Yii::init($config['default_language'] ?? 'ru');
|
|
$config = prelandNumericUtmConfig($config);
|
|
$resolvedUtm = prelandResolveUtm($_GET, $config);
|
|
$UTM = $resolvedUtm['context'];
|
|
$get_params = array_diff_key($_GET, array_fill_keys(['indpic','theme','degr','reg','banch','tp','cons','focus','part','registration','bchoice','chob','chb','key','azv'], true));
|
|
// Числа — внутренний snapshot для recovery. Публичная оболочка создаётся при навигации.
|
|
$redirect_digits = $resolvedUtm['digits'];
|
|
$themeInitial = prelandThemeResolve(($UTM['theme'] ?? 'light') === 'dark' ? 'dark' : 'light');
|
|
$themeSurface = 'preland';
|
|
$host = $config['host'] ?? ($_SERVER['HTTP_HOST'] ?? '');
|
|
$apiHost = $host ? (preg_match('#^https?://#', $host) ? rtrim($host, '/') : 'https://' . rtrim($host, '/')) : '';
|
|
|
|
// После загрузки — на сайт по ключу загрузки (client_key): /api/images/public/claim кладёт её в сессию посетителя и ведёт
|
|
// на /public/upscale. Сразу на /public/upscale нельзя: сессия кросс-доменной загрузки посетителю на сайте недоступна — 404.
|
|
$redirect_url_base = ($apiHost ? $apiHost : '') . '/api/images/public/claim?key=';
|
|
// свою метку key — нет: её значение перебило бы ключ загрузки в адресе claim
|
|
$redirect_url_utm = http_build_query(array_diff_key($get_params, ['key' => true]));
|
|
|
|
$assetsUriPrefix = $config['assetsUriPrefix'] ?? '';
|
|
if ($assetsUriPrefix === '' && !is_dir(__DIR__ . '/images') && !empty($apiHost)) {
|
|
$assetsUriPrefix = $apiHost;
|
|
}
|
|
|
|
$fontsUrl = $config['fontsUrl'] ?? ($assetsUriPrefix ? $assetsUriPrefix . '/fonts' : 'fonts');
|
|
$favicon = (object)[
|
|
'baseUrl' => $config['faviconUrl'] ?? ($assetsUriPrefix ? $assetsUriPrefix . '/favicon' : 'favicon')
|
|
];
|
|
$logoAltExt = $config['logoAltExt'] ?? 'svg';
|
|
$spritePath = $config['spritePath'] ?? ($assetsUriPrefix ? $assetsUriPrefix . '/images/sprite.svg' : 'images/sprite.svg');
|
|
$default_title = $config['title'] ?? 'Улучшение изображения';
|
|
|
|
$indpic = isset($UTM['indpic']) && preg_match('/^[a-zA-Z0-9_-]+$/', (string)$UTM['indpic'])
|
|
? (string)$UTM['indpic']
|
|
: ($config['utm']['indpic']['default'] ?? '2');
|
|
|
|
function renderComponent(string $name, array $params = []): void
|
|
{
|
|
global $redirect_digits, $assetsUriPrefix, $fontsUrl, $favicon, $logoAltExt, $spritePath, $UTM, $config, $indpic, $apiHost, $redirect_url_base, $redirect_url_utm;
|
|
extract($params, EXTR_SKIP);
|
|
$componentFile = __DIR__ . '/components/' . $name . '.php';
|
|
if (file_exists($componentFile)) {
|
|
require $componentFile;
|
|
}
|
|
}
|
|
|
|
require_once __DIR__ . '/template.php';
|