From 562a2c8fea292b02ac3a7b57e35c6e8de39c1333 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 9 Dec 2019 14:18:25 +0000 Subject: [PATCH] use microhtml for ext_manager --- composer.json | 1 + composer.lock | 24 ++--- core/util.php | 35 ++++++-- ext/ext_manager/theme.php | 185 ++++++++++++++------------------------ 4 files changed, 110 insertions(+), 135 deletions(-) diff --git a/composer.json b/composer.json index 7d6b166e..2e5f3216 100644 --- a/composer.json +++ b/composer.json @@ -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.*", diff --git a/composer.lock b/composer.lock index c672db7e..e21f4ffc 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [ diff --git a/core/util.php b/core/util.php index 48a4f1c1..3719c4a1 100644 --- a/core/util.php +++ b/core/util.php @@ -1,4 +1,6 @@ getMessage(); - - //$trace = var_dump($e->getTrace()); + $phpver = phpversion(); //$hash = exec("git rev-parse HEAD"); //$h_hash = $hash ? "

Hash: $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

Internal Error

Message: '.html_escape($message).' '.$q.' -

Version: '.$version.' (on '.phpversion().') +

Version: '.$version.' (on '.$phpver.') '; @@ -688,3 +687,29 @@ function make_form(string $target, string $method="POST", bool $multipart=false, } return '

'.$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; +} diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index 173e2e56..628163a0 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -1,5 +1,7 @@ Enabled" : ""; - $html = " - " . make_form(make_link("ext_manager/set")) . " - - - - $h_en - - - - - - - "; + $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 ? "" : ""; - $h_docs = ($extension->documentation ? "" : ""); //TODO: A proper "docs" symbol would be preferred here. - - $html .= " - - {$h_enabled_box} - - - - "; + $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 ? "" : ""; - $html .= " - - $h_set -
NameDocsDescription
{$h_docs}{$h_description} ".$extension->get_support_info()."
-
- "; $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) ? - "link)."\">Original Site" : ""; - $h_doc = isset($extension->documentation) ? - "name))."\">Documentation" : ""; - $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" : - "$h_author"; - - $html = " -

- - - - - - - - - - -
$h_name
By $h_author_linkEnabled: 
$h_description

$h_link $h_doc

- "; - if($n++ % 2 == 0) { - $col_1 .= $html; - } - else { - $col_2 .= $html; - } - } - $html = " - ".make_form(make_link("ext_manager/set"))." - ".$user->get_auth_html()." - - - -
$col_1$col_2
- - "; - - $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 = "
Author"; - if (count($info->authors) > 1) { - $author .= "s"; - } - $author .= ":"; + $author->appendChild(BR()); + $author->appendChild(B(count($info->authors) > 1 ? "Authors" : "Author")); foreach ($info->authors as $auth=>$email) { if (!empty($email)) { - $author .= "" . html_escape($auth) . ""; + $author->appendChild(A(["href"=>"mailto:$email"], $auth)); } else { - $author .= html_escape($auth); + $author->appendChild($auth); } - $author .= "
"; + $author->appendChild(BR()); } } - $version = ($info->version) ? "
Version: " . html_escape($info->version) : ""; - $link = ($info->link) ? "
Home Page: link) . "\">Link" : ""; - $doc = $info->documentation; - $html = " -

- $author - $version - $link -

$doc -


-

Back to the list -

"; + $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), + //
, + 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));