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-03-24 04:31:42 +00:00
|
|
|
$mode = (string)($_GET['m'] ?? 'view');
|
2018-03-22 17:56:35 +00:00
|
|
|
|
2018-03-24 04:31:42 +00:00
|
|
|
switch ($mode) {
|
|
|
|
case 'avatar':
|
|
|
|
$avatar_filename = $app->getPath(
|
2018-04-24 22:55:46 +00:00
|
|
|
$app->getConfig()->get('Avatar', 'default_path', 'string', 'public/images/no-avatar.png')
|
2018-03-24 04:31:42 +00:00
|
|
|
);
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$user_avatar = "{$user_id}.msz";
|
|
|
|
$cropped_avatar = $app->getStore('avatars/200x200')->filename($user_avatar);
|
|
|
|
|
|
|
|
if (File::exists($cropped_avatar)) {
|
|
|
|
$avatar_filename = $cropped_avatar;
|
|
|
|
} else {
|
|
|
|
$original_avatar = $app->getStore('avatars/original')->filename($user_avatar);
|
|
|
|
|
|
|
|
if (File::exists($original_avatar)) {
|
|
|
|
try {
|
|
|
|
File::writeAll(
|
|
|
|
$cropped_avatar,
|
|
|
|
crop_image_centred_path($original_avatar, 200, 200)->getImagesBlob()
|
|
|
|
);
|
|
|
|
|
|
|
|
$avatar_filename = $cropped_avatar;
|
|
|
|
} catch (Exception $ex) {
|
2018-03-24 04:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: ' . mime_content_type($avatar_filename));
|
|
|
|
echo File::readToEnd($avatar_filename);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'view':
|
|
|
|
default:
|
2018-04-26 15:01:59 +00:00
|
|
|
$templating = $app->getTemplating();
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$getProfile = Database::connection()->prepare('
|
|
|
|
SELECT
|
|
|
|
u.*,
|
|
|
|
r.`role_title` as `user_title`,
|
|
|
|
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `display_colour`
|
|
|
|
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-04-26 15:01:59 +00:00
|
|
|
echo $templating->render('user.notfound');
|
2018-03-24 04:31:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$templating->vars(compact('profile'));
|
2018-04-26 15:01:59 +00:00
|
|
|
echo $templating->render('user.view');
|
2018-03-24 04:31:42 +00:00
|
|
|
break;
|
|
|
|
}
|