diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 94d149410..a136eda9f 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth, Cache; use App\Page; +use App\Services\ConfigCacheService; class PageController extends Controller { @@ -18,7 +19,8 @@ class PageController extends Controller '/site/about' => 'site:about', '/site/privacy' => 'site:privacy', '/site/terms' => 'site:terms', - '/site/kb/community-guidelines' => 'site:help:community-guidelines' + '/site/kb/community-guidelines' => 'site:help:community-guidelines', + '/site/legal-notice' => 'site:legal-notice' ]; } @@ -60,10 +62,11 @@ class PageController extends Controller $page->title = $request->input('title'); $page->active = (bool) $request->input('active'); $page->save(); - if($page->cached) { - $keys = $this->cacheKeys(); - $key = $keys[$page->slug]; - Cache::forget($key); + $keys = $this->cacheKeys(); + $key = $keys[$page->slug]; + Cache::forget($key); + if($page->slug === '/site/legal-notice') { + ConfigCacheService::put('instance.has_legal_notice', $page->active); } return response()->json(['msg' => 200]); } @@ -75,14 +78,17 @@ class PageController extends Controller ]); $page = Page::findOrFail($request->input('id')); + $keys = $this->cacheKeys(); + $key = $keys[$page->slug]; $page->delete(); + Cache::forget($key); return redirect(route('admin.settings.pages')); } public function generatePage(Request $request) { $this->validate($request, [ - 'page' => 'required|string|in:about,terms,privacy,community_guidelines', + 'page' => 'required|string|in:about,terms,privacy,community_guidelines,legal_notice', ]); $page = $request->input('page'); @@ -103,6 +109,10 @@ class PageController extends Controller case 'community_guidelines': Page::firstOrCreate(['slug' => '/site/kb/community-guidelines']); break; + + case 'legal_notice': + Page::firstOrCreate(['slug' => '/site/legal-notice']); + break; } return redirect(route('admin.settings.pages')); diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index f4cac26be..379b24505 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -154,4 +154,14 @@ class SiteController extends Controller return redirect($url); } + + public function legalNotice(Request $request) + { + $page = Cache::remember('site:legal-notice', now()->addDays(120), function() { + $slug = '/site/legal-notice'; + return Page::whereSlug($slug)->whereActive(true)->first(); + }); + abort_if(!$page, 404); + return View::make('site.legal-notice')->with(compact('page'))->render(); + } } diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 91d644ee7..b334e9e33 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -53,6 +53,8 @@ class ConfigCacheService 'account.autofollow', 'account.autofollow_usernames', 'config.discover.features', + + 'instance.has_legal_notice', // 'system.user_mode' ]; diff --git a/config/instance.php b/config/instance.php index 15ce670f8..d2bf9231a 100644 --- a/config/instance.php +++ b/config/instance.php @@ -84,4 +84,6 @@ return [ ], 'enable_cc' => env('ENABLE_CONFIG_CACHE', false), + + 'has_legal_notice' => env('INSTANCE_LEGAL_NOTICE', false), ]; diff --git a/resources/views/admin/pages/home.blade.php b/resources/views/admin/pages/home.blade.php index bab294647..1f48d540c 100644 --- a/resources/views/admin/pages/home.blade.php +++ b/resources/views/admin/pages/home.blade.php @@ -11,7 +11,7 @@

Manage public and custom page content

- @if($pages->count() < 4) + @if($pages->count() < 5)

@@ -43,6 +43,13 @@ @endif + @if(!$pages->contains('slug', '=', '/site/legal-notice')) +
+ @csrf + + +
+ @endif
@endif diff --git a/resources/views/site/legal-notice.blade.php b/resources/views/site/legal-notice.blade.php new file mode 100644 index 000000000..18e7d92cd --- /dev/null +++ b/resources/views/site/legal-notice.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.app') + +@section('content') +
+
+

{{ $page->title ?? 'Legal Notice' }}

+
+
+ @if($page && $page->content) + {!! $page->content !!} + @endif +
+
+
+
+@endsection +@push('meta') + +@endpush diff --git a/routes/web.php b/routes/web.php index ab9aa03a0..14e30da02 100644 --- a/routes/web.php +++ b/routes/web.php @@ -513,6 +513,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('newsroom/archive', 'NewsroomController@archive'); Route::get('newsroom/search', 'NewsroomController@search'); Route::get('newsroom', 'NewsroomController@index'); + Route::get('legal-notice', 'SiteController@legalNotice'); }); Route::group(['prefix' => 'timeline'], function () {