diff --git a/includes/components/frontend/infoboxmarkup.class.php b/includes/components/frontend/infoboxmarkup.class.php index 7e6b5d74..bf6d5d18 100644 --- a/includes/components/frontend/infoboxmarkup.class.php +++ b/includes/components/frontend/infoboxmarkup.class.php @@ -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]' : ''; + } } ?> diff --git a/includes/utilities.php b/includes/utilities.php index 5c1193c4..e6e62dd5 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -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);