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])} -