proper support for html in usernav

This commit is contained in:
Shish 2023-07-03 16:03:34 +01:00
parent 463aec6df7
commit f040709a76
3 changed files with 14 additions and 8 deletions

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
require_once "core/event.php";
enum PageMode: string
@ -604,7 +606,7 @@ class PageSubNavBuildingEvent extends Event
$this->parent= $parent;
}
public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50)
public function add_nav_link(string $name, Link $link, string|HTMLElement $desc, ?bool $active = null, int $order = 50)
{
$this->links[] = new NavLink($name, $link, $desc, $active, $order);
}
@ -614,11 +616,11 @@ class NavLink
{
public string $name;
public Link $link;
public string $description;
public string|HTMLElement $description;
public int $order;
public bool $active = false;
public function __construct(String $name, Link $link, String $description, ?bool $active = null, int $order = 50)
public function __construct(string $name, Link $link, string|HTMLElement $description, ?bool $active = null, int $order = 50)
{
global $config;

View File

@ -9,6 +9,8 @@ use GQLA\Field;
use GQLA\Query;
use GQLA\Mutation;
use function MicroHTML\{emptyHTML, SPAN};
class SendPMEvent extends Event
{
public PM $pm;
@ -185,8 +187,8 @@ class PrivMsg extends Extension
if ($event->parent==="user") {
if ($user->can(Permissions::READ_PM)) {
$count = $this->count_pms($user);
$h_count = $count > 0 ? " <span class='unread'>($count)</span>" : "";
$event->add_nav_link("pm", new Link('user#private-messages'), "Private Messages$h_count");
$h_count = $count > 0 ? SPAN(["class"=>'unread'], "($count)") : "";
$event->add_nav_link("pm", new Link('user#private-messages'), emptyHTML("Private Messages", $h_count));
}
}
}
@ -196,8 +198,8 @@ class PrivMsg extends Extension
global $user;
if ($user->can(Permissions::READ_PM)) {
$count = $this->count_pms($user);
$h_count = $count > 0 ? " <span class='unread'>($count)</span>" : "";
$event->add_link("Private Messages$h_count", make_link("user", null, "private-messages"));
$h_count = $count > 0 ? SPAN(["class"=>'unread'], "($count)") : "";
$event->add_link(emptyHTML("Private Messages", $h_count), make_link("user", null, "private-messages"));
}
}

View File

@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement;
class UserBlockBuildingEvent extends Event
{
public array $parts = [];
public function add_link(string $name, string $link, int $position=50): void
public function add_link(string|HTMLElement $name, string $link, int $position=50): void
{
while (isset($this->parts[$position])) {
$position++;