2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-12-02 17:50:03 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-12-15 15:31:44 +00:00
|
|
|
use function MicroHTML\LABEL;
|
|
|
|
use function MicroHTML\A;
|
|
|
|
use function MicroHTML\B;
|
2024-02-10 19:42:28 +00:00
|
|
|
use function MicroHTML\BR;
|
2019-12-15 15:31:44 +00:00
|
|
|
use function MicroHTML\IMG;
|
|
|
|
use function MicroHTML\TABLE;
|
|
|
|
use function MicroHTML\THEAD;
|
|
|
|
use function MicroHTML\TFOOT;
|
|
|
|
use function MicroHTML\TBODY;
|
|
|
|
use function MicroHTML\TH;
|
|
|
|
use function MicroHTML\TR;
|
|
|
|
use function MicroHTML\TD;
|
|
|
|
use function MicroHTML\INPUT;
|
|
|
|
use function MicroHTML\DIV;
|
|
|
|
use function MicroHTML\P;
|
|
|
|
use function MicroHTML\emptyHTML;
|
2020-03-05 02:09:02 +00:00
|
|
|
use function MicroHTML\rawHTML;
|
2019-12-09 14:18:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class ExtManagerTheme extends Themelet
|
|
|
|
{
|
|
|
|
/**
|
2024-01-01 03:27:39 +00:00
|
|
|
* @param ExtensionInfo[] $extensions
|
2019-05-28 16:59:38 +00:00
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_table(Page $page, array $extensions, bool $editable): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-12-09 14:18:25 +00:00
|
|
|
$tbody = TBODY();
|
|
|
|
|
2020-01-26 13:25:02 +00:00
|
|
|
$form = SHM_SIMPLE_FORM(
|
2020-01-30 10:31:11 +00:00
|
|
|
"ext_manager/set",
|
2020-01-26 13:25:02 +00:00
|
|
|
TABLE(
|
2023-11-11 21:49:12 +00:00
|
|
|
["id" => 'extensions', "class" => 'zebra'],
|
2020-01-26 13:25:02 +00:00
|
|
|
THEAD(TR(
|
|
|
|
$editable ? TH("Enabled") : null,
|
|
|
|
TH("Name"),
|
|
|
|
TH("Docs"),
|
|
|
|
TH("Description")
|
|
|
|
)),
|
|
|
|
$tbody,
|
2023-11-11 21:49:12 +00:00
|
|
|
$editable ? TFOOT(TR(TD(["colspan" => '5'], INPUT(["type" => 'submit', "value" => 'Set Extensions'])))) : null
|
2020-01-26 13:25:02 +00:00
|
|
|
)
|
|
|
|
);
|
2019-12-09 14:18:25 +00:00
|
|
|
|
2024-02-10 19:42:28 +00:00
|
|
|
$categories = [];
|
|
|
|
$last_cat = null;
|
2019-05-28 16:59:38 +00:00
|
|
|
foreach ($extensions as $extension) {
|
2024-02-10 19:42:28 +00:00
|
|
|
if (
|
|
|
|
(!$editable && $extension->visibility === ExtensionVisibility::ADMIN)
|
|
|
|
|| $extension->visibility === ExtensionVisibility::HIDDEN
|
|
|
|
) {
|
2019-05-28 16:59:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-01-05 13:13:11 +00:00
|
|
|
|
2024-08-31 16:05:18 +00:00
|
|
|
if ($extension->category !== $last_cat) {
|
2024-02-10 19:42:28 +00:00
|
|
|
$last_cat = $extension->category;
|
|
|
|
$categories[] = $last_cat;
|
|
|
|
$tbody->appendChild(
|
|
|
|
TR(
|
|
|
|
["class" => 'category', "id" => $extension->category->value],
|
|
|
|
TH(["colspan" => '5'], BR(), $last_cat->value)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-09 14:18:25 +00:00
|
|
|
$tbody->appendChild(TR(
|
2023-11-11 21:49:12 +00:00
|
|
|
["data-ext" => $extension->name],
|
2019-12-09 14:18:25 +00:00
|
|
|
$editable ? TD(INPUT([
|
2023-11-11 21:49:12 +00:00
|
|
|
"type" => 'checkbox',
|
|
|
|
"name" => "ext_{$extension->key}",
|
|
|
|
"id" => "ext_{$extension->key}",
|
|
|
|
"checked" => ($extension->is_enabled() === true),
|
|
|
|
"disabled" => ($extension->is_supported() === false || $extension->core === true)
|
2019-12-09 14:18:25 +00:00
|
|
|
])) : null,
|
|
|
|
TD(LABEL(
|
2023-11-11 21:49:12 +00:00
|
|
|
["for" => "ext_{$extension->key}"],
|
2019-12-09 14:18:25 +00:00
|
|
|
(
|
2023-11-11 21:49:12 +00:00
|
|
|
($extension->beta === true ? "[BETA] " : "").
|
2019-12-09 14:18:25 +00:00
|
|
|
(empty($extension->name) ? $extension->key : $extension->name)
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
TD(
|
|
|
|
// TODO: A proper "docs" symbol would be preferred here.
|
|
|
|
$extension->documentation ?
|
|
|
|
A(
|
2023-11-11 21:49:12 +00:00
|
|
|
["href" => make_link("ext_doc/" . url_escape($extension->key))],
|
|
|
|
IMG(["src" => 'ext/ext_manager/baseline_open_in_new_black_18dp.png'])
|
2019-12-09 14:18:25 +00:00
|
|
|
) :
|
|
|
|
null
|
|
|
|
),
|
|
|
|
TD(
|
2023-11-11 21:49:12 +00:00
|
|
|
["style" => 'text-align: left;'],
|
2019-12-09 14:18:25 +00:00
|
|
|
$extension->description,
|
|
|
|
" ",
|
2023-11-11 21:49:12 +00:00
|
|
|
B(["style" => 'color:red'], $extension->get_support_info())
|
2019-12-09 14:18:25 +00:00
|
|
|
),
|
|
|
|
));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-01-17 02:49:15 +00:00
|
|
|
|
2024-08-31 16:05:18 +00:00
|
|
|
if ($editable) {
|
2024-01-06 21:04:12 +00:00
|
|
|
foreach ($extensions as $extension) {
|
|
|
|
if ($extension->visibility === ExtensionVisibility::HIDDEN && !$extension->core) {
|
|
|
|
$form->appendChild(INPUT([
|
|
|
|
"type" => 'hidden',
|
|
|
|
"name" => "ext_{$extension->key}",
|
|
|
|
"value" => ($extension->is_enabled() === true) ? "on" : "off"
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:42:28 +00:00
|
|
|
$cat_html = [
|
|
|
|
A(["href" => make_link()], "Index"),
|
|
|
|
BR(),
|
|
|
|
];
|
|
|
|
foreach ($categories as $cat) {
|
|
|
|
$cat_html[] = A(["href" => "#".$cat->value], $cat->value);
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title("Extensions");
|
|
|
|
$page->set_heading("Extensions");
|
2024-02-10 19:42:28 +00:00
|
|
|
$page->add_block(new Block("Navigation", \MicroHTML\joinHTML(BR(), $cat_html), "left", 0));
|
2022-10-28 00:45:35 +00:00
|
|
|
$page->add_block(new Block("Extension Manager", $form));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-01-17 02:49:15 +00:00
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_doc(Page $page, ExtensionInfo $info): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2019-12-09 14:18:25 +00:00
|
|
|
$author = emptyHTML();
|
2019-06-15 16:01:13 +00:00
|
|
|
if (count($info->authors) > 0) {
|
2019-12-09 14:18:25 +00:00
|
|
|
$author->appendChild(BR());
|
2020-03-05 02:09:02 +00:00
|
|
|
$author->appendChild(B(count($info->authors) > 1 ? "Authors: " : "Author: "));
|
2023-11-11 21:49:12 +00:00
|
|
|
foreach ($info->authors as $auth => $email) {
|
2019-08-07 19:53:59 +00:00
|
|
|
if (!empty($email)) {
|
2023-11-11 21:49:12 +00:00
|
|
|
$author->appendChild(A(["href" => "mailto:$email"], $auth));
|
2019-06-15 16:01:13 +00:00
|
|
|
} else {
|
2019-12-09 14:18:25 +00:00
|
|
|
$author->appendChild($auth);
|
2019-06-15 16:01:13 +00:00
|
|
|
}
|
2019-12-09 14:18:25 +00:00
|
|
|
$author->appendChild(BR());
|
2019-06-15 16:01:13 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-06-15 16:01:13 +00:00
|
|
|
|
2019-12-09 14:18:25 +00:00
|
|
|
$html = DIV(
|
2023-11-11 21:49:12 +00:00
|
|
|
["style" => 'margin: auto; text-align: left; width: 512px;'],
|
2019-12-09 14:18:25 +00:00
|
|
|
$author,
|
2023-11-11 21:49:12 +00:00
|
|
|
($info->link ? emptyHTML(BR(), B("Home Page"), A(["href" => $info->link], "Link")) : null),
|
2020-03-06 13:44:51 +00:00
|
|
|
P(rawHTML($info->documentation ?? "(This extension has no documentation)")),
|
2019-12-09 14:18:25 +00:00
|
|
|
// <hr>,
|
2023-11-11 21:49:12 +00:00
|
|
|
P(A(["href" => make_link("ext_manager")], "Back to the list"))
|
2019-12-09 14:18:25 +00:00
|
|
|
);
|
2009-01-17 04:00:52 +00:00
|
|
|
|
2019-06-15 16:01:13 +00:00
|
|
|
$page->set_title("Documentation for " . html_escape($info->name));
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_heading(html_escape($info->name));
|
|
|
|
$page->add_block(new NavBlock());
|
2022-10-28 00:45:35 +00:00
|
|
|
$page->add_block(new Block("Documentation", $html));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-12-02 17:50:03 +00:00
|
|
|
}
|