v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/site-front.php';
-
- $settings = SiteFront::settings();
- if (($settings['pwa_enabled'] ?? '0') !== '1') {
- http_response_code(404);
- exit;
- }
-
- function manifestIconMimeType(string $path): string
- {
- $extension = strtolower((string) pathinfo($path, PATHINFO_EXTENSION));
-
- return match ($extension) {
- 'png' => 'image/png',
- 'jpg', 'jpeg' => 'image/jpeg',
- 'svg' => 'image/svg+xml',
- 'webp' => 'image/webp',
- 'ico' => 'image/x-icon',
- default => 'image/png',
- };
- }
-
- $fallbackName = trim((string) ($settings['site_name'] ?? Config::get('APP_NAME', 'StocketBase')));
- $fallbackName = $fallbackName !== '' ? $fallbackName : 'Website';
-
- $appName = trim((string) ($settings['pwa_name'] ?? ''));
- $appName = $appName !== '' ? $appName : $fallbackName;
-
- $shortName = trim((string) ($settings['pwa_short_name'] ?? ''));
- $shortName = $shortName !== '' ? $shortName : $appName;
-
- $description = trim((string) ($settings['pwa_description'] ?? ''));
- $description = $description !== '' ? $description : trim((string) ($settings['site_description'] ?? ''));
-
- $icon = trim((string) ($settings['pwa_icon_url'] ?? ''));
- $icon = $icon !== '' ? $icon : trim((string) ($settings['site_logo_url'] ?? ''));
-
- $themeColor = trim((string) ($settings['pwa_theme_color'] ?? '')) ?: '#ffffff';
- $backgroundColor = trim((string) ($settings['pwa_background_color'] ?? '')) ?: '#ffffff';
-
- $basePath = rtrim(Config::get('APP_BASE_PATH', ''), '/') . '/';
-
- $manifest = [
- 'name' => $appName,
- 'short_name' => $shortName,
- 'start_url' => $basePath,
- 'scope' => $basePath,
- 'display' => 'standalone',
- 'background_color' => $backgroundColor,
- 'theme_color' => $themeColor,
- 'icons' => [],
- ];
-
- if ($description !== '') {
- $manifest['description'] = $description;
- }
-
- if ($icon !== '') {
- $mimeType = manifestIconMimeType($icon);
- $manifest['icons'][] = ['src' => $icon, 'sizes' => '192x192', 'type' => $mimeType];
- $manifest['icons'][] = ['src' => $icon, 'sizes' => '512x512', 'type' => $mimeType];
- }
-
- header('Content-Type: application/manifest+json; charset=utf-8');
- echo json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
-