Frontend/InfoboxMarkup

* you can now pass attributes to the [li] element
This commit is contained in:
Sarjuuk
2025-11-03 18:00:24 +01:00
parent 8212811970
commit 37380ff515
2 changed files with 40 additions and 7 deletions

View File

@@ -23,27 +23,44 @@ class InfoboxMarkup extends Markup
public function append(string $text) : self
{
if ($this->items && !$this->__text)
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
if ($_ = $this->prepare())
$this->replace($_);
return parent::append($text);
}
public function __toString() : string
{
if ($this->items && !$this->__text)
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
if ($_ = $this->prepare())
$this->replace($_);
return parent::__toString();
}
public function getJsGlobals() : array
{
if ($this->items && !$this->__text)
$this->replace('[ul][li]' . implode('[/li][li]', $this->items) . '[/li][/ul]');
if ($_ = $this->prepare())
$this->replace($_);
return parent::getJsGlobals();
}
private function prepare() : string
{
if (!$this->items || $this->__text)
return '';
$buff = '';
foreach ($this->items as $row)
{
if (is_array($row))
$buff .= '[li'.Util::nodeAttributes($row[1]).']' . $row[0] . '[/li]';
else if (is_string($row))
$buff .= '[li]' . $row . '[/li]';
}
return $buff ? '[ul]'.$buff.'[/ul]' : '';
}
}
?>

View File

@@ -35,7 +35,7 @@ abstract class Util
private static $perfectGems = null;
public static $regions = array(
public static $regions = array(
'us', 'eu', 'kr', 'tw', 'cn', 'dev'
);
@@ -1175,6 +1175,22 @@ abstract class Util
return (string)$var;
}
public static function nodeAttributes(?array $attribs) : string
{
if (!$attribs)
return '';
return array_reduce(array_keys($attribs), fn($carry, $name) => $carry . match(gettype($attribs[$name]))
{
'boolean' => ' ' . $attribs[$name] ? $name : '',
'integer',
'double' => ' ' . $name . '="' . $attribs[$name] . '"',
'string' => ' ' . $name . '="' . self::htmlEscape($attribs[$name]) . '"',
'array' => ' ' . $name . '="' . implode(' ', self::htmlEscape($attribs[$name])) . '"',
default => ''
}, '');
}
public static function buildPosFixMenu(int $mapId, float $posX, float $posY, int $type, int $guid, int $parentArea = 0, int $parentFloor = 0) : array
{
$points = WorldPosition::toZonePos($mapId, $posX, $posY);