From 6493a7d5c1240d0964993b64749331b81f3fd775 Mon Sep 17 00:00:00 2001 From: Repellent Date: Thu, 15 Jan 2026 20:47:25 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D0=B0=D0=B4=D0=BC?= =?UTF-8?q?=D0=B8=D0=BD=D0=BA=D0=B5=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/comment.php | 130 +++++++++++++++------ templates/admin_comments.tpl | 216 ++++++++++++++++------------------- 2 files changed, 190 insertions(+), 156 deletions(-) diff --git a/class/comment.php b/class/comment.php index 70034bf..5645791 100644 --- a/class/comment.php +++ b/class/comment.php @@ -1341,37 +1341,62 @@ function commentAdminListShow($tpl_dir) $action = $_REQUEST['admin_action'] ?? ''; $items = []; - // Собираем ID из разных источников для универсальности if (!empty($_REQUEST['ids'])) { - // Если пришли ID через запятую (массово) $items = explode(',', $_REQUEST['ids']); } elseif (!empty($_REQUEST['id'])) { - // Если пришел один ID (иконка) $items = (is_array($_REQUEST['id'])) ? $_REQUEST['id'] : [$_REQUEST['id']]; } if (!empty($action) && !empty($items)) { $ids = array_map('intval', $items); - $id_list = implode(',', $ids); + + // --- СОБИРАЕМ ВСЕ ID ПОТОМКОВ (ЛЮБАЯ ГЛУБИНА) --- + $all_ids_to_process = $ids; + $current_parents = $ids; + + while (!empty($current_parents)) { + $parent_list = implode(',', $current_parents); + + // Получаем результат запроса + $res = $AVE_DB->Query("SELECT Id FROM " . PREFIX . "_module_comment_info WHERE parent_id IN ($parent_list)"); + + $found_children = []; + // Перебираем результат построчно через стандартный FetchAssocArray + if ($res) { + while ($row_child = $res->FetchAssocArray()) { + $found_children[] = (int)$row_child['Id']; + } + } + + if (!empty($found_children)) { + $all_ids_to_process = array_merge($all_ids_to_process, $found_children); + $current_parents = $found_children; + } else { + $current_parents = []; + } + } + $all_ids_to_process = array_unique($all_ids_to_process); + $final_id_list = implode(',', $all_ids_to_process); + // ------------------------------------------------ switch ($action) { case 'approve': case 'set_status_1': - $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '1' WHERE Id IN ($id_list)"); + $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '1' WHERE Id IN ($final_id_list)"); break; case 'unapprove': case 'set_status_0': - $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '0' WHERE Id IN ($id_list)"); + $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '0' WHERE Id IN ($final_id_list)"); break; case 'delete': - $AVE_DB->Query("DELETE FROM " . PREFIX . "_module_comment_info WHERE Id IN ($id_list)"); + $AVE_DB->Query("DELETE FROM " . PREFIX . "_module_comment_info WHERE Id IN ($final_id_list)"); break; } header("Location: index.php?do=modules&action=modedit&mod=comment&moduleaction=1&cp=" . $session_id); exit; } - // --- ОРИГИНАЛЬНАЯ ЛОГИКА ВЫВОДА --- + // --- ЛОГИКА ВЫВОДА (С ПАГИНАЦИЕЙ) --- $num = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_module_comment_info")->GetCell(); $limit = $this->_limit; $seiten = ceil($num / $limit); @@ -1385,7 +1410,7 @@ function commentAdminListShow($tpl_dir) LIMIT " . (int)$start . "," . (int)$limit ); - $docs = array(); + $all_items = array(); $format = "%d %B %Y, %H:%M"; while ($row = $sql->FetchAssocArray()) { @@ -1400,36 +1425,25 @@ function commentAdminListShow($tpl_dir) $row['avatar_color_index'] = (abs(crc32($name)) % 12) + 1; } - // --- ОБРАБОТКА ФАЙЛОВ ДЛЯ АДМИНКИ --- - $row['images'] = []; - $row['files'] = []; - if (!empty($row['comment_file'])) { - $img_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp']; - $all_files = explode(',', $row['comment_file']); - - foreach ($all_files as $f_name) { - $f_name = trim($f_name); - if (!$f_name) continue; - - $ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION)); - - // Чистим имя (убираем временную метку _12345678) - $clean_name = preg_replace('/_[0-9]+(?=\.[a-z0-9]+$)/i', '', $f_name); - - $file_data = [ - 'orig_name' => $f_name, - 'clean_name' => $clean_name, - 'ext' => $ext - ]; - - if (in_array($ext, $img_exts)) { - $row['images'][] = $file_data; - } else { - $row['files'][] = $file_data; + // ОБРАБОТКА ФАЙЛОВ + $row['images'] = []; + $row['files'] = []; + if (!empty($row['comment_file'])) { + $img_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp']; + $all_files = explode(',', $row['comment_file']); + foreach ($all_files as $f_name) { + $f_name = trim($f_name); + if (!$f_name) continue; + $ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION)); + $clean_name = preg_replace('/_[0-9]+(?=\.[a-z0-9]+$)/i', '', $f_name); + $file_data = ['orig_name' => $f_name, 'clean_name' => $clean_name, 'ext' => $ext]; + if (in_array($ext, $img_exts)) { + $row['images'][] = $file_data; + } else { + $row['files'][] = $file_data; + } } } - } - // ------------------------------------ $row['CId'] = $row['Id']; $row['comment_text'] = stripslashes($row['comment_text']); @@ -1443,7 +1457,47 @@ function commentAdminListShow($tpl_dir) $row['r_count'] = (int)($row['rating_count'] ?? 0); $row['star_public'] = ($row['r_count'] > 0) ? round($row['rating_sum'] / $row['r_count']) : 0; - $docs[] = $row; + $all_items[$row['Id']] = $row; + } + + // --- ПОСТРОЕНИЕ ДЕРЕВА --- + $child_map = []; + foreach ($all_items as $id => $item) { + $p_id = (int)$item['parent_id']; + if ($p_id > 0) $child_map[$p_id][] = $id; + } + + $docs = []; + $processed = []; + + $buildTree = function($parent_id, $level) use (&$buildTree, &$docs, &$processed, &$all_items, &$child_map) { + if (isset($child_map[$parent_id])) { + foreach ($child_map[$parent_id] as $child_id) { + if (!in_array($child_id, $processed)) { + $item = $all_items[$child_id]; + $item['depth_level'] = $level; + $docs[] = $item; + $processed[] = $child_id; + $buildTree($child_id, $level + 1); + } + } + } + }; + + foreach ($all_items as $id => $item) { + if ($item['parent_id'] == 0 && !in_array($id, $processed)) { + $item['depth_level'] = 0; + $docs[] = $item; + $processed[] = $id; + $buildTree($id, 1); + } + } + + foreach ($all_items as $id => $item) { + if (!in_array($id, $processed)) { + $item['depth_level'] = 0; + $docs[] = $item; + } } $AVE_Template->assign([ diff --git a/templates/admin_comments.tpl b/templates/admin_comments.tpl index dabcb14..0c3d4a8 100644 --- a/templates/admin_comments.tpl +++ b/templates/admin_comments.tpl @@ -1,69 +1,73 @@
{#COMMENT_MODULE_NAME#} (Всего: {$docs|count})
@@ -77,30 +81,31 @@ - - - + + + {if $docs} - {foreach from=$docs item=row} - + {foreach from=$docs item=row name=zebraloop} + - + @@ -173,7 +182,7 @@
- @@ -186,49 +195,20 @@
\ No newline at end of file
IDДанные АвтораIDДанные Автора Текст комментария и файлы
{$row.CId} -
+ +
+
{if $row.avatar}{else}
{$row.first_letter}
{/if}
- {$row.comment_author_name|escape} + {$row.comment_author_name|escape}
-
- {section name=s start=1 loop=6}{if $smarty.section.s.index <= $row.user_rating}★{else}{/if}{/section} +
+ {section name=s start=1 loop=6}{if $smarty.section.s.index <= $row.user_rating}★{else}{/if}{/section}
📅 {$row.date_pub}
{if $row.date_edit}
📝 ред. {$row.date_edit}
{/if} @@ -108,15 +113,20 @@
-
+
- - {$row.document_title|default:"Документ"|truncate:25} + {if $row.parent_id > 0} + ОТВЕТ НА #{$row.parent_id} + {/if} + + {$row.document_title|default:"Документ"|truncate:35} - [#] к отзыву -
- + [#] Посмотреть + +
+ {if $row.comment_status=='1'}Одобрен{else}Скрыт{/if} {if $row.comment_status == '1'} @@ -125,7 +135,7 @@ {/if} - +
@@ -136,30 +146,29 @@ {foreach from=$row.images item=img}
- {$img.clean_name} + {$img.clean_name|truncate:15:"...":true}
{/foreach} {foreach from=$row.files item=f}
- - {$f.ext|upper} - + + {$f.ext|upper} - {$f.clean_name} + {$f.clean_name|truncate:15:"...":true}
{/foreach}
{/if} -
-
- {section name=s start=1 loop=6}{if $smarty.section.s.index <= $row.star_public}{else}{/if}{/section} +
+
+ {section name=s start=1 loop=6}{if $smarty.section.s.index <= $row.star_public}★{else}{/if}{/section}
- (Голосов: {$row.r_count|default:0}) + (Голосов: {$row.r_count|default:0})