SiteController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App, Auth, Cache;
  4. use Illuminate\Http\Request;
  5. use App\{Follower, Profile, Status, User};
  6. use App\Util\Lexer\PrettyNumber;
  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. // TODO: Use redis for timelines
  24. $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
  25. $following->push(Auth::user()->profile->id);
  26. $timeline = Status::whereIn('profile_id', $following)
  27. ->whereHas('media')
  28. ->orderBy('id','desc')
  29. ->withCount(['comments', 'likes', 'shares'])
  30. ->simplePaginate(20);
  31. $type = 'personal';
  32. return view('timeline.template', compact('timeline', 'type'));
  33. }
  34. public function changeLocale(Request $request, $locale)
  35. {
  36. if(!App::isLocale($locale)) {
  37. return redirect()->back();
  38. }
  39. App::setLocale($locale);
  40. return redirect()->back();
  41. }
  42. public function about()
  43. {
  44. $res = Cache::remember('site:page:about', 15, function() {
  45. $statuses = Status::whereHas('media')
  46. ->whereNull('in_reply_to_id')
  47. ->whereNull('reblog_of_id')
  48. ->count();
  49. $statusCount = PrettyNumber::convert($statuses);
  50. $userCount = PrettyNumber::convert(User::count());
  51. $remoteCount = PrettyNumber::convert(Profile::whereNotNull('remote_url')->count());
  52. $adminContact = User::whereIsAdmin(true)->first();
  53. return view('site.about')->with(compact('statusCount', 'userCount', 'remoteCount', 'adminContact'))->render();
  54. });
  55. return $res;
  56. }
  57. }