pixelfed/app/Http/Controllers/SiteController.php

66 lines
1.9 KiB
PHP
Raw Normal View History

2018-06-01 03:12:06 +00:00
<?php
namespace App\Http\Controllers;
2018-08-10 03:18:56 +00:00
use App, Auth, Cache;
2018-06-01 03:12:06 +00:00
use Illuminate\Http\Request;
2018-08-10 03:18:56 +00:00
use App\{Follower, Profile, Status, User};
use App\Util\Lexer\PrettyNumber;
2018-06-01 03:12:06 +00:00
class SiteController extends Controller
{
2018-07-12 16:37:31 +00:00
public function home()
{
if(Auth::check()) {
return $this->homeTimeline();
} else {
return $this->homeGuest();
}
}
public function homeGuest()
{
2018-08-10 05:42:12 +00:00
return view('welcome');
2018-07-12 16:37:31 +00:00
}
public function homeTimeline()
{
// TODO: Use redis for timelines
$following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
$following->push(Auth::user()->profile->id);
$timeline = Status::whereIn('profile_id', $following)
2018-08-10 03:18:56 +00:00
->whereHas('media')
2018-07-12 16:37:31 +00:00
->orderBy('id','desc')
->withCount(['comments', 'likes', 'shares'])
2018-08-10 03:18:56 +00:00
->simplePaginate(20);
$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)
{
if(!App::isLocale($locale)) {
return redirect()->back();
}
App::setLocale($locale);
return redirect()->back();
}
2018-08-10 03:18:56 +00:00
public function about()
{
$res = Cache::remember('site:page:about', 15, function() {
$statuses = Status::whereHas('media')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();
$statusCount = PrettyNumber::convert($statuses);
$userCount = PrettyNumber::convert(User::count());
$remoteCount = PrettyNumber::convert(Profile::whereNotNull('remote_url')->count());
$adminContact = User::whereIsAdmin(true)->first();
return view('site.about')->with(compact('statusCount', 'userCount', 'remoteCount', 'adminContact'))->render();
});
return $res;
}
2018-06-01 03:12:06 +00:00
}