]> git.wh0rd.org - tt-rss.git/blobdiff - include/controls.php
pngcrush.sh
[tt-rss.git] / include / controls.php
old mode 100644 (file)
new mode 100755 (executable)
index 0c56830..037e331
@@ -70,50 +70,56 @@ function print_radio($id, $default, $true_is, $values, $attributes = "") {
        }
 }
 
-function print_feed_select($id, $default_id = "",
+function print_feed_multi_select($id, $default_ids = [],
                                                   $attributes = "", $include_all_feeds = true,
-                                                  $root_id = false, $nest_level = 0) {
+                                                  $root_id = null, $nest_level = 0) {
+
+       $pdo = DB::pdo();
+
+       print_r(in_array("CAT:6",$default_ids));
 
        if (!$root_id) {
-               print "<select id=\"$id\" name=\"$id\" $attributes>";
+               print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
                if ($include_all_feeds) {
-                       $is_selected = ("0" == $default_id) ? "selected=\"1\"" : "";
+                       $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)
-                       $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("<option $is_selected value='CAT:%d'>%s</option>",
                                $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");
 
-                       while ($fline = db_fetch_assoc($feed_result)) {
-                               $is_selected = ($fline["id"] == $default_id) ? "selected=\"1\"" : "";
+                       $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"];
 
@@ -126,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("<option $is_selected value='CAT:0'>%s</option>",
                                __("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"];
 
@@ -149,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("<option $is_selected value='%d'>%s</option>",
                                $line["id"], htmlspecialchars($line["title"]));
@@ -167,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 "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
        }
 
-       if ($root_id)
-               $parent_qpart = "parent_cat = '$root_id'";
-       else
-               $parent_qpart = "parent_cat IS NULL";
+       $pdo = DB::pdo();
+
+       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]);
+
+       $found = 0;
+
+       while ($line = $sth->fetch()) {
+               ++$found;
 
-       while ($line = db_fetch_assoc($result)) {
                if ($line["id"] == $default_id) {
                        $is_selected = "selected=\"1\"";
                } else {
@@ -205,7 +217,7 @@ function print_feed_cat_select($id, $default_id,
 
        if (!$root_id) {
                if ($include_all_cats) {
-                       if (db_num_rows($result) > 0) {
+                       if ($found > 0) {
                                print "<option disabled=\"1\">--------</option>";
                        }
 
@@ -281,14 +293,6 @@ function format_inline_player($url, $ctype) {
                                        <source type=\"$ctype\" src=\"$url\"/>
                                        </audio>";
 
-               } else {
-
-                       $entry .= "<object type=\"application/x-shockwave-flash\"
-                                       data=\"lib/button/musicplayer.swf?song_url=$url\"
-                                       width=\"17\" height=\"17\" style='float : left; margin-right : 5px;'>
-                                       <param name=\"movie\"
-                                               value=\"lib/button/musicplayer.swf?song_url=$url\" />
-                                       </object>";
                }
 
                if ($entry) $entry .= "&nbsp; <a target=\"_blank\" rel=\"noopener noreferrer\"
@@ -300,3 +304,30 @@ function format_inline_player($url, $ctype) {
 
        return "";
 }
+
+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>";
+
+
+}