2026-02-04 23:31:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
use MintyPHP\Service\User\UserServicesFactory;
|
2026-02-04 23:31:53 +01:00
|
|
|
use MintyPHP\Support\Guard;
|
|
|
|
|
|
2026-02-11 19:28:12 +01:00
|
|
|
define('MINTY_ALLOW_OUTPUT', true);
|
|
|
|
|
|
2026-02-04 23:31:53 +01:00
|
|
|
Guard::requireLogin();
|
2026-02-23 12:58:19 +01:00
|
|
|
$userServicesFactory = new UserServicesFactory();
|
|
|
|
|
$userAccountService = $userServicesFactory->createUserAccountService();
|
|
|
|
|
$userAvatarService = $userServicesFactory->createUserAvatarService();
|
2026-02-04 23:31:53 +01:00
|
|
|
|
|
|
|
|
$uuid = trim((string) ($_GET['uuid'] ?? ''));
|
|
|
|
|
$size = isset($_GET['size']) ? (int) $_GET['size'] : null;
|
2026-02-23 12:58:19 +01:00
|
|
|
if (!$userAvatarService->isValidUuid($uuid)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
http_response_code(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$currentUserId = (int) ($_SESSION['user']['id'] ?? 0);
|
2026-02-23 12:58:19 +01:00
|
|
|
$user = $uuid !== '' ? $userAccountService->findByUuid($uuid) : null;
|
2026-02-04 23:31:53 +01:00
|
|
|
$userId = (int) ($user['id'] ?? 0);
|
2026-02-23 12:58:19 +01:00
|
|
|
if ($userId > 0 && $currentUserId !== $userId && !directoryServicesFactory()->createDirectoryScopeGateway()->canAccess('users', $userId, $currentUserId)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
http_response_code(403);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$path = $userAvatarService->findAvatarPath($uuid, $size);
|
2026-02-04 23:31:53 +01:00
|
|
|
if (!$path || !is_file($path)) {
|
|
|
|
|
http_response_code(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$mime = $userAvatarService->detectMime($path);
|
2026-02-04 23:31:53 +01:00
|
|
|
header('Content-Type: ' . $mime);
|
|
|
|
|
header('X-Content-Type-Options: nosniff');
|
|
|
|
|
header('Content-Security-Policy: sandbox');
|
|
|
|
|
header('Cache-Control: private, max-age=300');
|
|
|
|
|
header('Content-Length: ' . filesize($path));
|
|
|
|
|
readfile($path);
|