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

View file

@ -1,4 +1,6 @@
<?php <?php
use function MicroHTML\{FORM,INPUT};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc * * Misc *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -516,13 +518,11 @@ function _fatal_error(Exception $e): void
{ {
$version = VERSION; $version = VERSION;
$message = $e->getMessage(); $message = $e->getMessage();
$phpver = phpversion();
//$trace = var_dump($e->getTrace());
//$hash = exec("git rev-parse HEAD"); //$hash = exec("git rev-parse HEAD");
//$h_hash = $hash ? "<p><b>Hash:</b> $hash" : ""; //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
//'.$h_hash.' //'.$h_hash.'
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
print("Trace: "); print("Trace: ");
@ -540,7 +540,6 @@ function _fatal_error(Exception $e): void
print("Query: {$e->query}\n"); print("Query: {$e->query}\n");
} }
$phpver = phpversion();
print("Version: $version (on $phpver)\n"); print("Version: $version (on $phpver)\n");
} }
else { else {
@ -555,7 +554,7 @@ function _fatal_error(Exception $e): void
<h1>Internal Error</h1> <h1>Internal Error</h1>
<p><b>Message:</b> '.html_escape($message).' <p><b>Message:</b> '.html_escape($message).'
'.$q.' '.$q.'
<p><b>Version:</b> '.$version.' (on '.phpversion().') <p><b>Version:</b> '.$version.' (on '.$phpver.')
</body> </body>
</html> </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; 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 <?php
use function MicroHTML\{LABEL,A,B,IMG,TABLE,THEAD,TFOOT,TBODY,TH,TR,TD,INPUT,DIV,P,BR,emptyHTML};
class ExtManagerTheme extends Themelet class ExtManagerTheme extends Themelet
{ {
/** /**
@ -7,149 +9,92 @@ class ExtManagerTheme extends Themelet
*/ */
public function display_table(Page $page, array $extensions, bool $editable) public function display_table(Page $page, array $extensions, bool $editable)
{ {
$h_en = $editable ? "<th>Enabled</th>" : ""; $tbody = TBODY();
$html = "
" . make_form(make_link("ext_manager/set")) . " $form = SHM_FORM(make_link("ext_manager/set"));
<table id='extensions' class='zebra sortable'> $form->appendChild(TABLE(
<thead> ["id"=>'extensions', "class"=>'zebra sortable'],
<tr> THEAD(TR(
$h_en $editable ? TH("Enabled") : null,
<th>Name</th> TH("Name"),
<th>Docs</th> TH("Docs"),
<th>Description</th> TH("Description")
</tr> )),
</thead> $tbody,
<tbody> $editable ? TFOOT(TR(TD(["colspan"=>'5'], INPUT(["type"=>'submit', "value"=>'Set Extensions'])))) : null
"; ));
foreach ($extensions as $extension) { foreach ($extensions as $extension) {
if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN) if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN)
|| $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) { || $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) {
continue; continue;
} }
$h_name = html_escape(($extension->beta===true ? "[BETA] ":"").(empty($extension->name) ? $extension->key : $extension->name)); $tbody->appendChild(TR(
$h_description = html_escape($extension->description); ["data-ext"=>$extension->name],
$h_link = make_link("ext_doc/" . url_escape($extension->key)); $editable ? TD(INPUT([
"type"=>'checkbox',
$h_enabled = ($extension->is_enabled() === true ? " checked='checked'" : ""); "name"=>"ext_{$extension->key}",
$h_disabled = ($extension->is_supported()===false || $extension->core===true? " disabled ": " "); "id"=>"ext_{$extension->key}",
"checked"=>($extension->is_enabled() === true),
//baseline_open_in_new_black_18dp.png "disabled"=>($extension->is_supported()===false || $extension->core===true)
])) : null,
$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>" : ""; TD(LABEL(
$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. ["for"=>"ext_{$extension->key}"],
(
$html .= " ($extension->beta===true ? "[BETA] ":"").
<tr data-ext='{$extension->name}'> (empty($extension->name) ? $extension->key : $extension->name)
{$h_enabled_box} )
<td><label for='ext_" . html_escape($extension->key) . "'>{$h_name}</label></td> )),
<td>{$h_docs}</td> TD(
<td style='text-align: left;'>{$h_description} <b style='color:red'>".$extension->get_support_info()."</b></td> // TODO: A proper "docs" symbol would be preferred here.
</tr>"; $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_title("Extensions");
$page->set_heading("Extensions"); $page->set_heading("Extensions");
$page->add_block(new NavBlock()); $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) public function display_doc(Page $page, ExtensionInfo $info)
{ {
$author = ""; $author = emptyHTML();
if (count($info->authors) > 0) { if (count($info->authors) > 0) {
$author = "<br /><b>Author"; $author->appendChild(BR());
if (count($info->authors) > 1) { $author->appendChild(B(count($info->authors) > 1 ? "Authors" : "Author"));
$author .= "s";
}
$author .= ":</b>";
foreach ($info->authors as $auth=>$email) { foreach ($info->authors as $auth=>$email) {
if (!empty($email)) { if (!empty($email)) {
$author .= "<a href=\"mailto:" . html_escape($email) . "\">" . html_escape($auth) . "</a>"; $author->appendChild(A(["href"=>"mailto:$email"], $auth));
} else { } else {
$author .= html_escape($auth); $author->appendChild($auth);
} }
$author .= "<br/>"; $author->appendChild(BR());
} }
} }
$version = ($info->version) ? "<br><b>Version:</b> " . html_escape($info->version) : ""; $html = DIV(
$link = ($info->link) ? "<br><b>Home Page:</b> <a href=\"" . html_escape($info->link) . "\">Link</a>" : ""; ["style"=>'margin: auto; text-align: left; width: 512px;'],
$doc = $info->documentation; $author,
$html = " ($info->version ? emptyHTML(BR(), B("Version"), $info->version) : null),
<div style='margin: auto; text-align: left; width: 512px;'> ($info->link ? emptyHTML(BR(), B("Home Page"), A(["href"=>$info->link], "Link")) : null),
$author P($info->documentation),
$version // <hr>,
$link P(A(["href"=>make_link("ext_manager")], "Back to the list"))
<p>$doc );
<hr>
<p><a href='" . make_link("ext_manager") . "'>Back to the list</a>
</div>";
$page->set_title("Documentation for " . html_escape($info->name)); $page->set_title("Documentation for " . html_escape($info->name));
$page->set_heading(html_escape($info->name)); $page->set_heading(html_escape($info->name));