]> git.mxchange.org Git - friendica.git/commitdiff
The number of comments shown when collapsed is the total of all the descendant items.
authorDomovoy <domovoy@errlock.org>
Tue, 7 Aug 2012 07:53:53 +0000 (09:53 +0200)
committerDomovoy <domovoy@errlock.org>
Tue, 7 Aug 2012 07:53:53 +0000 (09:53 +0200)
include/conversation.php

index 706bcdde6739bc87208456f1c52dc61e1205a652..73c3337d520046f83a344a9a36a38df7eb699d8c 100644 (file)
@@ -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');
                }