Page MenuHomePhorge

D5790.1775203856.diff
No OneTemporary

Authored By
Unknown
Size
16 KB
Referenced Files
None
Subscribers
None

D5790.1775203856.diff

diff --git a/src/app/Http/Controllers/ContentController.php b/src/app/Http/Controllers/ContentController.php
--- a/src/app/Http/Controllers/ContentController.php
+++ b/src/app/Http/Controllers/ContentController.php
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
+use App\Support\Facades\Theme;
use App\Utils;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
@@ -21,17 +22,15 @@
abort(404);
}
- $theme = \config('app.theme');
- $page = mb_strtolower(str_replace('/', '.', $page));
+ $view = Theme::pageView($page);
- $file = "themes/{$theme}/pages/{$page}.blade.php";
- $view = "{$theme}.pages.{$page}";
-
- if (!file_exists(resource_path($file))) {
+ if (!$view) {
abort(404);
}
- return view($view)->with('env', Utils::uiEnv());
+ return view($view)
+ ->with('env', Utils::uiEnv())
+ ->with('meta', Theme::meta());
}
/**
@@ -45,114 +44,15 @@
return $this->errorResponse(404);
}
- $page = mb_strtolower($page);
- $faq = [];
-
- $theme_name = \config('app.theme');
- $theme_file = resource_path("themes/{$theme_name}/theme.json");
-
- if (file_exists($theme_file)) {
- $theme = json_decode(file_get_contents($theme_file), true);
- if (json_last_error() != \JSON_ERROR_NONE) {
- \Log::error("Failed to parse {$theme_file}: " . json_last_error_msg());
- } elseif (!empty($theme['faq']) && !empty($theme['faq'][$page])) {
- $faq = $theme['faq'][$page];
- }
-
- // TODO: Support pages with variables, e.g. users/<user-id>
- }
+ $faq = Theme::faq($page);
// Localization
- if (!empty($faq)) {
- foreach ($faq as $idx => $item) {
- if (!empty($item['label'])) {
- $faq[$idx]['title'] = \trans('theme::faq.' . $item['label']);
- }
- }
- }
-
- return response()->json(['status' => 'success', 'faq' => $faq]);
- }
-
- /**
- * Returns list of enabled locales
- *
- * @return array List of two-letter language codes
- */
- public static function locales(): array
- {
- if ($locales = \env('APP_LOCALES')) {
- return preg_split('/\s*,\s*/', strtolower(trim($locales)));
- }
-
- return ['en', 'de', 'fr'];
- }
-
- /**
- * Get menu definition from the theme
- */
- public static function menu(): array
- {
- $theme_name = \config('app.theme');
- $theme_file = resource_path("themes/{$theme_name}/theme.json");
- $menu = [];
-
- if (file_exists($theme_file)) {
- $theme = json_decode(file_get_contents($theme_file), true);
-
- if (json_last_error() != \JSON_ERROR_NONE) {
- \Log::error("Failed to parse {$theme_file}: " . json_last_error_msg());
- } elseif (!empty($theme['menu'])) {
- $menu = $theme['menu'];
- }
- }
-
- // TODO: These 2-3 lines could become a utility function somewhere
- $req_domain = preg_replace('/:[0-9]+$/', '', request()->getHttpHost());
- $sys_domain = \config('app.domain');
- $isAdmin = $req_domain == "admin.{$sys_domain}";
-
- $filter = static function ($item) use ($isAdmin) {
- if ($isAdmin && empty($item['admin'])) {
- return false;
- }
- if (!$isAdmin && !empty($item['admin']) && $item['admin'] === 'only') {
- return false;
- }
-
- return true;
- };
-
- $menu = array_values(array_filter($menu, $filter));
-
- // Load localization files for all supported languages
- $lang_path = resource_path("themes/{$theme_name}/lang");
- $locales = [];
- foreach (self::locales() as $lang) {
- $file = "{$lang_path}/{$lang}/menu.php";
- if (file_exists($file)) {
- $locales[$lang] = include $file;
- }
- }
-
- foreach ($menu as $idx => $item) {
- // Handle menu localization
+ foreach ($faq as $idx => $item) {
if (!empty($item['label'])) {
- $label = $item['label'];
-
- foreach ($locales as $lang => $labels) {
- if (!empty($labels[$label])) {
- $item["title-{$lang}"] = $labels[$label];
- }
- }
+ $faq[$idx]['title'] = \trans('theme::faq.' . $item['label']);
}
-
- // Unset properties that we don't need on the client side
- unset($item['admin']);
-
- $menu[$idx] = $item;
}
- return $menu;
+ return response()->json(['status' => 'success', 'faq' => $faq]);
}
}
diff --git a/src/app/Http/Middleware/Locale.php b/src/app/Http/Middleware/Locale.php
--- a/src/app/Http/Middleware/Locale.php
+++ b/src/app/Http/Middleware/Locale.php
@@ -2,7 +2,7 @@
namespace App\Http\Middleware;
-use App\Http\Controllers\ContentController;
+use App\Support\Facades\Theme;
use Illuminate\Http\Request;
class Locale
@@ -87,7 +87,7 @@
}
// Allow languages enabled for UI
- $enabledLanguages = ContentController::locales();
+ $enabledLanguages = Theme::locales();
return in_array($lang, $enabledLanguages) && file_exists("{$langDir}/{$lang}");
}
}
diff --git a/src/app/Http/Theme.php b/src/app/Http/Theme.php
new file mode 100644
--- /dev/null
+++ b/src/app/Http/Theme.php
@@ -0,0 +1,130 @@
+<?php
+
+namespace App\Http;
+
+class Theme
+{
+ protected $theme;
+ protected $meta = [];
+
+ public function __construct()
+ {
+ $this->theme = \config('app.theme');
+
+ $theme_file = resource_path("themes/{$this->theme}/theme.json");
+
+ if (file_exists($theme_file)) {
+ $this->meta = json_decode(file_get_contents($theme_file), true);
+
+ if (json_last_error() != \JSON_ERROR_NONE) {
+ \Log::error("Failed to parse {$theme_file}: " . json_last_error_msg());
+ $this->meta = [];
+ }
+ }
+ }
+
+ /**
+ * Get FAQ entries from the theme
+ *
+ * @param string $page Page name
+ */
+ public function faq(string $page): array
+ {
+ $page = mb_strtolower(str_replace('/', '.', $page));
+
+ return $this->meta['faq'][$page] ?? [];
+ }
+
+ /**
+ * Returns list of enabled locales
+ *
+ * @return array List of two-letter language codes
+ */
+ public static function locales(): array
+ {
+ if ($locales = \env('APP_LOCALES')) {
+ return preg_split('/\s*,\s*/', strtolower(trim($locales)));
+ }
+
+ return ['en', 'de', 'fr'];
+ }
+
+ /**
+ * Get menu definition from the theme
+ */
+ public function menu(): array
+ {
+ // TODO: These 2-3 lines could become a utility function somewhere
+ $req_domain = preg_replace('/:[0-9]+$/', '', \request()->getHttpHost());
+ $sys_domain = \config('app.domain');
+ $isAdmin = $req_domain == "admin.{$sys_domain}";
+
+ $filter = static function ($item) use ($isAdmin) {
+ if ($isAdmin && empty($item['admin'])) {
+ return false;
+ }
+ if (!$isAdmin && !empty($item['admin']) && $item['admin'] === 'only') {
+ return false;
+ }
+
+ return true;
+ };
+
+ $menu = array_values(array_filter($this->meta['menu'] ?? [], $filter));
+
+ // Load localization files for all supported languages
+ $lang_path = resource_path("themes/{$this->theme}/lang");
+ $locales = [];
+ foreach (self::locales() as $lang) {
+ $file = "{$lang_path}/{$lang}/menu.php";
+ if (file_exists($file)) {
+ $locales[$lang] = include $file;
+ }
+ }
+
+ foreach ($menu as $idx => $item) {
+ // Handle menu localization
+ if (!empty($item['label'])) {
+ $label = $item['label'];
+
+ foreach ($locales as $lang => $labels) {
+ if (!empty($labels[$label])) {
+ $item["title-{$lang}"] = $labels[$label];
+ }
+ }
+ }
+
+ // Unset properties that we don't need on the client side
+ unset($item['admin']);
+
+ $menu[$idx] = $item;
+ }
+
+ return $menu;
+ }
+
+ /**
+ * Get HTML <meta> definition from the theme
+ */
+ public function meta(): array
+ {
+ return $this->meta['meta'] ?? [];
+ }
+
+ /**
+ * Get theme view name for a specified page (if exists)
+ *
+ * @param string $page Page name
+ */
+ public function pageView(string $page): ?string
+ {
+ $page = mb_strtolower(str_replace('/', '.', $page));
+ $file = resource_path("themes/{$this->theme}/pages/{$page}.blade.php");
+
+ if (!file_exists($file)) {
+ return null;
+ }
+
+ return "{$this->theme}.pages.{$page}";
+ }
+}
diff --git a/src/app/Providers/AppServiceProvider.php b/src/app/Providers/AppServiceProvider.php
--- a/src/app/Providers/AppServiceProvider.php
+++ b/src/app/Providers/AppServiceProvider.php
@@ -15,6 +15,7 @@
use App\EventLog;
use App\Group;
use App\GroupSetting;
+use App\Http\Theme;
use App\Meet\Room;
use App\Observers\DelegationObserver;
use App\Observers\DomainObserver;
@@ -106,6 +107,9 @@
$this->app->bind('openexchangerates', static function () {
return new OpenExchangeRates();
});
+ $this->app->bind('theme', static function () {
+ return new Theme();
+ });
}
/**
diff --git a/src/app/Support/Facades/Theme.php b/src/app/Support/Facades/Theme.php
new file mode 100644
--- /dev/null
+++ b/src/app/Support/Facades/Theme.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Support\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+class Theme extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'theme';
+ }
+}
diff --git a/src/app/Utils.php b/src/app/Utils.php
--- a/src/app/Utils.php
+++ b/src/app/Utils.php
@@ -2,7 +2,7 @@
namespace App;
-use App\Http\Controllers\ContentController;
+use App\Support\Facades\Theme;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
@@ -102,7 +102,10 @@
}
$env = self::uiEnv();
- return view($env['view'])->with('env', $env);
+
+ return view($env['view'])
+ ->with('env', $env)
+ ->with('meta', Theme::meta());
}
/**
@@ -469,8 +472,8 @@
$env['paymentProvider'] = \config('services.payment_provider');
$env['stripePK'] = \config('services.stripe.public_key');
$env['maxChunkSize'] = \App\Backends\Storage::maxChunkSize();
- $env['languages'] = ContentController::locales();
- $env['menu'] = ContentController::menu();
+ $env['languages'] = Theme::locales();
+ $env['menu'] = Theme::menu();
return $env;
}
diff --git a/src/resources/views/layouts/app.blade.php b/src/resources/views/layouts/app.blade.php
--- a/src/resources/views/layouts/app.blade.php
+++ b/src/resources/views/layouts/app.blade.php
@@ -2,13 +2,13 @@
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no, maximum-scale=1.0">
- <meta name="csrf-token" content="{{ csrf_token() }}">
-
+ {{-- <meta name="csrf-token" content="{{ csrf_token() }}"> --}}
+@foreach ($meta ?? [] as $key => $val)
+ <meta name="{{ $key }}" content="{{ $val }}">
+@endforeach
<title>{{ config('app.name') }}</title>
- {{-- TODO: PWA disabled for now: @laravelPWA --}}
<link rel="icon" type="image/x-icon" href="@theme_asset(images/favicon.ico)">
<link href="@theme_asset(app.css)" rel="stylesheet">
</head>
diff --git a/src/resources/views/modules/laravelpwa/meta.blade.php b/src/resources/views/modules/laravelpwa/meta.blade.php
deleted file mode 100644
--- a/src/resources/views/modules/laravelpwa/meta.blade.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<!-- Web Application Manifest -->
-<link rel="manifest" href="{{ route('laravelpwa.manifest') }}">
-<!-- Chrome for Android theme color -->
-<meta name="theme-color" content="{{ $config['theme_color'] }}">
-
-<!-- Add to homescreen for Chrome on Android -->
-<meta name="mobile-web-app-capable" content="{{ $config['display'] == 'standalone' ? 'yes' : 'no' }}">
-<meta name="application-name" content="{{ $config['short_name'] }}">
-<link rel="icon" sizes="{{ data_get(end($config['icons']), 'sizes') }}" href="{{ data_get(end($config['icons']), 'src') }}">
-
-<!-- Add to homescreen for Safari on iOS -->
-<meta name="apple-mobile-web-app-capable" content="{{ $config['display'] == 'standalone' ? 'yes' : 'no' }}">
-<meta name="apple-mobile-web-app-status-bar-style" content="black">
-<meta name="apple-mobile-web-app-title" content="{{ $config['short_name'] }}">
-<link rel="apple-touch-icon" href="{{ data_get(end($config['icons']), 'src') }}">
-
-
-<link href="{{ $config['splash']['640x1136'] }}" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['750x1334'] }}" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1242x2208'] }}" media="(device-width: 621px) and (device-height: 1104px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1125x2436'] }}" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['828x1792'] }}" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1242x2688'] }}" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1536x2048'] }}" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1668x2224'] }}" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['1668x2388'] }}" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-<link href="{{ $config['splash']['2048x2732'] }}" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
-
-<!-- Tile for Win8 -->
-<meta name="msapplication-TileColor" content="{{ $config['background_color'] }}">
-<meta name="msapplication-TileImage" content="{{ data_get(end($config['icons']), 'src') }}">
-
-<script type="text/javascript">
- // Initialize the service worker
- if ('serviceWorker' in navigator) {
- navigator.serviceWorker.register('/serviceworker.js', {
- scope: '/'
- }).then(function (registration) {
- // Registration was successful
- console.log('Laravel PWA: ServiceWorker registration successful with scope: ', registration.scope);
- }, function (err) {
- // registration failed :(
- console.log('Laravel PWA: ServiceWorker registration failed: ', err);
- });
- }
-</script>
\ No newline at end of file
diff --git a/src/resources/views/modules/laravelpwa/offline.blade.php b/src/resources/views/modules/laravelpwa/offline.blade.php
deleted file mode 100644
--- a/src/resources/views/modules/laravelpwa/offline.blade.php
+++ /dev/null
@@ -1,7 +0,0 @@
-@extends('layouts.app')
-
-@section('content')
-
- <h1>You are currently not connected to any networks.</h1>
-
-@endsection
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 8:10 AM (13 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823164
Default Alt Text
D5790.1775203856.diff (16 KB)

Event Timeline