]> git.wh0rd.org Git - tt-rss.git/commitdiff
add search-to-label converter, ability to unsubscribe from label, various label fixes
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 1 Aug 2006 07:54:46 +0000 (08:54 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 1 Aug 2006 07:54:46 +0000 (08:54 +0100)
backend.php
functions.php
tt-rss.js
viewfeed.js

index 1aa0f3937913f99943a3c92d7e726208a698523e..8b031affad8f93e529ea83cda0975f517bdc4e80 100644 (file)
        
                                        error_reporting (0);
                
-                                       $tmp_result = db_query($link, "SELECT count(id) as count 
-                                               FROM ttrss_entries,ttrss_user_entries
+                                       $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count 
+                                               FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
                                                WHERE (" . $line["sql_exp"] . ") AND unread = true AND
-                                               ttrss_user_entries.ref_id = ttrss_entries.id
-                                               AND owner_uid = '$owner_uid'");
+                                               ttrss_user_entries.ref_id = ttrss_entries.id AND
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id
+                                               AND ttrss_user_entries.owner_uid = '$owner_uid'");
        
                                        $count = db_fetch_result($tmp_result, 0, "count");
        
                                                                <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
                                                &nbsp;&nbsp;
                                                Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
-                                                               <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
+                                                       <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
+
                                print "</td>";
 
+                               if ($search && $feed_id > 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
+                                       print "<td class=\"headlineActions$rtl_cpart\">
+                                               <a href=\"javascript:labelFromSearch('$search', '$search_mode',
+                                                               '$match_on', '$feed_id', '$is_cat');\">
+                                                       Convert this search to label</a></td>";
+                               }
+
                        } else {
 
                                print "<td class=\"headlineActions$rtl_cpart\">
                                $ids = split(",", db_escape_string($_GET["ids"]));
 
                                foreach ($ids as $id) {
-                                       db_query($link, "DELETE FROM ttrss_feeds 
-                                               WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
-                                       $icons_dir = ICONS_DIR;
+                                       if ($id > 0) {
+
+                                               db_query($link, "DELETE FROM ttrss_feeds 
+                                                       WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+
+                                               $icons_dir = ICONS_DIR;
                                        
-                                       if (file_exists($icons_dir . "/$id.ico")) {
-                                               unlink($icons_dir . "/$id.ico");
+                                               if (file_exists($icons_dir . "/$id.ico")) {
+                                                       unlink($icons_dir . "/$id.ico");
+                                               }
+                                       } else if ($id < -10) {
+
+                                               $label_id = -$id - 11;
+
+                                               db_query($link, "DELETE FROM ttrss_labels
+                                                       WHERE   id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
                                        }
                                }
                        }
 //                     print "<p><b>Expression</b>: $expr</p>";
 
                        $result = db_query($link, 
-                               "SELECT count(id) AS num_matches
-                                       FROM ttrss_entries,ttrss_user_entries
+                               "SELECT count(ttrss_entries.id) AS num_matches
+                                       FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
                                        WHERE ($expr) AND 
                                                ttrss_user_entries.ref_id = ttrss_entries.id AND
-                                               owner_uid = " . $_SESSION["uid"]);
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                                               ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
 
                        $num_matches = db_fetch_result($result, 0, "num_matches");;
                        
                                print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>";
 
                                $result = db_query($link, 
-                                       "SELECT title, 
+                                       "SELECT ttrss_entries.title, 
                                                (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
-                                       FROM ttrss_entries,ttrss_user_entries
+                                       FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
                                                        WHERE ($expr) AND 
                                                        ttrss_user_entries.ref_id = ttrss_entries.id
-                                                       AND owner_uid = " . $_SESSION["uid"] . " 
+                                                       AND ttrss_user_entries.feed_id = ttrss_feeds.id
+                                                       AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " 
                                                        ORDER BY date_entered DESC LIMIT 15");
 
                                print "<ul class=\"filterTestResults\">";
                return false;
        }
 
+       if ($op == "labelFromSearch") {
+               $search = db_escape_string($_GET["search"]);
+               $search_mode = db_escape_string($_GET["smode"]);
+               $match_on = db_escape_string($_GET["match"]);
+               $is_cat = db_escape_string($_GET["is_cat"]);
+               $title = db_escape_string($_GET["title"]);
+               $feed = sprintf("%d", $_GET["feed"]);
+
+               $label_qparts = array();
+
+               $search_expr = getSearchSql($search, $match_on);
+
+               if ($is_cat) {
+                       if ($feed != 0) {
+                               $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
+                       } else {
+                               $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
+                       }
+               } else {
+                       if ($search_mode == "all_feeds") {
+                               // NOOP
+                       } else if ($search_mode == "this_cat") {
+
+                               $tmp_result = db_query($link, "SELECT cat_id
+                                       FROM ttrss_feeds WHERE id = '$feed'");
+
+                               $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
+
+                               if ($cat_id > 0) {
+                                       $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
+                               } else {
+                                       $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
+                               }
+                       } else {
+                               $search_expr .= " AND ttrss_feeds.id = $feed ";
+                       }
+
+               }
+
+               $search_expr = db_escape_string($search_expr);
+
+               print $search_expr;
+
+               if ($title) {
+                       $result = db_query($link,
+                               "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) 
+                               VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
+               }
+       }
+
        db_close($link);
 ?>
 
index 987b8c9bc4cdd1845809aa41de1def00f4a0a15e..0a3d3f0f52b0b1e126e1a7c1b31e7d456cb50c85 100644 (file)
        }
 
        function catchup_feed($link, $feed, $cat_view) {
-                       if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) {
+
+                       if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
                        
                                if ($cat_view) {
 
                                                        "SELECT 
                                                                int_id 
                                                        FROM 
-                                                               ttrss_user_entries,ttrss_entries 
+                                                               ttrss_user_entries,ttrss_entries,ttrss_feeds
                                                        WHERE
-                                                               ref_id = id AND 
+                                                               ref_id = ttrss_entries.id AND 
+                                                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
                                                                $sql_exp AND
-                                                               owner_uid = " . $_SESSION["uid"]);
+                                                               ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
 
                                                while ($tmp_line = db_fetch_assoc($tmp2_result)) {
                                                        db_query($link, "UPDATE 
                if ($match_part) {
                
                        $result = db_query($link, "SELECT count(int_id) AS unread 
-                               FROM ttrss_user_entries 
-                               WHERE   unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
+                               FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE
+                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                               ttrss_user_entries.ref_id = ttrss_entries.id AND 
+                               unread = true AND ($match_part) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
                                
                } else {
                
                $old_counters = $_SESSION["lctr_last_value"];
                $lctrs_modified = false;
 
-               $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
+               $result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
                        WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND 
-                       unread = true AND owner_uid = ".$_SESSION["uid"]);
+                       ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                       unread = true AND ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
 
                $count = db_fetch_result($result, 0, "count");
 
 
                        error_reporting (0);
 
-                       $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
+                       $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count FROM ttrss_user_entries,ttrss_entries,ttrss_feeds
                                WHERE (" . $line["sql_exp"] . ") AND unread = true AND 
+                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
                                ttrss_user_entries.ref_id = ttrss_entries.id AND 
-                               owner_uid = ".$_SESSION["uid"]);
+                               ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
 
                        $count = db_fetch_result($tmp_result, 0, "count");
 
                print "</runtime-info>";
        }
 
-       function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false) {
+       function getSearchSql($search, $match_on) {
 
-                       if ($search) {
-                       
-                               $keywords = split(" ", $search);
-                               $query_keywords = array();
+               $search_query_part = "";
 
-                               if ($match_on == "both") {
+               $keywords = split(" ", $search);
+               $query_keywords = array();
 
-                                       foreach ($keywords as $k) {
-                                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
-                                                       OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
-                                       }
+               if ($match_on == "both") {
 
-                                       $search_query_part = implode("AND", $query_keywords) . " AND ";
+                       foreach ($keywords as $k) {
+                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
+                                       OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
+                       }
 
-                               } else if ($match_on == "title") {
+                       $search_query_part = implode("AND", $query_keywords) . " AND ";
 
-                                       foreach ($keywords as $k) {
-                                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
-                                       }
+               } else if ($match_on == "title") {
 
-                                       $search_query_part = implode("AND", $query_keywords) . " AND ";
+                       foreach ($keywords as $k) {
+                               array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
+                       }
 
-                               } else if ($match_on == "content") {
+                       $search_query_part = implode("AND", $query_keywords) . " AND ";
 
-                                       foreach ($keywords as $k) {
-                                               array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
-                                       }
+               } else if ($match_on == "content") {
+
+                       foreach ($keywords as $k) {
+                               array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
+                       }
+               }
+
+               $search_query_part = implode("AND", $query_keywords);
+
+               return $search_query_part;
+       }
+
+       function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false) {
+
+                       if ($search) {
+                       
+                               $search_query_part = getSearchSql($search, $match_on);
+                               $search_query_part .= " AND ";
 
-                                       $search_query_part = implode("AND", $query_keywords) . " AND ";
-                               }
                        } else {
                                $search_query_part = "";
                        }
                                $result = db_query($link, "SELECT description FROM ttrss_labels
                                        WHERE id = '$label_id'");
                                $feed_title = db_fetch_result($result, 0, "description");
+
+                               if ($search) {
+                                       $feed_title = "Label search results ($search, $feed_title)";
+                               }
                        } else {
                                $feed_title = "?";
                        }
index 164e7ea2885398df76fbec33132f8be3d07d16c2..e3d09ec3171411580ae8205d47381b1d116c9198 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -571,3 +571,4 @@ function catchupCurrentFeed() {
                return viewCurrentFeed(0, 'MarkAllRead')
        }
 }
+
index 58b7d3ecbfc6214267ff22317c67b876804c8a0b..e5109b22383b76dfe186290f65ab948d776d3078 100644 (file)
@@ -325,6 +325,31 @@ function catchupPage() {
        selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
 }
 
+function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
+
+       if (!xmlhttp_ready(xmlhttp_rpc)) {
+               printLockingError();
+       }
+
+       var title = prompt("Please enter label title:", "");
+
+       if (title) {
+
+               var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
+                       "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
+                       "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + 
+                       "&title=" + param_escape(title);
+
+               debug("LFS: " + query);
+       
+               xmlhttp_rpc.open("GET", query, true);
+               xmlhttp_rpc.onreadystatechange=getMainContext().dlg_frefresh_callback;
+               xmlhttp_rpc.send(null);
+       }
+
+}
+
+
 
 function init() {
        if (arguments.callee.done) return;
@@ -341,5 +366,5 @@ function init() {
                var bt = document.getElementById("headlineActionsBottom");
                bt.className = "headlinesSubToolbar";
        }
-       
+
 }