From ee0bc6edd9e744790e70233e16e7eea290bcf5cc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 14:36:52 +0400 Subject: [PATCH 1/9] add ttrss_feed_categories.parent_cat, bump schema --- schema/ttrss_schema_mysql.sql | 5 ++++- schema/ttrss_schema_pgsql.sql | 3 ++- schema/versions/mysql/93.sql | 10 ++++++++++ schema/versions/pgsql/93.sql | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 schema/versions/mysql/93.sql create mode 100644 schema/versions/pgsql/93.sql diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 5e6ca6096..3f63d44ee 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -57,6 +57,9 @@ create table ttrss_feed_categories(id integer not null primary key auto_incremen title varchar(200) not null, collapsed bool not null default false, order_id integer not null default 0, + parent_cat integer, + index(parent_cat), + foreign key (parent_cat) references ttrss_feed_categories(id) ON DELETE SET NULL, index(owner_uid), foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8; @@ -267,7 +270,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8; -insert into ttrss_version values (92); +insert into ttrss_version values (93); create table ttrss_enclosures (id integer primary key auto_increment, content_url text not null, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 3e0d800c9..d5d3f88f0 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -52,6 +52,7 @@ create table ttrss_feed_categories(id serial not null primary key, owner_uid integer not null references ttrss_users(id) on delete cascade, collapsed boolean not null default false, order_id integer not null default 0, + parent_cat integer references ttrss_feed_categories(id) on delete set null, title varchar(200) not null); create table ttrss_feeds (id serial not null primary key, @@ -231,7 +232,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (92); +insert into ttrss_version values (93); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/schema/versions/mysql/93.sql b/schema/versions/mysql/93.sql new file mode 100644 index 000000000..56b96e3b5 --- /dev/null +++ b/schema/versions/mysql/93.sql @@ -0,0 +1,10 @@ +begin; + +alter table ttrss_feed_categories add column parent_cat integer; +update ttrss_feed_categories set parent_cat = NULL; + +alter table ttrss_feed_categories add FOREIGN KEY (parent_cat) REFERENCES ttrss_feed_categories(id) ON DELETE SET NULL; + +update ttrss_version set schema_version = 93; + +commit; diff --git a/schema/versions/pgsql/93.sql b/schema/versions/pgsql/93.sql new file mode 100644 index 000000000..0374c0b0a --- /dev/null +++ b/schema/versions/pgsql/93.sql @@ -0,0 +1,10 @@ +begin; + +alter table ttrss_feed_categories add column parent_cat integer; +update ttrss_feed_categories set parent_cat = NULL; + +alter table ttrss_feed_categories add constraint "$2" FOREIGN KEY (parent_cat) REFERENCES ttrss_feed_categories(id) ON DELETE SET NULL; + +update ttrss_version set schema_version = 93; + +commit; From 2a060a94562a2e1678f15d69a7e71e376325e9c1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 14:47:43 +0400 Subject: [PATCH 2/9] initial work on nested categories --- classes/feeds.php | 127 ++++++++++++++++++++++++++++++++++++- classes/pref_feeds.php | 141 ++++++++++++++++++++++++++++++++++------- include/functions.php | 2 +- js/PrefFeedTree.js | 8 +-- 4 files changed, 247 insertions(+), 31 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 0c9812479..0762b0067 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -842,6 +842,8 @@ class Feeds extends Protected_Handler { } } + $this->feedlist_process_category('root', &$feedlist); + /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) { if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { $order_by_qpart = "order_id,category,unread DESC,title"; @@ -858,7 +860,7 @@ class Feeds extends Protected_Handler { /* real feeds */ - if ($enable_cats) + /* if ($enable_cats) $order_by_qpart = "ttrss_feed_categories.order_id,category, ttrss_feeds.order_id,title"; else @@ -876,7 +878,7 @@ class Feeds extends Protected_Handler { ON (ttrss_feeds.id = feed_id) WHERE - ttrss_feeds.owner_uid = '$owner_uid' + ttrss_feeds.owner_uid = '$owner_uid' AND parent_cat IS NULL ORDER BY $order_by_qpart"; $result = db_query($this->link, $query); @@ -932,11 +934,130 @@ class Feeds extends Protected_Handler { $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); } - } + } */ return $feedlist; } + private function feedlist_process_category($cat_id, &$feedlist) { + $owner_uid = $_SESSION['uid']; + $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS'); + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { + $order_by_qpart = "order_id,category,unread DESC,title"; + } else { + $order_by_qpart = "order_id,category,title"; + } + } else { + if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { + $order_by_qpart = "unread DESC,title"; + } else { + $order_by_qpart = "title"; + } + } + + if ($enable_cats) + $order_by_qpart = "ttrss_feed_categories.order_id,category, + ttrss_feeds.order_id,title"; + else + $order_by_qpart = "title"; + + /* real feeds */ + + if ($enable_cats) + $order_by_qpart = "ttrss_feed_categories.order_id,category, + ttrss_feeds.order_id,title"; + else + $order_by_qpart = "title"; + + if (!$enable_cats) { + $parent_qpart = "true"; + } else if ($cat_id == 'root') { + $parent_qpart = 'parent_cat IS NULL'; + } else { + $parent_qpart = 'parent_cat = '.db_escape_string($cat_id); + } + + $query = "SELECT ttrss_feeds.id, ttrss_feeds.title, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, + cat_id,last_error, + COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category, + ttrss_feed_categories.collapsed, + value AS unread + FROM ttrss_feeds LEFT JOIN ttrss_feed_categories + ON (ttrss_feed_categories.id = cat_id) + LEFT JOIN ttrss_counters_cache + ON + (ttrss_feeds.id = feed_id) + WHERE + ttrss_feeds.owner_uid = '$owner_uid' AND $parent_qpart + ORDER BY $order_by_qpart"; + + $result = db_query($this->link, $query); + + $actid = $_REQUEST["actid"]; + + if (db_num_rows($result) > 0) { + + $category = ""; + + if (!$enable_cats) + $cat['items'] = array(); + else + $cat = false; + + while ($line = db_fetch_assoc($result)) { + + $feed = htmlspecialchars(trim($line["title"])); + + if (!$feed) $feed = "[Untitled]"; + + $feed_id = $line["id"]; + $unread = $line["unread"]; + + $cat_id = $line["cat_id"]; + $tmp_category = $line["category"]; + + if ($category != $tmp_category && $enable_cats) { + + $category = $tmp_category; + + $collapsed = sql_bool_to_bool($line["collapsed"]); + + // workaround for NULL category + if ($category == __("Uncategorized")) { + $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT"); + } + + if ($cat) array_push($feedlist['items'], $cat); + + $cat = $this->feedlist_init_cat($cat_id, $collapsed); + + if ($cat_id) { + $cat_items = $this->feedlist_process_category($cat_id, &$feedlist); + if (count($cat_items) > 0) { + array_push($cat['items'], $cat_items); + } + } + } + + $updated = make_local_datetime($this->link, $line["updated_noms"], false); + + array_push($cat['items'], $this->feedlist_init_feed($feed_id, + $feed, $unread, $line['last_error'], $updated)); + } + + if ($enable_cats) { + array_push($feedlist['items'], $cat); + } else { + $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); + } + + } + + } + function catchupAll() { db_query($this->link, "UPDATE ttrss_user_entries SET diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index 44adc2ce0..ea061b6b2 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -32,6 +32,55 @@ class Pref_Feeds extends Protected_Handler { return; } + private function get_category_items($cat_id) { + + $items = array(); + + $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories + WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title"); + + while ($line = db_fetch_assoc($result)) { + + $cat = array(); + $cat['id'] = 'CAT:' . $line['id']; + $cat['bare_id'] = $feed_id; + $cat['name'] = $line['title']; + $cat['items'] = array(); + $cat['checkbox'] = false; + $cat['type'] = 'category'; + + $cat['items'] = $this->get_category_items($line['id']); + + $cat['param'] = T_sprintf('(%d feeds)', count($cat['items'])); + + if (count($cat['items']) > 0 || $show_empty_cats) + array_push($items, $cat); + + } + + $feed_result = db_query($this->link, "SELECT id, title, last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds + WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]. + "$search_qpart ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + $feed['error'] = $feed_line['last_error']; + $feed['icon'] = getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime($this->link, + $feed_line['last_updated'], true); + + array_push($items, $feed); + } + + return $items; + } + function getfeedtree() { $search = $_SESSION["prefs_feed_search"]; @@ -48,7 +97,7 @@ class Pref_Feeds extends Protected_Handler { $show_empty_cats = get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'); $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories - WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title"); + WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title"); while ($line = db_fetch_assoc($result)) { $cat = array(); @@ -59,25 +108,7 @@ class Pref_Feeds extends Protected_Handler { $cat['checkbox'] = false; $cat['type'] = 'category'; - $feed_result = db_query($this->link, "SELECT id, title, last_error, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated - FROM ttrss_feeds - WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"]. - "$search_qpart ORDER BY order_id, title"); - - while ($feed_line = db_fetch_assoc($feed_result)) { - $feed = array(); - $feed['id'] = 'FEED:' . $feed_line['id']; - $feed['bare_id'] = $feed_line['id']; - $feed['name'] = $feed_line['title']; - $feed['checkbox'] = false; - $feed['error'] = $feed_line['last_error']; - $feed['icon'] = getFeedIcon($feed_line['id']); - $feed['param'] = make_local_datetime($this->link, - $feed_line['last_updated'], true); - - array_push($cat['items'], $feed); - } + $cat['items'] = $this->get_category_items($line['id']); $cat['param'] = T_sprintf('(%d feeds)', count($cat['items'])); @@ -176,17 +207,77 @@ class Pref_Feeds extends Protected_Handler { (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true')); } + private function process_category_order($data_map, $item_id, $parent_id = false) { +# print "C: $item_id P: $parent_id\n"; + $bare_id = substr($item_id, strpos($item_id, ':')+1); + + if ($item_id != 'root') { + if ($parent_id && $parent_id != 'root') { + $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); + $parent_qpart = db_escape_string($parent_bare_id); + } else { + $parent_qpart = 'NULL'; + } + + db_query($this->link, "UPDATE ttrss_feed_categories + SET parent_cat = $parent_qpart WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + } + + $order_id = 0; + + $cat = $data_map[$item_id]; + + if ($cat && is_array($cat)) { + foreach ($cat as $item) { + $id = $item['_reference']; + $bare_id = substr($id, strpos($id, ':')+1); + +# print "[$order_id] $id/$bare_id\n"; + + if ($item['_reference']) { + + if (strpos($id, "FEED") === 0) { + + db_query($this->link, "UPDATE ttrss_feeds + SET order_id = '$order_id' WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + + } else if (strpos($id, "CAT:") === 0) { + $this->process_category_order(&$data_map, $item['_reference'], $item_id); + + if ($item_id != 'root') { + $parent_qpart = db_escape_string($bare_id); + } else { + $parent_qpart = 'NULL'; + } + + db_query($this->link, "UPDATE ttrss_feed_categories + SET order_id = '$order_id' WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + } + } + + ++$order_id; + } + } + } + function savefeedorder() { $data = json_decode($_POST['payload'], true); + #file_put_contents("/tmp/saveorder.json", $_POST['payload']); + #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); + if (is_array($data) && is_array($data['items'])) { $cat_order_id = 0; $data_map = array(); + $root_item = false; foreach ($data['items'] as $item) { - if ($item['id'] != 'root') { +# if ($item['id'] != 'root') { if (is_array($item['items'])) { if (isset($item['items']['_reference'])) { $data_map[$item['id']] = array($item['items']); @@ -194,10 +285,14 @@ class Pref_Feeds extends Protected_Handler { $data_map[$item['id']] =& $item['items']; } } + if ($item['id'] == 'root') { + $root_item = $item['id']; } } - foreach ($data['items'][0]['items'] as $item) { + $this->process_category_order(&$data_map, $root_item); + + /* foreach ($data['items'][0]['items'] as $item) { $id = $item['_reference']; $bare_id = substr($id, strpos($id, ':')+1); @@ -230,7 +325,7 @@ class Pref_Feeds extends Protected_Handler { ++$feed_order_id; } } - } + } */ } return; diff --git a/include/functions.php b/include/functions.php index 4ba60e844..009955c99 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ Date: Mon, 13 Aug 2012 18:56:55 +0400 Subject: [PATCH 3/9] sorta-kinda fix the feedlist --- classes/feeds.php | 326 ----------------------------------------- classes/pref_feeds.php | 136 +++++++++++++++-- index.php | 6 +- js/tt-rss.js | 6 +- 4 files changed, 134 insertions(+), 340 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 0762b0067..d1ef16738 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -7,49 +7,6 @@ class Feeds extends Protected_Handler { return array_search($method, $csrf_ignored) !== false; } - private function feedlist_init_cat($cat_id, $hidden = false) { - $obj = array(); - $cat_id = (int) $cat_id; - - if ($cat_id > 0) { - $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true); - } else if ($cat_id == 0 || $cat_id == -2) { - $cat_unread = getCategoryUnread($this->link, $cat_id); - } - - $obj['id'] = 'CAT:' . $cat_id; - $obj['items'] = array(); - $obj['name'] = getCategoryTitle($this->link, $cat_id); - $obj['type'] = 'feed'; - $obj['unread'] = (int) $cat_unread; - $obj['hidden'] = $hidden; - $obj['bare_id'] = $cat_id; - - return $obj; - } - - private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { - $obj = array(); - $feed_id = (int) $feed_id; - - if (!$title) - $title = getFeedTitle($this->link, $feed_id, false); - - if ($unread === false) - $unread = getFeedUnread($this->link, $feed_id, false); - - $obj['id'] = 'FEED:' . $feed_id; - $obj['name'] = $title; - $obj['unread'] = (int) $unread; - $obj['type'] = 'feed'; - $obj['error'] = $error; - $obj['updated'] = $updated; - $obj['icon'] = getFeedIcon($feed_id); - $obj['bare_id'] = $feed_id; - - return $obj; - } - private function format_headline_subtoolbar($feed_site_url, $feed_title, $feed_id, $is_cat, $search, $match_on, $search_mode, $view_mode, $error) { @@ -776,289 +733,6 @@ class Feeds extends Protected_Handler { $vgroup_last_feed, $reply); } - private function outputFeedList($special = true) { - - $feedlist = array(); - - $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS'); - - $feedlist['identifier'] = 'id'; - $feedlist['label'] = 'name'; - $feedlist['items'] = array(); - - $owner_uid = $_SESSION["uid"]; - - /* virtual feeds */ - - if ($special) { - - if ($enable_cats) { - $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL"); - $cat = $this->feedlist_init_cat(-1, $cat_hidden); - } else { - $cat['items'] = array(); - } - - foreach (array(-4, -3, -1, -2, 0) as $i) { - array_push($cat['items'], $this->feedlist_init_feed($i)); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - - $result = db_query($this->link, "SELECT * FROM - ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption"); - - if (db_num_rows($result) > 0) { - - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS"); - $cat = $this->feedlist_init_cat(-2, $cat_hidden); - } else { - $cat['items'] = array(); - } - - while ($line = db_fetch_assoc($result)) { - - $label_id = -$line['id'] - 11; - $count = getFeedUnread($this->link, $label_id); - - $feed = $this->feedlist_init_feed($label_id, false, $count); - - $feed['fg_color'] = $line['fg_color']; - $feed['bg_color'] = $line['bg_color']; - - array_push($cat['items'], $feed); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - } - } - - $this->feedlist_process_category('root', &$feedlist); - -/* if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "order_id,category,unread DESC,title"; - } else { - $order_by_qpart = "order_id,category,title"; - } - } else { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "unread DESC,title"; - } else { - $order_by_qpart = "title"; - } - } */ - - /* real feeds */ - - /* if ($enable_cats) - $order_by_qpart = "ttrss_feed_categories.order_id,category, - ttrss_feeds.order_id,title"; - else - $order_by_qpart = "title"; - - $query = "SELECT ttrss_feeds.id, ttrss_feeds.title, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, - cat_id,last_error, - COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category, - ttrss_feed_categories.collapsed, - value AS unread - FROM ttrss_feeds LEFT JOIN ttrss_feed_categories - ON (ttrss_feed_categories.id = cat_id) - LEFT JOIN ttrss_counters_cache - ON - (ttrss_feeds.id = feed_id) - WHERE - ttrss_feeds.owner_uid = '$owner_uid' AND parent_cat IS NULL - ORDER BY $order_by_qpart"; - - $result = db_query($this->link, $query); - - $actid = $_REQUEST["actid"]; - - if (db_num_rows($result) > 0) { - - $category = ""; - - if (!$enable_cats) - $cat['items'] = array(); - else - $cat = false; - - while ($line = db_fetch_assoc($result)) { - - $feed = htmlspecialchars(trim($line["title"])); - - if (!$feed) $feed = "[Untitled]"; - - $feed_id = $line["id"]; - $unread = $line["unread"]; - - $cat_id = $line["cat_id"]; - $tmp_category = $line["category"]; - - if ($category != $tmp_category && $enable_cats) { - - $category = $tmp_category; - - $collapsed = sql_bool_to_bool($line["collapsed"]); - - // workaround for NULL category - if ($category == __("Uncategorized")) { - $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT"); - } - - if ($cat) array_push($feedlist['items'], $cat); - - $cat = $this->feedlist_init_cat($cat_id, $collapsed); - } - - $updated = make_local_datetime($this->link, $line["updated_noms"], false); - - array_push($cat['items'], $this->feedlist_init_feed($feed_id, - $feed, $unread, $line['last_error'], $updated)); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - - } */ - - return $feedlist; - } - - private function feedlist_process_category($cat_id, &$feedlist) { - $owner_uid = $_SESSION['uid']; - $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS'); - - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "order_id,category,unread DESC,title"; - } else { - $order_by_qpart = "order_id,category,title"; - } - } else { - if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) { - $order_by_qpart = "unread DESC,title"; - } else { - $order_by_qpart = "title"; - } - } - - if ($enable_cats) - $order_by_qpart = "ttrss_feed_categories.order_id,category, - ttrss_feeds.order_id,title"; - else - $order_by_qpart = "title"; - - /* real feeds */ - - if ($enable_cats) - $order_by_qpart = "ttrss_feed_categories.order_id,category, - ttrss_feeds.order_id,title"; - else - $order_by_qpart = "title"; - - if (!$enable_cats) { - $parent_qpart = "true"; - } else if ($cat_id == 'root') { - $parent_qpart = 'parent_cat IS NULL'; - } else { - $parent_qpart = 'parent_cat = '.db_escape_string($cat_id); - } - - $query = "SELECT ttrss_feeds.id, ttrss_feeds.title, - ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, - cat_id,last_error, - COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category, - ttrss_feed_categories.collapsed, - value AS unread - FROM ttrss_feeds LEFT JOIN ttrss_feed_categories - ON (ttrss_feed_categories.id = cat_id) - LEFT JOIN ttrss_counters_cache - ON - (ttrss_feeds.id = feed_id) - WHERE - ttrss_feeds.owner_uid = '$owner_uid' AND $parent_qpart - ORDER BY $order_by_qpart"; - - $result = db_query($this->link, $query); - - $actid = $_REQUEST["actid"]; - - if (db_num_rows($result) > 0) { - - $category = ""; - - if (!$enable_cats) - $cat['items'] = array(); - else - $cat = false; - - while ($line = db_fetch_assoc($result)) { - - $feed = htmlspecialchars(trim($line["title"])); - - if (!$feed) $feed = "[Untitled]"; - - $feed_id = $line["id"]; - $unread = $line["unread"]; - - $cat_id = $line["cat_id"]; - $tmp_category = $line["category"]; - - if ($category != $tmp_category && $enable_cats) { - - $category = $tmp_category; - - $collapsed = sql_bool_to_bool($line["collapsed"]); - - // workaround for NULL category - if ($category == __("Uncategorized")) { - $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT"); - } - - if ($cat) array_push($feedlist['items'], $cat); - - $cat = $this->feedlist_init_cat($cat_id, $collapsed); - - if ($cat_id) { - $cat_items = $this->feedlist_process_category($cat_id, &$feedlist); - if (count($cat_items) > 0) { - array_push($cat['items'], $cat_items); - } - } - } - - $updated = make_local_datetime($this->link, $line["updated_noms"], false); - - array_push($cat['items'], $this->feedlist_init_feed($feed_id, - $feed, $unread, $line['last_error'], $updated)); - } - - if ($enable_cats) { - array_push($feedlist['items'], $cat); - } else { - $feedlist['items'] = array_merge($feedlist['items'], $cat['items']); - } - - } - - } - - function catchupAll() { db_query($this->link, "UPDATE ttrss_user_entries SET last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index ea061b6b2..a6760b9e1 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -36,18 +36,20 @@ class Pref_Feeds extends Protected_Handler { $items = array(); - $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories + $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title"); while ($line = db_fetch_assoc($result)) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; - $cat['bare_id'] = $feed_id; + $cat['bare_id'] = (int)$line['id']; $cat['name'] = $line['title']; $cat['items'] = array(); $cat['checkbox'] = false; + $cat['hidden'] = sql_bool_to_bool($line['collapsed']); $cat['type'] = 'category'; + $cat['unread'] = 0; $cat['items'] = $this->get_category_items($line['id']); @@ -67,9 +69,10 @@ class Pref_Feeds extends Protected_Handler { while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; - $feed['bare_id'] = $feed_line['id']; + $feed['bare_id'] = (int)$feed_line['id']; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; + $feed['unread'] = 0; $feed['error'] = $feed_line['last_error']; $feed['icon'] = getFeedIcon($feed_line['id']); $feed['param'] = make_local_datetime($this->link, @@ -93,20 +96,77 @@ class Pref_Feeds extends Protected_Handler { $root['items'] = array(); $root['type'] = 'category'; - if (get_pref($this->link, 'ENABLE_FEED_CATS')) { - $show_empty_cats = get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'); + $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS'); - $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories + if ($_REQUEST['mode'] == 2) { + + if ($enable_cats) { + $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL"); + $cat = $this->feedlist_init_cat(-1, $cat_hidden); + } else { + $cat['items'] = array(); + } + + foreach (array(-4, -3, -1, -2, 0) as $i) { + array_push($cat['items'], $this->feedlist_init_feed($i)); + } + + if ($enable_cats) { + array_push($root['items'], $cat); + } else { + $root['items'] = array_merge($root['items'], $cat['items']); + } + + $result = db_query($this->link, "SELECT * FROM + ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption"); + + if (db_num_rows($result) > 0) { + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS"); + $cat = $this->feedlist_init_cat(-2, $cat_hidden); + } else { + $cat['items'] = array(); + } + + while ($line = db_fetch_assoc($result)) { + + $label_id = -$line['id'] - 11; + $count = getFeedUnread($this->link, $label_id); + + $feed = $this->feedlist_init_feed($label_id, false, $count); + + $feed['fg_color'] = $line['fg_color']; + $feed['bg_color'] = $line['bg_color']; + + array_push($cat['items'], $feed); + } + + if ($enable_cats) { + array_push($root['items'], $cat); + } else { + $root['items'] = array_merge($root['items'], $cat['items']); + } + } + } + + if ($enable_cats) { + $show_empty_cats = $_REQUEST['mode'] != 2 && + get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'); + + $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title"); while ($line = db_fetch_assoc($result)) { $cat = array(); $cat['id'] = 'CAT:' . $line['id']; - $cat['bare_id'] = $feed_id; + $cat['bare_id'] = (int)$line['id']; $cat['name'] = $line['title']; $cat['items'] = array(); $cat['checkbox'] = false; + $cat['hidden'] = sql_bool_to_bool($line['collapsed']); $cat['type'] = 'category'; + $cat['unread'] = 0; $cat['items'] = $this->get_category_items($line['id']); @@ -125,8 +185,10 @@ class Pref_Feeds extends Protected_Handler { $cat['bare_id'] = 0; $cat['name'] = __("Uncategorized"); $cat['items'] = array(); + $cat['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT"); $cat['type'] = 'category'; $cat['checkbox'] = false; + $cat['unread'] = 0; $feed_result = db_query($this->link, "SELECT id, title,last_error, ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated @@ -137,13 +199,15 @@ class Pref_Feeds extends Protected_Handler { while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; - $feed['bare_id'] = $feed_line['id']; + $feed['bare_id'] = (int)$feed_line['id']; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; $feed['error'] = $feed_line['last_error']; $feed['icon'] = getFeedIcon($feed_line['id']); $feed['param'] = make_local_datetime($this->link, $feed_line['last_updated'], true); + $feed['unread'] = 0; + $feed['type'] = 'feed'; array_push($cat['items'], $feed); } @@ -166,25 +230,31 @@ class Pref_Feeds extends Protected_Handler { while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); $feed['id'] = 'FEED:' . $feed_line['id']; - $feed['bare_id'] = $feed_line['id']; + $feed['bare_id'] = (int)$feed_line['id']; $feed['name'] = $feed_line['title']; $feed['checkbox'] = false; $feed['error'] = $feed_line['last_error']; $feed['icon'] = getFeedIcon($feed_line['id']); $feed['param'] = make_local_datetime($this->link, $feed_line['last_updated'], true); + $feed['unread'] = 0; + $feed['type'] = 'feed'; array_push($root['items'], $feed); } $root['param'] = T_sprintf('(%d feeds)', count($root['items'])); - } $fl = array(); $fl['identifier'] = 'id'; $fl['label'] = 'name'; - $fl['items'] = array($root); + + if ($_REQUEST['mode'] != 2) { + $fl['items'] = array($root); + } else { + $fl['items'] =& $root['items']; + } print json_encode($fl); return; @@ -1686,5 +1756,49 @@ class Pref_Feeds extends Protected_Handler { print ""; #container } + + private function feedlist_init_cat($cat_id, $hidden = false) { + $obj = array(); + $cat_id = (int) $cat_id; + + if ($cat_id > 0) { + $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true); + } else if ($cat_id == 0 || $cat_id == -2) { + $cat_unread = getCategoryUnread($this->link, $cat_id); + } + + $obj['id'] = 'CAT:' . $cat_id; + $obj['items'] = array(); + $obj['name'] = getCategoryTitle($this->link, $cat_id); + $obj['type'] = 'category'; + $obj['unread'] = (int) $cat_unread; + $obj['hidden'] = $hidden; + $obj['bare_id'] = $cat_id; + + return $obj; + } + + private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { + $obj = array(); + $feed_id = (int) $feed_id; + + if (!$title) + $title = getFeedTitle($this->link, $feed_id, false); + + if ($unread === false) + $unread = getFeedUnread($this->link, $feed_id, false); + + $obj['id'] = 'FEED:' . $feed_id; + $obj['name'] = $title; + $obj['unread'] = (int) $unread; + $obj['type'] = 'feed'; + $obj['error'] = $error; + $obj['updated'] = $updated; + $obj['icon'] = getFeedIcon($feed_id); + $obj['bare_id'] = $feed_id; + + return $obj; + } + } ?> diff --git a/index.php b/index.php index 53901ec6e..c17a10416 100644 --- a/index.php +++ b/index.php @@ -79,7 +79,11 @@ } foreach (array("tt-rss", "functions", "feedlist", "viewfeed", "FeedTree") as $js) { - echo JSMin::minify(file_get_contents("js/$js.js")); + if (!isset($_GET['debug'])) { + echo JSMin::minify(file_get_contents("js/$js.js")); + } else { + echo file_get_contents("js/$js.js"); + } } ?> diff --git a/js/tt-rss.js b/js/tt-rss.js index ef5d72e5b..a4c67bfcc 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -61,12 +61,12 @@ function updateFeedList() { } var store = new dojo.data.ItemFileWriteStore({ - url: "backend.php?op=feeds"}); + url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"}); var treeModel = new fox.FeedStoreModel({ store: store, query: { - "type": "feed" + "type": init_params['enable_feed_cats'] == 1 ? "category" : "feed" }, rootId: "root", rootLabel: "Feeds", @@ -105,6 +105,8 @@ function updateFeedList() { id: "feedTree", }, "feedTree"); + _force_scheduled_update = true; + /* var menu = new dijit.Menu({id: 'feedMenu'}); menu.addChild(new dijit.MenuItem({ From be514d00c9df66392e85529d2df78d4de1601a98 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 18:58:21 +0400 Subject: [PATCH 4/9] remove feeds/index() --- classes/feeds.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index d1ef16738..4f0ac4f3f 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -745,29 +745,6 @@ class Feeds extends Protected_Handler { toggle_collapse_cat($this->link, $cat_id, $mode); } - function index() { - $root = (bool)$_REQUEST["root"]; - - if (!$root) { - print json_encode($this->outputFeedList($this->link)); - } else { - - $feeds = $this->outputFeedList($this->link, false); - - $root = array(); - $root['id'] = 'root'; - $root['name'] = __('Feeds'); - $root['items'] = $feeds['items']; - - $fl = array(); - $fl['identifier'] = 'id'; - $fl['label'] = 'name'; - $fl['items'] = array($root); - - print json_encode($fl); - } - } - function view() { $timing_info = getmicrotime(); From 2c5f231e439dac3fc68422fbb1c8ec57e9d8b35d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 19:52:34 +0400 Subject: [PATCH 5/9] add special indication for categories having unread items in child categories --- classes/pref_feeds.php | 3 +++ include/functions.php | 28 +++++++++++++++++++++++++++- js/FeedTree.js | 27 +++++++++++++++++++++++++-- js/feedlist.js | 16 ++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index a6760b9e1..c87b0e549 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -50,6 +50,7 @@ class Pref_Feeds extends Protected_Handler { $cat['hidden'] = sql_bool_to_bool($line['collapsed']); $cat['type'] = 'category'; $cat['unread'] = 0; + $cat['child_unread'] = 0; $cat['items'] = $this->get_category_items($line['id']); @@ -167,6 +168,7 @@ class Pref_Feeds extends Protected_Handler { $cat['hidden'] = sql_bool_to_bool($line['collapsed']); $cat['type'] = 'category'; $cat['unread'] = 0; + $cat['child_unread'] = 0; $cat['items'] = $this->get_category_items($line['id']); @@ -189,6 +191,7 @@ class Pref_Feeds extends Protected_Handler { $cat['type'] = 'category'; $cat['checkbox'] = false; $cat['unread'] = 0; + $cat['child_unread'] = 0; $feed_result = db_query($this->link, "SELECT id, title,last_error, ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated diff --git a/include/functions.php b/include/functions.php index 009955c99..b2319e6e1 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1501,7 +1501,9 @@ array_push($ret_arr, $cv); - $result = db_query($link, "SELECT id AS cat_id, value AS unread + $result = db_query($link, "SELECT id AS cat_id, value AS unread, + (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 + WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children FROM ttrss_feed_categories, ttrss_cat_counters_cache WHERE ttrss_cat_counters_cache.feed_id = id AND ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]); @@ -1509,7 +1511,14 @@ while ($line = db_fetch_assoc($result)) { $line["cat_id"] = (int) $line["cat_id"]; + if ($line["num_children"] > 0) { + $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]); + } else { + $child_counter = 0; + } + $cv = array("id" => $line["cat_id"], "kind" => "cat", + "child_counter" => $child_counter, "counter" => $line["unread"]); array_push($ret_arr, $cv); @@ -1525,6 +1534,23 @@ return $ret_arr; } + // only accepts real cats (>= 0) + function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) { + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + + $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat' + AND owner_uid = $owner_uid"); + + $unread = 0; + + while ($line = db_fetch_assoc($result)) { + $unread += getCategoryUnread($link, $line["id"], $owner_uid); + $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid); + } + + return $unread; + } + function getCategoryUnread($link, $cat, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; diff --git a/js/FeedTree.js b/js/FeedTree.js index 30e625015..b39e72862 100644 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -120,6 +120,14 @@ dojo.declare("fox.FeedTree", dijit.Tree, { dojo.place(span, tnode.iconNode, 'replace'); } + if (id.match("CAT:") && bare_id > 0) { + param = dojo.doc.createElement('span'); + param.className = 'feedParam'; + param.innerHTML = ""; + dojo.place(param, tnode.labelNode, 'after'); + tnode._paramNode = param; + } + if (id.match("FEED:") && bare_id > 0) { var menu = new dijit.Menu(); menu.row_id = bare_id; @@ -183,11 +191,15 @@ dojo.declare("fox.FeedTree", dijit.Tree, { name = name.replace(/</g, "<"); name = name.replace(/>/g, ">"); + var label; + if (item.unread > 0) { - return name + " (" + item.unread + ")"; + label = name + " (" + item.unread + ")"; } else { - return name; + label = name; } + + return label; }, selectFeed: function(feed, is_cat) { if (is_cat) @@ -443,4 +455,15 @@ dojo.declare("fox.FeedTree", dijit.Tree, { return false; } }, + setCatParam: function(cat, value) { + var treeNode = this._itemNodesMap['CAT:' + cat]; + + if (treeNode && treeNode[0] && treeNode[0]._paramNode) { + if (value > 0) + treeNode[0]._paramNode.innerHTML = '+' + value; + else + treeNode[0]._paramNode.innerHTML = ""; + } + this.model.setFeedValue(cat, true, 'child_unread', value); + }, }); diff --git a/js/feedlist.js b/js/feedlist.js index 13cdc2694..18d4a9770 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -286,6 +286,7 @@ function parse_counters(elems, scheduled_call) { var error = elems[l].error; var has_img = elems[l].has_img; var updated = elems[l].updated; + var child_unread = parseInt(elems[l].child_counter); if (id == "global-unread") { global_unread = ctr; @@ -322,6 +323,8 @@ function parse_counters(elems, scheduled_call) { setFeedIcon(id, false, 'images/blank_icon.gif'); } } + } else { + setCatParam(id, child_unread); } } @@ -411,6 +414,19 @@ function setFeedValue(feed, is_cat, key, value) { } } +function setCatParam(cat, value) { + try { + var tree = dijit.byId("feedTree"); + + if (tree && tree.model) + return tree.setCatParam(cat, value); + + } catch (e) { + // + } +} + + function selectFeed(feed, is_cat) { try { var tree = dijit.byId("feedTree"); From 6d8d00e8c0293dbc7c643df21fe56e7d2a601157 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 20:53:45 +0400 Subject: [PATCH 6/9] allow queryFeedHeadlines() to show child category entries --- include/functions.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/functions.php b/include/functions.php index b2319e6e1..0e2424c58 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2273,6 +2273,19 @@ return $search_query_part; } + function getChildCategories($link, $cat, $owner_uid) { + $rv = array(); + + $result = db_query($link, "SELECT id FROM ttrss_feed_categories + WHERE parent_cat = '$cat' AND owner_uid = $owner_uid"); + + while ($line = db_fetch_assoc($result)) { + array_push($rv, $line["id"]); + $rv = array_merge($rv, getChildCategories($link, $line["id"], $owner_uid)); + } + + return $rv; + } function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0) { @@ -2318,6 +2331,10 @@ $view_query_part = " "; } else if ($feed != -1) { $unread = getFeedUnread($link, $feed, $cat_view); + + if ($cat_view && $feed > 0) + $unread = getCategoryUnreadRecursive($link, $feed); + if ($unread > 0) { $view_query_part = " unread = true AND "; } @@ -2389,7 +2406,17 @@ if ($cat_view) { if ($feed > 0) { - $query_strategy_part = "cat_id = '$feed'"; + # sub-cats + $subcats = getChildCategories($link, $feed, $owner_uid); + + if (count($subcats) == 0) { + $query_strategy_part = "cat_id = '$feed'"; + } else { + array_push($subcats, $feed); + $query_strategy_part = "cat_id IN (". + implode(",", $subcats).")"; + } + } else { $query_strategy_part = "cat_id IS NULL"; } From 99c9e91a51a99ab5d8b9ded85ab61ad82cb2a9e7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 21:02:52 +0400 Subject: [PATCH 7/9] fix queryFeedHeadlines, rename getCategoryUnreadRecursive --- include/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/functions.php b/include/functions.php index 0e2424c58..1116e422c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1512,7 +1512,7 @@ $line["cat_id"] = (int) $line["cat_id"]; if ($line["num_children"] > 0) { - $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]); + $child_counter = getCategoryChildrenUnread($link, $line["cat_id"], $_SESSION["uid"]); } else { $child_counter = 0; } @@ -1535,7 +1535,7 @@ } // only accepts real cats (>= 0) - function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) { + function getCategoryChildrenUnread($link, $cat, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat' @@ -1545,7 +1545,7 @@ while ($line = db_fetch_assoc($result)) { $unread += getCategoryUnread($link, $line["id"], $owner_uid); - $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid); + $unread += getCategoryChildrenUnread($link, $line["id"], $owner_uid); } return $unread; @@ -2333,7 +2333,7 @@ $unread = getFeedUnread($link, $feed, $cat_view); if ($cat_view && $feed > 0) - $unread = getCategoryUnreadRecursive($link, $feed); + $unread += getCategoryChildrenUnread($link, $feed); if ($unread > 0) { $view_query_part = " unread = true AND "; From 09101297ee0596a6c66d9c7388795e8602c24113 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 21:25:46 +0400 Subject: [PATCH 8/9] add toolbar checkbox to include subcategories to viewfeed() --- classes/feeds.php | 10 ++++++---- include/functions.php | 22 +++++++++++++--------- index.php | 8 ++++++++ js/tt-rss.js | 8 ++++++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 4f0ac4f3f..502efd401 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -119,7 +119,7 @@ class Feeds extends Protected_Handler { private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, - $override_order = false) { + $override_order = false, $include_children = false) { $disable_cache = false; @@ -196,7 +196,8 @@ class Feeds extends Protected_Handler { } // error_log("search_mode: " . $search_mode); $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view, - $search, $search_mode, $match_on, $override_order, $offset); + $search, $search_mode, $match_on, $override_order, $offset, 0, + false, 0, $include_children); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); @@ -758,11 +759,12 @@ class Feeds extends Protected_Handler { $method = db_escape_string($_REQUEST["m"]); $view_mode = db_escape_string($_REQUEST["view_mode"]); $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT"); - @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; + @$cat_view = $_REQUEST["cat"] == "true"; @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); @$offset = db_escape_string($_REQUEST["skip"]); @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); $order_by = db_escape_string($_REQUEST["order_by"]); + $include_children = $_REQUEST["include_children"] == "on"; if (is_numeric($feed)) $feed = (int) $feed; @@ -856,7 +858,7 @@ class Feeds extends Protected_Handler { $ret = $this->format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, - $vgroup_last_feed, $override_order); + $vgroup_last_feed, $override_order, $include_children); $topmost_article_ids = $ret[0]; $headlines_count = $ret[1]; diff --git a/include/functions.php b/include/functions.php index 1116e422c..3cb503fd8 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2287,7 +2287,7 @@ return $rv; } - function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0) { + function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -2332,7 +2332,7 @@ } else if ($feed != -1) { $unread = getFeedUnread($link, $feed, $cat_view); - if ($cat_view && $feed > 0) + if ($cat_view && $feed > 0 && $include_children) $unread += getCategoryChildrenUnread($link, $feed); if ($unread > 0) { @@ -2406,15 +2406,19 @@ if ($cat_view) { if ($feed > 0) { - # sub-cats - $subcats = getChildCategories($link, $feed, $owner_uid); + if ($include_children) { + # sub-cats + $subcats = getChildCategories($link, $feed, $owner_uid); - if (count($subcats) == 0) { - $query_strategy_part = "cat_id = '$feed'"; + if (count($subcats) == 0) { + $query_strategy_part = "cat_id = '$feed'"; + } else { + array_push($subcats, $feed); + $query_strategy_part = "cat_id IN (". + implode(",", $subcats).")"; + } } else { - array_push($subcats, $feed); - $query_strategy_part = "cat_id IN (". - implode(",", $subcats).")"; + $query_strategy_part = "cat_id = '$feed'"; } } else { diff --git a/index.php b/index.php index c17a10416..96d13558d 100644 --- a/index.php +++ b/index.php @@ -183,6 +183,14 @@ +   + + + + diff --git a/js/tt-rss.js b/js/tt-rss.js index a4c67bfcc..11d5ef9c1 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -42,6 +42,14 @@ function setActiveFeedId(id, is_cat) { selectFeed(id, is_cat); + if (is_cat && id > 0) { + document.forms["main_toolbar_form"].include_children.disabled = false; + $("include_children_label").removeClassName("insensitive"); + } else { + document.forms["main_toolbar_form"].include_children.disabled = true; + $("include_children_label").addClassName("insensitive"); + } + } catch (e) { exception_error("setActiveFeedId", e); } From 854a2ace869b29f805d203bb74968ef1500eb54b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 13 Aug 2012 21:39:40 +0400 Subject: [PATCH 9/9] change include_children to a togglebutton; add placeholder setting save in a session --- classes/feeds.php | 4 +++- include/functions.php | 1 + index.php | 9 +++++++-- js/feedlist.js | 1 + js/tt-rss.js | 18 ++++++++++-------- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 502efd401..be7886472 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -764,7 +764,7 @@ class Feeds extends Protected_Handler { @$offset = db_escape_string($_REQUEST["skip"]); @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); $order_by = db_escape_string($_REQUEST["order_by"]); - $include_children = $_REQUEST["include_children"] == "on"; + $include_children = $_REQUEST["include_children"] == "true"; if (is_numeric($feed)) $feed = (int) $feed; @@ -806,6 +806,8 @@ class Feeds extends Protected_Handler { set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit); set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by); + $_SESSION["_DEFAULT_INCLUDE_CHILDREN"] = $include_children; + if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW() WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); diff --git a/include/functions.php b/include/functions.php index 3cb503fd8..cb24cb877 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2137,6 +2137,7 @@ $params["icons_url"] = ICONS_URL; $params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME; + $params["default_include_children"] = $_SESSION["_DEFAULT_INCLUDE_CHILDREN"]; $params["default_view_mode"] = get_pref($link, "_DEFAULT_VIEW_MODE"); $params["default_view_limit"] = (int) get_pref($link, "_DEFAULT_VIEW_LIMIT"); $params["default_view_order_by"] = get_pref($link, "_DEFAULT_VIEW_ORDER_BY"); diff --git a/index.php b/index.php index 96d13558d..3a68c90f6 100644 --- a/index.php +++ b/index.php @@ -185,11 +185,16 @@   - + --> + +