The number of comments shown when collapsed is the total of all the descendant items.
This commit is contained in:
parent
f3b1391501
commit
4cc6bf660c
1 changed files with 19 additions and 1 deletions
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue