refactor: clean up web assets and consolidate PHP helpers

- Remove 2079 unused bootstrap-icons SVGs + min.css (~9.3 MB saved, app uses font approach only)
- Remove unused editorjs.umd.js (only .mjs is imported)
- Extract shared syncControlState into app-conditional-controls.js, deduplicate SSO/LDAP toggles
- Add settingToBool() helper to DRY up repeated bool-parsing pattern across 6 call sites
- Merge single-function auth.php into app.php, delete auth.php
- Extract 9 branding functions from app.php into dedicated branding.php (app.php 709→528 lines)
- Remove empty web/img/ directory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 21:31:59 +02:00
parent 5f156661fd
commit 31ecb40235
2090 changed files with 348 additions and 7637 deletions

View File

@@ -2,7 +2,7 @@
// Load all global helper groups used by templates and page actions.
require __DIR__ . '/helpers/app.php';
require __DIR__ . '/helpers/auth.php';
require __DIR__ . '/helpers/branding.php';
require __DIR__ . '/helpers/grid.php';
require __DIR__ . '/helpers/i18n.php';
require __DIR__ . '/helpers/request.php';

View File

@@ -8,6 +8,37 @@ function e($string): void
echo htmlspecialchars((string) $string, ENT_QUOTES, 'UTF-8');
}
/**
* Parse a string setting value as boolean.
*
* Accepts common truthy values ('1', 'true', 'yes', 'on') and returns
* the given default for null, empty strings, or unrecognized values.
*/
function settingToBool(?string $value, bool $default = false): bool
{
if ($value === null || $value === '') {
return $default;
}
$normalized = strtolower(trim($value));
if (in_array($normalized, ['1', 'true', 'yes', 'on'], true)) {
return true;
}
if (in_array($normalized, ['0', 'false', 'no', 'off'], true)) {
return false;
}
return $default;
}
/**
* Resolve the profile target for the current session user.
*/
function accountUrl(): string
{
$user = $_SESSION['user'] ?? [];
$uuid = (string) ($user['uuid'] ?? '');
return $uuid !== '' ? lurl('profile') : lurl('login');
}
/**
* Build a web asset URL relative to the app base URL.
*/
@@ -168,15 +199,6 @@ function currentUserDisplayName(): string
return trim((string) ($user['email'] ?? ''));
}
/**
* Absolute logo URL (used in e-mails and metadata).
*/
function appLogoUrlAbsolute(int $size = 128): string
{
$url = appLogoUrl($size);
return appUrl($url);
}
/**
* Read one cached app setting from storage/runtime/settings.php.
*/
@@ -189,21 +211,6 @@ function appSetting(string $key): ?string
return app(\MintyPHP\Service\Settings\SettingCacheService::class)->get($key);
}
/**
* Load configured themes with a safe fallback list.
*/
function appThemes(): array
{
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigGateway')) {
return [
'light' => 'Light',
'dark' => 'Dark',
];
}
return app(\MintyPHP\Service\Settings\ThemeConfigGateway::class)->all();
}
/**
* Resolve default locale only if it exists in APP_LOCALES.
*/
@@ -220,64 +227,17 @@ function appDefaultLocale(): ?string
return $locale;
}
/**
* Resolve default theme from settings, then APP_THEME, then light.
*/
function appDefaultTheme(): string
{
$themes = appThemes();
$tenantTheme = strtolower(trim((string) ($_SESSION['current_tenant']['default_theme'] ?? '')));
if ($tenantTheme !== '' && isset($themes[$tenantTheme])) {
return $tenantTheme;
}
$setting = appSetting('app_theme');
if ($setting !== null && isset($themes[$setting])) {
return $setting;
}
$envTheme = getenv('APP_THEME') ?: 'light';
$envTheme = strtolower(trim((string) $envTheme));
return isset($themes[$envTheme]) ? $envTheme : 'light';
}
/**
* Resolve effective theme with optional per-user override.
*/
function currentTheme(): string
{
$themes = appThemes();
$theme = appDefaultTheme();
if (!allowUserTheme()) {
return $theme;
}
$user = $_SESSION['user'] ?? [];
$userTheme = strtolower(trim((string) ($user['theme'] ?? '')));
if ($userTheme !== '' && isset($themes[$userTheme])) {
return $userTheme;
}
return $theme;
}
/**
* Feature flag: allow users to choose their own theme.
*/
function allowUserTheme(): bool
{
$tenantValue = $_SESSION['current_tenant']['allow_user_theme'] ?? null;
if ($tenantValue !== null && $tenantValue !== '') {
$tenantValue = strtolower(trim((string) $tenantValue));
if (in_array($tenantValue, ['1', 'true', 'yes', 'on'], true)) {
return true;
}
if (in_array($tenantValue, ['0', 'false', 'no', 'off'], true)) {
return false;
}
if ($tenantValue !== null && (string) $tenantValue !== '') {
return settingToBool((string) $tenantValue, true);
}
$value = appSetting('app_theme_user');
if ($value === null || $value === '') {
return true;
}
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
return settingToBool(appSetting('app_theme_user'), true);
}
/**
@@ -285,11 +245,7 @@ function allowUserTheme(): bool
*/
function allowRegistration(): bool
{
$value = appSetting('app_registration');
if ($value === null || $value === '') {
return true;
}
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
return settingToBool(appSetting('app_registration'), true);
}
/**
@@ -297,11 +253,7 @@ function allowRegistration(): bool
*/
function frontendTelemetryEnabled(): bool
{
$value = appSetting('frontend_telemetry_enabled');
if ($value === null || $value === '') {
return false;
}
return in_array(strtolower(trim($value)), ['1', 'true', 'yes', 'on'], true);
return settingToBool(appSetting('frontend_telemetry_enabled'), false);
}
/**
@@ -352,138 +304,6 @@ function frontendTelemetryAllowedEvents(): array
return $normalized;
}
/**
* Resolve active primary color (tenant override -> app setting).
*/
function appPrimaryColor(): ?string
{
// Tenant-scoped branding has precedence over global settings.
$tenantColor = $_SESSION['current_tenant']['primary_color'] ?? null;
if ($tenantColor !== null) {
$tenantColor = strtolower(trim((string) $tenantColor));
if (preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $tenantColor)) {
return $tenantColor;
}
}
$value = appSetting('app_primary_color');
if ($value === null) {
return null;
}
$value = strtolower(trim($value));
if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
return null;
}
return $value;
}
/**
* Convert current hex color to CSS HSL custom properties.
*/
function appPrimaryCssVars(): string
{
$hex = appPrimaryColor();
if ($hex === null) {
return '';
}
$hex = ltrim($hex, '#');
if (strlen($hex) === 3) {
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
}
$r = hexdec(substr($hex, 0, 2)) / 255;
$g = hexdec(substr($hex, 2, 2)) / 255;
$b = hexdec(substr($hex, 4, 2)) / 255;
// Short-circuit grayscale values to avoid unstable hue math.
$monoThreshold = 0.000001;
if (abs($r - $g) < $monoThreshold && abs($g - $b) < $monoThreshold) {
$l = round($r * 100, 2) . '%';
return "--app-primary-h-base: 0; --app-primary-s-base: 0%; --app-primary-l-base: {$l}; --app-primary-h-light: 0; --app-primary-s-light: 0%; --app-primary-l-light: {$l};";
}
$max = max($r, $g, $b);
$min = min($r, $g, $b);
$delta = $max - $min;
if ($delta === 0.0) {
$l = round((($max + $min) / 2) * 100, 2) . '%';
return "--app-primary-h-base: 0; --app-primary-s-base: 0%; --app-primary-l-base: {$l}; --app-primary-h-light: 0; --app-primary-s-light: 0%; --app-primary-l-light: {$l};";
}
$h = 0.0;
if ($max === $r) {
$h = 60 * fmod((($g - $b) / $delta), 6);
} elseif ($max === $g) {
$h = 60 * ((($b - $r) / $delta) + 2);
} else {
$h = 60 * ((($r - $g) / $delta) + 4);
}
if ($h < 0) {
$h += 360;
}
$l = ($max + $min) / 2;
$denominator = 1 - abs(2 * $l - 1);
if ($delta === 0.0 || $denominator === 0.0) {
$s = 0.0;
} else {
$s = $delta / $denominator;
}
$h = round($h, 2);
$s = round($s * 100, 2) . '%';
$l = round($l * 100, 2) . '%';
return "--app-primary-h-base: {$h}; --app-primary-s-base: {$s}; --app-primary-l-base: {$l}; --app-primary-h-light: {$h}; --app-primary-s-light: {$s}; --app-primary-l-light: {$l};";
}
/**
* Resolve app logo path (custom upload with fallback asset).
*/
function appLogoUrl(?int $size = null): string
{
if (class_exists('MintyPHP\\Service\\Branding\\BrandingLogoService')) {
$logoService = app(\MintyPHP\Service\Branding\BrandingLogoService::class);
if ($logoService->hasLogo()) {
$query = $size ? '?size=' . (int) $size : '';
return lurl('branding/logo' . $query);
}
}
return asset('brand/logo.svg');
}
/**
* Resolve logo for auth pages: tenant avatar → global logo → default SVG.
*
* After logout the tenant context (`$_SESSION['current_tenant']`) is preserved,
* so the login page can show the tenant avatar instead of the generic app logo.
*/
function appAuthLogoUrl(?int $size = null): string
{
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantAvatarService')) {
if (app(\MintyPHP\Service\Tenant\TenantAvatarService::class)->hasAvatar($tenantUuid)) {
$query = $size ? '&size=' . (int) $size : '';
return lurl('auth/tenant-avatar-file?uuid=' . rawurlencode($tenantUuid) . $query);
}
}
return appLogoUrl($size);
}
/**
* Resolve favicon path (tenant favicon with global fallback).
*/
function appFaviconUrl(string $file): string
{
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantFaviconService')) {
if (app(\MintyPHP\Service\Tenant\TenantFaviconService::class)->hasFavicon($tenantUuid)) {
return asset('favicon/tenants/' . $tenantUuid . '/favicon/' . ltrim($file, '/'));
}
}
return asset('favicon/' . ltrim($file, '/'));
}
/**
* Sort array items by 'description' case-insensitively.
*/

