SiteController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. return view('site.about');
  59. }
  60. public function language()
  61. {
  62. return view('site.language');
  63. }
  64. }