From 103d30ad3f92ed03156fee400801d9a38f946b34 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 13 Feb 2021 22:16:17 +0300 Subject: batch subscribe: use client dialog --- include/controls.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index 8f49e99c5..e6678db9a 100755 --- a/include/controls.php +++ b/include/controls.php @@ -181,11 +181,19 @@ function print_feed_multi_select($id, $default_ids = [], } } -function print_feed_cat_select($id, $default_id, - $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { +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) { - print ""; } $pdo = Db::pdo(); @@ -215,18 +223,18 @@ function print_feed_cat_select($id, $default_id, $line["title"] = " " . $line["title"]; if ($line["title"]) - printf("", + $ret .= sprintf("", $line["id"], htmlspecialchars($line["title"])); if ($line["num_children"] > 0) - print_feed_cat_select($id, $default_id, $attributes, + $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) { - print ""; + $ret .= ""; } if ($default_id == 0) { @@ -235,10 +243,12 @@ function print_feed_cat_select($id, $default_id, $is_selected = ""; } - print ""; + $ret .= ""; } - print ""; + $ret .= ""; } + + return $ret; } function stylesheet_tag($filename, $id = false) { -- cgit v1.2.3 From 82adb01307e108e8a2b4eeb900552160d730d0b7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 14:10:46 +0300 Subject: render enclosures on the client --- include/controls.php | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index e6678db9a..f706931db 100755 --- a/include/controls.php +++ b/include/controls.php @@ -298,37 +298,6 @@ function print_error($msg) { return print format_error($msg); } -function format_inline_player($url, $ctype) { - - $entry = ""; - - $url = htmlspecialchars($url); - - if (strpos($ctype, "audio/") === 0) { - - $entry .= "
"; - - if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || - $_SESSION["hasMp3"])) { - - $entry .= " "; - - } - - if ($entry) $entry .= "" . basename($url) . ""; - - $entry .= "
"; - - return $entry; - - } - - return ""; -} - function print_label_select($name, $value, $attributes = "") { $pdo = Db::pdo(); -- cgit v1.2.3 From 26d6b84a572b5cbd99acffc5ae727ea6d1be543a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 14:23:00 +0300 Subject: add namespaced controls with unified naming; deprecated old-style control shortcuts --- include/controls.php | 383 +++++++++++++-------------------------------------- 1 file changed, 95 insertions(+), 288 deletions(-) (limited to 'include/controls.php') 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 @@ "; - foreach ($values as $v) { - if ($v == $default) - $sel = "selected=\"1\""; - else - $sel = ""; + $rv = ""; -} + $rv .= ""; + } -function print_select_hash($id, $default, $values, $attributes = "", $name = "") { - if (!$name) $name = $id; + $rv .= ""; - print ""; -} + $values = []; -function format_hidden($name, $value) { - return ""; -} + 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 ""; -} + $rv = ""; - 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 ""; + } - print " $v "; + function checkbox_tag(string $name, bool $checked, string $value = "", string $attributes = "", string $id = "") { + $is_checked = $checked ? "checked" : ""; + $value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : ""; - } -} + return ""; + } -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 .= ""; - if ($include_all_feeds) { - $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; - print ""; - } - } + $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("", + $line["id"], htmlspecialchars($line["title"])); - printf("", - $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 .= ""; + } - $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 .= ""; + } + $ret .= ""; + } - 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("", - $fline["id"], htmlspecialchars($fline["title"])); - } - } - - if (!$root_id) { - $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; - - printf("", - __("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("", - $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("", - $line["id"], htmlspecialchars($line["title"])); - } - } - - if (!$root_id) { - print ""; - } -} - -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 .= ""; - } - - return $ret; -} - -function stylesheet_tag($filename, $id = false) { - $timestamp = filemtime($filename); - - $id_part = $id ? "id=\"$id\"" : ""; - - return "\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 "\n"; -} - -function format_warning($msg, $id = "") { - return "
$msg
"; -} - -function format_notice($msg, $id = "") { - return "
$msg
"; -} - -function format_error($msg, $id = "") { - return "
$msg
"; -} - -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 ""; - - -} -- cgit v1.2.3 From d7127cead362ba00b0defd93b2091ce15aeae2f3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 14:42:27 +0300 Subject: feed debugger: use hidden helpers; add button helpers --- include/controls.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index 34a4af1f2..78f02233f 100755 --- a/include/controls.php +++ b/include/controls.php @@ -1,6 +1,14 @@ ".htmlspecialchars($value).""; + } + + function submit_tag(string $value, $attributes = "") { + return button_tag($value, "submit", "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'" : ""; -- cgit v1.2.3 From af4b3e7df06e50e956e9fda281935a7483f5673a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 15:05:32 +0300 Subject: login form: use control helpers --- include/controls.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index 78f02233f..b351a9449 100755 --- a/include/controls.php +++ b/include/controls.php @@ -64,12 +64,12 @@ name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($value)."\">"; } - function checkbox_tag(string $name, bool $checked, string $value = "", string $attributes = "", string $id = "") { + function checkbox_tag(string $name, bool $checked = false, string $value = "", string $attributes = "", string $id = "") { $is_checked = $checked ? "checked" : ""; $value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : ""; return ""; + $value_str $is_checked $attributes id=\"".htmlspecialchars($id)."\">"; } function select_feeds_cats(string $name, int $default_id = null, string $attributes = "", -- cgit v1.2.3 From 4f4e57bb26620ba6f4adcc413ff60b86fdeb158f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 15:27:22 +0300 Subject: hidden_tag: temporarily prevent htmlspecialchars() to stop embedded JSON from breaking --- include/controls.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index b351a9449..6d3cfc417 100755 --- a/include/controls.php +++ b/include/controls.php @@ -61,7 +61,7 @@ function hidden_tag(string $name, string $value) { return ""; + name=\"".htmlspecialchars($name)."\" value=\"$value\">"; } function checkbox_tag(string $name, bool $checked = false, string $value = "", string $attributes = "", string $id = "") { -- cgit v1.2.3 From 627af2c236bf4a370a5d31641757b69d679513f6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 15:36:40 +0300 Subject: amend previous to fix actual underlying problem (double escaping) --- include/controls.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/controls.php') diff --git a/include/controls.php b/include/controls.php index 6d3cfc417..b351a9449 100755 --- a/include/controls.php +++ b/include/controls.php @@ -61,7 +61,7 @@ function hidden_tag(string $name, string $value) { return ""; + name=\"".htmlspecialchars($name)."\" value=\"".htmlspecialchars($value)."\">"; } function checkbox_tag(string $name, bool $checked = false, string $value = "", string $attributes = "", string $id = "") { -- cgit v1.2.3 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 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'include/controls.php') 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 .= ""; + } + + function number_spinner_tag(string $name, string $value, array $attributes = [], string $id = "") { + return input_tag($name, $value, "text", array_merge(["dojoType" => "dijit.form.NumberSpinner"], $attributes), $id); + } + function submit_tag(string $value, array $attributes = []) { return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes)); } -- cgit v1.2.3