diff --git a/app/Livewire/EntryFilesModal.php b/app/Livewire/EntryFilesModal.php new file mode 100644 index 0000000..c03e0e1 --- /dev/null +++ b/app/Livewire/EntryFilesModal.php @@ -0,0 +1,37 @@ + 'openModal' + ]; + + public function openModal( int $entryId ): void + { + $this->entryId = $entryId; + $this->open = true; + + $this->dispatch('modal:opened'); + } + + public function close(): void + { + $this->open = false; + $this->entryId = null; + } + + public function render() + { + $files = $this->entryId ? Entry::find($this->entryId)?->files : collect(); + return view('livewire.entry-files-modal', compact('files')); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c61b956..ecf876b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -20,6 +20,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { + \Auth::extend('xenforo', function ($app, $name, array $config) { return new XenForoGuard($app['request']); }); diff --git a/app/Services/XenforoService.php b/app/Services/XenforoService.php index 82b7b36..c16009d 100644 --- a/app/Services/XenforoService.php +++ b/app/Services/XenforoService.php @@ -8,7 +8,16 @@ class XenforoService { private const array PERMISSIONS_KEPT = [ 'general', 'romhackplaza' ]; private const int TTL_PERMISSIONS = 300; + private const int TTL_ROUTES = 86400; + /** + * Get permissions for a specific user ID. + * + * @param int $userId + * @param int $permissionCombinationId + * + * @return array + */ public function getPermissions(int $userId, int $permissionCombinationId): array { return Cache::remember("xf_permissions_{$userId}", self::TTL_PERMISSIONS, function() use($permissionCombinationId) { @@ -29,8 +38,117 @@ class XenforoService { } + /** + * Clear user data. + * + * @param int $userId + * + * @return void + */ public function clearUserData(int $userId): void { Cache::forget("xf_permissions_{$userId}"); } + + /** + * + * + * @param string $routeName . + * + * @return string + */ + public function getRoute( string $routeName, array $arguments ): string { + + $routes = Cache::remember("xf_routes", self::TTL_ROUTES, function(){ + return \DB::connection('xenforo') + ->table('route') + ->where('route_type', 'public' ) + ->get(['route_prefix', 'sub_name', 'format']) + ->map(fn($r) => (array) $r ) + ->toArray(); + }); + + $baseUrl = config('app.forum_url'); + + try { + [$prefix, $subName] = explode('.', $routeName, 2); + + $route = collect($routes)->first(function ($r) use ($prefix, $subName) { + return $r['route_prefix'] === $prefix && $r['sub_name'] === $subName; + }); + + if( !$route ) + return $baseUrl . '/' . $prefix; + + $path = $this->buildRoutePath((array)$route, $arguments); + return rtrim($baseUrl, '/') . '/' . $path; + + } catch (\Throwable $th) { + $prefix = $routeName; + + $route = collect($routes)->first(function ($r) use ($prefix) { + return $r['route_prefix'] === $prefix; + }); + + if( !$route ) + return $baseUrl . '/' . $prefix; + + $path = $this->buildRoutePath((array)$route, $arguments); + return rtrim($baseUrl, '/') . '/' . $path; + } + + } + + private function buildRoutePath(array $route, array $arguments): string { + + $prefix = $route['route_prefix']; + $format = $route['format']; + $subName = $route['sub_name']; + + if (!$format) { + return $subName + ? $prefix . '-/' . $subName + : $prefix; + } + + if (str_starts_with($format, '-/')) { + return $prefix . $format; + } + + $built = preg_replace_callback( + '/:\+?(\w+)(?:_\w+)?(?:<([^>]+)>)?/', + function(array $m) use ($arguments): string { + $type = $m[1]; + $keys = isset($m[2]) + ? explode(',', $m[2]) + : []; + + return match(true) { + + $type === 'page' => isset($params['page']) && $params['page'] > 1 + ? 'page-' . $params['page'] + : '', + + $type === 'str_int' && count($keys) >= 2 => implode('.', array_filter([ + $params[$keys[0]] ?? null, + $params[$keys[1]] ?? null, + ])), + + $type === 'int' && count($keys) >= 1 => (string) ($params[$keys[0]] ?? ''), + + in_array($type, ['str', 'any']) && count($keys) >= 1 + => (string) ($params[$keys[0]] ?? ''), + + default => isset($params[$type]) ? (string) $params[$type] : '', + }; + }, + $format + ); + + $built = preg_replace('/\/+/', '/', $prefix . '/' . $built); + $built = rtrim($built, '/'); + + return $built; + + } } diff --git a/app/xenforo.php b/app/xenforo.php new file mode 100644 index 0000000..4eb88f4 --- /dev/null +++ b/app/xenforo.php @@ -0,0 +1,8 @@ +getRoute( $routeName, $arguments ); + } +} diff --git a/composer.json b/composer.json index 7fcd221..74825aa 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ }, "autoload": { "files": [ - "app/helpers.php" + "app/helpers.php", + "app/xenforo.php" ], "psr-4": { "App\\": "app/", diff --git a/config/menu.php b/config/menu.php new file mode 100644 index 0000000..0169ffb --- /dev/null +++ b/config/menu.php @@ -0,0 +1,94 @@ + => ['name', 'items'] + * Items: ['name','icon','route' or 'xf_route'] + */ +return [ + 'website' => [ + 'name' => 'Website', + 'items' => [ + [ + 'name' => 'Home', + 'icon' => 'home', + 'route' => 'home', + ], + [ + 'name' => 'Database', + 'icon' => 'database', + 'route' => 'home' + ], + [ + 'name' => "Submissions Queue", + 'icon' => 'gavel', + 'route' => 'home' + ], + ] + ], + 'community' => [ + 'name' => 'Community', + 'items' => [ + [ + 'name' => 'Forum', + 'icon' => 'message-circle', + 'xf_route' => '' + ], + [ + 'name' => 'Discord', + 'icon' => 'messages-square', + 'route' => 'home' + ], + [ + 'name' => 'Members', + 'icon' => 'users', + 'xf_route' => 'members' + ], + + ] + ], + 'tools' => [ + 'name' => 'Tools', + 'items' => [ + [ + 'name' => 'ROM Patcher', + 'icon' => 'stamp', + 'route' => 'home' + ], + [ + 'name' => 'ROM Hasher', + 'icon' => 'hash', + 'route' => 'home' + ], + [ + 'name' => 'ROM Checker', + 'icon' => 'check', + 'route' => 'home' + ] + ] + ], + 'pages' => [ + 'name' => 'Pages', + 'items' => [ + [ + 'name' => 'Learn Romhacking', + 'icon' => 'graduation-cap', + 'route' => 'home' + ], + [ + 'name' => 'About', + 'icon' => 'info', + 'route' => 'home' + ], + [ + 'name' => 'Contact Us', + 'icon' => 'at-sign', + 'route' => 'home' + ], + [ + 'name' => 'Legal pages', + 'icon' => 'scale', + 'route' => 'home' + ] + ] + ] +]; diff --git a/resources/css/components/modal.css b/resources/css/components/modal.css index f61ae6e..934b109 100644 --- a/resources/css/components/modal.css +++ b/resources/css/components/modal.css @@ -1,5 +1,5 @@ .modal-overlay { - display: none; + display: flex; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.7); diff --git a/resources/js/app.js b/resources/js/app.js index e7418b1..39c1d46 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -19,5 +19,3 @@ window.EasyMDE = EasyMDE; // Hashes. window.calculateHashes = calculateHashes; - - diff --git a/resources/views/components/menu.blade.php b/resources/views/components/menu.blade.php index 4f16b39..dcdb3ac 100644 --- a/resources/views/components/menu.blade.php +++ b/resources/views/components/menu.blade.php @@ -11,15 +11,17 @@ diff --git a/resources/views/entries/show.blade.php b/resources/views/entries/show.blade.php index b7fd1ad..06b6ac2 100644 --- a/resources/views/entries/show.blade.php +++ b/resources/views/entries/show.blade.php @@ -56,7 +56,7 @@ @endif
-
+ @livewire('entry-files-modal') @endsection diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index e025fc0..3037dbd 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -7,4 +7,6 @@ Ceci est un block ! + + {{ xfRoute( 'profile-posts.comments', ['profile_post_comment_id' => 1] ) }} @endsection diff --git a/resources/views/livewire/entry-files-modal.blade.php b/resources/views/livewire/entry-files-modal.blade.php new file mode 100644 index 0000000..089e720 --- /dev/null +++ b/resources/views/livewire/entry-files-modal.blade.php @@ -0,0 +1,33 @@ + diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore index d6b7ef3..e4ca604 100644 --- a/storage/app/public/.gitignore +++ b/storage/app/public/.gitignore @@ -1,2 +1,3 @@ * !.gitignore +z