From bdbbdbb0eddd125bec167da5f42bbd95c770151f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 16:59:21 +0300 Subject: rework controls to accept parameters as array --- include/controls.php | 47 ++++++++++++++++++++++++++++++----------------- include/login_form.php | 3 ++- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/controls.php b/include/controls.php index b351a9449..78ff75572 100755 --- a/include/controls.php +++ b/include/controls.php @@ -1,19 +1,30 @@ ".htmlspecialchars($value).""; + function attributes_to_string(array $attributes) { + $rv = ""; + + foreach ($attributes as $k => $v) { + $rv .= "$k=\"" . htmlspecialchars($v) . "\""; + } + + return $rv; + } + + function button_tag(string $value, string $type, array $attributes = []) { + return ""; } - function submit_tag(string $value, $attributes = "") { - return button_tag($value, "submit", "class=\"alt-primary\" $attributes"); + function submit_tag(string $value, array $attributes = []) { + return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes)); } - function select_tag(string $name, $value, array $values, string $attributes = "", string $id = "") { - $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; + function select_tag(string $name, $value, array $values, array $attributes = [], string $id = "") { + $attributes_str = attributes_to_string($attributes); + $dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; $rv = ""; + id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes_str>"; foreach ($values as $k => $v) { $is_sel = ($k == $value) ? "selected=\"selected\"" : ""; @@ -59,20 +71,21 @@ return $rv; } - function hidden_tag(string $name, string $value) { + function hidden_tag(string $name, string $value, array $attributes = []) { return ""; + ".attributes_to_string($attributes)." name=\"".htmlspecialchars($name)."\" + value=\"".htmlspecialchars($value)."\">"; } - function checkbox_tag(string $name, bool $checked = false, string $value = "", string $attributes = "", string $id = "") { + function checkbox_tag(string $name, bool $checked = false, string $value = "", array $attributes = [], string $id = "") { $is_checked = $checked ? "checked" : ""; $value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : ""; return ""; + $value_str $is_checked ".attributes_to_string($attributes)." id=\"".htmlspecialchars($id)."\">"; } - function select_feeds_cats(string $name, int $default_id = null, string $attributes = "", + function select_feeds_cats(string $name, int $default_id = null, array $attributes = [], bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = "") { $ret = ""; @@ -81,7 +94,7 @@ $ret .= "