diff --git a/class/comment.php b/class/comment.php index 2d1e3a7..536d393 100644 --- a/class/comment.php +++ b/class/comment.php @@ -289,6 +289,7 @@ function commentListShow($tpl_dir) $assign['comment_allowed_extensions'] = $settings['comment_allowed_extensions'] ?? 'jpg,jpeg,png,gif'; $assign['comment_max_file_size'] = $settings['comment_max_file_size'] ?? 2048; $assign['comment_max_files'] = (int)($settings['comment_max_files'] ?? 5); + $assign['ajax_replies_limit'] = (int)($settings['comment_ajax_replies_limit'] ?? 0); $comments = array(); @@ -447,6 +448,26 @@ if ($row['comment_changed'] > 0) { $page_nav = ''; } +// --- НАЧАЛО ВСТАВКИ ДЛЯ AJAX --- +$assign['more_counts'] = []; +// Проверяем, не запросил ли пользователь раскрыть конкретную ветку +$requested_branch = (int)($_REQUEST['ajax_load_branch'] ?? 0); + +if ($assign['ajax_replies_limit'] > 0 && !empty($comments)) { + foreach ($comments as $parentId => $subList) { + if ($parentId > 0 && count($subList) > $assign['ajax_replies_limit']) { + + // Если это ТА САМАЯ ветка, которую мы подгружаем по AJAX — НЕ обрезаем её + if ($requested_branch == $parentId) { + continue; + } + + $assign['more_counts'][$parentId] = count($subList) - $assign['ajax_replies_limit']; + $comments[$parentId] = array_slice($subList, 0, $assign['ajax_replies_limit']); + } + } +} + $assign['closed'] = @$comments[0][0]['comments_close']; $assign['comments'] = $comments; $assign['theme'] = defined('THEME_FOLDER') ? THEME_FOLDER : DEFAULT_THEME_FOLDER; diff --git a/templates/comments_tree.tpl b/templates/comments_tree.tpl index 8cc256d..ff246b3 100644 --- a/templates/comments_tree.tpl +++ b/templates/comments_tree.tpl @@ -36,11 +36,12 @@ {/if} - {if isset($comments[0])} -
- {include file="$subtpl" subcomments=$comments[0]} -
- {/if} +{if isset($comments[0])} +
+ {* Добавляем parentId=0, чтобы кнопка знала, к какой группе относятся ответы *} + {include file="$subtpl" subcomments=$comments[0] parentId=0} +
+{/if} @@ -286,5 +287,46 @@ + {literal} + + {/literal} + {/if} {/if} \ No newline at end of file diff --git a/templates/comments_tree_sub.tpl b/templates/comments_tree_sub.tpl index a7c3371..a0d1c24 100644 --- a/templates/comments_tree_sub.tpl +++ b/templates/comments_tree_sub.tpl @@ -1,4 +1,4 @@ -{foreach from=$subcomments item=c} +{foreach from=$subcomments item=c name=sub_loop}
- {if isset($comments) && isset($comments[$c.Id])} -
- {include file="$subtpl" subcomments=$comments[$c.Id] sub=1} -
- {/if} +{if isset($comments) && isset($comments[$c.Id])} +
+ {* ВАЖНО: передаем parentId=$c.Id для следующего уровня вложенности *} + {include file="$subtpl" subcomments=$comments[$c.Id] sub=1 parentId=$c.Id} +
+{/if}
+ + {* --- ВОТ СЮДА ВСТАВЛЯЕМ КНОПКУ --- *} + {if $smarty.foreach.sub_loop.last && isset($more_counts[$parentId])} +
+ +
+ {/if} + {/foreach} \ No newline at end of file