use microhtml for ext_manager

This commit is contained in:
Shish 2019-12-09 14:18:25 +00:00
parent 5a7af0f083
commit 562a2c8fea
4 changed files with 110 additions and 135 deletions

View file

@ -36,6 +36,7 @@
"shish/eventtracer-php" : "dev-master",
"shish/ffsphp" : "0.0.*",
"shish/microcrud" : "dev-master",
"shish/microhtml" : "^1.0.0",
"enshrined/svg-sanitize" : "0.8.*",
"bower-asset/jquery" : "1.12.*",

24
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "599bc5009cfcad0fdbf40925bbed4493",
"content-hash": "f6ab14a66aa01232794ac310aab1c06c",
"packages": [
{
"name": "bower-asset/jquery",
@ -388,19 +388,19 @@
"source": {
"type": "git",
"url": "https://github.com/shish/microcrud.git",
"reference": "060c30d1a7414cf3242f26aaf689d7c8683fb345"
"reference": "8ffe9514490e356897aa2bb2c4df5ce63b82bd2d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/microcrud/zipball/060c30d1a7414cf3242f26aaf689d7c8683fb345",
"reference": "060c30d1a7414cf3242f26aaf689d7c8683fb345",
"url": "https://api.github.com/repos/shish/microcrud/zipball/8ffe9514490e356897aa2bb2c4df5ce63b82bd2d",
"reference": "8ffe9514490e356897aa2bb2c4df5ce63b82bd2d",
"shasum": ""
},
"require": {
"ext-pdo": "*",
"php": ">=7.2",
"shish/ffsphp": "0.0.*",
"shish/microhtml": "0.0.*"
"shish/microhtml": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "8.*"
@ -429,20 +429,24 @@
"crud",
"generator"
],
<<<<<<< HEAD
"time": "2019-12-07T22:47:15+00:00"
=======
"time": "2019-12-09T13:30:51+00:00"
>>>>>>> use microhtml for ext_manager
},
{
"name": "shish/microhtml",
"version": "v0.0.2",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/shish/microhtml.git",
"reference": "76d923e69d140c638995bbe6f24085a9108950f1"
"reference": "1b81c6537eee07e7ba7fb4dbbf9ba2173e8c436c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/microhtml/zipball/76d923e69d140c638995bbe6f24085a9108950f1",
"reference": "76d923e69d140c638995bbe6f24085a9108950f1",
"url": "https://api.github.com/repos/shish/microhtml/zipball/1b81c6537eee07e7ba7fb4dbbf9ba2173e8c436c",
"reference": "1b81c6537eee07e7ba7fb4dbbf9ba2173e8c436c",
"shasum": ""
},
"require": {
@ -475,7 +479,7 @@
"generator",
"html"
],
"time": "2019-11-25T18:12:07+00:00"
"time": "2019-12-09T12:12:14+00:00"
}
],
"packages-dev": [

View file

@ -1,4 +1,6 @@
<?php
use function MicroHTML\{FORM,INPUT};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -516,13 +518,11 @@ function _fatal_error(Exception $e): void
{
$version = VERSION;
$message = $e->getMessage();
//$trace = var_dump($e->getTrace());
$phpver = phpversion();
//$hash = exec("git rev-parse HEAD");
//$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
//'.$h_hash.'
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
print("Trace: ");
@ -540,7 +540,6 @@ function _fatal_error(Exception $e): void
print("Query: {$e->query}\n");
}
$phpver = phpversion();
print("Version: $version (on $phpver)\n");
}
else {
@ -555,7 +554,7 @@ function _fatal_error(Exception $e): void
<h1>Internal Error</h1>
<p><b>Message:</b> '.html_escape($message).'
'.$q.'
<p><b>Version:</b> '.$version.' (on '.phpversion().')
<p><b>Version:</b> '.$version.' (on '.$phpver.')
</body>
</html>
';
@ -688,3 +687,29 @@ function make_form(string $target, string $method="POST", bool $multipart=false,
}
return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$extra_inputs;
}
function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit="") {
global $user;
$attrs = [
"action"=>$target,
"method"=>$method
];
if($form_id) {
$attrs["id"] = $form_id;
}
if ($multipart) {
$attrs["enctype"] = 'multipart/form-data';
}
if ($onsubmit) {
$attrs["onsubmit"] = $onsubmit;
}
$f = FORM(
$attrs,
INPUT(["type"=>"hidden", "name"=>"q", "value"=>$target]),
$method != "GET" ? "" : $user->get_auth_html()
);
return $f;
}

