misuzu/public/profile.php

57 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2018-03-24 04:31:42 +00:00
use Misuzu\IO\File;
use Misuzu\IO\FileStream;
use Misuzu\Users\User;
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');
$profile_user = User::find($user_id);
2018-03-22 17:56:35 +00:00
2018-03-24 04:31:42 +00:00
switch ($mode) {
case 'avatar':
$avatar_filename = $app->getPath(
$app->config->get('Avatar', 'default_path', 'string', 'public/images/no-avatar.png')
);
if ($profile_user !== null) {
$user_avatar = "{$profile_user->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()
);
2018-03-24 04:31:42 +00:00
$avatar_filename = $cropped_avatar;
} catch (Exception $ex) {
}
}
}
}
header('Content-Type: ' . mime_content_type($avatar_filename));
echo File::readToEnd($avatar_filename);
break;
case 'view':
default:
if ($profile_user === null) {
http_response_code(404);
echo $app->templating->render('user.notfound');
break;
}
$app->templating->var('profile', $profile_user);
echo $app->templating->render('user.view');
break;
}