доставка в плавающем

This commit is contained in:
Alisa
2026-06-08 10:58:47 +03:00
parent 3a065b34d6
commit 256afcbb80
18 changed files with 1478 additions and 187 deletions
+38
View File
@@ -36,6 +36,44 @@ function versioned_asset(string $path): string
return $assetPath . $querySeparator . filemtime($publicPath);
}
function public_asset_exists(string $path): bool
{
$assetPath = '/' . ltrim(strtok($path, '?') ?: $path, '/');
return is_file(base_path('public' . $assetPath));
}
function optimized_image_path(?string $path, string $mode = 'preview'): string
{
$assetPath = trim((string) $path);
if ($assetPath === '' || !str_starts_with($assetPath, '/assets/uploads/old/products/')) {
return $assetPath;
}
$assetPath = '/' . ltrim(strtok($assetPath, '?') ?: $assetPath, '/');
$directory = rtrim(str_replace('\\', '/', dirname($assetPath)), '/');
$filename = basename($assetPath);
$isFull = str_starts_with($filename, 'full_');
$baseFilename = $isFull ? substr($filename, 5) : $filename;
$candidates = $mode === 'detail'
? [$baseFilename, 'thumb_' . $baseFilename]
: ['thumb_' . $baseFilename, $baseFilename];
foreach ($candidates as $candidate) {
if ($candidate === '' || $candidate === $filename) {
continue;
}
$candidatePath = $directory . '/' . $candidate;
if (public_asset_exists($candidatePath)) {
return $candidatePath;
}
}
return $assetPath;
}
function view(string $template, array $data = []): void
{
View::render($template, $data);