2018-03-14 01:39:02 +00:00
|
|
|
<?php
|
2018-05-16 02:58:21 +00:00
|
|
|
use Misuzu\Database;
|
2018-03-24 04:31:42 +00:00
|
|
|
use Misuzu\IO\File;
|
2018-03-14 01:39:02 +00:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../misuzu.php';
|
|
|
|
|
2018-03-22 17:56:35 +00:00
|
|
|
$user_id = (int)($_GET['u'] ?? 0);
|
2018-09-17 09:20:15 +00:00
|
|
|
$mode = (string)($_GET['m'] ?? null);
|
2018-03-22 17:56:35 +00:00
|
|
|
|
2018-03-24 04:31:42 +00:00
|
|
|
switch ($mode) {
|
|
|
|
case 'avatar':
|
2018-09-15 23:27:12 +00:00
|
|
|
$avatar_filename = $app->getDefaultAvatar();
|
2018-05-16 02:58:21 +00:00
|
|
|
$user_avatar = "{$user_id}.msz";
|
2018-09-16 00:21:13 +00:00
|
|
|
$cropped_avatar = build_path(
|
|
|
|
create_directory(build_path($app->getStoragePath(), 'avatars/200x200')),
|
|
|
|
$user_avatar
|
|
|
|
);
|
2018-05-16 02:58:21 +00:00
|
|
|
|
2018-09-16 00:21:13 +00:00
|
|
|
if (is_file($cropped_avatar)) {
|
2018-05-16 02:58:21 +00:00
|
|
|
$avatar_filename = $cropped_avatar;
|
|
|
|
} else {
|
2018-09-16 00:21:13 +00:00
|
|
|
$original_avatar = build_path($app->getStoragePath(), 'avatars/original', $user_avatar);
|
2018-05-16 02:58:21 +00:00
|
|
|
|
2018-09-16 00:21:13 +00:00
|
|
|
if (is_file($original_avatar)) {
|
2018-05-16 02:58:21 +00:00
|
|
|
try {
|
2018-09-16 00:21:13 +00:00
|
|
|
file_put_contents(
|
2018-05-16 02:58:21 +00:00
|
|
|
$cropped_avatar,
|
2018-09-16 00:21:13 +00:00
|
|
|
crop_image_centred_path($original_avatar, 200, 200)->getImagesBlob(),
|
|
|
|
LOCK_EX
|
2018-05-16 02:58:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$avatar_filename = $cropped_avatar;
|
|
|
|
} catch (Exception $ex) {
|
2018-03-24 04:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: ' . mime_content_type($avatar_filename));
|
2018-09-16 00:21:13 +00:00
|
|
|
echo file_get_contents($avatar_filename);
|
2018-03-24 04:31:42 +00:00
|
|
|
break;
|
|
|
|
|
2018-09-16 01:37:32 +00:00
|
|
|
case 'background':
|
|
|
|
$user_background = build_path(
|
|
|
|
create_directory(build_path($app->getStoragePath(), 'backgrounds/original')),
|
|
|
|
"{$user_id}.msz"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!is_file($user_background)) {
|
|
|
|
echo render_error(404);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: ' . mime_content_type($user_background));
|
|
|
|
echo file_get_contents($user_background);
|
|
|
|
break;
|
|
|
|
|
2018-03-24 04:31:42 +00:00
|
|
|
default:
|
2018-07-15 22:59:14 +00:00
|
|
|
$getProfile = Database::prepare('
|
2018-05-16 02:58:21 +00:00
|
|
|
SELECT
|
|
|
|
u.*,
|
2018-05-27 23:24:16 +00:00
|
|
|
COALESCE(u.`user_title`, r.`role_title`) as `user_title`,
|
2018-07-18 16:01:17 +00:00
|
|
|
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`,
|
2018-05-18 01:20:27 +00:00
|
|
|
(
|
|
|
|
SELECT COUNT(`topic_id`)
|
2018-07-06 01:28:06 +00:00
|
|
|
FROM `msz_forum_topics`
|
|
|
|
WHERE `user_id` = u.`user_id`
|
2018-05-18 01:20:27 +00:00
|
|
|
) as `forum_topic_count`,
|
|
|
|
(
|
|
|
|
SELECT COUNT(`post_id`)
|
2018-07-06 01:28:06 +00:00
|
|
|
FROM `msz_forum_posts`
|
|
|
|
WHERE `user_id` = u.`user_id`
|
|
|
|
) as `forum_post_count`,
|
|
|
|
(
|
|
|
|
SELECT COUNT(`change_id`)
|
|
|
|
FROM `msz_changelog_changes`
|
|
|
|
WHERE `user_id` = u.`user_id`
|
2018-08-12 13:35:50 +00:00
|
|
|
) as `changelog_count`,
|
|
|
|
(
|
|
|
|
SELECT COUNT(`comment_id`)
|
|
|
|
FROM `msz_comments_posts`
|
|
|
|
WHERE `user_id` = u.`user_id`
|
|
|
|
) as `comments_count`
|
2018-05-16 02:58:21 +00:00
|
|
|
FROM `msz_users` as u
|
|
|
|
LEFT JOIN `msz_roles` as r
|
|
|
|
ON r.`role_id` = u.`display_role`
|
|
|
|
WHERE `user_id` = :user_id
|
|
|
|
');
|
|
|
|
$getProfile->bindValue('user_id', $user_id);
|
|
|
|
$profile = $getProfile->execute() ? $getProfile->fetch() : [];
|
|
|
|
|
|
|
|
if (!$profile) {
|
2018-03-24 04:31:42 +00:00
|
|
|
http_response_code(404);
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('user.notfound');
|
2018-03-24 04:31:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-16 01:37:32 +00:00
|
|
|
tpl_vars([
|
|
|
|
'profile' => $profile,
|
|
|
|
'has_background' => is_file(build_path($app->getStoragePath(), 'backgrounds/original', "{$profile['user_id']}.msz")),
|
|
|
|
]);
|
2018-09-17 09:20:15 +00:00
|
|
|
echo tpl_render('user.profile');
|
2018-03-24 04:31:42 +00:00
|
|
|
break;
|
|
|
|
}
|