]>
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);
25 $result = db_query("SELECT id AS cat_id, value AS unread,
26 (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
27 WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
28 FROM ttrss_feed_categories, ttrss_cat_counters_cache
29 WHERE ttrss_cat_counters_cache.feed_id = id AND
30 ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND
31 ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
33 while ($line = db_fetch_assoc($result)) {
34 $line["cat_id"] = (int) $line["cat_id"];
36 if ($line["num_children"] > 0) {
37 $child_counter = Feeds
::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
42 $cv = array("id" => $line["cat_id"], "kind" => "cat",
43 "counter" => $line["unread"] +
$child_counter);
45 array_push($ret_arr, $cv);
48 /* Special case: NULL category doesn't actually exist in the DB */
50 $cv = array("id" => 0, "kind" => "cat",
51 "counter" => (int) CCache
::find(0, $_SESSION["uid"], true));
53 array_push($ret_arr, $cv);
58 static function getGlobalCounters($global_unread = -1) {
61 if ($global_unread == -1) {
62 $global_unread = Feeds
::getGlobalUnread();
65 $cv = array("id" => "global-unread",
66 "counter" => (int) $global_unread);
68 array_push($ret_arr, $cv);
70 $result = db_query("SELECT COUNT(id) AS fn FROM
71 ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
73 $subscribed_feeds = db_fetch_result($result, 0, "fn");
75 $cv = array("id" => "subscribed-feeds",
76 "counter" => (int) $subscribed_feeds);
78 array_push($ret_arr, $cv);
83 static function getVirtCounters() {
87 for ($i = 0; $i >= -4; $i--) {
89 $count = getFeedUnread($i);
91 if ($i == 0 ||
$i == -1 ||
$i == -2)
92 $auxctr = Feeds
::getFeedArticles($i, false);
96 $cv = array("id" => $i,
97 "counter" => (int) $count,
98 "auxcounter" => (int) $auxctr);
100 // if (get_pref('EXTENDED_FEEDLIST'))
101 // $cv["xmsg"] = getFeedArticles($i)." ".__("total");
103 array_push($ret_arr, $cv);
106 $feeds = PluginHost
::getInstance()->get_feeds(-1);
108 if (is_array($feeds)) {
109 foreach ($feeds as $feed) {
110 $cv = array("id" => PluginHost
::pfeed_to_feed_id($feed['id']),
111 "counter" => $feed['sender']->get_unread($feed['id']));
113 if (method_exists($feed['sender'], 'get_total'))
114 $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
116 array_push($ret_arr, $cv);
123 static function getLabelCounters($descriptions = false) {
127 $owner_uid = $_SESSION["uid"];
129 $result = db_query("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
130 FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
131 (ttrss_labels2.id = label_id)
132 LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
133 WHERE ttrss_labels2.owner_uid = $owner_uid AND u1.owner_uid = $owner_uid
134 GROUP BY ttrss_labels2.id,
135 ttrss_labels2.caption");
137 while ($line = db_fetch_assoc($result)) {
139 $id = Labels
::label_to_feed_id($line["id"]);
141 $cv = array("id" => $id,
142 "counter" => (int) $line["unread"],
143 "auxcounter" => (int) $line["total"]);
146 $cv["description"] = $line["caption"];
148 array_push($ret_arr, $cv);
154 static function getFeedCounters($active_feed = false) {
158 $query = "SELECT ttrss_feeds.id,
160 ".SUBSTRING_FOR_DATE
."(ttrss_feeds.last_updated,1,19) AS last_updated,
161 last_error, value AS count
162 FROM ttrss_feeds, ttrss_counters_cache
163 WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
164 AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid
165 AND ttrss_counters_cache.feed_id = id";
167 $result = db_query($query);
169 while ($line = db_fetch_assoc($result)) {
172 $count = $line["count"];
173 $last_error = htmlspecialchars($line["last_error"]);
175 $last_updated = make_local_datetime($line['last_updated'], false);
177 $has_img = feed_has_icon($id);
179 if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
182 $cv = array("id" => $id,
183 "updated" => $last_updated,
184 "counter" => (int) $count,
185 "has_img" => (int) $has_img);
188 $cv["error"] = $last_error;
190 // if (get_pref('EXTENDED_FEEDLIST'))
191 // $cv["xmsg"] = getFeedArticles($id)." ".__("total");
193 if ($active_feed && $id == $active_feed)
194 $cv["title"] = truncate_string($line["title"], 30);
196 array_push($ret_arr, $cv);