SiteController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App, Auth, Cache, View;
  5. use App\Util\Lexer\PrettyNumber;
  6. use App\{Follower, Page, Profile, Status, User, UserFilter};
  7. class SiteController extends Controller
  8. {
  9. public function home()
  10. {
  11. if (Auth::check()) {
  12. return $this->homeTimeline();
  13. } else {
  14. return $this->homeGuest();
  15. }
  16. }
  17. public function homeGuest()
  18. {
  19. return view('site.index');
  20. }
  21. public function homeTimeline()
  22. {
  23. return view('timeline.home');
  24. }
  25. public function changeLocale(Request $request, $locale)
  26. {
  27. // todo: add other locales after pushing new l10n strings
  28. $locales = ['en'];
  29. if(in_array($locale, $locales)) {
  30. session()->put('locale', $locale);
  31. }
  32. return redirect()->back();
  33. }
  34. public function about()
  35. {
  36. $res = Cache::remember('site:about', 120, function() {
  37. $custom = Page::whereSlug('/site/about')->whereActive(true)->exists();
  38. if($custom) {
  39. $stats = Cache::remember('site:about:stats', 60, function() {
  40. return [
  41. 'posts' => Status::whereLocal(true)->count(),
  42. 'users' => User::count(),
  43. 'admin' => User::whereIsAdmin(true)->first()
  44. ];
  45. });
  46. return View::make('site.about')->with('stats', $stats)->render();
  47. } else {
  48. $stats = Cache::remember('site:about:stats', 60, function() {
  49. return [
  50. 'posts' => Status::whereLocal(true)->count(),
  51. 'users' => User::count(),
  52. 'admin' => User::whereIsAdmin(true)->first()
  53. ];
  54. });
  55. //return view('site.about', compact('stats'));
  56. return View::make('site.about')->with('stats', $stats)->render();
  57. }
  58. });
  59. return $res;
  60. }
  61. public function language()
  62. {
  63. return view('site.language');
  64. }
  65. public function communityGuidelines(Request $request)
  66. {
  67. $slug = '/site/kb/community-guidelines';
  68. $page = Page::whereSlug($slug)->whereActive(true)->first();
  69. return view('site.help.community-guidelines', compact('page'));
  70. }
  71. }