Files
aowow/includes/components/frontend/infoboxmarkup.class.php
Sarjuuk 37380ff515 Frontend/InfoboxMarkup
* you can now pass attributes to the [li] element
2025-11-03 18:47:06 +01:00

67 lines
1.4 KiB
PHP

<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class InfoboxMarkup extends Markup
{
public function __construct(private array $items, array $opts, string $parent = '')
{
parent::__construct('', $opts, $parent);
}
public function addItem(string $item, ?int $pos = null) : void
{
if (is_null($pos) || $pos >= count($this->items))
$this->items[] = $item;
else
array_splice($this->items, $pos, 0, $item);
}
public function append(string $text) : self
{
if ($_ = $this->prepare())
$this->replace($_);
return parent::append($text);
}
public function __toString() : string
{
if ($_ = $this->prepare())
$this->replace($_);
return parent::__toString();
}
public function getJsGlobals() : array
{
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]' : '';
}
}
?>