mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
* Add Smarty and Twig template engines * Update composer.json * Convert Widgets class to template engine and PHPStan fixes * Fix widget initialisation * Fix panel widget initialisation * chore: remove debug return * feat: convert 403/404 pages to new template system and general tidy * chore: style fixes * feat: update latest pages to new template engine * feat: template base should not be nullable in onPageLoad * feat: set template base directory upon initialisation and allow custom smarty security directories * chore: fix style
74 lines
3.3 KiB
PHP
74 lines
3.3 KiB
PHP
<?php
|
|
|
|
class MinecraftAccountProfileWidget extends ProfileWidgetBase {
|
|
|
|
private Cache $_cache;
|
|
private Language $_language;
|
|
|
|
public function __construct(TemplateEngine $engine, Cache $cache, Language $language) {
|
|
$this->_name = 'Minecraft Account';
|
|
$this->_description = 'Displays a users Minecraft account on their profile.';
|
|
$this->_module = 'Core';
|
|
|
|
$this->_engine = $engine;
|
|
$this->_cache = $cache;
|
|
$this->_language = $language;
|
|
}
|
|
|
|
public function initialise(User $user): void {
|
|
$integrationUser = $user->getIntegration('Minecraft');
|
|
if ($integrationUser === null || !$integrationUser->exists() || !$integrationUser->isVerified()) {
|
|
$this->_content = '';
|
|
return;
|
|
}
|
|
|
|
$config_path = defined('CONFIG_PATH')
|
|
? CONFIG_PATH
|
|
: '';
|
|
|
|
$this->_engine->addVariables([
|
|
'USERNAME' => $integrationUser->data()->username,
|
|
'UUID' => $integrationUser->data()->identifier,
|
|
'UUID_FORMATTED' => ProfileUtils::formatUUID($integrationUser->data()->identifier),
|
|
'LAST_SEEN_TEXT' => $this->_language->get('user', 'last_seen'),
|
|
'ON' => $this->_language->get('general', 'on'),
|
|
'MINECRAFT_ACCOUNT' => $this->_language->get('user', 'minecraft_account'),
|
|
'MINECRAFT_FONT_URL' => $config_path . '/core/assets/vendor/skinview3d/assets/minecraft.woff2',
|
|
// TODO: can't use AssetTree since this JS is included before the asset JS is included
|
|
// so it can't resolve the skinview3d object
|
|
'SKINVIEW_3D_JS_URL' => $config_path . '/core/assets/vendor/skinview3d/bundles/skinview3d.bundle.js',
|
|
]);
|
|
|
|
$this->_cache->setCache('minecraft_last_online');
|
|
if ($this->_cache->isCached($integrationUser->data()->identifier)) {
|
|
[$last_online, $server_id] = $this->_cache->retrieve($integrationUser->data()->identifier);
|
|
$server = DB::getInstance()->get('mc_servers', $server_id);
|
|
if ($server->count()) {
|
|
$server = $server->first();
|
|
$server_name = $server->name;
|
|
$server_ip = $server->ip;
|
|
} else {
|
|
$this->_engine->addVariable('SERVER_UNKNOWN', true);
|
|
$server_name = $this->_language->get('admin', 'unknown');
|
|
$server_ip = $this->_language->get('admin', 'unknown');
|
|
}
|
|
|
|
$this->_engine->addVariables([
|
|
'LAST_ONLINE' => date(DATE_FORMAT, $last_online),
|
|
'LAST_ONLINE_AGO' => (new TimeAgo(TIMEZONE))->inWords($last_online, $this->_language),
|
|
'LAST_ONLINE_SERVER' => $server_name,
|
|
'LAST_ONLINE_SERVER_IP' => $server_ip
|
|
]);
|
|
} else {
|
|
$this->_engine->addVariables([
|
|
'ALL_UNKNOWN' => true,
|
|
'LAST_ONLINE' => $this->_language->get('admin', 'unknown'),
|
|
'LAST_ONLINE_AGO' => $this->_language->get('admin', 'unknown'),
|
|
'LAST_ONLINE_SERVER' => $this->_language->get('admin', 'unknown'),
|
|
'LAST_ONLINE_SERVER_IP' => $this->_language->get('admin', 'unknown')
|
|
]);
|
|
}
|
|
|
|
$this->_content = $this->_engine->fetch('widgets/minecraft_account');
|
|
}
|
|
}
|