diff --git a/backend.php b/backend.php
index 1aa0f3937..8b031affa 100644
--- a/backend.php
+++ b/backend.php
@@ -208,11 +208,12 @@
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");
@@ -836,9 +837,17 @@
None
Toggle: Unread,
- Starred";
+ Starred";
+
print "";
+ if ($search && $feed_id > 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
+ print "
+
+ Convert this search to label | ";
+ }
+
} else {
print "
@@ -1430,13 +1439,23 @@
$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"]);
}
}
}
@@ -2228,11 +2247,12 @@
// print " Expression: $expr ";
$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");;
@@ -2241,12 +2261,13 @@
print "Query returned $num_matches matches, showing first 15: ";
$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 "";
@@ -3724,6 +3745,56 @@
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);
?>
diff --git a/functions.php b/functions.php
index 987b8c9bc..0a3d3f0f5 100644
--- a/functions.php
+++ b/functions.php
@@ -1261,7 +1261,8 @@
}
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) {
@@ -1336,11 +1337,12 @@
"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
@@ -1510,8 +1512,10 @@
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 {
@@ -1607,9 +1611,10 @@
$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");
@@ -1631,10 +1636,11 @@
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");
@@ -1958,38 +1964,49 @@
print "";
}
+ function getSearchSql($search, $match_on) {
+
+ $search_query_part = "";
+
+ $keywords = split(" ", $search);
+ $query_keywords = array();
+
+ if ($match_on == "both") {
+
+ foreach ($keywords as $k) {
+ array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
+ OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
+ }
+
+ $search_query_part = implode("AND", $query_keywords) . " AND ";
+
+ } else if ($match_on == "title") {
+
+ foreach ($keywords as $k) {
+ array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
+ }
+
+ $search_query_part = implode("AND", $query_keywords) . " AND ";
+
+ } 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) {
- $keywords = split(" ", $search);
- $query_keywords = array();
+ $search_query_part = getSearchSql($search, $match_on);
+ $search_query_part .= " AND ";
- if ($match_on == "both") {
-
- foreach ($keywords as $k) {
- array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%')
- OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))");
- }
-
- $search_query_part = implode("AND", $query_keywords) . " AND ";
-
- } else if ($match_on == "title") {
-
- foreach ($keywords as $k) {
- array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))");
- }
-
- $search_query_part = implode("AND", $query_keywords) . " AND ";
-
- } 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) . " AND ";
- }
} else {
$search_query_part = "";
}
@@ -2161,6 +2178,10 @@
$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 = "?";
}
diff --git a/tt-rss.js b/tt-rss.js
index 164e7ea28..e3d09ec31 100644
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -571,3 +571,4 @@ function catchupCurrentFeed() {
return viewCurrentFeed(0, 'MarkAllRead')
}
}
+
diff --git a/viewfeed.js b/viewfeed.js
index 58b7d3ecb..e5109b223 100644
--- a/viewfeed.js
+++ b/viewfeed.js
@@ -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";
}
-
+
}
|