}
}
- 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() {