2021-07-10 19:18:17 +01:00
|
|
|
<?php
|
2021-07-10 18:21:03 -04:00
|
|
|
define('IN_PONEPASTE', 1);
|
|
|
|
require_once('includes/common.php');
|
2021-07-10 19:18:17 +01:00
|
|
|
require_once('includes/functions.php');
|
|
|
|
|
2022-03-14 15:59:14 -04:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-08-29 01:26:29 -04:00
|
|
|
use PonePaste\Models\User;
|
2021-10-22 21:43:35 -04:00
|
|
|
use PonePaste\Models\Paste;
|
2021-08-29 01:26:29 -04:00
|
|
|
|
2021-07-15 18:06:24 -04:00
|
|
|
if (empty($_GET['user'])) {
|
|
|
|
// No username provided
|
|
|
|
header("Location: ../error.php");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$profile_username = trim($_GET['user']);
|
|
|
|
|
2022-03-12 13:56:32 -05:00
|
|
|
$profile_info = User::with('favourites')
|
|
|
|
->where('username', $profile_username)
|
|
|
|
->select('id', 'date', 'badge')
|
|
|
|
->first();
|
2021-07-15 18:06:24 -04:00
|
|
|
|
|
|
|
if (!$profile_info) {
|
|
|
|
// Invalid username
|
2021-07-12 09:03:02 -04:00
|
|
|
header("Location: ../error.php");
|
|
|
|
die();
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
2021-07-12 09:03:02 -04:00
|
|
|
|
2021-08-26 05:35:21 -04:00
|
|
|
$p_title = $profile_username . "'s Public Pastes";
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2022-03-14 15:59:14 -04:00
|
|
|
// There has to be a way to do the sum in SQL rather than PHP, but I can't figure out ho to do it in Eloquent.
|
|
|
|
$total_pfav = array_sum(
|
|
|
|
array_column(
|
|
|
|
Paste::select('id')
|
|
|
|
->where('user_id', $profile_info->id)
|
|
|
|
->withCount('favouriters')
|
|
|
|
->get()->toArray(),
|
|
|
|
'favouriters_count'
|
|
|
|
)
|
|
|
|
);
|
2021-08-27 06:46:27 -04:00
|
|
|
$total_yfav = $profile_info->favourites->count();
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-07-11 12:44:31 -04:00
|
|
|
// Badges
|
2021-07-15 18:06:24 -04:00
|
|
|
$profile_badge = match ($profile_info['badge']) {
|
2021-08-26 05:58:37 -04:00
|
|
|
1 => '<img src="/img/badges/donate.png" title="[Donated] Donated to Ponepaste" style="margin:5px" alt="Donated to PonePaste" />',
|
|
|
|
2 => '<img src="/img/badges/spoon.png" title="[TheWoodenSpoon] You had one job" style="margin:5px" alt="You had one job" />',
|
|
|
|
3 => '<img src="/img/badges/abadge.png" title="[>AFuckingBadge] Won a PasteJam Competition" style="margin:5px" alt="Won a PasteJam competition" />',
|
2021-07-11 12:44:31 -04:00
|
|
|
default => '',
|
|
|
|
};
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-10-22 21:43:35 -04:00
|
|
|
$profile_total_pastes = $profile_info->pastes->count();
|
|
|
|
$profile_total_public = $profile_info->pastes->where('visible', 0)->count();
|
|
|
|
$profile_total_unlisted = $profile_info->pastes->where('visible', 1)->count();
|
|
|
|
$profile_total_private = $profile_info->pastes->where('visible', 2)->count();
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2021-11-02 08:46:40 -04:00
|
|
|
$profile_total_paste_views = Paste::select('views')->where('user_id', $profile_info->id)->sum('views');
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2021-07-15 18:06:24 -04:00
|
|
|
$profile_join_date = $profile_info['date'];
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2021-10-22 21:43:35 -04:00
|
|
|
$profile_pastes = $profile_info->pastes;
|
2021-08-27 06:46:27 -04:00
|
|
|
$profile_favs = $profile_info->favourites;
|
|
|
|
$is_current_user = ($current_user !== null) && ($profile_info->id == $current_user->id);
|
2021-07-11 12:44:31 -04:00
|
|
|
|
2022-03-12 13:56:32 -05:00
|
|
|
updatePageViews();
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2022-03-14 15:43:01 -04:00
|
|
|
$csrf_token = setupCsrfToken();
|
2022-03-26 23:04:18 -04:00
|
|
|
$page_title = 'Profile of ' . $profile_username;
|
2021-08-22 21:45:26 -04:00
|
|
|
$page_template = 'user_profile';
|
2022-03-12 13:56:32 -05:00
|
|
|
array_push($script_bundles, 'user_profile');
|
2021-08-22 21:45:26 -04:00
|
|
|
require_once('theme/' . $default_theme . '/common.php');
|