Initial commit

This commit is contained in:
root
2026-05-09 17:28:23 +02:00
commit 9d73f82529
5575 changed files with 281989 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Miscellaneous\WebsiteSetting;
use App\Models\User;
use Carbon\Carbon;
class ProfileController extends Controller
{
public function __invoke(User $user)
{
$user->load([
'friends.friend:id,username,look',
'guilds.guild:id,name,badge',
'profileGuestbook.user:id,username,look',
'photos',
'badges',
]);
$showStats = WebsiteSetting::where('key', 'profile_show_stats')->first()?->value ?? '1';
$showOnline = WebsiteSetting::where('key', 'profile_show_online_status')->first()?->value ?? '1';
$accountAge = $this->getAccountAge($user->account_created);
$lastLogin = $this->getLastLogin($user->last_login);
$totalFriends = $user->friends()->count();
$totalGuilds = $user->guilds()->count();
return view('user.profile', [
'user' => $user,
'friends' => $user->friends->take(10),
'groups' => $user->guilds->take(5),
'guestbook' => $user->profileGuestbook->take(5),
'photos' => $user->photos->take(3),
'badges' => $user->badges->take(3),
'showStats' => $showStats,
'showOnline' => $showOnline,
'accountAge' => $accountAge,
'lastLogin' => $lastLogin,
'totalFriends' => $totalFriends,
'totalGuilds' => $totalGuilds,
]);
}
private function getAccountAge(int $timestamp): string
{
$created = Carbon::createFromTimestamp($timestamp);
$now = Carbon::now();
$days = $created->diffInDays($now);
if ($days < 7) {
return $days . ' day' . ($days !== 1 ? 's' : '');
} elseif ($days < 30) {
$weeks = floor($days / 7);
return $weeks . ' week' . ($weeks !== 1 ? 's' : '');
} elseif ($days < 365) {
$months = floor($days / 30);
return $months . ' month' . ($months !== 1 ? 's' : '');
} else {
$years = floor($days / 365);
return $years . ' year' . ($years !== 1 ? 's' : '');
}
}
private function getLastLogin(int $timestamp): string
{
$lastLogin = Carbon::createFromTimestamp($timestamp);
$now = Carbon::now();
$diff = $now->diffInMinutes($lastLogin);
if ($diff < 1) {
return 'Just now';
} elseif ($diff < 60) {
return $diff . ' minute' . ($diff !== 1 ? 's' : '') . ' ago';
} elseif ($diff < 1440) {
$hours = floor($diff / 60);
return $hours . ' hour' . ($hours !== 1 ? 's' : '') . ' ago';
} elseif ($diff < 10080) {
$days = floor($diff / 1440);
return $days . ' day' . ($days !== 1 ? 's' : '') . ' ago';
} else {
return $lastLogin->format('d M Y');
}
}
}