доставка в плавающем
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user