2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2021-12-14 18:32:47 +00:00
|
|
|
use MicroHTML\HTMLElement;
|
2022-10-27 16:21:46 +00:00
|
|
|
|
2021-12-14 18:32:47 +00:00
|
|
|
use function MicroHTML\emptyHTML;
|
|
|
|
use function MicroHTML\rawHTML;
|
|
|
|
use function MicroHTML\TABLE;
|
|
|
|
use function MicroHTML\TBODY;
|
|
|
|
use function MicroHTML\TFOOT;
|
|
|
|
use function MicroHTML\TR;
|
|
|
|
use function MicroHTML\TH;
|
|
|
|
use function MicroHTML\TD;
|
|
|
|
use function MicroHTML\LABEL;
|
|
|
|
use function MicroHTML\INPUT;
|
|
|
|
use function MicroHTML\SMALL;
|
|
|
|
use function MicroHTML\A;
|
|
|
|
use function MicroHTML\BR;
|
|
|
|
use function MicroHTML\P;
|
|
|
|
use function MicroHTML\SELECT;
|
|
|
|
use function MicroHTML\OPTION;
|
2007-07-16 19:47:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class UserPageTheme extends Themelet
|
|
|
|
{
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_login_page(Page $page): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$page->set_title("Login");
|
|
|
|
$page->set_heading("Login");
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block(
|
|
|
|
"Login There",
|
|
|
|
"There should be a login box to the left"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
2024-01-20 19:47:26 +00:00
|
|
|
* @param array<int, array{name: string|HTMLElement, link: string}> $parts
|
2024-01-20 14:10:59 +00:00
|
|
|
*/
|
|
|
|
public function display_user_links(Page $page, User $user, array $parts): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
# $page->add_block(new Block("User Links", join(", ", $parts), "main", 10));
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
2024-01-20 19:47:26 +00:00
|
|
|
* @param array<array{link: string, name: string|HTMLElement}> $parts
|
2024-01-20 14:10:59 +00:00
|
|
|
*/
|
|
|
|
public function display_user_block(Page $page, User $user, array $parts): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-12 15:26:29 +00:00
|
|
|
$html = emptyHTML('Logged in as ', $user->name);
|
2019-05-28 16:59:38 +00:00
|
|
|
foreach ($parts as $part) {
|
2020-01-12 15:26:29 +00:00
|
|
|
$html->appendChild(BR());
|
2023-11-11 21:49:12 +00:00
|
|
|
$html->appendChild(A(["href" => $part["link"]], $part["name"]));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2023-06-27 10:59:39 +00:00
|
|
|
$b = new Block("User Links", $html, "left", 90);
|
2020-06-24 14:40:25 +00:00
|
|
|
$b->is_content = false;
|
|
|
|
$page->add_block($b);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_signup_page(Page $page): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2023-12-26 23:47:12 +00:00
|
|
|
global $config, $user;
|
2019-05-28 16:59:38 +00:00
|
|
|
$tac = $config->get_string("login_tac", "");
|
|
|
|
|
|
|
|
if ($config->get_bool("login_tac_bbcode")) {
|
2023-12-26 23:47:12 +00:00
|
|
|
$tac = send_event(new TextFormattingEvent($tac))->formatted;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2023-12-26 23:47:12 +00:00
|
|
|
$email_required = (
|
|
|
|
$config->get_bool("user_email_required") &&
|
|
|
|
!$user->can(Permissions::CREATE_OTHER_USER)
|
|
|
|
);
|
|
|
|
|
2020-01-26 13:25:02 +00:00
|
|
|
$form = SHM_SIMPLE_FORM(
|
2020-01-30 10:31:11 +00:00
|
|
|
"user_admin/create",
|
2020-01-12 15:26:29 +00:00
|
|
|
TABLE(
|
2023-11-11 21:49:12 +00:00
|
|
|
["class" => "form"],
|
2020-01-12 15:26:29 +00:00
|
|
|
TBODY(
|
|
|
|
TR(
|
|
|
|
TH("Name"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'text', "name" => 'name', "required" => true]))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
TR(
|
|
|
|
TH("Password"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass1', "required" => true]))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
TR(
|
|
|
|
TH(rawHTML("Repeat Password")),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass2', "required" => true]))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
TR(
|
2023-12-26 23:47:12 +00:00
|
|
|
TH($email_required ? "Email" : rawHTML("Email (Optional)")),
|
|
|
|
TD(INPUT(["type" => 'email', "name" => 'email', "required" => $email_required]))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
TR(
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(["colspan" => "2"], rawHTML(captcha_get_html()))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
TFOOT(
|
2023-11-11 21:49:12 +00:00
|
|
|
TR(TD(["colspan" => "2"], INPUT(["type" => "submit", "value" => "Create Account"])))
|
2020-01-12 15:26:29 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-12 15:26:29 +00:00
|
|
|
$html = emptyHTML(
|
2020-03-18 17:29:08 +00:00
|
|
|
$tac ? P(rawHTML($tac)) : null,
|
2020-01-12 15:26:29 +00:00
|
|
|
$form
|
|
|
|
);
|
2007-07-16 19:47:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title("Create Account");
|
|
|
|
$page->set_heading("Create Account");
|
|
|
|
$page->add_block(new NavBlock());
|
2023-06-27 10:59:39 +00:00
|
|
|
$page->add_block(new Block("Signup", $html));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_user_creator(): void
|
2020-05-19 18:33:51 +00:00
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
|
|
|
|
$form = SHM_SIMPLE_FORM(
|
|
|
|
"user_admin/create_other",
|
|
|
|
TABLE(
|
2023-11-11 21:49:12 +00:00
|
|
|
["class" => "form"],
|
2020-05-19 18:33:51 +00:00
|
|
|
TBODY(
|
|
|
|
TR(
|
|
|
|
TH("Name"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'text', "name" => 'name', "required" => true]))
|
2020-05-19 18:33:51 +00:00
|
|
|
),
|
|
|
|
TR(
|
|
|
|
TH("Password"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass1', "required" => true]))
|
2020-05-19 18:33:51 +00:00
|
|
|
),
|
|
|
|
TR(
|
|
|
|
TH(rawHTML("Repeat Password")),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass2', "required" => true]))
|
2020-05-19 18:33:51 +00:00
|
|
|
),
|
|
|
|
TR(
|
2023-12-26 23:47:12 +00:00
|
|
|
TH(rawHTML("Email")),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'email', "name" => 'email']))
|
2020-05-19 18:33:51 +00:00
|
|
|
),
|
2023-12-26 23:47:12 +00:00
|
|
|
TR(
|
|
|
|
TD(["colspan" => 2], rawHTML("(Email is optional for admin-created accounts)")),
|
|
|
|
),
|
2020-05-19 18:33:51 +00:00
|
|
|
),
|
|
|
|
TFOOT(
|
2023-11-11 21:49:12 +00:00
|
|
|
TR(TD(["colspan" => "2"], INPUT(["type" => "submit", "value" => "Create Account"])))
|
2020-05-19 18:33:51 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$page->add_block(new Block("Create User", (string)$form, "main", 75));
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_signups_disabled(Page $page): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$page->set_title("Signups Disabled");
|
|
|
|
$page->set_heading("Signups Disabled");
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block(
|
|
|
|
"Signups Disabled",
|
|
|
|
"The board admin has disabled the ability to create new accounts~"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_login_block(Page $page): void
|
2023-12-26 23:47:12 +00:00
|
|
|
{
|
|
|
|
$page->add_block(new Block("Login", $this->create_login_block(), "left", 90));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create_login_block(): HTMLElement
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-11-28 21:32:18 +00:00
|
|
|
global $config, $user;
|
2020-01-26 13:25:02 +00:00
|
|
|
$form = SHM_SIMPLE_FORM(
|
2020-01-30 10:31:11 +00:00
|
|
|
"user_admin/login",
|
2020-01-12 15:26:29 +00:00
|
|
|
TABLE(
|
2023-11-11 21:49:12 +00:00
|
|
|
["style" => "width: 100%", "class" => "form"],
|
2020-01-12 15:26:29 +00:00
|
|
|
TBODY(
|
|
|
|
TR(
|
2023-11-11 21:49:12 +00:00
|
|
|
TH(LABEL(["for" => "user"], "Name")),
|
|
|
|
TD(INPUT(["id" => "user", "type" => "text", "name" => "user", "autocomplete" => "username"]))
|
2020-01-12 15:26:29 +00:00
|
|
|
),
|
|
|
|
TR(
|
2023-11-11 21:49:12 +00:00
|
|
|
TH(LABEL(["for" => "pass"], "Password")),
|
|
|
|
TD(INPUT(["id" => "pass", "type" => "password", "name" => "pass", "autocomplete" => "current-password"]))
|
2020-01-12 15:26:29 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
TFOOT(
|
2023-11-11 21:49:12 +00:00
|
|
|
TR(TD(["colspan" => "2"], INPUT(["type" => "submit", "value" => "Log In"])))
|
2020-01-12 15:26:29 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$html = emptyHTML();
|
|
|
|
$html->appendChild($form);
|
2019-11-28 21:32:18 +00:00
|
|
|
if ($config->get_bool("login_signup_enabled") && $user->can(Permissions::CREATE_USER)) {
|
2023-11-11 21:49:12 +00:00
|
|
|
$html->appendChild(SMALL(A(["href" => make_link("user_admin/create")], "Create Account")));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-01-12 15:26:29 +00:00
|
|
|
|
2023-12-26 23:47:12 +00:00
|
|
|
return $html;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, int> $ips
|
|
|
|
*/
|
2021-03-14 23:43:50 +00:00
|
|
|
private function _ip_list(string $name, array $ips): HTMLElement
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-16 19:13:12 +00:00
|
|
|
$td = TD("$name: ");
|
2019-05-28 16:59:38 +00:00
|
|
|
$n = 0;
|
2020-01-16 19:13:12 +00:00
|
|
|
foreach ($ips as $ip => $count) {
|
|
|
|
$td->appendChild(BR());
|
|
|
|
$td->appendChild("$ip ($count)");
|
2019-05-28 16:59:38 +00:00
|
|
|
if (++$n >= 20) {
|
2020-01-16 19:13:12 +00:00
|
|
|
$td->appendChild(BR());
|
|
|
|
$td->appendChild("...");
|
2019-05-28 16:59:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 19:13:12 +00:00
|
|
|
return $td;
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, int> $uploads
|
|
|
|
* @param array<string, int> $comments
|
|
|
|
* @param array<string, int> $events
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_ip_list(Page $page, array $uploads, array $comments, array $events): void
|
2020-01-16 19:13:12 +00:00
|
|
|
{
|
|
|
|
$html = TABLE(
|
2023-11-11 21:49:12 +00:00
|
|
|
["id" => "ip-history"],
|
2020-01-16 19:13:12 +00:00
|
|
|
TR(
|
|
|
|
$this->_ip_list("Uploaded from", $uploads),
|
|
|
|
$this->_ip_list("Commented from", $comments),
|
|
|
|
$this->_ip_list("Logged Events", $events)
|
|
|
|
),
|
|
|
|
TR(
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(["colspan" => "3"], "(Most recent at top)")
|
2020-01-16 19:13:12 +00:00
|
|
|
)
|
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2023-06-27 10:59:39 +00:00
|
|
|
$page->add_block(new Block("IPs", $html, "main", 70));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param string[] $stats
|
|
|
|
*/
|
|
|
|
public function display_user_page(User $duser, array $stats): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-10-02 10:23:57 +00:00
|
|
|
global $page;
|
2019-05-28 16:59:38 +00:00
|
|
|
$stats[] = 'User ID: '.$duser->id;
|
|
|
|
|
|
|
|
$page->set_title(html_escape($duser->name)."'s Page");
|
|
|
|
$page->set_heading(html_escape($duser->name)."'s Page");
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Stats", join("<br>", $stats), "main", 10));
|
|
|
|
}
|
|
|
|
|
2020-10-26 15:13:28 +00:00
|
|
|
|
|
|
|
public function build_operations(User $duser, UserOperationsBuildingEvent $event): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config, $user;
|
2020-01-16 19:13:12 +00:00
|
|
|
$html = emptyHTML();
|
2019-10-02 10:23:57 +00:00
|
|
|
|
2020-01-16 19:13:12 +00:00
|
|
|
// just a fool-admin protection so they dont mess around with anon users.
|
|
|
|
if ($duser->id != $config->get_int('anon_id')) {
|
2019-07-09 14:10:21 +00:00
|
|
|
if ($user->can(Permissions::EDIT_USER_NAME)) {
|
2020-01-16 19:13:12 +00:00
|
|
|
$html->appendChild(SHM_USER_FORM(
|
|
|
|
$duser,
|
|
|
|
"user_admin/change_name",
|
|
|
|
"Change Name",
|
|
|
|
TBODY(TR(
|
|
|
|
TH("New name"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'text', "name" => 'name', "value" => $duser->name]))
|
2020-01-16 19:13:12 +00:00
|
|
|
)),
|
|
|
|
"Set"
|
|
|
|
));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2015-07-12 21:14:57 +00:00
|
|
|
|
2020-01-16 19:13:12 +00:00
|
|
|
$html->appendChild(SHM_USER_FORM(
|
|
|
|
$duser,
|
|
|
|
"user_admin/change_pass",
|
|
|
|
"Change Password",
|
|
|
|
TBODY(
|
|
|
|
TR(
|
|
|
|
TH("Password"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass1', "autocomplete" => 'new-password']))
|
2020-01-16 19:13:12 +00:00
|
|
|
),
|
|
|
|
TR(
|
|
|
|
TH("Repeat Password"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'password', "name" => 'pass2', "autocomplete" => 'new-password']))
|
2020-01-16 19:13:12 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
"Set"
|
|
|
|
));
|
2012-01-22 19:14:35 +00:00
|
|
|
|
2020-01-16 19:13:12 +00:00
|
|
|
$html->appendChild(SHM_USER_FORM(
|
|
|
|
$duser,
|
|
|
|
"user_admin/change_email",
|
|
|
|
"Change Email",
|
|
|
|
TBODY(TR(
|
|
|
|
TH("Address"),
|
2023-11-11 21:49:12 +00:00
|
|
|
TD(INPUT(["type" => 'text', "name" => 'address', "value" => $duser->email, "autocomplete" => 'email', "inputmode" => 'email']))
|
2020-01-16 19:13:12 +00:00
|
|
|
)),
|
|
|
|
"Set"
|
|
|
|
));
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
if ($user->can(Permissions::EDIT_USER_CLASS)) {
|
2023-11-11 21:49:12 +00:00
|
|
|
$select = SELECT(["name" => "class"]);
|
2024-01-20 19:52:18 +00:00
|
|
|
foreach (UserClass::$known_classes as $name => $values) {
|
2020-01-16 19:13:12 +00:00
|
|
|
$select->appendChild(
|
2023-11-11 21:49:12 +00:00
|
|
|
OPTION(["value" => $name, "selected" => $name == $duser->class->name], ucwords($name))
|
2020-01-16 19:13:12 +00:00
|
|
|
);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-01-16 19:13:12 +00:00
|
|
|
$html->appendChild(SHM_USER_FORM(
|
|
|
|
$duser,
|
|
|
|
"user_admin/change_class",
|
|
|
|
"Change Class",
|
|
|
|
TBODY(TR(TD($select))),
|
|
|
|
"Set"
|
|
|
|
));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2012-03-31 18:25:27 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
if ($user->can(Permissions::DELETE_USER)) {
|
2020-01-16 19:13:12 +00:00
|
|
|
$html->appendChild(SHM_USER_FORM(
|
|
|
|
$duser,
|
|
|
|
"user_admin/delete_user",
|
|
|
|
"Delete User",
|
|
|
|
TBODY(
|
2023-11-11 21:49:12 +00:00
|
|
|
TR(TD(LABEL(INPUT(["type" => 'checkbox', "name" => 'with_images']), "Delete images"))),
|
|
|
|
TR(TD(LABEL(INPUT(["type" => 'checkbox', "name" => 'with_comments']), "Delete comments"))),
|
2020-01-16 19:13:12 +00:00
|
|
|
),
|
|
|
|
TFOOT(
|
2023-11-11 21:49:12 +00:00
|
|
|
TR(TD(INPUT(["type" => 'button', "class" => 'shm-unlocker', "data-unlock-sel" => '.deluser', "value" => 'Unlock']))),
|
|
|
|
TR(TD(INPUT(["type" => 'submit', "class" => 'deluser', "value" => 'Delete User', "disabled" => 'true']))),
|
2020-01-16 19:13:12 +00:00
|
|
|
)
|
|
|
|
));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-01-16 19:13:12 +00:00
|
|
|
|
2024-03-28 12:42:39 +00:00
|
|
|
foreach ($event->get_parts() as $part) {
|
2019-06-27 13:12:15 +00:00
|
|
|
$html .= $part;
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-01-26 13:19:35 +00:00
|
|
|
return (string)$html;
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-08-02 20:05:49 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
public function get_help_html(): HTMLElement
|
2019-08-02 20:05:49 +00:00
|
|
|
{
|
|
|
|
global $user;
|
2020-10-26 15:14:03 +00:00
|
|
|
$output = emptyHTML(P("Search for posts posted by particular individuals."));
|
2020-01-16 19:13:12 +00:00
|
|
|
$output->appendChild(SHM_COMMAND_EXAMPLE(
|
|
|
|
"poster=username",
|
2020-10-26 15:14:03 +00:00
|
|
|
'Returns posts posted by "username".'
|
2020-01-16 19:13:12 +00:00
|
|
|
));
|
|
|
|
$output->appendChild(SHM_COMMAND_EXAMPLE(
|
|
|
|
"poster_id=123",
|
2020-10-26 15:14:03 +00:00
|
|
|
'Returns posts posted by user 123.'
|
2020-01-16 19:13:12 +00:00
|
|
|
));
|
2019-08-02 20:05:49 +00:00
|
|
|
|
|
|
|
if ($user->can(Permissions::VIEW_IP)) {
|
2020-01-16 19:13:12 +00:00
|
|
|
$output->appendChild(SHM_COMMAND_EXAMPLE(
|
|
|
|
"poster_ip=127.0.0.1",
|
2020-10-26 15:14:03 +00:00
|
|
|
"Returns posts posted from IP 127.0.0.1."
|
2020-01-16 19:13:12 +00:00
|
|
|
));
|
2019-08-02 20:05:49 +00:00
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
2023-06-24 12:09:21 +00:00
|
|
|
|
2023-06-24 20:24:25 +00:00
|
|
|
/**
|
|
|
|
* @param Page $page
|
|
|
|
* @param UserClass[] $classes
|
|
|
|
* @param \ReflectionClassConstant[] $permissions
|
|
|
|
*/
|
2023-06-24 18:35:03 +00:00
|
|
|
public function display_user_classes(Page $page, array $classes, array $permissions): void
|
|
|
|
{
|
2023-11-11 21:49:12 +00:00
|
|
|
$table = TABLE(["class" => "zebra"]);
|
2023-06-24 12:09:21 +00:00
|
|
|
|
|
|
|
$row = TR();
|
2023-06-24 20:24:25 +00:00
|
|
|
$row->appendChild(TH("Permission"));
|
2023-06-24 12:09:21 +00:00
|
|
|
foreach ($classes as $class) {
|
2023-06-24 23:26:34 +00:00
|
|
|
$n = $class->name;
|
2023-06-25 10:17:56 +00:00
|
|
|
if ($class->parent) {
|
2023-06-24 23:26:34 +00:00
|
|
|
$n .= " ({$class->parent->name})";
|
|
|
|
}
|
|
|
|
$row->appendChild(TH($n));
|
2023-06-24 12:09:21 +00:00
|
|
|
}
|
2023-06-24 20:24:25 +00:00
|
|
|
$row->appendChild(TH("Description"));
|
2023-06-24 12:09:21 +00:00
|
|
|
$table->appendChild($row);
|
|
|
|
|
2023-06-24 20:24:25 +00:00
|
|
|
foreach ($permissions as $perm) {
|
2023-06-24 12:09:21 +00:00
|
|
|
$row = TR();
|
2023-06-24 20:24:25 +00:00
|
|
|
$row->appendChild(TH($perm->getName()));
|
|
|
|
|
2023-06-24 12:09:21 +00:00
|
|
|
foreach ($classes as $class) {
|
2023-06-24 23:26:34 +00:00
|
|
|
$opacity = array_key_exists($perm->getValue(), $class->abilities) ? 1 : 0.2;
|
2023-06-25 10:17:56 +00:00
|
|
|
if ($class->can($perm->getValue())) {
|
2023-11-11 21:49:12 +00:00
|
|
|
$cell = TD(["style" => "color: green; opacity: $opacity;"], "✔");
|
2023-06-24 18:35:03 +00:00
|
|
|
} else {
|
2023-11-11 21:49:12 +00:00
|
|
|
$cell = TD(["style" => "color: red; opacity: $opacity;"], "✘");
|
2023-06-24 12:09:21 +00:00
|
|
|
}
|
|
|
|
$row->appendChild($cell);
|
|
|
|
}
|
2023-06-24 20:24:25 +00:00
|
|
|
|
|
|
|
$doc = $perm->getDocComment();
|
2023-06-25 10:17:56 +00:00
|
|
|
if ($doc) {
|
2024-08-31 18:53:07 +00:00
|
|
|
$doc = preg_replace_ex('/\/\*\*|\n\s*\*\s*|\*\//', '', $doc);
|
2023-11-11 21:49:12 +00:00
|
|
|
$row->appendChild(TD(["style" => "text-align: left;"], $doc));
|
2023-06-24 20:24:25 +00:00
|
|
|
} else {
|
|
|
|
$row->appendChild(TD(""));
|
|
|
|
}
|
|
|
|
|
2023-06-24 12:09:21 +00:00
|
|
|
$table->appendChild($row);
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->set_title("User Classes");
|
|
|
|
$page->set_heading("User Classes");
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Classes", $table, "main", 10));
|
|
|
|
}
|
2007-07-16 19:47:25 +00:00
|
|
|
}
|