X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Fcontrols.php;h=037e331cc86b5aa9e7cf01d743e03cfd91dfc877;hb=e2b8c9273e09091c235959c25d8e4d8122aa6ca8;hp=0129db50115a1913483faaf54a8e41fd8c29e02b;hpb=0bf7e007bb3a7039ea11601c7f93c6da33604228;p=tt-rss.git diff --git a/include/controls.php b/include/controls.php old mode 100644 new mode 100755 index 0129db50..037e331c --- a/include/controls.php +++ b/include/controls.php @@ -71,147 +71,55 @@ function print_radio($id, $default, $true_is, $values, $attributes = "") { } function print_feed_multi_select($id, $default_ids = [], - $attributes = "", $include_all_feeds = true, - $root_id = false, $nest_level = 0) { - - print_r(in_array("CAT:6",$default_ids)); - - if (!$root_id) { - print ""; - } -} + $attributes = "", $include_all_feeds = true, + $root_id = null, $nest_level = 0) { + $pdo = DB::pdo(); -function print_feed_select($id, $default_id = "", - $attributes = "", $include_all_feeds = true, - $root_id = false, $nest_level = 0) { + print_r(in_array("CAT:6",$default_ids)); if (!$root_id) { - print ""; if ($include_all_feeds) { - $is_selected = ("0" == $default_id) ? "selected=\"1\"" : ""; + $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; print ""; } } if (get_pref('ENABLE_FEED_CATS')) { - if ($root_id) - $parent_qpart = "parent_cat = '$root_id'"; - else - $parent_qpart = "parent_cat IS NULL"; + if (!$root_id) $root_id = null; - $result = db_query("SELECT id,title, + $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 = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title"); + 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 = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { for ($i = 0; $i < $nest_level; $i++) $line["title"] = " - " . $line["title"]; - $is_selected = ("CAT:".$line["id"] == $default_id) ? "selected=\"1\"" : ""; + $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; printf("", $line["id"], htmlspecialchars($line["title"])); if ($line["num_children"] > 0) - print_feed_select($id, $default_id, $attributes, + print_feed_multi_select($id, $default_ids, $attributes, $include_all_feeds, $line["id"], $nest_level+1); - $feed_result = db_query("SELECT id,title FROM ttrss_feeds - WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); + $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 = db_fetch_assoc($feed_result)) { - $is_selected = ($fline["id"] == $default_id) ? "selected=\"1\"" : ""; + while ($fline = $f_sth->fetch()) { + $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; $fline["title"] = " + " . $fline["title"]; @@ -224,17 +132,17 @@ function print_feed_select($id, $default_id = "", } if (!$root_id) { - $default_is_cat = ($default_id == "CAT:0"); - $is_selected = $default_is_cat ? "selected=\"1\"" : ""; + $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; printf("", __("Uncategorized")); - $feed_result = db_query("SELECT id,title FROM ttrss_feeds - WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); + $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 = db_fetch_assoc($feed_result)) { - $is_selected = ($fline["id"] == $default_id && !$default_is_cat) ? "selected=\"1\"" : ""; + while ($fline = $f_sth->fetch()) { + $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; $fline["title"] = " + " . $fline["title"]; @@ -247,12 +155,13 @@ function print_feed_select($id, $default_id = "", } } else { - $result = db_query("SELECT id,title FROM ttrss_feeds - WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); + $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds + WHERE owner_uid = ? ORDER BY title"); + $sth->execute([$_SESSION['uid']]); - while ($line = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { - $is_selected = ($line["id"] == $default_id) ? "selected=\"1\"" : ""; + $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; printf("", $line["id"], htmlspecialchars($line["title"])); @@ -265,24 +174,29 @@ function print_feed_select($id, $default_id = "", } function print_feed_cat_select($id, $default_id, - $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) { + $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { if (!$root_id) { print ""; - while ($line = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; @@ -422,4 +331,3 @@ function print_label_select($name, $value, $attributes = "") { } -