You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.3 KiB
PHP

<?php
namespace Isekai\UserPoints;
use Html;
use MediaWiki\MediaWikiServices;
class Utils {
public static function getPointName($pointType) {
$pointConfig = MediaWikiServices::getInstance()->getMainConfig()->get('IsekaiUserPointConfig');
if (!isset($pointConfig[$pointType])) {
return '{' . $pointType . '}';
} else {
$currentConfig = $pointConfig[$pointType];
if (isset($currentConfig['namemsg'])) {
return wfMessage($currentConfig['namemsg'])->text();
} else {
return $currentConfig['name'];
}
}
}
public static function getPointIcon($pointType) {
$pointConfig = MediaWikiServices::getInstance()->getMainConfig()->get('IsekaiUserPointConfig');
if (!isset($pointConfig[$pointType])) {
return '';
}
$currentConfig = $pointConfig[$pointType];
if (!isset($currentConfig['icon']) || !isset($currentConfig['icon']['normal'])) {
return '';
}
$iconDom = [];
foreach(['normal', 'invert'] as $iconType) {
if (!isset($currentConfig['icon'][$iconType])) {
continue;
}
$iconConfig = $currentConfig['icon'][$iconType] ?? $currentConfig['icon']['normal'];
$className = $iconConfig['class'] ?? [];
if (is_string($className)) {
$className = explode(' ', $className);
}
$className[] = 'isekai-point-icon-' . $iconType;
if (isset($iconConfig['image'])) {
$iconDom[] = Html::element('img', [
'src' => $iconConfig['image'],
'class' => implode(' ', $className),
]);
} elseif (isset($iconConfig['html'])) {
$iconDom[] = Html::rawElement('span', [
'class' => implode(' ', $className),
], $iconConfig['html']);
} else {
$text = $iconConfig['text'] ?? '';
$iconDom[] = Html::element('span', [
'class' => implode(' ', $className),
], $text);
}
}
return Html::rawElement('span', [
'class' => "isekai-point-icon isekai-point-icon-type-$pointType"
], implode('', $iconDom));
}
}