SiteController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App;
  4. use App\Follower;
  5. use App\Profile;
  6. use App\Status;
  7. use App\User;
  8. use App\UserFilter;
  9. use App\Util\Lexer\PrettyNumber;
  10. use Auth;
  11. use Cache;
  12. use Illuminate\Http\Request;
  13. class SiteController extends Controller
  14. {
  15. public function home()
  16. {
  17. if (Auth::check()) {
  18. return $this->homeTimeline();
  19. } else {
  20. return $this->homeGuest();
  21. }
  22. }
  23. public function homeGuest()
  24. {
  25. return view('site.index');
  26. }
  27. public function homeTimeline()
  28. {
  29. $pid = Auth::user()->profile->id;
  30. // TODO: Use redis for timelines
  31. $following = Follower::whereProfileId($pid)->pluck('following_id');
  32. $following->push($pid)->toArray();
  33. $filtered = UserFilter::whereUserId($pid)
  34. ->whereFilterableType('App\Profile')
  35. ->whereIn('filter_type', ['mute', 'block'])
  36. ->pluck('filterable_id')->toArray();
  37. $timeline = Status::whereIn('profile_id', $following)
  38. ->whereNotIn('profile_id', $filtered)
  39. ->whereHas('media')
  40. ->whereVisibility('public')
  41. ->orderBy('created_at', 'desc')
  42. ->withCount(['comments', 'likes', 'shares'])
  43. ->simplePaginate(20);
  44. $type = 'personal';
  45. return view('timeline.template', compact('timeline', 'type'));
  46. }
  47. public function changeLocale(Request $request, $locale)
  48. {
  49. // todo: add other locales after pushing new l10n strings
  50. $locales = ['en'];
  51. if(in_array($locale, $locales)) {
  52. session()->put('locale', $locale);
  53. }
  54. return redirect()->back();
  55. }
  56. public function about()
  57. {
  58. $stats = Cache::remember('site:about:stats', 1440, function() {
  59. return [
  60. 'posts' => Status::whereLocal(true)->count(),
  61. 'users' => User::count(),
  62. 'admin' => User::whereIsAdmin(true)->first()
  63. ];
  64. });
  65. return view('site.about', compact('stats'));
  66. }
  67. public function language()
  68. {
  69. return view('site.language');
  70. }
  71. }