add namespaced controls with unified naming; deprecated old-style control shortcuts

This commit is contained in:
Andrew Dolgov 2021-02-16 14:23:00 +03:00
parent cb6b3584ce
commit 26d6b84a57
11 changed files with 470 additions and 349 deletions

View File

@ -583,7 +583,7 @@ class Feeds extends Handler_Protected {
function subscribeToFeed() { function subscribeToFeed() {
print json_encode([ print json_encode([
"cat_select" => format_feed_cat_select("cat", false, 'dojoType="fox.form.Select"') "cat_select" => \Controls\select_feeds_cats("cat")
]); ]);
} }
@ -607,8 +607,8 @@ class Feeds extends Handler_Protected {
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
print "<fieldset>"; print "<fieldset>";
print "<label class='inline'>" . __("Language:") . "</label>"; print "<label class='inline'>" . __("Language:") . "</label>";
print_select("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(),
"dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\""); "title=\"".__('Used for word stemming')."\"");
print "</fieldset>"; print "</fieldset>";
} }
@ -668,6 +668,15 @@ class Feeds extends Handler_Protected {
display : none; display : none;
} }
</style> </style>
<script>
dojoConfig = {
async: true,
cacheBust: "<?= get_scripts_timestamp(); ?>",
packages: [
{ name: "fox", location: "../../js" },
]
};
</script>
<?php <?php
echo javascript_tag("lib/prototype.js"); echo javascript_tag("lib/prototype.js");
echo javascript_tag("js/utility.js"); echo javascript_tag("js/utility.js");
@ -677,7 +686,7 @@ class Feeds extends Handler_Protected {
</head> </head>
<body class="flat ttrss_utility feed_debugger css_loading"> <body class="flat ttrss_utility feed_debugger css_loading">
<script type="text/javascript"> <script type="text/javascript">
require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox', 'dijit/form/Select', 'dijit/form/Form', require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox', 'fox/form/Select', 'dijit/form/Form',
'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser, ready){ 'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser, ready){
ready(function() { ready(function() {
parser.parse(); parser.parse();
@ -697,9 +706,8 @@ class Feeds extends Handler_Protected {
<fieldset> <fieldset>
<label> <label>
<?php print_select_hash("xdebug", $xdebug, <?= \Controls\select_hash("xdebug", $xdebug,
[Debug::$LOG_VERBOSE => "LOG_VERBOSE", Debug::$LOG_EXTENDED => "LOG_EXTENDED"], [Debug::$LOG_VERBOSE => "LOG_VERBOSE", Debug::$LOG_EXTENDED => "LOG_EXTENDED"]);
'dojoType="dijit.form.Select"');
?></label> ?></label>
</fieldset> </fieldset>

View File

@ -788,7 +788,7 @@ class Handler_Public extends Handler {
?> ?>
<form method="post"> <form method="post">
<input type="hidden" name="op" value="subscribe"> <input type="hidden" name="op" value="subscribe">
<?php print_hidden("csrf_token", $_SESSION["csrf_token"]) ?> <?= \Controls\hidden_tag("csrf_token", $_SESSION["csrf_token"]) ?>
<fieldset> <fieldset>
<label>Feed or site URL:</label> <label>Feed or site URL:</label>
<input style="width: 300px" dojoType="dijit.form.ValidationTextBox" required="1" name="feed_url" value="<?= htmlspecialchars($feed_url) ?>"> <input style="width: 300px" dojoType="dijit.form.ValidationTextBox" required="1" name="feed_url" value="<?= htmlspecialchars($feed_url) ?>">
@ -831,7 +831,7 @@ class Handler_Public extends Handler {
print "<form action='public.php'>"; print "<form action='public.php'>";
print "<input type='hidden' name='op' value='subscribe'>"; print "<input type='hidden' name='op' value='subscribe'>";
print_hidden("csrf_token", $_SESSION["csrf_token"]); print \Controls\hidden_tag("csrf_token", $_SESSION["csrf_token"]);
print "<fieldset>"; print "<fieldset>";
print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>";

View File

@ -563,15 +563,11 @@ class Pref_Feeds extends Handler_Protected {
/* Category */ /* Category */
if (get_pref('ENABLE_FEED_CATS')) { if (get_pref('ENABLE_FEED_CATS')) {
$cat_id = $row["cat_id"];
print "<fieldset>"; print "<fieldset>";
print "<label>" . __('Place in category:') . "</label> "; print "<label>" . __('Place in category:') . "</label> ";
print_feed_cat_select("cat_id", $cat_id, print \Controls\select_feeds_cats("cat_id", $row["cat_id"]);
'dojoType="fox.form.Select"');
print "</fieldset>"; print "</fieldset>";
} }
@ -601,8 +597,7 @@ class Pref_Feeds extends Handler_Protected {
print "<fieldset>"; print "<fieldset>";
print "<label>" . __('Language:') . "</label> "; print "<label>" . __('Language:') . "</label> ";
print_select("feed_language", $feed_language, $this::get_ts_languages(), print \Controls\select_tag("feed_language", $feed_language, $this::get_ts_languages());
'dojoType="fox.form.Select"');
print "</fieldset>"; print "</fieldset>";
} }
@ -623,8 +618,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_select_hash("update_interval", $update_interval, $local_update_intervals, print \Controls\select_hash("update_interval", $update_interval, $local_update_intervals);
'dojoType="fox.form.Select"');
print "</fieldset>"; print "</fieldset>";
@ -650,8 +644,7 @@ 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_select_hash("purge_interval", $purge_interval, $local_purge_intervals, print \Controls\select_hash("purge_interval", $purge_interval, $local_purge_intervals,
'dojoType="fox.form.Select" ' .
((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
print "</fieldset>"; print "</fieldset>";
@ -857,8 +850,8 @@ class Pref_Feeds extends Handler_Protected {
print "<fieldset>"; print "<fieldset>";
print "<label>" . __('Language:') . "</label> "; print "<label>" . __('Language:') . "</label> ";
print_select("feed_language", "", $this::get_ts_languages(), print \Controls\select_tag("feed_language", "", $this::get_ts_languages(),
'disabled="1" dojoType="fox.form.Select"'); 'disabled="1"');
$this->batch_edit_cbox("feed_language"); $this->batch_edit_cbox("feed_language");
@ -879,8 +872,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_select_hash("update_interval", "", $local_update_intervals, print \Controls\select_hash("update_interval", "", $local_update_intervals, 'disabled="1"');
'disabled="1" dojoType="fox.form.Select"');
$this->batch_edit_cbox("update_interval"); $this->batch_edit_cbox("update_interval");
@ -902,8 +894,7 @@ class Pref_Feeds extends Handler_Protected {
else else
$local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
print_select_hash("purge_interval", "", $local_purge_intervals, print \Controls\select_hash("purge_interval", "", $local_purge_intervals, 'disabled="1"');
'disabled="1" dojoType="fox.form.Select"');
$this->batch_edit_cbox("purge_interval"); $this->batch_edit_cbox("purge_interval");
@ -1550,7 +1541,7 @@ class Pref_Feeds extends Handler_Protected {
function batchSubscribe() { function batchSubscribe() {
print json_encode([ print json_encode([
"enable_cats" => (int)get_pref('ENABLE_FEED_CATS'), "enable_cats" => (int)get_pref('ENABLE_FEED_CATS'),
"cat_select" => format_feed_cat_select("cat", false, 'dojoType="fox.form.Select"') "cat_select" => \Controls\select_feeds_cats("cat")
]); ]);
} }

View File

@ -392,7 +392,7 @@ class Pref_Filters extends Handler_Protected {
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'> print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
<span onclick='App.dialogOf(this).editRule(this)'>".$this->_get_rule_name($line)."</span>". <span onclick='App.dialogOf(this).editRule(this)'>".$this->_get_rule_name($line)."</span>".
format_hidden("rule[]", $data)."</li>"; \Controls\hidden_tag("rule[]", $data)."</li>";
} }
} }
@ -434,7 +434,7 @@ class Pref_Filters extends Handler_Protected {
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'> print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
<span onclick='App.dialogOf(this).editAction(this)'>".$this->_get_action_name($line)."</span>". <span onclick='App.dialogOf(this).editAction(this)'>".$this->_get_action_name($line)."</span>".
format_hidden("action[]", $data)."</li>"; \Controls\hidden_tag("action[]", $data)."</li>";
} }
} }
@ -815,8 +815,7 @@ class Pref_Filters extends Handler_Protected {
print "<fieldset>"; print "<fieldset>";
print "<label style='display : inline'>". __("on field") . "</label> "; print "<label style='display : inline'>". __("on field") . "</label> ";
print_select_hash("filter_type", $filter_type, $filter_types, print \Controls\select_hash("filter_type", $filter_type, $filter_types);
'dojoType="fox.form.Select"');
print "<label style='padding-left : 10px; display : inline'>" . __("in") . "</label> "; print "<label style='padding-left : 10px; display : inline'>" . __("in") . "</label> ";
print "</fieldset>"; print "</fieldset>";
@ -894,9 +893,13 @@ class Pref_Filters extends Handler_Protected {
id='filterDlg_actionParam' style=\"$param_hidden\" id='filterDlg_actionParam' style=\"$param_hidden\"
name='action_param' value=\"$action_param\">"; name='action_param' value=\"$action_param\">";
print_label_select("action_param_label", $action_param, /*print_label_select("action_param_label", $action_param,
"id='filterDlg_actionParamLabel' style=\"$label_param_hidden\" "id='filterDlg_actionParamLabel' style=\"$label_param_hidden\"
dojoType='fox.form.Select'"); dojoType='fox.form.Select'");*/
print \Controls\select_labels("action_param_label", $action_param,
"style=\"$label_param_hidden\"",
"filterDlg_actionParamLabel");
$filter_actions = PluginHost::getInstance()->get_filter_actions(); $filter_actions = PluginHost::getInstance()->get_filter_actions();
$filter_action_hash = array(); $filter_action_hash = array();
@ -918,9 +921,9 @@ class Pref_Filters extends Handler_Protected {
$filter_plugin_disabled = ""; $filter_plugin_disabled = "";
} }
print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash, print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash,
"style=\"$plugin_param_hidden\" dojoType='fox.form.Select' $filter_plugin_disabled", "style=\"$plugin_param_hidden\" $filter_plugin_disabled",
"action_param_plugin"); "filterDlg_actionParamPlugin");
print "</span>"; print "</span>";

View File

@ -288,8 +288,8 @@ class Pref_Prefs extends Handler_Protected {
?> ?>
<form dojoType='dijit.form.Form'> <form dojoType='dijit.form.Form'>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "changeemail") ?> <?= \Controls\hidden_tag("method", "changeemail") ?>
<script type='dojo/method' event='onSubmit' args='evt'> <script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault(); evt.preventDefault();
@ -347,8 +347,8 @@ class Pref_Prefs extends Handler_Protected {
<form dojoType='dijit.form.Form'> <form dojoType='dijit.form.Form'>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "changepassword") ?> <?= \Controls\hidden_tag("method", "changepassword") ?>
<script type='dojo/method' event='onSubmit' args='evt'> <script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault(); evt.preventDefault();
@ -456,8 +456,8 @@ class Pref_Prefs extends Handler_Protected {
?> ?>
<form dojoType='dijit.form.Form'> <form dojoType='dijit.form.Form'>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "otpdisable") ?> <?= \Controls\hidden_tag("method", "otpdisable") ?>
<script type='dojo/method' event='onSubmit' args='evt'> <script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault(); evt.preventDefault();
@ -511,10 +511,10 @@ class Pref_Prefs extends Handler_Protected {
$otp_secret = $this->otpsecret(); $otp_secret = $this->otpsecret();
?> ?>
<form dojoType='dijit.form.Form' id='changeOtpForm'> <form dojoType='dijit.form.Form'>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "otpenable") ?> <?= \Controls\hidden_tag("method", "otpenable") ?>
<fieldset> <fieldset>
<label><?= __("OTP Key:") ?></label> <label><?= __("OTP Key:") ?></label>
@ -663,14 +663,14 @@ class Pref_Prefs extends Handler_Protected {
$type_name = $item['type_name']; $type_name = $item['type_name'];
if ($pref_name == "USER_LANGUAGE") { if ($pref_name == "USER_LANGUAGE") {
print_select_hash($pref_name, $value, get_translations(), print \Controls\select_hash($pref_name, $value, get_translations(),
"style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); "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_select($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
@ -715,12 +715,11 @@ class Pref_Prefs extends Handler_Protected {
global $update_intervals_nodefault; global $update_intervals_nodefault;
print_select_hash($pref_name, $value, $update_intervals_nodefault, print \Controls\select_hash($pref_name, $value, $update_intervals_nodefault);
'dojoType="fox.form.Select"');
} else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") {
print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), print \Controls\select_tag($pref_name, $value, Pref_Feeds::get_ts_languages());
'dojoType="fox.form.Select"');
} else if ($type_name == "bool") { } else if ($type_name == "bool") {
@ -799,14 +798,14 @@ class Pref_Prefs extends Handler_Protected {
} }
} }
} }
print_hidden("boolean_prefs", htmlspecialchars(join(",", $listed_boolean_prefs))); print \Controls\hidden_tag("boolean_prefs", htmlspecialchars(join(",", $listed_boolean_prefs)));
} }
private function index_prefs() { private function index_prefs() {
?> ?>
<form dojoType='dijit.form.Form' id='changeSettingsForm'> <form dojoType='dijit.form.Form' id='changeSettingsForm'>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "saveconfig") ?> <?= \Controls\hidden_tag("method", "saveconfig") ?>
<script type='dojo/method' event='onSubmit' args='evt, quit'> <script type='dojo/method' event='onSubmit' args='evt, quit'>
if (evt) evt.preventDefault(); if (evt) evt.preventDefault();
if (this.validate()) { if (this.validate()) {
@ -973,8 +972,8 @@ class Pref_Prefs extends Handler_Protected {
} }
</script> </script>
<?php print_hidden("op", "pref-prefs") ?> <?= \Controls\hidden_tag("op", "pref-prefs") ?>
<?php print_hidden("method", "setplugins") ?> <?= \Controls\hidden_tag("method", "setplugins") ?>
<div dojoType="dijit.layout.BorderContainer" gutters="false"> <div dojoType="dijit.layout.BorderContainer" gutters="false">
<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto"> <div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">

View File

@ -90,12 +90,12 @@ class Pref_System extends Handler_Administrative {
<div class='pull-right'> <div class='pull-right'>
<?= __("Severity:") ?> <?= __("Severity:") ?>
<?php print_select_hash("severity", $severity, <?= \Controls\select_hash("severity", $severity,
[ [
E_USER_ERROR => __("Errors"), E_USER_ERROR => __("Errors"),
E_USER_WARNING => __("Warnings"), E_USER_WARNING => __("Warnings"),
E_USER_NOTICE => __("Everything") E_USER_NOTICE => __("Everything")
], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"') ?> ], 'onchange="Helpers.EventLog.refresh()"', "severity") ?>
</div> </div>
</div> </div>

View File

@ -1,202 +1,82 @@
<?php <?php
namespace Controls;
function print_select($id, $default, $values, $attributes = "", $name = "") { function select_tag(string $name, $value, array $values, string $attributes = "", string $id = "") {
if (!$name) $name = $id; $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
$rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
print "<select name=\"$name\" id=\"$id\" $attributes>";
foreach ($values as $v) { foreach ($values as $v) {
if ($v == $default) $is_sel = ($v == $value) ? "selected=\"selected\"" : "";
$sel = "selected=\"1\"";
else
$sel = "";
$v = trim($v); $rv .= "<option value=\"".htmlspecialchars($v)."\" $is_sel>".htmlspecialchars($v)."</option>";
print "<option value=\"$v\" $sel>$v</option>";
}
print "</select>";
}
function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
if (!$name) $name = $id;
print "<select name=\"$name\" id='$id' $attributes>";
foreach (array_keys($values) as $v) {
if ($v == $default)
$sel = 'selected="selected"';
else
$sel = "";
$v = trim($v);
print "<option $sel value=\"$v\">".$values[$v]."</option>";
} }
print "</select>"; $rv .= "</select>";
}
function format_hidden($name, $value) { return $rv;
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
}
function print_hidden($name, $value) {
print format_hidden($name, $value);
}
function format_checkbox($id, $checked, $value = "", $attributes = "") {
$checked_str = $checked ? "checked" : "";
$value_str = $value ? "value=\"$value\"" : "";
return "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
}
function print_checkbox($id, $checked, $value = "", $attributes = "") {
print format_checkbox($id, $checked, $value, $attributes);
}
function print_button($type, $value, $attributes = "") {
print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
}
function print_radio($id, $default, $true_is, $values, $attributes = "") {
foreach ($values as $v) {
if ($v == $default)
$sel = "checked";
else
$sel = "";
if ($v == $true_is) {
$sel .= " value=\"1\"";
} else {
$sel .= " value=\"0\"";
} }
print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" function select_labels(string $name, string $value, string $attributes = "", string $id = "") {
type=\"radio\" $sel $attributes name=\"$id\">&nbsp;$v&nbsp;"; $pdo = \Db::pdo();
} $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
} WHERE owner_uid = ? ORDER BY caption");
function print_feed_multi_select($id, $default_ids = [],
$attributes = "", $include_all_feeds = true,
$root_id = null, $nest_level = 0) {
$pdo = Db::pdo();
print_r(in_array("CAT:6",$default_ids));
if (!$root_id) {
print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
if ($include_all_feeds) {
$is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
}
}
if (get_pref('ENABLE_FEED_CATS')) {
if (!$root_id) $root_id = null;
$sth = $pdo->prepare("SELECT id,title,
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
c2.parent_cat = ttrss_feed_categories.id) AS num_children
FROM ttrss_feed_categories
WHERE owner_uid = :uid AND
(parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
$sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
while ($line = $sth->fetch()) {
for ($i = 0; $i < $nest_level; $i++)
$line["title"] = "" . $line["title"];
$is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
if ($line["num_children"] > 0)
print_feed_multi_select($id, $default_ids, $attributes,
$include_all_feeds, $line["id"], $nest_level+1);
$f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
$f_sth->execute([$line['id'], $_SESSION['uid']]);
while ($fline = $f_sth->fetch()) {
$is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
$fline["title"] = "" . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = "" . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
if (!$root_id) {
$is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:0'>%s</option>",
__("Uncategorized"));
$f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title");
$f_sth->execute([$_SESSION['uid']]);
while ($fline = $f_sth->fetch()) {
$is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
$fline["title"] = "" . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = "" . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
} else {
$sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE owner_uid = ? ORDER BY title");
$sth->execute([$_SESSION['uid']]); $sth->execute([$_SESSION['uid']]);
while ($line = $sth->fetch()) { $values = [];
$is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; while ($row = $sth->fetch()) {
array_push($values, $row["caption"]);
printf("<option $is_selected value='%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
}
} }
if (!$root_id) { return select_tag($name, $value, $values, $attributes, $id);
print "</select>";
} }
}
function print_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, function select_hash(string $name, $value, array $values, string $attributes = "", string $id = "") {
$root_id = null, $nest_level = 0) { $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
print format_feed_cat_select($id, $default_id, $attributes, $include_all_cats, $root_id, $nest_level); $rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
} id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, foreach ($values as $k => $v) {
$root_id = null, $nest_level = 0) { $is_sel = ($k == $value) ? "selected=\"selected\"" : "";
$rv .= "<option value=\"".htmlspecialchars($k)."\" $is_sel>".htmlspecialchars($v)."</option>";
}
$rv .= "</select>";
return $rv;
}
function hidden_tag(string $name, string $value) {
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"
name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($value)."\">";
}
function checkbox_tag(string $name, bool $checked, string $value = "", string $attributes = "", string $id = "") {
$is_checked = $checked ? "checked" : "";
$value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : "";
return "<input dojoType='dijit.form.CheckBox' name=\"".htmlspecialchars($name)."\"
$value_str $is_checked $attributes name=\"".htmlspecialchars($id)."\">";
}
function select_feeds_cats(string $name, int $default_id = null, string $attributes = "",
bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = "") {
$ret = ""; $ret = "";
if (!$root_id) { if (!$root_id) {
$ret .= "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; $ret .= "<select name=\"".htmlspecialchars($name)."\"
id=\"".htmlspecialchars($id)."\"
default=\"".((string)$default_id)."\"
dojoType=\"fox.form.Select\" $attributes>";
} }
$pdo = Db::pdo(); $pdo = \Db::pdo();
if (!$root_id) $root_id = null; if (!$root_id) $root_id = null;
@ -227,8 +107,8 @@ function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats
$line["id"], htmlspecialchars($line["title"])); $line["id"], htmlspecialchars($line["title"]));
if ($line["num_children"] > 0) if ($line["num_children"] > 0)
$ret .= format_feed_cat_select($id, $default_id, $attributes, $ret .= select_feeds_cats($id, $default_id, $attributes,
$include_all_cats, $line["id"], $nest_level+1); $include_all_cats, $line["id"], $nest_level+1, $id);
} }
if (!$root_id) { if (!$root_id) {
@ -249,78 +129,5 @@ function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats
} }
return $ret; return $ret;
}
function stylesheet_tag($filename, $id = false) {
$timestamp = filemtime($filename);
$id_part = $id ? "id=\"$id\"" : "";
return "<link rel=\"stylesheet\" $id_part type=\"text/css\" data-orig-href=\"$filename\" href=\"$filename?$timestamp\"/>\n";
}
function javascript_tag($filename) {
$query = "";
if (!(strpos($filename, "?") === false)) {
$query = substr($filename, strpos($filename, "?")+1);
$filename = substr($filename, 0, strpos($filename, "?"));
} }
$timestamp = filemtime($filename);
if ($query) $timestamp .= "&$query";
return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
}
function format_warning($msg, $id = "") {
return "<div class=\"alert\" id=\"$id\">$msg</div>";
}
function format_notice($msg, $id = "") {
return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
}
function format_error($msg, $id = "") {
return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
}
function print_notice($msg) {
return print format_notice($msg);
}
function print_warning($msg) {
return print format_warning($msg);
}
function print_error($msg) {
return print format_error($msg);
}
function print_label_select($name, $value, $attributes = "") {
$pdo = Db::pdo();
$sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
WHERE owner_uid = ? ORDER BY caption");
$sth->execute([$_SESSION['uid']]);
print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
"\" $attributes>";
while ($line = $sth->fetch()) {
$issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
print "<option value=\"".htmlspecialchars($line["caption"])."\"
$issel>" . htmlspecialchars($line["caption"]) . "</option>";
}
# print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
print "</select>";
}

312
include/controls_compat.php Normal file
View File

@ -0,0 +1,312 @@
<?php
// the following is deprecated and will be eventually removed
function print_select($id, $default, $values, $attributes = "", $name = "") {
if (!$name) $name = $id;
print "<select name=\"$name\" id=\"$id\" $attributes>";
foreach ($values as $v) {
if ($v == $default)
$sel = "selected=\"1\"";
else
$sel = "";
$v = trim($v);
print "<option value=\"$v\" $sel>$v</option>";
}
print "</select>";
}
function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
if (!$name) $name = $id;
print "<select name=\"$name\" id='$id' $attributes>";
foreach (array_keys($values) as $v) {
if ($v == $default)
$sel = 'selected="selected"';
else
$sel = "";
$v = trim($v);
print "<option $sel value=\"$v\">".$values[$v]."</option>";
}
print "</select>";
}
function format_hidden($name, $value) {
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
}
function print_hidden($name, $value) {
print format_hidden($name, $value);
}
function format_checkbox($id, $checked, $value = "", $attributes = "") {
$checked_str = $checked ? "checked" : "";
$value_str = $value ? "value=\"$value\"" : "";
return "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
}
function print_checkbox($id, $checked, $value = "", $attributes = "") {
print format_checkbox($id, $checked, $value, $attributes);
}
function format_button($type, $value, $attributes = "") {
return "<button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
}
function print_button($type, $value, $attributes = "") {
print format_button($type, $value, $attributes);
}
function print_feed_multi_select($id, $default_ids = [],
$attributes = "", $include_all_feeds = true,
$root_id = null, $nest_level = 0) {
$pdo = Db::pdo();
print_r(in_array("CAT:6",$default_ids));
if (!$root_id) {
print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
if ($include_all_feeds) {
$is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
}
}
if (get_pref('ENABLE_FEED_CATS')) {
if (!$root_id) $root_id = null;
$sth = $pdo->prepare("SELECT id,title,
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
c2.parent_cat = ttrss_feed_categories.id) AS num_children
FROM ttrss_feed_categories
WHERE owner_uid = :uid AND
(parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
$sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
while ($line = $sth->fetch()) {
for ($i = 0; $i < $nest_level; $i++)
$line["title"] = "" . $line["title"];
$is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
if ($line["num_children"] > 0)
print_feed_multi_select($id, $default_ids, $attributes,
$include_all_feeds, $line["id"], $nest_level+1);
$f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
$f_sth->execute([$line['id'], $_SESSION['uid']]);
while ($fline = $f_sth->fetch()) {
$is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
$fline["title"] = "" . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = "" . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
if (!$root_id) {
$is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:0'>%s</option>",
__("Uncategorized"));
$f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title");
$f_sth->execute([$_SESSION['uid']]);
while ($fline = $f_sth->fetch()) {
$is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
$fline["title"] = "" . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = "" . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
} else {
$sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
WHERE owner_uid = ? ORDER BY title");
$sth->execute([$_SESSION['uid']]);
while ($line = $sth->fetch()) {
$is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : "";
printf("<option $is_selected value='%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
}
}
if (!$root_id) {
print "</select>";
}
}
function print_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true,
$root_id = null, $nest_level = 0) {
print format_feed_cat_select($id, $default_id, $attributes, $include_all_cats, $root_id, $nest_level);
}
function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true,
$root_id = null, $nest_level = 0) {
$ret = "";
if (!$root_id) {
$ret .= "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
}
$pdo = Db::pdo();
if (!$root_id) $root_id = null;
$sth = $pdo->prepare("SELECT id,title,
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
c2.parent_cat = ttrss_feed_categories.id) AS num_children
FROM ttrss_feed_categories
WHERE owner_uid = :uid AND
(parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
$sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
$found = 0;
while ($line = $sth->fetch()) {
++$found;
if ($line["id"] == $default_id) {
$is_selected = "selected=\"1\"";
} else {
$is_selected = "";
}
for ($i = 0; $i < $nest_level; $i++)
$line["title"] = "" . $line["title"];
if ($line["title"])
$ret .= sprintf("<option $is_selected value='%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
if ($line["num_children"] > 0)
$ret .= format_feed_cat_select($id, $default_id, $attributes,
$include_all_cats, $line["id"], $nest_level+1);
}
if (!$root_id) {
if ($include_all_cats) {
if ($found > 0) {
$ret .= "<option disabled=\"1\">―――――――――――――――</option>";
}
if ($default_id == 0) {
$is_selected = "selected=\"1\"";
} else {
$is_selected = "";
}
$ret .= "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
}
$ret .= "</select>";
}
return $ret;
}
function stylesheet_tag($filename, $id = false) {
$timestamp = filemtime($filename);
$id_part = $id ? "id=\"$id\"" : "";
return "<link rel=\"stylesheet\" $id_part type=\"text/css\" data-orig-href=\"$filename\" href=\"$filename?$timestamp\"/>\n";
}
function javascript_tag($filename) {
$query = "";
if (!(strpos($filename, "?") === false)) {
$query = substr($filename, strpos($filename, "?")+1);
$filename = substr($filename, 0, strpos($filename, "?"));
}
$timestamp = filemtime($filename);
if ($query) $timestamp .= "&$query";
return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
}
function format_warning($msg, $id = "") {
return "<div class=\"alert\" id=\"$id\">$msg</div>";
}
function format_notice($msg, $id = "") {
return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
}
function format_error($msg, $id = "") {
return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
}
function print_notice($msg) {
return print format_notice($msg);
}
function print_warning($msg) {
return print format_warning($msg);
}
function print_error($msg) {
return print format_error($msg);
}
function print_label_select($name, $value, $attributes = "") {
$pdo = Db::pdo();
$sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
WHERE owner_uid = ? ORDER BY caption");
$sth->execute([$_SESSION['uid']]);
print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
"\" $attributes>";
while ($line = $sth->fetch()) {
$issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
print "<option value=\"".htmlspecialchars($line["caption"])."\"
$issel>" . htmlspecialchars($line["caption"]) . "</option>";
}
# print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
print "</select>";
}

View File

@ -203,6 +203,7 @@
require_once 'db-prefs.php'; require_once 'db-prefs.php';
require_once 'controls.php'; require_once 'controls.php';
require_once 'controls_compat.php';
define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)');
ini_set('user_agent', SELF_USER_AGENT); ini_set('user_agent', SELF_USER_AGENT);

View File

@ -97,7 +97,7 @@
<form action="public.php?return=<?= $return ?>" <form action="public.php?return=<?= $return ?>"
dojoType="dijit.form.Form" method="POST"> dojoType="dijit.form.Form" method="POST">
<?php print_hidden("op", "login"); ?> <?= \Controls\hidden_tag("op", "login"); ?>
<?php if (!empty($_SESSION["login_error_msg"])) { ?> <?php if (!empty($_SESSION["login_error_msg"])) { ?>
<?= format_error($_SESSION["login_error_msg"]) ?> <?= format_error($_SESSION["login_error_msg"]) ?>

View File

@ -160,7 +160,7 @@ class Mail extends Plugin {
style=\"width : 30em;\" style=\"width : 30em;\"
name=\"destination\" id=\"emailArticleDlg_destination\">"; */ name=\"destination\" id=\"emailArticleDlg_destination\">"; */
print_select("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>"; */