From 6d71cd678e051b1d4f33aae39392320129015ca0 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 16 Mar 2025 18:31:38 +0100 Subject: [PATCH] Separate HTML functions --- adminer/include/bootstrap.inc.php | 1 + adminer/include/functions.inc.php | 540 +----------------------------- adminer/include/html.inc.php | 522 +++++++++++++++++++++++++++++ 3 files changed, 532 insertions(+), 531 deletions(-) create mode 100644 adminer/include/html.inc.php diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index ae06599b..a14a05cb 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -22,6 +22,7 @@ if (function_exists("mb_internal_encoding")) { } include "../adminer/include/functions.inc.php"; +include "../adminer/include/html.inc.php"; // used only in compiled file if (isset($_GET["file"])) { diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 0306b296..d45944fd 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -40,6 +40,15 @@ function idf_unescape($idf) { return str_replace($last . $last, $last, substr($idf, 1, -1)); } +/** Shortcut for $connection->quote($string) +* @param string +* @return string +*/ +function q($string) { + global $connection; + return $connection->quote($string); +} + /** Escape string to use inside '' * @param string * @return string @@ -122,171 +131,6 @@ function charset($connection) { return (min_version("5.5.3", 0, $connection) ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query } -/** Return $trailing"; -} - -/** Return \n"; -} - -/** Get a nonce="" attribute with CSP nonce -* @return string -*/ -function nonce() { - return ' nonce="' . get_nonce() . '"'; -} - -/** Get a target="_blank" attribute -* @return string -*/ -function target_blank() { - return ' target="_blank" rel="noreferrer noopener"'; -} - -/** Escape for HTML -* @param string -* @return string -*/ -function h($string) { - return str_replace("\0", "�", htmlspecialchars($string, ENT_QUOTES, 'utf-8')); -} - -/** Convert \n to
-* @param string -* @return string -*/ -function nl_br($string) { - return str_replace("\n", "
", $string); // nl2br() uses XHTML before PHP 5.3 -} - -/** Generate HTML checkbox -* @param string -* @param string -* @param bool -* @param string -* @param string -* @param string -* @param string -* @return string -*/ -function checkbox($name, $value, $checked, $label = "", $onclick = "", $class = "", $labelled_by = "") { - $return = "" - . ($onclick ? script("qsl('input').onclick = function () { $onclick };", "") : "") - ; - return ($label != "" || $class ? "$return" . h($label) . "" : $return); -} - -/** Generate list of HTML options -* @param array array of strings or arrays (creates optgroup) -* @param mixed -* @param bool always use array keys for value="", otherwise only string keys are used -* @return string -*/ -function optionlist($options, $selected = null, $use_keys = false) { - $return = ""; - foreach ($options as $k => $v) { - $opts = array($k => $v); - if (is_array($v)) { - $return .= ''; - $opts = $v; - } - foreach ($opts as $key => $val) { - $return .= '' . h($val) - ; - } - if (is_array($v)) { - $return .= ''; - } - } - return $return; -} - -/** Generate HTML " . optionlist($options, $value) . "" - . ($onchange ? script("qsl('select').onchange = function () { $onchange };", "") : "") - ; -} - -/** Generate HTML radio list -* @param string -* @param array -* @param string -* @return string -*/ -function html_radios($name, $options, $value = "") { - $return = ""; - foreach ($options as $key => $val) { - $return .= ""; - } - return $return; -} - -/** Get onclick confirmation -* @param string -* @param string -* @return string -*/ -function confirm($message = "", $selector = "qsl('input')") { - return script("$selector.onclick = function () { return confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "'); };", ""); -} - -/** Print header for hidden fieldset (close by ) -* @param string -* @param string -* @param bool -* @return null -*/ -function print_fieldset($id, $legend, $visible = false) { - echo "
"; - echo "$legend"; - echo script("qsl('a').onclick = partial(toggle, 'fieldset-$id');", ""); - echo ""; - echo "
) +* @param string +* @param string +* @param bool +* @return null +*/ +function print_fieldset($id, $legend, $visible = false) { + echo "
"; + echo "$legend"; + echo script("qsl('a').onclick = partial(toggle, 'fieldset-$id');", ""); + echo ""; + echo "