From 22a3efe4ed0b287ec6431fc1147d65a07b8ad7e9 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 16 Mar 2025 23:54:25 +0100 Subject: [PATCH] Code style: avoid excesive mixing of PHP and HTML --- adminer/create.inc.php | 51 +++++++++------------- adminer/include/design.inc.php | 23 ++++------ adminer/include/editing.inc.php | 72 +++++++++++++++---------------- adminer/include/functions.inc.php | 12 +----- adminer/include/html.inc.php | 4 +- adminer/include/lang.inc.php | 4 +- adminer/sql.inc.php | 4 +- phpcs.xml | 10 ++++- plugins/drivers/mongo.php | 4 +- 9 files changed, 81 insertions(+), 103 deletions(-) diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 8a3c8f63..e02452d6 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -180,31 +180,26 @@ foreach ($engines as $engine) {

- -: data-maxlength="64" value="" autocapitalize="off"> - "(" . lang('engine') . ")") + $engines, $row["Engine"]) . on_help("getTarget(event).value", 1) . script("qsl('select').onchange = helpClose;") : ""); ?> - \n"; + echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . on_help("getTarget(event).value", 1) . script("qsl('select').onchange = helpClose;") . "\n" : ""); if ($collations) { echo "" . optionlist($collations) . ""; echo (preg_match("~sqlite|mssql~", JUSH) ? "" : ""); } - ?> - - + echo "'>\n"; +} - -

- -\n"; + echo "
\n"; edit_fields($row["fields"], $collations, "TABLE", $foreign_keys); - ?> -
- -
-

-: "> - -\n"; + echo script("editFields();"); + echo "\n

\n"; + echo lang('Auto Increment') . "\n"; + echo checkbox("defaults", 1, ($_POST ? $_POST["defaults"] : get_setting("defaults")), lang('Default values'), "columnShow(this.checked, 5)", "jsonly"); $comments = ($_POST ? $_POST["comments"] : get_setting("comments")); echo (support("comment") ? checkbox("comments", 1, $comments, lang('Comment'), "editingCommentsClick(this, true);", "jsonly") @@ -226,24 +221,18 @@ foreach ($engines as $engine) { if (support("partitioning")) { $partition_table = preg_match('~RANGE|LIST~', $row["partition_by"]); print_fieldset("partition", lang('Partition by'), $row["partition_by"]); - ?> -

- "") + $partition_by, $row["partition_by"]) . on_help("getTarget(event).value.replace(/./, 'PARTITION BY \$&')", 1) . script("qsl('select').onchange = partitionByChange;"); ?> -(">) -: " value=""> -> - -" . html_select("partition_by", array("" => "") + $partition_by, $row["partition_by"]) . on_help("getTarget(event).value.replace(/./, 'PARTITION BY \$&')", 1) . script("qsl('select').onchange = partitionByChange;"); + echo "()\n"; + echo lang('Partitions') . ": \n"; + echo "\n"; + echo "\n"; foreach ($row["partition_names"] as $key => $val) { echo ''; echo ' - -\n\n"; } ?> diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 38c621c5..1754608f 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -66,21 +66,16 @@ fQIDAQAB $_COOKIE["adminer_version"] = $version["version"]; // doesn't need to send to the browser } } - ?> -> -mixin(document.body, {onkeydown: bodyKeydown, onclick: bodyClick}); + echo script("mixin(document.body, {onkeydown: bodyKeydown, onclick: bodyClick" + . (isset($_COOKIE["adminer_version"]) ? "" : ", onload: partial(verifyVersion, '$VERSION', '" . js_escape(ME) . "', '" . get_token() . "')") // $token may be empty in auth.inc.php + . "}); document.body.className = document.body.className.replace(/ nojs/, ' js'); -var offlineMessage = ''; -var thousandsSeparator = ''; - - -

- - -
-
\n"; + echo script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});"); + echo "
\n"; if ($breadcrumb !== null) { $link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1); echo '

" . lang('You have no privileges to update this table.') . "\n"; } else { diff --git a/adminer/include/lang.inc.php b/adminer/include/lang.inc.php index accff558..a7376386 100644 --- a/adminer/include/lang.inc.php +++ b/adminer/include/lang.inc.php @@ -77,8 +77,8 @@ function lang($idf, $number = null) { : ($LANG == 'lt' ? ($number % 10 == 1 && $number % 100 != 11 ? 0 : ($number % 10 > 1 && $number / 10 % 10 != 1 ? 1 : 2)) // different forms for 1, 12-19, other : ($LANG == 'lv' ? ($number % 10 == 1 && $number % 100 != 11 ? 0 : ($number ? 1 : 2)) // different forms for 1 except 11, other, 0 : (in_array($LANG, array('bs', 'ru', 'sr', 'uk')) ? ($number % 10 == 1 && $number % 100 != 11 ? 0 : ($number % 10 > 1 && $number % 10 < 5 && $number / 10 % 10 != 1 ? 1 : 2)) // different forms for 1 except 11, 2-4 except 12-14, other - : 1 // different forms for 1, other - )))))))); // http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html + : 1)))))))) // different forms for 1, other + ; // http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html $translation = $translation[$pos]; } $args = func_get_args(); diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index c36b29a5..d2f401f3 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -90,8 +90,8 @@ if (!$error && $_POST) { $pattern = ($found == '/*' ? '\*/' : ($found == '[' ? ']' : (preg_match('~^-- |^#~', $found) ? "\n" - : preg_quote($found) . ($c_style_escapes ? "|\\\\." : "") - ))); + : preg_quote($found) . ($c_style_escapes ? "|\\\\." : ""))) + ); while (preg_match("($pattern|\$)s", $query, $match, PREG_OFFSET_CAPTURE, $offset)) { $s = $match[0][0]; diff --git a/phpcs.xml b/phpcs.xml index bc76b8a1..76288eee 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -32,11 +32,19 @@ - + + + + + + + + + adminer/drivers/ adminer/include/pdo.inc.php diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index a8ef94a2..ac7912fd 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -73,8 +73,8 @@ if (isset($_GET["mongo"])) { (is_a($val, 'MongoDB\BSON\Binary') ? $val->getData() : //! allow downloading (is_a($val, 'MongoDB\BSON\Regex') ? "$val" : (is_object($val) || is_array($val) ? json_encode($val, 256) : // 256 = JSON_UNESCAPED_UNICODE - $val // MongoMinKey, MongoMaxKey - ))))); + $val))))) // MongoMinKey, MongoMaxKey + ; } $this->rows[] = $row; foreach ($row as $key => $val) {