Pick the site icon from the library and crop it, find legal pages by search, list newest first
- The site icon is no longer a select at the end of the company data. It has its own section: a button opens the media library (upload included), then a square is dragged, resized by its corner, a slider or +/-, and previewed at 180 and 32 px. The crop is stored as fractions (faviconCrop) and the PNGs are cut from it; faviconVersion changes the link so browsers pick up a new cut. Icons without a crop keep their old link. - openMedia() takes needsAlt: false, since the icon never appears as content. The dialog styles moved from editor.css to media-dialog.css so the dialog works outside the editor. - Privacy page and imprint are chosen with the content search, like the 404 page. The picker can store the path instead of the id (valueKey/data-value). - The page and post lists in the administration sort newest first; the subpage indentation is gone there, as it would point at the wrong parent. Tests: 581 PHPUnit, 35 node, test:editor green (the consent step now picks the privacy page by search). test:admin --admin-only fails only at the known nested-interactive menu summaries. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6632836580
commit
106f84dfd5
19 files changed
+300
-69
No files matched your search
@@ -222,11 +222,16 @@ final class MediaLibrary
|
||||
* Erzeugt aus einem Bild der Mediathek die Symboldateien der Website.
|
||||
*
|
||||
* Ein Favicon ist quadratisch, winzig und wird von den Browsern bis heute am zuverlässigsten
|
||||
* als PNG gelesen - deshalb hier PNG statt der WebP-Varianten und ein mittiger quadratischer
|
||||
* als PNG gelesen - deshalb hier PNG statt der WebP-Varianten und ein quadratischer
|
||||
* Ausschnitt statt eines gestauchten Bildes. Erzeugt wird einmal beim Speichern der
|
||||
* Einstellung, nicht bei jedem Aufruf.
|
||||
*
|
||||
* $crop ist der im Zuschnitt gewählte Ausschnitt als [links, oben, Kante]: links und oben als
|
||||
* Anteil von Breite und Höhe, die Kante als Anteil der kürzeren Seite. Ohne Angabe die Mitte.
|
||||
*
|
||||
* @param array{0: float, 1: float, 2: float}|null $crop
|
||||
*/
|
||||
public function renderFavicon(string $mediaId): void
|
||||
public function renderFavicon(string $mediaId, ?array $crop = null): void
|
||||
{
|
||||
// Ueber die Varianten, die dieses Bild tatsaechlich hat, nicht ueber die vier Regelbreiten:
|
||||
// ein 192 px breites Zeichen hat genau eine Variante mit 192 - und die Suche nach 480
|
||||
@@ -244,10 +249,18 @@ final class MediaLibrary
|
||||
throw new \RuntimeException('Das Bild für das Symbol konnte nicht gelesen werden.');
|
||||
}
|
||||
try {
|
||||
// Mittiger quadratischer Ausschnitt: ein breites Logo würde sonst zur Briefmarke.
|
||||
$kante = min(imagesx($source), imagesy($source));
|
||||
$links = (int) ((imagesx($source) - $kante) / 2);
|
||||
$oben = (int) ((imagesy($source) - $kante) / 2);
|
||||
// Quadratischer Ausschnitt: ein breites Logo würde sonst zur Briefmarke. Die Anteile
|
||||
// gelten für jede Variante gleich; gerechnet wird in der größten, die es gibt.
|
||||
$breite = imagesx($source);
|
||||
$hoehe = imagesy($source);
|
||||
$kante = min($breite, $hoehe);
|
||||
$links = (int) (($breite - $kante) / 2);
|
||||
$oben = (int) (($hoehe - $kante) / 2);
|
||||
if (null !== $crop) {
|
||||
$kante = max(1, min($kante, (int) round($crop[2] * min($breite, $hoehe))));
|
||||
$links = max(0, min($breite - $kante, (int) round($crop[0] * $breite)));
|
||||
$oben = max(0, min($hoehe - $kante, (int) round($crop[1] * $hoehe)));
|
||||
}
|
||||
foreach (self::FAVICON_SIZES as $size) {
|
||||
$target = imagecreatetruecolor($size, $size);
|
||||
try {
|
||||
|
||||
@@ -459,8 +459,9 @@ final class PageRepository
|
||||
$total = (int) (clone $qb)->select('COUNT(*)')->executeQuery()->fetchOne();
|
||||
$pages = max(1, (int) ceil($total / $limit));
|
||||
$page = max(1, min($pages, $page));
|
||||
$items = $qb->select('p.*', 'r.document')->orderBy('post' === $type ? 'p.created_at' : 'p.path', 'post' === $type ? 'DESC' : 'ASC')
|
||||
->addOrderBy('p.id')->setFirstResult(($page - 1) * $limit)->setMaxResults($limit)->executeQuery()->fetchAllAssociative();
|
||||
$items = $qb->select('p.*', 'r.document')->orderBy('p.created_at', 'DESC')
|
||||
// Neueste zuerst, bei Seiten wie bei Beiträgen (Umut: „absteigend also neueste zuerst“).
|
||||
->addOrderBy('p.id', 'DESC')->setFirstResult(($page - 1) * $limit)->setMaxResults($limit)->executeQuery()->fetchAllAssociative();
|
||||
|
||||
return ['items' => $items, 'total' => $total, 'page' => $page, 'pages' => $pages, 'limit' => $limit];
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ final class SiteSettings
|
||||
// Das Symbol der Website im Browser-Reiter: ein Bild aus der Mediathek, aus dem beim
|
||||
// Speichern quadratische PNG-Dateien entstehen. Leer heißt: das mitgelieferte Zeichen.
|
||||
'faviconMediaId' => '',
|
||||
// Der Zuschnitt dazu als "links,oben,kante" in Anteilen, leer heißt: die Mitte. Die Version
|
||||
// hängt am Verweis, damit ein neuer Ausschnitt im Browser ankommt.
|
||||
'faviconCrop' => '',
|
||||
'faviconVersion' => '',
|
||||
// Der Knopf „nach oben". Aus, weil eine kurze Seite ihn nicht braucht; alles daran ist
|
||||
// einstellbar, weil er auf jeder Seite in der Ecke klebt und deshalb zur Gestaltung
|
||||
// passen muss. Eingeblendet wird er beim Scrollen - ohne eine Zeile JavaScript.
|
||||
@@ -229,6 +233,14 @@ final class SiteSettings
|
||||
$values['stickyHeader'] = (bool) ($input['stickyHeader'] ?? false);
|
||||
$values['headerOverlay'] = (bool) ($input['headerOverlay'] ?? false);
|
||||
$favicon = trim((string) ($input['faviconMediaId'] ?? ''));
|
||||
$crop = '' === $favicon ? '' : trim((string) ($input['faviconCrop'] ?? ''));
|
||||
$anteile = null;
|
||||
if ('' !== $crop) {
|
||||
$anteile = array_map('floatval', explode(',', $crop));
|
||||
if (1 !== preg_match('/^[01](?:\.\d{1,6})?,[01](?:\.\d{1,6})?,[01](?:\.\d{1,6})?$/D', $crop) || max($anteile) > 1 || $anteile[2] < 0.02) {
|
||||
throw new InvalidPage('Der Ausschnitt für das Symbol ist ungültig. Bitte das Bild neu zuschneiden.');
|
||||
}
|
||||
}
|
||||
if ('' !== $favicon) {
|
||||
if (1 !== preg_match('/^[a-f0-9]{32}$/D', $favicon) || null === $this->media->find($favicon)) {
|
||||
throw new InvalidPage('Das gewählte Symbolbild gibt es nicht (mehr).');
|
||||
@@ -237,12 +249,15 @@ final class SiteSettings
|
||||
// die Einstellung gar nicht erst gespeichert - ein Verweis auf ein fehlendes Symbol
|
||||
// wäre schlimmer als das alte Symbol.
|
||||
try {
|
||||
$this->media->renderFavicon($favicon);
|
||||
$this->media->renderFavicon($favicon, $anteile);
|
||||
} catch (\RuntimeException $error) {
|
||||
throw new InvalidPage('Aus diesem Bild konnte kein Symbol erzeugt werden: '.$error->getMessage());
|
||||
}
|
||||
}
|
||||
$values['faviconMediaId'] = $favicon;
|
||||
$values['faviconCrop'] = $crop;
|
||||
// Ohne Zuschnitt die Kennung wie bisher, damit bestehende Verweise gleich bleiben.
|
||||
$values['faviconVersion'] = '' === $favicon ? '' : ('' === $crop ? substr($favicon, 0, 8) : substr(md5($favicon.'|'.$crop), 0, 8));
|
||||
foreach (['turnstileSiteKey' => 100, 'turnstileSecret' => 100] as $key => $max) {
|
||||
$wert = trim((string) ($input[$key] ?? ''));
|
||||
if ('' !== $wert && 1 !== preg_match('/^[A-Za-z0-9_:.-]{8,'.$max.'}$/D', $wert)) {
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Controller;
|
||||
|
||||
use App\Content\Consent;
|
||||
use App\Content\DemoContent;
|
||||
use App\Content\MediaLibrary;
|
||||
use App\Content\NotFoundPage;
|
||||
use App\Content\PageRepository;
|
||||
use App\Content\RedirectRepository;
|
||||
@@ -20,7 +19,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class SettingsController extends AbstractController
|
||||
{
|
||||
public function __construct(private SiteSettings $settings, private RedirectRepository $redirects, private PageRepository $pages, private MediaLibrary $media, private Theme $theme, private NotFoundPage $notFoundPage)
|
||||
public function __construct(private SiteSettings $settings, private RedirectRepository $redirects, private PageRepository $pages, private Theme $theme, private NotFoundPage $notFoundPage)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -31,8 +30,22 @@ final class SettingsController extends AbstractController
|
||||
// Veroeffentlichers, die Unternehmensdaten samt Einwilligung und Spamschutz die des
|
||||
// Administrators - der Bildschirm blendet den Teil aus, den die Rolle nicht aendern darf.
|
||||
$this->denyAccessUnlessGranted('ROLE_PUBLISHER');
|
||||
$settings = $this->settings->load();
|
||||
$choosable = [];
|
||||
// Datenschutz und Impressum werden per Suche gewählt; das Feld zeigt Titel und Adresse der
|
||||
// gespeicherten Seite. Eine Adresse ohne Seite bleibt sichtbar, statt still zu verschwinden.
|
||||
$legal = ['privacyPath' => null, 'imprintPath' => null];
|
||||
foreach (array_keys($legal) as $key) {
|
||||
if ('' !== $settings[$key]) {
|
||||
$legal[$key] = ['path' => $settings[$key], 'title' => $settings[$key]];
|
||||
}
|
||||
}
|
||||
foreach ($this->pages->listForEditor() as $page) {
|
||||
foreach ($legal as $key => $selection) {
|
||||
if (null !== $selection && $selection['path'] === $page['path']) {
|
||||
$legal[$key]['title'] = json_decode($page['document'] ?? '{}', true, 512, JSON_THROW_ON_ERROR)['title'] ?? $page['path'];
|
||||
}
|
||||
}
|
||||
// Only a published page can serve as the root; a draft would answer every visit with 404.
|
||||
if ('page' === $page['type'] && null !== $page['published_revision_id']) {
|
||||
$document = json_decode($page['document'] ?? '{}', true, 512, JSON_THROW_ON_ERROR);
|
||||
@@ -41,15 +54,14 @@ final class SettingsController extends AbstractController
|
||||
}
|
||||
|
||||
return $this->render('admin/settings.html.twig', [
|
||||
'settings' => $this->settings->load(),
|
||||
'settings' => $settings,
|
||||
'legalSelection' => $legal,
|
||||
'notFoundSelection' => $this->notFoundPage->selected(),
|
||||
'redirects' => $this->redirects->all($request->query->getInt('seite', 1)),
|
||||
'choosableHome' => $choosable,
|
||||
'consentGroups' => Consent::GROUPS,
|
||||
'missingLegal' => $this->settings->missingLegalPages(),
|
||||
'consentGroupHelp' => Consent::GROUP_HELP,
|
||||
// Für das Symbol der Website: die Mediathek zur Auswahl, die neuesten zuerst.
|
||||
'images' => $this->media->page(1, false, 96)['items'],
|
||||
// Fuer die Farbfelder: dieselbe Palette, die auch der Editor anbietet.
|
||||
'palette' => $this->theme->load()['colors'],
|
||||
'socialNetworks' => SocialProfiles::NETWORKS,
|
||||
|
||||
Reference in new issue
Block a user