diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index f1e78d7f9..b3d8869ac 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Auth; +use Auth, Cache; use App\Page; class PageController extends Controller @@ -13,6 +13,14 @@ class PageController extends Controller $this->middleware(['auth', 'admin']); } + protected function cacheKeys() { + return [ + '/site/about' => 'site:about', + '/site/privacy' => 'site:privacy', + '/site/terms' => 'site:terms', + ]; + } + protected function authCheck($admin_only = false) { $auth = $admin_only ? @@ -30,6 +38,9 @@ class PageController extends Controller 'page' => 'required|string' ]); $slug = urldecode($request->page); + if(in_array($slug, array_keys($this->cacheKeys())) == false) { + return redirect(route('admin.settings.pages')); + } $page = Page::firstOrCreate(['slug' => $slug]); return view('admin.pages.edit', compact('page')); } @@ -48,6 +59,47 @@ 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); + } return response()->json(['msg' => 200]); } + + public function delete(Request $request) + { + $this->validate($request, [ + 'id' => 'required|integer|min:1|exists:pages,id' + ]); + + $page = Page::findOrFail($request->input('id')); + $page->delete(); + return redirect(route('admin.settings.pages')); + } + + public function generatePage(Request $request) + { + $this->validate($request, [ + 'page' => 'required|string|in:about,terms,privacy', + ]); + + $page = $request->input('page'); + + switch ($page) { + case 'about': + Page::firstOrCreate(['slug' => '/site/about']); + break; + + case 'privacy': + Page::firstOrCreate(['slug' => '/site/privacy']); + break; + + case 'terms': + Page::firstOrCreate(['slug' => '/site/terms']); + break; + } + + return redirect(route('admin.settings.pages')); + } } diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index d7f158dca..c14dc1ddb 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -42,14 +42,19 @@ class SiteController extends Controller public function about() { - $stats = Cache::remember('site:about', now()->addMinutes(120), function() { - return [ + return Cache::remember('site:about', now()->addMinutes(120), function() { + $page = Page::whereSlug('/site/about')->whereActive(true)->first(); + $stats = [ 'posts' => Status::whereLocal(true)->count(), - 'users' => User::count(), + 'users' => User::whereNull('status')->count(), 'admin' => User::whereIsAdmin(true)->first() ]; + if($page) { + return View::make('site.about-custom')->with(compact('page', 'stats'))->render(); + } else { + return View::make('site.about')->with(compact('stats'))->render(); + } }); - return view('site.about', compact('stats')); } public function language() @@ -64,4 +69,22 @@ class SiteController extends Controller return view('site.help.community-guidelines', compact('page')); } + public function privacy(Request $request) + { + return Cache::remember('site:privacy', now()->addMinutes(120), function() { + $slug = '/site/privacy'; + $page = Page::whereSlug($slug)->whereActive(true)->first(); + return View::make('site.privacy')->with(compact('page'))->render(); + }); + } + + + public function terms(Request $request) + { + return Cache::remember('site:terms', now()->addMinutes(120), function() { + $slug = '/site/terms'; + $page = Page::whereSlug($slug)->whereActive(true)->first(); + return View::make('site.terms')->with(compact('page'))->render(); + }); + } } diff --git a/resources/views/admin/pages/edit.blade.php b/resources/views/admin/pages/edit.blade.php index bf9033045..b47dfcf4b 100644 --- a/resources/views/admin/pages/edit.blade.php +++ b/resources/views/admin/pages/edit.blade.php @@ -14,7 +14,7 @@
Page URL: {{$page->url()}} - Edit + {{-- Edit --}}