From 4cc6bf660c04c4b361eee8db59e5beb83e6b1081 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Tue, 7 Aug 2012 09:53:53 +0200 Subject: [PATCH] The number of comments shown when collapsed is the total of all the descendant items. --- include/conversation.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 706bcdde67..73c3337d52 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -299,6 +299,21 @@ function localize_item(&$item){ } +/** + * Count the total of comments on this item and its desendants + */ +function count_descendants($item) { + $total = count($item['children']); + + if($total > 0) { + foreach($item['children'] as $child) { + $total += count_descendants($child); + } + } + + return $total; +} + /** * Recursively prepare a thread for HTML */ @@ -311,6 +326,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr $items_seen = 0; $nb_items = count($items); + $total_children = $nb_items; + foreach($items as $item) { // prevent private email reply to public conversation from leaking. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { @@ -338,6 +355,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr $osparkle = ''; $lastcollapsed = false; $firstcollapsed = false; + $total_children += count_descendants($item); $toplevelpost = (($item['id'] == $item['parent']) ? true : false); $item_writeable = (($item['writable'] || $item['self']) ? true : false); @@ -577,7 +595,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr $item_result = $arr['output']; if($firstcollapsed) { - $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$nb_items),$nb_items ); + $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); $item_result['hide_text'] = t('show more'); }