Installe friendsofphp/php-cs-fixer en require-dev, configure le style PSR-12 avec guillemets simples et alignement des =>, et formate les fichiers PHP existants. Ajoute la config VS Codium pour le format on save. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.3 KiB
PHP
59 lines
2.3 KiB
PHP
<?php if (isset($file)): ?>
|
|
<?php
|
|
$alt = $alt ?? $file->alt() ?? '';
|
|
$lazy = $lazy ?? true;
|
|
$classAttr = isset($class) ? ' class="' . htmlspecialchars($class) . '"' : '';
|
|
$spanAttr = isset($span) ? ' style="--span: ' . htmlspecialchars($span) . ';"' : '';
|
|
?>
|
|
<?php if ($file->mime() === 'image/gif'): ?>
|
|
<picture<?= $classAttr ?><?= $spanAttr ?> data-id="<?= $file->uuid() ?>" orientation="<?= $file->orientation() ?>" data-mime="<?= $file->mime() ?>">
|
|
<img
|
|
src="<?= $file->url() ?>"
|
|
width="<?= $file->width() ?>"
|
|
height="<?= $file->height() ?>"
|
|
alt="<?= htmlspecialchars($alt) ?>"
|
|
loading="<?= $lazy ? 'lazy' : 'eager' ?>"
|
|
>
|
|
</picture>
|
|
<?php else: ?>
|
|
<?php
|
|
// Sizes : accepte soit une string complète ($sizes), soit un vw simple ($size)
|
|
if (isset($sizes)) {
|
|
$sizesAttr = $sizes;
|
|
} elseif (isset($size)) {
|
|
$sizesAttr = '(min-width: 1085px) ' . $size . 'vw, 100vw';
|
|
} else {
|
|
$sizesAttr = '(min-width: 1085px) 50vw, 100vw';
|
|
}
|
|
|
|
$srcsetName = $srcsetName ?? 'default';
|
|
$webpName = $srcsetName . '-webp';
|
|
$crop = $crop ?? false;
|
|
|
|
// Vérifie si un srcset webp nommé existe en config, sinon fallback sur 'webp'
|
|
$kirbyThumbs = kirby()->option('thumbs.srcsets', []);
|
|
$webpSrcset = isset($kirbyThumbs[$webpName])
|
|
? $file->srcset($webpName)
|
|
: $file->srcset('webp');
|
|
|
|
$srcset = $file->srcset($srcsetName);
|
|
$src = $file->url();
|
|
|
|
$resized = $file->resize(1800);
|
|
$width = $resized ? $resized->width() : $file->width();
|
|
$height = $resized ? $resized->height() : $file->height();
|
|
?>
|
|
<picture<?= $classAttr ?><?= $spanAttr ?> data-id="<?= $file->uuid() ?>" orientation="<?= $file->orientation() ?>" data-mime="<?= $file->mime() ?>">
|
|
<source srcset="<?= $webpSrcset ?>" sizes="<?= $sizesAttr ?>" type="image/webp">
|
|
<img
|
|
src="<?= $src ?>"
|
|
srcset="<?= $srcset ?>"
|
|
sizes="<?= $sizesAttr ?>"
|
|
width="<?= $width ?>"
|
|
height="<?= $height ?>"
|
|
alt="<?= htmlspecialchars($alt) ?>"
|
|
loading="<?= $lazy ? 'lazy' : 'eager' ?>"
|
|
>
|
|
</picture>
|
|
<?php endif ?>
|
|
<?php endif ?>
|