SiteController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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(Auth::user()->profile->id)->pluck('following_id');
  32. $following->push(Auth::user()->profile->id);
  33. $filtered = UserFilter::whereUserId($pid)
  34. ->whereFilterableType('App\Profile')
  35. ->whereIn('filter_type', ['mute', 'block'])
  36. ->pluck('filterable_id');
  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. if (!App::isLocale($locale)) {
  50. return redirect()->back();
  51. }
  52. App::setLocale($locale);
  53. return redirect()->back();
  54. }
  55. public function about()
  56. {
  57. $res = Cache::remember('site:page:about', 15, function () {
  58. $statuses = Status::whereHas('media')
  59. ->whereNull('in_reply_to_id')
  60. ->whereNull('reblog_of_id')
  61. ->count();
  62. $statusCount = PrettyNumber::convert($statuses);
  63. $userCount = PrettyNumber::convert(User::count());
  64. $remoteCount = PrettyNumber::convert(Profile::whereNotNull('remote_url')->count());
  65. $adminContact = User::whereIsAdmin(true)->first();
  66. return view('site.about')->with(compact('statusCount', 'userCount', 'remoteCount', 'adminContact'))->render();
  67. });
  68. return $res;
  69. }
  70. }