]>
git.wh0rd.org - tt-rss.git/blob - classes/counters.php
4 static function getAllCounters() {
5 $data = Counters
::getGlobalCounters();
7 $data = array_merge($data, Counters
::getVirtCounters());
8 $data = array_merge($data, Counters
::getLabelCounters());
9 $data = array_merge($data, Counters
::getFeedCounters());
10 $data = array_merge($data, Counters
::getCategoryCounters());
15 static function getCategoryCounters() {
20 $cv = array("id" => -2, "kind" => "cat",
21 "counter" => Feeds
::getCategoryUnread(-2));
23 array_push($ret_arr, $cv);
27 $sth = $pdo->prepare("SELECT id AS cat_id, value AS unread,
28 (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
29 WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
30 FROM ttrss_feed_categories, ttrss_cat_counters_cache
31 WHERE ttrss_cat_counters_cache.feed_id = id AND
32 ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND
33 ttrss_feed_categories.owner_uid = ?");
34 $sth->execute([$_SESSION['uid']]);
36 while ($line = $sth->fetch()) {
37 $line["cat_id"] = (int) $line["cat_id"];
39 if ($line["num_children"] > 0) {
40 $child_counter = Feeds
::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
45 $cv = array("id" => $line["cat_id"], "kind" => "cat",
46 "counter" => $line["unread"] +
$child_counter);
48 array_push($ret_arr, $cv);
51 /* Special case: NULL category doesn't actually exist in the DB */
53 $cv = array("id" => 0, "kind" => "cat",
54 "counter" => (int) CCache
::find(0, $_SESSION["uid"], true));
56 array_push($ret_arr, $cv);
61 static function getGlobalCounters($global_unread = -1) {
64 if ($global_unread == -1) {
65 $global_unread = Feeds
::getGlobalUnread();
68 $cv = array("id" => "global-unread",
69 "counter" => (int) $global_unread);
71 array_push($ret_arr, $cv);
75 $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM
76 ttrss_feeds WHERE owner_uid = ?");
77 $sth->execute([$_SESSION['uid']]);
80 $subscribed_feeds = $row["fn"];
82 $cv = array("id" => "subscribed-feeds",
83 "counter" => (int) $subscribed_feeds);
85 array_push($ret_arr, $cv);
90 static function getVirtCounters() {
94 for ($i = 0; $i >= -4; $i--) {
96 $count = getFeedUnread($i);
98 if ($i == 0 ||
$i == -1 ||
$i == -2)
99 $auxctr = Feeds
::getFeedArticles($i, false);
103 $cv = array("id" => $i,
104 "counter" => (int) $count,
105 "auxcounter" => (int) $auxctr);
107 // if (get_pref('EXTENDED_FEEDLIST'))
108 // $cv["xmsg"] = getFeedArticles($i)." ".__("total");
110 array_push($ret_arr, $cv);
113 $feeds = PluginHost
::getInstance()->get_feeds(-1);
115 if (is_array($feeds)) {
116 foreach ($feeds as $feed) {
117 $cv = array("id" => PluginHost
::pfeed_to_feed_id($feed['id']),
118 "counter" => $feed['sender']->get_unread($feed['id']));
120 if (method_exists($feed['sender'], 'get_total'))
121 $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
123 array_push($ret_arr, $cv);
130 static function getLabelCounters($descriptions = false) {
136 $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
137 FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
138 (ttrss_labels2.id = label_id)
139 LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
140 WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid
141 GROUP BY ttrss_labels2.id,
142 ttrss_labels2.caption");
143 $sth->execute([":uid" => $_SESSION['uid']]);
145 while ($line = $sth->fetch()) {
147 $id = Labels
::label_to_feed_id($line["id"]);
149 $cv = array("id" => $id,
150 "counter" => (int) $line["unread"],
151 "auxcounter" => (int) $line["total"]);
154 $cv["description"] = $line["caption"];
156 array_push($ret_arr, $cv);
162 static function getFeedCounters($active_feed = false) {
168 $sth = $pdo->prepare("SELECT ttrss_feeds.id,
170 ".SUBSTRING_FOR_DATE
."(ttrss_feeds.last_updated,1,19) AS last_updated,
171 last_error, value AS count
172 FROM ttrss_feeds, ttrss_counters_cache
173 WHERE ttrss_feeds.owner_uid = ?
174 AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid
175 AND ttrss_counters_cache.feed_id = id");
176 $sth->execute([$_SESSION['uid']]);
178 while ($line = $sth->fetch()) {
181 $count = $line["count"];
182 $last_error = htmlspecialchars($line["last_error"]);
184 $last_updated = make_local_datetime($line['last_updated'], false);
186 if (Feeds
::feedHasIcon($id)) {
187 $has_img = filemtime(Feeds
::getIconFile($id));
192 if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
195 $cv = array("id" => $id,
196 "updated" => $last_updated,
197 "counter" => (int) $count,
198 "has_img" => (int) $has_img);
201 $cv["error"] = $last_error;
203 // if (get_pref('EXTENDED_FEEDLIST'))
204 // $cv["xmsg"] = getFeedArticles($id)." ".__("total");
206 if ($active_feed && $id == $active_feed)
207 $cv["title"] = truncate_string($line["title"], 30);
209 array_push($ret_arr, $cv);