}
+/**
+ * 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
*/
$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']) {
$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);
$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');
}