1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-16 00:15:57 +00:00

move to Article:

+       static function purge_orphans($do_output = false) {

move to Feeds

+       static function getGlobalUnread($user_id = false) {
+       static function getCategoryTitle($cat_id) {
+       static function getLabelUnread($label_id, $owner_uid = false) {
This commit is contained in:
Andrew Dolgov
2017-05-04 15:00:21 +03:00
parent 86a8351ca2
commit a230bf88a9
10 changed files with 128 additions and 127 deletions

View File

@@ -101,7 +101,7 @@ class API extends Handler {
if ($feed_id) {
$this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat)));
} else {
$this->wrap(self::STATUS_OK, array("unread" => getGlobalUnread()));
$this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread()));
}
}
@@ -170,7 +170,7 @@ class API extends Handler {
if ($unread || !$unread_only) {
array_push($cats, array("id" => $cat_id,
"title" => getCategoryTitle($cat_id),
"title" => Feeds::getCategoryTitle($cat_id),
"unread" => $unread));
}
}

View File

@@ -864,4 +864,17 @@ class Article extends Handler_Protected {
return $rv;
}
static function purge_orphans($do_output = false) {
// purge orphaned posts in main content table
$result = db_query("DELETE FROM ttrss_entries WHERE
NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id)");
if ($do_output) {
$rows = db_affected_rows($result);
_debug("Purged $rows orphaned posts.");
}
}
}

View File

@@ -1445,7 +1445,7 @@ class Feeds extends Handler_Protected {
$label_id = feed_to_label_id($feed);
return getLabelUnread($label_id, $owner_uid);
return Feeds::getLabelUnread($label_id, $owner_uid);
}
@@ -1602,7 +1602,7 @@ class Feeds extends Handler_Protected {
static function getFeedTitle($id, $cat = false) {
if ($cat) {
return getCategoryTitle($id);
return Feeds::getCategoryTitle($id);
} else if ($id == -1) {
return __("Starred articles");
} else if ($id == -2) {
@@ -1707,5 +1707,51 @@ class Feeds extends Handler_Protected {
return $unread;
}
static function getGlobalUnread($user_id = false) {
if (!$user_id) {
$user_id = $_SESSION["uid"];
}
$result = db_query("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
WHERE owner_uid = '$user_id' AND feed_id > 0");
$c_id = db_fetch_result($result, 0, "c_id");
return $c_id;
}
static function getCategoryTitle($cat_id) {
if ($cat_id == -1) {
return __("Special");
} else if ($cat_id == -2) {
return __("Labels");
} else {
$result = db_query("SELECT title FROM ttrss_feed_categories WHERE
id = '$cat_id'");
if (db_num_rows($result) == 1) {
return db_fetch_result($result, 0, "title");
} else {
return __("Uncategorized");
}
}
}
static function getLabelUnread($label_id, $owner_uid = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
$result = db_query("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id");
if (db_num_rows($result) != 0) {
return db_fetch_result($result, 0, "unread");
} else {
return 0;
}
}
}

View File

@@ -287,7 +287,7 @@ class Handler_Public extends Handler {
if ($this->dbh->num_rows($result) == 1) {
$uid = $this->dbh->fetch_result($result, 0, "id");
print getGlobalUnread($uid);
print Feeds::getGlobalUnread($uid);
if ($fresh) {
print ";";

View File

@@ -1542,7 +1542,7 @@ class Pref_Feeds extends Handler_Protected {
$obj['id'] = 'CAT:' . $cat_id;
$obj['items'] = array();
$obj['name'] = getCategoryTitle($cat_id);
$obj['name'] = Feeds::getCategoryTitle($cat_id);
$obj['type'] = 'category';
$obj['unread'] = (int) $cat_unread;
$obj['bare_id'] = $cat_id;

View File

@@ -224,7 +224,7 @@ class Pref_Filters extends Handler_Protected {
while ($line = $this->dbh->fetch_assoc($result)) {
$where = sql_bool_to_bool($line["cat_filter"]) ?
getCategoryTitle($line["cat_id"]) :
Feeds::getCategoryTitle($line["cat_id"]) :
($line["feed_id"] ?
Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
@@ -497,7 +497,7 @@ class Pref_Filters extends Handler_Protected {
if (strpos($feed_id, "CAT:") === 0) {
$feed_id = (int) substr($feed_id, 4);
$feed = getCategoryTitle($feed_id);
$feed = Feeds::getCategoryTitle($feed_id);
} else {
$feed_id = (int) $feed_id;

View File

@@ -151,7 +151,7 @@ class RPC extends Handler_Protected {
$this->dbh->query("DELETE FROM ttrss_user_entries
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
purge_orphans();
Article::purge_orphans();
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
@@ -556,7 +556,7 @@ class RPC extends Handler_Protected {
}
// Purge orphans and cleanup tags
purge_orphans();
Article::purge_orphans();
//cleanup_tags(14, 50000);
if ($num_updated > 0) {