View file

@ -1,5 +1,7 @@
<?php
use function MicroHTML\{LABEL,A,B,IMG,TABLE,THEAD,TFOOT,TBODY,TH,TR,TD,INPUT,DIV,P,BR,emptyHTML};
class ExtManagerTheme extends Themelet
{
/**
@ -7,149 +9,92 @@ class ExtManagerTheme extends Themelet
*/
public function display_table(Page $page, array $extensions, bool $editable)
{
$h_en = $editable ? "<th>Enabled</th>" : "";
$html = "
" . make_form(make_link("ext_manager/set")) . "
<table id='extensions' class='zebra sortable'>
<thead>
<tr>
$h_en
<th>Name</th>
<th>Docs</th>
<th>Description</th>
</tr>
</thead>
<tbody>
";
$tbody = TBODY();
$form = SHM_FORM(make_link("ext_manager/set"));
$form->appendChild(TABLE(
["id"=>'extensions', "class"=>'zebra sortable'],
THEAD(TR(
$editable ? TH("Enabled") : null,
TH("Name"),
TH("Docs"),
TH("Description")
)),
$tbody,
$editable ? TFOOT(TR(TD(["colspan"=>'5'], INPUT(["type"=>'submit', "value"=>'Set Extensions'])))) : null
));
foreach ($extensions as $extension) {
if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN)
|| $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) {
continue;
}
$h_name = html_escape(($extension->beta===true ? "[BETA] ":"").(empty($extension->name) ? $extension->key : $extension->name));
$h_description = html_escape($extension->description);
$h_link = make_link("ext_doc/" . url_escape($extension->key));
$h_enabled = ($extension->is_enabled() === true ? " checked='checked'" : "");
$h_disabled = ($extension->is_supported()===false || $extension->core===true? " disabled ": " ");
//baseline_open_in_new_black_18dp.png
$h_enabled_box = $editable ? "<td><input type='checkbox' name='ext_" . html_escape($extension->key) . "' id='ext_" . html_escape($extension->key) . "'$h_disabled $h_enabled></td>" : "";
$h_docs = ($extension->documentation ? "<a href='$h_link'><img src='ext/ext_manager/baseline_open_in_new_black_18dp.png'/></a>" : ""); //TODO: A proper "docs" symbol would be preferred here.
$html .= "
<tr data-ext='{$extension->name}'>
{$h_enabled_box}
<td><label for='ext_" . html_escape($extension->key) . "'>{$h_name}</label></td>
<td>{$h_docs}</td>
<td style='text-align: left;'>{$h_description} <b style='color:red'>".$extension->get_support_info()."</b></td>
</tr>";
$tbody->appendChild(TR(
["data-ext"=>$extension->name],
$editable ? TD(INPUT([
"type"=>'checkbox',
"name"=>"ext_{$extension->key}",
"id"=>"ext_{$extension->key}",
"checked"=>($extension->is_enabled() === true),
"disabled"=>($extension->is_supported()===false || $extension->core===true)
])) : null,
TD(LABEL(
["for"=>"ext_{$extension->key}"],
(
($extension->beta===true ? "[BETA] ":"").
(empty($extension->name) ? $extension->key : $extension->name)
)
)),
TD(
// TODO: A proper "docs" symbol would be preferred here.
$extension->documentation ?
A(
["href"=>make_link("ext_doc/" . url_escape($extension->key))],
IMG(["src"=>'ext/ext_manager/baseline_open_in_new_black_18dp.png'])
) :
null
),
TD(
["style"=>'text-align: left;'],
$extension->description,
" ",
B(["style"=>'color:red'], $extension->get_support_info())
),
));
}
$h_set = $editable ? "<tfoot><tr><td colspan='5'><input type='submit' value='Set Extensions'></td></tr></tfoot>" : "";
$html .= "
</tbody>
$h_set
</table>
</form>
";
$page->set_title("Extensions");
$page->set_heading("Extensions");
$page->add_block(new NavBlock());
$page->add_block(new Block("Extension Manager", $html));
$page->add_block(new Block("Extension Manager", $form));
}
/*
public function display_blocks(Page $page, $extensions) {
global $user;
$col_1 = "";
$col_2 = "";
foreach($extensions as $extension) {
$ext_name = $extension->name;
$h_name = empty($extension->name) ? $ext_name : html_escape($extension->name);
$h_email = html_escape($extension->email);
$h_link = isset($extension->link) ?
"<a href=\"".html_escape($extension->link)."\">Original Site</a>" : "";
$h_doc = isset($extension->documentation) ?
"<a href=\"".make_link("ext_doc/".html_escape($extension->name))."\">Documentation</a>" : "";
$h_author = html_escape($extension->author);
$h_description = html_escape($extension->description);
$h_enabled = $extension->is_enabled() ? " checked='checked'" : "";
$h_author_link = empty($h_email) ?
"$h_author" :
"<a href='mailto:$h_email'>$h_author</a>";
$html = "
<p><table border='1'>
<tr>
<th colspan='2'>$h_name</th>
</tr>
<tr>
<td>By $h_author_link</td>
<td width='25%'>Enabled:&nbsp;<input type='checkbox' name='ext_$ext_name'$h_enabled></td>
</tr>
<tr>
<td style='text-align: left' colspan='2'>$h_description<p>$h_link $h_doc</td>
</tr>
</table>
";
if($n++ % 2 == 0) {
$col_1 .= $html;
}
else {
$col_2 .= $html;
}
}
$html = "
".make_form(make_link("ext_manager/set"))."
".$user->get_auth_html()."
<table border='0'>
<tr><td width='50%'>$col_1</td><td>$col_2</td></tr>
<tr><td colspan='2'><input type='submit' value='Set Extensions'></td></tr>
</table>
</form>
";
$page->set_title("Extensions");
$page->set_heading("Extensions");
$page->add_block(new NavBlock());
$page->add_block(new Block("Extension Manager", $html));
}
*/
public function display_doc(Page $page, ExtensionInfo $info)
{
$author = "";
$author = emptyHTML();
if (count($info->authors) > 0) {
$author = "<br /><b>Author";
if (count($info->authors) > 1) {
$author .= "s";
}
$author .= ":</b>";
$author->appendChild(BR());
$author->appendChild(B(count($info->authors) > 1 ? "Authors" : "Author"));
foreach ($info->authors as $auth=>$email) {
if (!empty($email)) {
$author .= "<a href=\"mailto:" . html_escape($email) . "\">" . html_escape($auth) . "</a>";
$author->appendChild(A(["href"=>"mailto:$email"], $auth));
} else {
$author .= html_escape($auth);
$author->appendChild($auth);
}
$author .= "<br/>";
$author->appendChild(BR());
}
}
$version = ($info->version) ? "<br><b>Version:</b> " . html_escape($info->version) : "";
$link = ($info->link) ? "<br><b>Home Page:</b> <a href=\"" . html_escape($info->link) . "\">Link</a>" : "";
$doc = $info->documentation;
$html = "
<div style='margin: auto; text-align: left; width: 512px;'>
$author
$version
$link
<p>$doc
<hr>
<p><a href='" . make_link("ext_manager") . "'>Back to the list</a>
</div>";
$html = DIV(
["style"=>'margin: auto; text-align: left; width: 512px;'],
$author,
($info->version ? emptyHTML(BR(), B("Version"), $info->version) : null),
($info->link ? emptyHTML(BR(), B("Home Page"), A(["href"=>$info->link], "Link")) : null),
P($info->documentation),
// <hr>,
P(A(["href"=>make_link("ext_manager")], "Back to the list"))
);
$page->set_title("Documentation for " . html_escape($info->name));
$page->set_heading(html_escape($info->name));