Merge pull request 'Replace special feed and category numbers with constants.' (#104) from wn/tt-rss:feature/special-feed-and-cat-consts into master
Reviewed-on: https://dev.tt-rss.org/tt-rss/tt-rss/pulls/104
This commit is contained in:
commit
cddbf5bf5a
|
@ -169,7 +169,7 @@ class API extends Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ([-2,-1,0] as $cat_id) {
|
foreach ([Feeds::CATEGORY_LABELS, Feeds::CATEGORY_SPECIAL, Feeds::CATEGORY_UNCATEGORIZED] as $cat_id) {
|
||||||
if ($include_empty || !$this->_is_cat_empty($cat_id)) {
|
if ($include_empty || !$this->_is_cat_empty($cat_id)) {
|
||||||
$unread = Feeds::_get_counters($cat_id, true, true);
|
$unread = Feeds::_get_counters($cat_id, true, true);
|
||||||
|
|
||||||
|
@ -528,8 +528,8 @@ class API extends Handler {
|
||||||
|
|
||||||
/* Labels */
|
/* Labels */
|
||||||
|
|
||||||
/* API only: -4 All feeds, including virtual feeds */
|
/* API only: -4 (Feeds::CATEGORY_ALL) All feeds, including virtual feeds */
|
||||||
if ($cat_id == -4 || $cat_id == -2) {
|
if ($cat_id == Feeds::CATEGORY_ALL || $cat_id == Feeds::CATEGORY_LABELS) {
|
||||||
$counters = Counters::get_labels();
|
$counters = Counters::get_labels();
|
||||||
|
|
||||||
foreach (array_values($counters) as $cv) {
|
foreach (array_values($counters) as $cv) {
|
||||||
|
@ -540,7 +540,7 @@ class API extends Handler {
|
||||||
'id' => (int) $cv['id'],
|
'id' => (int) $cv['id'],
|
||||||
'title' => $cv['description'],
|
'title' => $cv['description'],
|
||||||
'unread' => $cv['counter'],
|
'unread' => $cv['counter'],
|
||||||
'cat_id' => -2,
|
'cat_id' => Feeds::CATEGORY_LABELS,
|
||||||
];
|
];
|
||||||
|
|
||||||
array_push($feeds, $row);
|
array_push($feeds, $row);
|
||||||
|
@ -550,7 +550,7 @@ class API extends Handler {
|
||||||
|
|
||||||
/* Virtual feeds */
|
/* Virtual feeds */
|
||||||
|
|
||||||
$vfeeds = PluginHost::getInstance()->get_feeds(-1);
|
$vfeeds = PluginHost::getInstance()->get_feeds(Feeds::CATEGORY_SPECIAL);
|
||||||
|
|
||||||
if (is_array($vfeeds)) {
|
if (is_array($vfeeds)) {
|
||||||
foreach ($vfeeds as $feed) {
|
foreach ($vfeeds as $feed) {
|
||||||
|
@ -565,7 +565,7 @@ class API extends Handler {
|
||||||
'id' => PluginHost::pfeed_to_feed_id($feed['id']),
|
'id' => PluginHost::pfeed_to_feed_id($feed['id']),
|
||||||
'title' => $feed['title'],
|
'title' => $feed['title'],
|
||||||
'unread' => $unread,
|
'unread' => $unread,
|
||||||
'cat_id' => -1,
|
'cat_id' => Feeds::CATEGORY_SPECIAL,
|
||||||
];
|
];
|
||||||
|
|
||||||
array_push($feeds, $row);
|
array_push($feeds, $row);
|
||||||
|
@ -573,8 +573,9 @@ class API extends Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cat_id == -4 || $cat_id == -1) {
|
if ($cat_id == Feeds::CATEGORY_ALL || $cat_id == Feeds::CATEGORY_SPECIAL) {
|
||||||
foreach ([-1, -2, -3, -4, -6, 0] as $i) {
|
foreach ([Feeds::FEED_STARRED, Feeds::FEED_PUBLISHED, Feeds::FEED_FRESH,
|
||||||
|
Feeds::FEED_ALL, Feeds::FEED_RECENTLY_READ, Feeds::FEED_ARCHIVED] as $i) {
|
||||||
$unread = Feeds::_get_counters($i, false, true);
|
$unread = Feeds::_get_counters($i, false, true);
|
||||||
|
|
||||||
if ($unread || !$unread_only) {
|
if ($unread || !$unread_only) {
|
||||||
|
@ -584,7 +585,7 @@ class API extends Handler {
|
||||||
'id' => $i,
|
'id' => $i,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'unread' => $unread,
|
'unread' => $unread,
|
||||||
'cat_id' => -1,
|
'cat_id' => Feeds::CATEGORY_SPECIAL,
|
||||||
];
|
];
|
||||||
|
|
||||||
array_push($feeds, $row);
|
array_push($feeds, $row);
|
||||||
|
@ -620,7 +621,7 @@ class API extends Handler {
|
||||||
|
|
||||||
/* Real feeds */
|
/* Real feeds */
|
||||||
|
|
||||||
/* API only: -3 All feeds, excluding virtual feeds (e.g. Labels and such) */
|
/* API only: -3 (Feeds::CATEGORY_ALL_EXCEPT_VIRTUAL) All feeds, excluding virtual feeds (e.g. Labels and such) */
|
||||||
$feeds_obj = ORM::for_table('ttrss_feeds')
|
$feeds_obj = ORM::for_table('ttrss_feeds')
|
||||||
->select_many('id', 'feed_url', 'cat_id', 'title', 'order_id')
|
->select_many('id', 'feed_url', 'cat_id', 'title', 'order_id')
|
||||||
->select_expr(SUBSTRING_FOR_DATE.'(last_updated,1,19)', 'last_updated')
|
->select_expr(SUBSTRING_FOR_DATE.'(last_updated,1,19)', 'last_updated')
|
||||||
|
@ -631,7 +632,7 @@ class API extends Handler {
|
||||||
if ($limit) $feeds_obj->limit($limit);
|
if ($limit) $feeds_obj->limit($limit);
|
||||||
if ($offset) $feeds_obj->offset($offset);
|
if ($offset) $feeds_obj->offset($offset);
|
||||||
|
|
||||||
if ($cat_id != -3 && $cat_id != -4) {
|
if ($cat_id != Feeds::CATEGORY_ALL_EXCEPT_VIRTUAL && $cat_id != Feeds::CATEGORY_ALL) {
|
||||||
$feeds_obj->where_raw('(cat_id = ? OR (? = 0 AND cat_id IS NULL))', [$cat_id, $cat_id]);
|
$feeds_obj->where_raw('(cat_id = ? OR (? = 0 AND cat_id IS NULL))', [$cat_id, $cat_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,13 +932,13 @@ class API extends Handler {
|
||||||
|
|
||||||
// only works for labels or uncategorized for the time being
|
// only works for labels or uncategorized for the time being
|
||||||
private function _is_cat_empty(int $id): bool {
|
private function _is_cat_empty(int $id): bool {
|
||||||
if ($id == -2) {
|
if ($id == Feeds::CATEGORY_LABELS) {
|
||||||
$label_count = ORM::for_table('ttrss_labels2')
|
$label_count = ORM::for_table('ttrss_labels2')
|
||||||
->where('owner_uid', $_SESSION['uid'])
|
->where('owner_uid', $_SESSION['uid'])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
return $label_count == 0;
|
return $label_count == 0;
|
||||||
} else if ($id == 0) {
|
} else if ($id == Feeds::CATEGORY_UNCATEGORIZED) {
|
||||||
$uncategorized_count = ORM::for_table('ttrss_feeds')
|
$uncategorized_count = ORM::for_table('ttrss_feeds')
|
||||||
->where_null('cat_id')
|
->where_null('cat_id')
|
||||||
->where('owner_uid', $_SESSION['uid'])
|
->where('owner_uid', $_SESSION['uid'])
|
||||||
|
|
|
@ -60,8 +60,8 @@ class Counters {
|
||||||
|
|
||||||
/* Labels category */
|
/* Labels category */
|
||||||
|
|
||||||
$cv = array("id" => -2, "kind" => "cat",
|
$cv = array("id" => Feeds::CATEGORY_LABELS, "kind" => "cat",
|
||||||
"counter" => Feeds::_get_cat_unread(-2));
|
"counter" => Feeds::_get_cat_unread(Feeds::CATEGORY_LABELS));
|
||||||
|
|
||||||
array_push($ret, $cv);
|
array_push($ret, $cv);
|
||||||
|
|
||||||
|
@ -244,28 +244,29 @@ class Counters {
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
for ($i = 0; $i >= -4; $i--) {
|
foreach ([Feeds::FEED_ARCHIVED, Feeds::FEED_STARRED, Feeds::FEED_PUBLISHED,
|
||||||
|
Feeds::FEED_FRESH, Feeds::FEED_ALL] as $feed_id) {
|
||||||
|
|
||||||
$count = Feeds::_get_counters($i, false, true);
|
$count = Feeds::_get_counters($feed_id, false, true);
|
||||||
|
|
||||||
if ($i == 0 || $i == -1 || $i == -2)
|
if (in_array($feed_id, [Feeds::FEED_ARCHIVED, Feeds::FEED_STARRED, Feeds::FEED_PUBLISHED]))
|
||||||
$auxctr = Feeds::_get_counters($i, false);
|
$auxctr = Feeds::_get_counters($feed_id, false);
|
||||||
else
|
else
|
||||||
$auxctr = 0;
|
$auxctr = 0;
|
||||||
|
|
||||||
$cv = [
|
$cv = [
|
||||||
"id" => $i,
|
"id" => $feed_id,
|
||||||
"counter" => (int) $count,
|
"counter" => (int) $count,
|
||||||
"auxcounter" => (int) $auxctr
|
"auxcounter" => (int) $auxctr
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($i == -1)
|
if ($feed_id == Feeds::FEED_STARRED)
|
||||||
$cv["markedcounter"] = $auxctr;
|
$cv["markedcounter"] = $auxctr;
|
||||||
|
|
||||||
array_push($ret, $cv);
|
array_push($ret, $cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feeds = PluginHost::getInstance()->get_feeds(-1);
|
$feeds = PluginHost::getInstance()->get_feeds(Feeds::CATEGORY_SPECIAL);
|
||||||
|
|
||||||
if (is_array($feeds)) {
|
if (is_array($feeds)) {
|
||||||
foreach ($feeds as $feed) {
|
foreach ($feeds as $feed) {
|
||||||
|
|
|
@ -2,8 +2,52 @@
|
||||||
require_once "colors.php";
|
require_once "colors.php";
|
||||||
|
|
||||||
class Feeds extends Handler_Protected {
|
class Feeds extends Handler_Protected {
|
||||||
const NEVER_GROUP_FEEDS = [ -6, 0 ];
|
/** special feed for archived articles */
|
||||||
const NEVER_GROUP_BY_DATE = [ -2, -1, -3 ];
|
const FEED_ARCHIVED = 0;
|
||||||
|
|
||||||
|
/** special feed for starred articles */
|
||||||
|
const FEED_STARRED = -1;
|
||||||
|
|
||||||
|
/** special feed for published articles */
|
||||||
|
const FEED_PUBLISHED = -2;
|
||||||
|
|
||||||
|
/** special feed for archived articles */
|
||||||
|
const FEED_FRESH = -3;
|
||||||
|
|
||||||
|
/** special feed for all articles */
|
||||||
|
const FEED_ALL = -4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a special case feed used to display auxiliary information when there's nothing to load (e.g. no stuff in fresh feed)
|
||||||
|
*
|
||||||
|
* TODO: Remove this and 'Feeds::_generate_dashboard_feed()'? It only seems to be used if 'Feeds::view()' (also potentially removable)
|
||||||
|
* gets passed the ID.
|
||||||
|
*/
|
||||||
|
const FEED_DASHBOARD = -5;
|
||||||
|
|
||||||
|
/** special feed for recently read articles */
|
||||||
|
const FEED_RECENTLY_READ = -6;
|
||||||
|
|
||||||
|
/** special feed for error scenarios (e.g. feed not found) */
|
||||||
|
const FEED_ERROR = -7;
|
||||||
|
|
||||||
|
/** special "category" for uncategorized articles */
|
||||||
|
const CATEGORY_UNCATEGORIZED = 0;
|
||||||
|
|
||||||
|
/** special category for "special" articles (e.g. Starred, Published, Archived, plugin-provided, etc.) */
|
||||||
|
const CATEGORY_SPECIAL = -1;
|
||||||
|
|
||||||
|
/** special category for labels */
|
||||||
|
const CATEGORY_LABELS = -2;
|
||||||
|
|
||||||
|
/** special category for all feeds, excluding virtual feeds (e.g. labels and such) */
|
||||||
|
const CATEGORY_ALL_EXCEPT_VIRTUAL = -3;
|
||||||
|
|
||||||
|
/** special category for all feeds, including virtual feeds (e.g. labels and such) */
|
||||||
|
const CATEGORY_ALL = -4;
|
||||||
|
|
||||||
|
const NEVER_GROUP_FEEDS = [ Feeds::FEED_RECENTLY_READ, Feeds::FEED_ARCHIVED ];
|
||||||
|
const NEVER_GROUP_BY_DATE = [ Feeds::FEED_PUBLISHED, Feeds::FEED_STARRED, Feeds::FEED_FRESH ];
|
||||||
|
|
||||||
/** @var int|float int on 64-bit, float on 32-bit */
|
/** @var int|float int on 64-bit, float on 32-bit */
|
||||||
private $viewfeed_timestamp;
|
private $viewfeed_timestamp;
|
||||||
|
@ -205,7 +249,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
// normalize archived feed
|
// normalize archived feed
|
||||||
if ($line['feed_id'] === null) {
|
if ($line['feed_id'] === null) {
|
||||||
$line['feed_id'] = 0;
|
$line['feed_id'] = Feeds::FEED_ARCHIVED;
|
||||||
$line["feed_title"] = __("Archived articles");
|
$line["feed_title"] = __("Archived articles");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,10 +522,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
if (is_numeric($feed)) $feed = (int) $feed;
|
if (is_numeric($feed)) $feed = (int) $feed;
|
||||||
|
|
||||||
/* Feed -5 is a special case: it is used to display auxiliary information
|
if ($feed == Feeds::FEED_DASHBOARD) {
|
||||||
* when there's nothing to load - e.g. no stuff in fresh feed */
|
|
||||||
|
|
||||||
if ($feed == -5) {
|
|
||||||
print json_encode($this->_generate_dashboard_feed());
|
print json_encode($this->_generate_dashboard_feed());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +607,7 @@ class Feeds extends Handler_Protected {
|
||||||
private function _generate_dashboard_feed(): array {
|
private function _generate_dashboard_feed(): array {
|
||||||
$reply = array();
|
$reply = array();
|
||||||
|
|
||||||
$reply['headlines']['id'] = -5;
|
$reply['headlines']['id'] = Feeds::FEED_DASHBOARD;
|
||||||
$reply['headlines']['is_cat'] = false;
|
$reply['headlines']['is_cat'] = false;
|
||||||
|
|
||||||
$reply['headlines']['toolbar'] = '';
|
$reply['headlines']['toolbar'] = '';
|
||||||
|
@ -610,7 +651,7 @@ class Feeds extends Handler_Protected {
|
||||||
private function _generate_error_feed(string $error): array {
|
private function _generate_error_feed(string $error): array {
|
||||||
$reply = array();
|
$reply = array();
|
||||||
|
|
||||||
$reply['headlines']['id'] = -7;
|
$reply['headlines']['id'] = Feeds::FEED_ERROR;
|
||||||
$reply['headlines']['is_cat'] = false;
|
$reply['headlines']['is_cat'] = false;
|
||||||
|
|
||||||
$reply['headlines']['toolbar'] = '';
|
$reply['headlines']['toolbar'] = '';
|
||||||
|
@ -827,7 +868,9 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
if ($feed_id >= 0) {
|
if ($feed_id >= 0) {
|
||||||
|
|
||||||
if ($feed_id > 0) {
|
if ($feed_id == Feeds::CATEGORY_UNCATEGORIZED) {
|
||||||
|
$cat_qpart = "cat_id IS NULL";
|
||||||
|
} else {
|
||||||
$children = self::_get_child_cats($feed_id, $owner_uid);
|
$children = self::_get_child_cats($feed_id, $owner_uid);
|
||||||
array_push($children, $feed_id);
|
array_push($children, $feed_id);
|
||||||
$children = array_map("intval", $children);
|
$children = array_map("intval", $children);
|
||||||
|
@ -835,8 +878,6 @@ class Feeds extends Handler_Protected {
|
||||||
$children = join(",", $children);
|
$children = join(",", $children);
|
||||||
|
|
||||||
$cat_qpart = "cat_id IN ($children)";
|
$cat_qpart = "cat_id IN ($children)";
|
||||||
} else {
|
|
||||||
$cat_qpart = "cat_id IS NULL";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||||
|
@ -847,7 +888,7 @@ class Feeds extends Handler_Protected {
|
||||||
(SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
|
(SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
|
||||||
$sth->execute([$owner_uid]);
|
$sth->execute([$owner_uid]);
|
||||||
|
|
||||||
} else if ($feed_id == -2) {
|
} else if ($feed_id == Feeds::CATEGORY_LABELS) {
|
||||||
|
|
||||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
|
SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
|
||||||
|
@ -867,7 +908,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
} else if ($feed_id < 0 && $feed_id > LABEL_BASE_INDEX) { // special, like starred
|
} else if ($feed_id < 0 && $feed_id > LABEL_BASE_INDEX) { // special, like starred
|
||||||
|
|
||||||
if ($feed_id == -1) {
|
if ($feed_id == Feeds::FEED_STARRED) {
|
||||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
(SELECT id FROM
|
(SELECT id FROM
|
||||||
|
@ -876,7 +917,7 @@ class Feeds extends Handler_Protected {
|
||||||
$sth->execute([$owner_uid]);
|
$sth->execute([$owner_uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed_id == -2) {
|
if ($feed_id == Feeds::FEED_PUBLISHED) {
|
||||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
(SELECT id FROM
|
(SELECT id FROM
|
||||||
|
@ -885,7 +926,7 @@ class Feeds extends Handler_Protected {
|
||||||
$sth->execute([$owner_uid]);
|
$sth->execute([$owner_uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed_id == -3) {
|
if ($feed_id == Feeds::FEED_FRESH) {
|
||||||
|
|
||||||
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE);
|
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE);
|
||||||
|
|
||||||
|
@ -904,7 +945,7 @@ class Feeds extends Handler_Protected {
|
||||||
$sth->execute([$owner_uid]);
|
$sth->execute([$owner_uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed_id == -4) {
|
if ($feed_id == Feeds::FEED_ALL) {
|
||||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
(SELECT id FROM
|
(SELECT id FROM
|
||||||
|
@ -973,7 +1014,7 @@ class Feeds extends Handler_Protected {
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if ($n_feed == -6) {
|
} else if ($n_feed == Feeds::FEED_RECENTLY_READ) {
|
||||||
return 0;
|
return 0;
|
||||||
// tags
|
// tags
|
||||||
} else if ($feed != "0" && $n_feed == 0) {
|
} else if ($feed != "0" && $n_feed == 0) {
|
||||||
|
@ -989,11 +1030,11 @@ class Feeds extends Handler_Protected {
|
||||||
// Handle 'SUM()' returning null if there are no results
|
// Handle 'SUM()' returning null if there are no results
|
||||||
return $row["count"] ?? 0;
|
return $row["count"] ?? 0;
|
||||||
|
|
||||||
} else if ($n_feed == -1) {
|
} else if ($n_feed == Feeds::FEED_STARRED) {
|
||||||
$match_part = "marked = true";
|
$match_part = "marked = true";
|
||||||
} else if ($n_feed == -2) {
|
} else if ($n_feed == Feeds::FEED_PUBLISHED) {
|
||||||
$match_part = "published = true";
|
$match_part = "published = true";
|
||||||
} else if ($n_feed == -3) {
|
} else if ($n_feed == Feeds::FEED_FRESH) {
|
||||||
$match_part = "unread = true AND score >= 0";
|
$match_part = "unread = true AND score >= 0";
|
||||||
|
|
||||||
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid);
|
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid);
|
||||||
|
@ -1006,11 +1047,11 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
$need_entries = true;
|
$need_entries = true;
|
||||||
|
|
||||||
} else if ($n_feed == -4) {
|
} else if ($n_feed == Feeds::FEED_ALL) {
|
||||||
$match_part = "true";
|
$match_part = "true";
|
||||||
} else if ($n_feed >= 0) {
|
} else if ($n_feed >= 0) {
|
||||||
|
|
||||||
if ($n_feed != 0) {
|
if ($n_feed != Feeds::FEED_ARCHIVED) {
|
||||||
$match_part = sprintf("feed_id = %d", $n_feed);
|
$match_part = sprintf("feed_id = %d", $n_feed);
|
||||||
} else {
|
} else {
|
||||||
$match_part = "feed_id IS NULL";
|
$match_part = "feed_id IS NULL";
|
||||||
|
@ -1191,17 +1232,17 @@ class Feeds extends Handler_Protected {
|
||||||
*/
|
*/
|
||||||
static function _get_icon(int $id) {
|
static function _get_icon(int $id) {
|
||||||
switch ($id) {
|
switch ($id) {
|
||||||
case 0:
|
case Feeds::FEED_ARCHIVED:
|
||||||
return "archive";
|
return "archive";
|
||||||
case -1:
|
case Feeds::FEED_STARRED:
|
||||||
return "star";
|
return "star";
|
||||||
case -2:
|
case Feeds::FEED_PUBLISHED:
|
||||||
return "rss_feed";
|
return "rss_feed";
|
||||||
case -3:
|
case Feeds::FEED_FRESH:
|
||||||
return "whatshot";
|
return "whatshot";
|
||||||
case -4:
|
case Feeds::FEED_ALL:
|
||||||
return "inbox";
|
return "inbox";
|
||||||
case -6:
|
case Feeds::FEED_RECENTLY_READ:
|
||||||
return "restore";
|
return "restore";
|
||||||
default:
|
default:
|
||||||
if ($id < LABEL_BASE_INDEX) {
|
if ($id < LABEL_BASE_INDEX) {
|
||||||
|
@ -1264,17 +1305,17 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
if ($cat) {
|
if ($cat) {
|
||||||
return self::_get_cat_title($id);
|
return self::_get_cat_title($id);
|
||||||
} else if ($id == -1) {
|
} else if ($id == Feeds::FEED_STARRED) {
|
||||||
return __("Starred articles");
|
return __("Starred articles");
|
||||||
} else if ($id == -2) {
|
} else if ($id == Feeds::FEED_PUBLISHED) {
|
||||||
return __("Published articles");
|
return __("Published articles");
|
||||||
} else if ($id == -3) {
|
} else if ($id == Feeds::FEED_FRESH) {
|
||||||
return __("Fresh articles");
|
return __("Fresh articles");
|
||||||
} else if ($id == -4) {
|
} else if ($id == Feeds::FEED_ALL) {
|
||||||
return __("All articles");
|
return __("All articles");
|
||||||
} else if ($id === 0) {
|
} else if ($id === Feeds::FEED_ARCHIVED) {
|
||||||
return __("Archived articles");
|
return __("Archived articles");
|
||||||
} else if ($id == -6) {
|
} else if ($id == Feeds::FEED_RECENTLY_READ) {
|
||||||
return __("Recently read");
|
return __("Recently read");
|
||||||
} else if ($id < LABEL_BASE_INDEX) {
|
} else if ($id < LABEL_BASE_INDEX) {
|
||||||
|
|
||||||
|
@ -1350,9 +1391,9 @@ class Feeds extends Handler_Protected {
|
||||||
if ($row = $sth->fetch()) {
|
if ($row = $sth->fetch()) {
|
||||||
return (int) $row["unread"];
|
return (int) $row["unread"];
|
||||||
}
|
}
|
||||||
} else if ($cat == -1) {
|
} else if ($cat == Feeds::CATEGORY_SPECIAL) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if ($cat == -2) {
|
} else if ($cat == Feeds::CATEGORY_LABELS) {
|
||||||
|
|
||||||
$sth = $pdo->prepare("SELECT COUNT(DISTINCT article_id) AS unread
|
$sth = $pdo->prepare("SELECT COUNT(DISTINCT article_id) AS unread
|
||||||
FROM ttrss_user_entries ue, ttrss_user_labels2 l
|
FROM ttrss_user_entries ue, ttrss_user_labels2 l
|
||||||
|
@ -1407,11 +1448,11 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
static function _get_cat_title(int $cat_id): string {
|
static function _get_cat_title(int $cat_id): string {
|
||||||
switch ($cat_id) {
|
switch ($cat_id) {
|
||||||
case 0:
|
case Feeds::CATEGORY_UNCATEGORIZED:
|
||||||
return __("Uncategorized");
|
return __("Uncategorized");
|
||||||
case -1:
|
case Feeds::CATEGORY_SPECIAL:
|
||||||
return __("Special");
|
return __("Special");
|
||||||
case -2:
|
case Feeds::CATEGORY_LABELS:
|
||||||
return __("Labels");
|
return __("Labels");
|
||||||
default:
|
default:
|
||||||
$cat = ORM::for_table('ttrss_feed_categories')
|
$cat = ORM::for_table('ttrss_feed_categories')
|
||||||
|
@ -1526,6 +1567,7 @@ class Feeds extends Handler_Protected {
|
||||||
if ($search) {
|
if ($search) {
|
||||||
$view_query_part = " ";
|
$view_query_part = " ";
|
||||||
} else if ($feed != -1) {
|
} else if ($feed != -1) {
|
||||||
|
// not Feeds::FEED_STARRED or Feeds::CATEGORY_SPECIAL
|
||||||
|
|
||||||
$unread = Feeds::_get_counters($feed, $cat_view, true);
|
$unread = Feeds::_get_counters($feed, $cat_view, true);
|
||||||
|
|
||||||
|
@ -1550,7 +1592,7 @@ class Feeds extends Handler_Protected {
|
||||||
$view_query_part = " published = true AND ";
|
$view_query_part = " published = true AND ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($view_mode == "unread" && $feed != -6) {
|
if ($view_mode == "unread" && $feed != Feeds::FEED_RECENTLY_READ) {
|
||||||
$view_query_part = " unread = true AND ";
|
$view_query_part = " unread = true AND ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1594,13 +1636,13 @@ class Feeds extends Handler_Protected {
|
||||||
} else {
|
} else {
|
||||||
$query_strategy_part = "feed_id = " . $pdo->quote((string)$feed);
|
$query_strategy_part = "feed_id = " . $pdo->quote((string)$feed);
|
||||||
}
|
}
|
||||||
} else if ($feed == 0 && !$cat_view) { // archive virtual feed
|
} else if ($feed == Feeds::FEED_ARCHIVED && !$cat_view) { // archive virtual feed
|
||||||
$query_strategy_part = "feed_id IS NULL";
|
$query_strategy_part = "feed_id IS NULL";
|
||||||
$allow_archived = true;
|
$allow_archived = true;
|
||||||
} else if ($feed == 0 && $cat_view) { // uncategorized
|
} else if ($feed == Feeds::CATEGORY_UNCATEGORIZED && $cat_view) { // uncategorized
|
||||||
$query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
|
$query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
|
||||||
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
||||||
} else if ($feed == -1) { // starred virtual feed
|
} else if ($feed == -1) { // starred virtual feed, Feeds::FEED_STARRED or Feeds::CATEGORY_SPECIAL
|
||||||
$query_strategy_part = "marked = true";
|
$query_strategy_part = "marked = true";
|
||||||
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
||||||
$allow_archived = true;
|
$allow_archived = true;
|
||||||
|
@ -1609,7 +1651,7 @@ class Feeds extends Handler_Protected {
|
||||||
$override_order = "last_marked DESC, date_entered DESC, updated DESC";
|
$override_order = "last_marked DESC, date_entered DESC, updated DESC";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ($feed == -2) { // published virtual feed OR labels category
|
} else if ($feed == -2) { // published virtual feed (Feeds::FEED_PUBLISHED) OR labels category (Feeds::CATEGORY_LABELS)
|
||||||
|
|
||||||
if (!$cat_view) {
|
if (!$cat_view) {
|
||||||
$query_strategy_part = "published = true";
|
$query_strategy_part = "published = true";
|
||||||
|
@ -1629,7 +1671,7 @@ class Feeds extends Handler_Protected {
|
||||||
ttrss_user_labels2.article_id = ref_id";
|
ttrss_user_labels2.article_id = ref_id";
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if ($feed == -6) { // recently read
|
} else if ($feed == Feeds::FEED_RECENTLY_READ) { // recently read
|
||||||
$query_strategy_part = "unread = false AND last_read IS NOT NULL";
|
$query_strategy_part = "unread = false AND last_read IS NOT NULL";
|
||||||
|
|
||||||
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
|
@ -1644,7 +1686,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
if (!$override_order) $override_order = "last_read DESC";
|
if (!$override_order) $override_order = "last_read DESC";
|
||||||
|
|
||||||
} else if ($feed == -3) { // fresh virtual feed
|
} else if ($feed == Feeds::FEED_FRESH) { // fresh virtual feed
|
||||||
$query_strategy_part = "unread = true AND score >= 0";
|
$query_strategy_part = "unread = true AND score >= 0";
|
||||||
|
|
||||||
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid);
|
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid);
|
||||||
|
@ -1656,7 +1698,7 @@ class Feeds extends Handler_Protected {
|
||||||
}
|
}
|
||||||
|
|
||||||
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
||||||
} else if ($feed == -4) { // all articles virtual feed
|
} else if ($feed == Feeds::FEED_ALL) { // all articles virtual feed
|
||||||
$allow_archived = true;
|
$allow_archived = true;
|
||||||
$query_strategy_part = "true";
|
$query_strategy_part = "true";
|
||||||
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
$vfeed_query_part = "ttrss_feeds.title AS feed_title,";
|
||||||
|
@ -1771,7 +1813,7 @@ class Feeds extends Handler_Protected {
|
||||||
|
|
||||||
$first_id_query_strategy_part = $query_strategy_part;
|
$first_id_query_strategy_part = $query_strategy_part;
|
||||||
|
|
||||||
if ($feed == -3)
|
if ($feed == Feeds::FEED_FRESH)
|
||||||
$first_id_query_strategy_part = "true";
|
$first_id_query_strategy_part = "true";
|
||||||
|
|
||||||
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
if (Config::get(Config::DB_TYPE) == "pgsql") {
|
||||||
|
@ -1785,7 +1827,7 @@ class Feeds extends Handler_Protected {
|
||||||
}
|
}
|
||||||
|
|
||||||
// except for Labels category
|
// except for Labels category
|
||||||
if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid) && !($feed == -2 && $cat_view)) {
|
if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid) && !($feed == Feeds::CATEGORY_LABELS && $cat_view)) {
|
||||||
$distinct_qpart = "";
|
$distinct_qpart = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ class Handler_Public extends Handler {
|
||||||
if (!$override_order) {
|
if (!$override_order) {
|
||||||
$override_order = "date_entered DESC, updated DESC";
|
$override_order = "date_entered DESC, updated DESC";
|
||||||
|
|
||||||
if ($feed == -2 && !$is_cat) {
|
if ($feed == Feeds::FEED_PUBLISHED && !$is_cat) {
|
||||||
$override_order = "last_published DESC";
|
$override_order = "last_published DESC";
|
||||||
} else if ($feed == -1 && !$is_cat) {
|
} else if ($feed == Feeds::FEED_STARRED && !$is_cat) {
|
||||||
$override_order = "last_marked DESC";
|
$override_order = "last_marked DESC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ class Handler_Public extends Handler {
|
||||||
|
|
||||||
if ($fresh) {
|
if ($fresh) {
|
||||||
print ";";
|
print ";";
|
||||||
print Feeds::_get_counters(-3, false, true, $uid);
|
print Feeds::_get_counters(Feeds::FEED_FRESH, false, true, $uid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "-1;User not found";
|
print "-1;User not found";
|
||||||
|
|
|
@ -781,7 +781,7 @@ class PluginHost {
|
||||||
|
|
||||||
// Plugin feed functions are *EXPERIMENTAL*!
|
// Plugin feed functions are *EXPERIMENTAL*!
|
||||||
|
|
||||||
// cat_id: only -1 is supported (Special)
|
// cat_id: only -1 (Feeds::CATEGORY_SPECIAL) is supported (Special)
|
||||||
function add_feed(int $cat_id, string $title, string $icon, Plugin $sender): int {
|
function add_feed(int $cat_id, string $title, string $icon, Plugin $sender): int {
|
||||||
|
|
||||||
if (empty($this->feeds[$cat_id]))
|
if (empty($this->feeds[$cat_id]))
|
||||||
|
|
|
@ -135,18 +135,19 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
if (clean($_REQUEST['mode'] ?? 0) == 2) {
|
if (clean($_REQUEST['mode'] ?? 0) == 2) {
|
||||||
|
|
||||||
if ($enable_cats) {
|
if ($enable_cats) {
|
||||||
$cat = $this->feedlist_init_cat(-1);
|
$cat = $this->feedlist_init_cat(Feeds::CATEGORY_SPECIAL);
|
||||||
} else {
|
} else {
|
||||||
$cat['items'] = array();
|
$cat['items'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array(-4, -3, -1, -2, 0, -6) as $i) {
|
foreach ([Feeds::FEED_ALL, Feeds::FEED_FRESH, Feeds::FEED_STARRED, Feeds::FEED_PUBLISHED,
|
||||||
array_push($cat['items'], $this->feedlist_init_feed($i));
|
Feeds::FEED_ARCHIVED, Feeds::FEED_RECENTLY_READ] as $feed_id) {
|
||||||
|
array_push($cat['items'], $this->feedlist_init_feed($feed_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Plugin feeds for -1 */
|
/* Plugin feeds for -1 (Feeds::CATEGORY_SPECIAL) */
|
||||||
|
|
||||||
$feeds = PluginHost::getInstance()->get_feeds(-1);
|
$feeds = PluginHost::getInstance()->get_feeds(Feeds::CATEGORY_SPECIAL);
|
||||||
|
|
||||||
if ($feeds) {
|
if ($feeds) {
|
||||||
foreach ($feeds as $feed) {
|
foreach ($feeds as $feed) {
|
||||||
|
@ -180,7 +181,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
$sth->execute([$_SESSION['uid']]);
|
$sth->execute([$_SESSION['uid']]);
|
||||||
|
|
||||||
if (get_pref(Prefs::ENABLE_FEED_CATS)) {
|
if (get_pref(Prefs::ENABLE_FEED_CATS)) {
|
||||||
$cat = $this->feedlist_init_cat(-2);
|
$cat = $this->feedlist_init_cat(Feeds::CATEGORY_LABELS);
|
||||||
} else {
|
} else {
|
||||||
$cat['items'] = [];
|
$cat['items'] = [];
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1033,7 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
<?= format_notice('Published articles can be subscribed by anyone who knows the following URL:') ?></h3>
|
<?= format_notice('Published articles can be subscribed by anyone who knows the following URL:') ?></h3>
|
||||||
|
|
||||||
<button dojoType='dijit.form.Button' class='alt-primary'
|
<button dojoType='dijit.form.Button' class='alt-primary'
|
||||||
onclick="CommonDialogs.generatedFeed(-2, false)">
|
onclick="CommonDialogs.generatedFeed(<?= Feeds::FEED_PUBLISHED ?>, false)">
|
||||||
<?= \Controls\icon('share') ?>
|
<?= \Controls\icon('share') ?>
|
||||||
<?= __('Display URL') ?>
|
<?= __('Display URL') ?>
|
||||||
</button>
|
</button>
|
||||||
|
|
10
js/App.js
10
js/App.js
|
@ -1198,19 +1198,19 @@ const App = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_read"] = () => {
|
this.hotkey_actions["goto_read"] = () => {
|
||||||
Feeds.open({feed: -6});
|
Feeds.open({feed: Feeds.FEED_RECENTLY_READ});
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_all"] = () => {
|
this.hotkey_actions["goto_all"] = () => {
|
||||||
Feeds.open({feed: -4});
|
Feeds.open({feed: Feeds.FEED_ALL});
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_fresh"] = () => {
|
this.hotkey_actions["goto_fresh"] = () => {
|
||||||
Feeds.open({feed: -3});
|
Feeds.open({feed: Feeds.FEED_FRESH});
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_marked"] = () => {
|
this.hotkey_actions["goto_marked"] = () => {
|
||||||
Feeds.open({feed: -1});
|
Feeds.open({feed: Feeds.FEED_STARRED});
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_published"] = () => {
|
this.hotkey_actions["goto_published"] = () => {
|
||||||
Feeds.open({feed: -2});
|
Feeds.open({feed: Feeds.FEED_PUBLISHED});
|
||||||
};
|
};
|
||||||
this.hotkey_actions["goto_prefs"] = () => {
|
this.hotkey_actions["goto_prefs"] = () => {
|
||||||
App.openPreferences();
|
App.openPreferences();
|
||||||
|
|
|
@ -225,8 +225,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
if (item.auxcounter > 0) rc += " Has_Aux";
|
if (item.auxcounter > 0) rc += " Has_Aux";
|
||||||
if (item.markedcounter > 0) rc += " Has_Marked";
|
if (item.markedcounter > 0) rc += " Has_Marked";
|
||||||
if (item.updates_disabled > 0) rc += " UpdatesDisabled";
|
if (item.updates_disabled > 0) rc += " UpdatesDisabled";
|
||||||
if (item.bare_id >= App.LABEL_BASE_INDEX && item.bare_id < 0 && !is_cat || item.bare_id == 0 && !is_cat) rc += " Special";
|
if (item.bare_id >= App.LABEL_BASE_INDEX && item.bare_id < 0 && !is_cat || item.bare_id == Feeds.FEED_ARCHIVED && !is_cat) rc += " Special";
|
||||||
if (item.bare_id == -1 && is_cat) rc += " AlwaysVisible";
|
if (item.bare_id == Feeds.CATEGORY_SPECIAL && is_cat) rc += " AlwaysVisible";
|
||||||
if (item.bare_id < App.LABEL_BASE_INDEX) rc += " Label";
|
if (item.bare_id < App.LABEL_BASE_INDEX) rc += " Label";
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
13
js/Feeds.js
13
js/Feeds.js
|
@ -3,6 +3,19 @@
|
||||||
/* global __, App, Headlines, xhr, dojo, dijit, fox, PluginHost, Notify, fox */
|
/* global __, App, Headlines, xhr, dojo, dijit, fox, PluginHost, Notify, fox */
|
||||||
|
|
||||||
const Feeds = {
|
const Feeds = {
|
||||||
|
FEED_ARCHIVED: 0,
|
||||||
|
FEED_STARRED: -1,
|
||||||
|
FEED_PUBLISHED: -2,
|
||||||
|
FEED_FRESH: -3,
|
||||||
|
FEED_ALL: -4,
|
||||||
|
FEED_DASHBOARD: -5,
|
||||||
|
FEED_RECENTLY_READ: -6,
|
||||||
|
FEED_ERROR: -7,
|
||||||
|
CATEGORY_UNCATEGORIZED: 0,
|
||||||
|
CATEGORY_SPECIAL: -1,
|
||||||
|
CATEGORY_LABELS: -2,
|
||||||
|
CATEGORY_ALL_EXCEPT_VIRTUAL: -3,
|
||||||
|
CATEGORY_ALL: -4,
|
||||||
_default_feed_id: -3,
|
_default_feed_id: -3,
|
||||||
counters_last_request: 0,
|
counters_last_request: 0,
|
||||||
_active_feed_id: undefined,
|
_active_feed_id: undefined,
|
||||||
|
|
|
@ -307,7 +307,7 @@ const Headlines = {
|
||||||
offset = unread_in_buffer;
|
offset = unread_in_buffer;
|
||||||
break;
|
break;
|
||||||
case "adaptive":
|
case "adaptive":
|
||||||
if (!(Feeds.getActive() == -1 && !Feeds.activeIsCat()))
|
if (!(Feeds.getActive() == Feeds.FEED_STARRED && !Feeds.activeIsCat()))
|
||||||
offset = num_unread > 0 ? unread_in_buffer : num_all;
|
offset = num_unread > 0 ? unread_in_buffer : num_all;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -746,7 +746,7 @@ const Headlines = {
|
||||||
feed_id = reply['headlines']['id'];
|
feed_id = reply['headlines']['id'];
|
||||||
Feeds.last_search_query = reply['headlines']['search_query'];
|
Feeds.last_search_query = reply['headlines']['search_query'];
|
||||||
|
|
||||||
if (feed_id != -7 && (feed_id != Feeds.getActive() || is_cat != Feeds.activeIsCat()))
|
if (feed_id != Feeds.FEED_ERROR && (feed_id != Feeds.getActive() || is_cat != Feeds.activeIsCat()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const headlines_count = reply['headlines-info']['count'];
|
const headlines_count = reply['headlines-info']['count'];
|
||||||
|
|
Loading…
Reference in New Issue