SiteController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Util\Lexer\PrettyNumber;
  9. use Auth;
  10. use Cache;
  11. use Illuminate\Http\Request;
  12. class SiteController extends Controller
  13. {
  14. public function home()
  15. {
  16. if (Auth::check()) {
  17. return $this->homeTimeline();
  18. } else {
  19. return $this->homeGuest();
  20. }
  21. }
  22. public function homeGuest()
  23. {
  24. return view('site.index');
  25. }
  26. public function homeTimeline()
  27. {
  28. // TODO: Use redis for timelines
  29. $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
  30. $following->push(Auth::user()->profile->id);
  31. $timeline = Status::whereIn('profile_id', $following)
  32. ->whereHas('media')
  33. ->orderBy('id', 'desc')
  34. ->withCount(['comments', 'likes', 'shares'])
  35. ->simplePaginate(20);
  36. $type = 'personal';
  37. return view('timeline.template', compact('timeline', 'type'));
  38. }
  39. public function changeLocale(Request $request, $locale)
  40. {
  41. if (!App::isLocale($locale)) {
  42. return redirect()->back();
  43. }
  44. App::setLocale($locale);
  45. return redirect()->back();
  46. }
  47. public function about()
  48. {
  49. $res = Cache::remember('site:page:about', 15, function () {
  50. $statuses = Status::whereHas('media')
  51. ->whereNull('in_reply_to_id')
  52. ->whereNull('reblog_of_id')
  53. ->count();
  54. $statusCount = PrettyNumber::convert($statuses);
  55. $userCount = PrettyNumber::convert(User::count());
  56. $remoteCount = PrettyNumber::convert(Profile::whereNotNull('remote_url')->count());
  57. $adminContact = User::whereIsAdmin(true)->first();
  58. return view('site.about')->with(compact('statusCount', 'userCount', 'remoteCount', 'adminContact'))->render();
  59. });
  60. return $res;
  61. }
  62. }