From: Andrew Dolgov Date: Fri, 31 Mar 2017 08:21:35 +0000 (+0300) Subject: filter by search results while marking feed as read X-Git-Tag: 17.4~7 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=337535416f3d75f94a34c64e785f1c2200844013;p=tt-rss.git filter by search results while marking feed as read --- diff --git a/classes/feeds.php b/classes/feeds.php index 014c5e36..48c4ad19 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -300,6 +300,7 @@ class Feeds extends Handler_Protected { make_local_datetime($qfh_ret[4], false) : __("Never"); $highlight_words = $qfh_ret[5]; $reply['first_id'] = $qfh_ret[6]; + $reply['search_query'] = [$search, $search_language]; $vgroup_last_feed = $vgr_last_feed; diff --git a/classes/rpc.php b/classes/rpc.php index fd10a3a4..ca8ce39a 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -450,8 +450,10 @@ class RPC extends Handler_Protected { $feed_id = $this->dbh->escape_string($_REQUEST['feed_id']); $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; $mode = $this->dbh->escape_string($_REQUEST['mode']); + $search_query = $this->dbh->escape_string($_REQUEST['search_query']); + $search_lang = $this->dbh->escape_string($_REQUEST['search_lang']); - catchup_feed($feed_id, $is_cat, false, false, $mode); + catchup_feed($feed_id, $is_cat, false, false, $mode, [$search_query, $search_lang]); print json_encode(array("message" => "UPDATE_COUNTERS")); } diff --git a/include/functions.php b/include/functions.php index c6de853d..52675057 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1163,149 +1163,148 @@ } } - function catchup_feed($feed, $cat_view, $owner_uid = false, $max_id = false, $mode = 'all') { + function catchup_feed($feed, $cat_view, $owner_uid = false, $max_id = false, $mode = 'all', $search = false) { - if (!$owner_uid) $owner_uid = $_SESSION['uid']; - - //if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { + if (!$owner_uid) $owner_uid = $_SESSION['uid']; - // Todo: all this interval stuff needs some generic generator function + // Todo: all this interval stuff needs some generic generator function - $date_qpart = "false"; + $date_qpart = "false"; + $search_qpart = is_array($search) && $search[0] ? search_to_sql($search[0], $search[1])[0] : 'true'; - switch ($mode) { - case "1day": - if (DB_TYPE == "pgsql") { - $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; - } else { - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; - } - break; - case "1week": - if (DB_TYPE == "pgsql") { - $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; - } else { - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; - } - break; - case "2week": - if (DB_TYPE == "pgsql") { - $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; - } else { - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; - } - break; - default: - $date_qpart = "true"; + switch ($mode) { + case "1day": + if (DB_TYPE == "pgsql") { + $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; + } else { + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; } + break; + case "1week": + if (DB_TYPE == "pgsql") { + $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; + } else { + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; + } + break; + case "2week": + if (DB_TYPE == "pgsql") { + $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; + } else { + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; + } + break; + default: + $date_qpart = "true"; + } - if (is_numeric($feed)) { - if ($cat_view) { - - if ($feed >= 0) { - - if ($feed > 0) { - $children = getChildCategories($feed, $owner_uid); - array_push($children, $feed); - - $children = join(",", $children); + if (is_numeric($feed)) { + if ($cat_view) { - $cat_qpart = "cat_id IN ($children)"; - } else { - $cat_qpart = "cat_id IS NULL"; - } + if ($feed >= 0) { - db_query("UPDATE ttrss_user_entries - SET unread = false, last_read = NOW() WHERE ref_id IN - (SELECT id FROM - (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND unread = true AND feed_id IN - (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart) as tmp)"); + if ($feed > 0) { + $children = getChildCategories($feed, $owner_uid); + array_push($children, $feed); - } else if ($feed == -2) { + $children = join(",", $children); - db_query("UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) - FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart) > 0 - AND unread = true AND owner_uid = $owner_uid"); + $cat_qpart = "cat_id IN ($children)"; + } else { + $cat_qpart = "cat_id IS NULL"; } - } else if ($feed > 0) { - db_query("UPDATE ttrss_user_entries SET unread = false, last_read = NOW() WHERE ref_id IN (SELECT id FROM (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND unread = true AND feed_id = $feed AND $date_qpart) as tmp)"); + AND owner_uid = $owner_uid AND unread = true AND feed_id IN + (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)"); - } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred + } else if ($feed == -2) { - if ($feed == -1) { - db_query("UPDATE ttrss_user_entries - SET unread = false, last_read = NOW() WHERE ref_id IN - (SELECT id FROM - (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND unread = true AND marked = true AND $date_qpart) as tmp)"); - } + db_query("UPDATE ttrss_user_entries + SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) + FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart AND $search_qpart) > 0 + AND unread = true AND owner_uid = $owner_uid"); + } - if ($feed == -2) { - db_query("UPDATE ttrss_user_entries - SET unread = false, last_read = NOW() WHERE ref_id IN - (SELECT id FROM - (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND unread = true AND published = true AND $date_qpart) as tmp)"); - } + } else if ($feed > 0) { - if ($feed == -3) { + db_query("UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND feed_id = $feed AND $date_qpart AND $search_qpart) as tmp)"); - $intl = get_pref("FRESH_ARTICLE_MAX_AGE"); + } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred - if (DB_TYPE == "pgsql") { - $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; - } else { - $match_part = "date_entered > DATE_SUB(NOW(), - INTERVAL $intl HOUR) "; - } + if ($feed == -1) { + db_query("UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND marked = true AND $date_qpart AND $search_qpart) as tmp)"); + } - db_query("UPDATE ttrss_user_entries - SET unread = false, last_read = NOW() WHERE ref_id IN - (SELECT id FROM - (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND score >= 0 AND unread = true AND $date_qpart AND $match_part) as tmp)"); - } + if ($feed == -2) { + db_query("UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND published = true AND $date_qpart AND $search_qpart) as tmp)"); + } - if ($feed == -4) { - db_query("UPDATE ttrss_user_entries - SET unread = false, last_read = NOW() WHERE ref_id IN - (SELECT id FROM - (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id - AND owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); - } + if ($feed == -3) { - } else if ($feed < LABEL_BASE_INDEX) { // label + $intl = get_pref("FRESH_ARTICLE_MAX_AGE"); - $label_id = feed_to_label_id($feed); + if (DB_TYPE == "pgsql") { + $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; + } else { + $match_part = "date_entered > DATE_SUB(NOW(), + INTERVAL $intl HOUR) "; + } db_query("UPDATE ttrss_user_entries SET unread = false, last_read = NOW() WHERE ref_id IN (SELECT id FROM - (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id - AND label_id = '$label_id' AND ref_id = article_id - AND owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); + (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND score >= 0 AND unread = true AND $date_qpart AND $match_part AND $search_qpart) as tmp)"); + } + if ($feed == -4) { + db_query("UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); } - ccache_update($feed, $owner_uid, $cat_view); + } else if ($feed < LABEL_BASE_INDEX) { // label + + $label_id = feed_to_label_id($feed); - } else { // tag db_query("UPDATE ttrss_user_entries SET unread = false, last_read = NOW() WHERE ref_id IN (SELECT id FROM - (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id - AND post_int_id = int_id AND tag_name = '$feed' - AND ttrss_user_entries.owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); + (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id + AND label_id = '$label_id' AND ref_id = article_id + AND owner_uid = $owner_uid AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); } + + ccache_update($feed, $owner_uid, $cat_view); + + } else { // tag + db_query("UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id + AND post_int_id = int_id AND tag_name = '$feed' + AND ttrss_user_entries.owner_uid = $owner_uid AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); + + } } function getAllCounters() { diff --git a/js/feedlist.js b/js/feedlist.js index 941fe9e8..879b52d0 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -484,28 +484,31 @@ function catchupFeed(feed, is_cat, mode) { switch (mode) { case "1day": - str = __("Mark all articles in %s older than 1 day as read?"); + str = __("Mark %w in %s older than 1 day as read?"); break; case "1week": - str = __("Mark all articles in %s older than 1 week as read?"); + str = __("Mark %w in %s older than 1 week as read?"); break; case "2week": - str = __("Mark all articles in %s older than 2 weeks as read?"); + str = __("Mark %w in %s older than 2 weeks as read?"); break; default: - str = __("Mark all articles in %s as read?"); + str = __("Mark %w in %s as read?"); } + var mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); var fn = getFeedName(feed, is_cat); - str = str.replace("%s", fn); + str = str.replace("%s", fn) + .replace("%w", mark_what); if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { return; } - var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + - feed + "&is_cat=" + is_cat + "&mode=" + mode; + var catchup_query = {op: 'rpc', method: 'catchupFeed', feed_id: feed, + is_cat: is_cat, mode: mode, search_query: last_search_query[0], + search_lang: last_search_query[1]}; console.log(catchup_query); diff --git a/js/viewfeed.js b/js/viewfeed.js index 7cbcc08b..3e2f9775 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -13,6 +13,7 @@ var loaded_article_ids = []; var _last_headlines_update = 0; var _headlines_scroll_offset = 0; var current_first_id = 0; +var last_search_query; var _catchup_request_sent = false; @@ -38,6 +39,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { is_cat = reply['headlines']['is_cat']; feed_id = reply['headlines']['id']; + last_search_query = reply['headlines']['search_query']; if (background) { var content = reply['headlines']['content'];