diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c2ad33a991..355c1f2c73 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -48,22 +48,10 @@ protected function view($view = null, $data = []) { if (!$this->request->ajax()) { $data['breadcrumb'] = $this->breadcrumb->render(); - $data['gdpr'] = [ - 'content' => TwigLiteral::fromHtml((new UserSettings)->cookieAgreement()), - 'accepted' => $this->gdprAccepted(), - ]; } return view($view, $data); } - private function gdprAccepted(): bool - { - if ($this->request->user()) { - return (bool)$this->auth->gdpr; - } - return false; - } - /** * @param string $name * @param $value diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php index aae878f572..2807fd1f9b 100644 --- a/app/Providers/ViewServiceProvider.php +++ b/app/Providers/ViewServiceProvider.php @@ -1,13 +1,18 @@ app['view']->composer(['layout', 'adm.home'], InitialStateComposer::class); - $this->app['view']->composer('layout', function (View $view) use ($cache) { + /** @var Factory $view */ + $view = $this->app['view']; + $view->composer(['layout', 'adm.home'], InitialStateComposer::class); + $view->composer('layout', function (View $view) use ($cache) { $view->with([ '__master_menu' => $this->buildMasterMenu(), // temporary code '__dark_theme' => $this->app[Guest::class]->getSetting('dark.theme', true), - 'github_stars' => $cache->remember('homepage:github_stars', 30 * 60, fn() => $this->githubStars()) + 'github_stars' => $cache->remember('homepage:github_stars', 30 * 60, fn() => $this->githubStars()), + + 'gdpr' => [ + 'content' => TwigLiteral::fromHtml((new UserSettings)->cookieAgreement()), + 'accepted' => $this->gdprAccepted(), + ], ]); }); } + private function gdprAccepted(): bool + { + /** @var Request $request */ + $request = $this->app['request']; + $user = $request->user(); + if ($user) { + /** @var User $user */ + return (bool)$user->gdpr; + } + return false; + } + private function buildMasterMenu(): Builder { /** @var Menu $menu */ @@ -79,7 +103,7 @@ private function githubStars(): ?int 'https://api.github.com/repos/pradoslaw/coyote', false, \stream_context_create([ - 'http' => ['header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'] + 'http' => ['header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'], ])); if ($result !== false) { $data = @\json_decode($result, true);