summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/api.php34
-rw-r--r--classes/pref/feeds.php10
-rw-r--r--classes/pref/filters.php61
-rwxr-xr-xupdate_daemon2.php17
4 files changed, 69 insertions, 53 deletions
diff --git a/classes/api.php b/classes/api.php
index 0e56e58f9..ea57a61ab 100644
--- a/classes/api.php
+++ b/classes/api.php
@@ -165,12 +165,14 @@ class API extends Handler {
}
foreach (array(-2,-1,0) as $cat_id) {
- $unread = getFeedUnread($this->link, $cat_id, true);
+ if ($include_empty || !$this->isCategoryEmpty($cat_id)) {
+ $unread = getFeedUnread($this->link, $cat_id, true);
- if ($unread || !$unread_only) {
- array_push($cats, array("id" => $cat_id,
- "title" => getCategoryTitle($this->link, $cat_id),
- "unread" => $unread));
+ if ($unread || !$unread_only) {
+ array_push($cats, array("id" => $cat_id,
+ "title" => getCategoryTitle($this->link, $cat_id),
+ "unread" => $unread));
+ }
}
}
@@ -724,6 +726,28 @@ class API extends Handler {
}
}
+
+ // only works for labels or uncategorized for the time being
+ private function isCategoryEmpty($id) {
+
+ if ($id == -2) {
+ $result = db_query($this->link, "SELECT COUNT(*) AS count FROM ttrss_labels2
+ WHERE owner_uid = " . $_SESSION["uid"]);
+
+ return db_fetch_result($result, 0, "count") == 0;
+
+ } else if ($id == 0) {
+ $result = db_query($this->link, "SELECT COUNT(*) AS count FROM ttrss_feeds
+ WHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"]);
+
+ return db_fetch_result($result, 0, "count") == 0;
+
+ }
+
+ return false;
+ }
+
+
}
?>
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index e48953e94..46c3d083b 100644
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -58,7 +58,7 @@ class Pref_Feeds extends Handler_Protected {
$cat['items'] = $this->get_category_items($line['id']);
- $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($items, $cat);
@@ -206,7 +206,7 @@ class Pref_Feeds extends Handler_Protected {
$cat['items'] = $this->get_category_items($line['id']);
- $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($root['items'], $cat);
@@ -248,13 +248,13 @@ class Pref_Feeds extends Handler_Protected {
array_push($cat['items'], $feed);
}
- $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+ $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
if (count($cat['items']) > 0 || $show_empty_cats)
array_push($root['items'], $cat);
$root['param'] += count($cat['items']);
- $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+ $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
} else {
$feed_result = db_query($this->link, "SELECT id, title, last_error,
@@ -279,7 +279,7 @@ class Pref_Feeds extends Handler_Protected {
array_push($root['items'], $feed);
}
- $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+ $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
}
$fl = array();
diff --git a/classes/pref/filters.php b/classes/pref/filters.php
index 2f0fc5ebb..4be1cdae5 100644
--- a/classes/pref/filters.php
+++ b/classes/pref/filters.php
@@ -954,59 +954,36 @@ class Pref_Filters extends Handler_Protected {
private function getFilterName($id) {
$result = db_query($this->link,
- "SELECT title FROM ttrss_filters2 WHERE id = '$id'");
+ "SELECT title,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions
+ FROM ttrss_filters2 AS f LEFT JOIN ttrss_filters2_rules AS r
+ ON (r.filter_id = f.id)
+ LEFT JOIN ttrss_filters2_actions AS a
+ ON (a.filter_id = f.id) WHERE f.id = '$id' GROUP BY f.title");
$title = db_fetch_result($result, 0, "title");
+ $num_rules = db_fetch_result($result, 0, "num_rules");
+ $num_actions = db_fetch_result($result, 0, "num_actions");
- if (!$title) {
+ if (!$title) $title = __("[No caption]");
- $result = db_query($this->link,
- "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
- LIMIT 3");
+ $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", $num_rules), $title, $num_rules);
- $titles = array();
- $count = 0;
-
- while ($line = db_fetch_assoc($result)) {
-
- if (sql_bool_to_bool($line["cat_filter"])) {
- unset($line["cat_filter"]);
- $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
- unset($line["cat_id"]);
- }
-
- if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
+ $result = db_query($this->link,
+ "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 1");
- if ($count < 2) {
- array_push($titles, $this->getRuleName($line));
- } else {
- array_push($titles, "...");
- break;
- }
- ++$count;
- }
+ $actions = "";
- $title = __("[No caption]") . " " . truncate_string(join(", ", $titles), 64, "...");
+ if (db_num_rows($result) > 0) {
+ $line = db_fetch_assoc($result);
+ $actions = $this->getActionName($line);
+ $num_actions -= 1;
}
- $result = db_query($this->link,
- "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
-
- $actions = array();
- $count = 0;
-
- while ($line = db_fetch_assoc($result)) {
- if ($count < 2) {
- array_push($actions, $this->getActionName($line));
- } else {
- array_push($actions, "...");
- break;
- }
- ++$count;
- }
+ if ($num_actions > 0)
+ $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", $num_actions), $actions, $num_actions);
- return array($title, join(", ", $actions));
+ return array($title, $actions);
}
function join() {
diff --git a/update_daemon2.php b/update_daemon2.php
index fa64b302d..c87f0c10a 100755
--- a/update_daemon2.php
+++ b/update_daemon2.php
@@ -176,7 +176,9 @@
// It is unnecessary to start the fork loop if database is not ok.
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- if (!init_connection($link)) return;
+ if (!init_connection($link)) die("Can't initialize db connection.\n");
+
+ $schema_version = get_schema_version($link);
db_close($link);
@@ -193,6 +195,19 @@
if ($last_checkpoint + $spawn_interval < time()) {
+ /* Check if schema version changed */
+
+ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+ if (!init_connection($link)) die("Can't initialize db connection.\n");
+ $test_schema_version = get_schema_version($link);
+ db_close($link);
+
+ if ($test_schema_version != $schema_version) {
+ _debug("Expected schema version: $schema_version, got: $test_schema_version");
+ _debug("Schema version changed while we were running, bailing out");
+ exit(100);
+ }
+
check_ctimes();
reap_children();