* Recursively prepare a thread for HTML
*/
-function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner) {
+function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $collapse_all=false) {
$result = array();
$wall_template = 'wall_thread.tpl';
$wallwall_template = 'wallwall_thread.tpl';
$items_seen = 0;
$nb_items = count($items);
- $lastcollapsed = false;
- $firstcollapsed = false;
foreach($items as $item) {
// prevent private email reply to public conversation from leaking.
$thumb = $item['thumb'];
$indent = '';
$osparkle = '';
+ $lastcollapsed = false;
+ $firstcollapsed = false;
$toplevelpost = (($item['id'] == $item['parent']) ? true : false);
$item_writeable = (($item['writable'] || $item['self']) ? true : false);
} else {
$indent = 'comment';
// Collapse comments
- if($nb_items > 2) {
- if(!$firstcollapsed && ($items_seen <= ($nb_items - 2))) {
+ if(($nb_items > 2) || $collapse_all) {
+ if($items_seen == 1) {
$firstcollapsed = true;
}
- else if($items_seen == ($nb_items - 1)) {
+ if($collapse_all) {
+ if($items_seen == $nb_items)
+ $lastcollapsed = true;
+ }
+ else if($items_seen == ($nb_items - 2)) {
$lastcollapsed = true;
}
}
$tmp_item = array(
// collapse comments in template. I don't like this much...
- 'comment_firstcollapsed' => $comment_firstcollapsed,
- 'comment_lastcollapsed' => $comment_lastcollapsed,
+ 'comment_firstcollapsed' => $firstcollapsed,
+ 'comment_lastcollapsed' => $lastcollapsed,
// template to use to render item (wall, walltowall, search)
'template' => $template,
call_hooks('display_item', $arr);
$item_result = $arr['output'];
+ if($firstcollapsed) {
+ $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$nb_items),$nb_items );
+ $item_result['hide_text'] = t('show more');
+ }
$item_result['children'] = array();
if(count($item['children'])) {
- $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner);
+ if(!$toplevelpost && !$collapse_all)
+ $collapse_all = true;
+ $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, $collapse_all);
}
$item_result['private'] = $item['private'];
$result[] = $item_result;
}
$threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $previewing);
- } else {
+ }
+ else {
// Figure out how many comments each parent has
+{{if $item.comment_firstcollapsed}}
+ <div class="hide-comments-outer">
+ <span id="hide-comments-total-$item.id" class="hide-comments-total">$item.num_comments</span> <span id="hide-comments-$item.id" class="hide-comments fakelink" onclick="showHideComments($item.id);">$item.hide_text</span>
+ </div>
+ <div id="collapsed-comments-$item.id" class="collapsed-comments" style="display: none;">
+{{endif}}
<div id="tread-wrapper-$item.id" class="tread-wrapper">
- {{if $item.comment_firstcollapsed}}
- <div class="hide-comments-outer">
- <span id="hide-comments-total-$item.id" class="hide-comments-total">$item.num_comments</span> <span id="hide-comments-$item.id" class="hide-comments fakelink" onclick="showHideComments($item.id);">$item.hide_text</span>
- </div>
- <div id="collapsed-comments-$item.id" class="collapsed-comments" style="display: none;">
- {{endif}}
- {{if $item.comment_lastcollapsed}}</div>{{endif}}
-
<a name="$item.id" ></a>
<div class="wall-item-outside-wrapper $item.indent$item.previewing" id="wall-item-outside-wrapper-$item.id" >
<div class="wall-item-content-wrapper $item.indent" id="wall-item-content-wrapper-$item.id" >
{{ if $item.drop.dropping }}<input type="checkbox" onclick="checkboxhighlight(this);" title="$item.drop.select" class="item-select" name="itemselected[]" value="$item.id" />{{ endif }}
<div class="wall-item-delete-end"></div>
</div>
- <div class="wall-item-comment-wrapper" >
- $item.comment
- </div>
</div>
<div class="wall-item-wrapper-end"></div>
<div class="wall-item-like $item.indent" id="wall-item-like-$item.id">$item.like</div>
{{ for $item.children as $item }}
{{ inc $item.template }}{{ endinc }}
{{ endfor }}
+<div class="wall-item-comment-wrapper" >
+ $item.comment
+</div>
+
</div>
+{{if $item.comment_lastcollapsed}}</div>{{endif}}