From cdf1251f24493fcafa7ed48375102eb2ff3d9278 Mon Sep 17 00:00:00 2001 From: Repellent Date: Thu, 1 Jan 2026 18:33:12 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=20-=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B5=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20AJAX=20=D0=BF=D0=BE=D0=B4=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BE=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=81=D1=8C=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D1=87=D0=B8=D1=81=D0=BB=D0=B0=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/comment.php | 21 +++++++++++++ templates/comments_tree.tpl | 52 +++++++++++++++++++++++++++++---- templates/comments_tree_sub.tpl | 23 +++++++++++---- 3 files changed, 85 insertions(+), 11 deletions(-) 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