rework controls to accept parameters as array

master
Andrew Dolgov 4 years ago
parent 627af2c236
commit bdbbdbb0ed

@ -608,7 +608,7 @@ class Feeds extends Handler_Protected {
print "<fieldset>"; print "<fieldset>";
print "<label class='inline'>" . __("Language:") . "</label>"; print "<label class='inline'>" . __("Language:") . "</label>";
print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(),
"title=\"".__('Used for word stemming')."\""); ["title" => __('Used for word stemming')]);
print "</fieldset>"; print "</fieldset>";
} }

@ -644,8 +644,10 @@ class Pref_Feeds extends Handler_Protected {
$local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ]; $local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ];
} }
print \Controls\select_hash("purge_interval", $purge_interval, $local_purge_intervals, print \Controls\select_hash("purge_interval",
((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); $purge_interval,
$local_purge_intervals,
(FORCE_ARTICLE_PURGE == 0) ? [] : ["disabled" => 1]);
print "</fieldset>"; print "</fieldset>";
@ -815,8 +817,6 @@ class Pref_Feeds extends Handler_Protected {
print_notice("Enable the options you wish to apply using checkboxes on the right:"); print_notice("Enable the options you wish to apply using checkboxes on the right:");
print "<p>";
print \Controls\hidden_tag("ids", "$feed_ids"); print \Controls\hidden_tag("ids", "$feed_ids");
print \Controls\hidden_tag("op", "pref-feeds"); print \Controls\hidden_tag("op", "pref-feeds");
print \Controls\hidden_tag("method", "batchEditSave"); print \Controls\hidden_tag("method", "batchEditSave");
@ -846,8 +846,7 @@ class Pref_Feeds extends Handler_Protected {
print "<fieldset>"; print "<fieldset>";
print "<label>" . __('Language:') . "</label> "; print "<label>" . __('Language:') . "</label> ";
print \Controls\select_tag("feed_language", "", $this::get_ts_languages(), print \Controls\select_tag("feed_language", "", $this::get_ts_languages(), ["disabled"=> 1]);
'disabled="1"');
$this->batch_edit_cbox("feed_language"); $this->batch_edit_cbox("feed_language");
@ -868,7 +867,7 @@ class Pref_Feeds extends Handler_Protected {
$local_update_intervals = $update_intervals; $local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
print \Controls\select_hash("update_interval", "", $local_update_intervals, 'disabled="1"'); print \Controls\select_hash("update_interval", "", $local_update_intervals, ["disabled" => 1]);
$this->batch_edit_cbox("update_interval"); $this->batch_edit_cbox("update_interval");
@ -890,7 +889,7 @@ class Pref_Feeds extends Handler_Protected {
else else
$local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
print \Controls\select_hash("purge_interval", "", $local_purge_intervals, 'disabled="1"'); print \Controls\select_hash("purge_interval", "", $local_purge_intervals, ["disabled" => 1]);
$this->batch_edit_cbox("purge_interval"); $this->batch_edit_cbox("purge_interval");

@ -894,7 +894,7 @@ class Pref_Filters extends Handler_Protected {
dojoType='fox.form.Select'");*/ dojoType='fox.form.Select'");*/
print \Controls\select_labels("action_param_label", $action_param, print \Controls\select_labels("action_param_label", $action_param,
"style=\"$label_param_hidden\"", ["style" => $label_param_hidden],
"filterDlg_actionParamLabel"); "filterDlg_actionParamLabel");
$filter_actions = PluginHost::getInstance()->get_filter_actions(); $filter_actions = PluginHost::getInstance()->get_filter_actions();
@ -909,16 +909,16 @@ class Pref_Filters extends Handler_Protected {
} }
if (count($filter_action_hash) == 0) { if (count($filter_action_hash) == 0) {
$filter_plugin_disabled = "disabled"; $filter_plugin_disabled = ["disabled" => "1"];
$filter_action_hash["no-data"] = __("No actions available"); $filter_action_hash["no-data"] = __("No actions available");
} else { } else {
$filter_plugin_disabled = ""; $filter_plugin_disabled = [];
} }
print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash, print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash,
"style=\"$plugin_param_hidden\" $filter_plugin_disabled", array_merge(["style" => $plugin_param_hidden], $filter_plugin_disabled),
"filterDlg_actionParamPlugin"); "filterDlg_actionParamPlugin");
print "</span>"; print "</span>";

@ -664,13 +664,13 @@ class Pref_Prefs extends Handler_Protected {
if ($pref_name == "USER_LANGUAGE") { if ($pref_name == "USER_LANGUAGE") {
print \Controls\select_hash($pref_name, $value, get_translations(), print \Controls\select_hash($pref_name, $value, get_translations(),
"style='width : 220px; margin : 0px'"); ["style" => 'width : 220px; margin : 0px']);
} else if ($pref_name == "USER_TIMEZONE") { } else if ($pref_name == "USER_TIMEZONE") {
$timezones = explode("\n", file_get_contents("lib/timezones.txt")); $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
print \Controls\select_tag($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); print \Controls\select_tag($pref_name, $value, $timezones, ["dojoType" => "dijit.form.FilteringSelect"]);
} else if ($pref_name == "BLACKLISTED_TAGS") { # TODO: other possible <textarea> prefs go here } else if ($pref_name == "BLACKLISTED_TAGS") { # TODO: other possible <textarea> prefs go here

@ -95,7 +95,7 @@ class Pref_System extends Handler_Administrative {
E_USER_ERROR => __("Errors"), E_USER_ERROR => __("Errors"),
E_USER_WARNING => __("Warnings"), E_USER_WARNING => __("Warnings"),
E_USER_NOTICE => __("Everything") E_USER_NOTICE => __("Everything")
], 'onchange="Helpers.EventLog.refresh()"', "severity") ?> ], ["onchange"=> "Helpers.EventLog.refresh()"], "severity") ?>
</div> </div>
</div> </div>

@ -1,19 +1,30 @@
<?php <?php
namespace Controls; namespace Controls;
function button_tag(string $value, string $type, $attributes = "") { function attributes_to_string(array $attributes) {
return "<button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">".htmlspecialchars($value)."</button>"; $rv = "";
foreach ($attributes as $k => $v) {
$rv .= "$k=\"" . htmlspecialchars($v) . "\"";
}
return $rv;
}
function button_tag(string $value, string $type, array $attributes = []) {
return "<button dojoType=\"dijit.form.Button\" ".attributes_to_string($attributes)." type=\"$type\">".htmlspecialchars($value)."</button>";
} }
function submit_tag(string $value, $attributes = "") { function submit_tag(string $value, array $attributes = []) {
return button_tag($value, "submit", "class=\"alt-primary\" $attributes"); return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes));
} }
function select_tag(string $name, $value, array $values, string $attributes = "", string $id = "") { function select_tag(string $name, $value, array $values, array $attributes = [], string $id = "") {
$dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; $attributes_str = attributes_to_string($attributes);
$dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
$rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\" $rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>"; id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes_str>";
foreach ($values as $v) { foreach ($values as $v) {
$is_sel = ($v == $value) ? "selected=\"selected\"" : ""; $is_sel = ($v == $value) ? "selected=\"selected\"" : "";
@ -26,7 +37,7 @@
return $rv; return $rv;
} }
function select_labels(string $name, string $value, string $attributes = "", string $id = "") { function select_labels(string $name, string $value, array $attributes = [], string $id = "") {
$pdo = \Db::pdo(); $pdo = \Db::pdo();
$sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
@ -42,11 +53,12 @@
return select_tag($name, $value, $values, $attributes, $id); return select_tag($name, $value, $values, $attributes, $id);
} }
function select_hash(string $name, $value, array $values, string $attributes = "", string $id = "") { function select_hash(string $name, $value, array $values, array $attributes = [], string $id = "") {
$dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; $attributes_str = attributes_to_string($attributes);
$dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
$rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\" $rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>"; id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes_str>";
foreach ($values as $k => $v) { foreach ($values as $k => $v) {
$is_sel = ($k == $value) ? "selected=\"selected\"" : ""; $is_sel = ($k == $value) ? "selected=\"selected\"" : "";
@ -59,20 +71,21 @@
return $rv; return $rv;
} }
function hidden_tag(string $name, string $value) { function hidden_tag(string $name, string $value, array $attributes = []) {
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"
name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($value)."\">"; ".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" : ""; $is_checked = $checked ? "checked" : "";
$value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : ""; $value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : "";
return "<input dojoType='dijit.form.CheckBox' name=\"".htmlspecialchars($name)."\" return "<input dojoType='dijit.form.CheckBox' name=\"".htmlspecialchars($name)."\"
$value_str $is_checked $attributes id=\"".htmlspecialchars($id)."\">"; $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 = "") { bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = "") {
$ret = ""; $ret = "";
@ -81,7 +94,7 @@
$ret .= "<select name=\"".htmlspecialchars($name)."\" $ret .= "<select name=\"".htmlspecialchars($name)."\"
id=\"".htmlspecialchars($id)."\" id=\"".htmlspecialchars($id)."\"
default=\"".((string)$default_id)."\" default=\"".((string)$default_id)."\"
dojoType=\"fox.form.Select\" $attributes>"; dojoType=\"fox.form.Select\" ".attributes_to_string($attributes).">";
} }
$pdo = \Db::pdo(); $pdo = \Db::pdo();

@ -142,7 +142,8 @@
<label> </label> <label> </label>
<label id="bw_limit_label"> <label id="bw_limit_label">
<?= \Controls\checkbox_tag("safe_mode", false, "", "onchange='UtilityApp.bwLimitChange(this)'", 'bw_limit') ?> <?= \Controls\checkbox_tag("bw_limit", false, "",
["onchange" => 'UtilityApp.bwLimitChange(this)'], 'bw_limit') ?>
<?= __("Use less traffic") ?></label> <?= __("Use less traffic") ?></label>
</fieldset> </fieldset>

@ -160,7 +160,8 @@ class Mail extends Plugin {
style=\"width : 30em;\" style=\"width : 30em;\"
name=\"destination\" id=\"emailArticleDlg_destination\">"; */ name=\"destination\" id=\"emailArticleDlg_destination\">"; */
print \Controls\select_tag("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); print \Controls\select_tag("destination", "", $addresslist,
["style" => "width: 30em", "dojoType" => "dijit.form.ComboBox"]);
/* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\"
style=\"z-index: 30; display : none\"></div>"; */ style=\"z-index: 30; display : none\"></div>"; */

Loading…
Cancel
Save