mc-cms-namelessmc/modules/Core/queries/user.php
Sam ba6d81b77c
Merge commit from fork
Co-authored-by: Sam <samerton@users.noreply.github.com>
2026-03-15 18:43:46 +00:00

82 lines
2.4 KiB
PHP

<?php
/**
* Query to retrieve public data about a user
* Gets user ID from 'id' GET request
*
* @author Samerton
* @version 2.2.0
* @var Cache $cache
* @var FakeSmarty $smarty
* @var Navigation $cc_nav
* @var Navigation $navigation
* @var Navigation $staffcp_nav
* @var Pages $pages
* @var TemplateBase $template
* @var User $user
* @var Widgets $widgets
*/
// Check user ID is specified
if (!isset($_GET['id'])) {
die(json_encode(['html' => 'Error: Invalid ID']));
}
const PAGE = 'user_query';
$page_title = 'user_query';
require_once ROOT_PATH . '/core/templates/frontend_init.php';
if (!is_numeric($_GET['id'])) {
$username = preg_replace('/[^a-zA-Z0-9_]/', '', $_GET['id']);
$nickname = $username;
$profile = URL::build('/profile/' . $username);
$avatar = (isset($_GET['uuid']) ? AvatarSource::getAvatarFromUUID(
preg_replace('/[^a-zA-Z0-9\-]/', '', $_GET['uuid'])
) : AvatarSource::getAvatarFromUUID($username));
$style = '';
$groups = [];
$id = 0;
} else {
$cache->setCache('user_query');
[$username, $nickname, $profile, $avatar, $style, $groups, $id] = $cache->fetch($_GET['id'], function () {
$target_user = new User($_GET['id']);
if (!$target_user->exists()) {
die(json_encode(['html' => 'User not found']));
}
$username = $target_user->getDisplayname(true);
$nickname = $target_user->getDisplayname();
$profile = $target_user->getProfileURL();
$avatar = $target_user->getAvatar();
$style = $target_user->getGroupStyle();
$groups = $target_user->getAllGroupHtml();
$id = Output::getClean($target_user->data()->id);
return [$username, $nickname, $profile, $avatar, $style, $groups, $id];
}, 60);
}
$template->getEngine()->addVariables([
'PROFILE' => $profile,
'USERNAME' => $username,
'NICKNAME' => $nickname,
'AVATAR' => $avatar,
'STYLE' => $style,
'GROUPS' => $groups,
'USER_ID' => $id
]);
// Load modules + template
Module::loadPage($user, $pages, $cache, $smarty, [$navigation, $cc_nav, $staffcp_nav], $widgets, $template);
$template->onPageLoad();
echo json_encode([
'id' => $id,
'profile' => $profile,
'username' => $username,
'nickname' => $nickname,
'avatar' => $avatar,
'style' => $style,
'groups' => $groups,
'html' => $template->getTemplate('user_popover')
], JSON_PRETTY_PRINT);