View File

@@ -1,11 +0,0 @@
<?php
/**
* Resolve the profile target for the current session user.
*/
function accountUrl(): string
{
$user = $_SESSION['user'] ?? [];
$uuid = (string) ($user['uuid'] ?? '');
return $uuid !== '' ? lurl('profile') : lurl('login');
}

View File

@@ -0,0 +1,200 @@
<?php
/**
* Branding helpers — themes, colors, logos, favicons.
*
* Extracted from app.php to keep visual-identity concerns in one place.
*/
/**
* Load configured themes with a safe fallback list.
*/
function appThemes(): array
{
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigGateway')) {
return [
'light' => 'Light',
'dark' => 'Dark',
];
}
return app(\MintyPHP\Service\Settings\ThemeConfigGateway::class)->all();
}
/**
* Resolve default theme from settings, then APP_THEME, then light.
*/
function appDefaultTheme(): string
{
$themes = appThemes();
$tenantTheme = strtolower(trim((string) ($_SESSION['current_tenant']['default_theme'] ?? '')));
if ($tenantTheme !== '' && isset($themes[$tenantTheme])) {
return $tenantTheme;
}
$setting = appSetting('app_theme');
if ($setting !== null && isset($themes[$setting])) {
return $setting;
}
$envTheme = getenv('APP_THEME') ?: 'light';
$envTheme = strtolower(trim((string) $envTheme));
return isset($themes[$envTheme]) ? $envTheme : 'light';
}
/**
* Resolve effective theme with optional per-user override.
*/
function currentTheme(): string
{
$themes = appThemes();
$theme = appDefaultTheme();
if (!allowUserTheme()) {
return $theme;
}
$user = $_SESSION['user'] ?? [];
$userTheme = strtolower(trim((string) ($user['theme'] ?? '')));
if ($userTheme !== '' && isset($themes[$userTheme])) {
return $userTheme;
}
return $theme;
}
/**
* Resolve active primary color (tenant override -> app setting).
*/
function appPrimaryColor(): ?string
{
// Tenant-scoped branding has precedence over global settings.
$tenantColor = $_SESSION['current_tenant']['primary_color'] ?? null;
if ($tenantColor !== null) {
$tenantColor = strtolower(trim((string) $tenantColor));
if (preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $tenantColor)) {
return $tenantColor;
}
}
$value = appSetting('app_primary_color');
if ($value === null) {
return null;
}
$value = strtolower(trim($value));
if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
return null;
}
return $value;
}
/**
* Convert current hex color to CSS HSL custom properties.
*/
function appPrimaryCssVars(): string
{
$hex = appPrimaryColor();
if ($hex === null) {
return '';
}
$hex = ltrim($hex, '#');
if (strlen($hex) === 3) {
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
}
$r = hexdec(substr($hex, 0, 2)) / 255;
$g = hexdec(substr($hex, 2, 2)) / 255;
$b = hexdec(substr($hex, 4, 2)) / 255;
// Short-circuit grayscale values to avoid unstable hue math.
$monoThreshold = 0.000001;
if (abs($r - $g) < $monoThreshold && abs($g - $b) < $monoThreshold) {
$l = round($r * 100, 2) . '%';
return "--app-primary-h-base: 0; --app-primary-s-base: 0%; --app-primary-l-base: {$l}; --app-primary-h-light: 0; --app-primary-s-light: 0%; --app-primary-l-light: {$l};";
}
$max = max($r, $g, $b);
$min = min($r, $g, $b);
$delta = $max - $min;
if ($delta === 0.0) {
$l = round((($max + $min) / 2) * 100, 2) . '%';
return "--app-primary-h-base: 0; --app-primary-s-base: 0%; --app-primary-l-base: {$l}; --app-primary-h-light: 0; --app-primary-s-light: 0%; --app-primary-l-light: {$l};";
}
$h = 0.0;
if ($max === $r) {
$h = 60 * fmod((($g - $b) / $delta), 6);
} elseif ($max === $g) {
$h = 60 * ((($b - $r) / $delta) + 2);
} else {
$h = 60 * ((($r - $g) / $delta) + 4);
}
if ($h < 0) {
$h += 360;
}
$l = ($max + $min) / 2;
$denominator = 1 - abs(2 * $l - 1);
if ($delta === 0.0 || $denominator === 0.0) {
$s = 0.0;
} else {
$s = $delta / $denominator;
}
$h = round($h, 2);
$s = round($s * 100, 2) . '%';
$l = round($l * 100, 2) . '%';
return "--app-primary-h-base: {$h}; --app-primary-s-base: {$s}; --app-primary-l-base: {$l}; --app-primary-h-light: {$h}; --app-primary-s-light: {$s}; --app-primary-l-light: {$l};";
}
/**
* Resolve app logo path (custom upload with fallback asset).
*/
function appLogoUrl(?int $size = null): string
{
if (class_exists('MintyPHP\\Service\\Branding\\BrandingLogoService')) {
$logoService = app(\MintyPHP\Service\Branding\BrandingLogoService::class);
if ($logoService->hasLogo()) {
$query = $size ? '?size=' . (int) $size : '';
return lurl('branding/logo' . $query);
}
}
return asset('brand/logo.svg');
}
/**
* Resolve logo for auth pages: tenant avatar -> global logo -> default SVG.
*
* After logout the tenant context (`$_SESSION['current_tenant']`) is preserved,
* so the login page can show the tenant avatar instead of the generic app logo.
*/
function appAuthLogoUrl(?int $size = null): string
{
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantAvatarService')) {
if (app(\MintyPHP\Service\Tenant\TenantAvatarService::class)->hasAvatar($tenantUuid)) {
$query = $size ? '&size=' . (int) $size : '';
return lurl('auth/tenant-avatar-file?uuid=' . rawurlencode($tenantUuid) . $query);
}
}
return appLogoUrl($size);
}
/**
* Absolute logo URL (used in e-mails and metadata).
*/
function appLogoUrlAbsolute(int $size = 128): string
{
$url = appLogoUrl($size);
return appUrl($url);
}
/**
* Resolve favicon path (tenant favicon with global fallback).
*/
function appFaviconUrl(string $file): string
{
$tenantUuid = $_SESSION['current_tenant']['uuid'] ?? '';
if ($tenantUuid !== '' && class_exists('MintyPHP\\Service\\Tenant\\TenantFaviconService')) {
if (app(\MintyPHP\Service\Tenant\TenantFaviconService::class)->hasFavicon($tenantUuid)) {
return asset('favicon/tenants/' . $tenantUuid . '/favicon/' . ltrim($file, '/'));
}
}
return asset('favicon/' . ltrim($file, '/'));
}

View File

@@ -669,14 +669,7 @@ function gridQueryBool(array $query, string $key, bool $default = false): bool
if (!array_key_exists($key, $query)) {
return $default;
}
$value = strtolower(trim((string) $query[$key]));
if (in_array($value, ['1', 'true', 'yes', 'on'], true)) {
return true;
}
if (in_array($value, ['0', 'false', 'no', 'off'], true)) {
return false;
}
return $default;
return settingToBool(trim((string) $query[$key]), $default);
}
/**