2018-06-01 03:12:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
use App;
|
|
|
|
use App\Follower;
|
|
|
|
use App\Profile;
|
|
|
|
use App\Status;
|
|
|
|
use App\User;
|
2018-08-31 03:47:25 +00:00
|
|
|
use App\UserFilter;
|
2018-08-10 03:18:56 +00:00
|
|
|
use App\Util\Lexer\PrettyNumber;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Auth;
|
|
|
|
use Cache;
|
|
|
|
use Illuminate\Http\Request;
|
2018-06-01 03:12:06 +00:00
|
|
|
|
|
|
|
class SiteController extends Controller
|
|
|
|
{
|
2018-07-12 16:37:31 +00:00
|
|
|
public function home()
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
if (Auth::check()) {
|
|
|
|
return $this->homeTimeline();
|
2018-07-12 16:37:31 +00:00
|
|
|
} else {
|
2018-08-28 03:07:36 +00:00
|
|
|
return $this->homeGuest();
|
2018-07-12 16:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function homeGuest()
|
|
|
|
{
|
2018-08-20 01:22:54 +00:00
|
|
|
return view('site.index');
|
2018-07-12 16:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function homeTimeline()
|
|
|
|
{
|
2018-08-31 03:47:25 +00:00
|
|
|
$pid = Auth::user()->profile->id;
|
2018-08-28 03:07:36 +00:00
|
|
|
// TODO: Use redis for timelines
|
2018-11-16 03:52:36 +00:00
|
|
|
|
2018-11-20 01:50:28 +00:00
|
|
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
|
|
|
$following->push($pid)->toArray();
|
|
|
|
|
|
|
|
$filtered = UserFilter::whereUserId($pid)
|
2018-11-16 03:52:36 +00:00
|
|
|
->whereFilterableType('App\Profile')
|
|
|
|
->whereIn('filter_type', ['mute', 'block'])
|
|
|
|
->pluck('filterable_id')->toArray();
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$timeline = Status::whereIn('profile_id', $following)
|
2018-08-31 03:47:25 +00:00
|
|
|
->whereNotIn('profile_id', $filtered)
|
2018-08-10 03:18:56 +00:00
|
|
|
->whereHas('media')
|
2018-09-01 01:50:37 +00:00
|
|
|
->whereVisibility('public')
|
2018-09-12 02:55:19 +00:00
|
|
|
->orderBy('created_at', 'desc')
|
2018-07-12 16:37:31 +00:00
|
|
|
->withCount(['comments', 'likes', 'shares'])
|
2018-08-10 03:18:56 +00:00
|
|
|
->simplePaginate(20);
|
2018-11-20 01:50:28 +00:00
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
$type = 'personal';
|
|
|
|
|
|
|
|
return view('timeline.template', compact('timeline', 'type'));
|
2018-07-12 16:37:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 07:49:05 +00:00
|
|
|
public function changeLocale(Request $request, $locale)
|
|
|
|
{
|
2018-11-16 03:52:36 +00:00
|
|
|
// todo: add other locales after pushing new l10n strings
|
|
|
|
$locales = ['en'];
|
|
|
|
if(in_array($locale, $locales)) {
|
|
|
|
session()->put('locale', $locale);
|
2018-06-05 07:49:05 +00:00
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
|
2018-06-05 07:49:05 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
2018-08-10 03:18:56 +00:00
|
|
|
|
|
|
|
public function about()
|
|
|
|
{
|
2018-12-04 20:46:07 +00:00
|
|
|
$stats = Cache::remember('site:about:stats', 1440, function() {
|
|
|
|
return [
|
|
|
|
'posts' => Status::whereLocal(true)->count(),
|
|
|
|
'users' => User::count(),
|
|
|
|
'admin' => User::whereIsAdmin(true)->first()
|
|
|
|
];
|
|
|
|
});
|
|
|
|
return view('site.about', compact('stats'));
|
2018-11-16 03:52:36 +00:00
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
|
2018-11-16 03:52:36 +00:00
|
|
|
public function language()
|
|
|
|
{
|
|
|
|
return view('site.language');
|
2018-08-10 03:18:56 +00:00
|
|
|
}
|
2018-06-01 03:12:06 +00:00
|
|
|
}
|