Show a dropzone (with drag and drop) while a slide has no image and a row with preview, replace and remove buttons otherwise. A newly chosen file is previewed right away. Placement is picked from tiles with a small sketch instead of long radio labels, technical details move into a collapsible help. The section gets full-width dividers, and the modal a slim scrollbar. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
123 lines
7.6 KiB
PHP
123 lines
7.6 KiB
PHP
<?php
|
||
/**
|
||
* Image section of the slide form: dropzone or current image (replace / remove), placement tiles.
|
||
* Works without JavaScript (label opens the file dialog, checkbox removes); JavaScript adds
|
||
* preview, drag and drop and the remove toggle. Not for slide types without image support (YouTube).
|
||
*
|
||
* @var \App\View\AppView $this
|
||
* @var \App\Model\Entity\Slide $slide
|
||
* @var \App\Model\Entity\Poll $poll
|
||
*/
|
||
|
||
use App\Model\Entity\Slide;
|
||
use App\Service\ImageService;
|
||
use Cake\Core\Configure;
|
||
|
||
if (!Slide::supportsImage($slide->type)) {
|
||
return;
|
||
}
|
||
$request = $this->getRequest();
|
||
$posted = $request->is(['post', 'put', 'patch']);
|
||
$hasImage = $slide->hasImage();
|
||
// After a failed save the posted values are shown again.
|
||
$layout = $posted && in_array($request->getData('image_layout'), Slide::IMAGE_LAYOUTS, true)
|
||
? (string)$request->getData('image_layout')
|
||
: $slide->imageLayout();
|
||
$layouts = [
|
||
Slide::IMAGE_TOP => [__('Oben'), '<rect class="img" x="4" y="3" width="40" height="13" rx="2"/><rect x="4" y="20" width="30" height="3" rx="1.5"/><rect x="4" y="26" width="22" height="3" rx="1.5"/>'],
|
||
Slide::IMAGE_SIDE => [__('Daneben'), '<rect class="img" x="4" y="3" width="18" height="26" rx="2"/><rect x="27" y="6" width="17" height="3" rx="1.5"/><rect x="27" y="12" width="13" height="3" rx="1.5"/><rect x="27" y="18" width="17" height="3" rx="1.5"/>'],
|
||
];
|
||
if ($slide->type === Slide::TYPE_CONTENT) {
|
||
$layouts[Slide::IMAGE_FULL] = [__('Vollbild'), '<rect class="img" x="4" y="3" width="40" height="26" rx="2"/>'];
|
||
}
|
||
$imageError = $slide->getError('image');
|
||
$maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024);
|
||
$imageUrl = $hasImage
|
||
? $this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image])
|
||
: '';
|
||
?>
|
||
<div class="image-section" data-image-fields<?= $hasImage ? ' data-has-image' : '' ?>>
|
||
<fieldset class="image-fields">
|
||
<legend><?= __('Bild') ?> <span class="image-fields__optional"><?= __('(optional)') ?></span></legend>
|
||
<?php if (!ImageService::isAvailable()) : ?>
|
||
<p class="hint"><?= __('Bilder sind auf diesem Server nicht verfügbar (PHP-Erweiterung GD mit WebP fehlt).') ?></p>
|
||
<?php else : ?>
|
||
<?php if ($imageError) : ?>
|
||
<div class="error-message" id="image-error" role="alert"><?= h(implode(' ', (array)$imageError)) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<?php // One file input for both states; the labels below open it, so it can stay visually hidden. ?>
|
||
<input type="file" id="image-file" name="image" class="sr-only" accept="image/jpeg,image/png,image/webp,image/gif"
|
||
aria-describedby="image-hint<?= $imageError ? ' image-error' : '' ?>" <?= $imageError ? 'aria-invalid="true"' : '' ?>>
|
||
|
||
<label class="image-drop" for="image-file" data-image-drop<?= $hasImage ? ' hidden' : '' ?>>
|
||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"
|
||
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="1.5"/><path d="M21 16l-5-5-8 9"/>
|
||
</svg>
|
||
<span class="image-drop__title"><?= __('Bild auswählen') ?><span data-image-drop-extra hidden> <?= __('oder hierher ziehen') ?></span></span>
|
||
<span class="image-drop__hint"><?= __('JPEG, PNG, WebP oder GIF, bis {0} MB', $maxMb) ?></span>
|
||
</label>
|
||
|
||
<div class="image-fields__row" data-image-row<?= $hasImage ? '' : ' hidden' ?>>
|
||
<figure class="image-fields__current" data-image-figure>
|
||
<img src="<?= h($imageUrl) ?>" alt="" data-image-original="<?= h($imageUrl) ?>"
|
||
<?= $hasImage ? 'width="' . (int)$slide->image_width . '" height="' . (int)$slide->image_height . '"' : '' ?>>
|
||
</figure>
|
||
<div class="image-fields__side">
|
||
<p class="image-fields__info" role="status" aria-live="polite" data-image-info
|
||
data-text-current="<?= h(__('Aktuelles Bild')) ?><?= $hasImage ? h(' · ' . __('{0} × {1} Pixel', (int)$slide->image_width, (int)$slide->image_height)) : '' ?>"
|
||
data-text-new="<?= h(__('Neues Bild wird beim Speichern übernommen:')) ?>"
|
||
data-text-removed="<?= h(__('Das Bild wird beim Speichern entfernt.')) ?>"><?= $hasImage ? h(__('Aktuelles Bild') . ' · ' . __('{0} × {1} Pixel', (int)$slide->image_width, (int)$slide->image_height)) : '' ?></p>
|
||
<div class="image-fields__buttons">
|
||
<label class="button button--small" for="image-file" data-image-pick
|
||
data-label-replace="<?= h(__('Ersetzen')) ?>" data-label-choose="<?= h(__('Anderes Bild wählen')) ?>"><?= __('Ersetzen') ?></label>
|
||
<?php if ($hasImage) : ?>
|
||
<?php // Without JavaScript the checkbox does the job; with it, the button toggles the same checkbox. ?>
|
||
<div class="image-fields__remove" data-image-remove>
|
||
<?= $this->Form->control('remove_image', [
|
||
'type' => 'checkbox',
|
||
'label' => __('Bild entfernen'),
|
||
'value' => '1',
|
||
'hiddenField' => false,
|
||
'checked' => false,
|
||
]) ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<button type="button" class="button button--danger button--small" hidden data-image-remove-button
|
||
data-label-remove="<?= h(__('Entfernen')) ?>" data-label-undo="<?= h(__('Rückgängig')) ?>"
|
||
data-label-discard="<?= h(__('Auswahl verwerfen')) ?>">
|
||
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||
<path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14M10 11v5M14 11v5"/>
|
||
</svg>
|
||
<span data-label><?= __('Entfernen') ?></span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="image-fields__help" id="image-hint">
|
||
<details>
|
||
<summary><?= __('Was passiert mit dem Bild?') ?></summary>
|
||
<p class="hint"><?= __('JPEG, PNG, WebP oder GIF (nicht animiert), bis {0} MB. Das Bild wird automatisch auf höchstens 1600 Pixel verkleinert und als WebP gespeichert, Kameradaten wie der Aufnahmeort werden dabei entfernt.', $maxMb) ?></p>
|
||
</details>
|
||
</div>
|
||
|
||
<fieldset class="image-layout" data-image-layout>
|
||
<legend><?= __('Platzierung in der Präsentation') ?></legend>
|
||
<div class="image-layout__tiles">
|
||
<?php foreach ($layouts as $value => [$text, $shapes]) : ?>
|
||
<label class="image-layout__tile">
|
||
<input type="radio" name="image_layout" value="<?= h($value) ?>" class="sr-only" <?= $layout === $value ? 'checked' : '' ?>>
|
||
<svg viewBox="0 0 48 32" width="72" height="48" fill="currentColor" aria-hidden="true"><?= $shapes ?></svg>
|
||
<span><?= h($text) ?></span>
|
||
</label>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<p class="hint"><?= __('Auf dem Smartphone der Teilnehmenden steht das Bild immer oben.') ?></p>
|
||
</fieldset>
|
||
<?php endif; ?>
|
||
</fieldset>
|
||
</div>
|