summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-16 14:23:00 +0300
committerAndrew Dolgov <[email protected]>2021-02-16 14:23:00 +0300
commit26d6b84a572b5cbd99acffc5ae727ea6d1be543a (patch)
treedd1f491b0e46efa92f0b1eeed85253120e519347
parentcb6b3584ce6160b69ee03f1a31660a430cb06854 (diff)
add namespaced controls with unified naming; deprecated old-style control shortcuts
-rwxr-xr-xclasses/feeds.php22
-rwxr-xr-xclasses/handler/public.php4
-rwxr-xr-xclasses/pref/feeds.php27
-rwxr-xr-xclasses/pref/filters.php21
-rw-r--r--classes/pref/prefs.php41
-rw-r--r--classes/pref/system.php4
-rwxr-xr-xinclude/controls.php383
-rw-r--r--include/controls_compat.php312
-rw-r--r--include/functions.php1
-rwxr-xr-xinclude/login_form.php2
-rw-r--r--plugins/mail/init.php2
11 files changed, 470 insertions, 349 deletions
diff --git a/classes/feeds.php b/classes/feeds.php
index f3ce1e48b..aa1f889e0 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -583,7 +583,7 @@ class Feeds extends Handler_Protected {
function subscribeToFeed() {
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") {
print "<fieldset>";
print "<label class='inline'>" . __("Language:") . "</label>";
- print_select("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(),
- "dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\"");
+ print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(),
+ "title=\"".__('Used for word stemming')."\"");
print "</fieldset>";
}
@@ -668,6 +668,15 @@ class Feeds extends Handler_Protected {
display : none;
}
</style>
+ <script>
+ dojoConfig = {
+ async: true,
+ cacheBust: "<?= get_scripts_timestamp(); ?>",
+ packages: [
+ { name: "fox", location: "../../js" },
+ ]
+ };
+ </script>
<?php
echo javascript_tag("lib/prototype.js");
echo javascript_tag("js/utility.js");
@@ -677,7 +686,7 @@ class Feeds extends Handler_Protected {
</head>
<body class="flat ttrss_utility feed_debugger css_loading">
<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){
ready(function() {
parser.parse();
@@ -697,9 +706,8 @@ class Feeds extends Handler_Protected {
<fieldset>
<label>
- <?php print_select_hash("xdebug", $xdebug,
- [Debug::$LOG_VERBOSE => "LOG_VERBOSE", Debug::$LOG_EXTENDED => "LOG_EXTENDED"],
- 'dojoType="dijit.form.Select"');
+ <?= \Controls\select_hash("xdebug", $xdebug,
+ [Debug::$LOG_VERBOSE => "LOG_VERBOSE", Debug::$LOG_EXTENDED => "LOG_EXTENDED"]);
?></label>
</fieldset>
diff --git a/classes/handler/public.php b/classes/handler/public.php
index da1e53853..b0bed5d1c 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -788,7 +788,7 @@ class Handler_Public extends Handler {
?>
<form method="post">
<input type="hidden" name="op" value="subscribe">
- <?php print_hidden("csrf_token", $_SESSION["csrf_token"]) ?>
+ <?= \Controls\hidden_tag("csrf_token", $_SESSION["csrf_token"]) ?>
<fieldset>
<label>Feed or site URL:</label>
<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 "<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 "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>";
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index cb6ff94fc..d97081293 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -563,15 +563,11 @@ class Pref_Feeds extends Handler_Protected {
/* Category */
if (get_pref('ENABLE_FEED_CATS')) {
-
- $cat_id = $row["cat_id"];
-
print "<fieldset>";
print "<label>" . __('Place in category:') . "</label> ";
- print_feed_cat_select("cat_id", $cat_id,
- 'dojoType="fox.form.Select"');
+ print \Controls\select_feeds_cats("cat_id", $row["cat_id"]);
print "</fieldset>";
}
@@ -601,8 +597,7 @@ class Pref_Feeds extends Handler_Protected {
print "<fieldset>";
print "<label>" . __('Language:') . "</label> ";
- print_select("feed_language", $feed_language, $this::get_ts_languages(),
- 'dojoType="fox.form.Select"');
+ print \Controls\select_tag("feed_language", $feed_language, $this::get_ts_languages());
print "</fieldset>";
}
@@ -623,8 +618,7 @@ class Pref_Feeds extends Handler_Protected {
$local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
- print_select_hash("update_interval", $update_interval, $local_update_intervals,
- 'dojoType="fox.form.Select"');
+ print \Controls\select_hash("update_interval", $update_interval, $local_update_intervals);
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) ];
}
- print_select_hash("purge_interval", $purge_interval, $local_purge_intervals,
- 'dojoType="fox.form.Select" ' .
+ print \Controls\select_hash("purge_interval", $purge_interval, $local_purge_intervals,
((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
print "</fieldset>";
@@ -857,8 +850,8 @@ class Pref_Feeds extends Handler_Protected {
print "<fieldset>";
print "<label>" . __('Language:') . "</label> ";
- print_select("feed_language", "", $this::get_ts_languages(),
- 'disabled="1" dojoType="fox.form.Select"');
+ print \Controls\select_tag("feed_language", "", $this::get_ts_languages(),
+ 'disabled="1"');
$this->batch_edit_cbox("feed_language");
@@ -879,8 +872,7 @@ class Pref_Feeds extends Handler_Protected {
$local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
- print_select_hash("update_interval", "", $local_update_intervals,
- 'disabled="1" dojoType="fox.form.Select"');
+ print \Controls\select_hash("update_interval", "", $local_update_intervals, 'disabled="1"');
$this->batch_edit_cbox("update_interval");
@@ -902,8 +894,7 @@ class Pref_Feeds extends Handler_Protected {
else
$local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
- print_select_hash("purge_interval", "", $local_purge_intervals,
- 'disabled="1" dojoType="fox.form.Select"');
+ print \Controls\select_hash("purge_interval", "", $local_purge_intervals, 'disabled="1"');
$this->batch_edit_cbox("purge_interval");
@@ -1550,7 +1541,7 @@ class Pref_Feeds extends Handler_Protected {
function batchSubscribe() {
print json_encode([
"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")
]);
}
diff --git a/classes/pref/filters.php b/classes/pref/filters.php
index 930a4eeac..23275a1d6 100755
--- a/classes/pref/filters.php
+++ b/classes/pref/filters.php
@@ -392,7 +392,7 @@ class Pref_Filters extends Handler_Protected {
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>".
- 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)'>
<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 "<label style='display : inline'>". __("on field") . "</label> ";
- print_select_hash("filter_type", $filter_type, $filter_types,
- 'dojoType="fox.form.Select"');
+ print \Controls\select_hash("filter_type", $filter_type, $filter_types);
print "<label style='padding-left : 10px; display : inline'>" . __("in") . "</label> ";
print "</fieldset>";
@@ -894,9 +893,13 @@ class Pref_Filters extends Handler_Protected {
id='filterDlg_actionParam' style=\"$param_hidden\"
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\"
- 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_action_hash = array();
@@ -918,9 +921,9 @@ class Pref_Filters extends Handler_Protected {
$filter_plugin_disabled = "";
}
- print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash,
- "style=\"$plugin_param_hidden\" dojoType='fox.form.Select' $filter_plugin_disabled",
- "action_param_plugin");
+ print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash,
+ "style=\"$plugin_param_hidden\" $filter_plugin_disabled",
+ "filterDlg_actionParamPlugin");
print "</span>";
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index 81b7767eb..d8491995d 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -288,8 +288,8 @@ class Pref_Prefs extends Handler_Protected {
?>
<form dojoType='dijit.form.Form'>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "changeemail") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "changeemail") ?>
<script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault();
@@ -347,8 +347,8 @@ class Pref_Prefs extends Handler_Protected {
<form dojoType='dijit.form.Form'>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "changepassword") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "changepassword") ?>
<script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault();
@@ -456,8 +456,8 @@ class Pref_Prefs extends Handler_Protected {
?>
<form dojoType='dijit.form.Form'>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "otpdisable") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "otpdisable") ?>
<script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault();
@@ -511,10 +511,10 @@ class Pref_Prefs extends Handler_Protected {
$otp_secret = $this->otpsecret();
?>
- <form dojoType='dijit.form.Form' id='changeOtpForm'>
+ <form dojoType='dijit.form.Form'>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "otpenable") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "otpenable") ?>
<fieldset>
<label><?= __("OTP Key:") ?></label>
@@ -663,14 +663,14 @@ class Pref_Prefs extends Handler_Protected {
$type_name = $item['type_name'];
if ($pref_name == "USER_LANGUAGE") {
- print_select_hash($pref_name, $value, get_translations(),
- "style='width : 220px; margin : 0px' dojoType='fox.form.Select'");
+ print \Controls\select_hash($pref_name, $value, get_translations(),
+ "style='width : 220px; margin : 0px'");
} else if ($pref_name == "USER_TIMEZONE") {
$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
@@ -715,12 +715,11 @@ class Pref_Prefs extends Handler_Protected {
global $update_intervals_nodefault;
- print_select_hash($pref_name, $value, $update_intervals_nodefault,
- 'dojoType="fox.form.Select"');
+ print \Controls\select_hash($pref_name, $value, $update_intervals_nodefault);
+
} else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") {
- print_select($pref_name, $value, Pref_Feeds::get_ts_languages(),
- 'dojoType="fox.form.Select"');
+ print \Controls\select_tag($pref_name, $value, Pref_Feeds::get_ts_languages());
} 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() {
?>
<form dojoType='dijit.form.Form' id='changeSettingsForm'>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "saveconfig") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "saveconfig") ?>
<script type='dojo/method' event='onSubmit' args='evt, quit'>
if (evt) evt.preventDefault();
if (this.validate()) {
@@ -973,8 +972,8 @@ class Pref_Prefs extends Handler_Protected {
}
</script>
- <?php print_hidden("op", "pref-prefs") ?>
- <?php print_hidden("method", "setplugins") ?>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "setplugins") ?>
<div dojoType="dijit.layout.BorderContainer" gutters="false">
<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">
diff --git a/classes/pref/system.php b/classes/pref/system.php
index f0a5f7b7f..d3b733364 100644
--- a/classes/pref/system.php
+++ b/classes/pref/system.php
@@ -90,12 +90,12 @@ class Pref_System extends Handler_Administrative {
<div class='pull-right'>
<?= __("Severity:") ?>
- <?php print_select_hash("severity", $severity,
+ <?= \Controls\select_hash("severity", $severity,
[
E_USER_ERROR => __("Errors"),
E_USER_WARNING => __("Warnings"),
E_USER_NOTICE => __("Everything")
- ], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"') ?>
+ ], 'onchange="Helpers.EventLog.refresh()"', "severity") ?>
</div>
</div>
diff --git a/include/controls.php b/include/controls.php
index f706931db..34a4af1f2 100755
--- a/include/controls.php
+++ b/include/controls.php
@@ -1,326 +1,133 @@
<?php
+ namespace Controls;
-function print_select($id, $default, $values, $attributes = "", $name = "") {
- if (!$name) $name = $id;
+ function select_tag(string $name, $value, array $values, string $attributes = "", string $id = "") {
+ $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
- print "<select name=\"$name\" id=\"$id\" $attributes>";
- foreach ($values as $v) {
- if ($v == $default)
- $sel = "selected=\"1\"";
- else
- $sel = "";
+ $rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
+ id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
- $v = trim($v);
+ foreach ($values as $v) {
+ $is_sel = ($v == $value) ? "selected=\"selected\"" : "";
- print "<option value=\"$v\" $sel>$v</option>";
- }
- print "</select>";
-}
+ $rv .= "<option value=\"".htmlspecialchars($v)."\" $is_sel>".htmlspecialchars($v)."</option>";
+ }
-function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
- if (!$name) $name = $id;
+ $rv .= "</select>";
- print "<select name=\"$name\" id='$id' $attributes>";
- foreach (array_keys($values) as $v) {
- if ($v == $default)
- $sel = 'selected="selected"';
- else
- $sel = "";
+ return $rv;
+ }
- $v = trim($v);
+ function select_labels(string $name, string $value, string $attributes = "", string $id = "") {
+ $pdo = \Db::pdo();
- print "<option $sel value=\"$v\">".$values[$v]."</option>";
- }
+ $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
+ WHERE owner_uid = ? ORDER BY caption");
+ $sth->execute([$_SESSION['uid']]);
- print "</select>";
-}
+ $values = [];
-function format_hidden($name, $value) {
- return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
-}
+ while ($row = $sth->fetch()) {
+ array_push($values, $row["caption"]);
+ }
-function print_hidden($name, $value) {
- print format_hidden($name, $value);
-}
+ return select_tag($name, $value, $values, $attributes, $id);
+ }
-function format_checkbox($id, $checked, $value = "", $attributes = "") {
- $checked_str = $checked ? "checked" : "";
- $value_str = $value ? "value=\"$value\"" : "";
+ function select_hash(string $name, $value, array $values, string $attributes = "", string $id = "") {
+ $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
- return "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
-}
+ $rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
+ id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
-function print_checkbox($id, $checked, $value = "", $attributes = "") {
- print format_checkbox($id, $checked, $value, $attributes);
-}
+ foreach ($values as $k => $v) {
+ $is_sel = ($k == $value) ? "selected=\"selected\"" : "";
-function print_button($type, $value, $attributes = "") {
- print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
-}
+ $rv .= "<option value=\"".htmlspecialchars($k)."\" $is_sel>".htmlspecialchars($v)."</option>";
+ }
-function print_radio($id, $default, $true_is, $values, $attributes = "") {
- foreach ($values as $v) {
+ $rv .= "</select>";
- if ($v == $default)
- $sel = "checked";
- else
- $sel = "";
+ return $rv;
+ }
- if ($v == $true_is) {
- $sel .= " value=\"1\"";
- } else {
- $sel .= " value=\"0\"";
- }
+ function hidden_tag(string $name, string $value) {
+ return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"
+ name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($value)."\">";
+ }
- print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\"
- type=\"radio\" $sel $attributes name=\"$id\">&nbsp;$v&nbsp;";
+ 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 print_feed_multi_select($id, $default_ids = [],
- $attributes = "", $include_all_feeds = true,
- $root_id = null, $nest_level = 0) {
+ 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 = "") {
- $pdo = Db::pdo();
+ $ret = "";
- print_r(in_array("CAT:6",$default_ids));
+ if (!$root_id) {
+ $ret .= "<select name=\"".htmlspecialchars($name)."\"
+ id=\"".htmlspecialchars($id)."\"
+ default=\"".((string)$default_id)."\"
+ dojoType=\"fox.form.Select\" $attributes>";
+ }
- 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>";
- }
- }
+ $pdo = \Db::pdo();
- if (get_pref('ENABLE_FEED_CATS')) {
+ if (!$root_id) $root_id = null;
- 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]);
- $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");
+ $found = 0;
- $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
+ while ($line = $sth->fetch()) {
+ ++$found;
- while ($line = $sth->fetch()) {
+ if ($line["id"] == $default_id) {
+ $is_selected = "selected=\"1\"";
+ } else {
+ $is_selected = "";
+ }
- for ($i = 0; $i < $nest_level; $i++)
- $line["title"] = " " . $line["title"];
+ for ($i = 0; $i < $nest_level; $i++)
+ $line["title"] = " " . $line["title"];
- $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
+ if ($line["title"])
+ $ret .= sprintf("<option $is_selected value='%d'>%s</option>",
+ $line["id"], htmlspecialchars($line["title"]));
- printf("<option $is_selected value='CAT:%d'>%s</option>",
- $line["id"], htmlspecialchars($line["title"]));
+ if ($line["num_children"] > 0)
+ $ret .= select_feeds_cats($id, $default_id, $attributes,
+ $include_all_cats, $line["id"], $nest_level+1, $id);
+ }
- if ($line["num_children"] > 0)
- print_feed_multi_select($id, $default_ids, $attributes,
- $include_all_feeds, $line["id"], $nest_level+1);
+ if (!$root_id) {
+ if ($include_all_cats) {
+ if ($found > 0) {
+ $ret .= "<option disabled=\"1\">―――――――――――――――</option>";
+ }
- $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
- WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
+ if ($default_id == 0) {
+ $is_selected = "selected=\"1\"";
+ } else {
+ $is_selected = "";
+ }
- $f_sth->execute([$line['id'], $_SESSION['uid']]);
+ $ret .= "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
+ }
+ $ret .= "</select>";
+ }
- while ($fline = $f_sth->fetch()) {
- $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
+ return $ret;
+ }
- $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>";
-
-
-}
diff --git a/include/controls_compat.php b/include/controls_compat.php
new file mode 100644
index 000000000..3d2779b08
--- /dev/null
+++ b/include/controls_compat.php
@@ -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>";
+
+
+}
diff --git a/include/functions.php b/include/functions.php
index 4557c0411..174ef39f0 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -203,6 +203,7 @@
require_once 'db-prefs.php';
require_once 'controls.php';
+ require_once 'controls_compat.php';
define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)');
ini_set('user_agent', SELF_USER_AGENT);
diff --git a/include/login_form.php b/include/login_form.php
index aa6a72260..798efa624 100755
--- a/include/login_form.php
+++ b/include/login_form.php
@@ -97,7 +97,7 @@
<form action="public.php?return=<?= $return ?>"
dojoType="dijit.form.Form" method="POST">
- <?php print_hidden("op", "login"); ?>
+ <?= \Controls\hidden_tag("op", "login"); ?>
<?php if (!empty($_SESSION["login_error_msg"])) { ?>
<?= format_error($_SESSION["login_error_msg"]) ?>
diff --git a/plugins/mail/init.php b/plugins/mail/init.php
index 829620ebc..b1263ece5 100644
--- a/plugins/mail/init.php
+++ b/plugins/mail/init.php
@@ -160,7 +160,7 @@ class Mail extends Plugin {
style=\"width : 30em;\"
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\"
style=\"z-index: 30; display : none\"></div>"; */