Add optional images to slides
Slides (except YouTube) can carry one image. Uploads are validated, rotated by EXIF orientation, scaled to 1600 px and stored as WebP outside webroot, which also strips camera metadata. Images have an alt text (or are marked decorative) and a layout: top, side or full screen (content slides). Files are removed after the commit when a slide is deleted or its image is replaced, with the poll, and `bin/cake images_cleanup` sweeps leftovers. Duplicated slides get their own file. Docker image gains gd with WebP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c7818ee40
commit
a395b50894
30 files changed
+1705
-11
No files matched your search
@@ -87,6 +87,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
|
||||
<div class="slide-item__meta">
|
||||
<span class="badge badge--type-<?= h($slide->type) ?>"><?= h($slide->typeLabel()) ?></span>
|
||||
<?php if ($isCurrent) : ?><span class="badge badge--live"><?= __('live') ?></span><?php endif; ?>
|
||||
<?php if ($slide->hasImage()) : ?><span class="badge" title="<?= h(__('Die Folie hat ein Bild')) ?>">🖼 <?= __('Bild') ?></span><?php endif; ?>
|
||||
<?php if ($slide->is_hidden) : ?><span class="badge badge--off" title="<?= __('Wird beim Präsentieren übersprungen und fehlt im PDF-Export') ?>"><?= __('ausgeblendet') ?></span><?php endif; ?>
|
||||
<?php if ($slide->isInteractive()) : ?>
|
||||
<span class="muted"><?= __n('{0} Antwort', '{0} Antworten', $count, $count) ?></span>
|
||||
|
||||
@@ -38,6 +38,7 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
|
||||
<h1 class="stage__question" data-question><?= __('Lade …') ?></h1>
|
||||
<div class="stage__description formatted" data-description></div>
|
||||
<div class="stage__media" data-media hidden></div>
|
||||
<figure class="stage__image" data-image hidden></figure>
|
||||
<div class="stage__results" data-results></div>
|
||||
</main>
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
|
||||
<h1 class="stage__question" data-question><?= h($slide->question) ?></h1>
|
||||
<div class="stage__description formatted" data-description></div>
|
||||
<div class="stage__media" data-media hidden></div>
|
||||
<figure class="stage__image" data-image hidden></figure>
|
||||
<div class="stage__results" data-results></div>
|
||||
</main>
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ $countdown = function (?int $remaining): string {
|
||||
<?php if ($slide->description) : ?>
|
||||
<div class="prose formatted"><?= $this->Format->text($slide->description) ?></div>
|
||||
<?php endif; ?>
|
||||
<?= $this->element('slide_image', compact('slide', 'poll')) ?>
|
||||
</section>
|
||||
|
||||
<?php else : ?>
|
||||
@@ -118,6 +119,7 @@ $countdown = function (?int $remaining): string {
|
||||
<?php if ($slide->description) : ?>
|
||||
<div class="muted formatted"><?= $this->Format->text($slide->description) ?></div>
|
||||
<?php endif; ?>
|
||||
<?= $this->element('slide_image', compact('slide', 'poll')) ?>
|
||||
|
||||
<?php if ($quiz !== null) : ?>
|
||||
<?php if ($quiz['phase'] === 'ready') : ?>
|
||||
|
||||
@@ -31,7 +31,7 @@ $optionsError = $slide->getError('options_text');
|
||||
<p class="eyebrow"><?= h($slide->typeLabel()) ?></p>
|
||||
<h1 id="modal-title"><?= $isNew ? __('Neue Folie') : __('Folie bearbeiten') ?></h1>
|
||||
|
||||
<?= $this->Form->create($slide, ['url' => $formUrl]) ?>
|
||||
<?= $this->Form->create($slide, ['url' => $formUrl, 'type' => 'file']) ?>
|
||||
<?= $this->Form->hidden('type') ?>
|
||||
<?php if ($slide->isYouTube()) :
|
||||
$urlError = $slide->getError('youtube_url');
|
||||
@@ -116,6 +116,8 @@ $optionsError = $slide->getError('options_text');
|
||||
]) ?>
|
||||
<p class="hint" id="description-format"><?= __('Formatierung wie bei WhatsApp: *fett*, _kursiv_, ~durchgestrichen~, Aufzählung mit „- “ am Zeilenanfang.') ?></p>
|
||||
|
||||
<?= $this->element('slide_image_fields', compact('slide', 'poll')) ?>
|
||||
|
||||
<?php if ($slide->type === 'choice') : ?>
|
||||
<div class="input textarea<?= $optionsError ? ' error' : '' ?>">
|
||||
<label for="options-text"><?= __('Antwortoptionen (eine pro Zeile, max. 20)') ?></label>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* The image of a slide on the participant's page (always above the content, whatever the stage layout).
|
||||
* Width and height reserve the space, so the page does not jump while the image loads.
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
* @var \App\Model\Entity\Slide $slide
|
||||
* @var \App\Model\Entity\Poll $poll
|
||||
*/
|
||||
if (!$slide->hasImage()) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<figure class="slide-image">
|
||||
<img src="<?= h($this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image])) ?>"
|
||||
alt="<?= h((string)$slide->image_alt) ?>"
|
||||
<?= $slide->image_width && $slide->image_height ? 'width="' . (int)$slide->image_width . '" height="' . (int)$slide->image_height . '"' : '' ?>
|
||||
decoding="async">
|
||||
</figure>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Image fields of the slide form: upload, alternative text, layout, remove.
|
||||
* 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.
|
||||
$alt = $posted ? (string)$request->getData('image_alt', '') : (string)$slide->image_alt;
|
||||
$decorative = $posted
|
||||
? filter_var($request->getData('image_decorative'), FILTER_VALIDATE_BOOLEAN)
|
||||
: ($hasImage && $slide->image_alt === '');
|
||||
$layout = $posted && in_array($request->getData('image_layout'), Slide::IMAGE_LAYOUTS, true)
|
||||
? (string)$request->getData('image_layout')
|
||||
: $slide->imageLayout();
|
||||
$layouts = [
|
||||
Slide::IMAGE_TOP => __('Oben (über den Antworten bzw. Ergebnissen)'),
|
||||
Slide::IMAGE_SIDE => __('Daneben (Bild links, Text und Ergebnis rechts)'),
|
||||
];
|
||||
if ($slide->type === Slide::TYPE_CONTENT) {
|
||||
$layouts[Slide::IMAGE_FULL] = __('Bildschirm füllen (Bild so groß wie möglich)');
|
||||
}
|
||||
$imageError = $slide->getError('image');
|
||||
$altError = $slide->getError('image_alt');
|
||||
$maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024);
|
||||
?>
|
||||
<fieldset class="image-fields" data-image-fields>
|
||||
<legend><?= __('Bild (optional)') ?></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 ($hasImage) : ?>
|
||||
<figure class="image-fields__current">
|
||||
<img src="<?= h($this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image])) ?>"
|
||||
alt="<?= h((string)$slide->image_alt) ?>" width="<?= (int)$slide->image_width ?>" height="<?= (int)$slide->image_height ?>">
|
||||
</figure>
|
||||
<?= $this->Form->control('remove_image', [
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Bild entfernen'),
|
||||
'value' => '1',
|
||||
'hiddenField' => false,
|
||||
'checked' => false,
|
||||
]) ?>
|
||||
<?php endif; ?>
|
||||
<div class="input file<?= $imageError ? ' error' : '' ?>">
|
||||
<label for="image-file"><?= $hasImage ? __('Anderes Bild hochladen') : __('Bild hochladen') ?></label>
|
||||
<input type="file" id="image-file" name="image" accept="image/jpeg,image/png,image/webp,image/gif"
|
||||
aria-describedby="image-hint<?= $imageError ? ' image-error' : '' ?>" <?= $imageError ? 'aria-invalid="true"' : '' ?>>
|
||||
<p class="hint" id="image-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>
|
||||
<?php if ($imageError) : ?>
|
||||
<div class="error-message" id="image-error"><?= h(implode(' ', (array)$imageError)) ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="input text<?= $altError ? ' error' : '' ?>">
|
||||
<label for="image-alt"><?= __('Bildbeschreibung (für Screenreader)') ?></label>
|
||||
<input type="text" id="image-alt" name="image_alt" maxlength="<?= Slide::IMAGE_ALT_MAX ?>" autocomplete="off"
|
||||
value="<?= h($alt) ?>" placeholder="<?= h(__('z. B. Organigramm des Vereins')) ?>"
|
||||
aria-describedby="image-alt-hint<?= $altError ? ' image-alt-error' : '' ?>" <?= $altError ? 'aria-invalid="true"' : '' ?>>
|
||||
<p class="hint" id="image-alt-hint"><?= __('Pflicht, sobald ein Bild gesetzt ist – oder das Bild ist reine Dekoration.') ?></p>
|
||||
<?php if ($altError) : ?>
|
||||
<div class="error-message" id="image-alt-error"><?= h(implode(' ', (array)$altError)) ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?= $this->Form->control('image_decorative', [
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Reine Dekoration (keine Beschreibung nötig)'),
|
||||
'value' => '1',
|
||||
'hiddenField' => false,
|
||||
'checked' => $decorative,
|
||||
]) ?>
|
||||
<fieldset class="scale-style image-fields__layout">
|
||||
<legend><?= __('Platzierung in der Präsentation') ?></legend>
|
||||
<?= $this->Form->radio('image_layout', array_map(
|
||||
fn($value, $text) => ['value' => $value, 'text' => $text],
|
||||
array_keys($layouts),
|
||||
$layouts,
|
||||
), ['value' => $layout]) ?>
|
||||
<p class="hint"><?= __('Auf dem Smartphone der Teilnehmenden steht das Bild immer oben.') ?></p>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
Reference in new issue
Block a user